Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: ext/content.js

Issue 29338928: Issue 3853 - Use new messaging API for the first-run page (Closed)
Patch Set: Addressed comments Created April 19, 2016, 11:56 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ext/common.js ('k') | lib/child/cssProperties.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ext/content.js
===================================================================
--- a/ext/content.js
+++ b/ext/content.js
@@ -12,40 +12,81 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
(function(global)
{
+ const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
+ var Services = Cu.import("resource://gre/modules/Services.jsm", {}).Services;
+
+ function require(/**String*/ module)
+ {
+ var result = {};
+ result.wrappedJSObject = result;
+ Services.obs.notifyObservers(result, "adblockplus-require", module);
+ return result.exports;
+ }
+
+ function getOuterWindowID()
+ {
+ if (!getOuterWindowID.result)
+ {
+ getOuterWindowID.result = window.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIDOMWindowUtils)
+ .outerWindowID;
+ }
+ return getOuterWindowID.result;
+ }
+
+ const Port = require("messaging").Port;
+
if (!global.ext)
global.ext = {};
/* Message passing */
- global.ext.onMessage = new global.ext._EventTarget();
-
- global.ext.backgroundPage = new global.ext._MessageProxy(
- window.QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIDocShell)
- .QueryInterface(Ci.nsIInterfaceRequestor)
- .getInterface(Ci.nsIContentFrameMessageManager),
- global.ext.onMessage);
+ var port = new Port(Cc["@mozilla.org/childprocessmessagemanager;1"]
+ .getService(Ci.nsIMessageSender));
window.addEventListener("unload", function()
{
- global.ext.backgroundPage._disconnect();
+ try
+ {
+ port.emit("ext_disconnect", getOuterWindowID());
+ }
+ catch (e)
+ {
+ // This is expected to fail if Adblock Plus was disabled/uninstalled with
+ // the page still open.
+ }
+ port.disconnect();
}, false);
+ global.ext.onMessage = new global.ext._EventTarget(port, getOuterWindowID());
+ global.ext.backgroundPage = {
+ sendMessage: function(payload, responseCallback)
+ {
+ var message = {
+ senderID: getOuterWindowID(),
+ payload
+ };
+ if (typeof responseCallback == "function")
+ port.emitWithResponse("ext_message", message).then(responseCallback);
+ else
+ port.emit("ext_message", message);
+ }
+ };
+
/* i18n */
global.ext.i18n = (function()
{
- var Services = Cu.import("resource://gre/modules/Services.jsm", null).Services;
var pageName = location.pathname.replace(/.*\//, "").replace(/\..*?$/, "");
// Randomize URI to work around bug 719376
var stringBundle = Services.strings.createBundle("chrome://adblockplus/locale/" + pageName +
".properties?" + Math.random());
function getI18nMessage(key)
{
« no previous file with comments | « ext/common.js ('k') | lib/child/cssProperties.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld