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