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

Delta Between Two Patch Sets: lib/typoBootstrap.js

Issue 8788183: Detect and handle the case of our own typo correction extension being installed in parallel (Closed)
Left Patch Set: Created Nov. 19, 2012, 1:24 p.m.
Right Patch Set: Created Nov. 20, 2012, 11:38 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « lib/main.js ('k') | lib/typoFixer.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This Source Code is subject to the terms of the Mozilla Public License 2 * This file is part of the Adblock Plus,
3 * version 2.0 (the "License"). You can obtain a copy of the License at 3 * Copyright (C) 2006-2012 Eyeo GmbH
4 * http://mozilla.org/MPL/2.0/. 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
5 */ 16 */
6 17
7 /** 18 /**
8 * @fileOverview Adds typo correction feature 19 * @fileOverview Adds typo correction feature
9 */ 20 */
10 21
11 Cu.import("resource://gre/modules/AddonManager.jsm"); 22 Cu.import("resource://gre/modules/AddonManager.jsm");
12 23
13 let {TimeLine} = require("timeline");
14 let {Prefs} = require("prefs"); 24 let {Prefs} = require("prefs");
15 TimeLine.log("Done loading preferences"); 25 let urlfixerID = "{0fa2149e-bb2c-4ac2-a8d3-479599819475}";
26 let addonListener = null;
16 27
17 Cu.reportError("init"); 28 function init()
18 let urlfixerID = "{0fa2149e-bb2c-4ac2-a8d3-479599819475}";
19 let isTypoCorrectionEnabled = false;
20
21 function enableTypoCorrection()
22 { 29 {
23 Cu.reportError("enable"); 30 if (!Prefs.correctTyposAsked || (Prefs.correctTyposAsked && Prefs.correctTypos ))
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 { 31 {
47 checkAndEnable(addon && !addon.userDisabled); 32 AddonManager.getAddonByID(urlfixerID, function(addon)
48 }); 33 {
49 } 34 startTypoCorrection(addon && addon.isActive);
50 35 });
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 } 36 }
62 else 37 else
63 { 38 {
64 if (!Prefs.correctTyposAsked || (Prefs.correctTyposAsked && Prefs.correctTyp os)) 39 let onPrefChange = function(name)
65 { 40 {
66 Cu.reportError("feature enabled"); 41 if (name == "correctTypos" && Prefs[name])
67 enableTypoCorrection();
68 }
69 else if (!isTypoCorrectionEnabled)
70 {
71 Cu.reportError("feature disabled");
72 function onPrefChange(name)
73 { 42 {
74 if (name == "correctTypos") 43 init();
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); 44 Prefs.removeListener(onPrefChange);
176 } 45 }
177 } 46 }
178 47
179 Prefs.addListener(onPrefChange); 48 Prefs.addListener(onPrefChange);
180 } 49 }
181 } 50 }
182 51
183 function checkAddonStatusAndEnable(isInstalledAndEnabled) 52 function startTypoCorrection(isInstalledAndEnabled)
184 { 53 {
185 if (isInstalledAndEnabled) 54 if (isInstalledAndEnabled)
186 disableTypoCorrection(); 55 require("typoFixer").detachWindowObserver();
187 else 56 else
188 enableTypoCorrection(); 57 require("typoFixer").attachWindowObserver();
58
59 if (!addonListener)
60 {
61 addonListener = {
62 onEnabling: function(addon, needsRestart)
63 {
64 if (addon.id == urlfixerID)
65 startTypoCorrection(true);
66 },
67 onDisabled: function(addon)
68 {
69 if (addon.id == urlfixerID)
70 startTypoCorrection(false);
71 },
72 onInstalling: function(addon, needsRestart)
73 {
74 if (addon.id == urlfixerID)
75 startTypoCorrection(true);
76 },
77 onUninstalled: function(addon)
78 {
79 if (addon.id == urlfixerID)
80 startTypoCorrection(false);
81 }
82 }
83
84 AddonManager.addAddonListener(addonListener);
85 onShutdown.add(function() AddonManager.removeAddonListener(addonListener));
86 }
189 } 87 }
190 88
191 checkAndEnable(); 89 init();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld