| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 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         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(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 |  | 
| 265   // Consider the correction a second typed domain |  | 
| 266   if (!isIPAddress(domain)) |  | 
| 267     processTypedDomain(domain); |  | 
| 268 | 263 | 
| 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 } | 
| LEFT | RIGHT | 
|---|