Index: chrome/content/ui/ext/common.js |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/chrome/content/ui/ext/common.js |
@@ -0,0 +1,98 @@ |
+/* |
+ * This file is part of Adblock Plus <http://adblockplus.org/>, |
+ * Copyright (C) 2006-2014 Eyeo GmbH |
+ * |
+ * Adblock Plus is free software: you can redistribute it and/or modify |
+ * it under the terms of the GNU General Public License version 3 as |
+ * published by the Free Software Foundation. |
+ * |
+ * Adblock Plus is distributed in the hope that it will be useful, |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+ * 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/>. |
+ */ |
+ |
+/** |
+ * @fileOverview Implemenation of Firefox-specific general classes |
+ */ |
+ |
+(function() |
+{ |
+ var UI = require("ui").UI; |
+ |
+ var backgroundPage = { |
+ extractHostFromURL: function(url) |
+ { |
+ try |
+ { |
+ return Utils.unwrapURL(url).host; |
+ } |
+ catch(e) |
+ { |
+ return null; |
+ } |
+ }, |
+ |
+ openOptions: function() |
+ { |
+ UI.openFiltersDialog(); |
+ }, |
+ |
+ require: require |
+ }; |
+ |
+ // Randomize URI to work around bug 719376 |
+ var pageName = location.pathname.replace(/.*\//, '').replace(/\..*?$/, ''); |
+ var stringBundle = Services.strings.createBundle("chrome://adblockplus/locale/" + pageName + |
+ ".properties?" + Math.random()); |
+ |
+ |
+ ext = { |
+ backgroundPage: { |
+ getWindow: function() |
+ { |
+ return backgroundPage; |
+ } |
+ }, |
+ |
+ i18n: { |
+ /** |
+ * Get locale string |
+ * @param {String} key name of string |
+ * @param {Array} args parameters to pass |
+ * @return {String} string or null if translation is missing |
+ */ |
+ getMessage: function(key, args) |
+ { |
+ try |
+ { |
+ return stringBundle.GetStringFromName(key); |
+ } |
+ catch(e) |
+ { |
+ Cu.reportError("Missing translation: " + key); |
+ return null; |
+ } |
+ } |
+ }, |
+ |
+ pages: { |
+ query: function(info, callback) |
+ { |
+ var location = UI.getCurrentLocation(UI.currentWindow); |
+ if (info.active && info.lastFocusedWindow && location) |
+ { |
+ callback([{ |
+ url: location.spec, |
+ sendMessage: (message, responseCallback) => responseCallback() |
+ }]); |
+ } |
+ else |
+ callback([]); |
+ } |
+ } |
+ }; |
+})(); |