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. 19, 2012, 1:24 p.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/main.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 {TimeLine} = require("timeline");
14 let {Prefs} = require("prefs");
15 TimeLine.log("Done loading preferences");
16
17 Cu.reportError("init");
18 let urlfixerID = "{0fa2149e-bb2c-4ac2-a8d3-479599819475}";
19 let isTypoCorrectionEnabled = false;
20
21 function enableTypoCorrection()
22 {
23 Cu.reportError("enable");
24 if (isTypoCorrectionEnabled)
25 return;
26
27 require("typoFixer").attachWindowObserver();
28 isTypoCorrectionEnabled = true;
29 }
30
31 function disableTypoCorrection()
32 {
33 Cu.reportError("disable");
34 if (!isTypoCorrectionEnabled)
35 return;
36
37 require("typoFixer").detachWindowObserver();
38 isTypoCorrectionEnabled = false;
39 }
40
41 /*
Wladimir Palant 2012/11/19 13:49:45 Debug code?
42 function checkAddonStatusAndEnable()
43 {
44 Cu.reportError("check addon status and enable");
45 AddonManager.getAddonByID(urlfixerID, function(addon)
46 {
47 checkAndEnable(addon && !addon.userDisabled);
48 });
49 }
50
51 function checkAndEnable(isInstalledAndEnabled)
52 {
53 Cu.reportError("check and enable");
54 //Cu.reportError(isInstalledAndEnabled);
55 Cu.reportError(Prefs.correctTyposAsked);
56 Cu.reportError(Prefs.correctTypos);
57 Cu.reportError(isTypoCorrectionEnabled);
58 if (isInstalledAndEnabled)
59 {
60 disableTypoCorrection();
61 }
62 else
63 {
64 if (!Prefs.correctTyposAsked || (Prefs.correctTyposAsked && Prefs.correctTyp os))
65 {
66 Cu.reportError("feature enabled");
67 enableTypoCorrection();
68 }
69 else if (!isTypoCorrectionEnabled)
70 {
71 Cu.reportError("feature disabled");
72 function onPrefChange(name)
73 {
74 if (name == "correctTypos")
75 {
76 checkAddonStatusAndEnable();
77 Prefs.removeListener(onPrefChange);
78 }
79 }
80
81 Prefs.addListener(onPrefChange);
82 }
83 }
84 }
85
86 let addonListener = {
87 onEnabling: function(addon, needsRestart)
88 {
89 if (addon.id == urlfixerID)
90 checkAndEnable(true);
91 },
92 onDisabled: function(addon)
93 {
94 if (addon.id == urlfixerID)
95 checkAndEnable(false);
96 },
97 onInstalling: function(addon, needsRestart)
98 {
99 if (addon.id == urlfixerID)
100 checkAndEnable(true);
101 },
102 onUninstalled: function(addon)
103 {
104 if (addon.id == urlfixerID)
105 checkAndEnable(false);
106 }
107 }
108 AddonManager.addAddonListener(addonListener);
109
110 checkAddonStatusAndEnable();
111 */
112
113 let addonListener = null;
114 function checkAndEnable(isInstalledAndEnabled)
115 {
116 if (!Prefs.correctTyposAsked || (Prefs.correctTyposAsked && Prefs.correctTypos ))
117 {
118 Cu.reportError("feature enabled");
119 Cu.reportError("check addon status and enable");
120
121 if (typeof isInstalledAndEnabled == "undefined")
122 {
123 // must not be executed for addonListener because it needs to run synchron ously
124 AddonManager.getAddonByID(urlfixerID, function(addon)
125 {
126 if (addon && !addon.userDisabled)
127 disableTypoCorrection();
128 else
129 enableTypoCorrection();
130 });
131 }
132 else
133 {
134 if (isInstalledAndEnabled)
135 disableTypoCorrection();
136 else
137 enableTypoCorrection();
138 }
139
140 if (!addonListener)
141 {
142 addonListener = {
143 onEnabling: function(addon, needsRestart)
144 {
145 if (addon.id == urlfixerID)
146 checkAndEnable(true);
147 },
148 onDisabled: function(addon)
149 {
150 if (addon.id == urlfixerID)
151 checkAndEnable(false);
152 },
153 onInstalling: function(addon, needsRestart)
154 {
155 if (addon.id == urlfixerID)
156 checkAndEnable(true);
157 },
158 onUninstalled: function(addon)
159 {
160 if (addon.id == urlfixerID)
161 checkAndEnable(false);
162 }
163 }
164 AddonManager.addAddonListener(addonListener);
165 }
166 }
167 else if (!isTypoCorrectionEnabled)
168 {
169 Cu.reportError("feature disabled");
170 function onPrefChange(name)
171 {
172 if (name == "correctTypos")
173 {
174 checkAndEnable();
175 Prefs.removeListener(onPrefChange);
176 }
177 }
178
179 Prefs.addListener(onPrefChange);
180 }
181 }
182
183 function checkAddonStatusAndEnable(isInstalledAndEnabled)
184 {
185 if (isInstalledAndEnabled)
186 disableTypoCorrection();
187 else
188 enableTypoCorrection();
189 }
190
191 checkAndEnable();
OLDNEW
« 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