Skip to content

Commit

Permalink
DNR: Introduce IndexedRule to store parsed JSON rules.
Browse files Browse the repository at this point in the history
r489421 added the schema for specifying JSON rules for the Declarative Net
Request API. This CL introduces IndexedRule to store the parsed JSON rules. In a
subsequent CL, this structure will aid in the conversion to a flatbuffer UrlRule
as specified by the url_pattern_index component.

Doc=http://go/declarative-net-request (Internal only)
BUG=696822

Change-Id: I87b55c0266eafddf521bccb3f7d11757f47c2d7b
Reviewed-on: https://chromium-review.googlesource.com/577287
Commit-Queue: Karan Bhatia <karandeepb@chromium.org>
Reviewed-by: Istiaque Ahmed <lazyboy@chromium.org>
Reviewed-by: Pavel Kalinnikov <pkalinnikov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#492824}
  • Loading branch information
Karan Bhatia authored and Commit Bot committed Aug 9, 2017
1 parent 8cb8c81 commit 9356edc
Show file tree
Hide file tree
Showing 8 changed files with 819 additions and 0 deletions.
1 change: 1 addition & 0 deletions extensions/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ source_set("unit_tests") {
"api/declarative/declarative_rule_unittest.cc",
"api/declarative/deduping_factory_unittest.cc",
"api/declarative/rules_registry_unittest.cc",
"api/declarative_net_request/indexed_rule_unittest.cc",
"api/declarative_webrequest/webrequest_condition_attribute_unittest.cc",
"api/declarative_webrequest/webrequest_condition_unittest.cc",
"api/document_scan/document_scan_api_unittest.cc",
Expand Down
1 change: 1 addition & 0 deletions extensions/browser/api/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ source_set("api") {
"//extensions/browser/api/cast_channel",
"//extensions/browser/api/declarative",
"//extensions/browser/api/declarative_content",
"//extensions/browser/api/declarative_net_request",
"//extensions/browser/api/declarative_webrequest",
"//extensions/browser/api/display_source",
"//extensions/browser/api/dns",
Expand Down
22 changes: 22 additions & 0 deletions extensions/browser/api/declarative_net_request/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

source_set("declarative_net_request") {
sources = [
"constants.h",
"indexed_rule.cc",
"indexed_rule.h",
]

public_deps = [
"//components/url_pattern_index",
]

deps = [
"//base",
"//extensions/common",
"//extensions/common/api",
"//url",
]
}
3 changes: 3 additions & 0 deletions extensions/browser/api/declarative_net_request/DEPS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include_rules = [
"+components/url_pattern_index",
]
38 changes: 38 additions & 0 deletions extensions/browser/api/declarative_net_request/constants.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef EXTENSIONS_BROWSER_API_DECLARATIVE_NET_REQUEST_CONSTANTS_H_
#define EXTENSIONS_BROWSER_API_DECLARATIVE_NET_REQUEST_CONSTANTS_H_

namespace extensions {
namespace declarative_net_request {

// The result of parsing a JSON rule provided by an extension.
enum class ParseResult {
SUCCESS,
ERROR_RESOURCE_TYPE_DUPLICATED,
ERROR_EMPTY_REDIRECT_RULE_PRIORITY,
ERROR_EMPTY_REDIRECT_URL,
ERROR_INVALID_RULE_ID,
ERROR_INVALID_REDIRECT_RULE_PRIORITY,
ERROR_NO_APPLICABLE_RESOURCE_TYPES,
ERROR_EMPTY_DOMAINS_LIST,
ERROR_EMPTY_RESOURCE_TYPES_LIST,
ERROR_EMPTY_URL_FILTER,
ERROR_INVALID_REDIRECT_URL,
};

// Minimum valid value of a declarative rule ID.
constexpr int kMinValidID = 1;

// Minimum valid value of a declarative rule priority.
constexpr int kMinValidPriority = 1;

// Default priority used for rules when the priority is not explicity provided
// by an extension.
constexpr int kDefaultPriority = 1;
} // namespace declarative_net_request
} // namespace extensions

#endif // EXTENSIONS_BROWSER_API_DECLARATIVE_NET_REQUEST_CONSTANTS_H_
Loading

0 comments on commit 9356edc

Please sign in to comment.