Commit 7e588d6b authored by jam's avatar jam Committed by Commit bot

Fix <webview> subframe resource loads with PlzNavigate.

Also fix NavigationRequest not handling blocked requests.

This fixes
WebViewTests/WebViewTest.Shim_TestNestedSubframes/*
WebViewTests/WebViewTest.Shim_TestWebViewInsideFrame/*
with PlzNavigate.

BUG=504347
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_site_isolation

Review-Url: https://chromiumcodereview.appspot.com/2441843002
Cr-Commit-Position: refs/heads/master@{#426819}
parent daa2f24e
......@@ -16,6 +16,7 @@
#include "base/values.h"
#include "chrome/common/chrome_paths.h"
#include "content/public/browser/resource_request_info.h"
#include "content/public/common/browser_side_navigation_policy.h"
#include "content/public/test/mock_resource_context.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "extensions/browser/extension_protocols.h"
......@@ -230,18 +231,24 @@ TEST_F(ExtensionProtocolTest, IncognitoRequest) {
// Now do a subframe request.
{
std::unique_ptr<net::URLRequest> request(
resource_context_.GetRequestContext()->CreateRequest(
extension->GetResourceURL("404.html"), net::DEFAULT_PRIORITY,
&test_delegate_));
StartRequest(request.get(), content::RESOURCE_TYPE_SUB_FRAME);
if (cases[i].should_allow_sub_frame_load) {
EXPECT_EQ(net::ERR_FILE_NOT_FOUND, test_delegate_.request_status())
<< cases[i].name;
} else {
EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, test_delegate_.request_status())
<< cases[i].name;
// With PlzNavigate, the subframe navigation requests are blocked in
// ExtensionNavigationThrottle which isn't added in this unit test. This
// is tested in an integration test in
// ExtensionResourceRequestPolicyTest.IframeNavigateToInaccessible.
if (!content::IsBrowserSideNavigationEnabled()) {
std::unique_ptr<net::URLRequest> request(
resource_context_.GetRequestContext()->CreateRequest(
extension->GetResourceURL("404.html"), net::DEFAULT_PRIORITY,
&test_delegate_));
StartRequest(request.get(), content::RESOURCE_TYPE_SUB_FRAME);
if (cases[i].should_allow_sub_frame_load) {
EXPECT_EQ(net::ERR_FILE_NOT_FOUND, test_delegate_.request_status())
<< cases[i].name;
} else {
EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, test_delegate_.request_status())
<< cases[i].name;
}
}
}
}
......@@ -356,12 +363,18 @@ TEST_F(ExtensionProtocolTest, AllowFrameRequests) {
EXPECT_EQ(net::OK, test_delegate_.request_status());
}
{
std::unique_ptr<net::URLRequest> request(
resource_context_.GetRequestContext()->CreateRequest(
extension->GetResourceURL("test.dat"), net::DEFAULT_PRIORITY,
&test_delegate_));
StartRequest(request.get(), content::RESOURCE_TYPE_SUB_FRAME);
EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, test_delegate_.request_status());
// With PlzNavigate, the subframe navigation requests are blocked in
// ExtensionNavigationThrottle which isn't added in this unit test. This is
// tested in an integration test in
// ExtensionResourceRequestPolicyTest.IframeNavigateToInaccessible.
if (!content::IsBrowserSideNavigationEnabled()) {
std::unique_ptr<net::URLRequest> request(
resource_context_.GetRequestContext()->CreateRequest(
extension->GetResourceURL("test.dat"), net::DEFAULT_PRIORITY,
&test_delegate_));
StartRequest(request.get(), content::RESOURCE_TYPE_SUB_FRAME);
EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, test_delegate_.request_status());
}
}
// And subresource types, such as media, should fail.
......
......@@ -450,6 +450,11 @@ void NavigationRequest::OnStartChecksComplete(
return;
}
if (result == NavigationThrottle::BLOCK_REQUEST) {
OnRequestFailed(false, net::ERR_BLOCKED_BY_CLIENT);
return;
}
// Use the SiteInstance of the navigating RenderFrameHost to get access to
// the StoragePartition. Using the url of the navigation will result in a
// wrong StoragePartition being picked when a WebView is navigating.
......
......@@ -36,6 +36,7 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/resource_request_info.h"
#include "content/public/common/browser_side_navigation_policy.h"
#include "content/public/common/resource_type.h"
#include "crypto/secure_hash.h"
#include "crypto/sha2.h"
#include "extensions/browser/content_verifier.h"
......@@ -369,7 +370,7 @@ bool AllowExtensionResourceLoad(net::URLRequest* request,
// PlzNavigate: frame navigations to extensions have already been checked in
// the ExtensionNavigationThrottle.
if (info->GetChildID() == -1 &&
info->GetResourceType() == content::RESOURCE_TYPE_MAIN_FRAME &&
content::IsResourceTypeFrame(info->GetResourceType()) &&
content::IsBrowserSideNavigationEnabled()) {
return true;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment