OLD | NEW |
1 /* | 1 /* |
2 * This file is part of the Adblock Plus, | 2 * This file is part of the Adblock Plus, |
3 * Copyright (C) 2006-2012 Eyeo GmbH | 3 * Copyright (C) 2006-2012 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 |
(...skipping 18 matching lines...) Expand all Loading... |
29 functionHooks.delete(window); | 29 functionHooks.delete(window); |
30 } | 30 } |
31 }; | 31 }; |
32 | 32 |
33 switch (addonName) | 33 switch (addonName) |
34 { | 34 { |
35 case "url-fixer": | 35 case "url-fixer": |
36 { | 36 { |
37 // URL Fixer | 37 // URL Fixer |
38 exports.isTypoCorrectionEnabled = function(window, prefix, domain, suffix) t
rue; | 38 exports.isTypoCorrectionEnabled = function(window, prefix, domain, suffix) t
rue; |
39 | 39 |
40 break; | 40 break; |
41 } | 41 } |
42 case "adblockplus": | 42 case "adblockplus": |
43 { | 43 { |
44 // Adblock Plus | 44 // Adblock Plus |
45 let {Prefs} = require("prefs"); | 45 let {Prefs} = require("prefs"); |
46 | 46 |
47 // Do not ask to opt-in if user found setting | 47 // Do not ask to opt-in if user found setting |
48 if (!Prefs.correctTyposAsked) | 48 if (!Prefs.correctTyposAsked) |
49 { | 49 { |
50 let onPrefChange = function(name) | 50 let onPrefChange = function(name) |
51 { | 51 { |
52 if (name == "correctTypos") | 52 if (name == "correctTypos") |
53 { | 53 { |
54 Prefs.correctTyposAsked = true; | 54 Prefs.correctTyposAsked = true; |
55 Prefs.removeListener(onPrefChange); | 55 Prefs.removeListener(onPrefChange); |
56 } | 56 } |
57 } | 57 } |
58 | 58 |
59 Prefs.addListener(onPrefChange); | 59 Prefs.addListener(onPrefChange); |
60 } | 60 } |
61 | 61 |
62 exports.isTypoCorrectionEnabled = function(window, prefix, domain, suffix) | 62 exports.isTypoCorrectionEnabled = function(window, prefix, domain, suffix) |
63 { | 63 { |
64 if (!Prefs.correctTyposAsked && !Prefs.correctTypos) | 64 if (!Prefs.correctTyposAsked && !Prefs.correctTypos) |
65 { | 65 { |
66 let {Utils} = require("utils"); | 66 let {Utils} = require("utils"); |
67 let message = Utils.getString("typo_optin_message").replace(/\?1\?/, dom
ain); | 67 let message = Utils.getString("typo_optin_message").replace(/\?1\?/, dom
ain); |
68 let yes = Utils.getString("typo_optin_yes"); | 68 let yes = Utils.getString("typo_optin_yes"); |
69 let no = Utils.getString("typo_optin_no"); | 69 let no = Utils.getString("typo_optin_no"); |
70 let buttons = [ | 70 let buttons = [ |
71 { | 71 { |
(...skipping 13 matching lines...) Expand all Loading... |
85 callback: function() | 85 callback: function() |
86 { | 86 { |
87 // No: Do nothing | 87 // No: Do nothing |
88 Prefs.correctTyposAsked = true; | 88 Prefs.correctTyposAsked = true; |
89 } | 89 } |
90 } | 90 } |
91 ]; | 91 ]; |
92 // We need to have persistence being set to 1 due to redirect which happ
ens afterwards | 92 // We need to have persistence being set to 1 due to redirect which happ
ens afterwards |
93 exports.openInfobar(window, "adblockplus-infobar-correct-typos-ask", mes
sage, buttons, 1); | 93 exports.openInfobar(window, "adblockplus-infobar-correct-typos-ask", mes
sage, buttons, 1); |
94 } | 94 } |
95 | 95 |
96 return Prefs.correctTypos; | 96 return Prefs.correctTypos; |
97 }; | 97 }; |
98 | 98 |
99 break; | 99 break; |
100 } | 100 } |
101 } | 101 } |
102 | 102 |
103 switch (application) | 103 switch (application) |
104 { | 104 { |
105 case "firefox": | 105 case "firefox": |
106 { | 106 { |
107 // Firefox | 107 // Firefox |
108 exports.isKnownWindow = function(window) window.document.documentElement.get
Attribute("windowtype") == "navigator:browser"; | 108 exports.isKnownWindow = function(window) window.document.documentElement.get
Attribute("windowtype") == "navigator:browser"; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 | 165 |
166 exports.getBrowser = function(window) "gBrowser" in window ? window.gBrowser
: null; | 166 exports.getBrowser = function(window) "gBrowser" in window ? window.gBrowser
: null; |
167 | 167 |
168 exports.applyToWindow = function(window, corrector) | 168 exports.applyToWindow = function(window, corrector) |
169 { | 169 { |
170 let urlbar = exports.getURLBar(window); | 170 let urlbar = exports.getURLBar(window); |
171 let goButton = window.document.getElementById("go-button-container"); | 171 let goButton = window.document.getElementById("go-button-container"); |
172 | 172 |
173 if (urlbar && urlbar._fireEvent && !functionHooks.has(window)) | 173 if (urlbar && urlbar._fireEvent && !functionHooks.has(window)) |
174 { | 174 { |
175 function correctURL() | 175 let correctURL = function() |
176 { | 176 { |
177 let correction = corrector(window, urlbar.value); | 177 let correction = corrector(window, urlbar.value); |
178 if (correction) | 178 if (correction) |
179 urlbar.value = correction; | 179 urlbar.value = correction; |
180 } | 180 }; |
181 | 181 |
182 let unhook = hook(urlbar, "_fireEvent", function(eventType) | 182 let unhook = hook(urlbar, "_fireEvent", function(eventType) |
183 { | 183 { |
184 if (eventType == "textentered") | 184 if (eventType == "textentered") |
185 { | 185 { |
186 correctURL(); | 186 correctURL(); |
187 } | 187 } |
188 }); | 188 }); |
189 functionHooks.set(window, unhook); | 189 functionHooks.set(window, unhook); |
190 | 190 |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 | 308 |
309 exports.getURLBar = function(window) null; | 309 exports.getURLBar = function(window) null; |
310 | 310 |
311 exports.getBrowser = function(window) null; | 311 exports.getBrowser = function(window) null; |
312 | 312 |
313 exports.applyToWindow = function(window, corrector) | 313 exports.applyToWindow = function(window, corrector) |
314 { | 314 { |
315 if ("BrowserApp" in window && window.BrowserApp.observe && !functionHooks.
has(window)) | 315 if ("BrowserApp" in window && window.BrowserApp.observe && !functionHooks.
has(window)) |
316 { | 316 { |
317 let innerUnhook = null; | 317 let innerUnhook = null; |
318 function cleanup() | 318 let cleanup = function() |
319 { | 319 { |
320 if (innerUnhook) | 320 if (innerUnhook) |
321 innerUnhook(); | 321 innerUnhook(); |
322 | 322 |
323 innerUnhook = null; | 323 innerUnhook = null; |
324 } | 324 }; |
325 | 325 |
326 let unhook = hook(window.BrowserApp, "observe", function(subject, topic,
data) | 326 let unhook = hook(window.BrowserApp, "observe", function(subject, topic,
data) |
327 { | 327 { |
328 // Huge hack: we replace addTab/loadURI when the observer is | 328 // Huge hack: we replace addTab/loadURI when the observer is |
329 // triggered. This seems to be the only way to know that the calls | 329 // triggered. This seems to be the only way to know that the calls |
330 // originate from user input. | 330 // originate from user input. |
331 let method = null; | 331 let method = null; |
332 if (topic == "Tab:Add") | 332 if (topic == "Tab:Add") |
333 method = "addTab"; | 333 method = "addTab"; |
334 else if (topic == "Tab:Load") | 334 else if (topic == "Tab:Load") |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 }; | 369 }; |
370 | 370 |
371 break; | 371 break; |
372 } | 372 } |
373 default: | 373 default: |
374 { | 374 { |
375 exports.isKnownWindow = function(window) false; | 375 exports.isKnownWindow = function(window) false; |
376 break; | 376 break; |
377 } | 377 } |
378 } | 378 } |
OLD | NEW |