Commit e0857290 authored by acolwell's avatar acolwell Committed by Commit bot

Fix Mojo's WebURLLoader so that it provides protocol version and headers.

media::BufferedResourceLoader needs HTTP protocol and header information
in the HTTP responses so that it can properly detect live streams and
whether Range: headers are supported. This patch provides the missing
functionality needed by the media code.

Review URL: https://codereview.chromium.org/566453002

Cr-Commit-Position: refs/heads/master@{#294304}
parent 484d29dc
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/string_util.h"
#include "base/thread_task_runner_handle.h" #include "base/thread_task_runner_handle.h"
#include "mojo/common/common_type_converters.h" #include "mojo/common/common_type_converters.h"
#include "mojo/services/html_viewer/blink_url_request_type_converters.h" #include "mojo/services/html_viewer/blink_url_request_type_converters.h"
...@@ -19,12 +20,27 @@ ...@@ -19,12 +20,27 @@
namespace mojo { namespace mojo {
namespace { namespace {
static blink::WebURLResponse::HTTPVersion StatusLineToHTTPVersion(
const String& status_line) {
if (status_line.is_null())
return blink::WebURLResponse::HTTP_0_9;
if (StartsWithASCII(status_line, "HTTP/1.0", true))
return blink::WebURLResponse::HTTP_1_0;
if (StartsWithASCII(status_line, "HTTP/1.1", true))
return blink::WebURLResponse::HTTP_1_1;
return blink::WebURLResponse::Unknown;
}
blink::WebURLResponse ToWebURLResponse(const URLResponsePtr& url_response) { blink::WebURLResponse ToWebURLResponse(const URLResponsePtr& url_response) {
blink::WebURLResponse result; blink::WebURLResponse result;
result.initialize(); result.initialize();
result.setURL(GURL(url_response->url)); result.setURL(GURL(url_response->url));
result.setMIMEType(blink::WebString::fromUTF8(url_response->mime_type)); result.setMIMEType(blink::WebString::fromUTF8(url_response->mime_type));
result.setTextEncodingName(blink::WebString::fromUTF8(url_response->charset)); result.setTextEncodingName(blink::WebString::fromUTF8(url_response->charset));
result.setHTTPVersion(StatusLineToHTTPVersion(url_response->status_line));
result.setHTTPStatusCode(url_response->status_code); result.setHTTPStatusCode(url_response->status_code);
// TODO(darin): Initialize timing properly. // TODO(darin): Initialize timing properly.
...@@ -32,7 +48,22 @@ blink::WebURLResponse ToWebURLResponse(const URLResponsePtr& url_response) { ...@@ -32,7 +48,22 @@ blink::WebURLResponse ToWebURLResponse(const URLResponsePtr& url_response) {
timing.initialize(); timing.initialize();
result.setLoadTiming(timing); result.setLoadTiming(timing);
// TODO(darin): Copy other fields. for (size_t i = 0; i < url_response->headers.size(); ++i) {
const std::string& header_line = url_response->headers[i];
size_t first_colon = header_line.find(":");
if (first_colon == std::string::npos || first_colon == 0)
continue;
std::string value;
TrimWhitespaceASCII(header_line.substr(first_colon + 1),
base::TRIM_LEADING,
&value);
result.setHTTPHeaderField(
blink::WebString::fromUTF8(header_line.substr(0, first_colon)),
blink::WebString::fromUTF8(value));
}
return result; return result;
} }
......
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