| 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/strings/string_util.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| 11 #include "mojo/common/common_type_converters.h" | 11 #include "mojo/common/common_type_converters.h" |
| 12 #include "mojo/services/html_viewer/blink_url_request_type_converters.h" | 12 #include "mojo/services/html_viewer/blink_url_request_type_converters.h" |
| 13 #include "mojo/services/network/public/interfaces/network_service.mojom.h" | 13 #include "mojo/services/network/public/interfaces/network_service.mojom.h" |
| 14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 15 #include "third_party/WebKit/public/platform/WebURLError.h" | 15 #include "third_party/WebKit/public/platform/WebURLError.h" |
| 16 #include "third_party/WebKit/public/platform/WebURLLoadTiming.h" | 16 #include "third_party/WebKit/public/platform/WebURLLoadTiming.h" |
| 17 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" | 17 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" |
| 18 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 18 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
| 19 | 19 |
| 20 namespace mojo { | 20 using mojo::URLResponsePtr; |
| 21 |
| 22 namespace html_viewer { |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| 23 static blink::WebURLResponse::HTTPVersion StatusLineToHTTPVersion( | 25 blink::WebURLResponse::HTTPVersion StatusLineToHTTPVersion( |
| 24 const String& status_line) { | 26 const mojo::String& status_line) { |
| 25 if (status_line.is_null()) | 27 if (status_line.is_null()) |
| 26 return blink::WebURLResponse::HTTP_0_9; | 28 return blink::WebURLResponse::HTTP_0_9; |
| 27 | 29 |
| 28 if (StartsWithASCII(status_line, "HTTP/1.0", true)) | 30 if (StartsWithASCII(status_line, "HTTP/1.0", true)) |
| 29 return blink::WebURLResponse::HTTP_1_0; | 31 return blink::WebURLResponse::HTTP_1_0; |
| 30 | 32 |
| 31 if (StartsWithASCII(status_line, "HTTP/1.1", true)) | 33 if (StartsWithASCII(status_line, "HTTP/1.1", true)) |
| 32 return blink::WebURLResponse::HTTP_1_1; | 34 return blink::WebURLResponse::HTTP_1_1; |
| 33 | 35 |
| 34 return blink::WebURLResponse::Unknown; | 36 return blink::WebURLResponse::Unknown; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 } | 70 } |
| 69 | 71 |
| 70 } // namespace | 72 } // namespace |
| 71 | 73 |
| 72 WebURLRequestExtraData::WebURLRequestExtraData() { | 74 WebURLRequestExtraData::WebURLRequestExtraData() { |
| 73 } | 75 } |
| 74 | 76 |
| 75 WebURLRequestExtraData::~WebURLRequestExtraData() { | 77 WebURLRequestExtraData::~WebURLRequestExtraData() { |
| 76 } | 78 } |
| 77 | 79 |
| 78 WebURLLoaderImpl::WebURLLoaderImpl(NetworkService* network_service) | 80 WebURLLoaderImpl::WebURLLoaderImpl(mojo::NetworkService* network_service) |
| 79 : client_(NULL), | 81 : client_(NULL), weak_factory_(this) { |
| 80 weak_factory_(this) { | |
| 81 network_service->CreateURLLoader(GetProxy(&url_loader_)); | 82 network_service->CreateURLLoader(GetProxy(&url_loader_)); |
| 82 } | 83 } |
| 83 | 84 |
| 84 WebURLLoaderImpl::~WebURLLoaderImpl() { | 85 WebURLLoaderImpl::~WebURLLoaderImpl() { |
| 85 } | 86 } |
| 86 | 87 |
| 87 void WebURLLoaderImpl::loadSynchronously( | 88 void WebURLLoaderImpl::loadSynchronously( |
| 88 const blink::WebURLRequest& request, | 89 const blink::WebURLRequest& request, |
| 89 blink::WebURLResponse& response, | 90 blink::WebURLResponse& response, |
| 90 blink::WebURLError& error, | 91 blink::WebURLError& error, |
| 91 blink::WebData& data) { | 92 blink::WebData& data) { |
| 92 NOTIMPLEMENTED(); | 93 NOTIMPLEMENTED(); |
| 93 } | 94 } |
| 94 | 95 |
| 95 void WebURLLoaderImpl::loadAsynchronously(const blink::WebURLRequest& request, | 96 void WebURLLoaderImpl::loadAsynchronously(const blink::WebURLRequest& request, |
| 96 blink::WebURLLoaderClient* client) { | 97 blink::WebURLLoaderClient* client) { |
| 97 client_ = client; | 98 client_ = client; |
| 98 url_ = request.url(); | 99 url_ = request.url(); |
| 99 | 100 |
| 100 URLRequestPtr url_request = URLRequest::From(request); | 101 mojo::URLRequestPtr url_request = mojo::URLRequest::From(request); |
| 101 url_request->auto_follow_redirects = false; | 102 url_request->auto_follow_redirects = false; |
| 102 | 103 |
| 103 if (request.extraData()) { | 104 if (request.extraData()) { |
| 104 WebURLRequestExtraData* extra_data = | 105 WebURLRequestExtraData* extra_data = |
| 105 static_cast<WebURLRequestExtraData*>(request.extraData()); | 106 static_cast<WebURLRequestExtraData*>(request.extraData()); |
| 106 base::ThreadTaskRunnerHandle::Get()->PostTask( | 107 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 107 FROM_HERE, | 108 FROM_HERE, |
| 108 base::Bind(&WebURLLoaderImpl::OnReceivedResponse, | 109 base::Bind(&WebURLLoaderImpl::OnReceivedResponse, |
| 109 weak_factory_.GetWeakPtr(), | 110 weak_factory_.GetWeakPtr(), |
| 110 base::Passed(&extra_data->synthetic_response))); | 111 base::Passed(&extra_data->synthetic_response))); |
| 111 } else { | 112 } else { |
| 112 url_loader_->Start(url_request.Pass(), | 113 url_loader_->Start(url_request.Pass(), |
| 113 base::Bind(&WebURLLoaderImpl::OnReceivedResponse, | 114 base::Bind(&WebURLLoaderImpl::OnReceivedResponse, |
| 114 weak_factory_.GetWeakPtr())); | 115 weak_factory_.GetWeakPtr())); |
| 115 } | 116 } |
| 116 } | 117 } |
| 117 | 118 |
| 118 void WebURLLoaderImpl::cancel() { | 119 void WebURLLoaderImpl::cancel() { |
| 119 url_loader_.reset(); | 120 url_loader_.reset(); |
| 120 response_body_stream_.reset(); | 121 response_body_stream_.reset(); |
| 121 | 122 |
| 122 URLResponsePtr failed_response(URLResponse::New()); | 123 URLResponsePtr failed_response(mojo::URLResponse::New()); |
| 123 failed_response->url = String::From(url_); | 124 failed_response->url = mojo::String::From(url_); |
| 124 failed_response->error = NetworkError::New(); | 125 failed_response->error = mojo::NetworkError::New(); |
| 125 failed_response->error->code = net::ERR_ABORTED; | 126 failed_response->error->code = net::ERR_ABORTED; |
| 126 | 127 |
| 127 base::ThreadTaskRunnerHandle::Get()->PostTask( | 128 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 128 FROM_HERE, | 129 FROM_HERE, |
| 129 base::Bind(&WebURLLoaderImpl::OnReceivedResponse, | 130 base::Bind(&WebURLLoaderImpl::OnReceivedResponse, |
| 130 weak_factory_.GetWeakPtr(), | 131 weak_factory_.GetWeakPtr(), |
| 131 base::Passed(&failed_response))); | 132 base::Passed(&failed_response))); |
| 132 } | 133 } |
| 133 | 134 |
| 134 void WebURLLoaderImpl::setDefersLoading(bool defers_loading) { | 135 void WebURLLoaderImpl::setDefersLoading(bool defers_loading) { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 MOJO_HANDLE_SIGNAL_READABLE, | 215 MOJO_HANDLE_SIGNAL_READABLE, |
| 215 MOJO_DEADLINE_INDEFINITE, | 216 MOJO_DEADLINE_INDEFINITE, |
| 216 base::Bind(&WebURLLoaderImpl::OnResponseBodyStreamReady, | 217 base::Bind(&WebURLLoaderImpl::OnResponseBodyStreamReady, |
| 217 weak_factory_.GetWeakPtr())); | 218 weak_factory_.GetWeakPtr())); |
| 218 } | 219 } |
| 219 | 220 |
| 220 void WebURLLoaderImpl::OnResponseBodyStreamReady(MojoResult result) { | 221 void WebURLLoaderImpl::OnResponseBodyStreamReady(MojoResult result) { |
| 221 ReadMore(); | 222 ReadMore(); |
| 222 } | 223 } |
| 223 | 224 |
| 224 } // namespace mojo | 225 } // namespace html_viewer |
| OLD | NEW |