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: Addressed Nits Created May 18, 2016, 11:30 a.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..d102d14bb83889fbe61a52dde8d621db0f6653ca 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"
@@ -141,18 +141,23 @@ function loadOptions()
// Popuplate option checkboxes
initCheckbox("shouldShowBlockElementMenu");
initCheckbox("show_devtools_panel");
- initCheckbox("shouldShowNotifications", {
- key: "notifications_ignoredcategories",
- get: function(ignoredcategories)
- {
- return ignoredcategories.indexOf("*") == -1;
- }
- });
+ initCheckbox("shouldShowNotifications", "notifications_ignoredcategories");
+ initCheckbox("safariContentBlocker");
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 +179,7 @@ function loadOptions()
{
type: "prefs.listen",
filter: ["notifications_ignoredcategories", "notifications_showui",
- "safari_contentblocker", "show_devtools_panel",
+ "safariContentBlocker", "show_devtools_panel",
"shouldShowBlockElementMenu"]
});
ext.backgroundPage.sendMessage(
@@ -238,22 +243,18 @@ function reloadFilters()
});
}
-function initCheckbox(id, descriptor)
+function initCheckbox(id, key)
{
+ key = key || id;
var checkbox = document.getElementById(id);
- var key = descriptor && descriptor.key || id;
+
getPref(key, function(value)
{
- if (descriptor && descriptor.get)
- checkbox.checked = descriptor.get(value);
- else
- checkbox.checked = value;
+ onPrefMessage(key, value);
});
checkbox.addEventListener("click", function()
{
- if (descriptor && descriptor.toggle)
- checkbox.checked = descriptor.toggle();
togglePref(key);
}, false);
}
@@ -501,8 +502,21 @@ function onPrefMessage(key, value)
key = "shouldShowNotifications";
value = value.indexOf("*") == -1;
break;
+ case "safariContentBlocker":
+ 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 (!value)
+ {
+ ext.backgroundPage.sendMessage({type: "safari.contentBlockingActive"},
+ function(contentBlockingActive)
+ {
+ if (contentBlockingActive)
+ restartMessage.hidden = false;
+ });
+ }
}
-
var checkbox = document.getElementById(key);
if (checkbox)
checkbox.checked = value;
« no previous file with comments | « options.html ('k') | popup.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld