Commit f8f6786b authored by Theodore Dubois's avatar Theodore Dubois Committed by Commit Bot

DNR: Update documentation for generic priorities

R=karandeepb@chromium.org

Bug: 1026733
Bug: 1042650
Change-Id: I37da28a4e02d6eed97ba1b458b68803fa95084b8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2026932
Commit-Queue: Theodore Dubois <tbodt@google.com>
Reviewed-by: default avatarKaran Bhatia <karandeepb@chromium.org>
Auto-Submit: Theodore Dubois <tbodt@google.com>
Cr-Commit-Position: refs/heads/master@{#746241}
parent e8fb2509
...@@ -68,6 +68,7 @@ There are the following kinds of rules: ...@@ -68,6 +68,7 @@ There are the following kinds of rules:
<pre> <pre>
{ {
"id" : 1, "id" : 1,
"priority": 1,
"action" : { "type" : "block" }, "action" : { "type" : "block" },
"condition" : { "condition" : {
"urlFilter" : "abc", "urlFilter" : "abc",
...@@ -172,47 +173,45 @@ chrome.declarativeNetRequest.updateDynamicRules</a> API method. ...@@ -172,47 +173,45 @@ chrome.declarativeNetRequest.updateDynamicRules</a> API method.
<h3 id="matching-algorithm">Matching algorithm</h3> <h3 id="matching-algorithm">Matching algorithm</h3>
<p>
Before the request is sent, each extension is queried for an action to take.
The following actions are considered at this stage:
</p>
<ul> <ul>
<li> <li>Block actions with type <code>block</code></li>
If any extension ruleset wants to block a request<sup>1</sup>, the network <li>Redirect actions with type <code>redirect</code> or <code>upgradeScheme</code></li>
request is blocked. <li>Allow actions with type <code>allow</code><code>allowAllRequests</code></li>
</li>
<li>
If the request is not blocked, the request is redirected if any extension
ruleset wants to redirect the request<sup>2</sup>. The most recently
installed extension gets preference here. If multiple redirect rules from an
extension’s ruleset match, the rule with the greatest priority determines
the redirect URL.
</li>
<li>
If the request is not blocked or redirected, <code>removeHeaders</code>
rules are evaluated<sup>3</sup>. Rules from all extensions are evaluated
to determine the set of removed headers.
</li>
</ul> </ul>
<ol type="1"> <p>
<li> If more than one extension returns an action, the extension whose action type
An extension wants to block a request, if the the extension has a matching comes first in the list above gets priority. If more than one extension returns
block rule. Note the priority order between the different block/allow actions: an action with the same priority (position in the list), the most recently
<br/>dynamic allow > dynamic block > static allow > static block. installed extension gets priority.
</li> </p>
<li> <p>
An extension wants to redirect a request, if the extension has a matching When an extension is queried for how to handle a request, the highest priority
redirect rule. Note the priority order between the different redirect/allow matching static or dynamic rule is returned. If more than one matching rule has
actions: the highest priority, the tie is broken based on the action type, in the
<br/>dynamic allow > dynamic redirect > static allow > static redirect. following order:
</li> </p>
<li> <ul>
An extension wants to remove a header from a request, if the extension has <li><code>allow</code></li>
a matching removeHeaders rule. Note the priority order between the different <li><code>allowAllRequests</code></li>
removeHeaders/allow actions: <li><code>block</code></li>
<br/>dynamic allow > dynamic removeHeaders > static allow > static <li><code>upgradeScheme</code></li>
removeHeaders. <li><code>redirect</code></li>
</li> </ul>
</ol>
<p>
If the request was not blocked or redirected, <code>removeHeaders</code> rules
are evaluated on the request and response headers. All matching
<code>removeHeaders</code> rules from extensions that did not have a matching
<code>allow</code> or <code>allowAllRequests</code> action are evaluated.
</p>
<h3 id="web-request-comparison"> <h3 id="web-request-comparison">
Comparison with the <a href="webRequest">webRequest</a> API Comparison with the <a href="webRequest">webRequest</a> API
...@@ -259,14 +258,14 @@ chrome.declarativeNetRequest.updateDynamicRules</a> API method. ...@@ -259,14 +258,14 @@ chrome.declarativeNetRequest.updateDynamicRules</a> API method.
<p><b>manifest.json</b></p> <p><b>manifest.json</b></p>
<pre data-filename="manifest.json"> <pre data-filename="manifest.json">
{
"name" : "declarativeNetRequest extension", "name": "declarativeNetRequest extension",
"version" : "1", "version": "1",
"declarative_net_request" : { "declarative_net_request": {
"rule_resources" : ["rules.json"] "rule_resources": ["rules.json"]
}, },
"permissions" : ["*://*.google.com/*", "*://*.abcd.com/*", "*://*.example.com/*", "declarativeNetRequest"], "permissions": ["*://*.google.com/*", "*://*.abcd.com/*", "*://*.example.com/*", "declarativeNetRequest"],
"manifest_version" : 2 "manifest_version": 2
} }
</pre> </pre>
...@@ -274,37 +273,45 @@ chrome.declarativeNetRequest.updateDynamicRules</a> API method. ...@@ -274,37 +273,45 @@ chrome.declarativeNetRequest.updateDynamicRules</a> API method.
<pre data-filename="rules.json"> <pre data-filename="rules.json">
[ [
{ {
"id" : 1, "id": 1,
"action": { "type" : "block" }, "priority": 1,
"condition" : {"urlFilter" : "google.com", "resourceTypes" : ["main_frame"] } "action": { "type": "block" },
"condition": {"urlFilter": "google.com", "resourceTypes": ["main_frame"] }
}, },
{ {
"id" : 2, "id": 2,
"action" : { "type" : "allow" }, "priority": 1,
"condition" : { "urlFilter" : "google.com/123", "resourceTypes" : ["main_frame"] } "action": { "type": "allow" },
"condition": { "urlFilter": "google.com/123", "resourceTypes": ["main_frame"] }
}, },
{ {
"id" : 3, "id": 3,
"priority" : 1, "priority": 2,
"action" : { "type" : "redirect", "redirect" : { "url" : "https://example.com" } }, "action": { "type": "block" },
"condition" : { "urlFilter" : "google.com", "resourceTypes" : ["main_frame"] } "condition": { "urlFilter": "google.com/12345", "resourceTypes": ["main_frame"] }
}, },
{ {
"id" : 4, "id": 4,
"priority" : 1, "priority": 1,
"action" : { "type" : "redirect", "redirect" : { "extensionPath" : "/a.jpg" } }, "action": { "type": "redirect", "redirect": { "url": "https://example.com" } },
"condition" : { "urlFilter" : "abcd.com", "resourceTypes" : ["main_frame"] } "condition": { "urlFilter": "google.com", "resourceTypes": ["main_frame"] }
}, },
{ {
"id" : 5, "id": 5,
"priority" : 1, "priority": 1,
"action" : { "action": { "type": "redirect", "redirect": { "extensionPath": "/a.jpg" } },
"type" : "redirect", "condition": { "urlFilter": "abcd.com", "resourceTypes": ["main_frame"] }
"redirect" : { },
"transform" : { "scheme" : "https", "host" : "new.example.com" } {
"id": 6,
"priority": 1,
"action": {
"type": "redirect",
"redirect": {
"transform": { "scheme": "https", "host": "new.example.com" }
} }
}, },
"condition" : { "urlFilter" : "||example.com", "resourceTypes" : ["main_frame"] } "condition": { "urlFilter": "||example.com", "resourceTypes": ["main_frame"] }
} }
] ]
</pre> </pre>
...@@ -312,24 +319,31 @@ chrome.declarativeNetRequest.updateDynamicRules</a> API method. ...@@ -312,24 +319,31 @@ chrome.declarativeNetRequest.updateDynamicRules</a> API method.
<ul> <ul>
<!--TODO(crbug.com/1038831): Add examples for allowAllRequests rules. --> <!--TODO(crbug.com/1038831): Add examples for allowAllRequests rules. -->
<li> <li>
Consider a navigation to <code>"http://google.com"</code>. Rules with id (1) Consider a navigation to <code>"http://google.com"</code>. Rules with id
and (3) match. The request will be blocked because blocking rules have (1) and (4) match. The request will be blocked because blocking rules have
higher priority than redirect rules. higher priority than redirect rules when the <code>"priority"</code> is the
same.
</li> </li>
<li> <li>
Consider a navigation to <code>"http://google.com/1234"</code>. Rules with Consider a navigation to <code>"http://google.com/1234"</code>. Rules with
id (1), (2), and (3) match. Because the request has a matching id (1), (2), and (4) match. Because the request has a matching
<code>allow</code> rule, the request is not blocked nor redirected and <code>allow</code> rule and no higher priority rules, the request is not
continues to <code>"http://google.com/1234"</code>. blocked nor redirected and continues to
<code>"http://google.com/1234"</code>.
</li>
<li>
Consider a navigation to <code>"http://google.com/12345"</code> Rules with
id (1), (2), (3), and (4) match. The request will be blocked because rule
(3) has the highest priority, overriding all other matching rules.
</li> </li>
<li> <li>
Consider a navigation to <code>"http://abcd.com"</code>. The rule with id Consider a navigation to <code>"http://abcd.com"</code>. The rule with id
(4) matches. Since rule (4) specifies an extension path, the request is (5) matches. Since rule (5) specifies an extension path, the request is
redirected to <code>"chrome-extension://&lt;extension-id&gt;/a.jpg"</code>. redirected to <code>"chrome-extension://&lt;extension-id&gt;/a.jpg"</code>.
</li> </li>
<li> <li>
Consider a navigation to <code>"http://example.com/path"</code>. The rule Consider a navigation to <code>"http://example.com/path"</code>. The rule
with id (5) matches. Since rule (5) specifies a url transform, the request with id (6) matches. Since rule (6) specifies a url transform, the request
is redirected to <code>"https://new.example.com/path"</code>. is redirected to <code>"https://new.example.com/path"</code>.
</li> </li>
</ul> </ul>
...@@ -216,8 +216,8 @@ namespace declarativeNetRequest { ...@@ -216,8 +216,8 @@ namespace declarativeNetRequest {
// An id which uniquely identifies a rule. Mandatory and should be >= 1. // An id which uniquely identifies a rule. Mandatory and should be >= 1.
long id; long id;
// Rule priority. Mandatory for redirect and upgradeScheme rules and should // Rule priority. Mandatory for all rules other than removeHeaders, and
// be >= 1. This is used to break ties between multiple matching redirect // should be >= 1. This is used to break ties between multiple matching
// rules. // rules.
long? priority; long? priority;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment