OLD | NEW |
1 <h2 id="howto"> Implementing optional permissions </h2> | 1 <h2 id="howto"> Implementing optional permissions </h2> |
2 | 2 |
3 <h3 id="types"> | 3 <h3 id="types"> |
4 Step 1: Decide which permissions are required and which are optional | 4 Step 1: Decide which permissions are required and which are optional |
5 </h3> | 5 </h3> |
6 | 6 |
7 <p> | 7 <p> |
8 An extension can declare both required and optional permissions. In general, you
should: | 8 An extension can declare both required and optional permissions. In general, you
should: |
9 <ul> | 9 <ul> |
10 <li>Use required permissions when they are needed for your extension’s basic f
unctionality.</li> | 10 <li>Use required permissions when they are needed for your extension’s basic f
unctionality.</li> |
(...skipping 18 matching lines...) Expand all Loading... |
29 Extensions run with fewer permissions since users only enable permissions
that are needed.</li> | 29 Extensions run with fewer permissions since users only enable permissions
that are needed.</li> |
30 <li><strong>Better information for users:</strong> | 30 <li><strong>Better information for users:</strong> |
31 An extension can explain why it needs a particular permission when the use
r enables the relevant feature.</li> | 31 An extension can explain why it needs a particular permission when the use
r enables the relevant feature.</li> |
32 <li><strong>Easier upgrades:</strong> | 32 <li><strong>Easier upgrades:</strong> |
33 When you upgrade your extension, Chrome will not disable it for your users
if the upgrade adds optional rather than required permissions.</li> | 33 When you upgrade your extension, Chrome will not disable it for your users
if the upgrade adds optional rather than required permissions.</li> |
34 </ul> | 34 </ul> |
35 </p> | 35 </p> |
36 | 36 |
37 <h3 id="manifest"> Step 2: Declare optional permissions in the manifest </h3> | 37 <h3 id="manifest"> Step 2: Declare optional permissions in the manifest </h3> |
38 <p> | 38 <p> |
39 Declare optional permissions in your <a href="manifest.html">extension | 39 Declare optional permissions in your <a href="manifest">extension |
40 manifest</a> with the <code>optional_permissions</code> key, using the | 40 manifest</a> with the <code>optional_permissions</code> key, using the |
41 same format as the <a href="declare_permissions.html#manifest">permissions</a> | 41 same format as the <a href="declare_permissions#manifest">permissions</a> |
42 field: | 42 field: |
43 </p> | 43 </p> |
44 | 44 |
45 <pre data-filename="manifest.json"> | 45 <pre data-filename="manifest.json"> |
46 { | 46 { |
47 "name": "My extension", | 47 "name": "My extension", |
48 ... | 48 ... |
49 <b>"optional_permissions": [ "tabs", "http://www.google.com/" ],</b> | 49 <b>"optional_permissions": [ "tabs", "http://www.google.com/" ],</b> |
50 ... | 50 ... |
51 } | 51 } |
52 </pre> | 52 </pre> |
53 | 53 |
54 <p> | 54 <p> |
55 You can specify any of the following as optional | 55 You can specify any of the following as optional |
56 <a href="declare_permissions.html">permissions</a>: | 56 <a href="declare_permissions">permissions</a>: |
57 <ul> | 57 <ul> |
58 <li><i>host permissions</i></li> | 58 <li><i>host permissions</i></li> |
59 <li>background</li> | 59 <li>background</li> |
60 <li>bookmarks</li> | 60 <li>bookmarks</li> |
61 <li>clipboardRead</li> | 61 <li>clipboardRead</li> |
62 <li>clipboardWrite</li> | 62 <li>clipboardWrite</li> |
63 <li>contentSettings</li> | 63 <li>contentSettings</li> |
64 <li>contextMenus</li> | 64 <li>contextMenus</li> |
65 <li>cookies</li> | 65 <li>cookies</li> |
66 <li>debugger</li> | 66 <li>debugger</li> |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 } else { | 101 } else { |
102 doSomethingElse(); | 102 doSomethingElse(); |
103 } | 103 } |
104 }); | 104 }); |
105 }); | 105 }); |
106 </pre> | 106 </pre> |
107 </p> | 107 </p> |
108 | 108 |
109 <p> | 109 <p> |
110 Chrome prompts the user if adding the permissions results in different | 110 Chrome prompts the user if adding the permissions results in different |
111 <a href="permission_warnings.html">warning messages</a> than the user has | 111 <a href="permission_warnings">warning messages</a> than the user has |
112 already seen and accepted. For example, the previous code might result in | 112 already seen and accepted. For example, the previous code might result in |
113 a prompt like this: | 113 a prompt like this: |
114 </p> | 114 </p> |
115 | 115 |
116 <p style="text-align: center"> | 116 <p style="text-align: center"> |
117 <img src="{{static}}/images/perms-optional.png" | 117 <img src="{{static}}/images/perms-optional.png" |
118 alt="example permission confirmation prompt" | 118 alt="example permission confirmation prompt" |
119 width="490" height="193"> | 119 width="490" height="193"> |
120 </p> | 120 </p> |
121 | 121 |
(...skipping 30 matching lines...) Expand all Loading... |
152 origins: ['http://www.google.com/'] | 152 origins: ['http://www.google.com/'] |
153 }, function(removed) { | 153 }, function(removed) { |
154 if (removed) { | 154 if (removed) { |
155 // The permissions have been removed. | 155 // The permissions have been removed. |
156 } else { | 156 } else { |
157 // The permissions have not been removed (e.g., you tried to remove | 157 // The permissions have not been removed (e.g., you tried to remove |
158 // required permissions). | 158 // required permissions). |
159 } | 159 } |
160 }); | 160 }); |
161 </pre> | 161 </pre> |
OLD | NEW |