Chromium Code Reviews| 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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 ds->redirectChain(urls); | 300 ds->redirectChain(urls); |
| 301 result->reserve(urls.size()); | 301 result->reserve(urls.size()); |
| 302 for (size_t i = 0; i < urls.size(); ++i) { | 302 for (size_t i = 0; i < urls.size(); ++i) { |
| 303 if (urls[i] != GURL(kSwappedOutURL)) | 303 if (urls[i] != GURL(kSwappedOutURL)) |
| 304 result->push_back(urls[i]); | 304 result->push_back(urls[i]); |
| 305 else | 305 else |
| 306 result->push_back(blank_url); | 306 result->push_back(blank_url); |
| 307 } | 307 } |
| 308 } | 308 } |
| 309 | 309 |
| 310 // Gets URL that should override the default getter for this data source. | |
|
Charlie Reis
2015/11/24 00:22:59
nit: Add: "(if any), storing it in |output|."
boliu
2015/11/24 19:03:25
Done.
| |
| 311 // Return true if there is an override URL. | |
|
Charlie Reis
2015/11/24 00:22:59
nit: Returns
(to be consistent with "Gets")
boliu
2015/11/24 19:03:25
Done.
| |
| 312 bool MaybeGetURLOverride(WebDataSource* ds, GURL* output) { | |
|
Charlie Reis
2015/11/24 00:22:59
nit: MaybeGetOverriddenURL
boliu
2015/11/24 19:03:25
Done.
| |
| 313 DocumentState* document_state = DocumentState::FromDataSource(ds); | |
| 314 | |
| 315 // If load was from a data URL, then the saved data URL, not the history | |
| 316 // URL, should be the URL of the data source. | |
| 317 if (document_state->was_load_data_with_base_url_request()) { | |
| 318 *output = document_state->data_url(); | |
| 319 return true; | |
| 320 } | |
| 321 | |
| 322 // WebDataSource has unreachable URL means that the frame is loaded through | |
| 323 // blink::WebFrame::loadData(), and the base URL will be in the redirect | |
| 324 // chain. However, we never visited the baseURL. So in this case, we should | |
| 325 // use the unreachable URL as the original URL. | |
| 326 if (ds->hasUnreachableURL()) { | |
| 327 *output = ds->unreachableURL(); | |
| 328 return true; | |
| 329 } | |
| 330 | |
| 331 return false; | |
| 332 } | |
| 333 | |
| 310 // Returns the original request url. If there is no redirect, the original | 334 // Returns the original request url. If there is no redirect, the original |
| 311 // url is the same as ds->request()->url(). If the WebDataSource belongs to a | 335 // url is the same as ds->request()->url(). If the WebDataSource belongs to a |
| 312 // frame was loaded by loadData, the original url will be ds->unreachableURL() | 336 // frame was loaded by loadData, the original url will be ds->unreachableURL() |
| 313 GURL GetOriginalRequestURL(WebDataSource* ds) { | 337 GURL GetOriginalRequestURL(WebDataSource* ds) { |
| 314 // WebDataSource has unreachable URL means that the frame is loaded through | 338 GURL overriden_url; |
| 315 // blink::WebFrame::loadData(), and the base URL will be in the redirect | 339 if (MaybeGetURLOverride(ds, &overriden_url)) |
| 316 // chain. However, we never visited the baseURL. So in this case, we should | 340 return overriden_url; |
| 317 // use the unreachable URL as the original URL. | |
| 318 if (ds->hasUnreachableURL()) | |
| 319 return ds->unreachableURL(); | |
| 320 | 341 |
| 321 std::vector<GURL> redirects; | 342 std::vector<GURL> redirects; |
| 322 GetRedirectChain(ds, &redirects); | 343 GetRedirectChain(ds, &redirects); |
| 323 if (!redirects.empty()) | 344 if (!redirects.empty()) |
| 324 return redirects.at(0); | 345 return redirects.at(0); |
| 325 | 346 |
| 326 return ds->originalRequest().url(); | 347 return ds->originalRequest().url(); |
| 327 } | 348 } |
| 328 | 349 |
| 329 bool IsBrowserInitiated(NavigationParams* pending) { | 350 bool IsBrowserInitiated(NavigationParams* pending) { |
| (...skipping 2277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2607 } | 2628 } |
| 2608 | 2629 |
| 2609 DocumentState* document_state = DocumentState::FromDataSource(datasource); | 2630 DocumentState* document_state = DocumentState::FromDataSource(datasource); |
| 2610 if (!document_state) { | 2631 if (!document_state) { |
| 2611 document_state = new DocumentState; | 2632 document_state = new DocumentState; |
| 2612 datasource->setExtraData(document_state); | 2633 datasource->setExtraData(document_state); |
| 2613 if (!content_initiated) | 2634 if (!content_initiated) |
| 2614 PopulateDocumentStateFromPending(document_state); | 2635 PopulateDocumentStateFromPending(document_state); |
| 2615 } | 2636 } |
| 2616 | 2637 |
| 2617 // Carry over the user agent override flag, if it exists. | 2638 // The rest of RenderView assumes that a WebDataSource will always have a |
| 2639 // non-null NavigationState. | |
| 2640 UpdateNavigationState(document_state); | |
| 2641 | |
| 2642 // Carry over the user agent override flag and data URL if necessary. | |
| 2618 blink::WebView* webview = render_view_->webview(); | 2643 blink::WebView* webview = render_view_->webview(); |
| 2619 if (content_initiated && webview && webview->mainFrame() && | 2644 if (content_initiated && webview && webview->mainFrame() && |
| 2620 webview->mainFrame()->isWebLocalFrame() && | 2645 webview->mainFrame()->isWebLocalFrame() && |
| 2621 webview->mainFrame()->dataSource()) { | 2646 webview->mainFrame()->dataSource()) { |
| 2622 DocumentState* old_document_state = | 2647 DocumentState* old_document_state = |
| 2623 DocumentState::FromDataSource(webview->mainFrame()->dataSource()); | 2648 DocumentState::FromDataSource(webview->mainFrame()->dataSource()); |
| 2624 if (old_document_state) { | 2649 if (old_document_state) { |
| 2625 InternalDocumentStateData* internal_data = | 2650 InternalDocumentStateData* internal_data = |
| 2626 InternalDocumentStateData::FromDocumentState(document_state); | 2651 InternalDocumentStateData::FromDocumentState(document_state); |
| 2627 InternalDocumentStateData* old_internal_data = | 2652 InternalDocumentStateData* old_internal_data = |
| 2628 InternalDocumentStateData::FromDocumentState(old_document_state); | 2653 InternalDocumentStateData::FromDocumentState(old_document_state); |
| 2629 internal_data->set_is_overriding_user_agent( | 2654 internal_data->set_is_overriding_user_agent( |
| 2630 old_internal_data->is_overriding_user_agent()); | 2655 old_internal_data->is_overriding_user_agent()); |
| 2656 | |
| 2657 document_state->set_was_load_data_with_base_url_request( | |
|
Charlie Reis
2015/11/24 00:22:59
Looking closer, I'm skeptical about this call. Wo
boliu
2015/11/24 19:03:25
Err, this is not needed afaict. in-page navigation
Charlie Reis
2015/11/24 19:32:38
Great, I'm glad it's not needed.
| |
| 2658 old_document_state->was_load_data_with_base_url_request()); | |
| 2659 document_state->set_data_url(old_document_state->data_url()); | |
| 2631 } | 2660 } |
| 2632 } | 2661 } |
| 2633 | 2662 |
| 2634 // The rest of RenderView assumes that a WebDataSource will always have a | |
| 2635 // non-null NavigationState. | |
| 2636 UpdateNavigationState(document_state); | |
| 2637 | |
| 2638 // DocumentState::referred_by_prefetcher_ is true if we are | 2663 // DocumentState::referred_by_prefetcher_ is true if we are |
| 2639 // navigating from a page that used prefetching using a link on that | 2664 // navigating from a page that used prefetching using a link on that |
| 2640 // page. We are early enough in the request process here that we | 2665 // page. We are early enough in the request process here that we |
| 2641 // can still see the DocumentState of the previous page and set | 2666 // can still see the DocumentState of the previous page and set |
| 2642 // this value appropriately. | 2667 // this value appropriately. |
| 2643 // TODO(gavinp): catch the important case of navigation in a new | 2668 // TODO(gavinp): catch the important case of navigation in a new |
| 2644 // renderer process. | 2669 // renderer process. |
| 2645 if (webview) { | 2670 if (webview) { |
| 2646 if (WebFrame* old_frame = webview->mainFrame()) { | 2671 if (WebFrame* old_frame = webview->mainFrame()) { |
| 2647 const WebURLRequest& original_request = datasource->originalRequest(); | 2672 const WebURLRequest& original_request = datasource->originalRequest(); |
| (...skipping 2185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4833 | 4858 |
| 4834 if (should_load_request) { | 4859 if (should_load_request) { |
| 4835 // Sanitize navigation start now that we know the load_type. | 4860 // Sanitize navigation start now that we know the load_type. |
| 4836 pending_navigation_params_->common_params.navigation_start = | 4861 pending_navigation_params_->common_params.navigation_start = |
| 4837 SanitizeNavigationTiming(load_type, common_params.navigation_start, | 4862 SanitizeNavigationTiming(load_type, common_params.navigation_start, |
| 4838 renderer_navigation_start); | 4863 renderer_navigation_start); |
| 4839 // Perform a navigation to a data url if needed. | 4864 // Perform a navigation to a data url if needed. |
| 4840 if (!common_params.base_url_for_data_url.is_empty() || | 4865 if (!common_params.base_url_for_data_url.is_empty() || |
| 4841 (browser_side_navigation && | 4866 (browser_side_navigation && |
| 4842 common_params.url.SchemeIs(url::kDataScheme))) { | 4867 common_params.url.SchemeIs(url::kDataScheme))) { |
| 4843 LoadDataURL(common_params, frame_); | 4868 LoadDataURL(common_params, frame_, load_type); |
| 4844 } else { | 4869 } else { |
| 4845 // Load the request. | 4870 // Load the request. |
| 4846 frame_->toWebLocalFrame()->load(request, load_type, | 4871 frame_->toWebLocalFrame()->load(request, load_type, |
| 4847 item_for_history_navigation); | 4872 item_for_history_navigation); |
| 4848 } | 4873 } |
| 4849 } | 4874 } |
| 4850 | 4875 |
| 4851 // In case LoadRequest failed before didCreateDataSource was called. | 4876 // In case LoadRequest failed before didCreateDataSource was called. |
| 4852 pending_navigation_params_.reset(); | 4877 pending_navigation_params_.reset(); |
| 4853 } | 4878 } |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5073 MakeCommonNavigationParams(request, should_replace_current_entry), | 5098 MakeCommonNavigationParams(request, should_replace_current_entry), |
| 5074 BeginNavigationParams( | 5099 BeginNavigationParams( |
| 5075 request->httpMethod().latin1(), GetWebURLRequestHeaders(*request), | 5100 request->httpMethod().latin1(), GetWebURLRequestHeaders(*request), |
| 5076 GetLoadFlagsForWebURLRequest(*request), request->hasUserGesture(), | 5101 GetLoadFlagsForWebURLRequest(*request), request->hasUserGesture(), |
| 5077 request->skipServiceWorker(), | 5102 request->skipServiceWorker(), |
| 5078 GetRequestContextTypeForWebURLRequest(*request)), | 5103 GetRequestContextTypeForWebURLRequest(*request)), |
| 5079 GetRequestBodyForWebURLRequest(*request))); | 5104 GetRequestBodyForWebURLRequest(*request))); |
| 5080 } | 5105 } |
| 5081 | 5106 |
| 5082 void RenderFrameImpl::LoadDataURL(const CommonNavigationParams& params, | 5107 void RenderFrameImpl::LoadDataURL(const CommonNavigationParams& params, |
| 5083 WebFrame* frame) { | 5108 WebFrame* frame, |
| 5109 blink::WebFrameLoadType load_type) { | |
| 5084 // A loadData request with a specified base URL. | 5110 // A loadData request with a specified base URL. |
| 5085 std::string mime_type, charset, data; | 5111 std::string mime_type, charset, data; |
| 5086 if (net::DataURL::Parse(params.url, &mime_type, &charset, &data)) { | 5112 if (net::DataURL::Parse(params.url, &mime_type, &charset, &data)) { |
| 5087 const GURL base_url = params.base_url_for_data_url.is_empty() ? | 5113 const GURL base_url = params.base_url_for_data_url.is_empty() ? |
| 5088 params.url : params.base_url_for_data_url; | 5114 params.url : params.base_url_for_data_url; |
| 5115 bool replace = load_type == blink::WebFrameLoadType::ReloadFromOrigin || | |
| 5116 load_type == blink::WebFrameLoadType::Reload; | |
| 5089 frame->loadData( | 5117 frame->loadData( |
| 5090 WebData(data.c_str(), data.length()), | 5118 WebData(data.c_str(), data.length()), |
| 5091 WebString::fromUTF8(mime_type), | 5119 WebString::fromUTF8(mime_type), |
| 5092 WebString::fromUTF8(charset), | 5120 WebString::fromUTF8(charset), |
| 5093 base_url, | 5121 base_url, |
| 5122 // Needed so that history-url-only changes don't become reloads. | |
| 5094 params.history_url_for_data_url, | 5123 params.history_url_for_data_url, |
| 5095 false); | 5124 replace); |
| 5096 } else { | 5125 } else { |
| 5097 CHECK(false) << "Invalid URL passed: " | 5126 CHECK(false) << "Invalid URL passed: " |
| 5098 << params.url.possibly_invalid_spec(); | 5127 << params.url.possibly_invalid_spec(); |
| 5099 } | 5128 } |
| 5100 } | 5129 } |
| 5101 | 5130 |
| 5102 void RenderFrameImpl::SendUpdateState() { | 5131 void RenderFrameImpl::SendUpdateState() { |
| 5103 DCHECK(SiteIsolationPolicy::UseSubframeNavigationEntries()); | 5132 DCHECK(SiteIsolationPolicy::UseSubframeNavigationEntries()); |
| 5104 if (current_history_item_.isNull()) | 5133 if (current_history_item_.isNull()) |
| 5105 return; | 5134 return; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5149 if (RenderThreadImpl::current() && | 5178 if (RenderThreadImpl::current() && |
| 5150 RenderThreadImpl::current()->layout_test_mode()) { | 5179 RenderThreadImpl::current()->layout_test_mode()) { |
| 5151 return false; | 5180 return false; |
| 5152 } | 5181 } |
| 5153 | 5182 |
| 5154 return true; | 5183 return true; |
| 5155 } | 5184 } |
| 5156 | 5185 |
| 5157 GURL RenderFrameImpl::GetLoadingUrl() const { | 5186 GURL RenderFrameImpl::GetLoadingUrl() const { |
| 5158 WebDataSource* ds = frame_->dataSource(); | 5187 WebDataSource* ds = frame_->dataSource(); |
| 5159 if (ds->hasUnreachableURL()) | 5188 |
| 5160 return ds->unreachableURL(); | 5189 GURL overriden_url; |
| 5190 if (MaybeGetURLOverride(ds, &overriden_url)) | |
| 5191 return overriden_url; | |
| 5161 | 5192 |
| 5162 const WebURLRequest& request = ds->request(); | 5193 const WebURLRequest& request = ds->request(); |
| 5163 return request.url(); | 5194 return request.url(); |
| 5164 } | 5195 } |
| 5165 | 5196 |
| 5166 void RenderFrameImpl::PopulateDocumentStateFromPending( | 5197 void RenderFrameImpl::PopulateDocumentStateFromPending( |
| 5167 DocumentState* document_state) { | 5198 DocumentState* document_state) { |
| 5168 document_state->set_request_time( | 5199 document_state->set_request_time( |
| 5169 pending_navigation_params_->request_params.request_time); | 5200 pending_navigation_params_->request_params.request_time); |
| 5170 | 5201 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5217 | 5248 |
| 5218 void RenderFrameImpl::UpdateNavigationState(DocumentState* document_state) { | 5249 void RenderFrameImpl::UpdateNavigationState(DocumentState* document_state) { |
| 5219 if (pending_navigation_params_) { | 5250 if (pending_navigation_params_) { |
| 5220 // If this is a browser-initiated load that doesn't override | 5251 // If this is a browser-initiated load that doesn't override |
| 5221 // navigation_start, set it here. | 5252 // navigation_start, set it here. |
| 5222 if (pending_navigation_params_->common_params.navigation_start.is_null()) { | 5253 if (pending_navigation_params_->common_params.navigation_start.is_null()) { |
| 5223 pending_navigation_params_->common_params.navigation_start = | 5254 pending_navigation_params_->common_params.navigation_start = |
| 5224 base::TimeTicks::Now(); | 5255 base::TimeTicks::Now(); |
| 5225 } | 5256 } |
| 5226 document_state->set_navigation_state(CreateNavigationStateFromPending()); | 5257 document_state->set_navigation_state(CreateNavigationStateFromPending()); |
| 5258 | |
| 5259 const CommonNavigationParams& common_params = | |
| 5260 pending_navigation_params_->common_params; | |
| 5261 bool load_data = !common_params.base_url_for_data_url.is_empty() && | |
| 5262 !common_params.history_url_for_data_url.is_empty() && | |
| 5263 common_params.url.SchemeIs(url::kDataScheme); | |
| 5264 document_state->set_was_load_data_with_base_url_request(load_data); | |
| 5265 if (load_data) | |
| 5266 document_state->set_data_url(common_params.url); | |
| 5267 | |
| 5227 pending_navigation_params_.reset(); | 5268 pending_navigation_params_.reset(); |
| 5228 } else { | 5269 } else { |
| 5229 document_state->set_navigation_state( | 5270 document_state->set_navigation_state( |
| 5230 NavigationStateImpl::CreateContentInitiated()); | 5271 NavigationStateImpl::CreateContentInitiated()); |
| 5231 } | 5272 } |
| 5232 } | 5273 } |
| 5233 | 5274 |
| 5234 #if defined(OS_ANDROID) | 5275 #if defined(OS_ANDROID) |
| 5235 WebMediaPlayer* RenderFrameImpl::CreateAndroidWebMediaPlayer( | 5276 WebMediaPlayer* RenderFrameImpl::CreateAndroidWebMediaPlayer( |
| 5236 WebMediaPlayerClient* client, | 5277 WebMediaPlayerClient* client, |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5370 media::ConvertToSwitchOutputDeviceCB(web_callbacks); | 5411 media::ConvertToSwitchOutputDeviceCB(web_callbacks); |
| 5371 scoped_refptr<media::AudioOutputDevice> device = | 5412 scoped_refptr<media::AudioOutputDevice> device = |
| 5372 AudioDeviceFactory::NewOutputDevice(routing_id_, 0, sink_id.utf8(), | 5413 AudioDeviceFactory::NewOutputDevice(routing_id_, 0, sink_id.utf8(), |
| 5373 security_origin); | 5414 security_origin); |
| 5374 media::OutputDeviceStatus status = device->GetDeviceStatus(); | 5415 media::OutputDeviceStatus status = device->GetDeviceStatus(); |
| 5375 device->Stop(); | 5416 device->Stop(); |
| 5376 callback.Run(status); | 5417 callback.Run(status); |
| 5377 } | 5418 } |
| 5378 | 5419 |
| 5379 } // namespace content | 5420 } // namespace content |
| OLD | NEW |