Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 /* | 1 /* |
Thomas Greiner
2014/10/08 10:40:43
I assume you implemented this before we changed th
saroyanm
2014/10/10 12:05:58
Adapted, but have a little doubt.
Thomas Greiner
2014/10/13 13:18:23
Why is that?
| |
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 /** | 18 /** |
19 * @fileOverview implementation of platform specific general classes and API | 19 * @fileOverview Implemenation of Firefox-specific general classes |
Thomas Greiner
2014/10/08 10:40:43
What about "Implemenation of Firefox-specific gene
saroyanm
2014/10/10 12:05:58
Done.
| |
20 */ | 20 */ |
21 | 21 |
22 (function() | 22 (function() |
23 { | 23 { |
24 let UI = require("ui").UI; | 24 var UI = require("ui").UI; |
25 | 25 |
26 /** | 26 var backgroundPage = { |
27 * Tab class | |
28 * @param {Object} tab an object with url parameter | |
Thomas Greiner
2014/10/08 10:40:43
Nit: It's a property and not a parameter.
| |
29 */ | |
30 function Tab(tab) | |
31 { | |
32 this._url = tab.url; | |
33 } | |
34 Tab.prototype = { | |
35 _url: null, | |
36 | |
37 get url() | |
38 { | |
39 return this._url; | |
40 }, | |
41 | |
42 sendMessage: function(message, responseCallback) | |
43 { | |
44 responseCallback(); | |
45 } | |
46 }; | |
47 | |
48 /** | |
49 * Window class | |
50 * @param {Object} win Window object | |
51 */ | |
52 function Window(win) | |
53 { | |
54 this._window = win; | |
55 } | |
56 Window.prototype = { | |
57 _window: null, | |
58 | |
59 /** | |
60 * Pass Tab object of current active Window to callback function. | |
Thomas Greiner
2014/10/08 10:40:43
The text should describe the purpose of the functi
| |
61 * @param {function} callback | |
62 */ | |
63 getActiveTab: function(callback) | |
64 { | |
65 let location = UI.getCurrentLocation(this._window); | |
66 let tab = { | |
67 url: location.spec | |
68 }; | |
69 callback(new Tab(tab)); | |
70 } | |
71 }; | |
72 | |
73 let backgroundPage = { | |
74 extractHostFromURL: function(url) | 27 extractHostFromURL: function(url) |
75 { | 28 { |
76 try | 29 try |
77 { | 30 { |
78 return Utils.unwrapURL(url).host; | 31 return Utils.unwrapURL(url).host; |
79 } | 32 } |
80 catch(e) | 33 catch(e) |
81 { | 34 { |
82 return null; | 35 return null; |
83 } | 36 } |
84 }, | 37 }, |
85 | 38 |
86 openOptions: function() | 39 openOptions: function() |
87 { | 40 { |
88 UI.openFiltersDialog(); | 41 UI.openFiltersDialog(); |
89 }, | 42 }, |
90 | 43 |
91 require: function() | 44 require: require |
92 { | |
93 return require; | |
94 } | |
95 }; | 45 }; |
96 | 46 |
97 // Randomize URI to work around bug 719376 | 47 // Randomize URI to work around bug 719376 |
98 let pageName = location.pathname.replace(/.*\//, '').replace(/\..*?$/, ''); | 48 var pageName = location.pathname.replace(/.*\//, '').replace(/\..*?$/, ''); |
99 let stringBundle = Services.strings.createBundle("chrome://adblockplus/locale/ " + pageName + | 49 var stringBundle = Services.strings.createBundle("chrome://adblockplus/locale/ " + pageName + |
100 ".properties?" + Math.random()); | 50 ".properties?" + Math.random()); |
101 | 51 |
102 | 52 |
103 ext = { | 53 ext = { |
104 backgroundPage: { | 54 backgroundPage: { |
105 getWindow: function() | 55 getWindow: function() |
106 { | 56 { |
107 return backgroundPage; | 57 return backgroundPage; |
108 } | 58 } |
109 }, | 59 }, |
110 | 60 |
111 i18n: { | 61 i18n: { |
112 /** | 62 /** |
113 * get locale string | 63 * Get locale string |
Thomas Greiner
2014/10/08 10:40:43
Nit: Start with a capital letter.
| |
114 * @param {String} key name of string | 64 * @param {String} key name of string |
115 * @param {Array} args parameters to pass | 65 * @param {Array} args parameters to pass |
66 * @return {String} string or null if translation is missing | |
116 */ | 67 */ |
Thomas Greiner
2014/10/08 10:40:43
Please document only where it's appropriate. Apart
saroyanm
2014/10/10 12:05:58
Done.
| |
117 getMessage: function(key, args) | 68 getMessage: function(key, args) |
118 { | 69 { |
119 try | 70 try |
120 { | 71 { |
121 return (args ? stringBundle.formatStringFromName(key, args, args.lengt h) : stringBundle.GetStringFromName(key)); | 72 return stringBundle.GetStringFromName(key); |
122 } | 73 } |
123 catch(e) | 74 catch(e) |
124 { | 75 { |
125 Cu.reportError("Missing translation: " + key); | 76 Cu.reportError("Missing translation: " + key); |
77 return null; | |
126 } | 78 } |
127 } | 79 } |
128 }, | 80 }, |
129 | 81 |
130 windows: { | 82 pages: { |
131 /** | 83 query: function(info, callback) |
132 * pass focused window object to callback function | |
133 * @param {function} callback | |
Thomas Greiner
2014/10/08 10:40:43
Nit: Function and description should start with a
| |
134 */ | |
135 getLastFocused: function(callback) | |
136 { | 84 { |
137 let win = UI.currentWindow; | 85 var location = UI.getCurrentLocation(UI.currentWindow); |
138 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([]); | |
139 } | 95 } |
140 } | 96 } |
141 }; | 97 }; |
142 })(); | 98 })(); |
LEFT | RIGHT |