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

Delta Between Two Patch Sets: background.js

Issue 5693109165883392: Issue 2040 - Replaced localStorage with chrome.storage.local (Closed)
Left Patch Set: Re-introduces defaults mapping, added Prefs.onLoading event, made currentVersion a pref Created March 20, 2015, 1:19 p.m.
Right Patch Set: Fixed typo in comment Created April 13, 2015, 10:30 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 | « no previous file | chrome/ext/background.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 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;
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 = (function()
64 {
65 var info = require("info");
66 if (info.platform == "chromium" && "notifications" in chrome)
67 {
68 if (navigator.platform.indexOf("Linux") == -1)
69 return true;
70 if (Services.vc.compare(info.applicationVersion, "35") >= 0)
71 return true;
72 }
73 return false;
74 })();
75
61 var seenDataCorruption = false; 76 var seenDataCorruption = false;
62 var filterlistsReinitialized = false; 77 var filterlistsReinitialized = false;
63 78
64 function init() 79 function init()
65 { 80 {
66 var filtersLoaded = false; 81 var filtersLoaded = false;
67 var prefsLoaded = false; 82 var prefsLoaded = false;
68 83
69 var onProgress = function() 84 var checkLoaded = function()
70 { 85 {
71 if (!filtersLoaded || !prefsLoaded) 86 if (!filtersLoaded || !prefsLoaded)
72 return; 87 return;
73 88
74 var info = require("info"); 89 var info = require("info");
75 var previousVersion = Prefs.currentVersion; 90 var previousVersion = Prefs.currentVersion;
76 91
77 // There are no filters stored so we need to reinitialize all filterlists 92 // There are no filters stored so we need to reinitialize all filterlists
78 if (!FilterStorage.firstRun && FilterStorage.subscriptions.length === 0) 93 if (!FilterStorage.firstRun && FilterStorage.subscriptions.length === 0)
79 { 94 {
80 filterlistsReinitialized = true; 95 filterlistsReinitialized = true;
81 previousVersion = null; 96 previousVersion = null;
82 } 97 }
83 98
84 if (previousVersion != info.addonVersion || FilterStorage.firstRun) 99 if (previousVersion != info.addonVersion || FilterStorage.firstRun)
85 { 100 {
86 seenDataCorruption = previousVersion && FilterStorage.firstRun; 101 seenDataCorruption = previousVersion && FilterStorage.firstRun;
87 Prefs.currentVersion = info.addonVersion; 102 Prefs.currentVersion = info.addonVersion;
88 addSubscription(previousVersion); 103 addSubscription(previousVersion);
89 } 104 }
90 105
91 // The "Hide placeholders" option has been removed from the UI in 1.8.8.1285 106 // The "Hide placeholders" option has been removed from the UI in 1.8.8.1285
92 // So we reset the option for users updating from older versions. 107 // So we reset the option for users updating from older versions.
93 if (previousVersion && Services.vc.compare(previousVersion, "1.8.8.1285") < 0) 108 if (previousVersion && Services.vc.compare(previousVersion, "1.8.8.1285") < 0)
94 Prefs.hidePlaceholders = true; 109 Prefs.hidePlaceholders = true;
95 110
96 // Chrome on Linux does not fully support chrome.notifications until version 35 111 if (canUseChromeNotifications)
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(); 112 initChromeNotifications();
102 initAntiAdblockNotification(); 113 initAntiAdblockNotification();
103 114
104 // Update browser actions and context menus when whitelisting might have 115 // Update browser actions and context menus when whitelisting might have
105 // changed. That is now when initally loading the filters and later when 116 // changed. That is now when initally loading the filters and later when
106 // importing backups or saving filter changes. 117 // importing backups or saving filter changes.
107 FilterNotifier.addListener(function(action) 118 FilterNotifier.addListener(function(action)
108 { 119 {
109 if (action == "load" || action == "save") 120 if (action == "load" || action == "save")
110 refreshIconAndContextMenuForAllPages(); 121 refreshIconAndContextMenuForAllPages();
111 }); 122 });
112 refreshIconAndContextMenuForAllPages(); 123 refreshIconAndContextMenuForAllPages();
113 }; 124 };
114 125
115 var onFilterAction = function(action) 126 var onFilterAction = function(action)
116 { 127 {
117 if (action == "load") 128 if (action == "load")
118 { 129 {
119 FilterNotifier.removeListener(onFilterAction); 130 FilterNotifier.removeListener(onFilterAction);
120 filtersLoaded = true; 131 filtersLoaded = true;
121 onProgress(); 132 checkLoaded();
122 } 133 }
123 }; 134 };
124 135
125 var onPrefsLoaded = function() 136 var onPrefsLoaded = function()
126 { 137 {
127 Prefs.onLoaded.removeListener(onPrefsLoaded); 138 Prefs.onLoaded.removeListener(onPrefsLoaded);
128 prefsLoaded = true; 139 prefsLoaded = true;
129 onProgress(); 140 checkLoaded();
130 }; 141 };
131 142
132 FilterNotifier.addListener(onFilterAction); 143 FilterNotifier.addListener(onFilterAction);
133 Prefs.onLoaded.addListener(onPrefsLoaded); 144 Prefs.onLoaded.addListener(onPrefsLoaded);
134 } 145 }
135 init(); 146 init();
136 147
137 // Special-case domains for which we cannot use style-based hiding rules. 148 // Special-case domains for which we cannot use style-based hiding rules.
138 // See http://crbug.com/68705. 149 // See http://crbug.com/68705.
139 var noStyleRulesHosts = ["mail.google.com", "mail.yahoo.com", "www.google.com"]; 150 var noStyleRulesHosts = ["mail.google.com", "mail.yahoo.com", "www.google.com"];
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 page.sendMessage({type: "clickhide-deactivate"}); 616 page.sendMessage({type: "clickhide-deactivate"});
606 refreshIconAndContextMenu(page); 617 refreshIconAndContextMenu(page);
607 }); 618 });
608 619
609 setTimeout(function() 620 setTimeout(function()
610 { 621 {
611 var notificationToShow = NotificationStorage.getNextToShow(); 622 var notificationToShow = NotificationStorage.getNextToShow();
612 if (notificationToShow) 623 if (notificationToShow)
613 showNotification(notificationToShow); 624 showNotification(notificationToShow);
614 }, 3 * 60 * 1000); 625 }, 3 * 60 * 1000);
LEFTRIGHT

Powered by Google App Engine
This is Rietveld