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

Side by Side 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, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 <html>
kurrik.chromium 2011/04/14 17:53:43 Please add a DOCTYPE to popups
Bernhard Bauer 2011/04/15 16:34:32 Done.
2 <head>
3 <script>
4 var cs = chrome.experimental.contentSettings;
5 var pref = cs.misc.enableReferrers;
6
7 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.
8 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.
9 }
10
11 function updateUI(settings) {
12 var disableUI = !settingIsControllable(settings.levelOfControl);
13 document.getElementById("regularValue").disabled = disableUI;
14 document.getElementById("useSeparateIncognitoSettings").disabled = disableUI;
15 if (settings.hasOwnProperty('incognitoSpecific')) {
16 var hasIncognitoValue = settings.incognitoSpecific;
17 document.getElementById("useSeparateIncognitoSettings").checked = hasIncogni toValue;
18 document.getElementById("incognitoValue").disabled = disableUI || !hasIncogn itoValue;
19 document.getElementById("incognitoValue").checked = settings.value;
20 } else {
21 document.getElementById("regularValue").checked = settings.value;
22 }
23 }
24
25 function updateUIFromGet(settings) {
26 if (settings) {
27 console.log('pref.get result:' + JSON.stringify(settings));
28 updateUI(settings);
29 }
30 }
31
32 function updateUIFromOnChange(settings) {
33 console.log('pref.onChange event:' + JSON.stringify(settings));
34 updateUI(settings);
35 }
36
37 function init() {
38 chrome.extension.isAllowedIncognitoAccess(function(allowed) {
39 if (allowed) {
40 pref.get({'incognito': true}, updateUIFromGet);
41 document.getElementById("incognito").style.display = "block";
42 document.getElementById("incognito-forbidden").style.display = "none";
43 }
44 });
45 pref.get({}, updateUIFromGet);
46 pref.onChange.addListener(updateUIFromOnChange);
47 }
48
49 function setPrefValue(enabled, incognito) {
50 pref.set({'value':enabled, 'incognito': incognito});
51 }
52
53 function setUseSeparateIncognitoSettings(value) {
54 if (!value) {
55 pref.clear({'incognito': true});
56 } else {
57 // Explicitly set the value for incognito mode.
58 pref.get({'incognito': true}, function(settings) {
59 pref.set({'incognito': true, 'value': settings.value});
60 });
61 }
62 document.getElementById("incognitoValue").disabled = !value;
63 }
64
65 </script>
66 </head>
67 <body onload="init()">
68
69 <div style="width: 300px">
70 <input type="checkbox" onclick="setPrefValue(this.checked)" id="regularValue" /> Enable referrers
71
72 <div id="incognito" style="display:none">
73 <input type="checkbox" onclick="setUseSeparateIncognitoSettings(this.checked)" i d="useSeparateIncognitoSettings" /> Use separate setting for incognito mode:
74 <br>
75 <input type="checkbox" onclick="setPrefValue(this.checked, true)" id="incognitoV alue" disabled="disabled"/> Enable referrers in incognito sessions
76 </div>
77 <div id="incognito-forbidden">
78 Select "Allow in incognito" to access incognito preferences
79 </div>
80 </div>
81
82 </body>
83 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698