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

Side by Side Diff: lib/typoFixer.js

Issue 8382011: Applied changes from emailed code review (Closed)
Patch Set: Created Sept. 18, 2012, 2:06 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« lib/typedItCollector.js ('K') | « lib/typedItCollector.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 Cu.import("resource://gre/modules/Services.jsm"); 5 Cu.import("resource://gre/modules/Services.jsm");
6 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); 6 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
7 7
8 let {Prefs} = require("prefs"); 8 let {Prefs} = require("prefs");
9 let {WindowObserver} = require("windowObserver"); 9 let {WindowObserver} = require("windowObserver");
10 let {getSchemeCorrection, isKnownScheme, getDomainCorrection, getDomainReferral} = require("rules"); 10 let {getSchemeCorrection, isKnownScheme, getDomainCorrection, getDomainReferral} = require("rules");
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 } 136 }
137 catch (e) 137 catch (e)
138 { 138 {
139 return (e.result == Cr.NS_ERROR_HOST_IS_IP_ADDRESS); 139 return (e.result == Cr.NS_ERROR_HOST_IS_IP_ADDRESS);
140 } 140 }
141 } 141 }
142 142
143 function correctURL(window, value) 143 function correctURL(window, value)
144 { 144 {
145 let hasCorrection = false; 145 let hasCorrection = false;
146 146
147 // Trim it
148 value = value.trim(); 147 value = value.trim();
149 if (value.length == 0) 148 if (value.length == 0)
150 return null; 149 return null;
151 150
152 // Replace backslashes 151 // Replace backslashes
153 value = value.replace(/\\/g, "/"); 152 value = value.replace(/\\/g, "/");
154 153
155 // Does the URL scheme need correcting? 154 // Does the URL scheme need correcting?
156 if (/^([^\/]+)(\/.*)/.test(value)) 155 if (/^([^\/]+)(\/.*)/.test(value))
157 { 156 {
(...skipping 13 matching lines...) Expand all
171 170
172 // Ignore search keywords and such 171 // Ignore search keywords and such
173 if ("getShortcutOrURI" in window && window.getShortcutOrURI(value) != value) 172 if ("getShortcutOrURI" in window && window.getShortcutOrURI(value) != value)
174 return null; 173 return null;
175 174
176 // Spaces before the first slash or period is probably a quick search 175 // Spaces before the first slash or period is probably a quick search
177 if (/^[^\/\.\s]+\s/.test(value)) 176 if (/^[^\/\.\s]+\s/.test(value))
178 return null; 177 return null;
179 178
180 // Check manually entered corrections 179 // Check manually entered corrections
181 if (Prefs.custom_replace[value]) 180 if (Prefs.custom_replace.hasOwnProperty(value) && Prefs.custom_replace[value])
182 return Prefs.custom_replace[value]; 181 return Prefs.custom_replace[value];
183 182
184 let [prefix, domain, suffix] = parseURL(value); 183 let [prefix, domain, suffix] = parseURL(value);
185 if (!domain) 184 if (!domain)
186 return null; 185 return null;
187 186
188 let oldDomain = domain; 187 let oldDomain = domain;
189 if (!isIPAddress(domain)) 188 if (!isIPAddress(domain))
190 { 189 {
191 processTypedDomain(domain); 190 processTypedDomain(domain);
192 191
193 let newDomain = getDomainCorrection(domain); 192 let newDomain = getDomainCorrection(domain);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 } 227 }
229 228
230 if (!hasCorrection) 229 if (!hasCorrection)
231 return null; 230 return null;
232 231
233 // Show infobar to inform and ask about correction 232 // Show infobar to inform and ask about correction
234 let browser = appIntegration.getBrowser(window); 233 let browser = appIntegration.getBrowser(window);
235 let infobar = browser.getNotificationBox(); 234 let infobar = browser.getNotificationBox();
236 let notif = infobar.getNotificationWithValue("url-fixer-infobar-askafter"); 235 let notif = infobar.getNotificationWithValue("url-fixer-infobar-askafter");
237 236
238 let [message, yes, no, cancel] = getAskAfterDialogTexts(); 237 let [message, yes, no, cancel] = getInfobarTexts();
239 message = message.replace(/\?1\?/g, prefix+domain); 238 message = message.replace(/\?1\?/g, prefix+domain);
240 239
241 if (notif) 240 if (notif)
242 { 241 {
243 notif.label = message; 242 notif.label = message;
244 } 243 }
245 else 244 else
246 { 245 {
247 let buttons = [ 246 let buttons = [
248 { 247 {
249 label: yes, 248 label: yes,
250 accessKey: null, 249 accessKey: null,
251 callback: function() 250 callback: function()
252 { 251 {
253 // Yes: Do nothing 252 // Yes: Do nothing
254 } 253 }
255 }, 254 },
256 { 255 {
257 label: no, 256 label: no,
258 accessKey: null, 257 accessKey: null,
259 callback: function() 258 callback: function()
260 { 259 {
261 // No: Add to list of corrections (ignore) 260 // No: Add to list of corrections (ignore)
262 // TODO: maybe find more appropriate place to store this information 261 if (/^www\./.test(value))
263 Prefs.custom_replace[value] = value; 262 {
264 Prefs.custom_replace = JSON.parse(JSON.stringify(Prefs.custom_replace) ); 263 value = value.substr(4);
264 }
Wladimir Palant 2012/09/21 14:40:25 Somebody reading this code now has to recognize th
265 Prefs.whitelist[value] = value;
266 Prefs.whitelist = JSON.parse(JSON.stringify(Prefs.whitelist));
Wladimir Palant 2012/09/21 14:40:25 I understand why you wanted the whitelist to be a
265 267
266 browser.loadURI(value); 268 browser.loadURI(value);
267 processFalsePositive(oldDomain, domain); 269 processFalsePositive(oldDomain, domain);
268 } 270 }
269 } 271 }
270 ]; 272 ];
271 notif = infobar.appendNotification( 273 notif = infobar.appendNotification(
272 message, 274 message,
273 "url-fixer-infobar-askafter", 275 "url-fixer-infobar-askafter",
274 require("info").addonRoot + "icon64.png", 276 require("info").addonRoot + "icon64.png",
275 infobar.PRIORITY_INFO_LOW, 277 infobar.PRIORITY_INFO_HIGH,
276 buttons 278 buttons
277 ); 279 );
278 notif.persistence = 1; 280 notif.persistence = 1;
279 } 281 }
280 282
281 require("survey").incrementCorrectionsCounter(window); 283 require("survey").incrementCorrectionsCounter();
282 284
283 // Consider the correction a second typed domain 285 // Consider the correction a second typed domain
284 if (!isIPAddress(domain)) 286 if (!isIPAddress(domain))
285 processTypedDomain(domain); 287 processTypedDomain(domain);
286 288
287 return prefix + domain + suffix; 289 return prefix + domain + suffix;
288 } 290 }
289 291
290 let stringBundle = null; 292 let stringBundle = null;
291 293
292 function getAskAfterDialogTexts() 294 function getInfobarTexts()
293 { 295 {
296 // Randomize URI to work around bug 719376
294 if (!stringBundle) 297 if (!stringBundle)
295 stringBundle = Services.strings.createBundle("chrome://url-fixer/locale/loca le.properties?" + Math.random()); 298 stringBundle = Services.strings.createBundle("chrome://url-fixer/locale/loca le.properties?" + Math.random());
296 let result = [ 299 let result = [
297 stringBundle.GetStringFromName("urlfixer.isItCorrect"), 300 stringBundle.GetStringFromName("urlfixer.isItCorrect"),
298 stringBundle.GetStringFromName("urlfixer.yes"), 301 stringBundle.GetStringFromName("urlfixer.yes"),
299 stringBundle.GetStringFromName("urlfixer.no"), 302 stringBundle.GetStringFromName("urlfixer.no"),
300 stringBundle.GetStringFromName("urlfixer.cancel") 303 stringBundle.GetStringFromName("urlfixer.cancel")
301 ]; 304 ];
302 305
303 getAskAfterDialogTexts = function() result; 306 getInfobarTexts = function() result;
304 return getAskAfterDialogTexts(); 307 return getInfobarTexts();
305 } 308 }
OLDNEW
« lib/typedItCollector.js ('K') | « lib/typedItCollector.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld