Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "components/web_view/url_request_cloneable.h" | 5 #include "components/web_view/url_request_cloneable.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "mojo/common/data_pipe_utils.h" | 8 #include "mojo/common/data_pipe_utils.h" |
| 9 #include "mojo/common/url_type_converters.h" | 9 #include "mojo/common/url_type_converters.h" |
| 10 | 10 |
| 11 namespace web_view { | 11 namespace web_view { |
| 12 | 12 |
| 13 // TODO(erg): In the long run, we might not want to have a stack of | 13 // TODO(erg): In the long run, we might not want to have a stack of |
| 14 // URLRequestPtrs, but another type that captures most of the data. When I saw | 14 // URLRequestPtrs, but another type that captures most of the data. When I saw |
| 15 // NavigationController the first time, I didn't understand why they made their | 15 // NavigationController the first time, I didn't understand why they made their |
| 16 // own datastructure which kept track of everything in a request. The reason is | 16 // own datastructure which kept track of everything in a request. The reason is |
| 17 // that they have to build requests from multiple different datatypes. | 17 // that they have to build requests from multiple different datatypes. |
| 18 | 18 |
| 19 URLRequestCloneable::URLRequestCloneable(mojo::URLRequestPtr original_request) | 19 URLRequestCloneable::URLRequestCloneable(mojo::URLRequestPtr original_request) |
| 20 : url_(original_request->url), | 20 : url_(original_request->url), |
| 21 method_(original_request->method), | 21 method_(original_request->method), |
| 22 headers_(original_request->headers.Pass()), | 22 headers_(original_request->headers.Pass()), |
| 23 response_body_buffer_size_(original_request->response_body_buffer_size), | 23 response_body_buffer_size_(original_request->response_body_buffer_size), |
| 24 auto_follow_redirects_(original_request->auto_follow_redirects), | 24 auto_follow_redirects_(original_request->auto_follow_redirects), |
| 25 bypass_cache_(original_request->bypass_cache), | 25 bypass_cache_(original_request->bypass_cache), |
| 26 original_body_null_(original_request->body.is_null()), | 26 original_body_null_(original_request->body.is_null()), |
| 27 body_(original_request->body.size()) { | 27 body_(original_request->body.size()), |
| 28 originating_time_(base::TimeTicks::FromInternalValue( | |
| 29 original_request->originating_time_ticks)) { | |
| 28 // TODO(erg): Maybe we can do some sort of async copy here? | 30 // TODO(erg): Maybe we can do some sort of async copy here? |
| 29 for (size_t i = 0; i < original_request->body.size(); ++i) { | 31 for (size_t i = 0; i < original_request->body.size(); ++i) { |
| 30 mojo::common::BlockingCopyToString(original_request->body[i].Pass(), | 32 mojo::common::BlockingCopyToString(original_request->body[i].Pass(), |
| 31 &body_[i]); | 33 &body_[i]); |
| 32 } | 34 } |
| 33 } | 35 } |
| 34 | 36 |
| 35 URLRequestCloneable::URLRequestCloneable(const GURL& raw_url) | 37 URLRequestCloneable::URLRequestCloneable(const GURL& raw_url) |
| 36 : url_(mojo::String::From(raw_url)), | 38 : url_(mojo::String::From(raw_url)), |
| 37 method_("GET"), | 39 method_("GET"), |
| 38 headers_(), | 40 headers_(), |
| 39 response_body_buffer_size_(0), | 41 response_body_buffer_size_(0), |
| 40 auto_follow_redirects_(false), | 42 auto_follow_redirects_(false), |
| 41 bypass_cache_(false), | 43 bypass_cache_(false), |
| 42 original_body_null_(true) { | 44 original_body_null_(true) { |
| 43 } | 45 } |
| 44 | 46 |
| 45 URLRequestCloneable::~URLRequestCloneable() {} | 47 URLRequestCloneable::~URLRequestCloneable() {} |
| 46 | 48 |
| 47 mojo::URLRequestPtr URLRequestCloneable::Clone() const { | 49 mojo::URLRequestPtr URLRequestCloneable::Clone() { |
| 48 mojo::URLRequestPtr request = mojo::URLRequest::New(); | 50 mojo::URLRequestPtr request = mojo::URLRequest::New(); |
| 49 request->url = url_; | 51 request->url = url_; |
| 50 request->method = method_; | 52 request->method = method_; |
| 51 request->headers = headers_.Clone(); | 53 request->headers = headers_.Clone(); |
| 52 request->response_body_buffer_size = response_body_buffer_size_; | 54 request->response_body_buffer_size = response_body_buffer_size_; |
| 53 request->auto_follow_redirects = auto_follow_redirects_; | 55 request->auto_follow_redirects = auto_follow_redirects_; |
| 54 request->bypass_cache = bypass_cache_; | 56 request->bypass_cache = bypass_cache_; |
| 55 | 57 |
| 56 if (!original_body_null_) { | 58 if (!original_body_null_) { |
| 57 request->body = | 59 request->body = |
| 58 mojo::Array<mojo::ScopedDataPipeConsumerHandle>(body_.size()); | 60 mojo::Array<mojo::ScopedDataPipeConsumerHandle>(body_.size()); |
| 59 for (size_t i = 0; i < body_.size(); ++i) { | 61 for (size_t i = 0; i < body_.size(); ++i) { |
| 60 uint32_t num_bytes = static_cast<uint32_t>(body_[i].size()); | 62 uint32_t num_bytes = static_cast<uint32_t>(body_[i].size()); |
| 61 MojoCreateDataPipeOptions options; | 63 MojoCreateDataPipeOptions options; |
| 62 options.struct_size = sizeof(MojoCreateDataPipeOptions); | 64 options.struct_size = sizeof(MojoCreateDataPipeOptions); |
| 63 options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE; | 65 options.flags = MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE; |
| 64 options.element_num_bytes = 1; | 66 options.element_num_bytes = 1; |
| 65 options.capacity_num_bytes = num_bytes; | 67 options.capacity_num_bytes = num_bytes; |
| 66 mojo::DataPipe data_pipe(options); | 68 mojo::DataPipe data_pipe(options); |
| 67 request->body[i] = data_pipe.consumer_handle.Pass(); | 69 request->body[i] = data_pipe.consumer_handle.Pass(); |
| 68 WriteDataRaw(data_pipe.producer_handle.get(), body_[i].data(), &num_bytes, | 70 WriteDataRaw(data_pipe.producer_handle.get(), body_[i].data(), &num_bytes, |
| 69 MOJO_WRITE_DATA_FLAG_ALL_OR_NONE); | 71 MOJO_WRITE_DATA_FLAG_ALL_OR_NONE); |
| 70 DCHECK_EQ(num_bytes, body_[i].size()); | 72 DCHECK_EQ(num_bytes, body_[i].size()); |
| 71 } | 73 } |
| 72 } | 74 } |
| 73 | 75 |
| 76 if (originating_time_.is_null()) { | |
| 77 request->originating_time_ticks = base::TimeTicks::Now().ToInternalValue(); | |
|
sky
2015/10/14 22:46:24
Why do you want to set the time here? If no one su
yzshen1
2015/10/14 22:59:16
When we do back/forward navigation, we clone the o
sky
2015/10/14 23:08:36
Can't the code that clones it reset the time?
yzshen1
2015/10/15 00:05:10
Done.
| |
| 78 } else { | |
| 79 request->originating_time_ticks = originating_time_.ToInternalValue(); | |
| 80 originating_time_ = base::TimeTicks(); | |
| 81 } | |
| 82 | |
| 74 return request.Pass(); | 83 return request.Pass(); |
| 75 } | 84 } |
| 76 | 85 |
| 77 } // namespace web_view | 86 } // namespace web_view |
| OLD | NEW |