| 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 #include "chrome/browser/extensions/api/declarative_content/chrome_content_rules
_registry.h" | 5 #include "chrome/browser/extensions/api/declarative_content/chrome_content_rules
_registry.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/extensions/api/declarative_content/content_action.h" | 10 #include "chrome/browser/extensions/api/declarative_content/content_action.h" |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 : extension(extension), | 168 : extension(extension), |
| 169 conditions(conditions.Pass()), | 169 conditions(conditions.Pass()), |
| 170 actions(actions.Pass()), | 170 actions(actions.Pass()), |
| 171 priority(priority) { | 171 priority(priority) { |
| 172 } | 172 } |
| 173 | 173 |
| 174 ChromeContentRulesRegistry::ContentRule::~ContentRule() {} | 174 ChromeContentRulesRegistry::ContentRule::~ContentRule() {} |
| 175 | 175 |
| 176 scoped_ptr<const ChromeContentRulesRegistry::ContentRule> | 176 scoped_ptr<const ChromeContentRulesRegistry::ContentRule> |
| 177 ChromeContentRulesRegistry::CreateRule(const Extension* extension, | 177 ChromeContentRulesRegistry::CreateRule(const Extension* extension, |
| 178 const core_api::events::Rule& api_rule, | 178 const api::events::Rule& api_rule, |
| 179 std::string* error) { | 179 std::string* error) { |
| 180 ScopedVector<const ContentCondition> conditions; | 180 ScopedVector<const ContentCondition> conditions; |
| 181 for (const linked_ptr<base::Value>& value : api_rule.conditions) { | 181 for (const linked_ptr<base::Value>& value : api_rule.conditions) { |
| 182 conditions.push_back( | 182 conditions.push_back( |
| 183 ContentCondition::Create( | 183 ContentCondition::Create( |
| 184 extension, | 184 extension, |
| 185 page_url_condition_tracker_.condition_factory(), | 185 page_url_condition_tracker_.condition_factory(), |
| 186 *value, | 186 *value, |
| 187 error)); | 187 error)); |
| 188 if (!error->empty()) | 188 if (!error->empty()) |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 | 253 |
| 254 const ContentCondition* condition = rule_condition_pair.second; | 254 const ContentCondition* condition = rule_condition_pair.second; |
| 255 if (condition->IsFulfilled(renderer_data)) | 255 if (condition->IsFulfilled(renderer_data)) |
| 256 matching_rules.insert(rule); | 256 matching_rules.insert(rule); |
| 257 } | 257 } |
| 258 return matching_rules; | 258 return matching_rules; |
| 259 } | 259 } |
| 260 | 260 |
| 261 std::string ChromeContentRulesRegistry::AddRulesImpl( | 261 std::string ChromeContentRulesRegistry::AddRulesImpl( |
| 262 const std::string& extension_id, | 262 const std::string& extension_id, |
| 263 const std::vector<linked_ptr<core_api::events::Rule>>& rules) { | 263 const std::vector<linked_ptr<api::events::Rule>>& rules) { |
| 264 EvaluationScope evaluation_scope(this); | 264 EvaluationScope evaluation_scope(this); |
| 265 const Extension* extension = ExtensionRegistry::Get(browser_context()) | 265 const Extension* extension = ExtensionRegistry::Get(browser_context()) |
| 266 ->GetInstalledExtension(extension_id); | 266 ->GetInstalledExtension(extension_id); |
| 267 DCHECK(extension) << "Must have extension with id " << extension_id; | 267 DCHECK(extension) << "Must have extension with id " << extension_id; |
| 268 | 268 |
| 269 std::string error; | 269 std::string error; |
| 270 RulesMap new_content_rules; | 270 RulesMap new_content_rules; |
| 271 | 271 |
| 272 for (const linked_ptr<core_api::events::Rule>& rule : rules) { | 272 for (const linked_ptr<api::events::Rule>& rule : rules) { |
| 273 ExtensionRuleIdPair rule_id(extension, *rule->id); | 273 ExtensionRuleIdPair rule_id(extension, *rule->id); |
| 274 DCHECK(content_rules_.find(rule_id) == content_rules_.end()); | 274 DCHECK(content_rules_.find(rule_id) == content_rules_.end()); |
| 275 | 275 |
| 276 scoped_ptr<const ContentRule> content_rule(CreateRule( | 276 scoped_ptr<const ContentRule> content_rule(CreateRule( |
| 277 extension, | 277 extension, |
| 278 *rule, | 278 *rule, |
| 279 &error)); | 279 &error)); |
| 280 if (!error.empty()) { | 280 if (!error.empty()) { |
| 281 // Clean up temporary condition sets created during rule creation. | 281 // Clean up temporary condition sets created during rule creation. |
| 282 page_url_condition_tracker_.ClearUnusedConditionSets(); | 282 page_url_condition_tracker_.ClearUnusedConditionSets(); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 size_t count = 0; | 455 size_t count = 0; |
| 456 for (auto web_contents_rules_pair : active_rules_) | 456 for (auto web_contents_rules_pair : active_rules_) |
| 457 count += web_contents_rules_pair.second.size(); | 457 count += web_contents_rules_pair.second.size(); |
| 458 return count; | 458 return count; |
| 459 } | 459 } |
| 460 | 460 |
| 461 ChromeContentRulesRegistry::~ChromeContentRulesRegistry() { | 461 ChromeContentRulesRegistry::~ChromeContentRulesRegistry() { |
| 462 } | 462 } |
| 463 | 463 |
| 464 } // namespace extensions | 464 } // namespace extensions |
| OLD | NEW |