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

Side by Side Diff: chrome/common/extensions/docs/examples/api/preferences/enableReferrer/popup.js

Issue 8341010: Samples for `enableReferrer` and `allowThirdPartyCookies` should use the `privacy` namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Docs. Created 9 years, 2 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
1 <!DOCTYPE html> 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 <html> 2 // Use of this source code is governed by a BSD-style license that can be
3 <head> 3 // found in the LICENSE file.
4 <script> 4
5 var pref = chrome.experimental.contentSettings.global.referrersEnabled; 5
6 var pref = chrome.experimental.privacy.websites.referrersEnabled;
7
8 function $(id) {
9 return document.getElementById(id);
10 }
6 11
7 /** 12 /**
8 * Returns whether the |levelOfControl| means that the extension can change the 13 * Returns whether the |levelOfControl| means that the extension can change the
9 * preference value. 14 * preference value.
10 * 15 *
11 * @param levelOfControl{string} 16 * @param levelOfControl{string}
12 */ 17 */
13 function settingIsControllable(levelOfControl) { 18 function settingIsControllable(levelOfControl) {
14 return (levelOfControl == "controllable_by_this_extension" || 19 return (levelOfControl == 'controllable_by_this_extension' ||
15 levelOfControl == "controlled_by_this_extension"); 20 levelOfControl == 'controlled_by_this_extension');
16 } 21 }
17 22
18 /** 23 /**
19 * Updates the UI to reflect the state of the preference. 24 * Updates the UI to reflect the state of the preference.
20 * 25 *
21 * @param settings{object} A settings object, as returned from |get()| or the 26 * @param settings{object} A settings object, as returned from |get()| or the
22 * |onchange| event. 27 * |onchange| event.
23 */ 28 */
24 function updateUI(settings) { 29 function updateUI(settings) {
25 var disableUI = !settingIsControllable(settings.levelOfControl); 30 var disableUI = !settingIsControllable(settings.levelOfControl);
26 document.getElementById("regularValue").disabled = disableUI; 31 document.getElementById('regularValue').disabled = disableUI;
27 document.getElementById("useSeparateIncognitoSettings").disabled = disableUI; 32 document.getElementById('useSeparateIncognitoSettings').disabled = disableUI;
28 if (settings.hasOwnProperty('incognitoSpecific')) { 33 if (settings.hasOwnProperty('incognitoSpecific')) {
29 var hasIncognitoValue = settings.incognitoSpecific; 34 var hasIncognitoValue = settings.incognitoSpecific;
30 document.getElementById("useSeparateIncognitoSettings").checked = 35 document.getElementById('useSeparateIncognitoSettings').checked =
31 hasIncognitoValue; 36 hasIncognitoValue;
32 document.getElementById("incognitoValue").disabled = 37 document.getElementById('incognitoValue').disabled =
33 disableUI || !hasIncognitoValue; 38 disableUI || !hasIncognitoValue;
34 document.getElementById("incognitoValue").checked = settings.value; 39 document.getElementById('incognitoValue').checked = settings.value;
35 } else { 40 } else {
36 document.getElementById("regularValue").checked = settings.value; 41 document.getElementById('regularValue').checked = settings.value;
37 } 42 }
38 } 43 }
39 44
40 /** 45 /**
41 * Wrapper for |updateUI| which is used as callback for the |get()| method and 46 * Wrapper for |updateUI| which is used as callback for the |get()| method and
42 * which logs the result. 47 * which logs the result.
43 * If there was an error getting the preference, does nothing. 48 * If there was an error getting the preference, does nothing.
44 * 49 *
45 * @param settings{object} A settings object, as returned from |get()|. 50 * @param settings{object} A settings object, as returned from |get()|.
46 */ 51 */
(...skipping 16 matching lines...) Expand all
63 updateUI(settings); 68 updateUI(settings);
64 } 69 }
65 70
66 /* 71 /*
67 * Initializes the UI. 72 * Initializes the UI.
68 */ 73 */
69 function init() { 74 function init() {
70 chrome.extension.isAllowedIncognitoAccess(function(allowed) { 75 chrome.extension.isAllowedIncognitoAccess(function(allowed) {
71 if (allowed) { 76 if (allowed) {
72 pref.get({'incognito': true}, updateUIFromGet); 77 pref.get({'incognito': true}, updateUIFromGet);
73 document.getElementById("incognito").style.display = "block"; 78 $('incognito').style.display = 'block';
74 document.getElementById("incognito-forbidden").style.display = "none"; 79 $('incognito-forbidden').style.display = 'none';
75 } 80 }
76 }); 81 });
77 pref.get({}, updateUIFromGet); 82 pref.get({}, updateUIFromGet);
78 pref.onChange.addListener(updateUIFromOnChange); 83 pref.onChange.addListener(updateUIFromOnChange);
84
85 $('regularValue').addEventListener('click', function () {
86 setPrefValue(this.checked, false);
87 });
88 $('useSeparateIncognitoSettings').addEventListener('click', function () {
89 setUseSeparateIncognitoSettings(this.checked);
90 });
91 $('incognitoValue').addEventListener('click', function () {
92 setPrefValue(this.checked, true);
93 });
79 } 94 }
80 95
81 /** 96 /**
82 * Called from the UI to change the preference value. 97 * Called from the UI to change the preference value.
83 * 98 *
84 * @param enabled{boolean} The new preference value. 99 * @param enabled{boolean} The new preference value.
85 * @param incognito{boolean} Whether the value is specific to incognito mode. 100 * @param incognito{boolean} Whether the value is specific to incognito mode.
86 */ 101 */
87 function setPrefValue(enabled, incognito) { 102 function setPrefValue(enabled, incognito) {
88 var scope = incognito ? 'incognito_session_only' : 'regular'; 103 var scope = incognito ? 'incognito_session_only' : 'regular';
89 pref.set({'value': enabled, 'scope': scope}); 104 pref.set({'value': enabled, 'scope': scope});
90 } 105 }
91 106
92 /** 107 /**
93 * Called from the UI to change whether to use separate settings for 108 * Called from the UI to change whether to use separate settings for
94 * incognito mode. 109 * incognito mode.
95 * 110 *
96 * @param value{boolean} whether to use separate settings for 111 * @param value{boolean} whether to use separate settings for
97 * incognito mode. 112 * incognito mode.
98 */ 113 */
99 function setUseSeparateIncognitoSettings(value) { 114 function setUseSeparateIncognitoSettings(value) {
100 if (!value) { 115 if (!value) {
101 pref.clear({'incognito': true}); 116 pref.clear({'incognito': true});
102 } else { 117 } else {
103 // Explicitly set the value for incognito mode. 118 // Explicitly set the value for incognito mode.
104 pref.get({'incognito': true}, function(settings) { 119 pref.get({'incognito': true}, function(settings) {
105 pref.set({'incognito': true, 'value': settings.value}); 120 pref.set({'incognito': true, 'value': settings.value});
106 }); 121 });
107 } 122 }
108 document.getElementById("incognitoValue").disabled = !value; 123 document.getElementById('incognitoValue').disabled = !value;
109 } 124 }
110 125
111 </script> 126 // Call `init` to kick things off.
112 </head> 127 document.addEventListener('DOMContentLoaded', init);
113 <body onload="init()">
114
115 <div style="width: 300px">
116 <input type="checkbox" onclick="setPrefValue(this.checked)" id="regularValue" /> Enable referrers
117
118 <div id="incognito" style="display:none">
119 <input type="checkbox" onclick="setUseSeparateIncognitoSettings(this.checked)" i d="useSeparateIncognitoSettings" /> Use separate setting for incognito mode:
120 <br>
121 <input type="checkbox" onclick="setPrefValue(this.checked, true)" id="incognitoV alue" disabled="disabled"/> Enable referrers in incognito sessions
122 </div>
123 <div id="incognito-forbidden">
124 Select "Allow in incognito" to access incognito preferences
125 </div>
126 </div>
127
128 </body>
129 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698