OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/renderer/render_frame_impl.h" | 5 #include "content/renderer/render_frame_impl.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
449 } | 449 } |
450 | 450 |
451 // PlzNavigate | 451 // PlzNavigate |
452 CommonNavigationParams MakeCommonNavigationParams( | 452 CommonNavigationParams MakeCommonNavigationParams( |
453 blink::WebURLRequest* request) { | 453 blink::WebURLRequest* request) { |
454 const RequestExtraData kEmptyData; | 454 const RequestExtraData kEmptyData; |
455 const RequestExtraData* extra_data = | 455 const RequestExtraData* extra_data = |
456 static_cast<RequestExtraData*>(request->extraData()); | 456 static_cast<RequestExtraData*>(request->extraData()); |
457 if (!extra_data) | 457 if (!extra_data) |
458 extra_data = &kEmptyData; | 458 extra_data = &kEmptyData; |
459 CommonNavigationParams params; | 459 Referrer referrer( |
460 params.url = request->url(); | |
461 params.referrer = Referrer( | |
462 GURL(request->httpHeaderField(WebString::fromUTF8("Referer")).latin1()), | 460 GURL(request->httpHeaderField(WebString::fromUTF8("Referer")).latin1()), |
463 request->referrerPolicy()); | 461 request->referrerPolicy()); |
464 params.transition = extra_data->transition_type(); | |
465 | 462 |
466 // Set the ui timestamp for this navigation. Currently the timestamp here is | 463 // Set the ui timestamp for this navigation. Currently the timestamp here is |
467 // only non empty when the navigation was triggered by an Android intent, or | 464 // only non empty when the navigation was triggered by an Android intent, or |
468 // by the user clicking on a link. The timestamp is converted from a double | 465 // by the user clicking on a link. The timestamp is converted from a double |
469 // version supported by blink. It will be passed back to the renderer in the | 466 // version supported by blink. It will be passed back to the renderer in the |
470 // CommitNavigation IPC, and then back to the browser again in the | 467 // CommitNavigation IPC, and then back to the browser again in the |
471 // DidCommitProvisionalLoad and the DocumentLoadComplete IPCs. | 468 // DidCommitProvisionalLoad and the DocumentLoadComplete IPCs. |
472 params.ui_timestamp = | 469 base::TimeTicks ui_timestamp = |
473 base::TimeTicks() + base::TimeDelta::FromSecondsD(request->uiStartTime()); | 470 base::TimeTicks() + base::TimeDelta::FromSecondsD(request->uiStartTime()); |
474 params.report_type = static_cast<FrameMsg_UILoadMetricsReportType::Value>( | 471 FrameMsg_UILoadMetricsReportType::Value report_type = |
475 request->inputPerfMetricReportPolicy()); | 472 static_cast<FrameMsg_UILoadMetricsReportType::Value>( |
476 return params; | 473 request->inputPerfMetricReportPolicy()); |
474 return CommonNavigationParams(request->url(), referrer, | |
475 extra_data->transition_type(), | |
476 FrameMsg_Navigate_Type::NORMAL, true, | |
477 ui_timestamp, report_type, GURL(), GURL()); | |
477 } | 478 } |
478 | 479 |
479 #if !defined(OS_ANDROID) | 480 #if !defined(OS_ANDROID) |
480 media::Context3D GetSharedMainThreadContext3D() { | 481 media::Context3D GetSharedMainThreadContext3D() { |
481 cc::ContextProvider* provider = | 482 cc::ContextProvider* provider = |
482 RenderThreadImpl::current()->SharedMainThreadContextProvider().get(); | 483 RenderThreadImpl::current()->SharedMainThreadContextProvider().get(); |
483 if (!provider) | 484 if (!provider) |
484 return media::Context3D(); | 485 return media::Context3D(); |
485 return media::Context3D(provider->ContextGL(), provider->GrContext()); | 486 return media::Context3D(provider->ContextGL(), provider->GrContext()); |
486 } | 487 } |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1025 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItems, OnSelectPopupMenuItems) | 1026 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItems, OnSelectPopupMenuItems) |
1026 #elif defined(OS_MACOSX) | 1027 #elif defined(OS_MACOSX) |
1027 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItem, OnSelectPopupMenuItem) | 1028 IPC_MESSAGE_HANDLER(FrameMsg_SelectPopupMenuItem, OnSelectPopupMenuItem) |
1028 IPC_MESSAGE_HANDLER(InputMsg_CopyToFindPboard, OnCopyToFindPboard) | 1029 IPC_MESSAGE_HANDLER(InputMsg_CopyToFindPboard, OnCopyToFindPboard) |
1029 #endif | 1030 #endif |
1030 IPC_END_MESSAGE_MAP() | 1031 IPC_END_MESSAGE_MAP() |
1031 | 1032 |
1032 return handled; | 1033 return handled; |
1033 } | 1034 } |
1034 | 1035 |
1035 void RenderFrameImpl::OnNavigate(const FrameMsg_Navigate_Params& params) { | 1036 void RenderFrameImpl::OnNavigate( |
1036 TRACE_EVENT2("navigation", "RenderFrameImpl::OnNavigate", | 1037 const CommonNavigationParams& common_params, |
1037 "id", routing_id_, | 1038 const StartNavigationParams& start_params, |
1038 "url", params.common_params.url.possibly_invalid_spec()); | 1039 const CommitNavigationParams& commit_params, |
1040 const HistoryNavigationParams& history_params) { | |
1041 TRACE_EVENT2("navigation", "RenderFrameImpl::OnNavigate", "id", routing_id_, | |
1042 "url", common_params.url.possibly_invalid_spec()); | |
1039 | 1043 |
1040 bool is_reload = | 1044 bool is_reload = RenderViewImpl::IsReload(common_params.navigation_type); |
1041 RenderViewImpl::IsReload(params.common_params.navigation_type); | 1045 bool is_history_navigation = history_params.page_state.IsValid(); |
1042 bool is_history_navigation = params.history_params.page_state.IsValid(); | |
1043 WebURLRequest::CachePolicy cache_policy = | 1046 WebURLRequest::CachePolicy cache_policy = |
1044 WebURLRequest::UseProtocolCachePolicy; | 1047 WebURLRequest::UseProtocolCachePolicy; |
1045 if (!RenderFrameImpl::PrepareRenderViewForNavigation( | 1048 if (!RenderFrameImpl::PrepareRenderViewForNavigation( |
1046 params.common_params.url, is_history_navigation, | 1049 common_params.url, is_history_navigation, history_params, &is_reload, |
1047 params.history_params, &is_reload, &cache_policy)) { | 1050 &cache_policy)) { |
1048 Send(new FrameHostMsg_DidDropNavigation(routing_id_)); | 1051 Send(new FrameHostMsg_DidDropNavigation(routing_id_)); |
1049 return; | 1052 return; |
1050 } | 1053 } |
1051 | 1054 |
1052 GetContentClient()->SetActiveURL(params.common_params.url); | 1055 GetContentClient()->SetActiveURL(common_params.url); |
1053 | 1056 |
1054 WebFrame* frame = frame_; | 1057 WebFrame* frame = frame_; |
1055 if (!params.frame_to_navigate.empty()) { | 1058 if (!commit_params.frame_to_navigate.empty()) { |
1056 // TODO(nasko): Move this lookup to the browser process. | 1059 // TODO(nasko): Move this lookup to the browser process. |
1057 frame = render_view_->webview()->findFrameByName( | 1060 frame = render_view_->webview()->findFrameByName( |
1058 WebString::fromUTF8(params.frame_to_navigate)); | 1061 WebString::fromUTF8(commit_params.frame_to_navigate)); |
1059 CHECK(frame) << "Invalid frame name passed: " << params.frame_to_navigate; | 1062 CHECK(frame) << "Invalid frame name passed: " |
1063 << commit_params.frame_to_navigate; | |
1060 } | 1064 } |
1061 | 1065 |
1062 if (is_reload && !render_view_->history_controller()->GetCurrentEntry()) { | 1066 if (is_reload && !render_view_->history_controller()->GetCurrentEntry()) { |
1063 // We cannot reload if we do not have any history state. This happens, for | 1067 // We cannot reload if we do not have any history state. This happens, for |
1064 // example, when recovering from a crash. | 1068 // example, when recovering from a crash. |
1065 is_reload = false; | 1069 is_reload = false; |
1066 cache_policy = WebURLRequest::ReloadIgnoringCacheData; | 1070 cache_policy = WebURLRequest::ReloadIgnoringCacheData; |
1067 } | 1071 } |
1068 | 1072 |
1069 render_view_->pending_navigation_params_.reset( | 1073 render_view_->pending_common_params_.reset( |
clamy
2015/03/09 14:34:47
We probably need to do something similar in OnComm
| |
1070 new FrameMsg_Navigate_Params(params)); | 1074 new CommonNavigationParams(common_params)); |
1075 render_view_->pending_start_params_.reset( | |
1076 new StartNavigationParams(start_params)); | |
1077 render_view_->pending_commit_params_.reset( | |
1078 new CommitNavigationParams(commit_params)); | |
1079 render_view_->pending_history_params_.reset( | |
1080 new HistoryNavigationParams(history_params)); | |
1071 | 1081 |
1072 // If we are reloading, then WebKit will use the history state of the current | 1082 // If we are reloading, then WebKit will use the history state of the current |
1073 // page, so we should just ignore any given history state. Otherwise, if we | 1083 // page, so we should just ignore any given history state. Otherwise, if we |
1074 // have history state, then we need to navigate to it, which corresponds to a | 1084 // have history state, then we need to navigate to it, which corresponds to a |
1075 // back/forward navigation event. | 1085 // back/forward navigation event. |
1076 if (is_reload) { | 1086 if (is_reload) { |
1077 bool reload_original_url = | 1087 bool reload_original_url = |
1078 (params.common_params.navigation_type == | 1088 (common_params.navigation_type == |
1079 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL); | 1089 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL); |
1080 bool ignore_cache = (params.common_params.navigation_type == | 1090 bool ignore_cache = (common_params.navigation_type == |
1081 FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE); | 1091 FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE); |
1082 | 1092 |
1083 if (reload_original_url) | 1093 if (reload_original_url) |
1084 frame->reloadWithOverrideURL(params.common_params.url, true); | 1094 frame->reloadWithOverrideURL(common_params.url, true); |
1085 else | 1095 else |
1086 frame->reload(ignore_cache); | 1096 frame->reload(ignore_cache); |
1087 } else if (is_history_navigation) { | 1097 } else if (is_history_navigation) { |
1088 // We must know the page ID of the page we are navigating back to. | 1098 // We must know the page ID of the page we are navigating back to. |
1089 DCHECK_NE(params.history_params.page_id, -1); | 1099 DCHECK_NE(history_params.page_id, -1); |
1090 scoped_ptr<HistoryEntry> entry = | 1100 scoped_ptr<HistoryEntry> entry = |
1091 PageStateToHistoryEntry(params.history_params.page_state); | 1101 PageStateToHistoryEntry(history_params.page_state); |
1092 if (entry) { | 1102 if (entry) { |
1093 // Ensure we didn't save the swapped out URL in UpdateState, since the | 1103 // Ensure we didn't save the swapped out URL in UpdateState, since the |
1094 // browser should never be telling us to navigate to swappedout://. | 1104 // browser should never be telling us to navigate to swappedout://. |
1095 CHECK(entry->root().urlString() != WebString::fromUTF8(kSwappedOutURL)); | 1105 CHECK(entry->root().urlString() != WebString::fromUTF8(kSwappedOutURL)); |
1096 render_view_->history_controller()->GoToEntry(entry.Pass(), cache_policy); | 1106 render_view_->history_controller()->GoToEntry(entry.Pass(), cache_policy); |
1097 } | 1107 } |
1098 } else if (!params.common_params.base_url_for_data_url.is_empty()) { | 1108 } else if (!common_params.base_url_for_data_url.is_empty()) { |
1099 LoadDataURL(params.common_params, frame); | 1109 LoadDataURL(common_params, frame); |
1100 } else { | 1110 } else { |
1101 // Navigate to the given URL. | 1111 // Navigate to the given URL. |
1102 WebURLRequest request = | 1112 WebURLRequest request = CreateURLRequestForNavigation( |
1103 CreateURLRequestForNavigation(params.common_params, | 1113 common_params, scoped_ptr<StreamOverrideParameters>(), |
1104 scoped_ptr<StreamOverrideParameters>(), | 1114 frame->isViewSourceModeEnabled()); |
1105 frame->isViewSourceModeEnabled()); | |
1106 | 1115 |
1107 if (!params.extra_headers.empty()) { | 1116 if (!start_params.extra_headers.empty()) { |
1108 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(), | 1117 for (net::HttpUtil::HeadersIterator i(start_params.extra_headers.begin(), |
1109 params.extra_headers.end(), | 1118 start_params.extra_headers.end(), |
1110 "\n"); | 1119 "\n"); |
1111 i.GetNext();) { | 1120 i.GetNext();) { |
1112 request.addHTTPHeaderField(WebString::fromUTF8(i.name()), | 1121 request.addHTTPHeaderField(WebString::fromUTF8(i.name()), |
1113 WebString::fromUTF8(i.values())); | 1122 WebString::fromUTF8(i.values())); |
1114 } | 1123 } |
1115 } | 1124 } |
1116 | 1125 |
1117 if (params.is_post) { | 1126 if (start_params.is_post) { |
1118 request.setHTTPMethod(WebString::fromUTF8("POST")); | 1127 request.setHTTPMethod(WebString::fromUTF8("POST")); |
1119 | 1128 |
1120 // Set post data. | 1129 // Set post data. |
1121 WebHTTPBody http_body; | 1130 WebHTTPBody http_body; |
1122 http_body.initialize(); | 1131 http_body.initialize(); |
1123 const char* data = NULL; | 1132 const char* data = NULL; |
1124 if (params.browser_initiated_post_data.size()) { | 1133 if (start_params.browser_initiated_post_data.size()) { |
1125 data = reinterpret_cast<const char*>( | 1134 data = reinterpret_cast<const char*>( |
1126 ¶ms.browser_initiated_post_data.front()); | 1135 &start_params.browser_initiated_post_data.front()); |
1127 } | 1136 } |
1128 http_body.appendData( | 1137 http_body.appendData( |
1129 WebData(data, params.browser_initiated_post_data.size())); | 1138 WebData(data, start_params.browser_initiated_post_data.size())); |
1130 request.setHTTPBody(http_body); | 1139 request.setHTTPBody(http_body); |
1131 } | 1140 } |
1132 | 1141 |
1133 // A session history navigation should have been accompanied by state. | 1142 // A session history navigation should have been accompanied by state. |
1134 CHECK_EQ(params.history_params.page_id, -1); | 1143 CHECK_EQ(history_params.page_id, -1); |
1135 | 1144 |
1136 // Record this before starting the load, we need a lower bound of this time | 1145 // Record this before starting the load, we need a lower bound of this time |
1137 // to sanitize the navigationStart override set below. | 1146 // to sanitize the navigationStart override set below. |
1138 base::TimeTicks renderer_navigation_start = base::TimeTicks::Now(); | 1147 base::TimeTicks renderer_navigation_start = base::TimeTicks::Now(); |
1139 frame->loadRequest(request); | 1148 frame->loadRequest(request); |
1140 | 1149 |
1141 UpdateFrameNavigationTiming( | 1150 UpdateFrameNavigationTiming(frame, commit_params.browser_navigation_start, |
1142 frame, params.commit_params.browser_navigation_start, | 1151 renderer_navigation_start); |
1143 renderer_navigation_start); | |
1144 } | 1152 } |
1145 | 1153 |
1146 // In case LoadRequest failed before DidCreateDataSource was called. | 1154 // In case LoadRequest failed before DidCreateDataSource was called. |
1147 render_view_->pending_navigation_params_.reset(); | 1155 render_view_->pending_common_params_.reset(); |
1156 render_view_->pending_start_params_.reset(); | |
1157 render_view_->pending_commit_params_.reset(); | |
1158 render_view_->pending_history_params_.reset(); | |
1148 } | 1159 } |
1149 | 1160 |
1150 void RenderFrameImpl::NavigateToSwappedOutURL() { | 1161 void RenderFrameImpl::NavigateToSwappedOutURL() { |
1151 // We use loadRequest instead of loadHTMLString because the former commits | 1162 // We use loadRequest instead of loadHTMLString because the former commits |
1152 // synchronously. Otherwise a new navigation can interrupt the navigation | 1163 // synchronously. Otherwise a new navigation can interrupt the navigation |
1153 // to kSwappedOutURL. If that happens to be to the page we had been | 1164 // to kSwappedOutURL. If that happens to be to the page we had been |
1154 // showing, then WebKit will never send a commit and we'll be left spinning. | 1165 // showing, then WebKit will never send a commit and we'll be left spinning. |
1155 // Set the is_swapped_out_ bit to true, so IPC filtering is in effect and | 1166 // Set the is_swapped_out_ bit to true, so IPC filtering is in effect and |
1156 // the navigation to swappedout:// is not announced to the browser side. | 1167 // the navigation to swappedout:// is not announced to the browser side. |
1157 is_swapped_out_ = true; | 1168 is_swapped_out_ = true; |
(...skipping 1265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2423 // | 2434 // |
2424 // TODO(davidben): This should also take the failed navigation's replacement | 2435 // TODO(davidben): This should also take the failed navigation's replacement |
2425 // state into account, if a location.replace() failed. | 2436 // state into account, if a location.replace() failed. |
2426 bool replace = | 2437 bool replace = |
2427 navigation_state->pending_page_id() != -1 || | 2438 navigation_state->pending_page_id() != -1 || |
2428 ui::PageTransitionCoreTypeIs(navigation_state->transition_type(), | 2439 ui::PageTransitionCoreTypeIs(navigation_state->transition_type(), |
2429 ui::PAGE_TRANSITION_AUTO_SUBFRAME); | 2440 ui::PAGE_TRANSITION_AUTO_SUBFRAME); |
2430 | 2441 |
2431 // If we failed on a browser initiated request, then make sure that our error | 2442 // If we failed on a browser initiated request, then make sure that our error |
2432 // page load is regarded as the same browser initiated request. | 2443 // page load is regarded as the same browser initiated request. |
2433 if (!navigation_state->is_content_initiated()) { | 2444 if (!navigation_state->is_content_initiated()) { |
clamy
2015/03/09 14:34:47
This is quite bulky, and my intention is to refact
| |
2434 render_view_->pending_navigation_params_.reset( | 2445 render_view_->pending_common_params_.reset(new CommonNavigationParams( |
2435 new FrameMsg_Navigate_Params); | 2446 error.unreachableURL, Referrer(), navigation_state->transition_type(), |
2436 FrameMsg_Navigate_Params* pending_params = | 2447 FrameMsg_Navigate_Type::NORMAL, true, base::TimeTicks(), |
2437 render_view_->pending_navigation_params_.get(); | 2448 FrameMsg_UILoadMetricsReportType::NO_REPORT, GURL(), GURL())); |
2438 pending_params->history_params.page_id = | 2449 render_view_->pending_commit_params_.reset(new CommitNavigationParams( |
2439 navigation_state->pending_page_id(); | 2450 false, base::TimeTicks(), std::vector<GURL>(), false, std::string(), |
2440 pending_params->history_params.pending_history_list_offset = | 2451 document_state->request_time())); |
2441 navigation_state->pending_history_list_offset(); | 2452 render_view_->pending_start_params_.reset(new StartNavigationParams( |
2442 pending_params->history_params.should_clear_history_list = | 2453 false, std::string(), std::vector<unsigned char>(), replace, -1, -1)); |
2443 navigation_state->history_list_was_cleared(); | 2454 render_view_->pending_history_params_.reset(new HistoryNavigationParams( |
2444 pending_params->common_params.transition = | 2455 PageState(), navigation_state->pending_page_id(), |
2445 navigation_state->transition_type(); | 2456 navigation_state->pending_history_list_offset(), -1, 0, |
2446 pending_params->request_time = document_state->request_time(); | 2457 navigation_state->history_list_was_cleared())); |
2447 pending_params->should_replace_current_entry = replace; | |
2448 } | 2458 } |
2449 | 2459 |
2450 // Load an error page. | 2460 // Load an error page. |
2451 LoadNavigationErrorPage(failed_request, error, replace); | 2461 LoadNavigationErrorPage(failed_request, error, replace); |
2452 } | 2462 } |
2453 | 2463 |
2454 void RenderFrameImpl::didCommitProvisionalLoad( | 2464 void RenderFrameImpl::didCommitProvisionalLoad( |
2455 blink::WebLocalFrame* frame, | 2465 blink::WebLocalFrame* frame, |
2456 const blink::WebHistoryItem& item, | 2466 const blink::WebHistoryItem& item, |
2457 blink::WebHistoryCommitType commit_type) { | 2467 blink::WebHistoryCommitType commit_type) { |
(...skipping 2041 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4499 | 4509 |
4500 #if defined(ENABLE_BROWSER_CDMS) | 4510 #if defined(ENABLE_BROWSER_CDMS) |
4501 RendererCdmManager* RenderFrameImpl::GetCdmManager() { | 4511 RendererCdmManager* RenderFrameImpl::GetCdmManager() { |
4502 if (!cdm_manager_) | 4512 if (!cdm_manager_) |
4503 cdm_manager_ = new RendererCdmManager(this); | 4513 cdm_manager_ = new RendererCdmManager(this); |
4504 return cdm_manager_; | 4514 return cdm_manager_; |
4505 } | 4515 } |
4506 #endif // defined(ENABLE_BROWSER_CDMS) | 4516 #endif // defined(ENABLE_BROWSER_CDMS) |
4507 | 4517 |
4508 } // namespace content | 4518 } // namespace content |
OLD | NEW |