Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <div id="pageData-name" class="pageData">Privacy</div> | |
| 2 | |
| 3 <!-- BEGIN AUTHORED CONTENT --> | |
| 4 <p id="classSummary"> | |
| 5 Use the <code>chrome.privacy</code> module to control usage of the features in | |
| 6 Chrome that can affect a user's privacy. This module relies on the | |
| 7 <a href="types.html#ChromeSetting">ChromeSetting prototype of the type API</a> | |
| 8 for getting and setting Chrome's configuration. | |
| 9 </p> | |
| 10 | |
| 11 <p class="note"> | |
| 12 The <a href="http://www.google.com/intl/en/landing/chrome/google-chrome-privac y-whitepaper.pdf">Chrome Privacy Whitepaper</a> | |
| 13 gives background detail regarding the features which this API can control. | |
| 14 </p> | |
| 15 | |
| 16 <h2 id="manifest">Manifest</h2> | |
| 17 <p> | |
| 18 You must declare the "privacy" permission in your extension's | |
| 19 <a href="manifest.html"> manifest</a> to use the API. For example: | |
|
battre
2012/01/24 12:29:18
nit: remove space before manifest
Mike West
2012/01/24 13:49:33
Done.
| |
| 20 </p> | |
| 21 | |
| 22 <pre>{ | |
| 23 "name": "My extension", | |
| 24 ... | |
| 25 <b>"permissions": [ | |
| 26 "privacy" | |
| 27 ]</b>, | |
| 28 ... | |
| 29 }</pre> | |
| 30 | |
| 31 <h2 id="usage">Usage</h2> | |
| 32 | |
| 33 <p> | |
| 34 Reading the current value of a Chrome setting is straightforward. You'll first | |
| 35 need to find the property you're interested in, then you'll call | |
| 36 <code>get()</code> on that object in order to retrieve it's current value and | |
| 37 your extension's level of control. For example, to determine if Chrome's | |
| 38 Autofill feature is enabled, you'd write: | |
| 39 </p> | |
| 40 | |
| 41 <pre>chrome.privacy.services.autofillEnabled.get({}, function(details) { | |
| 42 if (details.value) | |
| 43 console.log('Autofill is on!'); | |
| 44 else | |
| 45 console.log('Autofill is off!'); | |
| 46 });</pre> | |
| 47 | |
| 48 <p> | |
| 49 Changing the value of a setting is a little bit more complex, simply because | |
| 50 you first must verify that your extension can control the setting. Chrome will | |
| 51 deny access to a setting if the setting is either locked to a specific value | |
|
battre
2012/01/24 12:29:18
technically, it won't deny access but only ignore
Mike West
2012/01/24 13:49:33
Gah. Complexity.
Done.
| |
| 52 by enterprise policies (<code>levelOfControl</code> will be set to | |
| 53 "not_controllable"), or if another extension is controlling the value | |
| 54 (<code>levelOfControl</code> will be set to "controlled_by_other_extensions"). | |
| 55 </p> | |
| 56 | |
| 57 <p class="note"> | |
| 58 Full details about extension's ability to control <code>ChromeSetting</code>s | |
|
battre
2012/01/24 12:29:18
nit: "about *an* extension's" or "about extensions
Mike West
2012/01/24 13:49:33
The latter. Done. :)
| |
| 59 can be found under | |
| 60 <a href="types.html#ChromeSetting"> | |
| 61 <code>chrome.types.ChromeSetting</code></a>. | |
| 62 </p> | |
| 63 | |
| 64 <p> | |
| 65 This means that you'll need to use the <code>get()</code> method to determine | |
| 66 your level of access, and then only call <code>set()</code> if your extension | |
| 67 can grab control over the setting: | |
|
battre
2012/01/24 12:29:18
not necessary, see above. It is still good practic
Mike West
2012/01/24 13:49:33
Done.
| |
| 68 </p> | |
| 69 | |
| 70 <pre>chrome.privacy.services.autofillEnabled.get({}, function(details) { | |
| 71 if (details.levelOfControl === 'controllable_by_this_extension') { | |
| 72 chrome.privacy.services.autofillEnabled.set({ value: true }, function() { | |
| 73 if (chrome.extension.lastError === undefined) | |
| 74 console.log("Hooray, it worked!"); | |
| 75 else | |
| 76 console.log("Sadness!", chrome.extension.lastError); | |
| 77 } | |
| 78 } | |
| 79 });</pre> | |
| 80 | |
| 81 <p> | |
| 82 If you're interested in changes to a setting's value, add a listener to its | |
| 83 <code>onChange</code> event. Among other uses, this will allow you to warn the | |
| 84 user if a more recently installed extension grabs control of a setting, or if | |
| 85 enterprise policy overrides your control. To listen for changes to Autofill's | |
| 86 status, for example, the following code would suffice: | |
| 87 </p> | |
| 88 | |
| 89 <pre>chrome.privacy.services.autofillEnabled.onChange.addListener( | |
| 90 function (details) { | |
| 91 // The new value is stored in `details.value`, the new level of control | |
| 92 // in `details.levelOfControl`, and `details.incognitoSpecific` will be | |
| 93 // `true` if the value is specific to Incognito mode. | |
| 94 });</pre> | |
| 95 | |
| 96 <h2 id="examples">Examples</h2> | |
| 97 <p> | |
| 98 For example code, see the | |
| 99 <a href="samples.html#privacy">Privacy API samples</a>. | |
| 100 </p> | |
| 101 <!-- END AUTHORED CONTENT --> | |
| OLD | NEW |