| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mojo/services/html_viewer/weburlloader_impl.h" | 5 #include "mojo/services/html_viewer/weburlloader_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/strings/string_util.h" |
| 9 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| 10 #include "mojo/common/common_type_converters.h" | 11 #include "mojo/common/common_type_converters.h" |
| 11 #include "mojo/services/html_viewer/blink_url_request_type_converters.h" | 12 #include "mojo/services/html_viewer/blink_url_request_type_converters.h" |
| 12 #include "mojo/services/public/interfaces/network/network_service.mojom.h" | 13 #include "mojo/services/public/interfaces/network/network_service.mojom.h" |
| 13 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 14 #include "third_party/WebKit/public/platform/WebURLError.h" | 15 #include "third_party/WebKit/public/platform/WebURLError.h" |
| 15 #include "third_party/WebKit/public/platform/WebURLLoadTiming.h" | 16 #include "third_party/WebKit/public/platform/WebURLLoadTiming.h" |
| 16 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" | 17 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" |
| 17 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 18 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
| 18 | 19 |
| 19 namespace mojo { | 20 namespace mojo { |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 23 static blink::WebURLResponse::HTTPVersion StatusLineToHTTPVersion( |
| 24 const String& status_line) { |
| 25 if (status_line.is_null()) |
| 26 return blink::WebURLResponse::HTTP_0_9; |
| 27 |
| 28 if (StartsWithASCII(status_line, "HTTP/1.0", true)) |
| 29 return blink::WebURLResponse::HTTP_1_0; |
| 30 |
| 31 if (StartsWithASCII(status_line, "HTTP/1.1", true)) |
| 32 return blink::WebURLResponse::HTTP_1_1; |
| 33 |
| 34 return blink::WebURLResponse::Unknown; |
| 35 } |
| 36 |
| 22 blink::WebURLResponse ToWebURLResponse(const URLResponsePtr& url_response) { | 37 blink::WebURLResponse ToWebURLResponse(const URLResponsePtr& url_response) { |
| 23 blink::WebURLResponse result; | 38 blink::WebURLResponse result; |
| 24 result.initialize(); | 39 result.initialize(); |
| 25 result.setURL(GURL(url_response->url)); | 40 result.setURL(GURL(url_response->url)); |
| 26 result.setMIMEType(blink::WebString::fromUTF8(url_response->mime_type)); | 41 result.setMIMEType(blink::WebString::fromUTF8(url_response->mime_type)); |
| 27 result.setTextEncodingName(blink::WebString::fromUTF8(url_response->charset)); | 42 result.setTextEncodingName(blink::WebString::fromUTF8(url_response->charset)); |
| 43 result.setHTTPVersion(StatusLineToHTTPVersion(url_response->status_line)); |
| 28 result.setHTTPStatusCode(url_response->status_code); | 44 result.setHTTPStatusCode(url_response->status_code); |
| 29 | 45 |
| 30 // TODO(darin): Initialize timing properly. | 46 // TODO(darin): Initialize timing properly. |
| 31 blink::WebURLLoadTiming timing; | 47 blink::WebURLLoadTiming timing; |
| 32 timing.initialize(); | 48 timing.initialize(); |
| 33 result.setLoadTiming(timing); | 49 result.setLoadTiming(timing); |
| 34 | 50 |
| 35 // TODO(darin): Copy other fields. | 51 for (size_t i = 0; i < url_response->headers.size(); ++i) { |
| 52 const std::string& header_line = url_response->headers[i]; |
| 53 size_t first_colon = header_line.find(":"); |
| 54 |
| 55 if (first_colon == std::string::npos || first_colon == 0) |
| 56 continue; |
| 57 |
| 58 std::string value; |
| 59 TrimWhitespaceASCII(header_line.substr(first_colon + 1), |
| 60 base::TRIM_LEADING, |
| 61 &value); |
| 62 result.setHTTPHeaderField( |
| 63 blink::WebString::fromUTF8(header_line.substr(0, first_colon)), |
| 64 blink::WebString::fromUTF8(value)); |
| 65 } |
| 66 |
| 36 return result; | 67 return result; |
| 37 } | 68 } |
| 38 | 69 |
| 39 } // namespace | 70 } // namespace |
| 40 | 71 |
| 41 WebURLRequestExtraData::WebURLRequestExtraData() { | 72 WebURLRequestExtraData::WebURLRequestExtraData() { |
| 42 } | 73 } |
| 43 | 74 |
| 44 WebURLRequestExtraData::~WebURLRequestExtraData() { | 75 WebURLRequestExtraData::~WebURLRequestExtraData() { |
| 45 } | 76 } |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 MOJO_DEADLINE_INDEFINITE, | 215 MOJO_DEADLINE_INDEFINITE, |
| 185 base::Bind(&WebURLLoaderImpl::OnResponseBodyStreamReady, | 216 base::Bind(&WebURLLoaderImpl::OnResponseBodyStreamReady, |
| 186 weak_factory_.GetWeakPtr())); | 217 weak_factory_.GetWeakPtr())); |
| 187 } | 218 } |
| 188 | 219 |
| 189 void WebURLLoaderImpl::OnResponseBodyStreamReady(MojoResult result) { | 220 void WebURLLoaderImpl::OnResponseBodyStreamReady(MojoResult result) { |
| 190 ReadMore(); | 221 ReadMore(); |
| 191 } | 222 } |
| 192 | 223 |
| 193 } // namespace mojo | 224 } // namespace mojo |
| OLD | NEW |