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

Unified Diff: lib/typoFixer.js

Issue 8382011: Applied changes from emailed code review (Closed)
Patch Set: Created Sept. 28, 2012, 1:40 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/typedItCollector.js ('k') | lib/updateRules.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
}
« 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