Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: lib/typoAppIntegration.js

Issue 8559070: Integrated URL Fixer into Adblock Plus (Closed)
Left Patch Set: Created Oct. 12, 2012, 2:18 p.m.
Right Patch Set: Created Nov. 9, 2012, 3:21 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/main.js ('k') | lib/typoCollector.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* This Source Code Form is subject to the terms of the Mozilla Public 1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
4 4
5 let {hook} = require("hooks"); 5 let {hook} = require("hooks");
6 let {application, addonName} = require("info");
7
6 let functionHooks = new WeakMap(); 8 let functionHooks = new WeakMap();
7 9
8 exports.removeFromWindow = function(window) 10 exports.removeFromWindow = function(window)
9 { 11 {
10 if (functionHooks.has(window)) 12 if (functionHooks.has(window))
11 { 13 {
12 let unhook = functionHooks.get(window); 14 let unhook = functionHooks.get(window);
13 unhook(); 15 unhook();
14 functionHooks.delete(window); 16 functionHooks.delete(window);
15 } 17 }
16 }; 18 };
17 19
18 let {application} = require("info"); 20 switch (addonName)
21 {
22 case "url-fixer":
23 {
24 // URL Fixer
25 exports.isTypoCorrectionEnabled = function(window, prefix, domain, suffix) t rue;
26
27 break;
28 }
29 case "adblockplus":
30 {
31 // Adblock Plus
32 let {Prefs} = require("prefs");
33
34 // Do not ask to opt-in if user found setting
35 if (!Prefs.correctTyposAsked)
36 {
37 let onPrefChange = function(name)
38 {
39 if (name == "correctTypos")
40 {
41 Prefs.correctTyposAsked = true;
42 Prefs.removeListener(onPrefChange);
43 }
44 }
45
46 Prefs.addListener(onPrefChange);
47 }
48
49 exports.isTypoCorrectionEnabled = function(window, prefix, domain, suffix)
50 {
51 if (!Prefs.correctTyposAsked && !Prefs.correctTypos)
52 {
53 let {Utils} = require("utils");
54 let message = Utils.getString("typo_optin_message").replace(/\?1\?/, dom ain);
55 let yes = Utils.getString("typo_optin_yes");
56 let no = Utils.getString("typo_optin_no");
57 let buttons = [
58 {
59 label: yes,
60 accessKey: null,
61 callback: function()
62 {
63 // Yes: Enable typo correction
64 Prefs.correctTypos = true;
65 exports.loadURI(window, prefix + domain + suffix);
66 Prefs.correctTyposAsked = true;
67 }
68 },
69 {
70 label: no,
71 accessKey: null,
72 callback: function()
73 {
74 // No: Do nothing
75 Prefs.correctTyposAsked = true;
76 }
77 }
78 ];
79 // We need to have persistence being set to 1 due to redirect which happ ens afterwards
80 exports.openInfobar(window, "adblockplus-infobar-correct-typos-ask", mes sage, buttons, 1);
81 }
82
83 return Prefs.correctTypos;
84 };
85
86 break;
87 }
88 }
89
19 switch (application) 90 switch (application)
20 { 91 {
21 case "firefox": 92 case "firefox":
22 { 93 {
23 // Firefox 94 // Firefox
24 exports.isKnownWindow = function(window) window.document.documentElement.get Attribute("windowtype") == "navigator:browser"; 95 exports.isKnownWindow = function(window) window.document.documentElement.get Attribute("windowtype") == "navigator:browser";
25 96
26 exports.getURLBar = function(window) "gURLBar" in window ? window.gURLBar : null; 97 exports.getURLBar = function(window) "gURLBar" in window ? window.gURLBar : null;
27 98
28 exports.getBrowser = function(window) "gBrowser" in window ? window.gBrowser : null; 99 exports.getBrowser = function(window) "gBrowser" in window ? window.gBrowser : null;
(...skipping 17 matching lines...) Expand all
46 exports.openInfobar = function(window, id, message, buttons, persistence) 117 exports.openInfobar = function(window, id, message, buttons, persistence)
47 { 118 {
48 let browser = exports.getBrowser(window); 119 let browser = exports.getBrowser(window);
49 let infobar = browser.getNotificationBox(); 120 let infobar = browser.getNotificationBox();
50 let notification = infobar.getNotificationWithValue(id); 121 let notification = infobar.getNotificationWithValue(id);
51 122
52 if (notification) 123 if (notification)
53 { 124 {
54 infobar.removeNotification(notification); 125 infobar.removeNotification(notification);
55 } 126 }
56
57 notification = infobar.appendNotification( 127 notification = infobar.appendNotification(
58 message, 128 message,
59 id, 129 id,
60 require("info").addonRoot + "icon64.png", 130 "chrome://" + addonName + "/skin/icon16.png",
61 infobar.PRIORITY_INFO_HIGH, 131 infobar.PRIORITY_INFO_HIGH,
62 buttons 132 buttons
63 ); 133 );
64 notification.persistence = persistence; 134 notification.persistence = persistence;
65 }; 135 };
66 136
67 exports.loadURI = function(window, uri) 137 exports.loadURI = function(window, uri)
68 { 138 {
69 exports.getBrowser(window).loadURI(uri); 139 exports.getBrowser(window).loadURI(uri);
70 }; 140 };
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 let notification = infobar.getNotificationWithValue(id); 206 let notification = infobar.getNotificationWithValue(id);
137 207
138 if (notification) 208 if (notification)
139 { 209 {
140 infobar.removeNotification(notification); 210 infobar.removeNotification(notification);
141 } 211 }
142 212
143 notification = infobar.appendNotification( 213 notification = infobar.appendNotification(
144 message, 214 message,
145 id, 215 id,
146 require("info").addonRoot + "icon64.png", 216 "chrome://" + addonName + "/skin/icon16.png",
147 infobar.PRIORITY_INFO_HIGH, 217 infobar.PRIORITY_INFO_HIGH,
148 buttons 218 buttons
149 ); 219 );
150 notification.persistence = persistence; 220 notification.persistence = persistence;
151 }; 221 };
152 222
153 exports.loadURI = function(window, uri) 223 exports.loadURI = function(window, uri)
154 { 224 {
155 exports.getBrowser(window).loadURI(uri); 225 exports.getBrowser(window).loadURI(uri);
156 }; 226 };
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 let notification = infobar.getNotificationWithValue(id); 263 let notification = infobar.getNotificationWithValue(id);
194 264
195 if (notification) 265 if (notification)
196 { 266 {
197 infobar.removeNotification(notification); 267 infobar.removeNotification(notification);
198 } 268 }
199 269
200 notification = infobar.appendNotification( 270 notification = infobar.appendNotification(
201 message, 271 message,
202 id, 272 id,
203 require("info").addonRoot + "icon64.png", 273 "chrome://" + addonName + "/skin/icon16.png",
204 infobar.PRIORITY_INFO_HIGH, 274 infobar.PRIORITY_INFO_HIGH,
205 buttons 275 buttons
206 ); 276 );
207 notification.persistence = persistence; 277 notification.persistence = persistence;
208 } 278 }
209 }; 279 };
210 280
211 exports.loadURI = function(window, uri) 281 exports.loadURI = function(window, uri)
212 { 282 {
213 if ("BrowserUI" in window && "goToURI" in window.BrowserUI) 283 if ("BrowserUI" in window && "goToURI" in window.BrowserUI)
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 functionHooks.set(window, unhook); 336 functionHooks.set(window, unhook);
267 } 337 }
268 }; 338 };
269 339
270 exports.openInfobar = function(window, id, message, buttons, persistence) 340 exports.openInfobar = function(window, id, message, buttons, persistence)
271 { 341 {
272 if ("BrowserApp" in window && "selectedTab" in window.BrowserApp) 342 if ("BrowserApp" in window && "selectedTab" in window.BrowserApp)
273 { 343 {
274 window.NativeWindow.doorhanger.show(message, id, buttons, window.Browser App.selectedTab.id, 344 window.NativeWindow.doorhanger.show(message, id, buttons, window.Browser App.selectedTab.id,
275 { 345 {
276 // No navigation is happening after doorhanger is shown 346 persistence: persistence
277 // so persistence needs to be reduced by one
278 persistence: persistence - 1
279 } 347 }
280 ); 348 );
281 } 349 }
282 }; 350 };
283 351
284 exports.loadURI = function(window, uri) 352 exports.loadURI = function(window, uri)
285 { 353 {
286 if ("BrowserApp" in window && "loadURI" in window.BrowserApp) 354 if ("BrowserApp" in window && "loadURI" in window.BrowserApp)
287 window.BrowserApp.loadURI(uri); 355 window.BrowserApp.loadURI(uri);
288 }; 356 };
289 357
290 break; 358 break;
291 } 359 }
292 default: 360 default:
293 { 361 {
294 exports.isKnownWindow = function(window) false; 362 exports.isKnownWindow = function(window) false;
295 break; 363 break;
296 } 364 }
297 } 365 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld