Index: lib/typoFixer.js |
=================================================================== |
--- a/lib/typoFixer.js |
+++ b/lib/typoFixer.js |
@@ -8,9 +8,8 @@ |
let {Prefs} = require("prefs"); |
let {WindowObserver} = require("windowObserver"); |
let {getSchemeCorrection, isKnownScheme, getDomainCorrection, getDomainReferral} = require("rules"); |
-let {processTypedDomain} = require("typedItCollector"); |
-let {processUserCorrection} = require("typedItCollector"); |
-let {processFalsePositive} = require("typedItCollector"); |
+let {processTypedDomain, processDomainCorrection, |
+ processUserCorrection, processFalsePositive} = require("typedItCollector"); |
let appIntegration = require("appIntegration"); |
// Attach our handlers to all browser windows |
@@ -94,7 +93,6 @@ |
let [prefix, newHost, suffix] = parseURL(newURL); |
let oldHost = document.defaultView.location.hostname.toLowerCase(); |
- processTypedDomain(newHost); |
processUserCorrection(oldHost, newHost); |
if (newHost.indexOf("www.") == 0 && oldHost.indexOf("www.") == 0) |
@@ -144,7 +142,6 @@ |
{ |
let hasCorrection = false; |
- // Trim it |
value = value.trim(); |
if (value.length == 0) |
return null; |
@@ -178,7 +175,7 @@ |
return null; |
// Check manually entered corrections |
- if (Prefs.custom_replace[value]) |
+ if (Prefs.custom_replace.hasOwnProperty(value) && Prefs.custom_replace[value]) |
return Prefs.custom_replace[value]; |
let [prefix, domain, suffix] = parseURL(value); |
@@ -193,6 +190,7 @@ |
let newDomain = getDomainCorrection(domain); |
if (newDomain != domain) |
{ |
+ processDomainCorrection(domain, newDomain); |
domain = newDomain; |
hasCorrection = true; |
@@ -231,75 +229,55 @@ |
return null; |
// Show infobar to inform and ask about correction |
- let browser = appIntegration.getBrowser(window); |
- let infobar = browser.getNotificationBox(); |
- let notif = infobar.getNotificationWithValue("url-fixer-infobar-askafter"); |
+ let [message, yes, no] = getInfobarTexts(); |
+ message = message.replace(/\?1\?/g, prefix+domain); |
+ let buttons = [ |
+ { |
+ label: yes, |
+ accessKey: null, |
+ callback: function() |
+ { |
+ // Yes: Do nothing |
+ } |
+ }, |
+ { |
+ label: no, |
+ accessKey: null, |
+ callback: function() |
+ { |
+ // No: Add to list of corrections (ignore) |
+ let {onWhitelistEntryAdded} = require("rules"); |
+ let entry = oldDomain.replace(/^www\./, ""); |
+ Prefs.whitelist[entry] = true; |
+ onWhitelistEntryAdded(entry); |
+ Prefs.whitelist = JSON.parse(JSON.stringify(Prefs.whitelist)); |
- let [message, yes, no, cancel] = getAskAfterDialogTexts(); |
- message = message.replace(/\?1\?/g, prefix+domain); |
+ require("appIntegration").loadURI(window, value); |
+ processFalsePositive(domain, oldDomain); |
+ } |
+ } |
+ ]; |
+ // We need to have persistence being set to 1 due to redirect which happens afterwards |
+ require("appIntegration").openInfobar(window, "url-fixer-infobar-askafter", message, buttons, 1); |
- if (notif) |
- { |
- notif.label = message; |
- } |
- else |
- { |
- let buttons = [ |
- { |
- label: yes, |
- accessKey: null, |
- callback: function() |
- { |
- // Yes: Do nothing |
- } |
- }, |
- { |
- label: no, |
- accessKey: null, |
- callback: function() |
- { |
- // No: Add to list of corrections (ignore) |
- // TODO: maybe find more appropriate place to store this information |
- Prefs.custom_replace[value] = value; |
- Prefs.custom_replace = JSON.parse(JSON.stringify(Prefs.custom_replace)); |
- |
- browser.loadURI(value); |
- processFalsePositive(oldDomain, domain); |
- } |
- } |
- ]; |
- notif = infobar.appendNotification( |
- message, |
- "url-fixer-infobar-askafter", |
- require("info").addonRoot + "icon64.png", |
- infobar.PRIORITY_INFO_LOW, |
- buttons |
- ); |
- notif.persistence = 1; |
- } |
- |
- require("survey").incrementCorrectionsCounter(window); |
- |
- // Consider the correction a second typed domain |
- if (!isIPAddress(domain)) |
- processTypedDomain(domain); |
+ require("survey").incrementCorrectionsCounter(); |
return prefix + domain + suffix; |
} |
let stringBundle = null; |
-function getAskAfterDialogTexts() |
+function getInfobarTexts() |
{ |
+ // Randomize URI to work around bug 719376 |
if (!stringBundle) |
stringBundle = Services.strings.createBundle("chrome://url-fixer/locale/locale.properties?" + Math.random()); |
let result = [ |
stringBundle.GetStringFromName("urlfixer.isItCorrect"), |
stringBundle.GetStringFromName("urlfixer.yes"), |
- stringBundle.GetStringFromName("urlfixer.no"), |
- stringBundle.GetStringFromName("urlfixer.cancel") |
+ stringBundle.GetStringFromName("urlfixer.no") |
]; |
- getAskAfterDialogTexts = function() result; |
- return getAskAfterDialogTexts(); |
+ getInfobarTexts = function() result; |
+ return getInfobarTexts(); |
} |