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

Side by Side Diff: chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_registry.cc

Issue 535203003: Replace Profile* in declarative_api with BrowserContext* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove changes to unit-test; those have to wait until move. Created 6 years, 3 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
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 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_ registry.h" 5 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_ registry.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condit ion.h" 13 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_condit ion.h"
14 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_consta nts.h" 14 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_consta nts.h"
15 #include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h" 15 #include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h"
16 #include "chrome/browser/extensions/api/web_request/web_request_permissions.h" 16 #include "chrome/browser/extensions/api/web_request/web_request_permissions.h"
17 #include "chrome/browser/profiles/profile.h"
18 #include "extensions/browser/extension_system.h" 17 #include "extensions/browser/extension_system.h"
19 #include "extensions/common/error_utils.h" 18 #include "extensions/common/error_utils.h"
20 #include "extensions/common/extension.h" 19 #include "extensions/common/extension.h"
21 #include "extensions/common/permissions/permissions_data.h" 20 #include "extensions/common/permissions/permissions_data.h"
22 #include "net/url_request/url_request.h" 21 #include "net/url_request/url_request.h"
23 22
24 using url_matcher::URLMatcherConditionSet; 23 using url_matcher::URLMatcherConditionSet;
25 24
26 namespace { 25 namespace {
27 26
28 const char kActionCannotBeExecuted[] = "The action '*' can never be executed " 27 const char kActionCannotBeExecuted[] = "The action '*' can never be executed "
29 "because there are is no time in the request life-cycle during which the " 28 "because there are is no time in the request life-cycle during which the "
30 "conditions can be checked and the action can possibly be executed."; 29 "conditions can be checked and the action can possibly be executed.";
31 30
32 const char kAllURLsPermissionNeeded[] = 31 const char kAllURLsPermissionNeeded[] =
33 "To execute the action '*', you need to request host permission for all " 32 "To execute the action '*', you need to request host permission for all "
34 "hosts."; 33 "hosts.";
35 34
36 } // namespace 35 } // namespace
37 36
38 namespace extensions { 37 namespace extensions {
39 38
40 WebRequestRulesRegistry::WebRequestRulesRegistry( 39 WebRequestRulesRegistry::WebRequestRulesRegistry(
41 Profile* profile, 40 content::BrowserContext* browser_context,
42 RulesCacheDelegate* cache_delegate, 41 RulesCacheDelegate* cache_delegate,
43 const WebViewKey& webview_key) 42 const WebViewKey& webview_key)
44 : RulesRegistry(profile, 43 : RulesRegistry(browser_context,
45 declarative_webrequest_constants::kOnRequest, 44 declarative_webrequest_constants::kOnRequest,
46 content::BrowserThread::IO, 45 content::BrowserThread::IO,
47 cache_delegate, 46 cache_delegate,
48 webview_key), 47 webview_key),
49 profile_id_(profile) { 48 browser_context_(browser_context) {
50 if (profile) 49 if (browser_context_)
51 extension_info_map_ = ExtensionSystem::Get(profile)->info_map(); 50 extension_info_map_ = ExtensionSystem::Get(browser_context_)->info_map();
52 } 51 }
53 52
54 std::set<const WebRequestRule*> WebRequestRulesRegistry::GetMatches( 53 std::set<const WebRequestRule*> WebRequestRulesRegistry::GetMatches(
55 const WebRequestData& request_data_without_ids) const { 54 const WebRequestData& request_data_without_ids) const {
56 RuleSet result; 55 RuleSet result;
57 56
58 WebRequestDataWithMatchIds request_data(&request_data_without_ids); 57 WebRequestDataWithMatchIds request_data(&request_data_without_ids);
59 request_data.url_match_ids = url_matcher_.MatchURL( 58 request_data.url_match_ids = url_matcher_.MatchURL(
60 request_data.data->request->url()); 59 request_data.data->request->url());
61 request_data.first_party_url_match_ids = url_matcher_.MatchURL( 60 request_data.first_party_url_match_ids = url_matcher_.MatchURL(
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 extension_info_map_->extensions().GetByID(extension_id); 174 extension_info_map_->extensions().GetByID(extension_id);
176 RulesMap& registered_rules = webrequest_rules_[extension_id]; 175 RulesMap& registered_rules = webrequest_rules_[extension_id];
177 176
178 for (std::vector<linked_ptr<RulesRegistry::Rule> >::const_iterator rule = 177 for (std::vector<linked_ptr<RulesRegistry::Rule> >::const_iterator rule =
179 rules.begin(); rule != rules.end(); ++rule) { 178 rules.begin(); rule != rules.end(); ++rule) {
180 const WebRequestRule::RuleId& rule_id(*(*rule)->id); 179 const WebRequestRule::RuleId& rule_id(*(*rule)->id);
181 DCHECK(registered_rules.find(rule_id) == registered_rules.end()); 180 DCHECK(registered_rules.find(rule_id) == registered_rules.end());
182 181
183 scoped_ptr<WebRequestRule> webrequest_rule(WebRequestRule::Create( 182 scoped_ptr<WebRequestRule> webrequest_rule(WebRequestRule::Create(
184 url_matcher_.condition_factory(), 183 url_matcher_.condition_factory(),
185 profile(), extension, extension_installation_time, *rule, 184 browser_context(), extension, extension_installation_time, *rule,
186 base::Bind(&Checker, base::Unretained(extension)), 185 base::Bind(&Checker, base::Unretained(extension)),
187 &error)); 186 &error));
188 if (!error.empty()) { 187 if (!error.empty()) {
189 // We don't return here, because we want to clear temporary 188 // We don't return here, because we want to clear temporary
190 // condition sets in the url_matcher_. 189 // condition sets in the url_matcher_.
191 break; 190 break;
192 } 191 }
193 192
194 new_webrequest_rules.push_back( 193 new_webrequest_rules.push_back(
195 IdRulePair(rule_id, make_linked_ptr(webrequest_rule.release()))); 194 IdRulePair(rule_id, make_linked_ptr(webrequest_rule.release())));
(...skipping 27 matching lines...) Expand all
223 for (RulesVector::const_iterator i = new_webrequest_rules.begin(); 222 for (RulesVector::const_iterator i = new_webrequest_rules.begin();
224 i != new_webrequest_rules.end(); ++i) { 223 i != new_webrequest_rules.end(); ++i) {
225 i->second->conditions().GetURLMatcherConditionSets(&all_new_condition_sets); 224 i->second->conditions().GetURLMatcherConditionSets(&all_new_condition_sets);
226 if (i->second->conditions().HasConditionsWithoutUrls()) 225 if (i->second->conditions().HasConditionsWithoutUrls())
227 rules_with_untriggered_conditions_.insert(i->second.get()); 226 rules_with_untriggered_conditions_.insert(i->second.get());
228 } 227 }
229 url_matcher_.AddConditionSets(all_new_condition_sets); 228 url_matcher_.AddConditionSets(all_new_condition_sets);
230 229
231 ClearCacheOnNavigation(); 230 ClearCacheOnNavigation();
232 231
233 if (profile_id_ && !registered_rules.empty()) { 232 if (browser_context_ && !registered_rules.empty()) {
234 content::BrowserThread::PostTask( 233 content::BrowserThread::PostTask(
235 content::BrowserThread::UI, FROM_HERE, 234 content::BrowserThread::UI, FROM_HERE,
236 base::Bind(&extension_web_request_api_helpers::NotifyWebRequestAPIUsed, 235 base::Bind(&extension_web_request_api_helpers::NotifyWebRequestAPIUsed,
237 profile_id_, make_scoped_refptr(extension))); 236 browser_context_, make_scoped_refptr(extension)));
238 } 237 }
239 238
240 return std::string(); 239 return std::string();
241 } 240 }
242 241
243 std::string WebRequestRulesRegistry::RemoveRulesImpl( 242 std::string WebRequestRulesRegistry::RemoveRulesImpl(
244 const std::string& extension_id, 243 const std::string& extension_id,
245 const std::vector<std::string>& rule_identifiers) { 244 const std::vector<std::string>& rule_identifiers) {
246 // URLMatcherConditionSet IDs that can be removed from URLMatcher. 245 // URLMatcherConditionSet IDs that can be removed from URLMatcher.
247 std::vector<URLMatcherConditionSet::ID> remove_from_url_matcher; 246 std::vector<URLMatcherConditionSet::ID> remove_from_url_matcher;
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 RuleTriggers::const_iterator rule_trigger = rule_triggers_.find(*url_match); 403 RuleTriggers::const_iterator rule_trigger = rule_triggers_.find(*url_match);
405 CHECK(rule_trigger != rule_triggers_.end()); 404 CHECK(rule_trigger != rule_triggers_.end());
406 if (!ContainsKey(*result, rule_trigger->second) && 405 if (!ContainsKey(*result, rule_trigger->second) &&
407 rule_trigger->second->conditions().IsFulfilled(*url_match, 406 rule_trigger->second->conditions().IsFulfilled(*url_match,
408 request_data)) 407 request_data))
409 result->insert(rule_trigger->second); 408 result->insert(rule_trigger->second);
410 } 409 }
411 } 410 }
412 411
413 } // namespace extensions 412 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698