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

Side by Side 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, 9:53 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/typoAppIntegration.js ('k') | lib/typoFixer.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This Source Code is subject to the terms of the Mozilla Public License
3 * version 2.0 (the "License"). You can obtain a copy of the License at
4 * http://mozilla.org/MPL/2.0/.
5 */
6
7 /**
8 * @fileOverview Adds typo correction feature
9 */
10
11 Cu.import("resource://gre/modules/AddonManager.jsm");
12
13 let {Prefs} = require("prefs");
14 let urlfixerID = "{0fa2149e-bb2c-4ac2-a8d3-479599819475}";
15 let addonListener = null;
16
17 function init()
18 {
19 if (!Prefs.correctTyposAsked || (Prefs.correctTyposAsked && Prefs.correctTypos ))
20 {
21 AddonManager.getAddonByID(urlfixerID, function(addon)
22 {
23 startTypoCorrection(addon && addon.isActive);
24 });
25 }
26 else
27 {
28 let onPrefChange = function(name)
29 {
30 if (name == "correctTypos" && Prefs[name])
31 {
32 init();
33 Prefs.removeListener(onPrefChange);
34 }
35 }
36
37 Prefs.addListener(onPrefChange);
38 }
39 }
40
41 exports.cleanup = cleanup;
42 function cleanup()
43 {
44 if (addonListener)
45 {
46 AddonManager.removeAddonListener(addonListener);
Wladimir Palant 2012/11/20 10:21:14 Please use onShutdown.add() to add a shutdown hand
47 addonListener = null;
48 }
49 }
50
51 function startTypoCorrection(isInstalledAndEnabled)
52 {
53 if (isInstalledAndEnabled)
54 require("typoFixer").detachWindowObserver();
55 else
56 require("typoFixer").attachWindowObserver();
57
58 if (!addonListener)
59 {
60 addonListener = {
61 onEnabling: function(addon, needsRestart)
62 {
63 if (addon.id == urlfixerID)
64 startTypoCorrection(true);
65 },
66 onDisabled: function(addon)
67 {
68 if (addon.id == urlfixerID)
69 startTypoCorrection(false);
70 },
71 onInstalling: function(addon, needsRestart)
72 {
73 if (addon.id == urlfixerID)
74 startTypoCorrection(true);
75 },
76 onUninstalled: function(addon)
77 {
78 if (addon.id == urlfixerID)
79 startTypoCorrection(false);
80 }
81 }
82
83 AddonManager.addAddonListener(addonListener);
84 }
85 }
86
87 init();
OLDNEW
« no previous file with comments | « lib/typoAppIntegration.js ('k') | lib/typoFixer.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld