Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5807)

Unified Diff: chrome/common/extensions/docs/examples/api/preferences/enableReferrer/popup.html

Issue 6793042: Add sample extension for preference access. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/docs/examples/api/preferences/enableReferrer/popup.html
diff --git a/chrome/common/extensions/docs/examples/api/preferences/enableReferrer/popup.html b/chrome/common/extensions/docs/examples/api/preferences/enableReferrer/popup.html
new file mode 100644
index 0000000000000000000000000000000000000000..21e73aa292a13de4819f26f70c19453a5207cf87
--- /dev/null
+++ b/chrome/common/extensions/docs/examples/api/preferences/enableReferrer/popup.html
@@ -0,0 +1,83 @@
+<html>
kurrik.chromium 2011/04/14 17:53:43 Please add a DOCTYPE to popups
Bernhard Bauer 2011/04/15 16:34:32 Done.
+<head>
+ <script>
+var cs = chrome.experimental.contentSettings;
+var pref = cs.misc.enableReferrers;
+
+function settingIsControllable(levelOfControl) {
kurrik.chromium 2011/04/14 17:53:43 I'd prefer to see some lightweight JSdoc for each
Bernhard Bauer 2011/04/15 16:34:32 Done.
+ return (levelOfControl == "ControllableByThisExtension" || levelOfControl == "ControlledByThisExtension");
kurrik.chromium 2011/04/14 17:53:43 Minor nit but you could wrap this line so as to be
Bernhard Bauer 2011/04/15 16:34:32 Done.
+}
+
+function updateUI(settings) {
+ var disableUI = !settingIsControllable(settings.levelOfControl);
+ document.getElementById("regularValue").disabled = disableUI;
+ document.getElementById("useSeparateIncognitoSettings").disabled = disableUI;
+ if (settings.hasOwnProperty('incognitoSpecific')) {
+ var hasIncognitoValue = settings.incognitoSpecific;
+ document.getElementById("useSeparateIncognitoSettings").checked = hasIncognitoValue;
+ document.getElementById("incognitoValue").disabled = disableUI || !hasIncognitoValue;
+ document.getElementById("incognitoValue").checked = settings.value;
+ } else {
+ document.getElementById("regularValue").checked = settings.value;
+ }
+}
+
+function updateUIFromGet(settings) {
+ if (settings) {
+ console.log('pref.get result:' + JSON.stringify(settings));
+ updateUI(settings);
+ }
+}
+
+function updateUIFromOnChange(settings) {
+ console.log('pref.onChange event:' + JSON.stringify(settings));
+ updateUI(settings);
+}
+
+function init() {
+ chrome.extension.isAllowedIncognitoAccess(function(allowed) {
+ if (allowed) {
+ pref.get({'incognito': true}, updateUIFromGet);
+ document.getElementById("incognito").style.display = "block";
+ document.getElementById("incognito-forbidden").style.display = "none";
+ }
+ });
+ pref.get({}, updateUIFromGet);
+ pref.onChange.addListener(updateUIFromOnChange);
+}
+
+function setPrefValue(enabled, incognito) {
+ pref.set({'value':enabled, 'incognito': incognito});
+}
+
+function setUseSeparateIncognitoSettings(value) {
+ if (!value) {
+ pref.clear({'incognito': true});
+ } else {
+ // Explicitly set the value for incognito mode.
+ pref.get({'incognito': true}, function(settings) {
+ pref.set({'incognito': true, 'value': settings.value});
+ });
+ }
+ document.getElementById("incognitoValue").disabled = !value;
+}
+
+ </script>
+</head>
+<body onload="init()">
+
+<div style="width: 300px">
+<input type="checkbox" onclick="setPrefValue(this.checked)" id="regularValue" /> Enable referrers
+
+<div id="incognito" style="display:none">
+<input type="checkbox" onclick="setUseSeparateIncognitoSettings(this.checked)" id="useSeparateIncognitoSettings" /> Use separate setting for incognito mode:
+<br>
+<input type="checkbox" onclick="setPrefValue(this.checked, true)" id="incognitoValue" disabled="disabled"/> Enable referrers in incognito sessions
+</div>
+<div id="incognito-forbidden">
+Select "Allow in incognito" to access incognito preferences
+</div>
+</div>
+
+</body>
+</html>

Powered by Google App Engine
This is Rietveld 408576698