Commit 6ab49c43 authored by Lucas Furukawa Gadani's avatar Lucas Furukawa Gadani Committed by Commit Bot

Convert android_webview to use the URLResponseHead mojom types.

Bug: 984550
Change-Id: I2bf27ce77287394c782692483117ee105e214563
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1875385Reviewed-by: default avatarBo <boliu@chromium.org>
Commit-Queue: Lucas Gadani <lfg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708731}
parent cd10afac
...@@ -100,8 +100,7 @@ AndroidStreamReaderURLLoader::AndroidStreamReaderURLLoader( ...@@ -100,8 +100,7 @@ AndroidStreamReaderURLLoader::AndroidStreamReaderURLLoader(
const net::MutableNetworkTrafficAnnotationTag& traffic_annotation, const net::MutableNetworkTrafficAnnotationTag& traffic_annotation,
std::unique_ptr<ResponseDelegate> response_delegate) std::unique_ptr<ResponseDelegate> response_delegate)
: resource_request_(resource_request), : resource_request_(resource_request),
resource_response_head_( response_head_(network::mojom::URLResponseHead::New()),
std::make_unique<network::ResourceResponseHead>()),
client_(std::move(client)), client_(std::move(client)),
traffic_annotation_(traffic_annotation), traffic_annotation_(traffic_annotation),
response_delegate_(std::move(response_delegate)), response_delegate_(std::move(response_delegate)),
...@@ -218,7 +217,7 @@ void AndroidStreamReaderURLLoader::HeadersComplete( ...@@ -218,7 +217,7 @@ void AndroidStreamReaderURLLoader::HeadersComplete(
// HttpResponseHeaders expects its input string to be terminated by two NULs. // HttpResponseHeaders expects its input string to be terminated by two NULs.
status.append("\0\0", 2); status.append("\0\0", 2);
network::ResourceResponseHead& head = *resource_response_head_; network::mojom::URLResponseHead& head = *response_head_;
head.request_start = base::TimeTicks::Now(); head.request_start = base::TimeTicks::Now();
head.response_start = base::TimeTicks::Now(); head.response_start = base::TimeTicks::Now();
head.headers = new net::HttpResponseHeaders(status); head.headers = new net::HttpResponseHeaders(status);
...@@ -286,7 +285,7 @@ void AndroidStreamReaderURLLoader::SendBody() { ...@@ -286,7 +285,7 @@ void AndroidStreamReaderURLLoader::SendBody() {
// needs the ability to break the stream after getting the headers but // needs the ability to break the stream after getting the headers but
// before finishing the read. // before finishing the read.
if (!base::FeatureList::IsEnabled(features::kWebViewSniffMimeType) || if (!base::FeatureList::IsEnabled(features::kWebViewSniffMimeType) ||
!resource_response_head_->mime_type.empty()) { !response_head_->mime_type.empty()) {
SendResponseToClient(); SendResponseToClient();
} }
ReadMore(); ReadMore();
...@@ -295,8 +294,7 @@ void AndroidStreamReaderURLLoader::SendBody() { ...@@ -295,8 +294,7 @@ void AndroidStreamReaderURLLoader::SendBody() {
void AndroidStreamReaderURLLoader::SendResponseToClient() { void AndroidStreamReaderURLLoader::SendResponseToClient() {
DCHECK(consumer_handle_.is_valid()); DCHECK(consumer_handle_.is_valid());
DCHECK(client_.is_bound()); DCHECK(client_.is_bound());
client_->OnReceiveResponse(*resource_response_head_); client_->OnReceiveResponse(std::move(response_head_));
resource_response_head_ = nullptr;
client_->OnStartLoadingResponseBody(std::move(consumer_handle_)); client_->OnStartLoadingResponseBody(std::move(consumer_handle_));
} }
...@@ -360,7 +358,7 @@ void AndroidStreamReaderURLLoader::DidRead(int result) { ...@@ -360,7 +358,7 @@ void AndroidStreamReaderURLLoader::DidRead(int result) {
// We only hit this on for the first buffer read, which we expect to be // We only hit this on for the first buffer read, which we expect to be
// enough to determine the MIME type. // enough to determine the MIME type.
DCHECK(base::FeatureList::IsEnabled(features::kWebViewSniffMimeType)); DCHECK(base::FeatureList::IsEnabled(features::kWebViewSniffMimeType));
if (resource_response_head_->mime_type.empty()) { if (response_head_->mime_type.empty()) {
// Limit sniffing to the first net::kMaxBytesToSniff. // Limit sniffing to the first net::kMaxBytesToSniff.
size_t data_length = result; size_t data_length = result;
if (data_length > net::kMaxBytesToSniff) if (data_length > net::kMaxBytesToSniff)
...@@ -373,8 +371,8 @@ void AndroidStreamReaderURLLoader::DidRead(int result) { ...@@ -373,8 +371,8 @@ void AndroidStreamReaderURLLoader::DidRead(int result) {
// SniffMimeType() returns false if there is not enough data to // SniffMimeType() returns false if there is not enough data to
// determine the mime type. However, even if it returns false, it // determine the mime type. However, even if it returns false, it
// returns a new type that is probably better than the current one. // returns a new type that is probably better than the current one.
resource_response_head_->mime_type.assign(new_type); response_head_->mime_type.assign(new_type);
resource_response_head_->did_mime_sniff = true; response_head_->did_mime_sniff = true;
} }
SendResponseToClient(); SendResponseToClient();
......
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
#include "mojo/public/cpp/system/simple_watcher.h" #include "mojo/public/cpp/system/simple_watcher.h"
#include "net/http/http_byte_range.h" #include "net/http/http_byte_range.h"
#include "services/network/public/cpp/net_adapters.h" #include "services/network/public/cpp/net_adapters.h"
#include "services/network/public/cpp/resource_response.h"
#include "services/network/public/mojom/url_loader.mojom.h" #include "services/network/public/mojom/url_loader.mojom.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
namespace android_webview { namespace android_webview {
...@@ -107,7 +107,7 @@ class AndroidStreamReaderURLLoader : public network::mojom::URLLoader { ...@@ -107,7 +107,7 @@ class AndroidStreamReaderURLLoader : public network::mojom::URLLoader {
net::HttpByteRange byte_range_; net::HttpByteRange byte_range_;
network::ResourceRequest resource_request_; network::ResourceRequest resource_request_;
std::unique_ptr<network::ResourceResponseHead> resource_response_head_; network::mojom::URLResponseHeadPtr response_head_;
network::mojom::URLLoaderClientPtr client_; network::mojom::URLLoaderClientPtr client_;
const net::MutableNetworkTrafficAnnotationTag traffic_annotation_; const net::MutableNetworkTrafficAnnotationTag traffic_annotation_;
std::unique_ptr<ResponseDelegate> response_delegate_; std::unique_ptr<ResponseDelegate> response_delegate_;
......
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