Commit a4e97a50 authored by Batalov Vladislav's avatar Batalov Vladislav Committed by Commit Bot

Fix network blocking via cache flags.

According docs the LOAD_ONLY_FROM_CACHE flag guarantees that
any navigation with it will fail if it cannot serve the
resource from the cache (or some equivalent local store).
However, this flag is used only by http_cache_transaction
which isn't created if we are using network context without
http cache at all.
Without cache there is only a http_network_transaction which
completely ignore LOAD_ONLY_FROM_CACHE flag and doesn't fail
requests with it.

Also, this CL fixes `setBlockNetworkLoads` for android webview
without cache.
https://cs.chromium.org/chromium/src/third_party/android_tools/sdk/sources/android-25/android/webkit/WebSettings.java?type=cs&q=setBlockNetworkLoads&g=0&l=887

Change-Id: I04c027fe671f83020cba580fa5c763b09fb00886
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1556775
Commit-Queue: Maks Orlovich <morlovich@chromium.org>
Reviewed-by: default avatarMaks Orlovich <morlovich@chromium.org>
Cr-Commit-Position: refs/heads/master@{#649888}
parent aaa12ffa
......@@ -165,6 +165,9 @@ HttpNetworkTransaction::~HttpNetworkTransaction() {
int HttpNetworkTransaction::Start(const HttpRequestInfo* request_info,
CompletionOnceCallback callback,
const NetLogWithSource& net_log) {
if (request_info->load_flags & LOAD_ONLY_FROM_CACHE)
return ERR_CACHE_MISS;
DCHECK(request_info->traffic_annotation.is_valid());
net_log_ = net_log;
request_ = request_info;
......
......@@ -19640,6 +19640,21 @@ TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ReportElapsedTime) {
#endif // BUILDFLAG(ENABLE_REPORTING)
TEST_F(HttpNetworkTransactionTest, AlwaysFailRequestToCache) {
HttpRequestInfo request;
request.method = "GET";
request.url = GURL("http://example.org/");
request.load_flags = LOAD_ONLY_FROM_CACHE;
std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_));
HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get());
TestCompletionCallback callback1;
int rv = trans.Start(&request, callback1.callback(), NetLogWithSource());
EXPECT_THAT(rv, IsError(ERR_CACHE_MISS));
}
TEST_F(HttpNetworkTransactionTest, ZeroRTTDoesntConfirm) {
HttpRequestInfo request;
request.method = "GET";
......
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