Chromium Code Reviews| 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 std::pair<void*, RulesRegistryService::WebViewKey> key(profile, webview_key); | |
|
vabr (Chromium)
2013/10/25 20:40:24
Use the already defined typedef RulesRegistryKey i
Fady Samuel
2013/10/25 22:48:08
This is a <std::string, WebViewKey> pair, instead
vabr (Chromium)
2013/10/28 14:46:09
I think there is a misunderstanding.
In web_reques
| |
| 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 1219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1836 return rv; | 1839 return rv; |
| 1837 } | 1840 } |
| 1838 | 1841 |
| 1839 bool ExtensionWebRequestEventRouter::ProcessDeclarativeRules( | 1842 bool ExtensionWebRequestEventRouter::ProcessDeclarativeRules( |
| 1840 void* profile, | 1843 void* profile, |
| 1841 ExtensionInfoMap* extension_info_map, | 1844 ExtensionInfoMap* extension_info_map, |
| 1842 const std::string& event_name, | 1845 const std::string& event_name, |
| 1843 net::URLRequest* request, | 1846 net::URLRequest* request, |
| 1844 extensions::RequestStage request_stage, | 1847 extensions::RequestStage request_stage, |
| 1845 const net::HttpResponseHeaders* original_response_headers) { | 1848 const net::HttpResponseHeaders* original_response_headers) { |
| 1849 bool is_main_frame = false; | |
| 1850 int64 frame_id = -1; | |
| 1851 bool parent_is_main_frame = false; | |
| 1852 int64 parent_frame_id = -1; | |
| 1853 int tab_id = -1; | |
| 1854 int window_id = -1; | |
| 1855 int render_process_host_id = -1; | |
| 1856 int routing_id = -1; | |
| 1857 ResourceType::Type resource_type = ResourceType::LAST_TYPE; | |
| 1858 | |
| 1859 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id, | |
| 1860 &parent_is_main_frame, &parent_frame_id, | |
| 1861 &tab_id, &window_id, &render_process_host_id, | |
| 1862 &routing_id, &resource_type); | |
| 1863 ExtensionRendererState::WebViewInfo webview_info; | |
| 1864 bool is_guest = ExtensionRendererState::GetInstance()-> | |
|
vabr (Chromium)
2013/10/25 20:40:24
What does "guest" mean in this context?
Fady Samuel
2013/10/25 22:48:08
The content of a <webview> lives in an different p
vabr (Chromium)
2013/10/28 14:46:09
OK, that makes sense. Could you please add this ex
| |
| 1865 GetWebViewInfo(render_process_host_id, routing_id, &webview_info); | |
| 1866 | |
| 1867 RulesRegistryService::WebViewKey webview_key( | |
| 1868 is_guest ? webview_info.embedder_process_id : 0, | |
| 1869 webview_info.instance_id); | |
| 1870 RulesRegistryKey rules_key(profile, webview_key); | |
| 1871 | |
| 1846 // If this check fails, check that the active stages are up-to-date in | 1872 // If this check fails, check that the active stages are up-to-date in |
| 1847 // browser/extensions/api/declarative_webrequest/request_stage.h . | 1873 // browser/extensions/api/declarative_webrequest/request_stage.h . |
| 1848 DCHECK(request_stage & extensions::kActiveStages); | 1874 DCHECK(request_stage & extensions::kActiveStages); |
| 1849 | 1875 |
| 1850 // Rules of the current |profile| may apply but we need to check also whether | 1876 // Rules of the current |profile| may apply but we need to check also whether |
| 1851 // there are applicable rules from extensions whose background page | 1877 // there are applicable rules from extensions whose background page |
| 1852 // spans from regular to incognito mode. | 1878 // spans from regular to incognito mode. |
| 1853 | 1879 |
| 1854 // First parameter identifies the registry, the second indicates whether the | 1880 // First parameter identifies the registry, the second indicates whether the |
| 1855 // registry belongs to the cross profile. | 1881 // registry belongs to the cross profile. |
| 1856 typedef std::pair<extensions::WebRequestRulesRegistry*, bool> | 1882 typedef std::pair<extensions::WebRequestRulesRegistry*, bool> |
| 1857 RelevantRegistry; | 1883 RelevantRegistry; |
| 1858 typedef std::vector<RelevantRegistry> RelevantRegistries; | 1884 typedef std::vector<RelevantRegistry> RelevantRegistries; |
| 1859 RelevantRegistries relevant_registries; | 1885 RelevantRegistries relevant_registries; |
| 1860 | 1886 |
| 1861 if (rules_registries_.find(profile) != rules_registries_.end()) { | 1887 if (rules_registries_.find(rules_key) != rules_registries_.end()) { |
| 1862 relevant_registries.push_back( | 1888 relevant_registries.push_back( |
| 1863 std::make_pair(rules_registries_[profile].get(), false)); | 1889 std::make_pair(rules_registries_[rules_key].get(), false)); |
| 1864 } | 1890 } |
| 1865 | 1891 |
| 1866 void* cross_profile = GetCrossProfile(profile); | 1892 void* cross_profile = GetCrossProfile(profile); |
| 1867 if (cross_profile && | 1893 if (cross_profile && |
| 1868 rules_registries_.find(cross_profile) != rules_registries_.end()) { | 1894 rules_registries_.find(rules_key) != rules_registries_.end()) { |
|
vabr (Chromium)
2013/10/25 20:40:24
|cross_profile| is not contained in rules_key -- i
Fady Samuel
2013/10/25 22:48:08
Good catch! Fixed. Added a cross_profile_rules_key
| |
| 1869 relevant_registries.push_back( | 1895 relevant_registries.push_back( |
| 1870 std::make_pair(rules_registries_[cross_profile].get(), true)); | 1896 std::make_pair(rules_registries_[rules_key].get(), true)); |
| 1871 } | 1897 } |
| 1872 | 1898 |
| 1873 // The following block is experimentally enabled and its impact on load time | 1899 // The following block is experimentally enabled and its impact on load time |
| 1874 // logged with UMA Extensions.NetworkDelayRegistryLoad. crbug.com/175961 | 1900 // logged with UMA Extensions.NetworkDelayRegistryLoad. crbug.com/175961 |
| 1875 for (RelevantRegistries::iterator i = relevant_registries.begin(); | 1901 for (RelevantRegistries::iterator i = relevant_registries.begin(); |
| 1876 i != relevant_registries.end(); ++i) { | 1902 i != relevant_registries.end(); ++i) { |
| 1877 extensions::WebRequestRulesRegistry* rules_registry = i->first; | 1903 extensions::WebRequestRulesRegistry* rules_registry = i->first; |
| 1878 if (!rules_registry->ready().is_signaled()) { | 1904 if (!rules_registry->ready().is_signaled()) { |
| 1879 // The rules registry is still loading. Block this request until it | 1905 // The rules registry is still loading. Block this request until it |
| 1880 // finishes. | 1906 // finishes. |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2286 } else if ((*it)->name().find("AdBlock") != std::string::npos) { | 2312 } else if ((*it)->name().find("AdBlock") != std::string::npos) { |
| 2287 adblock = true; | 2313 adblock = true; |
| 2288 } else { | 2314 } else { |
| 2289 other = true; | 2315 other = true; |
| 2290 } | 2316 } |
| 2291 } | 2317 } |
| 2292 } | 2318 } |
| 2293 | 2319 |
| 2294 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); | 2320 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); |
| 2295 } | 2321 } |
| OLD | NEW |