OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/web_view/navigation_entry.h" | |
6 | |
7 #include "mojo/common/data_pipe_utils.h" | |
8 | |
9 namespace web_view { | |
10 | |
11 NavigationEntry::NavigationEntry(mojo::URLRequestPtr request) | |
12 : url_(request->url), | |
13 method_(request->method), | |
14 headers_(request->headers.Pass()), | |
15 response_body_buffer_size_(request->response_body_buffer_size), | |
16 auto_follow_redirects_(request->auto_follow_redirects), | |
17 bypass_cache_(request->bypass_cache), | |
18 body_(request->body.size()) { | |
19 // TODO(erg): Maybe we can do some sort of async copy here? | |
20 for (size_t i = 0; i < request->body.size(); ++i) | |
21 mojo::common::BlockingCopyToString(request->body[i].Pass(), &body_[0]); | |
msw
2015/09/04 22:04:59
It looks like this repeatedly overwrites body_[0].
| |
22 } | |
23 | |
24 NavigationEntry::~NavigationEntry() {} | |
25 | |
26 mojo::URLRequestPtr NavigationEntry::AsURLRequest() { | |
27 mojo::URLRequestPtr request = mojo::URLRequest::New(); | |
28 request->url = url_; | |
29 request->method = method_; | |
30 request->headers = headers_.Clone(); | |
31 request->response_body_buffer_size = response_body_buffer_size_; | |
32 request->auto_follow_redirects = auto_follow_redirects_; | |
33 request->bypass_cache = bypass_cache_; | |
34 | |
35 mojo::Array<mojo::ScopedDataPipeConsumerHandle> body; | |
36 for (const std::string& body_data : body_) { | |
37 // 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
| |
38 // necessary so we just optimize those out here. | |
39 uint32_t num_bytes = body_data.size(); | |
40 MojoCreateDataPipeOptions options; | |
41 options.struct_size = sizeof(MojoCreateDataPipeOptions); | |
42 options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE; | |
43 options.element_num_bytes = 1; | |
44 options.capacity_num_bytes = num_bytes; | |
45 mojo::DataPipe data_pipe(options); | |
46 body.push_back(data_pipe.consumer_handle.Pass()); | |
msw
2015/09/04 22:04:59
nit: use request->body directly and avoid the loca
| |
47 WriteDataRaw(data_pipe.producer_handle.get(), | |
48 body_data.data(), | |
49 &num_bytes, | |
msw
2015/09/04 22:04:59
Maybe [d]check that num_bytes == body_data.size()
| |
50 MOJO_WRITE_DATA_FLAG_ALL_OR_NONE); | |
51 } | |
52 request->body = body.Pass(); | |
53 | |
54 return request.Pass(); | |
55 } | |
56 | |
57 } // namespace web_view | |
OLD | NEW |