LEFT | RIGHT |
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"); | |
16 | |
17 let urlfixerID = "{0fa2149e-bb2c-4ac2-a8d3-479599819475}"; | 25 let urlfixerID = "{0fa2149e-bb2c-4ac2-a8d3-479599819475}"; |
18 let addonListener = null; | 26 let addonListener = null; |
19 | 27 |
20 function init() | 28 function init() |
21 { | 29 { |
22 if (!Prefs.correctTyposAsked || (Prefs.correctTyposAsked && Prefs.correctTypos
)) | 30 if (!Prefs.correctTyposAsked || (Prefs.correctTyposAsked && Prefs.correctTypos
)) |
23 { | 31 { |
24 AddonManager.getAddonByID(urlfixerID, function(addon) | 32 AddonManager.getAddonByID(urlfixerID, function(addon) |
25 { | 33 { |
26 startTypoCorrection(addon && addon.isActive); | 34 startTypoCorrection(addon && addon.isActive); |
27 }); | 35 }); |
28 } | 36 } |
29 else | 37 else |
30 { | 38 { |
31 function onPrefChange(name) | 39 let onPrefChange = function(name) |
32 { | 40 { |
33 if (name == "correctTypos" && Prefs[name]) | 41 if (name == "correctTypos" && Prefs[name]) |
34 { | 42 { |
35 init(); | 43 init(); |
36 Prefs.removeListener(onPrefChange); | 44 Prefs.removeListener(onPrefChange); |
37 } | 45 } |
38 } | 46 } |
39 | 47 |
40 Prefs.addListener(onPrefChange); | 48 Prefs.addListener(onPrefChange); |
41 } | 49 } |
(...skipping 23 matching lines...) Expand all Loading... |
65 { | 73 { |
66 if (addon.id == urlfixerID) | 74 if (addon.id == urlfixerID) |
67 startTypoCorrection(true); | 75 startTypoCorrection(true); |
68 }, | 76 }, |
69 onUninstalled: function(addon) | 77 onUninstalled: function(addon) |
70 { | 78 { |
71 if (addon.id == urlfixerID) | 79 if (addon.id == urlfixerID) |
72 startTypoCorrection(false); | 80 startTypoCorrection(false); |
73 } | 81 } |
74 } | 82 } |
| 83 |
75 AddonManager.addAddonListener(addonListener); | 84 AddonManager.addAddonListener(addonListener); |
| 85 onShutdown.add(function() AddonManager.removeAddonListener(addonListener)); |
76 } | 86 } |
77 } | 87 } |
78 | 88 |
79 init(); | 89 init(); |
LEFT | RIGHT |