Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
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/>, | |
3 * Copyright (C) 2006-2014 Eyeo GmbH | |
4 * | |
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 | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * Adblock Plus is distributed in the hope that it will be useful, | |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 * GNU General Public License for more details. | |
13 * | |
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/>. | |
16 */ | |
17 | |
18 /** | |
19 * @fileOverview implementation of platform specific general classes and API | |
Thomas Greiner
2014/10/08 10:40:43
What about "Implemenation of Firefox-specific gene
saroyanm
2014/10/10 12:05:58
Done.
| |
20 */ | |
21 | |
22 (function() | |
23 { | |
24 let UI = require("ui").UI; | |
25 | |
26 /** | |
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) | |
75 { | |
76 try | |
77 { | |
78 return Utils.unwrapURL(url).host; | |
79 } | |
80 catch(e) | |
81 { | |
82 return null; | |
83 } | |
84 }, | |
85 | |
86 openOptions: function() | |
87 { | |
88 UI.openFiltersDialog(); | |
89 }, | |
90 | |
91 require: function() | |
92 { | |
93 return require; | |
94 } | |
95 }; | |
96 | |
97 // Randomize URI to work around bug 719376 | |
98 let pageName = location.pathname.replace(/.*\//, '').replace(/\..*?$/, ''); | |
99 let stringBundle = Services.strings.createBundle("chrome://adblockplus/locale/ " + pageName + | |
100 ".properties?" + Math.random()); | |
101 | |
102 | |
103 ext = { | |
104 backgroundPage: { | |
105 getWindow: function() | |
106 { | |
107 return backgroundPage; | |
108 } | |
109 }, | |
110 | |
111 i18n: { | |
112 /** | |
113 * get locale string | |
Thomas Greiner
2014/10/08 10:40:43
Nit: Start with a capital letter.
| |
114 * @param {String} key name of string | |
115 * @param {Array} args parameters to pass | |
116 */ | |
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) | |
118 { | |
119 try | |
120 { | |
121 return (args ? stringBundle.formatStringFromName(key, args, args.lengt h) : stringBundle.GetStringFromName(key)); | |
122 } | |
123 catch(e) | |
124 { | |
125 Cu.reportError("Missing translation: " + key); | |
126 } | |
127 } | |
128 }, | |
129 | |
130 windows: { | |
131 /** | |
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 { | |
137 let win = UI.currentWindow; | |
138 callback(new Window(UI.currentWindow)); | |
139 } | |
140 } | |
141 }; | |
142 })(); | |
OLD | NEW |