| OLD | NEW |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 Eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 (function(global) | 18 (function(global) |
| 19 { | 19 { |
| 20 const Cc = Components.classes; |
| 20 const Ci = Components.interfaces; | 21 const Ci = Components.interfaces; |
| 21 const Cu = Components.utils; | 22 const Cu = Components.utils; |
| 22 | 23 |
| 24 var Services = Cu.import("resource://gre/modules/Services.jsm", {}).Services; |
| 25 |
| 26 function require(/**String*/ module) |
| 27 { |
| 28 var result = {}; |
| 29 result.wrappedJSObject = result; |
| 30 Services.obs.notifyObservers(result, "adblockplus-require", module); |
| 31 return result.exports; |
| 32 } |
| 33 |
| 34 function getOuterWindowID() |
| 35 { |
| 36 if (!getOuterWindowID.result) |
| 37 { |
| 38 getOuterWindowID.result = window.QueryInterface(Ci.nsIInterfaceRequestor) |
| 39 .getInterface(Ci.nsIDOMWindowUtils) |
| 40 .outerWindowID; |
| 41 } |
| 42 return getOuterWindowID.result; |
| 43 } |
| 44 |
| 45 const Port = require("messaging").Port; |
| 46 |
| 23 if (!global.ext) | 47 if (!global.ext) |
| 24 global.ext = {}; | 48 global.ext = {}; |
| 25 | 49 |
| 26 /* Message passing */ | 50 /* Message passing */ |
| 27 global.ext.onMessage = new global.ext._EventTarget(); | 51 var port = new Port(Cc["@mozilla.org/childprocessmessagemanager;1"] |
| 28 | 52 .getService(Ci.nsIMessageSender)); |
| 29 global.ext.backgroundPage = new global.ext._MessageProxy( | |
| 30 window.QueryInterface(Ci.nsIInterfaceRequestor) | |
| 31 .getInterface(Ci.nsIDocShell) | |
| 32 .QueryInterface(Ci.nsIInterfaceRequestor) | |
| 33 .getInterface(Ci.nsIContentFrameMessageManager), | |
| 34 global.ext.onMessage); | |
| 35 window.addEventListener("unload", function() | 53 window.addEventListener("unload", function() |
| 36 { | 54 { |
| 37 global.ext.backgroundPage._disconnect(); | 55 try |
| 56 { |
| 57 port.emit("ext_disconnect", getOuterWindowID()); |
| 58 } |
| 59 catch (e) |
| 60 { |
| 61 // This is expected to fail if Adblock Plus was disabled/uninstalled with |
| 62 // the page still open. |
| 63 } |
| 64 port.disconnect(); |
| 38 }, false); | 65 }, false); |
| 39 | 66 |
| 67 global.ext.onMessage = new global.ext._EventTarget(port, getOuterWindowID()); |
| 68 global.ext.backgroundPage = { |
| 69 sendMessage: function(payload, responseCallback) |
| 70 { |
| 71 var message = { |
| 72 senderID: getOuterWindowID(), |
| 73 payload |
| 74 }; |
| 75 if (typeof responseCallback == "function") |
| 76 port.emitWithResponse("ext_message", message).then(responseCallback); |
| 77 else |
| 78 port.emit("ext_message", message); |
| 79 } |
| 80 }; |
| 81 |
| 40 /* i18n */ | 82 /* i18n */ |
| 41 global.ext.i18n = (function() | 83 global.ext.i18n = (function() |
| 42 { | 84 { |
| 43 var Services = Cu.import("resource://gre/modules/Services.jsm", null).Servic
es; | |
| 44 var pageName = location.pathname.replace(/.*\//, "").replace(/\..*?$/, ""); | 85 var pageName = location.pathname.replace(/.*\//, "").replace(/\..*?$/, ""); |
| 45 | 86 |
| 46 // Randomize URI to work around bug 719376 | 87 // Randomize URI to work around bug 719376 |
| 47 var stringBundle = Services.strings.createBundle("chrome://adblockplus/local
e/" + pageName + | 88 var stringBundle = Services.strings.createBundle("chrome://adblockplus/local
e/" + pageName + |
| 48 ".properties?" + Math.random()); | 89 ".properties?" + Math.random()); |
| 49 | 90 |
| 50 function getI18nMessage(key) | 91 function getI18nMessage(key) |
| 51 { | 92 { |
| 52 return { | 93 return { |
| 53 "message": stringBundle.GetStringFromName(key) | 94 "message": stringBundle.GetStringFromName(key) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 // Don't report errors for special strings, these are expected to be | 134 // Don't report errors for special strings, these are expected to be |
| 94 // missing. | 135 // missing. |
| 95 if (key[0] != "@") | 136 if (key[0] != "@") |
| 96 Cu.reportError(e); | 137 Cu.reportError(e); |
| 97 return ""; | 138 return ""; |
| 98 } | 139 } |
| 99 } | 140 } |
| 100 }; | 141 }; |
| 101 })(); | 142 })(); |
| 102 })(this); | 143 })(this); |
| OLD | NEW |