| 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_CONTENT_CHROME_CONTENT_RULES_R
EGISTRY_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CHROME_CONTENT_RULES_R
EGISTRY_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CHROME_CONTENT_RULES_R
EGISTRY_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CHROME_CONTENT_RULES_R
EGISTRY_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> |
| 11 #include <set> | 12 #include <set> |
| 12 #include <string> | 13 #include <string> |
| 13 #include <utility> | 14 #include <utility> |
| 14 #include <vector> | 15 #include <vector> |
| 15 | 16 |
| 16 #include "base/callback.h" | 17 #include "base/callback.h" |
| 17 #include "base/macros.h" | 18 #include "base/macros.h" |
| 18 #include "base/memory/linked_ptr.h" | 19 #include "base/memory/linked_ptr.h" |
| 19 #include "base/memory/scoped_ptr.h" | |
| 20 #include "chrome/browser/extensions/api/declarative_content/content_action.h" | 20 #include "chrome/browser/extensions/api/declarative_content/content_action.h" |
| 21 #include "chrome/browser/extensions/api/declarative_content/content_condition.h" | 21 #include "chrome/browser/extensions/api/declarative_content/content_condition.h" |
| 22 #include "chrome/browser/extensions/api/declarative_content/content_predicate_ev
aluator.h" | 22 #include "chrome/browser/extensions/api/declarative_content/content_predicate_ev
aluator.h" |
| 23 #include "content/public/browser/notification_observer.h" | 23 #include "content/public/browser/notification_observer.h" |
| 24 #include "content/public/browser/notification_registrar.h" | 24 #include "content/public/browser/notification_registrar.h" |
| 25 #include "extensions/browser/api/declarative_content/content_rules_registry.h" | 25 #include "extensions/browser/api/declarative_content/content_rules_registry.h" |
| 26 #include "extensions/common/extension.h" | 26 #include "extensions/common/extension.h" |
| 27 | 27 |
| 28 namespace content { | 28 namespace content { |
| 29 class BrowserContext; | 29 class BrowserContext; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 49 // however, is only responsible for applying rules registered by the incognito | 49 // however, is only responsible for applying rules registered by the incognito |
| 50 // side of split-mode extensions to incognito tabs. The non-incognito instance | 50 // side of split-mode extensions to incognito tabs. The non-incognito instance |
| 51 // handles incognito tabs for spanning-mode extensions, plus all non-incognito | 51 // handles incognito tabs for spanning-mode extensions, plus all non-incognito |
| 52 // tabs. | 52 // tabs. |
| 53 class ChromeContentRulesRegistry | 53 class ChromeContentRulesRegistry |
| 54 : public ContentRulesRegistry, | 54 : public ContentRulesRegistry, |
| 55 public content::NotificationObserver, | 55 public content::NotificationObserver, |
| 56 public ContentPredicateEvaluator::Delegate { | 56 public ContentPredicateEvaluator::Delegate { |
| 57 public: | 57 public: |
| 58 using PredicateEvaluatorsFactory = | 58 using PredicateEvaluatorsFactory = |
| 59 base::Callback<std::vector<scoped_ptr<ContentPredicateEvaluator>>( | 59 base::Callback<std::vector<std::unique_ptr<ContentPredicateEvaluator>>( |
| 60 ContentPredicateEvaluator::Delegate*)>; | 60 ContentPredicateEvaluator::Delegate*)>; |
| 61 | 61 |
| 62 // For testing, |cache_delegate| can be NULL. In that case it constructs the | 62 // For testing, |cache_delegate| can be NULL. In that case it constructs the |
| 63 // registry with storage functionality suspended. | 63 // registry with storage functionality suspended. |
| 64 ChromeContentRulesRegistry( | 64 ChromeContentRulesRegistry( |
| 65 content::BrowserContext* browser_context, | 65 content::BrowserContext* browser_context, |
| 66 RulesCacheDelegate* cache_delegate, | 66 RulesCacheDelegate* cache_delegate, |
| 67 const PredicateEvaluatorsFactory& evaluators_factory); | 67 const PredicateEvaluatorsFactory& evaluators_factory); |
| 68 | 68 |
| 69 // ContentRulesRegistry: | 69 // ContentRulesRegistry: |
| (...skipping 28 matching lines...) Expand all Loading... |
| 98 | 98 |
| 99 protected: | 99 protected: |
| 100 ~ChromeContentRulesRegistry() override; | 100 ~ChromeContentRulesRegistry() override; |
| 101 | 101 |
| 102 private: | 102 private: |
| 103 // The internal declarative rule representation. Corresponds to a declarative | 103 // The internal declarative rule representation. Corresponds to a declarative |
| 104 // API rule: https://developer.chrome.com/extensions/events.html#declarative. | 104 // API rule: https://developer.chrome.com/extensions/events.html#declarative. |
| 105 struct ContentRule { | 105 struct ContentRule { |
| 106 public: | 106 public: |
| 107 ContentRule(const Extension* extension, | 107 ContentRule(const Extension* extension, |
| 108 std::vector<scoped_ptr<const ContentCondition>> conditions, | 108 std::vector<std::unique_ptr<const ContentCondition>> conditions, |
| 109 std::vector<scoped_ptr<const ContentAction>> actions, | 109 std::vector<std::unique_ptr<const ContentAction>> actions, |
| 110 int priority); | 110 int priority); |
| 111 ~ContentRule(); | 111 ~ContentRule(); |
| 112 | 112 |
| 113 const Extension* extension; | 113 const Extension* extension; |
| 114 std::vector<scoped_ptr<const ContentCondition>> conditions; | 114 std::vector<std::unique_ptr<const ContentCondition>> conditions; |
| 115 std::vector<scoped_ptr<const ContentAction>> actions; | 115 std::vector<std::unique_ptr<const ContentAction>> actions; |
| 116 int priority; | 116 int priority; |
| 117 | 117 |
| 118 private: | 118 private: |
| 119 DISALLOW_COPY_AND_ASSIGN(ContentRule); | 119 DISALLOW_COPY_AND_ASSIGN(ContentRule); |
| 120 }; | 120 }; |
| 121 | 121 |
| 122 // Specifies what to do with evaluation requests. | 122 // Specifies what to do with evaluation requests. |
| 123 // TODO(wittman): Try to eliminate the need for IGNORE after refactoring to | 123 // TODO(wittman): Try to eliminate the need for IGNORE after refactoring to |
| 124 // treat all condition evaluation consistently. | 124 // treat all condition evaluation consistently. |
| 125 enum EvaluationDisposition { | 125 enum EvaluationDisposition { |
| 126 EVALUATE_REQUESTS, // Evaluate immediately. | 126 EVALUATE_REQUESTS, // Evaluate immediately. |
| 127 DEFER_REQUESTS, // Defer for later evaluation. | 127 DEFER_REQUESTS, // Defer for later evaluation. |
| 128 IGNORE_REQUESTS // Ignore. | 128 IGNORE_REQUESTS // Ignore. |
| 129 }; | 129 }; |
| 130 | 130 |
| 131 class EvaluationScope; | 131 class EvaluationScope; |
| 132 | 132 |
| 133 // Creates a ContentRule for |extension| given a json definition. The format | 133 // Creates a ContentRule for |extension| given a json definition. The format |
| 134 // of each condition and action's json is up to the specific ContentCondition | 134 // of each condition and action's json is up to the specific ContentCondition |
| 135 // and ContentAction. |extension| may be NULL in tests. If |error| is empty, | 135 // and ContentAction. |extension| may be NULL in tests. If |error| is empty, |
| 136 // the translation was successful and the returned rule is internally | 136 // the translation was successful and the returned rule is internally |
| 137 // consistent. | 137 // consistent. |
| 138 scoped_ptr<const ContentRule> CreateRule( | 138 std::unique_ptr<const ContentRule> CreateRule( |
| 139 const Extension* extension, | 139 const Extension* extension, |
| 140 const std::map<std::string, ContentPredicateFactory*>& | 140 const std::map<std::string, ContentPredicateFactory*>& |
| 141 predicate_factories, | 141 predicate_factories, |
| 142 const api::events::Rule& api_rule, | 142 const api::events::Rule& api_rule, |
| 143 std::string* error); | 143 std::string* error); |
| 144 | 144 |
| 145 // True if this object is managing the rules for |context|. | 145 // True if this object is managing the rules for |context|. |
| 146 bool ManagingRulesForBrowserContext(content::BrowserContext* context); | 146 bool ManagingRulesForBrowserContext(content::BrowserContext* context); |
| 147 | 147 |
| 148 // True if |condition| matches on |tab|. | 148 // True if |condition| matches on |tab|. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 168 RulesMap content_rules_; | 168 RulesMap content_rules_; |
| 169 | 169 |
| 170 // Maps a WebContents to the set of rules that match on that WebContents. | 170 // Maps a WebContents to the set of rules that match on that WebContents. |
| 171 // This lets us call Revert as appropriate. Note that this is expected to have | 171 // This lets us call Revert as appropriate. Note that this is expected to have |
| 172 // a key-value pair for every WebContents the registry is tracking, even if | 172 // a key-value pair for every WebContents the registry is tracking, even if |
| 173 // the value is the empty set. | 173 // the value is the empty set. |
| 174 std::map<content::WebContents*, std::set<const ContentRule*>> active_rules_; | 174 std::map<content::WebContents*, std::set<const ContentRule*>> active_rules_; |
| 175 | 175 |
| 176 // The evaluators responsible for creating predicates and tracking | 176 // The evaluators responsible for creating predicates and tracking |
| 177 // predicate-related state. | 177 // predicate-related state. |
| 178 std::vector<scoped_ptr<ContentPredicateEvaluator>> evaluators_; | 178 std::vector<std::unique_ptr<ContentPredicateEvaluator>> evaluators_; |
| 179 | 179 |
| 180 // Specifies what to do with evaluation requests. | 180 // Specifies what to do with evaluation requests. |
| 181 EvaluationDisposition evaluation_disposition_; | 181 EvaluationDisposition evaluation_disposition_; |
| 182 | 182 |
| 183 // Contains WebContents which require rule evaluation. Only used while | 183 // Contains WebContents which require rule evaluation. Only used while |
| 184 // |evaluation_disposition_| is DEFER. | 184 // |evaluation_disposition_| is DEFER. |
| 185 std::set<content::WebContents*> evaluation_pending_; | 185 std::set<content::WebContents*> evaluation_pending_; |
| 186 | 186 |
| 187 // Manages our notification registrations. | 187 // Manages our notification registrations. |
| 188 content::NotificationRegistrar registrar_; | 188 content::NotificationRegistrar registrar_; |
| 189 | 189 |
| 190 DISALLOW_COPY_AND_ASSIGN(ChromeContentRulesRegistry); | 190 DISALLOW_COPY_AND_ASSIGN(ChromeContentRulesRegistry); |
| 191 }; | 191 }; |
| 192 | 192 |
| 193 } // namespace extensions | 193 } // namespace extensions |
| 194 | 194 |
| 195 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CHROME_CONTENT_RULE
S_REGISTRY_H_ | 195 #endif // CHROME_BROWSER_EXTENSIONS_API_DECLARATIVE_CONTENT_CHROME_CONTENT_RULE
S_REGISTRY_H_ |
| OLD | NEW |