Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 // These conditions are probed linearly (only if the URL Matcher found a hit). | 30 // These conditions are probed linearly (only if the URL Matcher found a hit). |
| 31 // | 31 // |
| 32 // TODO(battre) Consider making the URLMatcher an owner of the | 32 // TODO(battre) Consider making the URLMatcher an owner of the |
| 33 // URLMatcherConditionSet and only pass a pointer to URLMatcherConditionSet | 33 // URLMatcherConditionSet and only pass a pointer to URLMatcherConditionSet |
| 34 // in url_matcher_condition_set(). This saves some copying in | 34 // in url_matcher_condition_set(). This saves some copying in |
| 35 // WebRequestConditionSet::GetURLMatcherConditionSets. | 35 // WebRequestConditionSet::GetURLMatcherConditionSets. |
| 36 class WebRequestCondition { | 36 class WebRequestCondition { |
| 37 public: | 37 public: |
| 38 WebRequestCondition( | 38 WebRequestCondition( |
| 39 scoped_refptr<URLMatcherConditionSet> url_matcher_conditions, | 39 scoped_refptr<URLMatcherConditionSet> url_matcher_conditions, |
| 40 scoped_refptr<URLMatcherConditionSet> first_party_url_matcher_conditions, | |
| 40 const WebRequestConditionAttributes& condition_attributes); | 41 const WebRequestConditionAttributes& condition_attributes); |
| 41 ~WebRequestCondition(); | 42 ~WebRequestCondition(); |
| 42 | 43 |
| 43 // Factory method that instantiates a WebRequestCondition according to | 44 // Factory method that instantiates a WebRequestCondition according to |
| 44 // the description |condition| passed by the extension API. | 45 // the description |condition| passed by the extension API. |
| 45 static scoped_ptr<WebRequestCondition> Create( | 46 static scoped_ptr<WebRequestCondition> Create( |
| 46 URLMatcherConditionFactory* url_matcher_condition_factory, | 47 URLMatcherConditionFactory* url_matcher_condition_factory, |
| 48 URLMatcherConditionFactory* first_party_url_matcher_condition_factory, | |
|
Jeffrey Yasskin
2012/12/18 03:09:58
Why are there two condition_factories when the oth
vabr (Chromium)
2013/01/21 10:57:48
This has now changed to multiple factories and mul
| |
| 47 const base::Value& condition, | 49 const base::Value& condition, |
| 48 std::string* error); | 50 std::string* error); |
| 49 | 51 |
| 50 // Returns whether the request is a match, given that the URLMatcher found | 52 // Returns whether the request is a match, given that the URLMatcher found |
| 51 // a match for |url_matcher_conditions_|. | 53 // a match for |url_matcher_conditions_| and |
| 54 // |first_party_url_matcher_conditions_|. | |
| 52 bool IsFulfilled(const WebRequestRule::RequestData& request_data) const; | 55 bool IsFulfilled(const WebRequestRule::RequestData& request_data) const; |
| 53 | 56 |
| 54 // Returns a URLMatcherConditionSet::ID which is the canonical representation | 57 // Returns a URLMatcherConditionSet::ID which is the canonical representation |
| 55 // for all URL patterns that need to be matched by this WebRequestCondition. | 58 // for all URL patterns that need to be matched by this WebRequestCondition. |
| 56 // This ID is registered in a URLMatcher that can inform us in case of a | 59 // This ID is registered in a URLMatcher that can inform us in case of a |
| 57 // match. | 60 // match. |
| 58 URLMatcherConditionSet::ID url_matcher_condition_set_id() const { | 61 URLMatcherConditionSet::ID url_matcher_condition_set_id() const { |
| 59 return url_matcher_conditions_->id(); | 62 return url_matcher_conditions_->id(); |
| 60 } | 63 } |
| 64 URLMatcherConditionSet::ID first_party_url_matcher_condition_set_id() const { | |
| 65 return first_party_url_matcher_conditions_->id(); | |
| 66 } | |
| 61 | 67 |
| 62 // Returns the set of conditions that are checked on the URL. This is the | 68 // Returns the set of conditions that are checked on the URL. This is the |
| 63 // primary trigger for WebRequestCondition and therefore never empty. | 69 // primary trigger for WebRequestCondition and therefore never empty. |
| 64 // (If it was empty, the URLMatcher would never notify us about network | 70 // (If it was empty, the URLMatcher would never notify us about network |
| 65 // requests which might fulfill the entire WebRequestCondition). | 71 // requests which might fulfill the entire WebRequestCondition). |
| 66 scoped_refptr<URLMatcherConditionSet> url_matcher_condition_set() const { | 72 scoped_refptr<URLMatcherConditionSet> url_matcher_condition_set() const { |
| 67 return url_matcher_conditions_; | 73 return url_matcher_conditions_; |
| 68 } | 74 } |
| 75 // Returns the set of conditions that are checked on the first party for | |
| 76 // cookies URL. This is also never empty. | |
| 77 scoped_refptr<URLMatcherConditionSet> | |
| 78 first_party_url_matcher_condition_set() const { | |
| 79 return first_party_url_matcher_conditions_; | |
| 80 } | |
| 69 | 81 |
| 70 // Returns the condition attributes checked by this condition. | 82 // Returns the condition attributes checked by this condition. |
| 71 const WebRequestConditionAttributes condition_attributes() const { | 83 const WebRequestConditionAttributes condition_attributes() const { |
| 72 return condition_attributes_; | 84 return condition_attributes_; |
| 73 } | 85 } |
| 74 | 86 |
| 75 // Returns a bit vector representing extensions::RequestStage. The bit vector | 87 // Returns a bit vector representing extensions::RequestStage. The bit vector |
| 76 // contains a 1 for each request stage during which the condition can be | 88 // contains a 1 for each request stage during which the condition can be |
| 77 // tested. | 89 // tested. |
| 78 int stages() const { return applicable_request_stages_; } | 90 int stages() const { return applicable_request_stages_; } |
| 79 | 91 |
| 80 private: | 92 private: |
| 81 scoped_refptr<URLMatcherConditionSet> url_matcher_conditions_; | 93 scoped_refptr<URLMatcherConditionSet> url_matcher_conditions_; |
| 94 scoped_refptr<URLMatcherConditionSet> first_party_url_matcher_conditions_; | |
| 82 WebRequestConditionAttributes condition_attributes_; | 95 WebRequestConditionAttributes condition_attributes_; |
| 83 | 96 |
| 84 // Bit vector indicating all RequestStage during which all | 97 // Bit vector indicating all RequestStage during which all |
| 85 // |condition_attributes_| can be evaluated. | 98 // |condition_attributes_| can be evaluated. |
| 86 int applicable_request_stages_; | 99 int applicable_request_stages_; |
| 87 | 100 |
| 88 DISALLOW_COPY_AND_ASSIGN(WebRequestCondition); | 101 DISALLOW_COPY_AND_ASSIGN(WebRequestCondition); |
| 89 }; | 102 }; |
| 90 | 103 |
| 91 // This class stores a set of conditions that may be part of a WebRequestRule. | 104 // This class stores a set of conditions that may be part of a WebRequestRule. |
| 92 // If any condition is fulfilled, the WebRequestActions of the WebRequestRule | 105 // If any condition is fulfilled, the WebRequestActions of the WebRequestRule |
| 93 // can be triggered. | 106 // can be triggered. |
| 94 class WebRequestConditionSet { | 107 class WebRequestConditionSet { |
| 95 public: | 108 public: |
| 96 typedef std::vector<linked_ptr<json_schema_compiler::any::Any> > AnyVector; | 109 typedef std::vector<linked_ptr<json_schema_compiler::any::Any> > AnyVector; |
| 97 typedef std::vector<linked_ptr<WebRequestCondition> > Conditions; | 110 typedef std::vector<linked_ptr<WebRequestCondition> > Conditions; |
| 98 | 111 |
| 99 explicit WebRequestConditionSet(const Conditions& conditions); | 112 explicit WebRequestConditionSet(const Conditions& conditions); |
| 100 ~WebRequestConditionSet(); | 113 ~WebRequestConditionSet(); |
| 101 | 114 |
| 102 // Factory method that creates an WebRequestConditionSet according to the JSON | 115 // Factory method that creates an WebRequestConditionSet according to the JSON |
| 103 // array |conditions| passed by the extension API. | 116 // array |conditions| passed by the extension API. |
| 104 // Sets |error| and returns NULL in case of an error. | 117 // Sets |error| and returns NULL in case of an error. |
| 105 static scoped_ptr<WebRequestConditionSet> Create( | 118 static scoped_ptr<WebRequestConditionSet> Create( |
| 106 URLMatcherConditionFactory* url_matcher_condition_factory, | 119 URLMatcherConditionFactory* url_matcher_condition_factory, |
| 120 URLMatcherConditionFactory* first_party_url_matcher_condition_factory, | |
| 107 const AnyVector& conditions, | 121 const AnyVector& conditions, |
| 108 std::string* error); | 122 std::string* error); |
| 109 | 123 |
| 110 const Conditions& conditions() const { | 124 const Conditions& conditions() const { |
| 111 return conditions_; | 125 return conditions_; |
| 112 } | 126 } |
| 113 | 127 |
| 114 // Returns whether any condition in the condition set is fulfilled | 128 // Returns whether any condition in the condition set is fulfilled |
| 115 // based on a match |url_match| and the value of |request_data.request|. | 129 // based on a match |url_match| and the value of |request_data.request|. |
| 116 // This function should be called for each URLMatcherConditionSet::ID | 130 // This function should be called for each URLMatcherConditionSet::ID |
| 117 // that was found by the URLMatcher to ensure that the each trigger in | 131 // that was found by the URLMatcher to ensure that the each trigger in |
| 118 // |match_triggers_| is found. | 132 // |match_triggers_| is found. |
| 119 bool IsFulfilled( | 133 bool IsFulfilled( |
| 120 URLMatcherConditionSet::ID url_match, | 134 URLMatcherConditionSet::ID url_match, |
| 121 const WebRequestRule::RequestData& request_data) const; | 135 const WebRequestRule::RequestData& request_data) const; |
| 122 | 136 |
| 123 // Appends the URLMatcherConditionSet from all conditions to |condition_sets|. | 137 // Append the URLMatcherConditionSet for request URL, and for the first party |
| 138 // for cookies URL, respectively, from all conditions to |condition_sets|. | |
| 124 void GetURLMatcherConditionSets( | 139 void GetURLMatcherConditionSets( |
| 125 URLMatcherConditionSet::Vector* condition_sets) const; | 140 URLMatcherConditionSet::Vector* condition_sets) const; |
| 141 void GetFirstPartyURLMatcherConditionSets( | |
| 142 URLMatcherConditionSet::Vector* condition_sets) const; | |
| 126 | 143 |
| 127 private: | 144 private: |
| 128 Conditions conditions_; | 145 Conditions conditions_; |
| 129 | 146 |
| 130 typedef std::map<URLMatcherConditionSet::ID, WebRequestCondition*> | 147 typedef std::map<URLMatcherConditionSet::ID, WebRequestCondition*> |
| 131 MatchTriggers; | 148 MatchTriggers; |
| 132 MatchTriggers match_triggers_; | 149 MatchTriggers match_triggers_; |
| 133 | 150 |
| 134 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionSet); | 151 DISALLOW_COPY_AND_ASSIGN(WebRequestConditionSet); |
| 135 }; | 152 }; |
| 136 | 153 |
| 137 } // namespace extensions | 154 } // namespace extensions |
| 138 | 155 |
| 139 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDI TION_H_ | 156 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_WEBREQUEST_WEBREQUEST_CONDI TION_H_ |
| OLD | NEW |