Home | History | Annotate | Download | only in intros
      1 <h2 id="manifest">Manifest</h2>
      2 <p>You must declare the "contentSettings" permission
      3 in your extension's manifest to use the API.
      4 For example:</p>
      5 <pre data-filename="manifest.json">
      6 {
      7   "name": "My extension",
      8   ...
      9   <b>"permissions": [
     10     "contentSettings"
     11   ]</b>,
     12   ...
     13 }
     14 </pre>
     15 
     16 
     17 <h2 id="patterns">Content setting patterns</h2>
     18 <p>
     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.
     30 </li>
     31 </ul>
     32 </p>
     33 
     34 <h3 id="pattern-precedence">Pattern precedence</h3>
     35 <p>
     36 When more than one content setting rule applies for a given site, the rule with
     37 the more specific pattern takes precedence.
     38 </p>
     39 <p>For example, the following patterns are ordered by precedence:</p>
     40 <ol>
     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>&lt;all_urls&gt;</code> (matching every URL)</li>
     45 </ol>
     46 <p>
     47 Three kinds of wildcards affect how specific a pattern is:
     48 </p>
     49 <ul>
     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>
     56 </ul>
     57 <p>
     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
     61 precedence:</p>
     62 <ol>
     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
     67 the scheme.</li>
     68 <li><code>http://*.example.com:123/*</code><br>
     69 Lower because although it specifies the port and scheme, it has a wildcard
     70 in the hostname.</li>
     71 </ol>
     72 
     73 <h2 id="primary-secondary">Primary and secondary patterns</h2>
     74 <p>
     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>
     79 <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).
     85 </p>
     86 <p>
     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>
     92 <table>
     93 <tr><th>Precedence</th><th>Primary pattern</th><th>Secondary pattern</th>
     94 <tr>
     95   <td>1</td>
     96   <td><code>http://www.moose.com/*</code>, </td>
     97   <td><code>http://www.wombat.com/*</code></td>
     98 </tr><tr>
     99   <td>2</td>
    100   <td><code>http://www.moose.com/*</code>, </td>
    101   <td><code>&lt;all_urls&gt;</code></td>
    102 </tr><tr>
    103   <td>3</td>
    104   <td><code>&lt;all_urls&gt;</code>, </td>
    105   <td><code>http://www.wombat.com/*</code></td>
    106 </tr><tr>
    107   <td>4</td>
    108   <td><code>&lt;all_urls&gt;</code>, </td>
    109   <td><code>&lt;all_urls&gt;</code></td>
    110 </tr>
    111 </table>
    112 
    113 <h2 id="resource-identifiers">Resource identifiers</h2>
    114 <p>
    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 plug-in. When applying content
    119 settings, first the settings for the specific plug-in are checked. If there are
    120 no settings found for the specific plug-in, the general content settings for
    121 plug-ins are checked.
    122 </p>
    123 <p>
    124 For example, if a content setting rule has the resource identifier
    125 <code>adobe-flash-player</code> and the pattern <code>&lt;all_urls&gt;</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.
    128 </p>
    129 <p>
    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 plug-ins on the user's machine, but Chrome
    133 tries to keep the identifiers stable across plug-in updates.
    134 </p>
    135 
    136 <h2 id="examples">Examples</h2>
    137 
    138 <p>
    139 You can find samples of this API on the
    140 <a href="samples#contentSettings">sample page</a>.
    141 </p>
    142