refactor: use std::string instead of base::string16 for IPC channel names (#14286)
This commit is contained in:
parent
605a4570c1
commit
e6e3ccfc50
12 changed files with 45 additions and 24 deletions
|
@ -303,7 +303,7 @@ struct WebContents::FrameDispatchHelper {
|
||||||
api_web_contents->OnGetZoomLevel(rfh, reply_msg);
|
api_web_contents->OnGetZoomLevel(rfh, reply_msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnRendererMessageSync(const base::string16& channel,
|
void OnRendererMessageSync(const std::string& channel,
|
||||||
const base::ListValue& args,
|
const base::ListValue& args,
|
||||||
IPC::Message* message) {
|
IPC::Message* message) {
|
||||||
api_web_contents->OnRendererMessageSync(rfh, channel, args, message);
|
api_web_contents->OnRendererMessageSync(rfh, channel, args, message);
|
||||||
|
@ -1550,7 +1550,7 @@ void WebContents::TabTraverse(bool reverse) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WebContents::SendIPCMessage(bool all_frames,
|
bool WebContents::SendIPCMessage(bool all_frames,
|
||||||
const base::string16& channel,
|
const std::string& channel,
|
||||||
const base::ListValue& args) {
|
const base::ListValue& args) {
|
||||||
auto* frame_host = web_contents()->GetMainFrame();
|
auto* frame_host = web_contents()->GetMainFrame();
|
||||||
if (frame_host) {
|
if (frame_host) {
|
||||||
|
@ -2063,18 +2063,18 @@ AtomBrowserContext* WebContents::GetBrowserContext() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::OnRendererMessage(content::RenderFrameHost* frame_host,
|
void WebContents::OnRendererMessage(content::RenderFrameHost* frame_host,
|
||||||
const base::string16& channel,
|
const std::string& channel,
|
||||||
const base::ListValue& args) {
|
const base::ListValue& args) {
|
||||||
// webContents.emit(channel, new Event(), args...);
|
// webContents.emit(channel, new Event(), args...);
|
||||||
Emit(base::UTF16ToUTF8(channel), args);
|
Emit(channel, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::OnRendererMessageSync(content::RenderFrameHost* frame_host,
|
void WebContents::OnRendererMessageSync(content::RenderFrameHost* frame_host,
|
||||||
const base::string16& channel,
|
const std::string& channel,
|
||||||
const base::ListValue& args,
|
const base::ListValue& args,
|
||||||
IPC::Message* message) {
|
IPC::Message* message) {
|
||||||
// webContents.emit(channel, new Event(sender, message), args...);
|
// webContents.emit(channel, new Event(sender, message), args...);
|
||||||
EmitWithSender(base::UTF16ToUTF8(channel), frame_host, message, args);
|
EmitWithSender(channel, frame_host, message, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
|
|
|
@ -178,7 +178,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||||
|
|
||||||
// Send messages to browser.
|
// Send messages to browser.
|
||||||
bool SendIPCMessage(bool all_frames,
|
bool SendIPCMessage(bool all_frames,
|
||||||
const base::string16& channel,
|
const std::string& channel,
|
||||||
const base::ListValue& args);
|
const base::ListValue& args);
|
||||||
|
|
||||||
// Send WebInputEvent to the page.
|
// Send WebInputEvent to the page.
|
||||||
|
@ -410,12 +410,12 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||||
|
|
||||||
// Called when received a message from renderer.
|
// Called when received a message from renderer.
|
||||||
void OnRendererMessage(content::RenderFrameHost* frame_host,
|
void OnRendererMessage(content::RenderFrameHost* frame_host,
|
||||||
const base::string16& channel,
|
const std::string& channel,
|
||||||
const base::ListValue& args);
|
const base::ListValue& args);
|
||||||
|
|
||||||
// Called when received a synchronous message from renderer.
|
// Called when received a synchronous message from renderer.
|
||||||
void OnRendererMessageSync(content::RenderFrameHost* frame_host,
|
void OnRendererMessageSync(content::RenderFrameHost* frame_host,
|
||||||
const base::string16& channel,
|
const std::string& channel,
|
||||||
const base::ListValue& args,
|
const base::ListValue& args,
|
||||||
IPC::Message* message);
|
IPC::Message* message);
|
||||||
|
|
||||||
|
|
|
@ -25,17 +25,17 @@ IPC_STRUCT_TRAITS_BEGIN(atom::DraggableRegion)
|
||||||
IPC_STRUCT_TRAITS_END()
|
IPC_STRUCT_TRAITS_END()
|
||||||
|
|
||||||
IPC_MESSAGE_ROUTED2(AtomFrameHostMsg_Message,
|
IPC_MESSAGE_ROUTED2(AtomFrameHostMsg_Message,
|
||||||
base::string16 /* channel */,
|
std::string /* channel */,
|
||||||
base::ListValue /* arguments */)
|
base::ListValue /* arguments */)
|
||||||
|
|
||||||
IPC_SYNC_MESSAGE_ROUTED2_1(AtomFrameHostMsg_Message_Sync,
|
IPC_SYNC_MESSAGE_ROUTED2_1(AtomFrameHostMsg_Message_Sync,
|
||||||
base::string16 /* channel */,
|
std::string /* channel */,
|
||||||
base::ListValue /* arguments */,
|
base::ListValue /* arguments */,
|
||||||
base::ListValue /* result */)
|
base::ListValue /* result */)
|
||||||
|
|
||||||
IPC_MESSAGE_ROUTED3(AtomFrameMsg_Message,
|
IPC_MESSAGE_ROUTED3(AtomFrameMsg_Message,
|
||||||
bool /* send_to_all */,
|
bool /* send_to_all */,
|
||||||
base::string16 /* channel */,
|
std::string /* channel */,
|
||||||
base::ListValue /* arguments */)
|
base::ListValue /* arguments */)
|
||||||
|
|
||||||
IPC_MESSAGE_ROUTED0(AtomViewMsg_Offscreen)
|
IPC_MESSAGE_ROUTED0(AtomViewMsg_Offscreen)
|
||||||
|
|
|
@ -34,8 +34,7 @@ RemoteCallbackFreer::RemoteCallbackFreer(v8::Isolate* isolate,
|
||||||
RemoteCallbackFreer::~RemoteCallbackFreer() {}
|
RemoteCallbackFreer::~RemoteCallbackFreer() {}
|
||||||
|
|
||||||
void RemoteCallbackFreer::RunDestructor() {
|
void RemoteCallbackFreer::RunDestructor() {
|
||||||
base::string16 channel =
|
auto* channel = "ELECTRON_RENDERER_RELEASE_CALLBACK";
|
||||||
base::ASCIIToUTF16("ELECTRON_RENDERER_RELEASE_CALLBACK");
|
|
||||||
base::ListValue args;
|
base::ListValue args;
|
||||||
args.AppendString(context_id_);
|
args.AppendString(context_id_);
|
||||||
args.AppendInteger(object_id_);
|
args.AppendInteger(object_id_);
|
||||||
|
|
|
@ -56,7 +56,7 @@ void RemoteObjectFreer::RunDestructor() {
|
||||||
if (!render_frame)
|
if (!render_frame)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
base::string16 channel = base::ASCIIToUTF16("ipc-message");
|
auto* channel = "ipc-message";
|
||||||
base::ListValue args;
|
base::ListValue args;
|
||||||
args.AppendString("ELECTRON_BROWSER_DEREFERENCE");
|
args.AppendString("ELECTRON_BROWSER_DEREFERENCE");
|
||||||
args.AppendString(context_id_);
|
args.AppendString(context_id_);
|
||||||
|
|
|
@ -28,7 +28,7 @@ RenderFrame* GetCurrentRenderFrame() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Send(mate::Arguments* args,
|
void Send(mate::Arguments* args,
|
||||||
const base::string16& channel,
|
const std::string& channel,
|
||||||
const base::ListValue& arguments) {
|
const base::ListValue& arguments) {
|
||||||
RenderFrame* render_frame = GetCurrentRenderFrame();
|
RenderFrame* render_frame = GetCurrentRenderFrame();
|
||||||
if (render_frame == nullptr)
|
if (render_frame == nullptr)
|
||||||
|
@ -42,7 +42,7 @@ void Send(mate::Arguments* args,
|
||||||
}
|
}
|
||||||
|
|
||||||
base::ListValue SendSync(mate::Arguments* args,
|
base::ListValue SendSync(mate::Arguments* args,
|
||||||
const base::string16& channel,
|
const std::string& channel,
|
||||||
const base::ListValue& arguments) {
|
const base::ListValue& arguments) {
|
||||||
base::ListValue result;
|
base::ListValue result;
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
#ifndef ATOM_RENDERER_API_ATOM_API_RENDERER_IPC_H_
|
#ifndef ATOM_RENDERER_API_ATOM_API_RENDERER_IPC_H_
|
||||||
#define ATOM_RENDERER_API_ATOM_API_RENDERER_IPC_H_
|
#define ATOM_RENDERER_API_ATOM_API_RENDERER_IPC_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "base/values.h"
|
#include "base/values.h"
|
||||||
#include "native_mate/arguments.h"
|
#include "native_mate/arguments.h"
|
||||||
|
|
||||||
|
@ -13,11 +15,11 @@ namespace atom {
|
||||||
namespace api {
|
namespace api {
|
||||||
|
|
||||||
void Send(mate::Arguments* args,
|
void Send(mate::Arguments* args,
|
||||||
const base::string16& channel,
|
const std::string& channel,
|
||||||
const base::ListValue& arguments);
|
const base::ListValue& arguments);
|
||||||
|
|
||||||
base::ListValue SendSync(mate::Arguments* args,
|
base::ListValue SendSync(mate::Arguments* args,
|
||||||
const base::string16& channel,
|
const std::string& channel,
|
||||||
const base::ListValue& arguments);
|
const base::ListValue& arguments);
|
||||||
|
|
||||||
void Initialize(v8::Local<v8::Object> exports,
|
void Initialize(v8::Local<v8::Object> exports,
|
||||||
|
|
|
@ -168,7 +168,7 @@ bool AtomRenderFrameObserver::OnMessageReceived(const IPC::Message& message) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AtomRenderFrameObserver::OnBrowserMessage(bool send_to_all,
|
void AtomRenderFrameObserver::OnBrowserMessage(bool send_to_all,
|
||||||
const base::string16& channel,
|
const std::string& channel,
|
||||||
const base::ListValue& args) {
|
const base::ListValue& args) {
|
||||||
// Don't handle browser messages before document element is created.
|
// Don't handle browser messages before document element is created.
|
||||||
// When we receive a message from the browser, we try to transfer it
|
// When we receive a message from the browser, we try to transfer it
|
||||||
|
@ -195,7 +195,7 @@ void AtomRenderFrameObserver::OnBrowserMessage(bool send_to_all,
|
||||||
}
|
}
|
||||||
|
|
||||||
void AtomRenderFrameObserver::EmitIPCEvent(blink::WebLocalFrame* frame,
|
void AtomRenderFrameObserver::EmitIPCEvent(blink::WebLocalFrame* frame,
|
||||||
const base::string16& channel,
|
const std::string& channel,
|
||||||
const base::ListValue& args) {
|
const base::ListValue& args) {
|
||||||
if (!frame)
|
if (!frame)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
#ifndef ATOM_RENDERER_ATOM_RENDER_FRAME_OBSERVER_H_
|
#ifndef ATOM_RENDERER_ATOM_RENDER_FRAME_OBSERVER_H_
|
||||||
#define ATOM_RENDERER_ATOM_RENDER_FRAME_OBSERVER_H_
|
#define ATOM_RENDERER_ATOM_RENDER_FRAME_OBSERVER_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "atom/renderer/renderer_client_base.h"
|
#include "atom/renderer/renderer_client_base.h"
|
||||||
#include "base/strings/string16.h"
|
#include "base/strings/string16.h"
|
||||||
#include "content/public/renderer/render_frame_observer.h"
|
#include "content/public/renderer/render_frame_observer.h"
|
||||||
|
@ -42,7 +44,7 @@ class AtomRenderFrameObserver : public content::RenderFrameObserver {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void EmitIPCEvent(blink::WebLocalFrame* frame,
|
virtual void EmitIPCEvent(blink::WebLocalFrame* frame,
|
||||||
const base::string16& channel,
|
const std::string& channel,
|
||||||
const base::ListValue& args);
|
const base::ListValue& args);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -51,7 +53,7 @@ class AtomRenderFrameObserver : public content::RenderFrameObserver {
|
||||||
bool IsMainWorld(int world_id);
|
bool IsMainWorld(int world_id);
|
||||||
bool IsIsolatedWorld(int world_id);
|
bool IsIsolatedWorld(int world_id);
|
||||||
void OnBrowserMessage(bool send_to_all,
|
void OnBrowserMessage(bool send_to_all,
|
||||||
const base::string16& channel,
|
const std::string& channel,
|
||||||
const base::ListValue& args);
|
const base::ListValue& args);
|
||||||
|
|
||||||
content::RenderFrame* render_frame_;
|
content::RenderFrame* render_frame_;
|
||||||
|
|
|
@ -106,7 +106,7 @@ class AtomSandboxedRenderFrameObserver : public AtomRenderFrameObserver {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void EmitIPCEvent(blink::WebLocalFrame* frame,
|
void EmitIPCEvent(blink::WebLocalFrame* frame,
|
||||||
const base::string16& channel,
|
const std::string& channel,
|
||||||
const base::ListValue& args) override {
|
const base::ListValue& args) override {
|
||||||
if (!frame)
|
if (!frame)
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -154,6 +154,21 @@ describe('ipc renderer module', () => {
|
||||||
|
|
||||||
contents.loadURL(`file://${path.join(fixtures, 'pages', 'ping-pong.html')}`)
|
contents.loadURL(`file://${path.join(fixtures, 'pages', 'ping-pong.html')}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('sends message to WebContents (channel has special chars)', done => {
|
||||||
|
const webContentsId = remote.getCurrentWebContents().id
|
||||||
|
|
||||||
|
ipcRenderer.once('pong-æøåü', (event, id) => {
|
||||||
|
expect(webContentsId).to.equal(id)
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
|
||||||
|
contents.once('did-finish-load', () => {
|
||||||
|
ipcRenderer.sendTo(contents.id, 'ping-æøåü', webContentsId)
|
||||||
|
})
|
||||||
|
|
||||||
|
contents.loadURL(`file://${path.join(fixtures, 'pages', 'ping-pong.html')}`)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('remote listeners', () => {
|
describe('remote listeners', () => {
|
||||||
|
|
3
spec/fixtures/pages/ping-pong.html
vendored
3
spec/fixtures/pages/ping-pong.html
vendored
|
@ -5,6 +5,9 @@
|
||||||
ipcRenderer.on('ping', function (event, id) {
|
ipcRenderer.on('ping', function (event, id) {
|
||||||
ipcRenderer.sendTo(id, 'pong', id)
|
ipcRenderer.sendTo(id, 'pong', id)
|
||||||
})
|
})
|
||||||
|
ipcRenderer.on('ping-æøåü', function (event, id) {
|
||||||
|
ipcRenderer.sendTo(id, 'pong-æøåü', id)
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue