Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1119)

Side by Side Diff: chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.h

Issue 11414230: Declarative Web Request: firstPartyForCookiesUrl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Back to one matcher Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDITIO N_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDITIO N_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDITIO N_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDITIO N_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/memory/linked_ptr.h" 14 #include "base/memory/linked_ptr.h"
15 #include "chrome/browser/extensions/api/declarative/declarative_rule.h" 15 #include "chrome/browser/extensions/api/declarative/declarative_rule.h"
16 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condit ion_attribute.h" 16 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condit ion_attribute.h"
17 #include "chrome/common/extensions/matcher/url_matcher.h" 17 #include "chrome/common/extensions/matcher/url_matcher.h"
18 #include "net/http/http_response_headers.h" 18 #include "net/http/http_response_headers.h"
19 19
20 namespace extensions { 20 namespace extensions {
21 21
22 // Container for information about a URLRequest to determine which 22 // Container for information about a URLRequest to determine which
23 // rules apply to the request. 23 // rules apply to the request.
24 struct DeclarativeWebRequestData { 24 struct DeclarativeWebRequestData {
25 DeclarativeWebRequestData(net::URLRequest* request, RequestStage stage) 25 DeclarativeWebRequestData(net::URLRequest* request, RequestStage stage);
26 : request(request), stage(stage),
27 original_response_headers(NULL) {}
28 DeclarativeWebRequestData( 26 DeclarativeWebRequestData(
29 net::URLRequest* request, RequestStage stage, 27 net::URLRequest* request,
30 const net::HttpResponseHeaders* original_response_headers) 28 RequestStage stage,
31 : request(request), stage(stage), 29 const net::HttpResponseHeaders* original_response_headers);
32 original_response_headers(original_response_headers) {} 30 ~DeclarativeWebRequestData();
33 net::URLRequest* request; 31 net::URLRequest* request;
34 RequestStage stage; 32 RequestStage stage;
33 std::set<URLMatcherConditionSet::ID> url_match_ids;
vabr (Chromium) 2013/01/22 14:54:30 Adding the sets caused the need for off-lined cons
34 std::set<URLMatcherConditionSet::ID> first_party_url_match_ids;
35 // Additional information about requests that is not 35 // Additional information about requests that is not
36 // available in all request stages. 36 // available in all request stages.
37 const net::HttpResponseHeaders* original_response_headers; 37 const net::HttpResponseHeaders* original_response_headers;
38 }; 38 };
39 39
40 // Representation of a condition in the Declarative WebRequest API. A condition 40 // Representation of a condition in the Declarative WebRequest API. A condition
41 // consists of several attributes. Each of these attributes needs to be 41 // consists of several attributes. Each of these attributes needs to be
42 // fulfilled in order for the condition to be fulfilled. 42 // fulfilled in order for the condition to be fulfilled.
43 // 43 //
44 // We distinguish between two types of conditions: 44 // We distinguish between two types of conditions:
45 // - URL Matcher conditions are conditions that test the URL of a request. 45 // - URL Matcher conditions are conditions that test the URL of a request.
46 // These are treated separately because we use a URLMatcher to efficiently 46 // These are treated separately because we use a URLMatcher to efficiently
47 // test many of these conditions in parallel by using some advanced 47 // test many of these conditions in parallel by using some advanced
48 // data structures. The URLMatcher tells us if all URL Matcher conditions 48 // data structures. The URLMatcher tells us if all URL Matcher conditions
49 // are fulfilled for a WebRequestCondition. 49 // are fulfilled for a WebRequestCondition.
50 // - All other conditions are represented as WebRequestConditionAttributes. 50 // - All other conditions are represented as WebRequestConditionAttributes.
51 // These conditions are probed linearly (only if the URL Matcher found a hit). 51 // These conditions are probed linearly (only if the URL Matcher found a hit).
52 // 52 //
53 // TODO(battre) Consider making the URLMatcher an owner of the 53 // TODO(battre) Consider making the URLMatcher an owner of the
54 // URLMatcherConditionSet and only pass a pointer to URLMatcherConditionSet 54 // URLMatcherConditionSet and only pass a pointer to URLMatcherConditionSet
55 // in url_matcher_condition_set(). This saves some copying in 55 // in url_matcher_condition_set(). This saves some copying in
56 // WebRequestConditionSet::GetURLMatcherConditionSets. 56 // WebRequestConditionSet::GetURLMatcherConditionSets.
57 class WebRequestCondition { 57 class WebRequestCondition {
58 public: 58 public:
59 typedef DeclarativeWebRequestData MatchData; 59 typedef DeclarativeWebRequestData MatchData;
60 60
61 WebRequestCondition( 61 WebRequestCondition(
62 scoped_refptr<URLMatcherConditionSet> url_matcher_conditions, 62 scoped_refptr<URLMatcherConditionSet> url_matcher_conditions,
63 scoped_refptr<URLMatcherConditionSet> first_party_url_matcher_conditions,
63 const WebRequestConditionAttributes& condition_attributes); 64 const WebRequestConditionAttributes& condition_attributes);
64 ~WebRequestCondition(); 65 ~WebRequestCondition();
65 66
66 // Factory method that instantiates a WebRequestCondition according to 67 // Factory method that instantiates a WebRequestCondition according to
67 // the description |condition| passed by the extension API. 68 // the description |condition| passed by the extension API.
68 static scoped_ptr<WebRequestCondition> Create( 69 static scoped_ptr<WebRequestCondition> Create(
69 URLMatcherConditionFactory* url_matcher_condition_factory, 70 URLMatcherConditionFactory* url_matcher_condition_factory,
70 const base::Value& condition, 71 const base::Value& condition,
71 std::string* error); 72 std::string* error);
72 73
73 // Returns whether the request matches this condition. |url_matches| lists 74 // Returns whether the request matches this condition.
74 // the IDs that match the request's URL. 75 bool IsFulfilled(
75 bool IsFulfilled(const std::set<URLMatcherConditionSet::ID> &url_matches, 76 const std::set<URLMatcherConditionSet::ID>& /*url_matches*/,
vabr (Chromium) 2013/01/22 14:54:30 Now that we ignore |url_matches| in favour of the
76 const DeclarativeWebRequestData& request_data) const; 77 const DeclarativeWebRequestData& request_data) const;
77 78
78 // True if this condition has a url filter. 79 // If this condition has url attributes, appends them to |condition_sets|.
79 bool has_url_matcher_condition_set() const {
80 return url_matcher_conditions_ != NULL;
81 }
82
83 // If this Condition has a url filter, appends it to |condition_sets|.
84 void GetURLMatcherConditionSets( 80 void GetURLMatcherConditionSets(
85 URLMatcherConditionSet::Vector* condition_sets) const { 81 URLMatcherConditionSet::Vector* condition_sets) const;
86 if (url_matcher_conditions_)
87 condition_sets->push_back(url_matcher_conditions_);
88 }
89 82
90 // Returns the condition attributes checked by this condition. 83 // Returns the condition attributes checked by this condition.
91 const WebRequestConditionAttributes condition_attributes() const { 84 const WebRequestConditionAttributes condition_attributes() const {
92 return condition_attributes_; 85 return condition_attributes_;
93 } 86 }
94 87
95 // Returns a bit vector representing extensions::RequestStage. The bit vector 88 // Returns a bit vector representing extensions::RequestStage. The bit vector
96 // contains a 1 for each request stage during which the condition can be 89 // contains a 1 for each request stage during which the condition can be
97 // tested. 90 // tested.
98 int stages() const { return applicable_request_stages_; } 91 int stages() const { return applicable_request_stages_; }
99 92
100 private: 93 private:
101 // Represents the 'url' attribute of this condition. If NULL, then there was 94 // URL attributes of this condition.
102 // no 'url' attribute in this condition.
103 scoped_refptr<URLMatcherConditionSet> url_matcher_conditions_; 95 scoped_refptr<URLMatcherConditionSet> url_matcher_conditions_;
96 scoped_refptr<URLMatcherConditionSet> first_party_url_matcher_conditions_;
104 97
105 // All non-UrlFilter attributes of this condition. 98 // All non-UrlFilter attributes of this condition.
106 WebRequestConditionAttributes condition_attributes_; 99 WebRequestConditionAttributes condition_attributes_;
107 100
108 // Bit vector indicating all RequestStage during which all 101 // Bit vector indicating all RequestStage during which all
109 // |condition_attributes_| can be evaluated. 102 // |condition_attributes_| can be evaluated.
110 int applicable_request_stages_; 103 int applicable_request_stages_;
111 104
112 DISALLOW_COPY_AND_ASSIGN(WebRequestCondition); 105 DISALLOW_COPY_AND_ASSIGN(WebRequestCondition);
113 }; 106 };
114 107
115 typedef DeclarativeConditionSet<WebRequestCondition> WebRequestConditionSet; 108 typedef DeclarativeConditionSet<WebRequestCondition> WebRequestConditionSet;
116 109
117 } // namespace extensions 110 } // namespace extensions
118 111
119 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDI TION_H_ 112 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDI TION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698