OLD | NEW |
(Empty) | |
| 1 <div id="pageData-name" class="pageData">Content Settings</div> |
| 2 |
| 3 <!-- BEGIN AUTHORED CONTENT --> |
| 4 <p> |
| 5 The content settings module allows you to change settings that control whether |
| 6 websites can use features such as cookies, JavaScript, and plug-ins. |
| 7 More generally speaking, content settings allow you to customize Chrome's |
| 8 behavior on a per-site basis instead of globally.</p> |
| 9 <p> |
| 10 </p> |
| 11 |
| 12 <h2 id="manifest">Manifest</h2> |
| 13 <p>You must declare the "contentSettings" permission |
| 14 in your extension's manifest to use the API. |
| 15 For example:</p> |
| 16 <pre>{ |
| 17 "name": "My extension", |
| 18 ... |
| 19 <b>"permissions": [ |
| 20 "contentSettings" |
| 21 ]</b>, |
| 22 ... |
| 23 }</pre> |
| 24 |
| 25 |
| 26 <h2 id="patterns">Content setting patterns</h2> |
| 27 <p> |
| 28 You can use patterns to specify the websites that each content setting affects. |
| 29 For example, <code>http://*.youtube.com/*</code> specifies youtube.com and all |
| 30 of its subdomains. The syntax for content setting patterns is the same as for |
| 31 <a href="match_patterns.html">match patterns</a>, with a few differences: |
| 32 <ul><li>For <code>http</code>, |
| 33 <code>https</code>, and <code>ftp</code> URLs, the path must be a wildcard |
| 34 (<code>/*</code>). For <code>file</code> URLs, the path must be completely |
| 35 specified and <strong>must not</strong> contain wildcards.</li> |
| 36 <li>In contrast to match patterns, content setting patterns can specify a port |
| 37 number. If a port number is specified, the pattern only matches websites with |
| 38 that port. If no port number is specified, the pattern matches all ports. |
| 39 </li> |
| 40 </ul> |
| 41 </p> |
| 42 |
| 43 <h3 id="pattern-precedence">Pattern precedence</h3> |
| 44 <p> |
| 45 When more than one content setting rule applies for a given site, the rule with |
| 46 the more specific pattern takes precedence. |
| 47 </p> |
| 48 <p>For example, the following patterns are ordered by precedence:</p> |
| 49 <ol> |
| 50 <li><code>http://www.example.com/*</code></li> |
| 51 <li><code>http://*.example.com/*</code> (matching |
| 52 example.com and all subdomains)</li> |
| 53 <li><code><all_urls></code> (matching every URL)</li> |
| 54 </ol> |
| 55 <p> |
| 56 Three kinds of wildcards affect how specific a pattern is: |
| 57 </p> |
| 58 <ul> |
| 59 <li>Wildcards in the port (for example |
| 60 <code>http://www.example.com:*/*</code>)</li> |
| 61 <li>Wildcards in the scheme (for example |
| 62 <code>*://www.example.com:123/*</code>)</li> |
| 63 <li>Wildcards in the hostname (for example |
| 64 <code>http://*.example.com:123/*</code>)</li> |
| 65 </ul> |
| 66 <p> |
| 67 If a pattern is more specific than another pattern in one part but less specific |
| 68 in another part, the different parts are checked in the following order: |
| 69 hostname, scheme, port. For example, the following patterns are ordered by |
| 70 precedence:</p> |
| 71 <ol> |
| 72 <li><code>http://www.example.com:*/*</code><br> |
| 73 Specifies the hostname and scheme.</li> |
| 74 <li><code>*:/www.example.com:123/*</code><br> |
| 75 Not as high, because although it specifies the hostname, it doesn't specify |
| 76 the scheme.</li> |
| 77 <li><code>http://*.example.com:123/*</code><br> |
| 78 Lower because although it specifies the port and scheme, it has a wildcard |
| 79 in the hostname.</li> |
| 80 </ol> |
| 81 |
| 82 <h2 id="primary-secondary">Primary and secondary patterns</h2> |
| 83 <p> |
| 84 The URL taken into account when deciding which content setting to apply depends |
| 85 on the content type. For example, for |
| 86 <a href="#property-notifications">notifications</a> settings are |
| 87 based on the URL shown in the omnibox. This URL is called the "primary" URL.</p> |
| 88 <p> |
| 89 Some content types can take additional URLs into account. For example, |
| 90 whether a site is allowed to set a |
| 91 <a href="#property-cookies">cookie</a> is decided based on the URL |
| 92 of the HTTP request (which is the primary URL in this case) as well as the URL |
| 93 shown in the omnibox (which is called the "secondary" URL). |
| 94 </p> |
| 95 <p> |
| 96 If multiple rules have primary and secondary patterns, the rule with the more |
| 97 specific primary pattern takes precedence. If there multiple rules have the same |
| 98 primary pattern, the rule with the more specific secondary pattern takes |
| 99 precedence. For example, the following list of primary/secondary pattern pairs |
| 100 is ordered by precedence:</p> |
| 101 <table> |
| 102 <tr><th>Precedence</th><th>Primary pattern</th><th>Secondary pattern</th> |
| 103 <tr> |
| 104 <td>1</td> |
| 105 <td><code>http://www.moose.com/*</code>, </td> |
| 106 <td><code>http://www.wombat.com/*</code></td> |
| 107 </tr><tr> |
| 108 <td>2</td> |
| 109 <td><code>http://www.moose.com/*</code>, </td> |
| 110 <td><code><all_urls></code></td> |
| 111 </tr><tr> |
| 112 <td>3</td> |
| 113 <td><code><all_urls></code>, </td> |
| 114 <td><code>http://www.wombat.com/*</code></td> |
| 115 </tr><tr> |
| 116 <td>4</td> |
| 117 <td><code><all_urls></code>, </td> |
| 118 <td><code><all_urls></code></td> |
| 119 </tr> |
| 120 </table> |
| 121 |
| 122 <h2 id="resource-identifiers">Resource identifiers</h2> |
| 123 <p> |
| 124 Resource identifiers allow you to specify content settings for specific |
| 125 subtypes of a content type. Currently, the only content type that supports |
| 126 resource identifiers is <a href="#property-plugins"><code>plugins</code></a>, |
| 127 where a resource identifier identifies a specific plug-in. When applying content |
| 128 settings, first the settings for the specific plug-in are checked. If there are |
| 129 no settings found for the specific plug-in, the general content settings for |
| 130 plug-ins are checked. |
| 131 </p> |
| 132 <p> |
| 133 For example, if a content setting rule has the resource identifier |
| 134 <code>adobe-flash-player</code> and the pattern <code><all_urls></code>, |
| 135 it takes precedence over a rule without a resource identifier and the pattern |
| 136 <code>http://www.example.com/*</code>, even if that pattern is more specific. |
| 137 </p> |
| 138 <p> |
| 139 You can get a list of resource identifiers for a content type by calling the |
| 140 <a href="contentSettings.html#method-ContentSetting-getResourceIdentifiers"> |
| 141 <code>getResourceIdentifiers()</code></a> method. The returned list |
| 142 can change with the set of installed plug-ins on the user's machine, but Chrome |
| 143 tries to keep the identifiers stable across plug-in updates. |
| 144 </p> |
| 145 |
| 146 <h2 id="examples">Examples</h2> |
| 147 |
| 148 <p> |
| 149 You can find samples of this API on the |
| 150 <a href="samples.html#contentSettings">sample page</a>. |
| 151 </p> |
| 152 |
| 153 <!-- END AUTHORED CONTENT --> |
OLD | NEW |