| OLD | NEW |
| 1 <!-- BEGIN AUTHORED CONTENT --> | |
| 2 <p id="classSummary"> | 1 <p id="classSummary"> |
| 3 Use the <code>chrome.permissions</code> module to implement | 2 Use the <code>chrome.permissions</code> module to implement |
| 4 optional permissions. You can request optional permissions during your | 3 optional permissions. You can request optional permissions during your |
| 5 extension's regular application flow rather than at install time, so users | 4 extension's regular application flow rather than at install time, so users |
| 6 understand why the permissions are needed and use only those that are | 5 understand why the permissions are needed and use only those that are |
| 7 necessary. | 6 necessary. |
| 8 </p> | 7 </p> |
| 8 |
| 9 <p> | 9 <p> |
| 10 For general information about permissions and details about each permission, | 10 For general information about permissions and details about each permission, |
| 11 see the <a href="manifest.html#permissions">permissions</a> section of the | 11 see the <a href="manifest.html#permissions">permissions</a> section of the |
| 12 manifest documentation. | 12 manifest documentation. |
| 13 </p> | 13 </p> |
| 14 |
| 14 <h2 id="howto"> Implementing optional permissions </h2> | 15 <h2 id="howto"> Implementing optional permissions </h2> |
| 15 | 16 |
| 16 <h3 id="types"> Step 1: Decide which permissions are optional and required </h3> | 17 <h3 id="types"> |
| 18 Step 1: Decide which permissions are optional and required |
| 19 </h3> |
| 17 <p> | 20 <p> |
| 18 Extensions should generally require permissions when they are needed for the | 21 Extensions should generally require permissions when they are needed for the |
| 19 extension's basic functionality and employ optional permissions for optional | 22 extension's basic functionality and employ optional permissions for optional |
| 20 features. | 23 features. |
| 21 </p> | 24 </p> |
| 25 |
| 22 <p> | 26 <p> |
| 23 Advantages of optional permissions: | 27 Advantages of optional permissions: |
| 24 <ul> | 28 <ul> |
| 25 <li> | 29 <li> |
| 26 Users run with less permissions since they enable only what is needed. | 30 Users run with less permissions since they enable only what is needed. |
| 27 </li> | 31 </li> |
| 28 <li> | 32 <li> |
| 29 The extension can help explain why it needs particular permissions by | 33 The extension can help explain why it needs particular permissions by |
| 30 requesting them when the user enables the relevant feature. | 34 requesting them when the user enables the relevant feature. |
| 31 </li> | 35 </li> |
| 32 <li> | 36 <li> |
| 33 Chrome can avoid disabling extensions that upgrade if they add permissions | 37 Chrome can avoid disabling extensions that upgrade if they add permissions |
| 34 as optional rather than required. | 38 as optional rather than required. |
| 35 </li> | 39 </li> |
| 36 </ul> | 40 </ul> |
| 37 </p> | 41 </p> |
| 42 |
| 38 <p> | 43 <p> |
| 39 Advantages of required permissions: | 44 Advantages of required permissions: |
| 40 <ul> | 45 <ul> |
| 41 <li> | 46 <li> |
| 42 The extension can prompt the user once to accept all permissions. | 47 The extension can prompt the user once to accept all permissions. |
| 43 </li> | 48 </li> |
| 44 <li> | 49 <li> |
| 45 They simplify extension development by guaranteeing which permissions are | 50 They simplify extension development by guaranteeing which permissions are |
| 46 present. | 51 present. |
| 47 </li> | 52 </li> |
| 48 </ul> | 53 </ul> |
| 49 </p> | 54 </p> |
| 55 |
| 56 |
| 50 <h3 id="manifest"> Step 2: Declare optional permissions in the manifest </h3> | 57 <h3 id="manifest"> Step 2: Declare optional permissions in the manifest </h3> |
| 51 <p> | 58 <p> |
| 52 Declare optional permissions in your <a href="manifest.html">extension | 59 Declare optional permissions in your <a href="manifest.html">extension |
| 53 manifest</a> with the <code>optional_permissions</code> key, using the | 60 manifest</a> with the <code>optional_permissions</code> key, using the |
| 54 same format as the <a href="manifest.html#permissions">permissions</a> | 61 same format as the <a href="manifest.html#permissions">permissions</a> |
| 55 field: | 62 field: |
| 63 |
| 56 <pre>{ | 64 <pre>{ |
| 57 "name": "My extension", | 65 "name": "My extension", |
| 58 ... | 66 ... |
| 59 <b>"optional_permissions": [ "tabs", "http://www.google.com/" ],</b> | 67 <b>"optional_permissions": [ "tabs", "http://www.google.com/" ],</b> |
| 60 ... | 68 ... |
| 61 }</pre> | 69 }</pre> |
| 62 </p> | 70 </p> |
| 71 |
| 63 <p> | 72 <p> |
| 64 You can specify any of the following as optional permissions: | 73 You can specify any of the following as optional permissions: |
| 65 <ul> | 74 <ul> |
| 66 <li><i>host permissions</i></li> | 75 <li><i>host permissions</i></li> |
| 67 <li>appNotifications</li> | 76 <li>appNotifications</li> |
| 68 <li>background</li> | 77 <li>background</li> |
| 69 <li>bookmarks</li> | 78 <li>bookmarks</li> |
| 70 <li>clipboardRead</li> | 79 <li>clipboardRead</li> |
| 71 <li>clipboardWrite</li> | 80 <li>clipboardWrite</li> |
| 72 <li>contentSettings</li> | 81 <li>contentSettings</li> |
| 73 <li>contextMenus</li> | 82 <li>contextMenus</li> |
| 74 <li>cookies</li> | 83 <li>cookies</li> |
| 75 <li>debugger</li> | 84 <li>debugger</li> |
| 76 <li>history</li> | 85 <li>history</li> |
| 77 <li>idle</li> | 86 <li>idle</li> |
| 78 <li>management</li> | 87 <li>management</li> |
| 79 <li>notifications</li> | 88 <li>notifications</li> |
| 80 <li>pageCapture</li> | 89 <li>pageCapture</li> |
| 81 <li>tabs</li> | 90 <li>tabs</li> |
| 82 <li>topSites</li> | 91 <li>topSites</li> |
| 83 <li>webNavigation</li> | 92 <li>webNavigation</li> |
| 84 <li>webRequest</li> | 93 <li>webRequest</li> |
| 85 <li>webRequestBlocking</li> | 94 <li>webRequestBlocking</li> |
| 86 </ul> | 95 </ul> |
| 87 </p> | 96 </p> |
| 97 |
| 88 <p class="note"> | 98 <p class="note"> |
| 89 <b>Version note:</b> This list is correct as of Chrome 17. | 99 <b>Version note:</b> This list is correct as of Chrome 17. |
| 90 More optional permissions might be allowed in future releases. | 100 More optional permissions might be allowed in future releases. |
| 91 </p> | 101 </p> |
| 102 |
| 92 <h3 id="request"> Step 3: Request optional permissions </h3> | 103 <h3 id="request"> Step 3: Request optional permissions </h3> |
| 93 <p> | 104 <p> |
| 94 Request the permissions from within a user gesture using | 105 Request the permissions from within a user gesture using |
| 95 <code>permissions.request()</code>: | 106 <code>permissions.request()</code>: |
| 96 <pre> | 107 <pre> |
| 97 document.querySelector('#my-button').addEventListener('click', function(event) { | 108 document.querySelector('#my-button').addEventListener('click', function(event) { |
| 98 // Permissions must be requested from inside a user gesture, like a button's | 109 // Permissions must be requested from inside a user gesture, like a button's |
| 99 // click handler. | 110 // click handler. |
| 100 chrome.permissions.request({ | 111 chrome.permissions.request({ |
| 101 permissions: ['tabs'], | 112 permissions: ['tabs'], |
| 102 origins: ['http://www.google.com/'] | 113 origins: ['http://www.google.com/'] |
| 103 }, function(granted) { | 114 }, function(granted) { |
| 104 // The callback argument will be true if the user granted the permissions. | 115 // The callback argument will be true if the user granted the permissions. |
| 105 if (granted) { | 116 if (granted) { |
| 106 doSomething(); | 117 doSomething(); |
| 107 } else { | 118 } else { |
| 108 doSomethingElse(); | 119 doSomethingElse(); |
| 109 } | 120 } |
| 110 }); | 121 }); |
| 111 }); | 122 }); |
| 112 </pre> | 123 </pre> |
| 113 </p> | 124 </p> |
| 125 |
| 114 <p> | 126 <p> |
| 115 Chrome prompts the user if adding the permissions results in different | 127 Chrome prompts the user if adding the permissions results in different |
| 116 <a href="permission_warnings.html">warning messages</a> than the user has | 128 <a href="permission_warnings.html">warning messages</a> than the user has |
| 117 already seen and accepted. For example, the previous code might result in | 129 already seen and accepted. For example, the previous code might result in |
| 118 a prompt like this: | 130 a prompt like this: |
| 119 </p> | 131 </p> |
| 132 |
| 120 <p style="text-align: center"> | 133 <p style="text-align: center"> |
| 121 <img src="{{static}}/images/perms-optional.png" | 134 <img src="{{static}}/images/perms-optional.png" |
| 122 alt="example permission confirmation prompt" | 135 alt="example permission confirmation prompt" |
| 123 width="416" height="234"> | 136 width="416" height="234"> |
| 124 </p> | 137 </p> |
| 138 |
| 125 <h3 id="contains"> Step 4: Check the extension's current permissions </h3> | 139 <h3 id="contains"> Step 4: Check the extension's current permissions </h3> |
| 126 <p> | 140 <p> |
| 127 To check whether your extension has a specific permission or set of | 141 To check whether your extension has a specific permission or set of |
| 128 permissions, use <code>permission.contains()</code>: | 142 permissions, use <code>permission.contains()</code>: |
| 129 </p> | 143 </p> |
| 144 |
| 130 <pre> | 145 <pre> |
| 131 chrome.permissions.contains({ | 146 chrome.permissions.contains({ |
| 132 permissions: ['tabs'], | 147 permissions: ['tabs'], |
| 133 origins: ['http://www.google.com/'] | 148 origins: ['http://www.google.com/'] |
| 134 }, function(result) { | 149 }, function(result) { |
| 135 if (result) { | 150 if (result) { |
| 136 // The extension has the permissions. | 151 // The extension has the permissions. |
| 137 } else { | 152 } else { |
| 138 // The extension doesn't have the permissions. | 153 // The extension doesn't have the permissions. |
| 139 } | 154 } |
| 140 }); | 155 }); |
| 141 </pre> | 156 </pre> |
| 157 |
| 142 <h3 id="remove"> Step 5: Remove the permissions </h3> | 158 <h3 id="remove"> Step 5: Remove the permissions </h3> |
| 143 <p> | 159 <p> |
| 144 You should remove permissions when you no longer need them. | 160 You should remove permissions when you no longer need them. |
| 145 After a permission has been removed, calling | 161 After a permission has been removed, calling |
| 146 <code>permissions.request()</code> usually adds the permission back without | 162 <code>permissions.request()</code> usually adds the permission back without |
| 147 prompting the user. | 163 prompting the user. |
| 148 </p> | 164 </p> |
| 165 |
| 149 <pre> | 166 <pre> |
| 150 chrome.permissions.remove({ | 167 chrome.permissions.remove({ |
| 151 permissions: ['tabs'], | 168 permissions: ['tabs'], |
| 152 origins: ['http://www.google.com/'] | 169 origins: ['http://www.google.com/'] |
| 153 }, function(removed) { | 170 }, function(removed) { |
| 154 if (removed) { | 171 if (removed) { |
| 155 // The permissions have been removed. | 172 // The permissions have been removed. |
| 156 } else { | 173 } else { |
| 157 // The permissions have not been removed (e.g., you tried to remove | 174 // The permissions have not been removed (e.g., you tried to remove |
| 158 // required permissions). | 175 // required permissions). |
| 159 } | 176 } |
| 160 }); | 177 }); |
| 161 </pre> | 178 </pre> |
| 162 <!-- END AUTHORED CONTENT --> | |
| OLD | NEW |