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

Side by Side Diff: chrome/browser/extensions/api/web_request/web_request_api.cc

Issue 28273006: <webview>: Implement declarativeWebRequest API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed nits Created 7 years, 1 month 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/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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::InfoMap; 79 using extensions::InfoMap;
80 using extensions::Feature; 80 using extensions::Feature;
81 using extensions::RulesRegistryService;
81 using extensions::web_navigation_api_helpers::GetFrameId; 82 using extensions::web_navigation_api_helpers::GetFrameId;
82 83
83 namespace helpers = extension_web_request_api_helpers; 84 namespace helpers = extension_web_request_api_helpers;
84 namespace keys = extension_web_request_api_constants; 85 namespace keys = extension_web_request_api_constants;
85 namespace web_request = extensions::api::web_request; 86 namespace web_request = extensions::api::web_request;
86 namespace declarative_keys = extensions::declarative_webrequest_constants; 87 namespace declarative_keys = extensions::declarative_webrequest_constants;
87 namespace activitylog = activity_log_web_request_constants; 88 namespace activitylog = activity_log_web_request_constants;
88 89
89 namespace { 90 namespace {
90 91
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 594
594 ExtensionWebRequestEventRouter::ExtensionWebRequestEventRouter() 595 ExtensionWebRequestEventRouter::ExtensionWebRequestEventRouter()
595 : request_time_tracker_(new ExtensionWebRequestTimeTracker) { 596 : request_time_tracker_(new ExtensionWebRequestTimeTracker) {
596 } 597 }
597 598
598 ExtensionWebRequestEventRouter::~ExtensionWebRequestEventRouter() { 599 ExtensionWebRequestEventRouter::~ExtensionWebRequestEventRouter() {
599 } 600 }
600 601
601 void ExtensionWebRequestEventRouter::RegisterRulesRegistry( 602 void ExtensionWebRequestEventRouter::RegisterRulesRegistry(
602 void* profile, 603 void* profile,
604 const RulesRegistryService::WebViewKey& webview_key,
603 scoped_refptr<extensions::WebRequestRulesRegistry> rules_registry) { 605 scoped_refptr<extensions::WebRequestRulesRegistry> rules_registry) {
606 RulesRegistryKey key(profile, webview_key);
604 if (rules_registry.get()) 607 if (rules_registry.get())
605 rules_registries_[profile] = rules_registry; 608 rules_registries_[key] = rules_registry;
606 else 609 else
607 rules_registries_.erase(profile); 610 rules_registries_.erase(key);
608 } 611 }
609 612
610 int ExtensionWebRequestEventRouter::OnBeforeRequest( 613 int ExtensionWebRequestEventRouter::OnBeforeRequest(
611 void* profile, 614 void* profile,
612 InfoMap* extension_info_map, 615 InfoMap* extension_info_map,
613 net::URLRequest* request, 616 net::URLRequest* request,
614 const net::CompletionCallback& callback, 617 const net::CompletionCallback& callback,
615 GURL* new_url) { 618 GURL* new_url) {
616 // We hide events from the system context as well as sensitive requests. 619 // We hide events from the system context as well as sensitive requests.
617 if (!profile || 620 if (!profile ||
(...skipping 1229 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 InfoMap* extension_info_map, 1855 InfoMap* 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 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
2296 } else if ((*it)->name().find("AdBlock") != std::string::npos) { 2324 } else if ((*it)->name().find("AdBlock") != std::string::npos) {
2297 adblock = true; 2325 adblock = true;
2298 } else { 2326 } else {
2299 other = true; 2327 other = true;
2300 } 2328 }
2301 } 2329 }
2302 } 2330 }
2303 2331
2304 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); 2332 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other));
2305 } 2333 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/web_request/web_request_api.h ('k') | chrome/common/extensions/api/_api_features.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698