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

Unified Diff: options.js

Issue 29340571: Issue 3687 - Add experimental support for Safari content blockers (Closed)
Patch Set: Improve comment about strange API behaviour Created May 17, 2016, 3:53 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « options.html ('k') | popup.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: options.js
diff --git a/options.js b/options.js
index 3055baa441154856edac4c5b9f556150d27fbb6c..f0793806d8906ecaf41fa75fcdf6d4851663dc57 100644
--- a/options.js
+++ b/options.js
@@ -84,7 +84,7 @@ var delayedSubscriptionSelection = null;
var acceptableAdsUrl;
-// Loads options and sets UI elements accordingly
+// Loads options from localStorage and sets UI elements accordingly
function loadOptions()
{
// Set page title to i18n version of "Adblock Plus Options"
@@ -148,11 +148,38 @@ function loadOptions()
return ignoredcategories.indexOf("*") == -1;
}
});
+ initCheckbox("safariContentBlocker", {onChange: function(checkbox)
+ {
+ var restartMessage = document.getElementById("restart-safari");
+ restartMessage.hidden = true;
+
+ // When the user has chosen to use the legacy APIs but Safari has disabled
+ // them we need to show a "Please restart Safari" message.
+ if (!checkbox.checked)
+ {
+ ext.backgroundPage.sendMessage({type: "safari.contentBlockingActive"},
+ function (contentBlockingActive)
+ {
+ if (contentBlockingActive)
+ restartMessage.hidden = false;
+ });
+ }
+ }});
getInfo("features", function(features)
{
if (!features.devToolsPanel)
document.getElementById("showDevtoolsPanelContainer").hidden = true;
+
+ // Only show the option for Safari content blocking API if the user is
+ // running Safari and both the legacy and content blocking APIs are
+ // available.
+ document.getElementById("safariContentBlockerContainer").hidden = !(
+ features.safariContentBlocker &&
+ typeof safari != "undefined" &&
+ "canLoad" in safari.self.tab &&
+ "onbeforeload" in Element.prototype
+ );
});
getPref("notifications_showui", function(notifications_showui)
{
@@ -174,7 +201,7 @@ function loadOptions()
{
type: "prefs.listen",
filter: ["notifications_ignoredcategories", "notifications_showui",
- "safari_contentblocker", "show_devtools_panel",
+ "safariContentBlocker", "show_devtools_panel",
"shouldShowBlockElementMenu"]
});
ext.backgroundPage.sendMessage(
@@ -242,20 +269,27 @@ function initCheckbox(id, descriptor)
{
var checkbox = document.getElementById(id);
var key = descriptor && descriptor.key || id;
+ var onChange;
+ if (descriptor && descriptor.onChange)
+ onChange = descriptor.onChange.bind(undefined, checkbox);
getPref(key, function(value)
{
if (descriptor && descriptor.get)
checkbox.checked = descriptor.get(value);
else
checkbox.checked = value;
+
+ if (onChange)
+ onChange();
});
checkbox.addEventListener("click", function()
{
- if (descriptor && descriptor.toggle)
- checkbox.checked = descriptor.toggle();
togglePref(key);
}, false);
+
+ if (onChange)
+ checkbox.addEventListener("change", onChange);
}
function loadRecommendations()
@@ -505,7 +539,12 @@ function onPrefMessage(key, value)
var checkbox = document.getElementById(key);
if (checkbox)
+ {
checkbox.checked = value;
+ // Apparently modifying the checked attribute for a checkbox does not
+ // dispatch the change event automatically...
+ checkbox.dispatchEvent(new Event("change"));
+ }
}
function onFilterMessage(action, filter)
« no previous file with comments | « options.html ('k') | popup.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld