| Index: chrome/content/ui/ext/common.js |
| =================================================================== |
| new file mode 100644 |
| --- /dev/null |
| +++ b/chrome/content/ui/ext/common.js |
| @@ -0,0 +1,159 @@ |
| +/* |
| + * 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/>. |
| + */ |
| + |
| +(function() |
| +{ |
| + var UI = require("ui").UI; |
|
Thomas Greiner
2014/09/29 16:19:49
We can make use of some ES6 features in this and o
saroyanm
2014/10/02 07:53:56
updated scripts imported to popup.html except the
Thomas Greiner
2014/10/08 10:40:43
We haven't done this in other files which are used
saroyanm
2014/10/10 12:05:58
np, I should also wrote that down, reverted.
|
| + |
| + /* Background page */ |
| + |
| + function Tab(tab) // {id, url} |
|
Thomas Greiner
2014/09/29 16:19:49
This is not a proper documentation format (for exa
saroyanm
2014/10/02 07:53:56
Done.
|
| + { |
| + this._location = tab.location; |
| + } |
| + Tab.prototype = { |
| + _location: null, |
| + |
| + get location() |
| + { |
| + return this._location; |
| + }, |
| + |
| + sendMessage: function(message, responseCallback) |
| + { |
| + // TODO |
| + responseCallback(); // TODO |
|
Thomas Greiner
2014/09/29 16:19:49
Remove the TODOs here if nothing's missing.
saroyanm
2014/10/02 07:53:56
Done.
|
| + } |
| + }; |
| + |
| + function Window(win) // {id, status} |
| + { |
| + // TODO |
|
Thomas Greiner
2014/09/29 16:19:49
Remove the TODOs here if nothing's missing.
saroyanm
2014/10/02 07:53:56
Done.
|
| + this._window = win; |
| + } |
| + Window.prototype = { |
| + _window: null, |
| + |
| + getActiveTab: function(callback) |
| + { |
| + var location = UI.getCurrentLocation(this._window); |
| + var tab = { |
| + location: location |
| + }; |
| + callback(new Tab(tab)); |
| + } |
| + }; |
| + |
| + var backgroundPage = { |
| + extractHostFromURL: function(url) |
| + { |
| + try |
| + { |
| + return Utils.unwrapURL(url).host; |
| + } |
| + catch(e) |
| + { |
| + return null; |
| + } |
| + }, |
| + |
| + openOptions: function() |
| + { |
| + UI.openFiltersDialog(); |
| + }, |
| + |
| + require: function() |
| + { |
| + return require; |
| + } |
| + }; |
| + |
| + /* i18n */ |
| + |
| + // 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()); |
| + |
| + function getI18nMessage(key, args) |
| + { |
| + return { |
| + "message": (args ? stringBundle.formatStringFromName(key, args, args.length) : stringBundle.GetStringFromName(key)) |
| + }; |
| + } |
| + |
| + function getText(message, args) |
| + { |
| + var text = message.message; |
| + var placeholders = message.placeholders; |
| + |
| + if (!args || !placeholders) |
| + return text; |
| + |
| + for (var key in placeholders) |
| + { |
| + var content = placeholders[key].content; |
| + if (!content) |
| + continue; |
| + |
| + var index = parseInt(content.slice(1), 10); |
| + if (isNaN(index)) |
| + continue; |
| + |
| + var replacement = args[index - 1]; |
| + if (typeof replacement === "undefined") |
| + continue; |
| + |
| + text = text.split("$" + key + "$").join(replacement); |
| + } |
| + return text; |
| + } |
| + |
| + /* API */ |
| + |
| + ext = { |
| + backgroundPage: { |
| + getWindow: function() |
| + { |
| + return backgroundPage; |
| + } |
| + }, |
| + |
| + i18n: { |
| + getMessage: function(key, args) |
| + { |
| + try{ |
| + var message = getI18nMessage(key, args); |
| + return getText(message, args); |
| + } |
| + catch(e) |
| + { |
| + Cu.reportError(e); |
| + return "Missing translation: " + key; |
|
Thomas Greiner
2014/10/08 10:40:43
We should at least return null here.
saroyanm
2014/10/10 12:05:58
Done.
|
| + } |
| + } |
| + }, |
| + |
| + windows: { |
| + getLastFocused: function(callback) |
| + { |
| + var win = UI.currentWindow; |
| + callback(new Window(UI.currentWindow)); |
| + } |
| + } |
| + }; |
| +})(); |