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

Side by Side Diff: options.js

Issue 29340571: Issue 3687 - Add experimental support for Safari content blockers (Closed)
Patch Set: Addressed Nits Created May 18, 2016, 11:30 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « options.html ('k') | popup.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 var addFilter = wrapper({type: "filters.add"}, "text"); 77 var addFilter = wrapper({type: "filters.add"}, "text");
78 var getFilters = wrapper({type: "filters.get"}, "subscriptionUrl"); 78 var getFilters = wrapper({type: "filters.get"}, "subscriptionUrl");
79 var removeFilter = wrapper({type: "filters.remove"}, "text"); 79 var removeFilter = wrapper({type: "filters.remove"}, "text");
80 80
81 var i18n = ext.i18n; 81 var i18n = ext.i18n;
82 var whitelistedDomainRegexp = /^@@\|\|([^\/:]+)\^\$document$/; 82 var whitelistedDomainRegexp = /^@@\|\|([^\/:]+)\^\$document$/;
83 var delayedSubscriptionSelection = null; 83 var delayedSubscriptionSelection = null;
84 84
85 var acceptableAdsUrl; 85 var acceptableAdsUrl;
86 86
87 // Loads options and sets UI elements accordingly 87 // Loads options from localStorage and sets UI elements accordingly
88 function loadOptions() 88 function loadOptions()
89 { 89 {
90 // Set page title to i18n version of "Adblock Plus Options" 90 // Set page title to i18n version of "Adblock Plus Options"
91 document.title = i18n.getMessage("options"); 91 document.title = i18n.getMessage("options");
92 92
93 // Set links 93 // Set links
94 getPref("subscriptions_exceptionsurl", function(url) 94 getPref("subscriptions_exceptionsurl", function(url)
95 { 95 {
96 acceptableAdsUrl = url; 96 acceptableAdsUrl = url;
97 $("#acceptableAdsLink").attr("href", acceptableAdsUrl); 97 $("#acceptableAdsLink").attr("href", acceptableAdsUrl);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 // Display jQuery UI elements 134 // Display jQuery UI elements
135 $("#tabs").tabs(); 135 $("#tabs").tabs();
136 $("button").button(); 136 $("button").button();
137 $(".refreshButton").button("option", "icons", {primary: "ui-icon-refresh"}); 137 $(".refreshButton").button("option", "icons", {primary: "ui-icon-refresh"});
138 $(".addButton").button("option", "icons", {primary: "ui-icon-plus"}); 138 $(".addButton").button("option", "icons", {primary: "ui-icon-plus"});
139 $(".removeButton").button("option", "icons", {primary: "ui-icon-minus"}); 139 $(".removeButton").button("option", "icons", {primary: "ui-icon-minus"});
140 140
141 // Popuplate option checkboxes 141 // Popuplate option checkboxes
142 initCheckbox("shouldShowBlockElementMenu"); 142 initCheckbox("shouldShowBlockElementMenu");
143 initCheckbox("show_devtools_panel"); 143 initCheckbox("show_devtools_panel");
144 initCheckbox("shouldShowNotifications", { 144 initCheckbox("shouldShowNotifications", "notifications_ignoredcategories");
145 key: "notifications_ignoredcategories", 145 initCheckbox("safariContentBlocker");
146 get: function(ignoredcategories)
147 {
148 return ignoredcategories.indexOf("*") == -1;
149 }
150 });
151 146
152 getInfo("features", function(features) 147 getInfo("features", function(features)
153 { 148 {
154 if (!features.devToolsPanel) 149 if (!features.devToolsPanel)
155 document.getElementById("showDevtoolsPanelContainer").hidden = true; 150 document.getElementById("showDevtoolsPanelContainer").hidden = true;
151
152 // Only show the option for Safari content blocking API if the user is
153 // running Safari and both the legacy and content blocking APIs are
154 // available.
155 document.getElementById("safariContentBlockerContainer").hidden = !(
156 features.safariContentBlocker &&
157 typeof safari != "undefined" &&
158 "canLoad" in safari.self.tab &&
159 "onbeforeload" in Element.prototype
160 );
156 }); 161 });
157 getPref("notifications_showui", function(notifications_showui) 162 getPref("notifications_showui", function(notifications_showui)
158 { 163 {
159 if (!notifications_showui) 164 if (!notifications_showui)
160 document.getElementById("shouldShowNotificationsContainer").hidden = true; 165 document.getElementById("shouldShowNotificationsContainer").hidden = true;
161 }); 166 });
162 167
163 // Register listeners in the background message responder 168 // Register listeners in the background message responder
164 ext.backgroundPage.sendMessage({ 169 ext.backgroundPage.sendMessage({
165 type: "app.listen", 170 type: "app.listen",
166 filter: ["addSubscription", "focusSection"] 171 filter: ["addSubscription", "focusSection"]
167 }); 172 });
168 ext.backgroundPage.sendMessage( 173 ext.backgroundPage.sendMessage(
169 { 174 {
170 type: "filters.listen", 175 type: "filters.listen",
171 filter: ["added", "loaded", "removed"] 176 filter: ["added", "loaded", "removed"]
172 }); 177 });
173 ext.backgroundPage.sendMessage( 178 ext.backgroundPage.sendMessage(
174 { 179 {
175 type: "prefs.listen", 180 type: "prefs.listen",
176 filter: ["notifications_ignoredcategories", "notifications_showui", 181 filter: ["notifications_ignoredcategories", "notifications_showui",
177 "safari_contentblocker", "show_devtools_panel", 182 "safariContentBlocker", "show_devtools_panel",
178 "shouldShowBlockElementMenu"] 183 "shouldShowBlockElementMenu"]
179 }); 184 });
180 ext.backgroundPage.sendMessage( 185 ext.backgroundPage.sendMessage(
181 { 186 {
182 type: "subscriptions.listen", 187 type: "subscriptions.listen",
183 filter: ["added", "disabled", "homepage", "lastDownload", "removed", 188 filter: ["added", "disabled", "homepage", "lastDownload", "removed",
184 "title", "downloadStatus", "downloading"] 189 "title", "downloadStatus", "downloading"]
185 }); 190 });
186 191
187 // Load recommended subscriptions 192 // Load recommended subscriptions
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 getSubscriptions(false, true, function(subscriptions) 236 getSubscriptions(false, true, function(subscriptions)
232 { 237 {
233 clearListBox("userFiltersBox"); 238 clearListBox("userFiltersBox");
234 clearListBox("excludedDomainsBox"); 239 clearListBox("excludedDomainsBox");
235 240
236 for (var i = 0; i < subscriptions.length; i++) 241 for (var i = 0; i < subscriptions.length; i++)
237 convertSpecialSubscription(subscriptions[i]); 242 convertSpecialSubscription(subscriptions[i]);
238 }); 243 });
239 } 244 }
240 245
241 function initCheckbox(id, descriptor) 246 function initCheckbox(id, key)
242 { 247 {
248 key = key || id;
243 var checkbox = document.getElementById(id); 249 var checkbox = document.getElementById(id);
244 var key = descriptor && descriptor.key || id; 250
245 getPref(key, function(value) 251 getPref(key, function(value)
246 { 252 {
247 if (descriptor && descriptor.get) 253 onPrefMessage(key, value);
248 checkbox.checked = descriptor.get(value);
249 else
250 checkbox.checked = value;
251 }); 254 });
252 255
253 checkbox.addEventListener("click", function() 256 checkbox.addEventListener("click", function()
254 { 257 {
255 if (descriptor && descriptor.toggle)
256 checkbox.checked = descriptor.toggle();
257 togglePref(key); 258 togglePref(key);
258 }, false); 259 }, false);
259 } 260 }
260 261
261 function loadRecommendations() 262 function loadRecommendations()
262 { 263 {
263 fetch("subscriptions.xml") 264 fetch("subscriptions.xml")
264 .then(function(response) 265 .then(function(response)
265 { 266 {
266 return response.text(); 267 return response.text();
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 { 495 {
495 switch (key) 496 switch (key)
496 { 497 {
497 case "notifications_showui": 498 case "notifications_showui":
498 document.getElementById("shouldShowNotificationsContainer").hidden = !valu e; 499 document.getElementById("shouldShowNotificationsContainer").hidden = !valu e;
499 return; 500 return;
500 case "notifications_ignoredcategories": 501 case "notifications_ignoredcategories":
501 key = "shouldShowNotifications"; 502 key = "shouldShowNotifications";
502 value = value.indexOf("*") == -1; 503 value = value.indexOf("*") == -1;
503 break; 504 break;
505 case "safariContentBlocker":
506 var restartMessage = document.getElementById("restart-safari");
507 restartMessage.hidden = true;
508 // When the user has chosen to use the legacy APIs but Safari has disabled
509 // them we need to show a "Please restart Safari" message.
510 if (!value)
511 {
512 ext.backgroundPage.sendMessage({type: "safari.contentBlockingActive"},
513 function(contentBlockingActive)
514 {
515 if (contentBlockingActive)
516 restartMessage.hidden = false;
517 });
518 }
504 } 519 }
505
506 var checkbox = document.getElementById(key); 520 var checkbox = document.getElementById(key);
507 if (checkbox) 521 if (checkbox)
508 checkbox.checked = value; 522 checkbox.checked = value;
509 } 523 }
510 524
511 function onFilterMessage(action, filter) 525 function onFilterMessage(action, filter)
512 { 526 {
513 switch (action) 527 switch (action)
514 { 528 {
515 case "loaded": 529 case "loaded":
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 onFilterMessage(message.action, message.args[0]); 762 onFilterMessage(message.action, message.args[0]);
749 break; 763 break;
750 case "prefs.respond": 764 case "prefs.respond":
751 onPrefMessage(message.action, message.args[0]); 765 onPrefMessage(message.action, message.args[0]);
752 break; 766 break;
753 case "subscriptions.respond": 767 case "subscriptions.respond":
754 onSubscriptionMessage(message.action, message.args[0]); 768 onSubscriptionMessage(message.action, message.args[0]);
755 break; 769 break;
756 } 770 }
757 }); 771 });
OLDNEW
« no previous file with comments | « options.html ('k') | popup.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld