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

Unified Diff: lib/typoBootstrap.js

Issue 8788183: Detect and handle the case of our own typo correction extension being installed in parallel (Closed)
Patch Set: Created Nov. 20, 2012, 10:27 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/typoFixer.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/typoBootstrap.js
===================================================================
new file mode 100644
--- /dev/null
+++ b/lib/typoBootstrap.js
@@ -0,0 +1,87 @@
+/*
+ * This Source Code is subject to the terms of the Mozilla Public License
+ * version 2.0 (the "License"). You can obtain a copy of the License at
+ * http://mozilla.org/MPL/2.0/.
+ */
+
+/**
+ * @fileOverview Adds typo correction feature
+ */
+
+Cu.import("resource://gre/modules/AddonManager.jsm");
+
+let {Prefs} = require("prefs");
+let urlfixerID = "{0fa2149e-bb2c-4ac2-a8d3-479599819475}";
+let addonListener = null;
+
+function init()
+{
+ if (!Prefs.correctTyposAsked || (Prefs.correctTyposAsked && Prefs.correctTypos))
+ {
+ AddonManager.getAddonByID(urlfixerID, function(addon)
+ {
+ startTypoCorrection(addon && addon.isActive);
+ });
+ }
+ else
+ {
+ let onPrefChange = function(name)
+ {
+ if (name == "correctTypos" && Prefs[name])
+ {
+ init();
+ Prefs.removeListener(onPrefChange);
+ }
+ }
+
+ Prefs.addListener(onPrefChange);
+ }
+}
+
+function cleanup()
+{
+ if (addonListener)
+ {
+ AddonManager.removeAddonListener(addonListener);
+ addonListener = null;
+ }
+}
+onShutdown.add(cleanup);
Wladimir Palant 2012/11/20 11:13:30 Seriously, please look around at how this is done
+
+function startTypoCorrection(isInstalledAndEnabled)
+{
+ if (isInstalledAndEnabled)
+ require("typoFixer").detachWindowObserver();
+ else
+ require("typoFixer").attachWindowObserver();
+
+ if (!addonListener)
+ {
+ addonListener = {
+ onEnabling: function(addon, needsRestart)
+ {
+ if (addon.id == urlfixerID)
+ startTypoCorrection(true);
+ },
+ onDisabled: function(addon)
+ {
+ if (addon.id == urlfixerID)
+ startTypoCorrection(false);
+ },
+ onInstalling: function(addon, needsRestart)
+ {
+ if (addon.id == urlfixerID)
+ startTypoCorrection(true);
+ },
+ onUninstalled: function(addon)
+ {
+ if (addon.id == urlfixerID)
+ startTypoCorrection(false);
+ }
+ }
+
+ AddonManager.addAddonListener(addonListener);
+ }
+}
+
+init();
« no previous file with comments | « lib/main.js ('k') | lib/typoFixer.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld