Left: | ||
Right: |
OLD | NEW |
---|---|
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"); | |
13 | 14 |
14 let {TimeLine} = require("timeline"); | 15 let {TimeLine} = require("timeline"); |
15 | 16 |
16 TimeLine.enter("Adblock Plus startup"); | 17 TimeLine.enter("Adblock Plus startup"); |
17 let {Prefs} = require("prefs"); | 18 let {Prefs} = require("prefs"); |
18 TimeLine.log("Done loading preferences"); | 19 TimeLine.log("Done loading preferences"); |
19 registerPublicAPI(); | 20 registerPublicAPI(); |
20 TimeLine.log("Done registering public API"); | 21 TimeLine.log("Done registering public API"); |
21 require("filterListener"); | 22 require("filterListener"); |
22 TimeLine.log("Done loading filter listener"); | 23 TimeLine.log("Done loading filter listener"); |
23 require("contentPolicy"); | 24 require("contentPolicy"); |
24 TimeLine.log("Done loading content policy"); | 25 TimeLine.log("Done loading content policy"); |
25 require("synchronizer"); | 26 require("synchronizer"); |
26 TimeLine.log("Done loading subscription synchronizer"); | 27 TimeLine.log("Done loading subscription synchronizer"); |
27 require("sync"); | 28 require("sync"); |
28 TimeLine.log("Done loading sync support"); | 29 TimeLine.log("Done loading sync support"); |
29 require("ui"); | 30 require("ui"); |
30 TimeLine.log("Done loading UI integration code"); | 31 TimeLine.log("Done loading UI integration code"); |
31 if (!Prefs.correctTyposAsked || (Prefs.correctTyposAsked && Prefs.correctTypos)) | 32 (function() |
Wladimir Palant
2012/11/19 07:30:02
Please move that entire logic into a separate typo
| |
32 { | 33 { |
33 require("typoFixer"); | 34 let urlfixerID = "{0fa2149e-bb2c-4ac2-a8d3-479599819475}"; |
34 TimeLine.log("Done loading typo correction"); | 35 let isTypoCorrectionEnabled; |
35 } | 36 let typoFixerLoaded = false; |
36 else | 37 |
37 { | 38 function enableTypoCorrection() |
38 let onPrefChange = function(name) | |
39 { | 39 { |
40 if (name == "correctTypos") | 40 if (isTypoCorrectionEnabled) |
41 return; | |
42 | |
43 if (typoFixerLoaded) | |
44 { | |
45 require("typoFixer").attachWindowObserver(); | |
46 } | |
47 else | |
41 { | 48 { |
42 require("typoFixer"); | 49 require("typoFixer"); |
43 Prefs.removeListener(onPrefChange); | 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 } | |
44 } | 102 } |
45 } | 103 } |
46 | 104 |
47 Prefs.addListener(onPrefChange); | 105 let addonListener = { |
48 } | 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"); | |
49 TimeLine.leave("Started up"); | 137 TimeLine.leave("Started up"); |
50 | 138 |
51 function registerPublicAPI() | 139 function registerPublicAPI() |
52 { | 140 { |
53 let {addonRoot} = require("info"); | 141 let {addonRoot} = require("info"); |
54 | 142 |
55 let uri = Services.io.newURI(addonRoot + "lib/Public.jsm", null, null); | 143 let uri = Services.io.newURI(addonRoot + "lib/Public.jsm", null, null); |
56 if (uri instanceof Ci.nsIMutable) | 144 if (uri instanceof Ci.nsIMutable) |
57 uri.mutable = false; | 145 uri.mutable = false; |
58 | 146 |
(...skipping 12 matching lines...) Expand all Loading... | |
71 | 159 |
72 let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); | 160 let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); |
73 registrar.registerFactory(classID, "Adblock Plus public API URL", contractID, factory); | 161 registrar.registerFactory(classID, "Adblock Plus public API URL", contractID, factory); |
74 | 162 |
75 onShutdown.add(function() | 163 onShutdown.add(function() |
76 { | 164 { |
77 registrar.unregisterFactory(classID, factory); | 165 registrar.unregisterFactory(classID, factory); |
78 Cu.unload(uri.spec); | 166 Cu.unload(uri.spec); |
79 }); | 167 }); |
80 } | 168 } |
OLD | NEW |