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: Applied remaining changes Created Sept. 26, 2012, 9:02 a.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 30 matching lines...) Expand all
224 223
225 suffix += anchor; 224 suffix += anchor;
226 } 225 }
227 } 226 }
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 [message, yes, no, cancel] = getInfobarTexts();
Wladimir Palant 2012/09/28 09:29:34 You don't use a Cancel button - please remove the
235 let infobar = browser.getNotificationBox(); 234 message = message.replace(/\?1\?/g, prefix+domain);
236 let notif = infobar.getNotificationWithValue("url-fixer-infobar-askafter"); 235 let buttons = [
236 {
237 label: yes,
238 accessKey: null,
239 callback: function()
240 {
241 // Yes: Do nothing
242 }
243 },
244 {
245 label: no,
246 accessKey: null,
247 callback: function()
248 {
249 // No: Add to list of corrections (ignore)
250 if (/^www\./.test(value))
251 {
252 value = value.substr(4);
253 }
254 Prefs.whitelist[value] = value;
Wladimir Palant 2012/09/28 09:29:34 Comments from previous review not addressed here -
255 Prefs.whitelist = JSON.parse(JSON.stringify(Prefs.whitelist));
237 256
238 let [message, yes, no, cancel] = getAskAfterDialogTexts(); 257 require("appIntegration").loadURI(value);
239 message = message.replace(/\?1\?/g, prefix+domain); 258 processFalsePositive(oldDomain, domain);
259 }
260 }
261 ];
262 require("appIntegration").openInfobar(window, "url-fixer-infobar-askafter", me ssage, buttons, 1);
Wladimir Palant 2012/09/28 09:29:34 It isn't obvious why we pass 1 for persistence her
240 263
241 if (notif) 264 require("survey").incrementCorrectionsCounter();
242 {
243 notif.label = message;
244 }
245 else
246 {
247 let buttons = [
248 {
249 label: yes,
250 accessKey: null,
251 callback: function()
252 {
253 // Yes: Do nothing
254 }
255 },
256 {
257 label: no,
258 accessKey: null,
259 callback: function()
260 {
261 // No: Add to list of corrections (ignore)
262 // TODO: maybe find more appropriate place to store this information
263 Prefs.custom_replace[value] = value;
264 Prefs.custom_replace = JSON.parse(JSON.stringify(Prefs.custom_replace) );
265
266 browser.loadURI(value);
267 processFalsePositive(oldDomain, domain);
268 }
269 }
270 ];
271 notif = infobar.appendNotification(
272 message,
273 "url-fixer-infobar-askafter",
274 require("info").addonRoot + "icon64.png",
275 infobar.PRIORITY_INFO_LOW,
276 buttons
277 );
278 notif.persistence = 1;
279 }
280
281 require("survey").incrementCorrectionsCounter(window);
282 265
283 // Consider the correction a second typed domain 266 // Consider the correction a second typed domain
284 if (!isIPAddress(domain)) 267 if (!isIPAddress(domain))
285 processTypedDomain(domain); 268 processTypedDomain(domain);
286 269
287 return prefix + domain + suffix; 270 return prefix + domain + suffix;
288 } 271 }
289 272
290 let stringBundle = null; 273 let stringBundle = null;
291 274
292 function getAskAfterDialogTexts() 275 function getInfobarTexts()
293 { 276 {
277 // Randomize URI to work around bug 719376
294 if (!stringBundle) 278 if (!stringBundle)
295 stringBundle = Services.strings.createBundle("chrome://url-fixer/locale/loca le.properties?" + Math.random()); 279 stringBundle = Services.strings.createBundle("chrome://url-fixer/locale/loca le.properties?" + Math.random());
296 let result = [ 280 let result = [
297 stringBundle.GetStringFromName("urlfixer.isItCorrect"), 281 stringBundle.GetStringFromName("urlfixer.isItCorrect"),
298 stringBundle.GetStringFromName("urlfixer.yes"), 282 stringBundle.GetStringFromName("urlfixer.yes"),
299 stringBundle.GetStringFromName("urlfixer.no"), 283 stringBundle.GetStringFromName("urlfixer.no"),
300 stringBundle.GetStringFromName("urlfixer.cancel") 284 stringBundle.GetStringFromName("urlfixer.cancel")
301 ]; 285 ];
302 286
303 getAskAfterDialogTexts = function() result; 287 getInfobarTexts = function() result;
304 return getAskAfterDialogTexts(); 288 return getInfobarTexts();
305 } 289 }
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