diff options
author | mkwst@chromium.org <mkwst@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-18 13:47:31 +0000 |
---|---|---|
committer | mkwst@chromium.org <mkwst@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-18 13:47:31 +0000 |
commit | 58ae297434a9e33d1006c52b6d13d8a78e3b7e5e (patch) | |
tree | d8fe784f34b0a56d6665bb38e531435398040dbc /chrome/common/extensions/docs/examples/api/preferences | |
parent | 82f4655aeafd179c7551a6e618c34b056db428e5 (diff) | |
download | chromium_src-58ae297434a9e33d1006c52b6d13d8a78e3b7e5e.zip chromium_src-58ae297434a9e33d1006c52b6d13d8a78e3b7e5e.tar.gz chromium_src-58ae297434a9e33d1006c52b6d13d8a78e3b7e5e.tar.bz2 |
Samples for `enableReferrer` and `allowThirdPartyCookies` should use the `privacy` namespace.
While fixing these samples, I've also added `content_security_policy` as a
drive-by.
BUG=92644
TEST=
Review URL: http://codereview.chromium.org/8341010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106059 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions/docs/examples/api/preferences')
10 files changed, 321 insertions, 247 deletions
diff --git a/chrome/common/extensions/docs/examples/api/preferences/allowThirdPartyCookies.zip b/chrome/common/extensions/docs/examples/api/preferences/allowThirdPartyCookies.zip Binary files differindex 3a13b42..bb8480a 100644 --- a/chrome/common/extensions/docs/examples/api/preferences/allowThirdPartyCookies.zip +++ b/chrome/common/extensions/docs/examples/api/preferences/allowThirdPartyCookies.zip diff --git a/chrome/common/extensions/docs/examples/api/preferences/allowThirdPartyCookies/manifest.json b/chrome/common/extensions/docs/examples/api/preferences/allowThirdPartyCookies/manifest.json index ad42502..ff3db44 100644 --- a/chrome/common/extensions/docs/examples/api/preferences/allowThirdPartyCookies/manifest.json +++ b/chrome/common/extensions/docs/examples/api/preferences/allowThirdPartyCookies/manifest.json @@ -2,9 +2,10 @@ "name" : "Block/allow third-party cookies API example extension",
"version" : "0.1",
"description" : "Sample extension which demonstrates how to access a preference.",
- "permissions": [ "experimental", "contentSettings" ],
+ "permissions": [ "experimental", "privacy" ],
"browser_action": {
"default_icon": "advicedog.jpg",
"popup": "popup.html"
- }
+ },
+ "content_security_policy": "default-src 'none'; script-src 'self'; style-src 'self'"
}
diff --git a/chrome/common/extensions/docs/examples/api/preferences/allowThirdPartyCookies/popup.css b/chrome/common/extensions/docs/examples/api/preferences/allowThirdPartyCookies/popup.css new file mode 100644 index 0000000..3e715ba --- /dev/null +++ b/chrome/common/extensions/docs/examples/api/preferences/allowThirdPartyCookies/popup.css @@ -0,0 +1,13 @@ +/** + * Copyright (c) 2011 The Chromium Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#container { + width: 300px; +} + +#incognito { + display: none; +} diff --git a/chrome/common/extensions/docs/examples/api/preferences/allowThirdPartyCookies/popup.html b/chrome/common/extensions/docs/examples/api/preferences/allowThirdPartyCookies/popup.html index 67556a1..37dccec 100644 --- a/chrome/common/extensions/docs/examples/api/preferences/allowThirdPartyCookies/popup.html +++ b/chrome/common/extensions/docs/examples/api/preferences/allowThirdPartyCookies/popup.html @@ -1,128 +1,24 @@ <!DOCTYPE html> <html> <head> - <script> -var pref = chrome.experimental.contentSettings.global.thirdPartyCookiesAllowed; - -/** - * Returns whether the |levelOfControl| means that the extension can change the - * preference value. - * - * @param levelOfControl{string} - */ -function settingIsControllable(levelOfControl) { - return (levelOfControl == "controllable_by_this_extension" || - levelOfControl == "controlled_by_this_extension"); -} - -/** - * Updates the UI to reflect the state of the preference. - * - * @param settings{object} A settings object, as returned from |get()| or the - * |onchange| event. - */ -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; - } -} - -/** - * Wrapper for |updateUI| which is used as callback for the |get()| method and - * which logs the result. - * If there was an error getting the preference, does nothing. - * - * @param settings{object} A settings object, as returned from |get()|. - */ -function updateUIFromGet(settings) { - if (settings) { - console.log('pref.get result:' + JSON.stringify(settings)); - updateUI(settings); - } -} - -/** - * Wrapper for |updateUI| which is used as handler for the |onchange| event - * and which logs the result. - * - * @param settings{object} A settings object, as returned from the |onchange| - * event. - */ -function updateUIFromOnChange(settings) { - console.log('pref.onChange event:' + JSON.stringify(settings)); - updateUI(settings); -} - -/* - * Initializes the UI. - */ -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); -} - -/** - * Called from the UI to change the preference value. - * - * @param enabled{boolean} The new preference value. - * @param incognito{boolean} Whether the value is specific to incognito mode. - */ -function setPrefValue(enabled, incognito) { - var scope = incognito ? 'incognito_session_only' : 'regular'; - pref.set({'value': enabled, 'scope': scope}); -} - -/** - * Called from the UI to change whether to use separate settings for - * incognito mode. - * - * @param value{boolean} whether to use separate settings for - * incognito mode. - */ -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> + <link href="popup.css" rel="stylesheet" type="text/css"> + <script src="popup.js"></script> </head> -<body onload="init()"> - -<div style="width: 300px"> -<input type="checkbox" onclick="setPrefValue(this.checked)" id="regularValue" /> Allow third-party sites to set cookies - -<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> +<body> + +<div id="container"> + <input type="checkbox" id="regularValue" /> + Allow third-party sites to set cookies + <div id="incognito"> + <input type="checkbox" id="useSeparateIncognitoSettings" /> + Use separate setting for incognito mode: + <br> + <input type="checkbox" id="incognitoValue" disabled="disabled"/> + Allow third-party sites to set cookies in incognito sessions + </div> + <div id="incognito-forbidden"> + Select "Allow in incognito" to access incognito preferences + </div> </div> </body> diff --git a/chrome/common/extensions/docs/examples/api/preferences/allowThirdPartyCookies/popup.js b/chrome/common/extensions/docs/examples/api/preferences/allowThirdPartyCookies/popup.js new file mode 100644 index 0000000..2eb2797 --- /dev/null +++ b/chrome/common/extensions/docs/examples/api/preferences/allowThirdPartyCookies/popup.js @@ -0,0 +1,127 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + + +var pref = chrome.experimental.privacy.websites.thirdPartyCookiesAllowed; + +function $(id) { + return document.getElementById(id); +} + +/** + * Returns whether the |levelOfControl| means that the extension can change the + * preference value. + * + * @param levelOfControl{string} + */ +function settingIsControllable(levelOfControl) { + return (levelOfControl == 'controllable_by_this_extension' || + levelOfControl == 'controlled_by_this_extension'); +} + +/** + * Updates the UI to reflect the state of the preference. + * + * @param settings{object} A settings object, as returned from |get()| or the + * |onchange| event. + */ +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; + } +} + +/** + * Wrapper for |updateUI| which is used as callback for the |get()| method and + * which logs the result. + * If there was an error getting the preference, does nothing. + * + * @param settings{object} A settings object, as returned from |get()|. + */ +function updateUIFromGet(settings) { + if (settings) { + console.log('pref.get result:' + JSON.stringify(settings)); + updateUI(settings); + } +} + +/** + * Wrapper for |updateUI| which is used as handler for the |onchange| event + * and which logs the result. + * + * @param settings{object} A settings object, as returned from the |onchange| + * event. + */ +function updateUIFromOnChange(settings) { + console.log('pref.onChange event:' + JSON.stringify(settings)); + updateUI(settings); +} + +/* + * Initializes the UI. + */ +function init() { + chrome.extension.isAllowedIncognitoAccess(function(allowed) { + if (allowed) { + pref.get({'incognito': true}, updateUIFromGet); + $('incognito').style.display = 'block'; + $('incognito-forbidden').style.display = 'none'; + } + }); + pref.get({}, updateUIFromGet); + pref.onChange.addListener(updateUIFromOnChange); + + $('regularValue').addEventListener('click', function () { + setPrefValue(this.checked, false); + }); + $('useSeparateIncognitoSettings').addEventListener('click', function () { + setUseSeparateIncognitoSettings(this.checked); + }); + $('incognitoValue').addEventListener('click', function () { + setPrefValue(this.checked, true); + }); +} + +/** + * Called from the UI to change the preference value. + * + * @param enabled{boolean} The new preference value. + * @param incognito{boolean} Whether the value is specific to incognito mode. + */ +function setPrefValue(enabled, incognito) { + var scope = incognito ? 'incognito_session_only' : 'regular'; + pref.set({'value': enabled, 'scope': scope}); +} + +/** + * Called from the UI to change whether to use separate settings for + * incognito mode. + * + * @param value{boolean} whether to use separate settings for + * incognito mode. + */ +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; +} + +// Call `init` to kick things off. +document.addEventListener('DOMContentLoaded', init); diff --git a/chrome/common/extensions/docs/examples/api/preferences/enableReferrer.zip b/chrome/common/extensions/docs/examples/api/preferences/enableReferrer.zip Binary files differindex 21c9576..ac6af98 100644 --- a/chrome/common/extensions/docs/examples/api/preferences/enableReferrer.zip +++ b/chrome/common/extensions/docs/examples/api/preferences/enableReferrer.zip diff --git a/chrome/common/extensions/docs/examples/api/preferences/enableReferrer/manifest.json b/chrome/common/extensions/docs/examples/api/preferences/enableReferrer/manifest.json index 03b0e5a..bd7a8a4 100644 --- a/chrome/common/extensions/docs/examples/api/preferences/enableReferrer/manifest.json +++ b/chrome/common/extensions/docs/examples/api/preferences/enableReferrer/manifest.json @@ -1,10 +1,11 @@ {
- "name" : "Enable/disable referrers API example extension",
+ "name" : "Block/allow referrer API example extension",
"version" : "0.1",
"description" : "Sample extension which demonstrates how to access a preference.",
- "permissions": [ "experimental", "contentSettings" ],
+ "permissions": [ "experimental", "privacy" ],
"browser_action": {
"default_icon": "advicedog.jpg",
"popup": "popup.html"
- }
+ },
+ "content_security_policy": "default-src 'none'; script-src 'self'; style-src 'self'"
}
diff --git a/chrome/common/extensions/docs/examples/api/preferences/enableReferrer/popup.css b/chrome/common/extensions/docs/examples/api/preferences/enableReferrer/popup.css new file mode 100644 index 0000000..3e715ba --- /dev/null +++ b/chrome/common/extensions/docs/examples/api/preferences/enableReferrer/popup.css @@ -0,0 +1,13 @@ +/** + * Copyright (c) 2011 The Chromium Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#container { + width: 300px; +} + +#incognito { + display: none; +} diff --git a/chrome/common/extensions/docs/examples/api/preferences/enableReferrer/popup.html b/chrome/common/extensions/docs/examples/api/preferences/enableReferrer/popup.html index 11f8d11..7f94699 100644 --- a/chrome/common/extensions/docs/examples/api/preferences/enableReferrer/popup.html +++ b/chrome/common/extensions/docs/examples/api/preferences/enableReferrer/popup.html @@ -1,128 +1,24 @@ <!DOCTYPE html> <html> <head> - <script> -var pref = chrome.experimental.contentSettings.global.referrersEnabled; - -/** - * Returns whether the |levelOfControl| means that the extension can change the - * preference value. - * - * @param levelOfControl{string} - */ -function settingIsControllable(levelOfControl) { - return (levelOfControl == "controllable_by_this_extension" || - levelOfControl == "controlled_by_this_extension"); -} - -/** - * Updates the UI to reflect the state of the preference. - * - * @param settings{object} A settings object, as returned from |get()| or the - * |onchange| event. - */ -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; - } -} - -/** - * Wrapper for |updateUI| which is used as callback for the |get()| method and - * which logs the result. - * If there was an error getting the preference, does nothing. - * - * @param settings{object} A settings object, as returned from |get()|. - */ -function updateUIFromGet(settings) { - if (settings) { - console.log('pref.get result:' + JSON.stringify(settings)); - updateUI(settings); - } -} - -/** - * Wrapper for |updateUI| which is used as handler for the |onchange| event - * and which logs the result. - * - * @param settings{object} A settings object, as returned from the |onchange| - * event. - */ -function updateUIFromOnChange(settings) { - console.log('pref.onChange event:' + JSON.stringify(settings)); - updateUI(settings); -} - -/* - * Initializes the UI. - */ -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); -} - -/** - * Called from the UI to change the preference value. - * - * @param enabled{boolean} The new preference value. - * @param incognito{boolean} Whether the value is specific to incognito mode. - */ -function setPrefValue(enabled, incognito) { - var scope = incognito ? 'incognito_session_only' : 'regular'; - pref.set({'value': enabled, 'scope': scope}); -} - -/** - * Called from the UI to change whether to use separate settings for - * incognito mode. - * - * @param value{boolean} whether to use separate settings for - * incognito mode. - */ -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> + <link href="popup.css" rel="stylesheet" type="text/css"> + <script src="popup.js"></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> +<body> + +<div id="container"> + <input type="checkbox" id="regularValue" /> + Enable referrers + <div id="incognito"> + <input type="checkbox" id="useSeparateIncognitoSettings" /> + Use separate setting for incognito mode: + <br> + <input type="checkbox" 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> diff --git a/chrome/common/extensions/docs/examples/api/preferences/enableReferrer/popup.js b/chrome/common/extensions/docs/examples/api/preferences/enableReferrer/popup.js new file mode 100644 index 0000000..56ac004 --- /dev/null +++ b/chrome/common/extensions/docs/examples/api/preferences/enableReferrer/popup.js @@ -0,0 +1,127 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + + +var pref = chrome.experimental.privacy.websites.referrersEnabled; + +function $(id) { + return document.getElementById(id); +} + +/** + * Returns whether the |levelOfControl| means that the extension can change the + * preference value. + * + * @param levelOfControl{string} + */ +function settingIsControllable(levelOfControl) { + return (levelOfControl == 'controllable_by_this_extension' || + levelOfControl == 'controlled_by_this_extension'); +} + +/** + * Updates the UI to reflect the state of the preference. + * + * @param settings{object} A settings object, as returned from |get()| or the + * |onchange| event. + */ +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; + } +} + +/** + * Wrapper for |updateUI| which is used as callback for the |get()| method and + * which logs the result. + * If there was an error getting the preference, does nothing. + * + * @param settings{object} A settings object, as returned from |get()|. + */ +function updateUIFromGet(settings) { + if (settings) { + console.log('pref.get result:' + JSON.stringify(settings)); + updateUI(settings); + } +} + +/** + * Wrapper for |updateUI| which is used as handler for the |onchange| event + * and which logs the result. + * + * @param settings{object} A settings object, as returned from the |onchange| + * event. + */ +function updateUIFromOnChange(settings) { + console.log('pref.onChange event:' + JSON.stringify(settings)); + updateUI(settings); +} + +/* + * Initializes the UI. + */ +function init() { + chrome.extension.isAllowedIncognitoAccess(function(allowed) { + if (allowed) { + pref.get({'incognito': true}, updateUIFromGet); + $('incognito').style.display = 'block'; + $('incognito-forbidden').style.display = 'none'; + } + }); + pref.get({}, updateUIFromGet); + pref.onChange.addListener(updateUIFromOnChange); + + $('regularValue').addEventListener('click', function () { + setPrefValue(this.checked, false); + }); + $('useSeparateIncognitoSettings').addEventListener('click', function () { + setUseSeparateIncognitoSettings(this.checked); + }); + $('incognitoValue').addEventListener('click', function () { + setPrefValue(this.checked, true); + }); +} + +/** + * Called from the UI to change the preference value. + * + * @param enabled{boolean} The new preference value. + * @param incognito{boolean} Whether the value is specific to incognito mode. + */ +function setPrefValue(enabled, incognito) { + var scope = incognito ? 'incognito_session_only' : 'regular'; + pref.set({'value': enabled, 'scope': scope}); +} + +/** + * Called from the UI to change whether to use separate settings for + * incognito mode. + * + * @param value{boolean} whether to use separate settings for + * incognito mode. + */ +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; +} + +// Call `init` to kick things off. +document.addEventListener('DOMContentLoaded', init); |