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

Unified Diff: lib/main.js

Issue 8788183: Detect and handle the case of our own typo correction extension being installed in parallel (Closed)
Patch Set: Created Nov. 15, 2012, 1:18 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 | « no previous file | lib/typoFixer.js » ('j') | lib/typoFixer.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/main.js
===================================================================
--- a/lib/main.js
+++ b/lib/main.js
@@ -10,6 +10,7 @@
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/AddonManager.jsm");
let {TimeLine} = require("timeline");
@@ -28,24 +29,111 @@
TimeLine.log("Done loading sync support");
require("ui");
TimeLine.log("Done loading UI integration code");
-if (!Prefs.correctTyposAsked || (Prefs.correctTyposAsked && Prefs.correctTypos))
+(function()
Wladimir Palant 2012/11/19 07:30:02 Please move that entire logic into a separate typo
{
- require("typoFixer");
- TimeLine.log("Done loading typo correction");
-}
-else
-{
- let onPrefChange = function(name)
+ let urlfixerID = "{0fa2149e-bb2c-4ac2-a8d3-479599819475}";
+ let isTypoCorrectionEnabled;
+ let typoFixerLoaded = false;
+
+ function enableTypoCorrection()
{
- if (name == "correctTypos")
+ if (isTypoCorrectionEnabled)
+ return;
+
+ if (typoFixerLoaded)
+ {
+ require("typoFixer").attachWindowObserver();
+ }
+ else
{
require("typoFixer");
- Prefs.removeListener(onPrefChange);
+ typoFixerLoaded = true;
+ }
Wladimir Palant 2012/11/19 07:30:02 How about just doing require("typoFixer").attachWi
+
+ isTypoCorrectionEnabled = true;
+ }
+
+ function disableTypoCorrection()
+ {
+ if (!isTypoCorrectionEnabled)
+ return;
+
+ if (typoFixerLoaded)
+ {
+ require("typoFixer").detachWindowObserver();
+ }
Wladimir Palant 2012/11/19 07:30:02 How about just doing require("typoFixer").detachWi
+
+ isTypoCorrectionEnabled = false;
+ }
+
+ function checkAddonStatusAndEnable()
+ {
+ AddonManager.getAddonByID(urlfixerID, function(addon)
+ {
+ checkAndEnable(addon && !addon.userDisabled);
+ });
+ }
+
+ function checkAndEnable(isInstalledAndEnabled)
+ {
+ if (isInstalledAndEnabled)
+ {
+ disableTypoCorrection();
+ }
+ else
+ {
+ if (!Prefs.correctTyposAsked || (Prefs.correctTyposAsked && Prefs.correctTypos))
Wladimir Palant 2012/11/19 07:30:02 This logic seems wrong. If typo corrections are di
+ {
+ enableTypoCorrection();
+ }
+ else if (!typoFixerLoaded)
+ {
+ function onPrefChange(name)
+ {
+ if (name == "correctTypos")
+ {
+ checkAddonStatusAndEnable();
+ Prefs.removeListener(onPrefChange);
+ }
+ }
+
+ Prefs.addListener(onPrefChange);
+ }
}
}
- Prefs.addListener(onPrefChange);
-}
+ let addonListener = {
+ onEnabling: function(addon, needsRestart)
+ {
+ if (addon.id == urlfixerID)
+ checkAndEnable(true);
+ },
+ onDisabled: function(addon)
+ {
+ if (addon.id == urlfixerID)
+ checkAndEnable(false);
+ },
+ onInstalling: function(addon, needsRestart)
+ {
+ if (addon.id == urlfixerID)
+ checkAndEnable(true);
+ },
+ onUninstalled: function(addon)
+ {
+ if (addon.id == urlfixerID)
+ checkAndEnable(false);
+ },
+ onOperationCancelled: function(addon)
+ {
+ if (addon.id == urlfixerID)
+ checkAddonStatusAndEnable();
Wladimir Palant 2012/11/19 07:30:02 Please ignore this call - URL Fixer is restartless
+ }
+ }
+ AddonManager.addAddonListener(addonListener);
+
+ checkAddonStatusAndEnable();
+})();
+TimeLine.log("Done loading typo correction");
TimeLine.leave("Started up");
function registerPublicAPI()
« no previous file with comments | « no previous file | lib/typoFixer.js » ('j') | lib/typoFixer.js » ('J')

Powered by Google App Engine
This is Rietveld