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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 11 matching lines...) Expand all Loading... | |
22 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
23 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
24 #include "base/time/time.h" | 24 #include "base/time/time.h" |
25 #include "base/values.h" | 25 #include "base/values.h" |
26 #include "chromeos/login/login_state.h" | 26 #include "chromeos/login/login_state.h" |
27 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
28 #include "content/public/browser/resource_request_info.h" | 28 #include "content/public/browser/resource_request_info.h" |
29 #include "content/public/browser/user_metrics.h" | 29 #include "content/public/browser/user_metrics.h" |
30 #include "content/public/common/browser_side_navigation_policy.h" | 30 #include "content/public/common/browser_side_navigation_policy.h" |
31 #include "content/public/common/child_process_host.h" | 31 #include "content/public/common/child_process_host.h" |
32 #include "content/public/common/resource_type.h" | |
32 #include "extensions/browser/api/activity_log/web_request_constants.h" | 33 #include "extensions/browser/api/activity_log/web_request_constants.h" |
33 #include "extensions/browser/api/declarative/rules_registry_service.h" | 34 #include "extensions/browser/api/declarative/rules_registry_service.h" |
34 #include "extensions/browser/api/declarative_webrequest/request_stage.h" | 35 #include "extensions/browser/api/declarative_webrequest/request_stage.h" |
35 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" | 36 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" |
36 #include "extensions/browser/api/declarative_webrequest/webrequest_rules_registr y.h" | 37 #include "extensions/browser/api/declarative_webrequest/webrequest_rules_registr y.h" |
37 #include "extensions/browser/api/extensions_api_client.h" | 38 #include "extensions/browser/api/extensions_api_client.h" |
38 #include "extensions/browser/api/web_request/web_request_api_constants.h" | 39 #include "extensions/browser/api/web_request/web_request_api_constants.h" |
39 #include "extensions/browser/api/web_request/web_request_api_helpers.h" | 40 #include "extensions/browser/api/web_request/web_request_api_helpers.h" |
40 #include "extensions/browser/api/web_request/web_request_event_details.h" | 41 #include "extensions/browser/api/web_request/web_request_event_details.h" |
41 #include "extensions/browser/api/web_request/web_request_event_router_delegate.h " | 42 #include "extensions/browser/api/web_request/web_request_event_router_delegate.h " |
(...skipping 1331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1373 void ExtensionWebRequestEventRouter::GetMatchingListenersImpl( | 1374 void ExtensionWebRequestEventRouter::GetMatchingListenersImpl( |
1374 void* browser_context, | 1375 void* browser_context, |
1375 const net::URLRequest* request, | 1376 const net::URLRequest* request, |
1376 const InfoMap* extension_info_map, | 1377 const InfoMap* extension_info_map, |
1377 ExtensionNavigationUIData* navigation_ui_data, | 1378 ExtensionNavigationUIData* navigation_ui_data, |
1378 bool crosses_incognito, | 1379 bool crosses_incognito, |
1379 const std::string& event_name, | 1380 const std::string& event_name, |
1380 const GURL& url, | 1381 const GURL& url, |
1381 int render_process_host_id, | 1382 int render_process_host_id, |
1382 int routing_id, | 1383 int routing_id, |
1383 content::ResourceType resource_type, | 1384 WebRequestResourceType resource_type, |
1384 bool is_async_request, | 1385 bool is_async_request, |
1385 bool is_request_from_extension, | 1386 bool is_request_from_extension, |
1386 int* extra_info_spec, | 1387 int* extra_info_spec, |
1387 RawListeners* matching_listeners) { | 1388 RawListeners* matching_listeners) { |
1388 std::string web_request_event_name(event_name); | 1389 std::string web_request_event_name(event_name); |
1389 WebViewRendererState::WebViewInfo web_view_info; | 1390 WebViewRendererState::WebViewInfo web_view_info; |
1390 bool is_web_view_guest = | 1391 bool is_web_view_guest = |
1391 WebViewRendererState::GetInstance()->GetInfo( | 1392 WebViewRendererState::GetInstance()->GetInfo( |
1392 render_process_host_id, routing_id, &web_view_info) || | 1393 render_process_host_id, routing_id, &web_view_info) || |
1393 (navigation_ui_data && navigation_ui_data->is_web_view()); | 1394 (navigation_ui_data && navigation_ui_data->is_web_view()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1445 } | 1446 } |
1446 // Check if the tab id and window id match, if they were set in the | 1447 // Check if the tab id and window id match, if they were set in the |
1447 // listener params. | 1448 // listener params. |
1448 if ((listener->filter.tab_id != -1 && | 1449 if ((listener->filter.tab_id != -1 && |
1449 frame_data.tab_id != listener->filter.tab_id) || | 1450 frame_data.tab_id != listener->filter.tab_id) || |
1450 (listener->filter.window_id != -1 && | 1451 (listener->filter.window_id != -1 && |
1451 frame_data.window_id != listener->filter.window_id)) { | 1452 frame_data.window_id != listener->filter.window_id)) { |
1452 continue; | 1453 continue; |
1453 } | 1454 } |
1454 | 1455 |
1455 const std::vector<content::ResourceType>& types = listener->filter.types; | 1456 const std::vector<WebRequestResourceType>& types = listener->filter.types; |
1456 if (!types.empty() && | 1457 if (!types.empty() && |
1457 std::find(types.begin(), types.end(), resource_type) == types.end()) { | 1458 std::find(types.begin(), types.end(), resource_type) == types.end()) { |
1458 continue; | 1459 continue; |
1459 } | 1460 } |
1460 | 1461 |
1461 if (!is_web_view_guest) { | 1462 if (!is_web_view_guest) { |
1462 PermissionsData::AccessType access = | 1463 PermissionsData::AccessType access = |
1463 WebRequestPermissions::CanExtensionAccessURL( | 1464 WebRequestPermissions::CanExtensionAccessURL( |
1464 extension_info_map, listener->id.extension_id, url, | 1465 extension_info_map, listener->id.extension_id, url, |
1465 frame_data.tab_id, crosses_incognito, | 1466 frame_data.tab_id, crosses_incognito, |
(...skipping 13 matching lines...) Expand all Loading... | |
1479 (ExtraInfoSpec::BLOCKING | ExtraInfoSpec::ASYNC_BLOCKING)) != 0; | 1480 (ExtraInfoSpec::BLOCKING | ExtraInfoSpec::ASYNC_BLOCKING)) != 0; |
1480 | 1481 |
1481 // We do not want to notify extensions about XHR requests that are | 1482 // We do not want to notify extensions about XHR requests that are |
1482 // triggered by themselves. This is a workaround to prevent deadlocks | 1483 // triggered by themselves. This is a workaround to prevent deadlocks |
1483 // in case of synchronous XHR requests that block the extension renderer | 1484 // in case of synchronous XHR requests that block the extension renderer |
1484 // and therefore prevent the extension from processing the request | 1485 // and therefore prevent the extension from processing the request |
1485 // handler. This is only a problem for blocking listeners. | 1486 // handler. This is only a problem for blocking listeners. |
1486 // http://crbug.com/105656 | 1487 // http://crbug.com/105656 |
1487 bool synchronous_xhr_from_extension = | 1488 bool synchronous_xhr_from_extension = |
1488 !is_async_request && is_request_from_extension && | 1489 !is_async_request && is_request_from_extension && |
1489 resource_type == content::RESOURCE_TYPE_XHR; | 1490 resource_type == WebRequestResourceType::XHR; |
1490 | 1491 |
1491 // Only send webRequest events for URLs the extension has access to. | 1492 // Only send webRequest events for URLs the extension has access to. |
1492 if (blocking_listener && synchronous_xhr_from_extension) | 1493 if (blocking_listener && synchronous_xhr_from_extension) |
1493 continue; | 1494 continue; |
1494 | 1495 |
1495 matching_listeners->push_back(listener.get()); | 1496 matching_listeners->push_back(listener.get()); |
1496 *extra_info_spec |= listener->extra_info_spec; | 1497 *extra_info_spec |= listener->extra_info_spec; |
1497 } | 1498 } |
1498 } | 1499 } |
1499 | 1500 |
1500 ExtensionWebRequestEventRouter::RawListeners | 1501 ExtensionWebRequestEventRouter::RawListeners |
1501 ExtensionWebRequestEventRouter::GetMatchingListeners( | 1502 ExtensionWebRequestEventRouter::GetMatchingListeners( |
1502 void* browser_context, | 1503 void* browser_context, |
1503 const InfoMap* extension_info_map, | 1504 const InfoMap* extension_info_map, |
1504 ExtensionNavigationUIData* navigation_ui_data, | 1505 ExtensionNavigationUIData* navigation_ui_data, |
1505 const std::string& event_name, | 1506 const std::string& event_name, |
1506 const net::URLRequest* request, | 1507 const net::URLRequest* request, |
1507 int* extra_info_spec) { | 1508 int* extra_info_spec) { |
1508 // TODO(mpcomplete): handle browser_context == NULL (should collect all | 1509 // TODO(mpcomplete): handle browser_context == NULL (should collect all |
1509 // listeners). | 1510 // listeners). |
1510 *extra_info_spec = 0; | 1511 *extra_info_spec = 0; |
1511 | 1512 |
1512 const GURL& url = request->url(); | 1513 const GURL& url = request->url(); |
1513 int render_process_host_id = content::ChildProcessHost::kInvalidUniqueID; | 1514 int render_process_host_id = content::ChildProcessHost::kInvalidUniqueID; |
1514 int routing_id = MSG_ROUTING_NONE; | 1515 int routing_id = MSG_ROUTING_NONE; |
1515 content::ResourceType resource_type = content::RESOURCE_TYPE_LAST_TYPE; | 1516 auto resource_type = WebRequestResourceType::OTHER; |
1516 // We are conservative here and assume requests are asynchronous in case | 1517 // We are conservative here and assume requests are asynchronous in case |
1517 // we don't have an info object. We don't want to risk a deadlock. | 1518 // we don't have an info object. We don't want to risk a deadlock. |
1518 bool is_async_request = false; | 1519 bool is_async_request = false; |
1519 bool is_request_from_extension = | 1520 bool is_request_from_extension = |
1520 IsRequestFromExtension(request, extension_info_map); | 1521 IsRequestFromExtension(request, extension_info_map); |
1521 | 1522 |
1522 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 1523 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
1523 if (info) { | 1524 if (info) { |
1524 is_async_request = info->IsAsync(); | 1525 is_async_request = info->IsAsync(); |
1525 if (helpers::IsRelevantResourceType(info->GetResourceType())) | 1526 if (helpers::IsRelevantResourceType(info->GetResourceType())) |
1526 resource_type = info->GetResourceType(); | 1527 resource_type = ToWebRequestResourceType(info->GetResourceType()); |
Devlin
2017/02/16 16:08:26
here, too, looks like this type should be able to
pkalinnikov
2017/02/16 19:27:33
Yes, I have already done it in the follow-up CL (n
| |
1527 render_process_host_id = info->GetChildID(); | 1528 render_process_host_id = info->GetChildID(); |
1528 routing_id = info->GetRouteID(); | 1529 routing_id = info->GetRouteID(); |
1529 } | 1530 } |
1530 | 1531 |
1531 RawListeners matching_listeners; | 1532 RawListeners matching_listeners; |
1532 GetMatchingListenersImpl(browser_context, request, extension_info_map, | 1533 GetMatchingListenersImpl(browser_context, request, extension_info_map, |
1533 navigation_ui_data, false, event_name, url, | 1534 navigation_ui_data, false, event_name, url, |
1534 render_process_host_id, routing_id, resource_type, | 1535 render_process_host_id, routing_id, resource_type, |
1535 is_async_request, is_request_from_extension, | 1536 is_async_request, is_request_from_extension, |
1536 extra_info_spec, &matching_listeners); | 1537 extra_info_spec, &matching_listeners); |
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2390 // Since EventListeners are segmented by browser_context, check that | 2391 // Since EventListeners are segmented by browser_context, check that |
2391 // last, as it is exceedingly unlikely to be different. | 2392 // last, as it is exceedingly unlikely to be different. |
2392 return extension_id == that.extension_id && | 2393 return extension_id == that.extension_id && |
2393 sub_event_name == that.sub_event_name && | 2394 sub_event_name == that.sub_event_name && |
2394 web_view_instance_id == that.web_view_instance_id && | 2395 web_view_instance_id == that.web_view_instance_id && |
2395 embedder_process_id == that.embedder_process_id && | 2396 embedder_process_id == that.embedder_process_id && |
2396 browser_context == that.browser_context; | 2397 browser_context == that.browser_context; |
2397 } | 2398 } |
2398 | 2399 |
2399 } // namespace extensions | 2400 } // namespace extensions |
OLD | NEW |