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

Delta Between Two Patch Sets: lib/main.js

Issue 8788183: Detect and handle the case of our own typo correction extension being installed in parallel (Closed)
Left Patch Set: Created Nov. 15, 2012, 1:18 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 | « chrome/content/ui/subscriptions.xml ('k') | lib/typoBootstrap.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 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 3 * version 2.0 (the "License"). You can obtain a copy of the License at
4 * http://mozilla.org/MPL/2.0/. 4 * http://mozilla.org/MPL/2.0/.
5 */ 5 */
6 6
7 /** 7 /**
8 * @fileOverview Starts up Adblock Plus 8 * @fileOverview Starts up Adblock Plus
9 */ 9 */
10 10
11 Cu.import("resource://gre/modules/XPCOMUtils.jsm"); 11 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
12 Cu.import("resource://gre/modules/Services.jsm"); 12 Cu.import("resource://gre/modules/Services.jsm");
13 Cu.import("resource://gre/modules/AddonManager.jsm");
14 13
15 let {TimeLine} = require("timeline"); 14 let {TimeLine} = require("timeline");
16 15
17 TimeLine.enter("Adblock Plus startup"); 16 TimeLine.enter("Adblock Plus startup");
18 let {Prefs} = require("prefs");
19 TimeLine.log("Done loading preferences");
20 registerPublicAPI(); 17 registerPublicAPI();
21 TimeLine.log("Done registering public API"); 18 TimeLine.log("Done registering public API");
22 require("filterListener"); 19 require("filterListener");
23 TimeLine.log("Done loading filter listener"); 20 TimeLine.log("Done loading filter listener");
24 require("contentPolicy"); 21 require("contentPolicy");
25 TimeLine.log("Done loading content policy"); 22 TimeLine.log("Done loading content policy");
26 require("synchronizer"); 23 require("synchronizer");
27 TimeLine.log("Done loading subscription synchronizer"); 24 TimeLine.log("Done loading subscription synchronizer");
28 require("sync"); 25 require("sync");
29 TimeLine.log("Done loading sync support"); 26 TimeLine.log("Done loading sync support");
30 require("ui"); 27 require("ui");
31 TimeLine.log("Done loading UI integration code"); 28 TimeLine.log("Done loading UI integration code");
32 (function() 29 require("typoBootstrap");
Wladimir Palant 2012/11/19 07:30:02 Please move that entire logic into a separate typo
33 {
34 let urlfixerID = "{0fa2149e-bb2c-4ac2-a8d3-479599819475}";
35 let isTypoCorrectionEnabled;
36 let typoFixerLoaded = false;
37
38 function enableTypoCorrection()
39 {
40 if (isTypoCorrectionEnabled)
41 return;
42
43 if (typoFixerLoaded)
44 {
45 require("typoFixer").attachWindowObserver();
46 }
47 else
48 {
49 require("typoFixer");
50 typoFixerLoaded = true;
51 }
Wladimir Palant 2012/11/19 07:30:02 How about just doing require("typoFixer").attachWi
52
53 isTypoCorrectionEnabled = true;
54 }
55
56 function disableTypoCorrection()
57 {
58 if (!isTypoCorrectionEnabled)
59 return;
60
61 if (typoFixerLoaded)
62 {
63 require("typoFixer").detachWindowObserver();
64 }
Wladimir Palant 2012/11/19 07:30:02 How about just doing require("typoFixer").detachWi
65
66 isTypoCorrectionEnabled = false;
67 }
68
69 function checkAddonStatusAndEnable()
70 {
71 AddonManager.getAddonByID(urlfixerID, function(addon)
72 {
73 checkAndEnable(addon && !addon.userDisabled);
74 });
75 }
76
77 function checkAndEnable(isInstalledAndEnabled)
78 {
79 if (isInstalledAndEnabled)
80 {
81 disableTypoCorrection();
82 }
83 else
84 {
85 if (!Prefs.correctTyposAsked || (Prefs.correctTyposAsked && Prefs.correctT ypos))
Wladimir Palant 2012/11/19 07:30:02 This logic seems wrong. If typo corrections are di
86 {
87 enableTypoCorrection();
88 }
89 else if (!typoFixerLoaded)
90 {
91 function onPrefChange(name)
92 {
93 if (name == "correctTypos")
94 {
95 checkAddonStatusAndEnable();
96 Prefs.removeListener(onPrefChange);
97 }
98 }
99
100 Prefs.addListener(onPrefChange);
101 }
102 }
103 }
104
105 let addonListener = {
106 onEnabling: function(addon, needsRestart)
107 {
108 if (addon.id == urlfixerID)
109 checkAndEnable(true);
110 },
111 onDisabled: function(addon)
112 {
113 if (addon.id == urlfixerID)
114 checkAndEnable(false);
115 },
116 onInstalling: function(addon, needsRestart)
117 {
118 if (addon.id == urlfixerID)
119 checkAndEnable(true);
120 },
121 onUninstalled: function(addon)
122 {
123 if (addon.id == urlfixerID)
124 checkAndEnable(false);
125 },
126 onOperationCancelled: function(addon)
127 {
128 if (addon.id == urlfixerID)
129 checkAddonStatusAndEnable();
Wladimir Palant 2012/11/19 07:30:02 Please ignore this call - URL Fixer is restartless
130 }
131 }
132 AddonManager.addAddonListener(addonListener);
133
134 checkAddonStatusAndEnable();
135 })();
136 TimeLine.log("Done loading typo correction"); 30 TimeLine.log("Done loading typo correction");
137 TimeLine.leave("Started up"); 31 TimeLine.leave("Started up");
138 32
139 function registerPublicAPI() 33 function registerPublicAPI()
140 { 34 {
141 let {addonRoot} = require("info"); 35 let {addonRoot} = require("info");
142 36
143 let uri = Services.io.newURI(addonRoot + "lib/Public.jsm", null, null); 37 let uri = Services.io.newURI(addonRoot + "lib/Public.jsm", null, null);
144 if (uri instanceof Ci.nsIMutable) 38 if (uri instanceof Ci.nsIMutable)
145 uri.mutable = false; 39 uri.mutable = false;
(...skipping 13 matching lines...) Expand all
159 53
160 let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); 54 let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
161 registrar.registerFactory(classID, "Adblock Plus public API URL", contractID, factory); 55 registrar.registerFactory(classID, "Adblock Plus public API URL", contractID, factory);
162 56
163 onShutdown.add(function() 57 onShutdown.add(function()
164 { 58 {
165 registrar.unregisterFactory(classID, factory); 59 registrar.unregisterFactory(classID, factory);
166 Cu.unload(uri.spec); 60 Cu.unload(uri.spec);
167 }); 61 });
168 } 62 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld