Skip to content

Commit affdca4

Browse files
author
Fabrice Desré
committed
Bug 835548 - Refactor BrowserElementParent.js into a .js and .jsm, and speed up message registration. r=jlebar
--HG-- rename : dom/browser-element/BrowserElementParent.js => dom/browser-element/BrowserElementParent.jsm
1 parent ba72d36 commit affdca4

File tree

5 files changed

+664
-618
lines changed

5 files changed

+664
-618
lines changed

browser/installer/removed-files.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,7 @@ xpicleanup@BIN_SUFFIX@
889889
components/BrowserElementParent.js
890890
components/BrowserElementParent.manifest
891891
components/BrowserElementPromptService.jsm
892+
components/BrowserElementParent.jsm
892893
components/contentAreaDropListener.js
893894
components/contentSecurityPolicy.js
894895
components/crypto-SDR.js

dom/browser-element/BrowserElementChild.js

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,21 @@ function debug(msg) {
2525
}
2626

2727
function sendAsyncMsg(msg, data) {
28-
sendAsyncMessage('browser-element-api:' + msg, data);
28+
if (!data) {
29+
data = { };
30+
}
31+
32+
data.msg_name = msg;
33+
sendAsyncMessage('browser-element-api:call', data);
2934
}
3035

3136
function sendSyncMsg(msg, data) {
32-
return sendSyncMessage('browser-element-api:' + msg, data);
37+
if (!data) {
38+
data = { };
39+
}
40+
41+
data.msg_name = msg;
42+
return sendSyncMessage('browser-element-api:call', data);
3343
}
3444

3545
/**
@@ -116,29 +126,34 @@ BrowserElementChild.prototype = {
116126
sendAsyncMsg('firstpaint');
117127
});
118128

119-
var self = this;
120-
function addMsgListener(msg, handler) {
121-
addMessageListener('browser-element-api:' + msg, handler.bind(self));
122-
}
123-
124-
addMsgListener("purge-history", this._recvPurgeHistory);
125-
addMsgListener("get-screenshot", this._recvGetScreenshot);
126-
addMsgListener("set-visible", this._recvSetVisible);
127-
addMsgListener("get-visible", this._recvVisible);
128-
addMsgListener("send-mouse-event", this._recvSendMouseEvent);
129-
addMsgListener("send-touch-event", this._recvSendTouchEvent);
130-
addMsgListener("get-can-go-back", this._recvCanGoBack);
131-
addMsgListener("get-can-go-forward", this._recvCanGoForward);
132-
addMsgListener("go-back", this._recvGoBack);
133-
addMsgListener("go-forward", this._recvGoForward);
134-
addMsgListener("reload", this._recvReload);
135-
addMsgListener("stop", this._recvStop);
136-
addMsgListener("unblock-modal-prompt", this._recvStopWaiting);
137-
addMsgListener("fire-ctx-callback", this._recvFireCtxCallback);
138-
addMsgListener("owner-visibility-change", this._recvOwnerVisibilityChange);
139-
addMsgListener("exit-fullscreen", this._recvExitFullscreen.bind(this));
140-
addMsgListener("activate-next-paint-listener", this._activateNextPaintListener.bind(this));
141-
addMsgListener("deactivate-next-paint-listener", this._deactivateNextPaintListener.bind(this));
129+
let self = this;
130+
131+
let mmCalls = {
132+
"purge-history": this._recvPurgeHistory,
133+
"get-screenshot": this._recvGetScreenshot,
134+
"set-visible": this._recvSetVisible,
135+
"get-visible": this._recvVisible,
136+
"send-mouse-event": this._recvSendMouseEvent,
137+
"send-touch-event": this._recvSendTouchEvent,
138+
"get-can-go-back": this._recvCanGoBack,
139+
"get-can-go-forward": this._recvCanGoForward,
140+
"go-back": this._recvGoBack,
141+
"go-forward": this._recvGoForward,
142+
"reload": this._recvReload,
143+
"stop": this._recvStop,
144+
"unblock-modal-prompt": this._recvStopWaiting,
145+
"fire-ctx-callback": this._recvFireCtxCallback,
146+
"owner-visibility-change": this._recvOwnerVisibilityChange,
147+
"exit-fullscreen": this._recvExitFullscreen.bind(this),
148+
"activate-next-paint-listener": this._activateNextPaintListener.bind(this),
149+
"deactivate-next-paint-listener": this._deactivateNextPaintListener.bind(this)
150+
}
151+
152+
addMessageListener("browser-element-api:call", function(aMessage) {
153+
if (aMessage.data.msg_name in mmCalls) {
154+
return mmCalls[aMessage.data.msg_name].apply(self, arguments);
155+
}
156+
});
142157

143158
let els = Cc["@mozilla.org/eventlistenerservice;1"]
144159
.getService(Ci.nsIEventListenerService);
@@ -186,7 +201,7 @@ BrowserElementChild.prototype = {
186201
return;
187202
switch (topic) {
188203
case 'fullscreen-origin-change':
189-
sendAsyncMsg('fullscreen-origin-change', data);
204+
sendAsyncMsg('fullscreen-origin-change', { _payload_: data });
190205
break;
191206
case 'ask-parent-to-exit-fullscreen':
192207
sendAsyncMsg('exit-fullscreen');
@@ -342,7 +357,7 @@ BrowserElementChild.prototype = {
342357
// Ignore titlechanges which don't come from the top-level
343358
// <iframe mozbrowser> window.
344359
if (win == content) {
345-
sendAsyncMsg('titlechange', e.target.title);
360+
sendAsyncMsg('titlechange', { _payload_: e.target.title });
346361
}
347362
else {
348363
debug("Not top level!");
@@ -360,7 +375,7 @@ BrowserElementChild.prototype = {
360375
// Ignore iconchanges which don't come from the top-level
361376
// <iframe mozbrowser> window.
362377
if (win == content) {
363-
sendAsyncMsg('iconchange', e.target.href);
378+
sendAsyncMsg('iconchange', { _payload_: e.target.href });
364379
}
365380
else {
366381
debug("Not top level!");
@@ -762,7 +777,7 @@ BrowserElementChild.prototype = {
762777
location = Cc["@mozilla.org/docshell/urifixup;1"]
763778
.getService(Ci.nsIURIFixup).createExposableURI(location);
764779

765-
sendAsyncMsg('locationchange', location.spec);
780+
sendAsyncMsg('locationchange', { _payload_: location.spec });
766781
},
767782

768783
onStateChange: function(webProgress, request, stateFlags, status) {
@@ -787,7 +802,7 @@ BrowserElementChild.prototype = {
787802

788803
// TODO See nsDocShell::DisplayLoadError for a list of all the error
789804
// codes (the status param) we should eventually handle here.
790-
sendAsyncMsg('error', {type: 'other'});
805+
sendAsyncMsg('error', { type: 'other' });
791806
}
792807
},
793808

@@ -814,7 +829,7 @@ BrowserElementChild.prototype = {
814829
// XXX Until bug 764496 is fixed, this will always return false.
815830
var isEV = !!(state & Ci.nsIWebProgressListener.STATE_IDENTITY_EV_TOPLEVEL);
816831

817-
sendAsyncMsg('securitychange', {state: stateDesc, extendedValidation: isEV});
832+
sendAsyncMsg('securitychange', { state: stateDesc, extendedValidation: isEV });
818833
},
819834

820835
onStatusChange: function(webProgress, request, status, message) {},

0 commit comments

Comments
 (0)