| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 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 /** | |
| 19 * @fileOverview Implemenation of Firefox-specific general classes | |
| 20 */ | |
| 21 | |
| 18 (function() | 22 (function() |
| 19 { | 23 { |
| 20 var UI = require("ui").UI; | 24 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.
| |
| 21 | |
| 22 /* Background page */ | |
| 23 | |
| 24 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.
| |
| 25 { | |
| 26 this._location = tab.location; | |
| 27 } | |
| 28 Tab.prototype = { | |
| 29 _location: null, | |
| 30 | |
| 31 get location() | |
| 32 { | |
| 33 return this._location; | |
| 34 }, | |
| 35 | |
| 36 sendMessage: function(message, responseCallback) | |
| 37 { | |
| 38 // TODO | |
| 39 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.
| |
| 40 } | |
| 41 }; | |
| 42 | |
| 43 function Window(win) // {id, status} | |
| 44 { | |
| 45 // 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.
| |
| 46 this._window = win; | |
| 47 } | |
| 48 Window.prototype = { | |
| 49 _window: null, | |
| 50 | |
| 51 getActiveTab: function(callback) | |
| 52 { | |
| 53 var location = UI.getCurrentLocation(this._window); | |
| 54 var tab = { | |
| 55 location: location | |
| 56 }; | |
| 57 callback(new Tab(tab)); | |
| 58 } | |
| 59 }; | |
| 60 | 25 |
| 61 var backgroundPage = { | 26 var backgroundPage = { |
| 62 extractHostFromURL: function(url) | 27 extractHostFromURL: function(url) |
| 63 { | 28 { |
| 64 try | 29 try |
| 65 { | 30 { |
| 66 return Utils.unwrapURL(url).host; | 31 return Utils.unwrapURL(url).host; |
| 67 } | 32 } |
| 68 catch(e) | 33 catch(e) |
| 69 { | 34 { |
| 70 return null; | 35 return null; |
| 71 } | 36 } |
| 72 }, | 37 }, |
| 73 | 38 |
| 74 openOptions: function() | 39 openOptions: function() |
| 75 { | 40 { |
| 76 UI.openFiltersDialog(); | 41 UI.openFiltersDialog(); |
| 77 }, | 42 }, |
| 78 | 43 |
| 79 require: function() | 44 require: require |
| 80 { | |
| 81 return require; | |
| 82 } | |
| 83 }; | 45 }; |
| 84 | |
| 85 /* i18n */ | |
| 86 | 46 |
| 87 // Randomize URI to work around bug 719376 | 47 // Randomize URI to work around bug 719376 |
| 88 var pageName = location.pathname.replace(/.*\//, '').replace(/\..*?$/, ''); | 48 var pageName = location.pathname.replace(/.*\//, '').replace(/\..*?$/, ''); |
| 89 var stringBundle = Services.strings.createBundle("chrome://adblockplus/locale/ " + pageName + | 49 var stringBundle = Services.strings.createBundle("chrome://adblockplus/locale/ " + pageName + |
| 90 ".properties?" + Math.random()); | 50 ".properties?" + Math.random()); |
| 91 | 51 |
| 92 function getI18nMessage(key, args) | |
| 93 { | |
| 94 return { | |
| 95 "message": (args ? stringBundle.formatStringFromName(key, args, args.lengt h) : stringBundle.GetStringFromName(key)) | |
| 96 }; | |
| 97 } | |
| 98 | |
| 99 function getText(message, args) | |
| 100 { | |
| 101 var text = message.message; | |
| 102 var placeholders = message.placeholders; | |
| 103 | |
| 104 if (!args || !placeholders) | |
| 105 return text; | |
| 106 | |
| 107 for (var key in placeholders) | |
| 108 { | |
| 109 var content = placeholders[key].content; | |
| 110 if (!content) | |
| 111 continue; | |
| 112 | |
| 113 var index = parseInt(content.slice(1), 10); | |
| 114 if (isNaN(index)) | |
| 115 continue; | |
| 116 | |
| 117 var replacement = args[index - 1]; | |
| 118 if (typeof replacement === "undefined") | |
| 119 continue; | |
| 120 | |
| 121 text = text.split("$" + key + "$").join(replacement); | |
| 122 } | |
| 123 return text; | |
| 124 } | |
| 125 | |
| 126 /* API */ | |
| 127 | 52 |
| 128 ext = { | 53 ext = { |
| 129 backgroundPage: { | 54 backgroundPage: { |
| 130 getWindow: function() | 55 getWindow: function() |
| 131 { | 56 { |
| 132 return backgroundPage; | 57 return backgroundPage; |
| 133 } | 58 } |
| 134 }, | 59 }, |
| 135 | 60 |
| 136 i18n: { | 61 i18n: { |
| 62 /** | |
| 63 * Get locale string | |
| 64 * @param {String} key name of string | |
| 65 * @param {Array} args parameters to pass | |
| 66 * @return {String} string or null if translation is missing | |
| 67 */ | |
| 137 getMessage: function(key, args) | 68 getMessage: function(key, args) |
| 138 { | 69 { |
| 139 try{ | 70 try |
| 140 var message = getI18nMessage(key, args); | 71 { |
| 141 return getText(message, args); | 72 return stringBundle.GetStringFromName(key); |
| 142 } | 73 } |
| 143 catch(e) | 74 catch(e) |
| 144 { | 75 { |
| 145 Cu.reportError(e); | 76 Cu.reportError("Missing translation: " + key); |
| 146 return "Missing translation: " + key; | 77 return null; |
|
Thomas Greiner
2014/10/08 10:40:43
We should at least return null here.
saroyanm
2014/10/10 12:05:58
Done.
| |
| 147 } | 78 } |
| 148 } | 79 } |
| 149 }, | 80 }, |
| 150 | 81 |
| 151 windows: { | 82 pages: { |
| 152 getLastFocused: function(callback) | 83 query: function(info, callback) |
| 153 { | 84 { |
| 154 var win = UI.currentWindow; | 85 var location = UI.getCurrentLocation(UI.currentWindow); |
| 155 callback(new Window(UI.currentWindow)); | 86 if (info.active && info.lastFocusedWindow && location) |
| 87 { | |
| 88 callback([{ | |
| 89 url: location.spec, | |
| 90 sendMessage: (message, responseCallback) => responseCallback() | |
| 91 }]); | |
| 92 } | |
| 93 else | |
| 94 callback([]); | |
| 156 } | 95 } |
| 157 } | 96 } |
| 158 }; | 97 }; |
| 159 })(); | 98 })(); |
| LEFT | RIGHT |