Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(411)

Side by Side Diff: components/web_view/url_request_cloneable.cc

Issue 1326443006: mandoline: Add back/forward support and UI. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: msw nits and comments Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/url_request_cloneable.h"
6
7 #include "base/logging.h"
8 #include "mojo/common/data_pipe_utils.h"
9
10 namespace web_view {
11
12 URLRequestCloneable::URLRequestCloneable(mojo::URLRequestPtr original_request)
13 : url_(original_request->url),
14 method_(original_request->method),
15 headers_(original_request->headers.Pass()),
16 response_body_buffer_size_(original_request->response_body_buffer_size),
17 auto_follow_redirects_(original_request->auto_follow_redirects),
18 bypass_cache_(original_request->bypass_cache),
19 body_(original_request->body.size()) {
sky 2015/09/08 16:00:32 I believe this force body_ to non-null, even if or
20 // TODO(erg): Maybe we can do some sort of async copy here?
21 for (size_t i = 0; i < original_request->body.size(); ++i) {
22 mojo::common::BlockingCopyToString(original_request->body[i].Pass(),
23 &body_[i]);
24 }
25 }
26
27 URLRequestCloneable::~URLRequestCloneable() {}
28
29 mojo::URLRequestPtr URLRequestCloneable::Clone() const {
30 mojo::URLRequestPtr request = mojo::URLRequest::New();
31 request->url = url_;
32 request->method = method_;
33 request->headers = headers_.Clone();
34 request->response_body_buffer_size = response_body_buffer_size_;
35 request->auto_follow_redirects = auto_follow_redirects_;
36 request->bypass_cache = bypass_cache_;
37
38 for (const std::string& body_data : body_) {
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 request->body.push_back(data_pipe.consumer_handle.Pass());
47 WriteDataRaw(data_pipe.producer_handle.get(),
48 body_data.data(),
49 &num_bytes,
50 MOJO_WRITE_DATA_FLAG_ALL_OR_NONE);
51 DCHECK_EQ(num_bytes, body_data.size());
52 }
53
54 return request.Pass();
55 }
56
57 } // namespace web_view
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698