Chromium Code Reviews| 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 "content/browser/frame_host/navigation_request.h" | 5 #include "content/browser/frame_host/navigation_request.h" |
| 6 | 6 |
| 7 #include "content/browser/frame_host/frame_tree.h" | 7 #include "content/browser/frame_host/frame_tree.h" |
| 8 #include "content/browser/frame_host/frame_tree_node.h" | 8 #include "content/browser/frame_host/frame_tree_node.h" |
| 9 #include "content/browser/frame_host/navigation_controller_impl.h" | |
| 9 #include "content/browser/frame_host/navigation_request_info.h" | 10 #include "content/browser/frame_host/navigation_request_info.h" |
| 10 #include "content/browser/frame_host/navigator.h" | 11 #include "content/browser/frame_host/navigator.h" |
| 11 #include "content/browser/loader/navigation_url_loader.h" | 12 #include "content/browser/loader/navigation_url_loader.h" |
| 12 #include "content/browser/site_instance_impl.h" | 13 #include "content/browser/site_instance_impl.h" |
| 13 #include "content/common/resource_request_body.h" | 14 #include "content/common/resource_request_body.h" |
| 14 #include "content/public/browser/navigation_controller.h" | 15 #include "content/public/browser/navigation_controller.h" |
| 15 #include "content/public/browser/stream_handle.h" | 16 #include "content/public/browser/stream_handle.h" |
| 16 #include "content/public/common/content_client.h" | 17 #include "content/public/common/content_client.h" |
| 17 #include "net/base/load_flags.h" | 18 #include "net/base/load_flags.h" |
| 18 #include "net/http/http_request_headers.h" | 19 #include "net/http/http_request_headers.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 // TODO(clamy): same document navigations should not make network requests. | 56 // TODO(clamy): same document navigations should not make network requests. |
| 56 return !url.SchemeIs(url::kDataScheme); | 57 return !url.SchemeIs(url::kDataScheme); |
| 57 } | 58 } |
| 58 | 59 |
| 59 // static | 60 // static |
| 60 scoped_ptr<NavigationRequest> NavigationRequest::CreateBrowserInitiated( | 61 scoped_ptr<NavigationRequest> NavigationRequest::CreateBrowserInitiated( |
| 61 FrameTreeNode* frame_tree_node, | 62 FrameTreeNode* frame_tree_node, |
| 62 const NavigationEntryImpl& entry, | 63 const NavigationEntryImpl& entry, |
| 63 FrameMsg_Navigate_Type::Value navigation_type, | 64 FrameMsg_Navigate_Type::Value navigation_type, |
| 64 base::TimeTicks navigation_start, | 65 base::TimeTicks navigation_start, |
| 65 const HistoryNavigationParams& history_params) { | 66 NavigationControllerImpl* controller) { |
| 66 std::string method = entry.GetHasPostData() ? "POST" : "GET"; | 67 std::string method = entry.GetHasPostData() ? "POST" : "GET"; |
| 67 | 68 |
| 68 // Copy existing headers and add necessary headers that may not be present | 69 // Copy existing headers and add necessary headers that may not be present |
| 69 // in the RequestNavigationParams. | 70 // in the RequestNavigationParams. |
| 70 net::HttpRequestHeaders headers; | 71 net::HttpRequestHeaders headers; |
| 71 headers.AddHeadersFromString(entry.extra_headers()); | 72 headers.AddHeadersFromString(entry.extra_headers()); |
| 72 headers.SetHeaderIfMissing(net::HttpRequestHeaders::kUserAgent, | 73 headers.SetHeaderIfMissing(net::HttpRequestHeaders::kUserAgent, |
| 73 GetContentClient()->GetUserAgent()); | 74 GetContentClient()->GetUserAgent()); |
| 74 // TODO(clamy): match what blink is doing with accept headers. | 75 // TODO(clamy): match what blink is doing with accept headers. |
| 75 headers.SetHeaderIfMissing("Accept", "*/*"); | 76 headers.SetHeaderIfMissing("Accept", "*/*"); |
| 76 | 77 |
| 77 // Fill POST data from the browser in the request body. | 78 // Fill POST data from the browser in the request body. |
| 78 scoped_refptr<ResourceRequestBody> request_body; | 79 scoped_refptr<ResourceRequestBody> request_body; |
| 79 if (entry.GetHasPostData()) { | 80 if (entry.GetHasPostData()) { |
| 80 request_body = new ResourceRequestBody(); | 81 request_body = new ResourceRequestBody(); |
| 81 request_body->AppendBytes( | 82 request_body->AppendBytes( |
| 82 reinterpret_cast<const char *>( | 83 reinterpret_cast<const char *>( |
| 83 entry.GetBrowserInitiatedPostData()->front()), | 84 entry.GetBrowserInitiatedPostData()->front()), |
| 84 entry.GetBrowserInitiatedPostData()->size()); | 85 entry.GetBrowserInitiatedPostData()->size()); |
| 85 } | 86 } |
| 86 | 87 |
| 87 FrameMsg_UILoadMetricsReportType::Value report_type = | |
| 88 FrameMsg_UILoadMetricsReportType::NO_REPORT; | |
| 89 base::TimeTicks ui_timestamp = base::TimeTicks(); | |
| 90 #if defined(OS_ANDROID) | |
| 91 if (!entry.intent_received_timestamp().is_null()) | |
| 92 report_type = FrameMsg_UILoadMetricsReportType::REPORT_INTENT; | |
| 93 ui_timestamp = entry.intent_received_timestamp(); | |
| 94 #endif | |
| 95 | |
| 96 scoped_ptr<NavigationRequest> navigation_request(new NavigationRequest( | 88 scoped_ptr<NavigationRequest> navigation_request(new NavigationRequest( |
| 97 frame_tree_node, | 89 frame_tree_node, entry.MakeCommonNavigationParams(navigation_type), |
| 98 CommonNavigationParams( | |
| 99 entry.GetURL(), entry.GetReferrer(), entry.GetTransitionType(), | |
| 100 navigation_type, !entry.IsViewSourceMode(), ui_timestamp, report_type, | |
| 101 entry.GetBaseURLForDataURL(), entry.GetHistoryURLForDataURL()), | |
| 102 BeginNavigationParams(method, headers.ToString(), | 90 BeginNavigationParams(method, headers.ToString(), |
| 103 LoadFlagFromNavigationType(navigation_type), false), | 91 LoadFlagFromNavigationType(navigation_type), false), |
| 104 CommitNavigationParams(entry.GetIsOverridingUserAgent(), | 92 entry.MakeCommitNavigationParams(navigation_start), |
| 105 navigation_start), | 93 entry.MakeHistoryNavigationParams(controller), request_body, true, |
| 106 history_params, request_body, true, &entry)); | 94 &entry)); |
| 107 return navigation_request.Pass(); | 95 return navigation_request.Pass(); |
| 108 } | 96 } |
| 109 | 97 |
| 110 // static | 98 // static |
| 111 scoped_ptr<NavigationRequest> NavigationRequest::CreateRendererInitiated( | 99 scoped_ptr<NavigationRequest> NavigationRequest::CreateRendererInitiated( |
| 112 FrameTreeNode* frame_tree_node, | 100 FrameTreeNode* frame_tree_node, |
| 113 const CommonNavigationParams& common_params, | 101 const CommonNavigationParams& common_params, |
| 114 const BeginNavigationParams& begin_params, | 102 const BeginNavigationParams& begin_params, |
| 115 scoped_refptr<ResourceRequestBody> body, | 103 scoped_refptr<ResourceRequestBody> body, |
| 116 int current_history_list_offset, | 104 int current_history_list_offset, |
| 117 int current_history_list_length) { | 105 int current_history_list_length) { |
| 118 // TODO(clamy): Check if some PageState should be provided here. | 106 // TODO(clamy): Check if some PageState should be provided here. |
| 119 // TODO(clamy): See how we should handle override of the user agent when the | 107 // TODO(clamy): See how we should handle override of the user agent when the |
| 120 // navigation may start in a renderer and commit in another one. | 108 // navigation may start in a renderer and commit in another one. |
| 121 // TODO(clamy): See if the navigation start time should be measured in the | 109 // TODO(clamy): See if the navigation start time should be measured in the |
| 122 // renderer and sent to the browser instead of being measured here. | 110 // renderer and sent to the browser instead of being measured here. |
| 111 CommitNavigationParams commit_params; | |
| 112 commit_params.browser_navigation_start = base::TimeTicks::Now(); | |
| 113 commit_params.request_time = base::Time::Now(); | |
|
clamy
2015/03/09 14:34:46
This setting of the time needs to be done in every
nasko
2015/03/09 23:24:23
Let's set those in the default creator and then we
clamy
2015/03/10 16:45:44
Done.
| |
| 123 scoped_ptr<NavigationRequest> navigation_request(new NavigationRequest( | 114 scoped_ptr<NavigationRequest> navigation_request(new NavigationRequest( |
| 124 frame_tree_node, common_params, begin_params, | 115 frame_tree_node, common_params, begin_params, commit_params, |
| 125 CommitNavigationParams(false, base::TimeTicks::Now()), | |
| 126 HistoryNavigationParams(PageState(), -1, -1, current_history_list_offset, | 116 HistoryNavigationParams(PageState(), -1, -1, current_history_list_offset, |
| 127 current_history_list_length, false), | 117 current_history_list_length, false), |
| 128 body, false, nullptr)); | 118 body, false, nullptr)); |
| 129 return navigation_request.Pass(); | 119 return navigation_request.Pass(); |
| 130 } | 120 } |
| 131 | 121 |
| 132 NavigationRequest::NavigationRequest( | 122 NavigationRequest::NavigationRequest( |
| 133 FrameTreeNode* frame_tree_node, | 123 FrameTreeNode* frame_tree_node, |
| 134 const CommonNavigationParams& common_params, | 124 const CommonNavigationParams& common_params, |
| 135 const BeginNavigationParams& begin_params, | 125 const BeginNavigationParams& begin_params, |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 // TODO(davidben): Network failures should display a network error page. | 210 // TODO(davidben): Network failures should display a network error page. |
| 221 NOTIMPLEMENTED() << " where net_error=" << net_error; | 211 NOTIMPLEMENTED() << " where net_error=" << net_error; |
| 222 } | 212 } |
| 223 | 213 |
| 224 void NavigationRequest::OnRequestStarted(base::TimeTicks timestamp) { | 214 void NavigationRequest::OnRequestStarted(base::TimeTicks timestamp) { |
| 225 frame_tree_node_->navigator()->LogResourceRequestTime(timestamp, | 215 frame_tree_node_->navigator()->LogResourceRequestTime(timestamp, |
| 226 common_params_.url); | 216 common_params_.url); |
| 227 } | 217 } |
| 228 | 218 |
| 229 } // namespace content | 219 } // namespace content |
| OLD | NEW |