Index: chrome/content/ui/ext/common.js |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/chrome/content/ui/ext/common.js |
@@ -0,0 +1,122 @@ |
+/* |
+ * 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; |
+ |
+ /** |
+ * Page class |
+ * @param {Object} tab an object with url property |
+ */ |
+ function Page(tab) |
+ { |
+ this._url = tab.url; |
+ } |
+ |
+ Page.prototype = { |
+ _url: null, |
+ |
+ get url() |
+ { |
+ return this._url; |
+ }, |
+ |
+ sendMessage: function(message, responseCallback) |
+ { |
+ responseCallback(); |
+ } |
+ }; |
+ |
+ var backgroundPage = { |
+ extractHostFromURL: function(url) |
+ { |
+ try |
+ { |
+ return Utils.unwrapURL(url).host; |
+ } |
+ catch(e) |
+ { |
+ return null; |
+ } |
+ }, |
+ |
+ openOptions: function() |
+ { |
+ UI.openFiltersDialog(); |
+ }, |
+ |
+ require: function() |
+ { |
+ return 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 (args ? stringBundle.formatStringFromName(key, args, args.length) : stringBundle.GetStringFromName(key)); |
+ } |
+ catch(e) |
+ { |
+ Cu.reportError("Missing translation: " + key); |
+ return null; |
+ } |
+ } |
+ }, |
+ |
+ pages: { |
+ query: function(info, callback) |
+ { |
+ if (info.active && info.lastFocusedWindow) |
saroyanm
2014/10/10 12:05:58
Not sure about array that should be returned with
Thomas Greiner
2014/10/13 13:18:24
We do need to call the callback function even if t
saroyanm
2014/10/16 11:26:15
Done.
|
+ { |
+ var location = UI.getCurrentLocation(UI.currentWindow); |
+ var tab = { |
+ url: location.spec |
Thomas Greiner
2014/10/13 13:18:24
This will throw an error if location is `null`.
saroyanm
2014/10/16 11:26:15
Done.
|
+ }; |
+ callback([new Page(tab)]); |
+ } |
+ } |
+ } |
+ }; |
+})(); |