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

Unified Diff: lib/typoAppIntegration.js

Issue 8948027: Ported changes from Adblock Plus integration back into URL Fixer (Closed)
Patch Set: Created Jan. 14, 2013, 10:03 a.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/main.js ('k') | lib/typoCollector.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/typoAppIntegration.js
===================================================================
--- a/lib/typoAppIntegration.js
+++ b/lib/typoAppIntegration.js
@@ -16,6 +16,8 @@
*/
let {hook} = require("hooks");
+let {application, addonName} = require("info");
+
let functionHooks = new WeakMap();
exports.removeFromWindow = function(window)
@@ -28,7 +30,76 @@
}
};
-let {application} = require("info");
+switch (addonName)
+{
+ case "url-fixer":
+ {
+ // URL Fixer
+ exports.isTypoCorrectionEnabled = function(window, prefix, domain, suffix) true;
+
+ break;
+ }
+ case "adblockplus":
+ {
+ // Adblock Plus
+ let {Prefs} = require("prefs");
+
+ // Do not ask to opt-in if user found setting
+ if (!Prefs.correctTyposAsked)
+ {
+ let onPrefChange = function(name)
+ {
+ if (name == "correctTypos")
+ {
+ Prefs.correctTyposAsked = true;
+ Prefs.removeListener(onPrefChange);
+ }
+ }
+
+ Prefs.addListener(onPrefChange);
+ }
+
+ exports.isTypoCorrectionEnabled = function(window, prefix, domain, suffix)
+ {
+ if (!Prefs.correctTyposAsked && !Prefs.correctTypos)
+ {
+ let {Utils} = require("utils");
+ let message = Utils.getString("typo_optin_message").replace(/\?1\?/, domain);
+ let yes = Utils.getString("typo_optin_yes");
+ let no = Utils.getString("typo_optin_no");
+ let buttons = [
+ {
+ label: yes,
+ accessKey: null,
+ callback: function()
+ {
+ // Yes: Enable typo correction
+ Prefs.correctTypos = true;
+ exports.loadURI(window, prefix + domain + suffix);
+ Prefs.correctTyposAsked = true;
+ }
+ },
+ {
+ label: no,
+ accessKey: null,
+ callback: function()
+ {
+ // No: Do nothing
+ Prefs.correctTyposAsked = true;
+ }
+ }
+ ];
+ // We need to have persistence being set to 1 due to redirect which happens afterwards
+ exports.openInfobar(window, "adblockplus-infobar-correct-typos-ask", message, buttons, 1);
+ }
+
+ return Prefs.correctTypos;
+ };
+
+ break;
+ }
+}
+
switch (application)
{
case "firefox":
@@ -66,11 +137,10 @@
{
infobar.removeNotification(notification);
}
-
notification = infobar.appendNotification(
message,
id,
- require("info").addonRoot + "icon64.png",
+ "chrome://" + addonName + "/skin/icon16.png",
infobar.PRIORITY_INFO_HIGH,
buttons
);
@@ -156,7 +226,7 @@
notification = infobar.appendNotification(
message,
id,
- require("info").addonRoot + "icon64.png",
+ "chrome://" + addonName + "/skin/icon16.png",
infobar.PRIORITY_INFO_HIGH,
buttons
);
@@ -213,7 +283,7 @@
notification = infobar.appendNotification(
message,
id,
- require("info").addonRoot + "icon64.png",
+ "chrome://" + addonName + "/skin/icon16.png",
infobar.PRIORITY_INFO_HIGH,
buttons
);
@@ -286,9 +356,7 @@
{
window.NativeWindow.doorhanger.show(message, id, buttons, window.BrowserApp.selectedTab.id,
{
- // No navigation is happening after doorhanger is shown
- // so persistence needs to be reduced by one
- persistence: persistence - 1
+ persistence: persistence
}
);
}
« no previous file with comments | « lib/main.js ('k') | lib/typoCollector.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld