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

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

Issue 307543005: Fix the Declarative WebRequest API for <webview> (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move_webcontentsdelegate_impl_to_chrome
Patch Set: Fix WebRequest unit tests Created 6 years, 6 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/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 15 matching lines...) Expand all
26 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_consta nts.h" 26 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_consta nts.h"
27 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_ registry.h" 27 #include "chrome/browser/extensions/api/declarative_webrequest/webrequest_rules_ registry.h"
28 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_helper s.h" 28 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_helper s.h"
29 #include "chrome/browser/extensions/api/web_request/upload_data_presenter.h" 29 #include "chrome/browser/extensions/api/web_request/upload_data_presenter.h"
30 #include "chrome/browser/extensions/api/web_request/web_request_api_constants.h" 30 #include "chrome/browser/extensions/api/web_request/web_request_api_constants.h"
31 #include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h" 31 #include "chrome/browser/extensions/api/web_request/web_request_api_helpers.h"
32 #include "chrome/browser/extensions/api/web_request/web_request_time_tracker.h" 32 #include "chrome/browser/extensions/api/web_request/web_request_time_tracker.h"
33 #include "chrome/browser/extensions/extension_renderer_state.h" 33 #include "chrome/browser/extensions/extension_renderer_state.h"
34 #include "chrome/browser/extensions/extension_warning_service.h" 34 #include "chrome/browser/extensions/extension_warning_service.h"
35 #include "chrome/browser/extensions/extension_warning_set.h" 35 #include "chrome/browser/extensions/extension_warning_set.h"
36 #include "chrome/browser/guest_view/web_view/web_view_constants.h"
36 #include "chrome/browser/profiles/profile.h" 37 #include "chrome/browser/profiles/profile.h"
37 #include "chrome/browser/profiles/profile_manager.h" 38 #include "chrome/browser/profiles/profile_manager.h"
38 #include "chrome/common/extensions/api/web_request.h" 39 #include "chrome/common/extensions/api/web_request.h"
39 #include "chrome/common/extensions/extension_constants.h" 40 #include "chrome/common/extensions/extension_constants.h"
40 #include "chrome/common/url_constants.h" 41 #include "chrome/common/url_constants.h"
41 #include "content/public/browser/browser_message_filter.h" 42 #include "content/public/browser/browser_message_filter.h"
42 #include "content/public/browser/browser_thread.h" 43 #include "content/public/browser/browser_thread.h"
43 #include "content/public/browser/render_process_host.h" 44 #include "content/public/browser/render_process_host.h"
44 #include "content/public/browser/resource_request_info.h" 45 #include "content/public/browser/resource_request_info.h"
45 #include "content/public/browser/user_metrics.h" 46 #include "content/public/browser/user_metrics.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); 157 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
157 158
158 // If this request was not created by the ResourceDispatcher, |info| is NULL. 159 // If this request was not created by the ResourceDispatcher, |info| is NULL.
159 // All requests from extensions are created by the ResourceDispatcher. 160 // All requests from extensions are created by the ResourceDispatcher.
160 if (!info) 161 if (!info)
161 return false; 162 return false;
162 163
163 return extension_info_map->process_map().Contains(info->GetChildID()); 164 return extension_info_map->process_map().Contains(info->GetChildID());
164 } 165 }
165 166
167 void ExtractRequestRoutingInfo(net::URLRequest* request,
168 int* render_process_host_id,
169 int* routing_id) {
170 if (!request->GetUserData(NULL))
171 return;
172 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
173 *render_process_host_id = info->GetChildID();
174 *routing_id = info->GetRouteID();
175 }
176
177 // Given a |request|, this function determines whether it originated from
178 // a <webview> guest process or not. If it is from a <webview> guest process,
179 // then |web_view_info| is returned with information about the instance ID
180 // that uniquely identifies the <webview> and its embedder.
181 bool GetWebViewInfo(net::URLRequest* request,
182 ExtensionRendererState::WebViewInfo* web_view_info) {
183 int render_process_host_id = -1;
184 int routing_id = -1;
185 ExtractRequestRoutingInfo(request, &render_process_host_id, &routing_id);
186 return ExtensionRendererState::GetInstance()->
187 GetWebViewInfo(render_process_host_id, routing_id, web_view_info);
188 }
189
166 void ExtractRequestInfoDetails(net::URLRequest* request, 190 void ExtractRequestInfoDetails(net::URLRequest* request,
167 bool* is_main_frame, 191 bool* is_main_frame,
168 int64* frame_id, 192 int64* frame_id,
169 bool* parent_is_main_frame, 193 bool* parent_is_main_frame,
170 int64* parent_frame_id, 194 int64* parent_frame_id,
171 int* tab_id, 195 int* tab_id,
172 int* window_id, 196 int* window_id,
173 int* render_process_host_id, 197 int* render_process_host_id,
174 int* routing_id, 198 int* routing_id,
175 ResourceType::Type* resource_type) { 199 ResourceType::Type* resource_type) {
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 return; 380 return;
357 381
358 content::RenderProcessHost* process = 382 content::RenderProcessHost* process =
359 content::RenderProcessHost::FromID(process_id); 383 content::RenderProcessHost::FromID(process_id);
360 if (!process) 384 if (!process)
361 return; 385 return;
362 386
363 event_router->RemoveEventListener(event_name, process, extension_id); 387 event_router->RemoveEventListener(event_name, process, extension_id);
364 } 388 }
365 389
366 // Sends an event to subscribers of chrome.declarativeWebRequest.onMessage. 390 // Sends an event to subscribers of chrome.declarativeWebRequest.onMessage or
391 // to subscribers of webview.onMessage if the action is being operated upon
392 // a <webview> guest renderer.
367 // |extension_id| identifies the extension that sends and receives the event. 393 // |extension_id| identifies the extension that sends and receives the event.
394 // |is_web_view_guest| indicates whether the action is for a <webview>.
395 // |web_view_info| is a struct containing information about the <webview>
396 // embedder.
368 // |event_argument| is passed to the event listener. 397 // |event_argument| is passed to the event listener.
369 void SendOnMessageEventOnUI( 398 void SendOnMessageEventOnUI(
370 void* profile_id, 399 void* profile_id,
371 const std::string& extension_id, 400 const std::string& extension_id,
401 bool is_web_view_guest,
402 const ExtensionRendererState::WebViewInfo& web_view_info,
372 scoped_ptr<base::DictionaryValue> event_argument) { 403 scoped_ptr<base::DictionaryValue> event_argument) {
373 DCHECK_CURRENTLY_ON(BrowserThread::UI); 404 DCHECK_CURRENTLY_ON(BrowserThread::UI);
374 405
375 Profile* profile = reinterpret_cast<Profile*>(profile_id); 406 Profile* profile = reinterpret_cast<Profile*>(profile_id);
376 if (!g_browser_process->profile_manager()->IsValidProfile(profile)) 407 if (!g_browser_process->profile_manager()->IsValidProfile(profile))
377 return; 408 return;
378 409
379 scoped_ptr<base::ListValue> event_args(new base::ListValue); 410 scoped_ptr<base::ListValue> event_args(new base::ListValue);
380 event_args->Append(event_argument.release()); 411 event_args->Append(event_argument.release());
381 412
382 extensions::EventRouter* event_router = extensions::EventRouter::Get(profile); 413 extensions::EventRouter* event_router = extensions::EventRouter::Get(profile);
383 414
415 extensions::EventFilteringInfo event_filtering_info;
416 // The instance ID uniquely identifies a <webview> instance within an embedder
417 // process. We use a filter here so that only event listeners for a particular
418 // <webview> will fire.
419 if (is_web_view_guest)
420 event_filtering_info.SetInstanceID(web_view_info.instance_id);
421
384 scoped_ptr<extensions::Event> event(new extensions::Event( 422 scoped_ptr<extensions::Event> event(new extensions::Event(
385 declarative_keys::kOnMessage, event_args.Pass(), profile, 423 is_web_view_guest ? webview::kEventMessage : declarative_keys::kOnMessage,
386 GURL(), extensions::EventRouter::USER_GESTURE_UNKNOWN, 424 event_args.Pass(), profile, GURL(),
387 extensions::EventFilteringInfo())); 425 extensions::EventRouter::USER_GESTURE_UNKNOWN,
426 event_filtering_info));
388 event_router->DispatchEventToExtension(extension_id, event.Pass()); 427 event_router->DispatchEventToExtension(extension_id, event.Pass());
389 } 428 }
390 429
391 void RemoveEventListenerOnIOThread( 430 void RemoveEventListenerOnIOThread(
392 content::BrowserContext* browser_context, 431 content::BrowserContext* browser_context,
393 const std::string& extension_id, 432 const std::string& extension_id,
394 const std::string& sub_event_name) { 433 const std::string& sub_event_name) {
395 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener( 434 ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener(
396 browser_context, extension_id, sub_event_name); 435 browser_context, extension_id, sub_event_name);
397 } 436 }
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after
1233 void* profile, 1272 void* profile,
1234 const std::string& extension_id, 1273 const std::string& extension_id,
1235 const std::string& extension_name, 1274 const std::string& extension_name,
1236 const std::string& event_name, 1275 const std::string& event_name,
1237 const std::string& sub_event_name, 1276 const std::string& sub_event_name,
1238 const RequestFilter& filter, 1277 const RequestFilter& filter,
1239 int extra_info_spec, 1278 int extra_info_spec,
1240 int embedder_process_id, 1279 int embedder_process_id,
1241 int webview_instance_id, 1280 int webview_instance_id,
1242 base::WeakPtr<IPC::Sender> ipc_sender) { 1281 base::WeakPtr<IPC::Sender> ipc_sender) {
1243
1244 if (!IsWebRequestEvent(event_name)) 1282 if (!IsWebRequestEvent(event_name))
1245 return false; 1283 return false;
1246 1284
1247 EventListener listener; 1285 EventListener listener;
1248 listener.extension_id = extension_id; 1286 listener.extension_id = extension_id;
1249 listener.extension_name = extension_name; 1287 listener.extension_name = extension_name;
1250 listener.sub_event_name = sub_event_name; 1288 listener.sub_event_name = sub_event_name;
1251 listener.filter = filter; 1289 listener.filter = filter;
1252 listener.extra_info_spec = extra_info_spec; 1290 listener.extra_info_spec = extra_info_spec;
1253 listener.ipc_sender = ipc_sender; 1291 listener.ipc_sender = ipc_sender;
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1412 int window_id, 1450 int window_id,
1413 int render_process_host_id, 1451 int render_process_host_id,
1414 int routing_id, 1452 int routing_id,
1415 ResourceType::Type resource_type, 1453 ResourceType::Type resource_type,
1416 bool is_async_request, 1454 bool is_async_request,
1417 bool is_request_from_extension, 1455 bool is_request_from_extension,
1418 int* extra_info_spec, 1456 int* extra_info_spec,
1419 std::vector<const ExtensionWebRequestEventRouter::EventListener*>* 1457 std::vector<const ExtensionWebRequestEventRouter::EventListener*>*
1420 matching_listeners) { 1458 matching_listeners) {
1421 std::string web_request_event_name(event_name); 1459 std::string web_request_event_name(event_name);
1422 ExtensionRendererState::WebViewInfo webview_info; 1460 ExtensionRendererState::WebViewInfo web_view_info;
1423 bool is_guest = ExtensionRendererState::GetInstance()-> 1461 bool is_web_view_guest = ExtensionRendererState::GetInstance()->
1424 GetWebViewInfo(render_process_host_id, routing_id, &webview_info); 1462 GetWebViewInfo(render_process_host_id, routing_id, &web_view_info);
1425 if (is_guest) 1463 if (is_web_view_guest)
1426 web_request_event_name.replace(0, sizeof(kWebRequest) - 1, kWebView); 1464 web_request_event_name.replace(0, sizeof(kWebRequest) - 1, kWebView);
1427 1465
1428 std::set<EventListener>& listeners = 1466 std::set<EventListener>& listeners =
1429 listeners_[profile][web_request_event_name]; 1467 listeners_[profile][web_request_event_name];
1430 for (std::set<EventListener>::iterator it = listeners.begin(); 1468 for (std::set<EventListener>::iterator it = listeners.begin();
1431 it != listeners.end(); ++it) { 1469 it != listeners.end(); ++it) {
1432 if (!it->ipc_sender.get()) { 1470 if (!it->ipc_sender.get()) {
1433 // The IPC sender has been deleted. This listener will be removed soon 1471 // The IPC sender has been deleted. This listener will be removed soon
1434 // via a call to RemoveEventListener. For now, just skip it. 1472 // via a call to RemoveEventListener. For now, just skip it.
1435 continue; 1473 continue;
1436 } 1474 }
1437 1475
1438 if (is_guest && 1476 if (is_web_view_guest &&
1439 (it->embedder_process_id != webview_info.embedder_process_id || 1477 (it->embedder_process_id != web_view_info.embedder_process_id ||
1440 it->webview_instance_id != webview_info.instance_id)) 1478 it->webview_instance_id != web_view_info.instance_id))
1441 continue; 1479 continue;
1442 1480
1443 if (!it->filter.urls.is_empty() && !it->filter.urls.MatchesURL(url)) 1481 if (!it->filter.urls.is_empty() && !it->filter.urls.MatchesURL(url))
1444 continue; 1482 continue;
1445 if (it->filter.tab_id != -1 && tab_id != it->filter.tab_id) 1483 if (it->filter.tab_id != -1 && tab_id != it->filter.tab_id)
1446 continue; 1484 continue;
1447 if (it->filter.window_id != -1 && window_id != it->filter.window_id) 1485 if (it->filter.window_id != -1 && window_id != it->filter.window_id)
1448 continue; 1486 continue;
1449 if (!it->filter.types.empty() && 1487 if (!it->filter.types.empty() &&
1450 std::find(it->filter.types.begin(), it->filter.types.end(), 1488 std::find(it->filter.types.begin(), it->filter.types.end(),
1451 resource_type) == it->filter.types.end()) 1489 resource_type) == it->filter.types.end())
1452 continue; 1490 continue;
1453 1491
1454 if (!is_guest && !WebRequestPermissions::CanExtensionAccessURL( 1492 if (!is_web_view_guest && !WebRequestPermissions::CanExtensionAccessURL(
1455 extension_info_map, it->extension_id, url, crosses_incognito, 1493 extension_info_map, it->extension_id, url, crosses_incognito,
1456 WebRequestPermissions::REQUIRE_HOST_PERMISSION)) 1494 WebRequestPermissions::REQUIRE_HOST_PERMISSION))
1457 continue; 1495 continue;
1458 1496
1459 bool blocking_listener = 1497 bool blocking_listener =
1460 (it->extra_info_spec & 1498 (it->extra_info_spec &
1461 (ExtraInfoSpec::BLOCKING | ExtraInfoSpec::ASYNC_BLOCKING)) != 0; 1499 (ExtraInfoSpec::BLOCKING | ExtraInfoSpec::ASYNC_BLOCKING)) != 0;
1462 1500
1463 // We do not want to notify extensions about XHR requests that are 1501 // We do not want to notify extensions about XHR requests that are
1464 // triggered by themselves. This is a workaround to prevent deadlocks 1502 // triggered by themselves. This is a workaround to prevent deadlocks
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
1786 void* profile, 1824 void* profile,
1787 const BlockedRequest& blocked_request) { 1825 const BlockedRequest& blocked_request) {
1788 const helpers::EventResponseDeltas& deltas = blocked_request.response_deltas; 1826 const helpers::EventResponseDeltas& deltas = blocked_request.response_deltas;
1789 for (helpers::EventResponseDeltas::const_iterator delta = deltas.begin(); 1827 for (helpers::EventResponseDeltas::const_iterator delta = deltas.begin();
1790 delta != deltas.end(); ++delta) { 1828 delta != deltas.end(); ++delta) {
1791 const std::set<std::string>& messages = (*delta)->messages_to_extension; 1829 const std::set<std::string>& messages = (*delta)->messages_to_extension;
1792 for (std::set<std::string>::const_iterator message = messages.begin(); 1830 for (std::set<std::string>::const_iterator message = messages.begin();
1793 message != messages.end(); ++message) { 1831 message != messages.end(); ++message) {
1794 scoped_ptr<base::DictionaryValue> argument(new base::DictionaryValue); 1832 scoped_ptr<base::DictionaryValue> argument(new base::DictionaryValue);
1795 ExtractRequestInfo(blocked_request.request, argument.get()); 1833 ExtractRequestInfo(blocked_request.request, argument.get());
1834 ExtensionRendererState::WebViewInfo web_view_info;
1835 bool is_web_view_guest = GetWebViewInfo(blocked_request.request,
1836 &web_view_info);
1796 argument->SetString(keys::kMessageKey, *message); 1837 argument->SetString(keys::kMessageKey, *message);
1797 argument->SetString(keys::kStageKey, 1838 argument->SetString(keys::kStageKey,
1798 GetRequestStageAsString(blocked_request.event)); 1839 GetRequestStageAsString(blocked_request.event));
1799 1840
1800 BrowserThread::PostTask( 1841 BrowserThread::PostTask(
1801 BrowserThread::UI, 1842 BrowserThread::UI,
1802 FROM_HERE, 1843 FROM_HERE,
1803 base::Bind(&SendOnMessageEventOnUI, 1844 base::Bind(&SendOnMessageEventOnUI,
1804 profile, 1845 profile,
1805 (*delta)->extension_id, 1846 (*delta)->extension_id,
1847 is_web_view_guest,
1848 web_view_info,
1806 base::Passed(&argument))); 1849 base::Passed(&argument)));
1807 } 1850 }
1808 } 1851 }
1809 } 1852 }
1810 1853
1811 int ExtensionWebRequestEventRouter::ExecuteDeltas( 1854 int ExtensionWebRequestEventRouter::ExecuteDeltas(
1812 void* profile, 1855 void* profile,
1813 uint64 request_id, 1856 uint64 request_id,
1814 bool call_callback) { 1857 bool call_callback) {
1815 BlockedRequest& blocked_request = blocked_requests_[request_id]; 1858 BlockedRequest& blocked_request = blocked_requests_[request_id];
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1910 return rv; 1953 return rv;
1911 } 1954 }
1912 1955
1913 bool ExtensionWebRequestEventRouter::ProcessDeclarativeRules( 1956 bool ExtensionWebRequestEventRouter::ProcessDeclarativeRules(
1914 void* profile, 1957 void* profile,
1915 InfoMap* extension_info_map, 1958 InfoMap* extension_info_map,
1916 const std::string& event_name, 1959 const std::string& event_name,
1917 net::URLRequest* request, 1960 net::URLRequest* request,
1918 extensions::RequestStage request_stage, 1961 extensions::RequestStage request_stage,
1919 const net::HttpResponseHeaders* original_response_headers) { 1962 const net::HttpResponseHeaders* original_response_headers) {
1920 bool is_main_frame = false; 1963 ExtensionRendererState::WebViewInfo web_view_info;
1921 int64 frame_id = -1; 1964 bool is_web_view_guest = GetWebViewInfo(request, &web_view_info);
1922 bool parent_is_main_frame = false;
1923 int64 parent_frame_id = -1;
1924 int tab_id = -1;
1925 int window_id = -1;
1926 int render_process_host_id = -1;
1927 int routing_id = -1;
1928 ResourceType::Type resource_type = ResourceType::LAST_TYPE;
1929
1930 ExtractRequestInfoDetails(request, &is_main_frame, &frame_id,
1931 &parent_is_main_frame, &parent_frame_id,
1932 &tab_id, &window_id, &render_process_host_id,
1933 &routing_id, &resource_type);
1934 ExtensionRendererState::WebViewInfo webview_info;
1935 bool is_guest = ExtensionRendererState::GetInstance()->
1936 GetWebViewInfo(render_process_host_id, routing_id, &webview_info);
1937 1965
1938 RulesRegistryService::WebViewKey webview_key( 1966 RulesRegistryService::WebViewKey webview_key(
1939 is_guest ? webview_info.embedder_process_id : 0, 1967 is_web_view_guest ? web_view_info.embedder_process_id : 0,
1940 is_guest ? webview_info.instance_id : 0); 1968 is_web_view_guest ? web_view_info.instance_id : 0);
1941 RulesRegistryKey rules_key(profile, webview_key); 1969 RulesRegistryKey rules_key(profile, webview_key);
1942
1943 // If this check fails, check that the active stages are up-to-date in 1970 // If this check fails, check that the active stages are up-to-date in
1944 // browser/extensions/api/declarative_webrequest/request_stage.h . 1971 // browser/extensions/api/declarative_webrequest/request_stage.h .
1945 DCHECK(request_stage & extensions::kActiveStages); 1972 DCHECK(request_stage & extensions::kActiveStages);
1946 1973
1947 // Rules of the current |profile| may apply but we need to check also whether 1974 // Rules of the current |profile| may apply but we need to check also whether
1948 // there are applicable rules from extensions whose background page 1975 // there are applicable rules from extensions whose background page
1949 // spans from regular to incognito mode. 1976 // spans from regular to incognito mode.
1950 1977
1951 // First parameter identifies the registry, the second indicates whether the 1978 // First parameter identifies the registry, the second indicates whether the
1952 // registry belongs to the cross profile. 1979 // registry belongs to the cross profile.
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
2176 2203
2177 base::WeakPtr<extensions::ExtensionMessageFilter> ipc_sender = 2204 base::WeakPtr<extensions::ExtensionMessageFilter> ipc_sender =
2178 ipc_sender_weak(); 2205 ipc_sender_weak();
2179 int embedder_process_id = 2206 int embedder_process_id =
2180 ipc_sender.get() ? ipc_sender->render_process_id() : -1; 2207 ipc_sender.get() ? ipc_sender->render_process_id() : -1;
2181 2208
2182 const Extension* extension = 2209 const Extension* extension =
2183 extension_info_map()->extensions().GetByID(extension_id()); 2210 extension_info_map()->extensions().GetByID(extension_id());
2184 std::string extension_name = extension ? extension->name() : extension_id(); 2211 std::string extension_name = extension ? extension->name() : extension_id();
2185 2212
2186 bool is_guest = webview_instance_id != 0; 2213 bool is_web_view_guest = webview_instance_id != 0;
2187 // We check automatically whether the extension has the 'webRequest' 2214 // We check automatically whether the extension has the 'webRequest'
2188 // permission. For blocking calls we require the additional permission 2215 // permission. For blocking calls we require the additional permission
2189 // 'webRequestBlocking'. 2216 // 'webRequestBlocking'.
2190 if ((!is_guest && extra_info_spec & 2217 if ((!is_web_view_guest && extra_info_spec &
2191 (ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING | 2218 (ExtensionWebRequestEventRouter::ExtraInfoSpec::BLOCKING |
2192 ExtensionWebRequestEventRouter::ExtraInfoSpec::ASYNC_BLOCKING)) && 2219 ExtensionWebRequestEventRouter::ExtraInfoSpec::ASYNC_BLOCKING)) &&
2193 !extension->HasAPIPermission( 2220 !extension->HasAPIPermission(
2194 extensions::APIPermission::kWebRequestBlocking)) { 2221 extensions::APIPermission::kWebRequestBlocking)) {
2195 error_ = keys::kBlockingPermissionRequired; 2222 error_ = keys::kBlockingPermissionRequired;
2196 return false; 2223 return false;
2197 } 2224 }
2198 2225
2199 // We allow to subscribe to patterns that are broader than the host 2226 // We allow to subscribe to patterns that are broader than the host
2200 // permissions. E.g., we could subscribe to http://www.example.com/* 2227 // permissions. E.g., we could subscribe to http://www.example.com/*
2201 // while having host permissions for http://www.example.com/foo/* and 2228 // while having host permissions for http://www.example.com/foo/* and
2202 // http://www.example.com/bar/*. 2229 // http://www.example.com/bar/*.
2203 // For this reason we do only a coarse check here to warn the extension 2230 // For this reason we do only a coarse check here to warn the extension
2204 // developer if he does something obviously wrong. 2231 // developer if he does something obviously wrong.
2205 if (!is_guest && extensions::PermissionsData::GetEffectiveHostPermissions( 2232 if (!is_web_view_guest &&
2233 extensions::PermissionsData::GetEffectiveHostPermissions(
2206 extension).is_empty()) { 2234 extension).is_empty()) {
2207 error_ = keys::kHostPermissionsRequired; 2235 error_ = keys::kHostPermissionsRequired;
2208 return false; 2236 return false;
2209 } 2237 }
2210 2238
2211 bool success = 2239 bool success =
2212 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener( 2240 ExtensionWebRequestEventRouter::GetInstance()->AddEventListener(
2213 profile_id(), extension_id(), extension_name, 2241 profile_id(), extension_id(), extension_name,
2214 event_name, sub_event_name, filter, extra_info_spec, 2242 event_name, sub_event_name, filter, extra_info_spec,
2215 embedder_process_id, webview_instance_id, ipc_sender_weak()); 2243 embedder_process_id, webview_instance_id, ipc_sender_weak());
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
2445 } else if ((*it)->name().find("AdBlock") != std::string::npos) { 2473 } else if ((*it)->name().find("AdBlock") != std::string::npos) {
2446 adblock = true; 2474 adblock = true;
2447 } else { 2475 } else {
2448 other = true; 2476 other = true;
2449 } 2477 }
2450 } 2478 }
2451 } 2479 }
2452 2480
2453 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other)); 2481 host->Send(new ExtensionMsg_UsingWebRequestAPI(adblock, adblock_plus, other));
2454 } 2482 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/declarative_webrequest/webrequest_action.cc ('k') | chrome/browser/guest_view/guest_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698