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

Delta Between Two Patch Sets: background.js

Issue 5251132066627584: Issue 1488 - Add pre-configurable preference to suppress first run page (Closed)
Left Patch Set: Created March 19, 2015, 2:24 p.m.
Right Patch Set: Rebased and renamed onProgress() to checkLoaded() Created April 8, 2015, 3:09 p.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 | « no previous file | chrome/managed-storage-schema.json » ('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 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 29 matching lines...) Expand all
40 this.isThirdParty = isThirdParty; 40 this.isThirdParty = isThirdParty;
41 this.extractHostFromFrame = extractHostFromFrame; 41 this.extractHostFromFrame = extractHostFromFrame;
42 } 42 }
43 with(require("icon")) 43 with(require("icon"))
44 { 44 {
45 this.updateIcon = updateIcon; 45 this.updateIcon = updateIcon;
46 this.startIconAnimation = startIconAnimation; 46 this.startIconAnimation = startIconAnimation;
47 this.stopIconAnimation = stopIconAnimation; 47 this.stopIconAnimation = stopIconAnimation;
48 } 48 }
49 var FilterStorage = require("filterStorage").FilterStorage; 49 var FilterStorage = require("filterStorage").FilterStorage;
50 var filterNotifier = require("filterNotifier").FilterNotifier; 50 var FilterNotifier = require("filterNotifier").FilterNotifier;
kzar 2015/03/19 15:20:37 Shouldn't this be `FilterNotifier`?
Sebastian Noack 2015/03/20 13:26:12 No, the module is still called "filterNotifier".
kzar 2015/03/20 14:47:44 I meant the variable name.
Sebastian Noack 2015/03/20 15:40:55 I see ,you are right. Surprisingly, it still worke
51 var ElemHide = require("elemHide").ElemHide; 51 var ElemHide = require("elemHide").ElemHide;
52 var defaultMatcher = require("matcher").defaultMatcher; 52 var defaultMatcher = require("matcher").defaultMatcher;
53 var Prefs = require("prefs").Prefs; 53 var Prefs = require("prefs").Prefs;
54 var Synchronizer = require("synchronizer").Synchronizer; 54 var Synchronizer = require("synchronizer").Synchronizer;
55 var Utils = require("utils").Utils; 55 var Utils = require("utils").Utils;
56 var NotificationStorage = require("notification").Notification; 56 var NotificationStorage = require("notification").Notification;
57 var initAntiAdblockNotification = require("antiadblockInit").initAntiAdblockNoti fication; 57 var initAntiAdblockNotification = require("antiadblockInit").initAntiAdblockNoti fication;
58 var parseFilters = require("filterValidation").parseFilters; 58 var parseFilters = require("filterValidation").parseFilters;
59 var composeFilters = require("filterComposer").composeFilters; 59 var composeFilters = require("filterComposer").composeFilters;
60 60
61 // Chrome on Linux does not fully support chrome.notifications until version 35
62 // https://code.google.com/p/chromium/issues/detail?id=291485
63 var canUseChromeNotifications = require("info").platform == "chromium"
64 && "notifications" in chrome
65 && (navigator.platform.indexOf("Linux") == -1 || parseInt(require("info").appl icationVersion, 10) > 34);
66
67 var seenDataCorruption = false; 61 var seenDataCorruption = false;
68 var filterlistsReinitialized = false; 62 var filterlistsReinitialized = false;
69 63
70 function init() 64 function init()
71 { 65 {
72 var previousVersion = null;
73
74 var filtersLoaded = false; 66 var filtersLoaded = false;
75 var prefsLoaded = false; 67 var prefsLoaded = false;
76 68
77 var onLoaded = function() 69 var checkLoaded = function()
78 { 70 {
79 var addonVersion = require("info").addonVersion; 71 if (!filtersLoaded || !prefsLoaded)
72 return;
73
74 var info = require("info");
75 var previousVersion = Prefs.currentVersion;
80 76
81 // There are no filters stored so we need to reinitialize all filterlists 77 // There are no filters stored so we need to reinitialize all filterlists
82 if (!FilterStorage.firstRun && FilterStorage.subscriptions.length === 0) 78 if (!FilterStorage.firstRun && FilterStorage.subscriptions.length === 0)
83 { 79 {
84 filterlistsReinitialized = true; 80 filterlistsReinitialized = true;
85 previousVersion = null; 81 previousVersion = null;
86 } 82 }
87 83
88 if (previousVersion != addonVersion || FilterStorage.firstRun) 84 if (previousVersion != info.addonVersion || FilterStorage.firstRun)
89 { 85 {
90 seenDataCorruption = previousVersion && FilterStorage.firstRun; 86 seenDataCorruption = previousVersion && FilterStorage.firstRun;
91 ext.storage.set("currentVersion", addonVersion); 87 Prefs.currentVersion = info.addonVersion;
Wladimir Palant 2015/03/19 16:57:04 Prefs.currentVersion = addonVersion?
Sebastian Noack 2015/03/20 13:26:12 currentVersion isn't a preference, but I agree we
92 addSubscription(previousVersion); 88 addSubscription(previousVersion);
93 } 89 }
94 90
95 // The "Hide placeholders" option has been removed from the UI in 1.8.8.1285 91 // The "Hide placeholders" option has been removed from the UI in 1.8.8.1285
96 // So we reset the option for users updating from older versions. 92 // So we reset the option for users updating from older versions.
97 if (previousVersion && Services.vc.compare(previousVersion, "1.8.8.1285") < 0) 93 if (previousVersion && Services.vc.compare(previousVersion, "1.8.8.1285") < 0)
98 Prefs.hidePlaceholders = true; 94 Prefs.hidePlaceholders = true;
99 95
100 if (canUseChromeNotifications) 96 // Chrome on Linux does not fully support chrome.notifications until version 35
97 // https://code.google.com/p/chromium/issues/detail?id=291485
98 if (info.platform == "chromium" && "notifications" in chrome &&
99 (navigator.platform.indexOf("Linux") == -1 ||
100 Services.vc.compare(info.applicationVersion, "35") >= 0))
101 initChromeNotifications(); 101 initChromeNotifications();
102 initAntiAdblockNotification(); 102 initAntiAdblockNotification();
103 103
104 // Update browser actions and context menus when whitelisting might have cha nged, 104 // Update browser actions and context menus when whitelisting might have
105 // now when initally loading the filters, or later when saving filter chang es. 105 // changed. That is now when initally loading the filters and later when
kzar 2015/03/19 15:20:37 nit: The second line of this comment doesn't read
Sebastian Noack 2015/03/20 13:26:12 I had to rephrase it anyway while addressing Wladi
106 // importing backups or saving filter changes.
106 FilterNotifier.addListener(function(action) 107 FilterNotifier.addListener(function(action)
107 { 108 {
108 if (action == "save") 109 if (action == "load" || action == "save")
Wladimir Palant 2015/03/19 16:57:04 Please check for action == "load" as well here. Wh
Sebastian Noack 2015/03/20 13:26:12 Done.
109 refreshIconAndContextMenuForAllPages(); 110 refreshIconAndContextMenuForAllPages();
110 }); 111 });
111 refreshIconAndContextMenuForAllPages(); 112 refreshIconAndContextMenuForAllPages();
112 }; 113 };
113 114
114 var onFilterAction = function(action) 115 var onFilterAction = function(action)
115 { 116 {
116 if (action == "load") 117 if (action == "load")
117 { 118 {
119 FilterNotifier.removeListener(onFilterAction);
118 filtersLoaded = true; 120 filtersLoaded = true;
119 if (prefsLoaded) 121 checkLoaded();
Wladimir Palant 2015/03/19 16:57:04 This makes the condition you are checking for (and
Sebastian Noack 2015/03/20 13:26:12 The reason I didn't put it into onLoading in the f
120 onLoaded();
121
122 FilterNotifier.removeListener(onFilterAction);
Wladimir Palant 2015/03/19 16:57:04 Please always clean up before you run complicated
Sebastian Noack 2015/03/20 13:26:12 Done.
123 } 122 }
124 }; 123 };
125 124
126 var onPrefsLoaded = function() 125 var onPrefsLoaded = function()
127 { 126 {
128 // We have to wait for Prefs.onLoaded before retrieving "currentVersion".
129 // Otherwise it might not be migrated from localStorage yet.
130 ext.storage.get(["currentVersion"], function(items)
Wladimir Palant 2015/03/19 16:57:04 This shouldn't be necessary, you can simply use Pr
Sebastian Noack 2015/03/20 13:26:12 See above, currentVersion wasn't a pref yet. Now w
131 {
132 previousVersion = items.currentVersion;
133
134 prefsLoaded = true;
135 if (filtersLoaded)
136 onLoaded();
137 });
138
139 Prefs.onLoaded.removeListener(onPrefsLoaded); 127 Prefs.onLoaded.removeListener(onPrefsLoaded);
128 prefsLoaded = true;
129 checkLoaded();
140 }; 130 };
141 131
142 FilterNotifier.addListener(onFilterAction); 132 FilterNotifier.addListener(onFilterAction);
143 Prefs.onLoaded.addListener(onPrefsLoaded); 133 Prefs.onLoaded.addListener(onPrefsLoaded);
144 } 134 }
145 init(); 135 init();
146 136
147 // Special-case domains for which we cannot use style-based hiding rules. 137 // Special-case domains for which we cannot use style-based hiding rules.
148 // See http://crbug.com/68705. 138 // See http://crbug.com/68705.
149 var noStyleRulesHosts = ["mail.google.com", "mail.yahoo.com", "www.google.com"]; 139 var noStyleRulesHosts = ["mail.google.com", "mail.yahoo.com", "www.google.com"];
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 page.sendMessage({type: "clickhide-deactivate"}); 606 page.sendMessage({type: "clickhide-deactivate"});
617 refreshIconAndContextMenu(page); 607 refreshIconAndContextMenu(page);
618 }); 608 });
619 609
620 setTimeout(function() 610 setTimeout(function()
621 { 611 {
622 var notificationToShow = NotificationStorage.getNextToShow(); 612 var notificationToShow = NotificationStorage.getNextToShow();
623 if (notificationToShow) 613 if (notificationToShow)
624 showNotification(notificationToShow); 614 showNotification(notificationToShow);
625 }, 3 * 60 * 1000); 615 }, 3 * 60 * 1000);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld