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

Side by Side Diff: new-options.js

Issue 29519669: Issue 5539 - Implement "Acceptable Ads notification" (Closed)
Patch Set: Created Aug. 18, 2017, 11:51 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 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/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 /* globals checkShareResource, getDocLink, i18nFormatDateTime, openSharePopup, 18 /* globals checkShareResource, getDocLink, i18nFormatDateTime, openSharePopup,
19 setLinks, E */ 19 setLinks, E */
20 20
21 "use strict"; 21 "use strict";
22 22
23 { 23 {
24 let subscriptionsMap = Object.create(null); 24 let subscriptionsMap = Object.create(null);
25 let filtersMap = Object.create(null); 25 let filtersMap = Object.create(null);
26 let collections = Object.create(null); 26 let collections = Object.create(null);
27 let acceptableAdsUrl = null; 27 let acceptableAdsUrl = null;
28 let acceptableAdsPrivacyUrl = null; 28 let acceptableAdsPrivacyUrl = null;
29 let isCustomFiltersLoaded = false; 29 let isCustomFiltersLoaded = false;
30 let isSubscriptionsLoaded = false;
30 let {getMessage} = ext.i18n; 31 let {getMessage} = ext.i18n;
31 let customFilters = []; 32 let customFilters = [];
32 let filterErrors = new Map([ 33 let filterErrors = new Map([
33 ["synchronize_invalid_url", 34 ["synchronize_invalid_url",
34 "options_filterList_lastDownload_invalidURL"], 35 "options_filterList_lastDownload_invalidURL"],
35 ["synchronize_connection_error", 36 ["synchronize_connection_error",
36 "options_filterList_lastDownload_connectionError"], 37 "options_filterList_lastDownload_connectionError"],
37 ["synchronize_invalid_data", 38 ["synchronize_invalid_data",
38 "options_filterList_lastDownload_invalidData"], 39 "options_filterList_lastDownload_invalidData"],
39 ["synchronize_checksum_mismatch", 40 ["synchronize_checksum_mismatch",
(...skipping 981 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 break; 1022 break;
1022 } 1023 }
1023 } 1024 }
1024 } 1025 }
1025 1026
1026 function isAcceptableAds(url) 1027 function isAcceptableAds(url)
1027 { 1028 {
1028 return url == acceptableAdsUrl || url == acceptableAdsPrivacyUrl; 1029 return url == acceptableAdsUrl || url == acceptableAdsPrivacyUrl;
1029 } 1030 }
1030 1031
1032 function isPrivacyAndAdsEnabled()
Thomas Greiner 2017/08/25 18:44:52 This function is a bit difficult to understand so
saroyanm 2017/08/27 16:25:28 Agree, thanks.
saroyanm 2017/09/14 21:56:14 Done.
1033 {
1034 let isAcceptableAds = subscriptionsMap[acceptableAdsUrl];
1035 isAcceptableAds = isAcceptableAds && isAcceptableAds.disabled == false;
1036 for (let url in subscriptionsMap)
1037 {
1038 let subscription = subscriptionsMap[url];
1039 if (subscription.recommended == "privacy")
1040 return subscription.disabled == false && isAcceptableAds;
1041 }
1042 }
1043
1031 function populateLists() 1044 function populateLists()
1032 { 1045 {
1033 subscriptionsMap = Object.create(null); 1046 subscriptionsMap = Object.create(null);
1034 filtersMap = Object.create(null); 1047 filtersMap = Object.create(null);
1035 1048
1036 // Empty collections and lists 1049 // Empty collections and lists
1037 for (let property in collections) 1050 for (let property in collections)
1038 collections[property].clearAll(); 1051 collections[property].clearAll();
1039 1052
1040 ext.backgroundPage.sendMessage({ 1053 ext.backgroundPage.sendMessage({
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 1096
1084 // Load user subscriptions 1097 // Load user subscriptions
1085 ext.backgroundPage.sendMessage({ 1098 ext.backgroundPage.sendMessage({
1086 type: "subscriptions.get", 1099 type: "subscriptions.get",
1087 downloadable: true 1100 downloadable: true
1088 }, 1101 },
1089 (subscriptions) => 1102 (subscriptions) =>
1090 { 1103 {
1091 for (let subscription of subscriptions) 1104 for (let subscription of subscriptions)
1092 onSubscriptionMessage("added", subscription); 1105 onSubscriptionMessage("added", subscription);
1106 isSubscriptionsLoaded = true;
1093 }); 1107 });
1094 }); 1108 });
1095 }); 1109 });
1096 } 1110 }
1097 1111
1098 function addWhitelistedDomain() 1112 function addWhitelistedDomain()
1099 { 1113 {
1100 let domain = E("whitelisting-textbox"); 1114 let domain = E("whitelisting-textbox");
1101 for (let whitelistItem of collections.whitelist.items) 1115 for (let whitelistItem of collections.whitelist.items)
1102 { 1116 {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 updateSubscription(subscription); 1200 updateSubscription(subscription);
1187 break; 1201 break;
1188 case "downloading": 1202 case "downloading":
1189 case "downloadStatus": 1203 case "downloadStatus":
1190 case "homepage": 1204 case "homepage":
1191 case "lastDownload": 1205 case "lastDownload":
1192 case "title": 1206 case "title":
1193 updateSubscription(subscription); 1207 updateSubscription(subscription);
1194 break; 1208 break;
1195 case "added": 1209 case "added":
1196 if (subscription.url in subscriptionsMap) 1210 let url = subscription.url;
1211 if (url in subscriptionsMap)
1197 updateSubscription(subscription); 1212 updateSubscription(subscription);
1198 else 1213 else
1199 addSubscription(subscription); 1214 addSubscription(subscription);
1200 1215
1201 if (isAcceptableAds(subscription.url)) 1216 if (isAcceptableAds(url))
1202 setAcceptableAds(); 1217 setAcceptableAds();
1203 1218
1204 if (subscription.url == acceptableAdsPrivacyUrl) 1219 if (url == acceptableAdsPrivacyUrl)
1205 { 1220 {
1206 if (!navigator.doNotTrack) 1221 if (!navigator.doNotTrack)
1207 setDntNotification(true); 1222 setDntNotification(true);
1208 } 1223 }
1209 1224
1225 if (url == acceptableAdsUrl || subscription.recommended == "privacy")
1226 {
1227 if (isSubscriptionsLoaded && isPrivacyAndAdsEnabled())
Thomas Greiner 2017/08/25 18:44:51 Why is checking for `isSubscriptionsLoaded` necess
saroyanm 2017/08/27 16:25:28 I did it in order not to show on each load of the
Thomas Greiner 2017/08/29 10:20:41 So it's a stopgap solution until we have the prefe
saroyanm 2017/09/14 21:56:14 Done.
1228 openDialog("tracking");
saroyanm 2017/08/19 00:00:40 In specs it says that "This is a one time message"
Thomas Greiner 2017/08/25 18:44:51 Yes. Probably best to prefix the preference name w
saroyanm 2017/08/27 16:25:28 Thanks, I'll have a look into this.
saroyanm 2017/09/14 21:56:14 Done.
1229 }
1230
1210 collections.filterLists.addItem(subscription); 1231 collections.filterLists.addItem(subscription);
1211 break; 1232 break;
1212 case "removed": 1233 case "removed":
1213 if (subscription.recommended) 1234 if (subscription.recommended)
1214 { 1235 {
1215 subscription.disabled = true; 1236 subscription.disabled = true;
1216 onSubscriptionMessage("disabled", subscription); 1237 onSubscriptionMessage("disabled", subscription);
1217 } 1238 }
1218 else if (isAcceptableAds(subscription.url)) 1239 else if (isAcceptableAds(subscription.url))
1219 { 1240 {
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1388 }); 1409 });
1389 ext.backgroundPage.sendMessage({ 1410 ext.backgroundPage.sendMessage({
1390 type: "subscriptions.listen", 1411 type: "subscriptions.listen",
1391 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 1412 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
1392 "title", "downloadStatus", "downloading"] 1413 "title", "downloadStatus", "downloading"]
1393 }); 1414 });
1394 1415
1395 window.addEventListener("DOMContentLoaded", onDOMLoaded, false); 1416 window.addEventListener("DOMContentLoaded", onDOMLoaded, false);
1396 window.addEventListener("hashchange", onHashChange, false); 1417 window.addEventListener("hashchange", onHashChange, false);
1397 } 1418 }
OLDNEW
« locale/en-US/new-options.json ('K') | « new-options.html ('k') | skin/new-options.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld