1 <h2 id=
"manifest">Manifest
</h2>
2 <p>You must declare the
"contentSettings" permission
3 in your extension's manifest to use the API.
5 <pre data-filename=
"manifest.json">
7 "name":
"My extension",
17 <h2 id=
"patterns">Content setting patterns
</h2>
19 You can use patterns to specify the websites that each content setting affects.
20 For example,
<code>http://*.youtube.com/*
</code> specifies youtube.com and all
21 of its subdomains. The syntax for content setting patterns is the same as for
22 <a href=
"match_patterns">match patterns
</a>, with a few differences:
23 <ul><li>For
<code>http
</code>,
24 <code>https
</code>, and
<code>ftp
</code> URLs, the path must be a wildcard
25 (
<code>/*
</code>). For
<code>file
</code> URLs, the path must be completely
26 specified and
<strong>must not
</strong> contain wildcards.
</li>
27 <li>In contrast to match patterns, content setting patterns can specify a port
28 number. If a port number is specified, the pattern only matches websites with
29 that port. If no port number is specified, the pattern matches all ports.
34 <h3 id=
"pattern-precedence">Pattern precedence
</h3>
36 When more than one content setting rule applies for a given site, the rule with
37 the more specific pattern takes precedence.
39 <p>For example, the following patterns are ordered by precedence:
</p>
41 <li><code>http://www.example.com/*
</code></li>
42 <li><code>http://*.example.com/*
</code> (matching
43 example.com and all subdomains)
</li>
44 <li><code><all_urls
></code> (matching every URL)
</li>
47 Three kinds of wildcards affect how specific a pattern is:
50 <li>Wildcards in the port (for example
51 <code>http://www.example.com:*/*
</code>)
</li>
52 <li>Wildcards in the scheme (for example
53 <code>*://www.example.com:
123/*
</code>)
</li>
54 <li>Wildcards in the hostname (for example
55 <code>http://*.example.com:
123/*
</code>)
</li>
58 If a pattern is more specific than another pattern in one part but less specific
59 in another part, the different parts are checked in the following order:
60 hostname, scheme, port. For example, the following patterns are ordered by
63 <li><code>http://www.example.com:*/*
</code><br>
64 Specifies the hostname and scheme.
</li>
65 <li><code>*:/www.example.com:
123/*
</code><br>
66 Not as high, because although it specifies the hostname, it doesn't specify
68 <li><code>http://*.example.com:
123/*
</code><br>
69 Lower because although it specifies the port and scheme, it has a wildcard
73 <h2 id=
"primary-secondary">Primary and secondary patterns
</h2>
75 The URL taken into account when deciding which content setting to apply depends
76 on the content type. For example, for
77 $(ref:contentSettings.notifications) settings are
78 based on the URL shown in the omnibox. This URL is called the
"primary" URL.
</p>
80 Some content types can take additional URLs into account. For example,
81 whether a site is allowed to set a
82 $(ref:contentSettings.cookies) is decided based on the URL
83 of the HTTP request (which is the primary URL in this case) as well as the URL
84 shown in the omnibox (which is called the
"secondary" URL).
87 If multiple rules have primary and secondary patterns, the rule with the more
88 specific primary pattern takes precedence. If there multiple rules have the same
89 primary pattern, the rule with the more specific secondary pattern takes
90 precedence. For example, the following list of primary/secondary pattern pairs
91 is ordered by precedence:
</p>
93 <tr><th>Precedence
</th><th>Primary pattern
</th><th>Secondary pattern
</th>
96 <td><code>http://www.moose.com/*
</code>,
</td>
97 <td><code>http://www.wombat.com/*
</code></td>
100 <td><code>http://www.moose.com/*
</code>,
</td>
101 <td><code><all_urls
></code></td>
104 <td><code><all_urls
></code>,
</td>
105 <td><code>http://www.wombat.com/*
</code></td>
108 <td><code><all_urls
></code>,
</td>
109 <td><code><all_urls
></code></td>
113 <h2 id=
"resource-identifiers">Resource identifiers
</h2>
115 Resource identifiers allow you to specify content settings for specific
116 subtypes of a content type. Currently, the only content type that supports
117 resource identifiers is $(ref:contentSettings.plugins),
118 where a resource identifier identifies a specific plugin. When applying content
119 settings, first the settings for the specific plugin are checked. If there are
120 no settings found for the specific plugin, the general content settings for
124 For example, if a content setting rule has the resource identifier
125 <code>adobe-flash-player
</code> and the pattern
<code><all_urls
></code>,
126 it takes precedence over a rule without a resource identifier and the pattern
127 <code>http://www.example.com/*
</code>, even if that pattern is more specific.
130 You can get a list of resource identifiers for a content type by calling the
131 $(ref:contentSettings.ContentSetting.getResourceIdentifiers) method. The returned list
132 can change with the set of installed plugins on the user's machine, but Chrome
133 tries to keep the identifiers stable across plugin updates.
136 <h2 id=
"examples">Examples
</h2>
139 You can find samples of this API on the
140 <a href=
"samples#search:contentSettings">sample page
</a>.