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 /** | 18 /** |
19 * @fileOverview Implemenation of Firefox-specific general classes | 19 * @fileOverview Implemenation of Firefox-specific general classes |
20 */ | 20 */ |
21 | 21 |
22 (function() | 22 (function() |
23 { | 23 { |
24 var UI = require("ui").UI; | 24 var UI = require("ui").UI; |
25 | 25 |
26 /** | |
27 * Page class | |
28 * @param {Object} tab an object with url property | |
29 */ | |
30 function Page(tab) | |
31 { | |
32 this._url = tab.url; | |
33 } | |
34 | |
35 Page.prototype = { | |
36 _url: null, | |
37 | |
38 get url() | |
39 { | |
40 return this._url; | |
41 }, | |
42 | |
43 sendMessage: function(message, responseCallback) | |
44 { | |
45 responseCallback(); | |
46 } | |
47 }; | |
48 | |
49 var backgroundPage = { | 26 var backgroundPage = { |
50 extractHostFromURL: function(url) | 27 extractHostFromURL: function(url) |
51 { | 28 { |
52 try | 29 try |
53 { | 30 { |
54 return Utils.unwrapURL(url).host; | 31 return Utils.unwrapURL(url).host; |
55 } | 32 } |
56 catch(e) | 33 catch(e) |
57 { | 34 { |
58 return null; | 35 return null; |
59 } | 36 } |
60 }, | 37 }, |
61 | 38 |
62 openOptions: function() | 39 openOptions: function() |
63 { | 40 { |
64 UI.openFiltersDialog(); | 41 UI.openFiltersDialog(); |
65 }, | 42 }, |
66 | 43 |
67 require: function() | 44 require: require |
68 { | |
69 return require; | |
70 } | |
71 }; | 45 }; |
72 | 46 |
73 // Randomize URI to work around bug 719376 | 47 // Randomize URI to work around bug 719376 |
74 var pageName = location.pathname.replace(/.*\//, '').replace(/\..*?$/, ''); | 48 var pageName = location.pathname.replace(/.*\//, '').replace(/\..*?$/, ''); |
75 var stringBundle = Services.strings.createBundle("chrome://adblockplus/locale/ " + pageName + | 49 var stringBundle = Services.strings.createBundle("chrome://adblockplus/locale/ " + pageName + |
76 ".properties?" + Math.random()); | 50 ".properties?" + Math.random()); |
77 | 51 |
78 | 52 |
79 ext = { | 53 ext = { |
80 backgroundPage: { | 54 backgroundPage: { |
81 getWindow: function() | 55 getWindow: function() |
82 { | 56 { |
83 return backgroundPage; | 57 return backgroundPage; |
84 } | 58 } |
85 }, | 59 }, |
86 | 60 |
87 i18n: { | 61 i18n: { |
88 /** | 62 /** |
89 * Get locale string | 63 * Get locale string |
90 * @param {String} key name of string | 64 * @param {String} key name of string |
91 * @param {Array} args parameters to pass | 65 * @param {Array} args parameters to pass |
92 * @return {String} string or null if translation is missing | 66 * @return {String} string or null if translation is missing |
93 */ | 67 */ |
94 getMessage: function(key, args) | 68 getMessage: function(key, args) |
95 { | 69 { |
96 try | 70 try |
97 { | 71 { |
98 return (args ? stringBundle.formatStringFromName(key, args, args.lengt h) : stringBundle.GetStringFromName(key)); | 72 return stringBundle.GetStringFromName(key); |
99 } | 73 } |
100 catch(e) | 74 catch(e) |
101 { | 75 { |
102 Cu.reportError("Missing translation: " + key); | 76 Cu.reportError("Missing translation: " + key); |
103 return null; | 77 return null; |
104 } | 78 } |
105 } | 79 } |
106 }, | 80 }, |
107 | 81 |
108 pages: { | 82 pages: { |
109 query: function(info, callback) | 83 query: function(info, callback) |
110 { | 84 { |
111 if (info.active && info.lastFocusedWindow) | 85 var location = UI.getCurrentLocation(UI.currentWindow); |
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.
| |
86 if (info.active && info.lastFocusedWindow && location) | |
112 { | 87 { |
113 var location = UI.getCurrentLocation(UI.currentWindow); | 88 callback([{ |
114 var tab = { | 89 url: location.spec, |
115 url: location.spec | 90 sendMessage: (message, responseCallback) => responseCallback() |
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.
| |
116 }; | 91 }]); |
117 callback([new Page(tab)]); | |
118 } | 92 } |
93 else | |
94 callback([]); | |
119 } | 95 } |
120 } | 96 } |
121 }; | 97 }; |
122 })(); | 98 })(); |
LEFT | RIGHT |