Simplify the implementation of sendToAll

This commit is contained in:
Cheng Zhao 2016-05-29 12:10:32 +09:00
parent de001a9bbf
commit 5f3fdbe635
3 changed files with 9 additions and 20 deletions

View file

@ -1088,14 +1088,10 @@ void WebContents::TabTraverse(bool reverse) {
web_contents()->FocusThroughTabTraversal(reverse);
}
bool WebContents::SendIPCMessage(const base::string16& channel,
bool WebContents::SendIPCMessage(bool all_frames,
const base::string16& channel,
const base::ListValue& args) {
return Send(new AtomViewMsg_Message(routing_id(), false, channel, args));
}
bool WebContents::SendIPCMessageToAll(const base::string16& channel,
const base::ListValue& args) {
return Send(new AtomViewMsg_Message(routing_id(), true, channel, args));
return Send(new AtomViewMsg_Message(routing_id(), all_frames, channel, args));
}
void WebContents::SendInputEvent(v8::Isolate* isolate,
@ -1263,7 +1259,6 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
.SetMethod("focus", &WebContents::Focus)
.SetMethod("tabTraverse", &WebContents::TabTraverse)
.SetMethod("_send", &WebContents::SendIPCMessage)
.SetMethod("_sendToAll", &WebContents::SendIPCMessageToAll)
.SetMethod("sendInputEvent", &WebContents::SendInputEvent)
.SetMethod("beginFrameSubscription",
&WebContents::BeginFrameSubscription)

View file

@ -122,9 +122,8 @@ class WebContents : public mate::TrackableObject<WebContents>,
void TabTraverse(bool reverse);
// Send messages to browser.
bool SendIPCMessage(const base::string16& channel,
const base::ListValue& args);
bool SendIPCMessageToAll(const base::string16& channel,
bool SendIPCMessage(bool all_frames,
const base::string16& channel,
const base::ListValue& args);
// Send WebInputEvent to the page.

View file

@ -71,20 +71,15 @@ let wrapWebContents = function (webContents) {
webContents.setMaxListeners(0)
// WebContents::send(channel, args..)
webContents.send = function (channel, ...args) {
if (channel == null) {
throw new Error('Missing required channel argument')
}
return this._send(channel, args)
}
// WebContents::sendToAll(channel, args..)
webContents.sendToAll = function (channel, ...args) {
const sendWrapper = (allFrames, channel, ...args) => {
if (channel == null) {
throw new Error('Missing required channel argument')
}
return this._sendToAll(channel, args)
return webContents._send(allFrames, channel, args)
}
webContents.send = sendWrapper.bind(null, false)
webContents.sendToAll = sendWrapper.bind(null, true)
// The navigation controller.
controller = new NavigationController(webContents)