| 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/web_request/web_request_api.h" | 5 #include "chrome/browser/extensions/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" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 using chrome::VersionInfo; | 70 using chrome::VersionInfo; |
| 71 using content::BrowserMessageFilter; | 71 using content::BrowserMessageFilter; |
| 72 using content::BrowserThread; | 72 using content::BrowserThread; |
| 73 using content::ResourceRequestInfo; | 73 using content::ResourceRequestInfo; |
| 74 using extensions::ErrorUtils; | 74 using extensions::ErrorUtils; |
| 75 using extensions::Extension; | 75 using extensions::Extension; |
| 76 using extensions::ExtensionWarning; | 76 using extensions::ExtensionWarning; |
| 77 using extensions::ExtensionWarningService; | 77 using extensions::ExtensionWarningService; |
| 78 using extensions::ExtensionWarningSet; | 78 using extensions::ExtensionWarningSet; |
| 79 using extensions::Feature; | 79 using extensions::Feature; |
| 80 using extensions::RulesRegistryService; |
| 80 using extensions::web_navigation_api_helpers::GetFrameId; | 81 using extensions::web_navigation_api_helpers::GetFrameId; |
| 81 | 82 |
| 82 namespace helpers = extension_web_request_api_helpers; | 83 namespace helpers = extension_web_request_api_helpers; |
| 83 namespace keys = extension_web_request_api_constants; | 84 namespace keys = extension_web_request_api_constants; |
| 84 namespace web_request = extensions::api::web_request; | 85 namespace web_request = extensions::api::web_request; |
| 85 namespace declarative_keys = extensions::declarative_webrequest_constants; | 86 namespace declarative_keys = extensions::declarative_webrequest_constants; |
| 86 namespace activitylog = activity_log_web_request_constants; | 87 namespace activitylog = activity_log_web_request_constants; |
| 87 | 88 |
| 88 namespace { | 89 namespace { |
| 89 | 90 |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 | 593 |
| 593 ExtensionWebRequestEventRouter::ExtensionWebRequestEventRouter() | 594 ExtensionWebRequestEventRouter::ExtensionWebRequestEventRouter() |
| 594 : request_time_tracker_(new ExtensionWebRequestTimeTracker) { | 595 : request_time_tracker_(new ExtensionWebRequestTimeTracker) { |
| 595 } | 596 } |
| 596 | 597 |
| 597 ExtensionWebRequestEventRouter::~ExtensionWebRequestEventRouter() { | 598 ExtensionWebRequestEventRouter::~ExtensionWebRequestEventRouter() { |
| 598 } | 599 } |
| 599 | 600 |
| 600 void ExtensionWebRequestEventRouter::RegisterRulesRegistry( | 601 void ExtensionWebRequestEventRouter::RegisterRulesRegistry( |
| 601 void* profile, | 602 void* profile, |
| 603 const RulesRegistryService::WebViewKey& webview_key, |
| 602 scoped_refptr<extensions::WebRequestRulesRegistry> rules_registry) { | 604 scoped_refptr<extensions::WebRequestRulesRegistry> rules_registry) { |
| 605 RulesRegistryKey key(profile, webview_key); |
| 603 if (rules_registry.get()) | 606 if (rules_registry.get()) |
| 604 rules_registries_[profile] = rules_registry; | 607 rules_registries_[key] = rules_registry; |
| 605 else | 608 else |
| 606 rules_registries_.erase(profile); | 609 rules_registries_.erase(key); |
| 607 } | 610 } |
| 608 | 611 |
| 609 int ExtensionWebRequestEventRouter::OnBeforeRequest( | 612 int ExtensionWebRequestEventRouter::OnBeforeRequest( |
| 610 void* profile, | 613 void* profile, |
| 611 ExtensionInfoMap* extension_info_map, | 614 ExtensionInfoMap* extension_info_map, |
| 612 net::URLRequest* request, | 615 net::URLRequest* request, |
| 613 const net::CompletionCallback& callback, | 616 const net::CompletionCallback& callback, |
| 614 GURL* new_url) { | 617 GURL* new_url) { |
| 615 // We hide events from the system context as well as sensitive requests. | 618 // We hide events from the system context as well as sensitive requests. |
| 616 if (!profile || | 619 if (!profile || |
| (...skipping 1230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1847 return rv; | 1850 return rv; |
| 1848 } | 1851 } |
| 1849 | 1852 |
| 1850 bool ExtensionWebRequestEventRouter::ProcessDeclarativeRules( | 1853 bool ExtensionWebRequestEventRouter::ProcessDeclarativeRules( |
| 1851 void* profile, | 1854 void* profile, |
| 1852 ExtensionInfoMap* extension_info_map, | 1855 ExtensionInfoMap* extension_info_map, |
| 1853 const std::string& event_name, | 1856 const std::string& event_name, |
| 1854 net::URLRequest* request, | 1857 net::URLRequest* request, |
| 1855 extensions::RequestStage request_stage, | 1858 extensions::RequestStage request_stage, |
| 1856 const net::HttpResponseHeaders* original_response_headers) { | 1859 const net::HttpResponseHeaders* original_response_headers) { |
| 1860 bool is_main_frame = false; |
| 1861 int64 frame_id = -1; |
| 1862 bool parent_is_main_frame = false; |
| 1863 int64 parent_frame_id = -1; |
| 1864 int tab_id = -1; |
| 1865 int window_id = -1; |
| 1866 int render_process_host_id = -1; |
| 1867 int routing_id = -1; |
| 1868 ResourceType::Type resource_type = ResourceType::LAST_TYPE; |
| 1869 |
| 1870 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id, |
| 1871 &parent_is_main_frame, &parent_frame_id, |
| 1872 &tab_id, &window_id, &render_process_host_id, |
| 1873 &routing_id, &resource_type); |
| 1874 ExtensionRendererState::WebViewInfo webview_info; |
| 1875 bool is_guest = ExtensionRendererState::GetInstance()-> |
| 1876 GetWebViewInfo(render_process_host_id, routing_id, &webview_info); |
| 1877 |
| 1878 RulesRegistryService::WebViewKey webview_key( |
| 1879 is_guest ? webview_info.embedder_process_id : 0, |
| 1880 is_guest ? webview_info.instance_id : 0); |
| 1881 RulesRegistryKey rules_key(profile, webview_key); |
| 1882 |
| 1857 // If this check fails, check that the active stages are up-to-date in | 1883 // If this check fails, check that the active stages are up-to-date in |
| 1858 // browser/extensions/api/declarative_webrequest/request_stage.h . | 1884 // browser/extensions/api/declarative_webrequest/request_stage.h . |
| 1859 DCHECK(request_stage & extensions::kActiveStages); | 1885 DCHECK(request_stage & extensions::kActiveStages); |
| 1860 | 1886 |
| 1861 // Rules of the current |profile| may apply but we need to check also whether | 1887 // Rules of the current |profile| may apply but we need to check also whether |
| 1862 // there are applicable rules from extensions whose background page | 1888 // there are applicable rules from extensions whose background page |
| 1863 // spans from regular to incognito mode. | 1889 // spans from regular to incognito mode. |
| 1864 | 1890 |
| 1865 // First parameter identifies the registry, the second indicates whether the | 1891 // First parameter identifies the registry, the second indicates whether the |
| 1866 // registry belongs to the cross profile. | 1892 // registry belongs to the cross profile. |
| 1867 typedef std::pair<extensions::WebRequestRulesRegistry*, bool> | 1893 typedef std::pair<extensions::WebRequestRulesRegistry*, bool> |
| 1868 RelevantRegistry; | 1894 RelevantRegistry; |
| 1869 typedef std::vector<RelevantRegistry> RelevantRegistries; | 1895 typedef std::vector<RelevantRegistry> RelevantRegistries; |
| 1870 RelevantRegistries relevant_registries; | 1896 RelevantRegistries relevant_registries; |
| 1871 | 1897 |
| 1872 if (rules_registries_.find(profile) != rules_registries_.end()) { | 1898 if (rules_registries_.find(rules_key) != rules_registries_.end()) { |
| 1873 relevant_registries.push_back( | 1899 relevant_registries.push_back( |
| 1874 std::make_pair(rules_registries_[profile].get(), false)); | 1900 std::make_pair(rules_registries_[rules_key].get(), false)); |
| 1875 } | 1901 } |
| 1876 | 1902 |
| 1877 void* cross_profile = GetCrossProfile(profile); | 1903 void* cross_profile = GetCrossProfile(profile); |
| 1904 RulesRegistryKey cross_profile_rules_key(cross_profile, webview_key); |
| 1878 if (cross_profile && | 1905 if (cross_profile && |
| 1879 rules_registries_.find(cross_profile) != rules_registries_.end()) { | 1906 rules_registries_.find(cross_profile_rules_key) != |
| 1907 rules_registries_.end()) { |
| 1880 relevant_registries.push_back( | 1908 relevant_registries.push_back( |
| 1881 std::make_pair(rules_registries_[cross_profile].get(), true)); | 1909 std::make_pair(rules_registries_[cross_profile_rules_key].get(), true)); |
| 1882 } | 1910 } |
| 1883 | 1911 |
| 1884 // The following block is experimentally enabled and its impact on load time | 1912 // The following block is experimentally enabled and its impact on load time |
| 1885 // logged with UMA Extensions.NetworkDelayRegistryLoad. crbug.com/175961 | 1913 // logged with UMA Extensions.NetworkDelayRegistryLoad. crbug.com/175961 |
| 1886 for (RelevantRegistries::iterator i = relevant_registries.begin(); | 1914 for (RelevantRegistries::iterator i = relevant_registries.begin(); |
| 1887 i != relevant_registries.end(); ++i) { | 1915 i != relevant_registries.end(); ++i) { |
| 1888 extensions::WebRequestRulesRegistry* rules_registry = i->first; | 1916 extensions::WebRequestRulesRegistry* rules_registry = i->first; |
| 1889 if (!rules_registry->ready().is_signaled()) { | 1917 if (!rules_registry->ready().is_signaled()) { |
| 1890 // The rules registry is still loading. Block this request until it | 1918 // The rules registry is still loading. Block this request until it |
| 1891 // finishes. | 1919 // finishes. |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2297 } else if ((*it)->name().find("AdBlock") != std::string::npos) { | 2325 } else if ((*it)->name().find("AdBlock") != std::string::npos) { |
| 2298 adblock = true; | 2326 adblock = true; |
| 2299 } else { | 2327 } else { |
| 2300 other = true; | 2328 other = true; |
| 2301 } | 2329 } |
| 2302 } | 2330 } |
| 2303 } | 2331 } |
| 2304 | 2332 |
| 2305 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); | 2333 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); |
| 2306 } | 2334 } |
| OLD | NEW |