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

Side by Side Diff: lib/typoFixer.js

Issue 8433028: added hook function to appIntegration to handle function-overwrites from other extensions (Closed)
Patch Set: added missing statement Created Sept. 28, 2012, 9:52 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') | lib/updateRules.js » ('j') | 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 28 matching lines...) Expand all
136 } 134 }
137 catch (e) 135 catch (e)
138 { 136 {
139 return (e.result == Cr.NS_ERROR_HOST_IS_IP_ADDRESS); 137 return (e.result == Cr.NS_ERROR_HOST_IS_IP_ADDRESS);
140 } 138 }
141 } 139 }
142 140
143 function correctURL(window, value) 141 function correctURL(window, value)
144 { 142 {
145 let hasCorrection = false; 143 let hasCorrection = false;
146 144
147 value = value.trim(); 145 value = value.trim();
148 if (value.length == 0) 146 if (value.length == 0)
149 return null; 147 return null;
150 148
151 // Replace backslashes 149 // Replace backslashes
152 value = value.replace(/\\/g, "/"); 150 value = value.replace(/\\/g, "/");
153 151
154 // Does the URL scheme need correcting? 152 // Does the URL scheme need correcting?
155 if (/^([^\/]+)(\/.*)/.test(value)) 153 if (/^([^\/]+)(\/.*)/.test(value))
156 { 154 {
(...skipping 15 matching lines...) Expand all
172 if ("getShortcutOrURI" in window && window.getShortcutOrURI(value) != value) 170 if ("getShortcutOrURI" in window && window.getShortcutOrURI(value) != value)
173 return null; 171 return null;
174 172
175 // Spaces before the first slash or period is probably a quick search 173 // Spaces before the first slash or period is probably a quick search
176 if (/^[^\/\.\s]+\s/.test(value)) 174 if (/^[^\/\.\s]+\s/.test(value))
177 return null; 175 return null;
178 176
179 // Check manually entered corrections 177 // Check manually entered corrections
180 if (Prefs.custom_replace.hasOwnProperty(value) && Prefs.custom_replace[value]) 178 if (Prefs.custom_replace.hasOwnProperty(value) && Prefs.custom_replace[value])
181 return Prefs.custom_replace[value]; 179 return Prefs.custom_replace[value];
182 180
183 let [prefix, domain, suffix] = parseURL(value); 181 let [prefix, domain, suffix] = parseURL(value);
184 if (!domain) 182 if (!domain)
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 { 239 {
241 // Yes: Do nothing 240 // Yes: Do nothing
242 } 241 }
243 }, 242 },
244 { 243 {
245 label: no, 244 label: no,
246 accessKey: null, 245 accessKey: null,
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 if (/^www\./.test(value)) 249 let {onWhitelistEntryAdded} = require("rules");
251 { 250 let entry = oldDomain.replace(/^www\./, "");
252 value = value.substr(4); 251 Prefs.whitelist[entry] = true;
253 } 252 onWhitelistEntryAdded(entry);
254 Prefs.whitelist[value] = value;
255 Prefs.whitelist = JSON.parse(JSON.stringify(Prefs.whitelist)); 253 Prefs.whitelist = JSON.parse(JSON.stringify(Prefs.whitelist));
256 254
257 require("appIntegration").loadURI(value); 255 require("appIntegration").loadURI(window, value);
258 processFalsePositive(oldDomain, domain); 256 processFalsePositive(domain, oldDomain);
259 } 257 }
260 } 258 }
261 ]; 259 ];
262 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);
263 261
264 require("survey").incrementCorrectionsCounter(); 262 require("survey").incrementCorrectionsCounter();
265 263
266 // Consider the correction a second typed domain
267 if (!isIPAddress(domain))
268 processTypedDomain(domain);
269
270 return prefix + domain + suffix; 264 return prefix + domain + suffix;
271 } 265 }
272 266
273 let stringBundle = null; 267 let stringBundle = null;
274 268
275 function getInfobarTexts() 269 function getInfobarTexts()
276 { 270 {
277 // Randomize URI to work around bug 719376 271 // Randomize URI to work around bug 719376
278 if (!stringBundle) 272 if (!stringBundle)
279 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());
280 let result = [ 274 let result = [
281 stringBundle.GetStringFromName("urlfixer.isItCorrect"), 275 stringBundle.GetStringFromName("urlfixer.isItCorrect"),
282 stringBundle.GetStringFromName("urlfixer.yes"), 276 stringBundle.GetStringFromName("urlfixer.yes"),
283 stringBundle.GetStringFromName("urlfixer.no"), 277 stringBundle.GetStringFromName("urlfixer.no"),
284 stringBundle.GetStringFromName("urlfixer.cancel") 278 stringBundle.GetStringFromName("urlfixer.cancel")
285 ]; 279 ];
286 280
287 getInfobarTexts = function() result; 281 getInfobarTexts = function() result;
288 return getInfobarTexts(); 282 return getInfobarTexts();
289 } 283 }
OLDNEW
« no previous file with comments | « lib/typedItCollector.js ('k') | lib/updateRules.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld