| 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 "extensions/browser/api/web_request/web_request_api.h" | 5 #include "extensions/browser/api/web_request/web_request_api.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "content/public/browser/browser_message_filter.h" | 19 #include "content/public/browser/browser_message_filter.h" |
| 20 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/render_frame_host.h" | 21 #include "content/public/browser/render_frame_host.h" |
| 22 #include "content/public/browser/render_process_host.h" | 22 #include "content/public/browser/render_process_host.h" |
| 23 #include "content/public/browser/resource_request_info.h" | 23 #include "content/public/browser/resource_request_info.h" |
| 24 #include "content/public/browser/user_metrics.h" | 24 #include "content/public/browser/user_metrics.h" |
| 25 #include "extensions/browser/api/activity_log/web_request_constants.h" | 25 #include "extensions/browser/api/activity_log/web_request_constants.h" |
| 26 #include "extensions/browser/api/declarative/rules_registry_service.h" |
| 26 #include "extensions/browser/api/declarative_webrequest/request_stage.h" | 27 #include "extensions/browser/api/declarative_webrequest/request_stage.h" |
| 27 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" | 28 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" |
| 28 #include "extensions/browser/api/declarative_webrequest/webrequest_rules_registr
y.h" | 29 #include "extensions/browser/api/declarative_webrequest/webrequest_rules_registr
y.h" |
| 29 #include "extensions/browser/api/extensions_api_client.h" | 30 #include "extensions/browser/api/extensions_api_client.h" |
| 30 #include "extensions/browser/api/web_request/upload_data_presenter.h" | 31 #include "extensions/browser/api/web_request/upload_data_presenter.h" |
| 31 #include "extensions/browser/api/web_request/web_request_api_constants.h" | 32 #include "extensions/browser/api/web_request/web_request_api_constants.h" |
| 32 #include "extensions/browser/api/web_request/web_request_api_helpers.h" | 33 #include "extensions/browser/api/web_request/web_request_api_helpers.h" |
| 33 #include "extensions/browser/api/web_request/web_request_event_router_delegate.h
" | 34 #include "extensions/browser/api/web_request/web_request_event_router_delegate.h
" |
| 34 #include "extensions/browser/api/web_request/web_request_time_tracker.h" | 35 #include "extensions/browser/api/web_request/web_request_time_tracker.h" |
| 35 #include "extensions/browser/event_router.h" | 36 #include "extensions/browser/event_router.h" |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 web_request_event_router_delegate_.reset( | 655 web_request_event_router_delegate_.reset( |
| 655 extensions::ExtensionsAPIClient::Get()-> | 656 extensions::ExtensionsAPIClient::Get()-> |
| 656 CreateWebRequestEventRouterDelegate()); | 657 CreateWebRequestEventRouterDelegate()); |
| 657 } | 658 } |
| 658 | 659 |
| 659 ExtensionWebRequestEventRouter::~ExtensionWebRequestEventRouter() { | 660 ExtensionWebRequestEventRouter::~ExtensionWebRequestEventRouter() { |
| 660 } | 661 } |
| 661 | 662 |
| 662 void ExtensionWebRequestEventRouter::RegisterRulesRegistry( | 663 void ExtensionWebRequestEventRouter::RegisterRulesRegistry( |
| 663 void* browser_context, | 664 void* browser_context, |
| 664 const extensions::RulesRegistry::WebViewKey& webview_key, | 665 int rules_registry_id, |
| 665 scoped_refptr<extensions::WebRequestRulesRegistry> rules_registry) { | 666 scoped_refptr<extensions::WebRequestRulesRegistry> rules_registry) { |
| 666 RulesRegistryKey key(browser_context, webview_key); | 667 RulesRegistryKey key(browser_context, rules_registry_id); |
| 667 if (rules_registry.get()) | 668 if (rules_registry.get()) |
| 668 rules_registries_[key] = rules_registry; | 669 rules_registries_[key] = rules_registry; |
| 669 else | 670 else |
| 670 rules_registries_.erase(key); | 671 rules_registries_.erase(key); |
| 671 } | 672 } |
| 672 | 673 |
| 673 void ExtensionWebRequestEventRouter::ExtractRequestInfo( | 674 void ExtensionWebRequestEventRouter::ExtractRequestInfo( |
| 674 net::URLRequest* request, base::DictionaryValue* out) { | 675 net::URLRequest* request, base::DictionaryValue* out) { |
| 675 bool is_main_frame = false; | 676 bool is_main_frame = false; |
| 676 int frame_id = -1; | 677 int frame_id = -1; |
| (...skipping 1282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1959 | 1960 |
| 1960 bool ExtensionWebRequestEventRouter::ProcessDeclarativeRules( | 1961 bool ExtensionWebRequestEventRouter::ProcessDeclarativeRules( |
| 1961 void* browser_context, | 1962 void* browser_context, |
| 1962 InfoMap* extension_info_map, | 1963 InfoMap* extension_info_map, |
| 1963 const std::string& event_name, | 1964 const std::string& event_name, |
| 1964 net::URLRequest* request, | 1965 net::URLRequest* request, |
| 1965 extensions::RequestStage request_stage, | 1966 extensions::RequestStage request_stage, |
| 1966 const net::HttpResponseHeaders* original_response_headers) { | 1967 const net::HttpResponseHeaders* original_response_headers) { |
| 1967 extensions::WebViewRendererState::WebViewInfo web_view_info; | 1968 extensions::WebViewRendererState::WebViewInfo web_view_info; |
| 1968 bool is_web_view_guest = GetWebViewInfo(request, &web_view_info); | 1969 bool is_web_view_guest = GetWebViewInfo(request, &web_view_info); |
| 1970 int rules_registry_id = is_web_view_guest |
| 1971 ? web_view_info.rules_registry_id |
| 1972 : RulesRegistryService::kDefaultRulesRegistryID; |
| 1969 | 1973 |
| 1970 extensions::RulesRegistry::WebViewKey webview_key( | 1974 RulesRegistryKey rules_key(browser_context, rules_registry_id); |
| 1971 is_web_view_guest ? web_view_info.embedder_process_id : 0, | |
| 1972 is_web_view_guest ? web_view_info.instance_id : 0); | |
| 1973 RulesRegistryKey rules_key(browser_context, webview_key); | |
| 1974 // If this check fails, check that the active stages are up-to-date in | 1975 // If this check fails, check that the active stages are up-to-date in |
| 1975 // extensions/browser/api/declarative_webrequest/request_stage.h . | 1976 // extensions/browser/api/declarative_webrequest/request_stage.h . |
| 1976 DCHECK(request_stage & extensions::kActiveStages); | 1977 DCHECK(request_stage & extensions::kActiveStages); |
| 1977 | 1978 |
| 1978 // Rules of the current |browser_context| may apply but we need to check also | 1979 // Rules of the current |browser_context| may apply but we need to check also |
| 1979 // whether there are applicable rules from extensions whose background page | 1980 // whether there are applicable rules from extensions whose background page |
| 1980 // spans from regular to incognito mode. | 1981 // spans from regular to incognito mode. |
| 1981 | 1982 |
| 1982 // First parameter identifies the registry, the second indicates whether the | 1983 // First parameter identifies the registry, the second indicates whether the |
| 1983 // registry belongs to the cross browser_context. | 1984 // registry belongs to the cross browser_context. |
| 1984 typedef std::pair<extensions::WebRequestRulesRegistry*, bool> | 1985 typedef std::pair<extensions::WebRequestRulesRegistry*, bool> |
| 1985 RelevantRegistry; | 1986 RelevantRegistry; |
| 1986 typedef std::vector<RelevantRegistry> RelevantRegistries; | 1987 typedef std::vector<RelevantRegistry> RelevantRegistries; |
| 1987 RelevantRegistries relevant_registries; | 1988 RelevantRegistries relevant_registries; |
| 1988 | 1989 |
| 1989 if (rules_registries_.find(rules_key) != rules_registries_.end()) { | 1990 if (rules_registries_.find(rules_key) != rules_registries_.end()) { |
| 1990 relevant_registries.push_back( | 1991 relevant_registries.push_back( |
| 1991 std::make_pair(rules_registries_[rules_key].get(), false)); | 1992 std::make_pair(rules_registries_[rules_key].get(), false)); |
| 1992 } | 1993 } |
| 1993 | 1994 |
| 1994 void* cross_browser_context = GetCrossBrowserContext(browser_context); | 1995 void* cross_browser_context = GetCrossBrowserContext(browser_context); |
| 1995 RulesRegistryKey cross_browser_context_rules_key( | 1996 RulesRegistryKey cross_browser_context_rules_key(cross_browser_context, |
| 1996 cross_browser_context, webview_key); | 1997 rules_registry_id); |
| 1997 if (cross_browser_context && | 1998 if (cross_browser_context && |
| 1998 rules_registries_.find(cross_browser_context_rules_key) != | 1999 rules_registries_.find(cross_browser_context_rules_key) != |
| 1999 rules_registries_.end()) { | 2000 rules_registries_.end()) { |
| 2000 relevant_registries.push_back( | 2001 relevant_registries.push_back( |
| 2001 std::make_pair( | 2002 std::make_pair( |
| 2002 rules_registries_[cross_browser_context_rules_key].get(), true)); | 2003 rules_registries_[cross_browser_context_rules_key].get(), true)); |
| 2003 } | 2004 } |
| 2004 | 2005 |
| 2005 // The following block is experimentally enabled and its impact on load time | 2006 // The following block is experimentally enabled and its impact on load time |
| 2006 // logged with UMA Extensions.NetworkDelayRegistryLoad. crbug.com/175961 | 2007 // logged with UMA Extensions.NetworkDelayRegistryLoad. crbug.com/175961 |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2453 base::Bind(&WarningService::NotifyWarningsOnUI, profile_id(), warnings)); | 2454 base::Bind(&WarningService::NotifyWarningsOnUI, profile_id(), warnings)); |
| 2454 | 2455 |
| 2455 // Continue gracefully. | 2456 // Continue gracefully. |
| 2456 RunSync(); | 2457 RunSync(); |
| 2457 } | 2458 } |
| 2458 | 2459 |
| 2459 bool WebRequestHandlerBehaviorChangedFunction::RunSync() { | 2460 bool WebRequestHandlerBehaviorChangedFunction::RunSync() { |
| 2460 helpers::ClearCacheOnNavigation(); | 2461 helpers::ClearCacheOnNavigation(); |
| 2461 return true; | 2462 return true; |
| 2462 } | 2463 } |
| OLD | NEW |