Chromium Code Reviews| Index: components/web_view/navigation_entry.cc |
| diff --git a/components/web_view/navigation_entry.cc b/components/web_view/navigation_entry.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..aa120b8fba9c5314cd4fb287b0a7b4aea7ed7ff6 |
| --- /dev/null |
| +++ b/components/web_view/navigation_entry.cc |
| @@ -0,0 +1,57 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/web_view/navigation_entry.h" |
| + |
| +#include "mojo/common/data_pipe_utils.h" |
| + |
| +namespace web_view { |
| + |
| +NavigationEntry::NavigationEntry(mojo::URLRequestPtr request) |
| + : url_(request->url), |
| + method_(request->method), |
| + headers_(request->headers.Pass()), |
| + response_body_buffer_size_(request->response_body_buffer_size), |
| + auto_follow_redirects_(request->auto_follow_redirects), |
| + bypass_cache_(request->bypass_cache), |
| + body_(request->body.size()) { |
| + // TODO(erg): Maybe we can do some sort of async copy here? |
| + for (size_t i = 0; i < request->body.size(); ++i) |
| + mojo::common::BlockingCopyToString(request->body[i].Pass(), &body_[0]); |
|
msw
2015/09/04 22:04:59
It looks like this repeatedly overwrites body_[0].
|
| +} |
| + |
| +NavigationEntry::~NavigationEntry() {} |
| + |
| +mojo::URLRequestPtr NavigationEntry::AsURLRequest() { |
| + mojo::URLRequestPtr request = mojo::URLRequest::New(); |
| + request->url = url_; |
| + request->method = method_; |
| + request->headers = headers_.Clone(); |
| + request->response_body_buffer_size = response_body_buffer_size_; |
| + request->auto_follow_redirects = auto_follow_redirects_; |
| + request->bypass_cache = bypass_cache_; |
| + |
| + mojo::Array<mojo::ScopedDataPipeConsumerHandle> body; |
| + for (const std::string& body_data : body_) { |
| + // WebKit sometimes gives up empty data to append. These aren't |
|
msw
2015/09/04 22:04:59
I don't see any removal of empty data; is this an
|
| + // necessary so we just optimize those out here. |
| + uint32_t num_bytes = body_data.size(); |
| + MojoCreateDataPipeOptions options; |
| + options.struct_size = sizeof(MojoCreateDataPipeOptions); |
| + options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE; |
| + options.element_num_bytes = 1; |
| + options.capacity_num_bytes = num_bytes; |
| + mojo::DataPipe data_pipe(options); |
| + body.push_back(data_pipe.consumer_handle.Pass()); |
|
msw
2015/09/04 22:04:59
nit: use request->body directly and avoid the loca
|
| + WriteDataRaw(data_pipe.producer_handle.get(), |
| + body_data.data(), |
| + &num_bytes, |
|
msw
2015/09/04 22:04:59
Maybe [d]check that num_bytes == body_data.size()
|
| + MOJO_WRITE_DATA_FLAG_ALL_OR_NONE); |
| + } |
| + request->body = body.Pass(); |
| + |
| + return request.Pass(); |
| +} |
| + |
| +} // namespace web_view |