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

Side by Side Diff: lib/typoFixer.js

Issue 8397151: Use a better format for typed in data and record domain corrections; only send data once per hour (Closed)
Patch Set: Created Sept. 28, 2012, 8:10 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
« no previous file with comments | « 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");
11 let {processTypedDomain} = require("typedItCollector"); 11 let {processTypedDomain, processDomainCorrection,
12 let {processUserCorrection} = require("typedItCollector"); 12 processUserCorrection, processFalsePositive} = require("typedItCollector");
13 let {processFalsePositive} = require("typedItCollector");
14 let appIntegration = require("appIntegration"); 13 let appIntegration = require("appIntegration");
15 14
16 // Attach our handlers to all browser windows 15 // Attach our handlers to all browser windows
17 new WindowObserver( 16 new WindowObserver(
18 { 17 {
19 applyToWindow: function(window) 18 applyToWindow: function(window)
20 { 19 {
21 if (!appIntegration.isKnownWindow(window)) 20 if (!appIntegration.isKnownWindow(window))
22 return; 21 return;
23 22
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 let retryButton = document.getElementById("url-fixer-retry"); 86 let retryButton = document.getElementById("url-fixer-retry");
88 retryButton.addEventListener("click", function() 87 retryButton.addEventListener("click", function()
89 { 88 {
90 let newURL = textField.value.replace(/^\s+/, "").replace(/\s+$/, ""); 89 let newURL = textField.value.replace(/^\s+/, "").replace(/\s+$/, "");
91 if (!newURL.length) 90 if (!newURL.length)
92 return; 91 return;
93 92
94 let [prefix, newHost, suffix] = parseURL(newURL); 93 let [prefix, newHost, suffix] = parseURL(newURL);
95 let oldHost = document.defaultView.location.hostname.toLowerCase(); 94 let oldHost = document.defaultView.location.hostname.toLowerCase();
96 95
97 processTypedDomain(newHost);
98 processUserCorrection(oldHost, newHost); 96 processUserCorrection(oldHost, newHost);
99 97
100 if (newHost.indexOf("www.") == 0 && oldHost.indexOf("www.") == 0) 98 if (newHost.indexOf("www.") == 0 && oldHost.indexOf("www.") == 0)
101 { 99 {
102 // Ignore www. prefix if they both start with it 100 // Ignore www. prefix if they both start with it
103 newHost = newHost.substr(4); 101 newHost = newHost.substr(4);
104 oldHost = oldHost.substr(4); 102 oldHost = oldHost.substr(4);
105 } 103 }
106 if (oldHost && newHost != oldHost) 104 if (oldHost && newHost != oldHost)
107 { 105 {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 return null; 183 return null;
186 184
187 let oldDomain = domain; 185 let oldDomain = domain;
188 if (!isIPAddress(domain)) 186 if (!isIPAddress(domain))
189 { 187 {
190 processTypedDomain(domain); 188 processTypedDomain(domain);
191 189
192 let newDomain = getDomainCorrection(domain); 190 let newDomain = getDomainCorrection(domain);
193 if (newDomain != domain) 191 if (newDomain != domain)
194 { 192 {
193 processDomainCorrection(domain, newDomain);
195 domain = newDomain; 194 domain = newDomain;
196 hasCorrection = true; 195 hasCorrection = true;
197 196
198 let referral = getDomainReferral(domain.replace(/^www\./, "")); 197 let referral = getDomainReferral(domain.replace(/^www\./, ""));
199 if (referral) 198 if (referral)
200 { 199 {
201 // We need to add a query string parameter when sending users to this do main 200 // We need to add a query string parameter when sending users to this do main
202 let anchorIndex = suffix.indexOf("#"); 201 let anchorIndex = suffix.indexOf("#");
203 let anchor = ""; 202 let anchor = "";
204 if (anchorIndex >= 0) 203 if (anchorIndex >= 0)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 callback: function() 246 callback: function()
248 { 247 {
249 // No: Add to list of corrections (ignore) 248 // No: Add to list of corrections (ignore)
250 let {onWhitelistEntryAdded} = require("rules"); 249 let {onWhitelistEntryAdded} = require("rules");
251 let entry = oldDomain.replace(/^www\./, ""); 250 let entry = oldDomain.replace(/^www\./, "");
252 Prefs.whitelist[entry] = true; 251 Prefs.whitelist[entry] = true;
253 onWhitelistEntryAdded(entry); 252 onWhitelistEntryAdded(entry);
254 Prefs.whitelist = JSON.parse(JSON.stringify(Prefs.whitelist)); 253 Prefs.whitelist = JSON.parse(JSON.stringify(Prefs.whitelist));
255 254
256 require("appIntegration").loadURI(window, value); 255 require("appIntegration").loadURI(window, value);
257 processFalsePositive(oldDomain, domain); 256 processFalsePositive(domain, oldDomain);
258 } 257 }
259 } 258 }
260 ]; 259 ];
261 require("appIntegration").openInfobar(window, "url-fixer-infobar-askafter", me ssage, buttons, 1); 260 require("appIntegration").openInfobar(window, "url-fixer-infobar-askafter", me ssage, buttons, 1);
262 261
263 require("survey").incrementCorrectionsCounter(); 262 require("survey").incrementCorrectionsCounter();
264 263
265 // Consider the correction a second typed domain
266 if (!isIPAddress(domain))
267 processTypedDomain(domain);
268
269 return prefix + domain + suffix; 264 return prefix + domain + suffix;
270 } 265 }
271 266
272 let stringBundle = null; 267 let stringBundle = null;
273 268
274 function getInfobarTexts() 269 function getInfobarTexts()
275 { 270 {
276 // Randomize URI to work around bug 719376 271 // Randomize URI to work around bug 719376
277 if (!stringBundle) 272 if (!stringBundle)
278 stringBundle = Services.strings.createBundle("chrome://url-fixer/locale/loca le.properties?" + Math.random()); 273 stringBundle = Services.strings.createBundle("chrome://url-fixer/locale/loca le.properties?" + Math.random());
279 let result = [ 274 let result = [
280 stringBundle.GetStringFromName("urlfixer.isItCorrect"), 275 stringBundle.GetStringFromName("urlfixer.isItCorrect"),
281 stringBundle.GetStringFromName("urlfixer.yes"), 276 stringBundle.GetStringFromName("urlfixer.yes"),
282 stringBundle.GetStringFromName("urlfixer.no"), 277 stringBundle.GetStringFromName("urlfixer.no"),
283 stringBundle.GetStringFromName("urlfixer.cancel") 278 stringBundle.GetStringFromName("urlfixer.cancel")
284 ]; 279 ];
285 280
286 getInfobarTexts = function() result; 281 getInfobarTexts = function() result;
287 return getInfobarTexts(); 282 return getInfobarTexts();
288 } 283 }
OLDNEW
« no previous file with comments | « lib/typedItCollector.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld