OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 var composeFilters = require("filterComposer").composeFilters; | 52 var composeFilters = require("filterComposer").composeFilters; |
53 var updateIcon = require("icon").updateIcon; | 53 var updateIcon = require("icon").updateIcon; |
54 var initNotifications = require("notificationHelper").initNotifications; | 54 var initNotifications = require("notificationHelper").initNotifications; |
55 var showNextNotificationForUrl = require("notificationHelper").showNextNotificat
ionForUrl; | 55 var showNextNotificationForUrl = require("notificationHelper").showNextNotificat
ionForUrl; |
56 | 56 |
57 var seenDataCorruption = false; | 57 var seenDataCorruption = false; |
58 var filterlistsReinitialized = false; | 58 var filterlistsReinitialized = false; |
59 | 59 |
60 function init() | 60 function init() |
61 { | 61 { |
62 var filtersLoaded = false; | 62 var filtersLoaded = new Promise(function(resolve) |
63 var prefsLoaded = false; | 63 { |
| 64 function onFilterAction(action) |
| 65 { |
| 66 if (action == "load") |
| 67 { |
| 68 FilterNotifier.removeListener(onFilterAction); |
| 69 resolve(); |
| 70 } |
| 71 } |
| 72 FilterNotifier.addListener(onFilterAction); |
| 73 }); |
64 | 74 |
65 var checkLoaded = function() | 75 function onLoaded() |
66 { | 76 { |
67 if (!filtersLoaded || !prefsLoaded) | |
68 return; | |
69 | |
70 var info = require("info"); | 77 var info = require("info"); |
71 var previousVersion = Prefs.currentVersion; | 78 var previousVersion = Prefs.currentVersion; |
72 | 79 |
73 // There are no filters stored so we need to reinitialize all filterlists | 80 // There are no filters stored so we need to reinitialize all filterlists |
74 if (!FilterStorage.firstRun && FilterStorage.subscriptions.length === 0) | 81 if (!FilterStorage.firstRun && FilterStorage.subscriptions.length === 0) |
75 { | 82 { |
76 filterlistsReinitialized = true; | 83 filterlistsReinitialized = true; |
77 previousVersion = null; | 84 previousVersion = null; |
78 } | 85 } |
79 | 86 |
80 if (previousVersion != info.addonVersion || FilterStorage.firstRun) | 87 if (previousVersion != info.addonVersion || FilterStorage.firstRun) |
81 { | 88 { |
82 seenDataCorruption = previousVersion && FilterStorage.firstRun; | 89 seenDataCorruption = previousVersion && FilterStorage.firstRun; |
83 Prefs.currentVersion = info.addonVersion; | 90 Prefs.currentVersion = info.addonVersion; |
84 addSubscription(previousVersion); | 91 addSubscription(previousVersion); |
85 } | 92 } |
86 | 93 |
87 initNotifications(); | 94 initNotifications(); |
88 | 95 |
89 // Update browser actions and context menus when whitelisting might have | 96 // Update browser actions and context menus when whitelisting might have |
90 // changed. That is now when initally loading the filters and later when | 97 // changed. That is now when initally loading the filters and later when |
91 // importing backups or saving filter changes. | 98 // importing backups or saving filter changes. |
92 FilterNotifier.addListener(function(action) | 99 FilterNotifier.addListener(function(action) |
93 { | 100 { |
94 if (action == "load" || action == "save") | 101 if (action == "load" || action == "save") |
95 refreshIconAndContextMenuForAllPages(); | 102 refreshIconAndContextMenuForAllPages(); |
96 }); | 103 }); |
97 refreshIconAndContextMenuForAllPages(); | 104 refreshIconAndContextMenuForAllPages(); |
98 }; | 105 } |
99 | 106 |
100 var onFilterAction = function(action) | 107 Promise.all([filtersLoaded, Prefs.isLoaded]).then(onLoaded); |
101 { | |
102 if (action == "load") | |
103 { | |
104 FilterNotifier.removeListener(onFilterAction); | |
105 filtersLoaded = true; | |
106 checkLoaded(); | |
107 } | |
108 }; | |
109 | |
110 var onPrefsLoaded = function() | |
111 { | |
112 Prefs.onLoaded.removeListener(onPrefsLoaded); | |
113 prefsLoaded = true; | |
114 checkLoaded(); | |
115 }; | |
116 | |
117 FilterNotifier.addListener(onFilterAction); | |
118 Prefs.onLoaded.addListener(onPrefsLoaded); | |
119 } | 108 } |
120 init(); | 109 init(); |
121 | 110 |
122 // Special-case domains for which we cannot use style-based hiding rules. | 111 // Special-case domains for which we cannot use style-based hiding rules. |
123 // See http://crbug.com/68705. | 112 // See http://crbug.com/68705. |
124 var noStyleRulesHosts = ["mail.google.com", "mail.yahoo.com", "www.google.com"]; | 113 var noStyleRulesHosts = ["mail.google.com", "mail.yahoo.com", "www.google.com"]; |
125 | 114 |
126 var htmlPages = new ext.PageMap(); | 115 var htmlPages = new ext.PageMap(); |
127 | 116 |
128 var contextMenuItem = { | 117 var contextMenuItem = { |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 } | 416 } |
428 }); | 417 }); |
429 | 418 |
430 // update icon when page changes location | 419 // update icon when page changes location |
431 ext.pages.onLoading.addListener(function(page) | 420 ext.pages.onLoading.addListener(function(page) |
432 { | 421 { |
433 page.sendMessage({type: "clickhide-deactivate"}); | 422 page.sendMessage({type: "clickhide-deactivate"}); |
434 refreshIconAndContextMenu(page); | 423 refreshIconAndContextMenu(page); |
435 showNextNotificationForUrl(page.url); | 424 showNextNotificationForUrl(page.url); |
436 }); | 425 }); |
OLD | NEW |