Chromium Code Reviews| Index: extensions/browser/url_request_util.cc |
| diff --git a/extensions/browser/url_request_util.cc b/extensions/browser/url_request_util.cc |
| index 1e44115bcb7c545ff28353e4785ae75006b309c7..4c64b504de5196d9062b3c3e9a1145ceef00f2c0 100644 |
| --- a/extensions/browser/url_request_util.cc |
| +++ b/extensions/browser/url_request_util.cc |
| @@ -7,6 +7,7 @@ |
| #include <string> |
| #include "content/public/browser/resource_request_info.h" |
| +#include "content/public/common/browser_side_navigation_policy.h" |
| #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" |
| #include "extensions/browser/info_map.h" |
| #include "extensions/common/extension.h" |
| @@ -25,34 +26,31 @@ bool AllowCrossRendererResourceLoad(net::URLRequest* request, |
| bool* allowed) { |
| const content::ResourceRequestInfo* info = |
| content::ResourceRequestInfo::ForRequest(request); |
| - |
| - // Extensions with webview: allow loading certain resources by guest renderers |
| - // with privileged partition IDs as specified in owner's extension the |
| - // manifest file. |
| - std::string owner_extension_id; |
| - int owner_process_id; |
| - WebViewRendererState::GetInstance()->GetOwnerInfo( |
| - info->GetChildID(), &owner_process_id, &owner_extension_id); |
| - const Extension* owner_extension = |
| - extension_info_map->extensions().GetByID(owner_extension_id); |
| - std::string partition_id; |
| - bool is_guest = WebViewRendererState::GetInstance()->GetPartitionID( |
| - info->GetChildID(), &partition_id); |
| std::string resource_path = request->url().path(); |
| - // |owner_extension == extension| needs to be checked because extension |
| - // resources should only be accessible to WebViews owned by that extension. |
| - if (is_guest && owner_extension == extension && |
| - WebviewInfo::IsResourceWebviewAccessible(extension, partition_id, |
| - resource_path)) { |
| - *allowed = true; |
| - return true; |
| - } |
| - |
| - if (is_guest && |
| - !ui::PageTransitionIsWebTriggerable(info->GetPageTransition())) { |
| - *allowed = false; |
| - return true; |
| + // PlzNavigate: this logic is performed for main frame requests in |
| + // ExtensionNavigationThrottle::WillStartRequest. |
| + if (info->GetChildID() != -1 || |
| + info->GetResourceType() != content::RESOURCE_TYPE_MAIN_FRAME || |
| + !content::IsBrowserSideNavigationEnabled()) { |
| + // Extensions with webview: allow loading certain resources by guest |
| + // renderers with privileged partition IDs as specified in owner's extension |
| + // the manifest file. |
| + std::string owner_extension_id; |
| + int owner_process_id; |
| + WebViewRendererState::GetInstance()->GetOwnerInfo( |
| + info->GetChildID(), &owner_process_id, &owner_extension_id); |
| + const Extension* owner_extension = |
| + extension_info_map->extensions().GetByID(owner_extension_id); |
| + std::string partition_id; |
| + bool is_guest = WebViewRendererState::GetInstance()->GetPartitionID( |
| + info->GetChildID(), &partition_id); |
| + |
| + if (AllowCrossRendererResourceLoad(is_guest, extension, owner_extension, |
|
Fady Samuel
2016/10/13 15:33:01
Can we call this something else? It's a bit confus
jam
2016/10/13 16:30:06
Done.
|
| + partition_id, resource_path, |
| + info->GetPageTransition(), allowed)) { |
| + return true; |
| + } |
| } |
| // The following checks require that we have an actual extension object. If we |
| @@ -137,5 +135,29 @@ bool IsWebViewRequest(const net::URLRequest* request) { |
| return WebViewRendererState::GetInstance()->IsGuest(info->GetChildID()); |
| } |
| +bool AllowCrossRendererResourceLoad(bool is_guest, |
| + const Extension* extension, |
| + const Extension* owner_extension, |
| + const std::string& partition_id, |
| + const std::string& resource_path, |
| + ui::PageTransition page_transition, |
| + bool* allowed) { |
| + // |owner_extension == extension| needs to be checked because extension |
| + // resources should only be accessible to WebViews owned by that extension. |
| + if (is_guest && owner_extension == extension && |
| + WebviewInfo::IsResourceWebviewAccessible(extension, partition_id, |
| + resource_path)) { |
| + *allowed = true; |
| + return true; |
| + } |
| + |
| + if (is_guest && !ui::PageTransitionIsWebTriggerable(page_transition)) { |
| + *allowed = false; |
| + return true; |
| + } |
| + |
| + return false; |
| +} |
| + |
| } // namespace url_request_util |
| } // namespace extensions |