8000 refactor: use std::string instead of base::string16 for IPC channel names by miniak · Pull Request #14286 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

refactor: use std::string instead of base::string16 for IPC channel names #14286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions atom/browser/api/atom_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ struct WebContents::FrameDispatchHelper {
api_web_contents->OnGetZoomLevel(rfh, reply_msg);
}

void OnRendererMessageSync(const base::string16& channel,
void OnRendererMessageSync(const std::string& channel,
const base::ListValue& args,
IPC::Message* message) {
api_web_contents->OnRendererMessageSync(rfh, channel, args, message);
Expand Down Expand Up @@ -1550,7 +1550,7 @@ void WebContents::TabTraverse(bool reverse) {
}

bool WebContents::SendIPCMessage(bool all_frames,
const base::string16& channel,
const std::string& channel,
const base::ListValue& args) {
auto* frame_host = web_contents()->GetMainFrame();
if (frame_host) {
Expand Down Expand Up @@ -2063,18 +2063,18 @@ AtomBrowserContext* WebContents::GetBrowserContext() const {
}

void WebContents::OnRendererMessage(content::RenderFrameHost* frame_host,
const base::string16& channel,
const std::string& channel,
const base::ListValue& args) {
// webContents.emit(channel, new Event(), args...);
Emit(base::UTF16ToUTF8(channel), args);
Emit(channel, args);
}

void WebContents::OnRendererMessageSync(content::RenderFrameHost* frame_host,
const base::string16& channel,
const std::string& channel,
const base::ListValue& args,
IPC::Message* message) {
// webContents.emit(channel, new Event(sender, message), args...);
EmitWithSender(base::UTF16ToUTF8(channel), frame_host, message, args);
EmitWithSender(channel, frame_host, message, args);
}

// static
Expand Down
6 changes: 3 additions & 3 deletions atom/browser/api/atom_api_web_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class WebContents : public mate::TrackableObject<WebContents>,

// Send messages to browser.
bool SendIPCMessage(bool all_frames,
const base::string16& channel,
const std::string& channel,
const base::ListValue& args);

// Send WebInputEvent to the page.
Expand Down Expand Up @@ -410,12 +410,12 @@ class WebContents : public mate::TrackableObject<WebContents>,

// Called when received a message from renderer.
void OnRendererMessage(content::RenderFrameHost* frame_host,
const base::string16& channel,
const std::string& channel,
const base::ListValue& args);

// Called when received a synchronous message from renderer.
void OnRendererMessageSync(content::RenderFrameHost* frame_host,
const base::string16& channel,
const std::string& channel,
const base::ListValue& args,
IPC::Message* message);

Expand Down
6 changes: 3 additions & 3 deletions atom/common/api/api_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ IPC_STRUCT_TRAITS_BEGIN(atom::DraggableRegion)
IPC_STRUCT_TRAITS_END()

IPC_MESSAGE_ROUTED2(AtomFrameHostMsg_Message,
base::string16 /* channel */,
std::string /* channel */,
base::ListValue /* arguments */)

IPC_SYNC_MESSAGE_ROUTED2_1(AtomFrameHostMsg_Message_Sync,
base::string16 /* channel */,
std::string /* channel */,
base::ListValue /* arguments */,
base::ListValue /* result */)

IPC_MESSAGE_ROUTED3(AtomFrameMsg_Message,
bool /* send_to_all */,
base::string16 /* channel */,
std::string /* channel */,
base::ListValue /* arguments */)

IPC_MESSAGE_ROUTED0(AtomViewMsg_Offscreen)
Expand Down
3 changes: 1 addition & 2 deletions atom/common/api/remote_callback_freer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ RemoteCallbackFreer::RemoteCallbackFreer(v8::Isolate* isolate,
RemoteCallbackFreer::~RemoteCallbackFreer() {}

void RemoteCallbackFreer::RunDestructor() {
base::string16 channel =
base::ASCIIToUTF16("ELECTRON_RENDERER_RELEASE_CALLBACK");
auto* channel = "ELECTRON_RENDERER_RELEASE_CALLBACK";
base::ListValue args;
args.AppendString(context_id_);
args.AppendInteger(object_id_);
Expand Down
2 changes: 1 addition & 1 deletion atom/common/api/remote_object_freer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void RemoteObjectFreer::RunDestructor() {
if (!render_frame)
return;

base::string16 channel = base::ASCIIToUTF16("ipc-message");
auto* channel = "ipc-message";
base::ListValue args;
args.AppendString("ELECTRON_BROWSER_DEREFERENCE");
args.AppendString(context_id_);
Expand Down
4 changes: 2 additions & 2 deletions atom/renderer/api/atom_api_renderer_ipc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ RenderFrame* GetCurrentRenderFrame() {
}

void Send(mate::Arguments* args,
const base::string16& channel,
const std::string& channel,
const base::ListValue& arguments) {
RenderFrame* render_frame = GetCurrentRenderFrame();
if (render_frame == nullptr)
Expand All @@ -42,7 +42,7 @@ void Send(mate::Arguments* args,
}

base::ListValue SendSync(mate::Arguments* args,
const base::string16& channel,
const std::string& channel,
const base::ListValue& arguments) {
base::ListValue result;

Expand Down
6 changes: 4 additions & 2 deletions atom/renderer/api/atom_api_renderer_ipc.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef ATOM_RENDERER_API_ATOM_API_RENDERER_IPC_H_
#define ATOM_RENDERER_API_ATOM_API_RENDERER_IPC_H_

#include <string>

#include "base/values.h"
#include "native_mate/arguments.h"

Expand All @@ -13,11 +15,11 @@ namespace atom {
namespace api {

void Send(mate::Arguments* args,
const base::string16& channel,
const std::string& channel,
const base::ListValue& arguments);

base::ListValue SendSync(mate::Arguments* args,
const base::string16& channel,
const std::string& channel,
const base::ListValue& arguments);

void Initialize(v8::Local<v8::Object> exports,
Expand Down
4 changes: 2 additions & 2 deletions atom/renderer/atom_render_frame_observer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ bool AtomRenderFrameObserver::OnMessageReceived(const IPC::Message& message) {
}

void AtomRenderFrameObserver::OnBrowserMessage(bool send_to_all,
const base::string16& channel,
const std::string& channel,
const base::ListValue& args) {
// Don't handle browser messages before document element is created.
// When we receive a message from the browser, we try to transfer it
Expand All @@ -195,7 +195,7 @@ void AtomRenderFrameObserver::OnBrowserMessage(bool send_to_all,
}

void AtomRenderFrameObserver::EmitIPCEvent(blink::WebLocalFrame* frame,
const base::string16& channel,
const std::string& channel,
const base::ListValue& args) {
if (!frame)
return;
Expand Down
6 changes: 4 additions & 2 deletions atom/renderer/atom_render_frame_observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef 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 "base/strings/string16.h"
#include "content/public/renderer/render_frame_observer.h"
Expand Down Expand Up @@ -42,7 +44,7 @@ class AtomRenderFrameObserver : public content::RenderFrameObserver {

protected:
virtual void EmitIPCEvent(blink::WebLocalFrame* frame,
const base::string16& channel,
const std::string& channel,
const base::ListValue& args);

private:
Expand All @@ -51,7 +53,7 @@ class AtomRenderFrameObserver : public content::RenderFrameObserver {
bool IsMainWorld(int world_id);
bool IsIsolatedWorld(int world_id);
void OnBrowserMessage(bool send_to_all,
const base::string16& channel,
const std::string& channel,
const base::ListValue& args);

content::RenderFrame* render_frame_;
Expand Down
2 changes: 1 addition & 1 deletion atom/renderer/atom_sandboxed_renderer_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class AtomSandboxedRenderFrameObserver : public AtomRenderFrameObserver {

protected:
void EmitIPCEvent(blink::WebLocalFrame* frame,
const base::string16& channel,
const std::string& channel,
const base::ListValue& args) override {
if (!frame)
return;
Expand Down
15 changes: 15 additions & 0 deletions spec/api-ipc-renderer-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,21 @@ describe('ipc renderer module', () => {

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', () => {
Expand Down
3 changes: 3 additions & 0 deletions spec/fixtures/pages/ping-pong.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
ipcRenderer.on('ping', function (event, id) {
ipcRenderer.sendTo(id, 'pong', id)
})
ipcRenderer.on('ping-æøåü', function (event, id) {
ipcRenderer.sendTo(id, 'pong-æøåü', id)
})
</script>
</body>
</html>
Expand Down
0