Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 Loading... | |
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 Loading... | |
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 Loading... | |
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 18 matching lines...) Expand all Loading... | |
223 | 222 |
224 suffix += anchor; | 223 suffix += anchor; |
225 } | 224 } |
226 } | 225 } |
227 } | 226 } |
228 | 227 |
229 if (!hasCorrection) | 228 if (!hasCorrection) |
230 return null; | 229 return null; |
231 | 230 |
232 // Show infobar to inform and ask about correction | 231 // Show infobar to inform and ask about correction |
233 let [message, yes, no, cancel] = getInfobarTexts(); | 232 let [message, yes, no] = getInfobarTexts(); |
Wladimir Palant
2012/09/28 09:29:34
You don't use a Cancel button - please remove the
| |
234 message = message.replace(/\?1\?/g, prefix+domain); | 233 message = message.replace(/\?1\?/g, prefix+domain); |
235 let buttons = [ | 234 let buttons = [ |
236 { | 235 { |
237 label: yes, | 236 label: yes, |
238 accessKey: null, | 237 accessKey: null, |
239 callback: function() | 238 callback: function() |
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; | |
Wladimir Palant
2012/09/28 09:29:34
Comments from previous review not addressed here -
| |
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 ]; |
260 // We need to have persistence being set to 1 due to redirect which happens af terwards | |
262 require("appIntegration").openInfobar(window, "url-fixer-infobar-askafter", me ssage, buttons, 1); | 261 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
| |
263 | 262 |
264 require("survey").incrementCorrectionsCounter(); | 263 require("survey").incrementCorrectionsCounter(); |
265 | |
266 // Consider the correction a second typed domain | |
267 if (!isIPAddress(domain)) | |
268 processTypedDomain(domain); | |
269 | 264 |
270 return prefix + domain + suffix; | 265 return prefix + domain + suffix; |
271 } | 266 } |
272 | 267 |
273 let stringBundle = null; | 268 let stringBundle = null; |
274 | 269 |
275 function getInfobarTexts() | 270 function getInfobarTexts() |
276 { | 271 { |
277 // Randomize URI to work around bug 719376 | 272 // Randomize URI to work around bug 719376 |
278 if (!stringBundle) | 273 if (!stringBundle) |
279 stringBundle = Services.strings.createBundle("chrome://url-fixer/locale/loca le.properties?" + Math.random()); | 274 stringBundle = Services.strings.createBundle("chrome://url-fixer/locale/loca le.properties?" + Math.random()); |
280 let result = [ | 275 let result = [ |
281 stringBundle.GetStringFromName("urlfixer.isItCorrect"), | 276 stringBundle.GetStringFromName("urlfixer.isItCorrect"), |
282 stringBundle.GetStringFromName("urlfixer.yes"), | 277 stringBundle.GetStringFromName("urlfixer.yes"), |
283 stringBundle.GetStringFromName("urlfixer.no"), | 278 stringBundle.GetStringFromName("urlfixer.no") |
284 stringBundle.GetStringFromName("urlfixer.cancel") | |
285 ]; | 279 ]; |
286 | 280 |
287 getInfobarTexts = function() result; | 281 getInfobarTexts = function() result; |
288 return getInfobarTexts(); | 282 return getInfobarTexts(); |
289 } | 283 } |
LEFT | RIGHT |