<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 data-filename="manifest.json">
{
  "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
$(ref:contentSettings.notifications) 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
$(ref:contentSettings.cookies) 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 $(ref:contentSettings.plugins),
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
$(ref:contentSettings.ContentSetting.getResourceIdentifiers) 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>