| OLD | NEW | 
|    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 29 matching lines...) Expand all  Loading... | 
|  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   // Trim it |  | 
|  148   value = value.trim(); |  145   value = value.trim(); | 
|  149   if (value.length == 0) |  146   if (value.length == 0) | 
|  150     return null; |  147     return null; | 
|  151  |  148  | 
|  152   // Replace backslashes |  149   // Replace backslashes | 
|  153   value = value.replace(/\\/g, "/"); |  150   value = value.replace(/\\/g, "/"); | 
|  154  |  151  | 
|  155   // Does the URL scheme need correcting? |  152   // Does the URL scheme need correcting? | 
|  156   if (/^([^\/]+)(\/.*)/.test(value)) |  153   if (/^([^\/]+)(\/.*)/.test(value)) | 
|  157   { |  154   { | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
|  171  |  168  | 
|  172   // Ignore search keywords and such |  169   // Ignore search keywords and such | 
|  173   if ("getShortcutOrURI" in window && window.getShortcutOrURI(value) != value) |  170   if ("getShortcutOrURI" in window && window.getShortcutOrURI(value) != value) | 
|  174     return null; |  171     return null; | 
|  175  |  172  | 
|  176   // 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 | 
|  177   if (/^[^\/\.\s]+\s/.test(value)) |  174   if (/^[^\/\.\s]+\s/.test(value)) | 
|  178     return null; |  175     return null; | 
|  179  |  176  | 
|  180   // Check manually entered corrections |  177   // Check manually entered corrections | 
|  181   if (Prefs.custom_replace[value]) |  178   if (Prefs.custom_replace.hasOwnProperty(value) && Prefs.custom_replace[value]) | 
|  182     return Prefs.custom_replace[value]; |  179     return Prefs.custom_replace[value]; | 
|  183  |  180  | 
|  184   let [prefix, domain, suffix] = parseURL(value); |  181   let [prefix, domain, suffix] = parseURL(value); | 
|  185   if (!domain) |  182   if (!domain) | 
|  186     return null; |  183     return null; | 
|  187  |  184  | 
|  188   let oldDomain = domain; |  185   let oldDomain = domain; | 
|  189   if (!isIPAddress(domain)) |  186   if (!isIPAddress(domain)) | 
|  190   { |  187   { | 
|  191     processTypedDomain(domain); |  188     processTypedDomain(domain); | 
|  192  |  189  | 
|  193     let newDomain = getDomainCorrection(domain); |  190     let newDomain = getDomainCorrection(domain); | 
|  194     if (newDomain != domain) |  191     if (newDomain != domain) | 
|  195     { |  192     { | 
 |  193       processDomainCorrection(domain, newDomain); | 
|  196       domain = newDomain; |  194       domain = newDomain; | 
|  197       hasCorrection = true; |  195       hasCorrection = true; | 
|  198  |  196  | 
|  199       let referral = getDomainReferral(domain.replace(/^www\./, "")); |  197       let referral = getDomainReferral(domain.replace(/^www\./, "")); | 
|  200       if (referral) |  198       if (referral) | 
|  201       { |  199       { | 
|  202         // 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 | 
|  203         let anchorIndex = suffix.indexOf("#"); |  201         let anchorIndex = suffix.indexOf("#"); | 
|  204         let anchor = ""; |  202         let anchor = ""; | 
|  205         if (anchorIndex >= 0) |  203         if (anchorIndex >= 0) | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
|  224  |  222  | 
|  225         suffix += anchor; |  223         suffix += anchor; | 
|  226       } |  224       } | 
|  227     } |  225     } | 
|  228   } |  226   } | 
|  229  |  227  | 
|  230   if (!hasCorrection) |  228   if (!hasCorrection) | 
|  231     return null; |  229     return null; | 
|  232  |  230  | 
|  233   // Show infobar to inform and ask about correction |  231   // Show infobar to inform and ask about correction | 
|  234   let browser = appIntegration.getBrowser(window); |  232   let [message, yes, no] = getInfobarTexts(); | 
|  235   let infobar = browser.getNotificationBox(); |  233   message = message.replace(/\?1\?/g, prefix+domain); | 
|  236   let notif = infobar.getNotificationWithValue("url-fixer-infobar-askafter"); |  234   let buttons = [ | 
 |  235     { | 
 |  236       label:      yes, | 
 |  237       accessKey:  null, | 
 |  238       callback:   function() | 
 |  239       { | 
 |  240         // Yes: Do nothing | 
 |  241       } | 
 |  242     }, | 
 |  243     { | 
 |  244       label:      no, | 
 |  245       accessKey:  null, | 
 |  246       callback:   function() | 
 |  247       { | 
 |  248         // No: Add to list of corrections (ignore) | 
 |  249         let {onWhitelistEntryAdded} = require("rules"); | 
 |  250         let entry = oldDomain.replace(/^www\./, ""); | 
 |  251         Prefs.whitelist[entry] = true; | 
 |  252         onWhitelistEntryAdded(entry); | 
 |  253         Prefs.whitelist = JSON.parse(JSON.stringify(Prefs.whitelist)); | 
|  237  |  254  | 
|  238   let [message, yes, no, cancel] = getAskAfterDialogTexts(); |  255         require("appIntegration").loadURI(window, value); | 
|  239   message = message.replace(/\?1\?/g, prefix+domain); |  256         processFalsePositive(domain, oldDomain); | 
 |  257       } | 
 |  258     } | 
 |  259   ]; | 
 |  260   // We need to have persistence being set to 1 due to redirect which happens af
     terwards | 
 |  261   require("appIntegration").openInfobar(window, "url-fixer-infobar-askafter", me
     ssage, buttons, 1); | 
|  240  |  262  | 
|  241   if (notif) |  263   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  |  | 
|  283   // Consider the correction a second typed domain |  | 
|  284   if (!isIPAddress(domain)) |  | 
|  285     processTypedDomain(domain); |  | 
|  286  |  264  | 
|  287   return prefix + domain + suffix; |  265   return prefix + domain + suffix; | 
|  288 } |  266 } | 
|  289  |  267  | 
|  290 let stringBundle = null; |  268 let stringBundle = null; | 
|  291  |  269  | 
|  292 function getAskAfterDialogTexts() |  270 function getInfobarTexts() | 
|  293 { |  271 { | 
 |  272   // Randomize URI to work around bug 719376 | 
|  294   if (!stringBundle) |  273   if (!stringBundle) | 
|  295     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()); | 
|  296   let result = [ |  275   let result = [ | 
|  297     stringBundle.GetStringFromName("urlfixer.isItCorrect"), |  276     stringBundle.GetStringFromName("urlfixer.isItCorrect"), | 
|  298     stringBundle.GetStringFromName("urlfixer.yes"), |  277     stringBundle.GetStringFromName("urlfixer.yes"), | 
|  299     stringBundle.GetStringFromName("urlfixer.no"), |  278     stringBundle.GetStringFromName("urlfixer.no") | 
|  300     stringBundle.GetStringFromName("urlfixer.cancel") |  | 
|  301   ]; |  279   ]; | 
|  302  |  280  | 
|  303   getAskAfterDialogTexts = function() result; |  281   getInfobarTexts = function() result; | 
|  304   return getAskAfterDialogTexts(); |  282   return getInfobarTexts(); | 
|  305 } |  283 } | 
| OLD | NEW |