summaryrefslogtreecommitdiffstats
path: root/chrome/common/extensions/docs/static/contentSettings.html
blob: 8ce8b8e18949f358054912b1c6576abd737170a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<div id="pageData-name" class="pageData">Content Settings</div>

<!-- BEGIN AUTHORED CONTENT -->
<p>
The content settings module allows you to change settings that control whether
websites can use features such as cookies, JavaScript, and plug-ins.
More generally speaking, content settings allow you to customize Chrome's
behavior on a per-site basis instead of globally.</p>
<p>
</p>

<h2 id="manifest">Manifest</h2>
<p>You must declare the "contentSettings" permission
in your extension's manifest to use the API.
For example:</p>
<pre>{
  "name": "My extension",
  ...
  <b>"permissions": [
    "contentSettings"
  ]</b>,
  ...
}</pre>


<h2 id="patterns">Content setting patterns</h2>
<p>
You can use patterns to specify the websites that each content setting affects.
For example, <code>http://*.youtube.com/*</code> specifies youtube.com and all
of its subdomains. The syntax for content setting patterns is the same as for
<a href="match_patterns.html">match patterns</a>, with a few differences:
<ul><li>For <code>http</code>,
<code>https</code>, and <code>ftp</code> URLs, the path must be a wildcard
(<code>/*</code>). For <code>file</code> URLs, the path must be completely
specified and <strong>must not</strong> contain wildcards.</li>
<li>In contrast to match patterns, content setting patterns can specify a port
number. If a port number is specified, the pattern only matches websites with
that port. If no port number is specified, the pattern matches all ports.
</li>
</ul>
</p>

<h3 id="pattern-precedence">Pattern precedence</h3>
<p>
When more than one content setting rule applies for a given site, the rule with
the more specific pattern takes precedence.
</p>
<p>For example, the following patterns are ordered by precedence:</p>
<ol>
<li><code>http://www.example.com/*</code></li>
<li><code>http://*.example.com/*</code> (matching
example.com and all subdomains)</li>
<li><code>&lt;all_urls&gt;</code> (matching every URL)</li>
</ol>
<p>
Three kinds of wildcards affect how specific a pattern is:
</p>
<ul>
<li>Wildcards in the port (for example
<code>http://www.example.com:*/*</code>)</li>
<li>Wildcards in the scheme (for example
<code>*://www.example.com:123/*</code>)</li>
<li>Wildcards in the hostname (for example
<code>http://*.example.com:123/*</code>)</li>
</ul>
<p>
If a pattern is more specific than another pattern in one part but less specific
in another part, the different parts are checked in the following order:
hostname, scheme, port. For example, the following patterns are ordered by
precedence:</p>
<ol>
<li><code>http://www.example.com:*/*</code><br>
Specifies the hostname and scheme.</li>
<li><code>*:/www.example.com:123/*</code><br>
Not as high, because although it specifies the hostname, it doesn't specify
the scheme.</li>
<li><code>http://*.example.com:123/*</code><br>
Lower because although it specifies the port and scheme, it has a wildcard
in the hostname.</li>
</ol>

<h2 id="primary-secondary">Primary and secondary patterns</h2>
<p>
The URL taken into account when deciding which content setting to apply depends
on the content type. For example, for
<a href="#property-notifications">notifications</a> settings are
based on the URL shown in the omnibox. This URL is called the "primary" URL.</p>
<p>
Some content types can take additional URLs into account. For example,
whether a site is allowed to set a
<a href="#property-cookies">cookie</a> is decided based on the URL
of the HTTP request (which is the primary URL in this case) as well as the URL
shown in the omnibox (which is called the "secondary" URL).
</p>
<p>
If multiple rules have primary and secondary patterns, the rule with the more
specific primary pattern takes precedence. If there multiple rules have the same
primary pattern, the rule with the more specific secondary pattern takes
precedence. For example, the following list of primary/secondary pattern pairs
is ordered by precedence:</p>
<table>
<tr><th>Precedence</th><th>Primary pattern</th><th>Secondary pattern</th>
<tr>
  <td>1</td>
  <td><code>http://www.moose.com/*</code>, </td>
  <td><code>http://www.wombat.com/*</code></td>
</tr><tr>
  <td>2</td>
  <td><code>http://www.moose.com/*</code>, </td>
  <td><code>&lt;all_urls&gt;</code></td>
</tr><tr>
  <td>3</td>
  <td><code>&lt;all_urls&gt;</code>, </td>
  <td><code>http://www.wombat.com/*</code></td>
</tr><tr>
  <td>4</td>
  <td><code>&lt;all_urls&gt;</code>, </td>
  <td><code>&lt;all_urls&gt;</code></td>
</tr>
</table>

<h2 id="resource-identifiers">Resource identifiers</h2>
<p>
Resource identifiers allow you to specify content settings for specific
subtypes of a content type. Currently, the only content type that supports
resource identifiers is <a href="#property-plugins"><code>plugins</code></a>,
where a resource identifier identifies a specific plug-in. When applying content
settings, first the settings for the specific plug-in are checked. If there are
no settings found for the specific plug-in, the general content settings for
plug-ins are checked.
</p>
<p>
For example, if a content setting rule has the resource identifier
<code>adobe-flash-player</code> and the pattern <code>&lt;all_urls&gt;</code>,
it takes precedence over a rule without a resource identifier and the pattern
<code>http://www.example.com/*</code>, even if that pattern is more specific.
</p>
<p>
You can get a list of resource identifiers for a content type by calling the
<a href="contentSettings.html#method-ContentSetting-getResourceIdentifiers">
<code>getResourceIdentifiers()</code></a> method. The returned list
can change with the set of installed plug-ins on the user's machine, but Chrome
tries to keep the identifiers stable across plug-in updates.
</p>

<h2 id="examples">Examples</h2>

<p>
You can find samples of this API on the
<a href="samples.html#contentSettings">sample page</a>.
</p>

<!-- END AUTHORED CONTENT -->