Commit 1d773b17 authored by Tim Volodine's avatar Tim Volodine Committed by Commit Bot

[AW NS] Make sure to not call shouldInterceptRequest for special android urls

shouldInterceptRequest callback should not be called for special
android URLs, unless they fail to load. Special android urls are
urls such as "file:///android_asset/", "file:///android_res/"
or "content:" scheme urls.

Fixed tests:
-AwContentsClientShouldInterceptRequestTest.testNotCalledForExistingAsset
-AwContentsClientShouldInterceptRequestTest.testNotCalledForExistingContentUrl
-AwContentsClientShouldInterceptRequestTest.testNotCalledForExistingResource

BUG=893566,841556

Cq-Include-Trybots: master.tryserver.chromium.android:android_mojo
Change-Id: I1fd6275194d2ee2d09822896f53626e96789ff32
Reviewed-on: https://chromium-review.googlesource.com/c/1424892Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Reviewed-by: default avatarTobias Sargeant <tobiasjs@chromium.org>
Commit-Queue: Tim Volodine <timvolodine@chromium.org>
Cr-Commit-Position: refs/heads/master@{#625424}
parent 8dfac453
......@@ -32,6 +32,7 @@ namespace android_webview {
namespace {
const char kAutoLoginHeaderName[] = "X-Auto-Login";
const char kRequestedWithHeaderName[] = "X-Requested-With";
class InterceptResponseDelegate
: public AndroidStreamReaderURLLoader::ResponseDelegate {
......@@ -241,24 +242,38 @@ void InterceptedRequest::Restart() {
request_.load_flags =
UpdateLoadFlags(request_.load_flags, io_thread_client.get());
// TODO: verify the case when WebContents::RenderFrameDeleted is called
// before network request is intercepted (i.e. if that's possible and
// whether it can result in any issues).
io_thread_client->ShouldInterceptRequestAsync(
AwWebResourceRequest(request_),
base::BindOnce(&InterceptedRequest::InterceptResponseReceived,
weak_factory_.GetWeakPtr()));
if (!input_stream_previously_failed_ &&
(request_.url.SchemeIs(url::kContentScheme) ||
android_webview::IsAndroidSpecialFileUrl(request_.url))) {
// Do not call shouldInterceptRequest callback for special android urls,
// unless they fail to load on first attempt. Special android urls are urls
// such as "file:///android_asset/", "file:///android_res/" urls or
// "content:" scheme urls.
InterceptResponseReceived(nullptr);
} else {
// TODO: verify the case when WebContents::RenderFrameDeleted is called
// before network request is intercepted (i.e. if that's possible and
// whether it can result in any issues).
io_thread_client->ShouldInterceptRequestAsync(
AwWebResourceRequest(request_),
base::BindOnce(&InterceptedRequest::InterceptResponseReceived,
weak_factory_.GetWeakPtr()));
}
}
void SetRequestedWithHeader(net::HttpRequestHeaders& headers) {
// We send the application's package name in the X-Requested-With header for
// compatibility with previous WebView versions. This should not be visible to
// shouldInterceptRequest.
request_.headers.SetHeaderIfMissing(
"X-Requested-With",
headers.SetHeaderIfMissing(
kRequestedWithHeaderName,
base::android::BuildInfo::GetInstance()->host_package_name());
}
void InterceptedRequest::InterceptResponseReceived(
std::unique_ptr<AwWebResourceResponse> response) {
SetRequestedWithHeader(request_.headers);
if (response) {
// non-null response: make sure to use it as an override for the
// normal network data.
......
......@@ -22,9 +22,6 @@
-org.chromium.android_webview.test.AwContentsClientShouldInterceptRequestTest.testLoadDataShouldTriggerShouldInterceptRequest
-org.chromium.android_webview.test.AwContentsClientShouldInterceptRequestTest.testLoadDataUrlShouldTriggerShouldInterceptRequest
-org.chromium.android_webview.test.AwContentsClientShouldInterceptRequestTest.testLoadDataWithBaseUrlTriggersShouldInterceptRequest
-org.chromium.android_webview.test.AwContentsClientShouldInterceptRequestTest.testNotCalledForExistingAsset
-org.chromium.android_webview.test.AwContentsClientShouldInterceptRequestTest.testNotCalledForExistingContentUrl
-org.chromium.android_webview.test.AwContentsClientShouldInterceptRequestTest.testNotCalledForExistingResource
-org.chromium.android_webview.test.AwContentsClientShouldInterceptRequestTest.testNotCalledForHttpRedirect
# https://crbug.com/893568
......
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