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 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 ds->redirectChain(urls); | 296 ds->redirectChain(urls); |
| 297 result->reserve(urls.size()); | 297 result->reserve(urls.size()); |
| 298 for (size_t i = 0; i < urls.size(); ++i) { | 298 for (size_t i = 0; i < urls.size(); ++i) { |
| 299 if (urls[i] != GURL(kSwappedOutURL)) | 299 if (urls[i] != GURL(kSwappedOutURL)) |
| 300 result->push_back(urls[i]); | 300 result->push_back(urls[i]); |
| 301 else | 301 else |
| 302 result->push_back(blank_url); | 302 result->push_back(blank_url); |
| 303 } | 303 } |
| 304 } | 304 } |
| 305 | 305 |
| 306 // Return URLs that should override the default getter for this data source. | |
|
Charlie Reis
2015/11/20 21:30:12
nit: Please rephrase. This method returns a bool,
boliu
2015/11/23 22:32:25
Done.
| |
| 307 // Or an invalid GURL if there are no overrides. | |
| 308 bool MaybeGetURLOverride(WebDataSource* ds, GURL* output) { | |
| 309 DocumentState* document_state = DocumentState::FromDataSource(ds); | |
| 310 | |
| 311 // If load was from a data URL, then the saved data URL should be the | |
| 312 // URL of the data source. | |
|
Charlie Reis
2015/11/20 21:30:12
nit: ..., not the history URL.
Sanity check: I kn
boliu
2015/11/23 22:32:25
Done
Charlie Reis
2015/11/24 00:22:59
Acknowledged.
| |
| 313 if (document_state->was_load_data_url_with_base_url_request()) { | |
| 314 *output = document_state->data_url(); | |
| 315 return true; | |
| 316 } | |
| 317 | |
| 318 // WebDataSource has unreachable URL means that the frame is loaded through | |
| 319 // blink::WebFrame::loadData(), and the base URL will be in the redirect | |
| 320 // chain. However, we never visited the baseURL. So in this case, we should | |
| 321 // use the unreachable URL as the original URL. | |
| 322 if (ds->hasUnreachableURL()) { | |
| 323 *output = ds->unreachableURL(); | |
| 324 return true; | |
| 325 } | |
| 326 | |
| 327 return false; | |
| 328 } | |
| 329 | |
| 306 // Returns the original request url. If there is no redirect, the original | 330 // Returns the original request url. If there is no redirect, the original |
| 307 // url is the same as ds->request()->url(). If the WebDataSource belongs to a | 331 // url is the same as ds->request()->url(). If the WebDataSource belongs to a |
| 308 // frame was loaded by loadData, the original url will be ds->unreachableURL() | 332 // frame was loaded by loadData, the original url will be ds->unreachableURL() |
| 309 GURL GetOriginalRequestURL(WebDataSource* ds) { | 333 GURL GetOriginalRequestURL(WebDataSource* ds) { |
| 310 // WebDataSource has unreachable URL means that the frame is loaded through | 334 GURL overriden_url; |
| 311 // blink::WebFrame::loadData(), and the base URL will be in the redirect | 335 if (MaybeGetURLOverride(ds, &overriden_url)) { |
| 312 // chain. However, we never visited the baseURL. So in this case, we should | 336 return overriden_url; |
| 313 // use the unreachable URL as the original URL. | 337 } |
| 314 if (ds->hasUnreachableURL()) | |
| 315 return ds->unreachableURL(); | |
| 316 | 338 |
| 317 std::vector<GURL> redirects; | 339 std::vector<GURL> redirects; |
| 318 GetRedirectChain(ds, &redirects); | 340 GetRedirectChain(ds, &redirects); |
| 319 if (!redirects.empty()) | 341 if (!redirects.empty()) |
| 320 return redirects.at(0); | 342 return redirects.at(0); |
| 321 | 343 |
| 322 return ds->originalRequest().url(); | 344 return ds->originalRequest().url(); |
| 323 } | 345 } |
| 324 | 346 |
| 325 bool IsBrowserInitiated(NavigationParams* pending) { | 347 bool IsBrowserInitiated(NavigationParams* pending) { |
| (...skipping 2272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2598 } | 2620 } |
| 2599 | 2621 |
| 2600 DocumentState* document_state = DocumentState::FromDataSource(datasource); | 2622 DocumentState* document_state = DocumentState::FromDataSource(datasource); |
| 2601 if (!document_state) { | 2623 if (!document_state) { |
| 2602 document_state = new DocumentState; | 2624 document_state = new DocumentState; |
| 2603 datasource->setExtraData(document_state); | 2625 datasource->setExtraData(document_state); |
| 2604 if (!content_initiated) | 2626 if (!content_initiated) |
| 2605 PopulateDocumentStateFromPending(document_state); | 2627 PopulateDocumentStateFromPending(document_state); |
| 2606 } | 2628 } |
| 2607 | 2629 |
| 2630 // The rest of RenderView assumes that a WebDataSource will always have a | |
| 2631 // non-null NavigationState. | |
| 2632 UpdateNavigationState(document_state); | |
| 2633 | |
| 2608 // Carry over the user agent override flag, if it exists. | 2634 // Carry over the user agent override flag, if it exists. |
|
Charlie Reis
2015/11/20 21:30:12
nit: Update comment.
boliu
2015/11/23 22:32:25
Done
| |
| 2609 blink::WebView* webview = render_view_->webview(); | 2635 blink::WebView* webview = render_view_->webview(); |
| 2610 if (content_initiated && webview && webview->mainFrame() && | 2636 if (content_initiated && webview && webview->mainFrame() && |
| 2611 webview->mainFrame()->isWebLocalFrame() && | 2637 webview->mainFrame()->isWebLocalFrame() && |
| 2612 webview->mainFrame()->dataSource()) { | 2638 webview->mainFrame()->dataSource()) { |
| 2613 DocumentState* old_document_state = | 2639 DocumentState* old_document_state = |
| 2614 DocumentState::FromDataSource(webview->mainFrame()->dataSource()); | 2640 DocumentState::FromDataSource(webview->mainFrame()->dataSource()); |
| 2615 if (old_document_state) { | 2641 if (old_document_state) { |
| 2616 InternalDocumentStateData* internal_data = | 2642 InternalDocumentStateData* internal_data = |
| 2617 InternalDocumentStateData::FromDocumentState(document_state); | 2643 InternalDocumentStateData::FromDocumentState(document_state); |
| 2618 InternalDocumentStateData* old_internal_data = | 2644 InternalDocumentStateData* old_internal_data = |
| 2619 InternalDocumentStateData::FromDocumentState(old_document_state); | 2645 InternalDocumentStateData::FromDocumentState(old_document_state); |
| 2620 internal_data->set_is_overriding_user_agent( | 2646 internal_data->set_is_overriding_user_agent( |
| 2621 old_internal_data->is_overriding_user_agent()); | 2647 old_internal_data->is_overriding_user_agent()); |
| 2648 | |
| 2649 document_state->set_was_load_data_url_with_base_url_request( | |
| 2650 old_document_state->was_load_data_url_with_base_url_request()); | |
| 2651 document_state->set_data_url(old_document_state->data_url()); | |
| 2622 } | 2652 } |
| 2623 } | 2653 } |
| 2624 | 2654 |
| 2625 // The rest of RenderView assumes that a WebDataSource will always have a | |
| 2626 // non-null NavigationState. | |
| 2627 UpdateNavigationState(document_state); | |
| 2628 | |
| 2629 // DocumentState::referred_by_prefetcher_ is true if we are | 2655 // DocumentState::referred_by_prefetcher_ is true if we are |
| 2630 // navigating from a page that used prefetching using a link on that | 2656 // navigating from a page that used prefetching using a link on that |
| 2631 // page. We are early enough in the request process here that we | 2657 // page. We are early enough in the request process here that we |
| 2632 // can still see the DocumentState of the previous page and set | 2658 // can still see the DocumentState of the previous page and set |
| 2633 // this value appropriately. | 2659 // this value appropriately. |
| 2634 // TODO(gavinp): catch the important case of navigation in a new | 2660 // TODO(gavinp): catch the important case of navigation in a new |
| 2635 // renderer process. | 2661 // renderer process. |
| 2636 if (webview) { | 2662 if (webview) { |
| 2637 if (WebFrame* old_frame = webview->mainFrame()) { | 2663 if (WebFrame* old_frame = webview->mainFrame()) { |
| 2638 const WebURLRequest& original_request = datasource->originalRequest(); | 2664 const WebURLRequest& original_request = datasource->originalRequest(); |
| (...skipping 2185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4824 | 4850 |
| 4825 if (should_load_request) { | 4851 if (should_load_request) { |
| 4826 // Sanitize navigation start now that we know the load_type. | 4852 // Sanitize navigation start now that we know the load_type. |
| 4827 pending_navigation_params_->common_params.navigation_start = | 4853 pending_navigation_params_->common_params.navigation_start = |
| 4828 SanitizeNavigationTiming(load_type, common_params.navigation_start, | 4854 SanitizeNavigationTiming(load_type, common_params.navigation_start, |
| 4829 renderer_navigation_start); | 4855 renderer_navigation_start); |
| 4830 // Perform a navigation to a data url if needed. | 4856 // Perform a navigation to a data url if needed. |
| 4831 if (!common_params.base_url_for_data_url.is_empty() || | 4857 if (!common_params.base_url_for_data_url.is_empty() || |
| 4832 (browser_side_navigation && | 4858 (browser_side_navigation && |
| 4833 common_params.url.SchemeIs(url::kDataScheme))) { | 4859 common_params.url.SchemeIs(url::kDataScheme))) { |
| 4834 LoadDataURL(common_params, frame_); | 4860 LoadDataURL(common_params, frame_, load_type); |
| 4835 } else { | 4861 } else { |
| 4836 // Load the request. | 4862 // Load the request. |
| 4837 frame_->toWebLocalFrame()->load(request, load_type, | 4863 frame_->toWebLocalFrame()->load(request, load_type, |
| 4838 item_for_history_navigation); | 4864 item_for_history_navigation); |
| 4839 } | 4865 } |
| 4840 } | 4866 } |
| 4841 | 4867 |
| 4842 // In case LoadRequest failed before didCreateDataSource was called. | 4868 // In case LoadRequest failed before didCreateDataSource was called. |
| 4843 pending_navigation_params_.reset(); | 4869 pending_navigation_params_.reset(); |
| 4844 } | 4870 } |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5064 MakeCommonNavigationParams(request, should_replace_current_entry), | 5090 MakeCommonNavigationParams(request, should_replace_current_entry), |
| 5065 BeginNavigationParams( | 5091 BeginNavigationParams( |
| 5066 request->httpMethod().latin1(), GetWebURLRequestHeaders(*request), | 5092 request->httpMethod().latin1(), GetWebURLRequestHeaders(*request), |
| 5067 GetLoadFlagsForWebURLRequest(*request), request->hasUserGesture(), | 5093 GetLoadFlagsForWebURLRequest(*request), request->hasUserGesture(), |
| 5068 request->skipServiceWorker(), | 5094 request->skipServiceWorker(), |
| 5069 GetRequestContextTypeForWebURLRequest(*request)), | 5095 GetRequestContextTypeForWebURLRequest(*request)), |
| 5070 GetRequestBodyForWebURLRequest(*request))); | 5096 GetRequestBodyForWebURLRequest(*request))); |
| 5071 } | 5097 } |
| 5072 | 5098 |
| 5073 void RenderFrameImpl::LoadDataURL(const CommonNavigationParams& params, | 5099 void RenderFrameImpl::LoadDataURL(const CommonNavigationParams& params, |
| 5074 WebFrame* frame) { | 5100 WebFrame* frame, |
| 5101 blink::WebFrameLoadType load_type) { | |
| 5075 // A loadData request with a specified base URL. | 5102 // A loadData request with a specified base URL. |
| 5076 std::string mime_type, charset, data; | 5103 std::string mime_type, charset, data; |
| 5077 if (net::DataURL::Parse(params.url, &mime_type, &charset, &data)) { | 5104 if (net::DataURL::Parse(params.url, &mime_type, &charset, &data)) { |
| 5078 const GURL base_url = params.base_url_for_data_url.is_empty() ? | 5105 const GURL base_url = params.base_url_for_data_url.is_empty() ? |
| 5079 params.url : params.base_url_for_data_url; | 5106 params.url : params.base_url_for_data_url; |
| 5107 bool replace = load_type == blink::WebFrameLoadType::ReloadFromOrigin || | |
| 5108 load_type == blink::WebFrameLoadType::Reload; | |
| 5080 frame->loadData( | 5109 frame->loadData( |
| 5081 WebData(data.c_str(), data.length()), | 5110 WebData(data.c_str(), data.length()), |
| 5082 WebString::fromUTF8(mime_type), | 5111 WebString::fromUTF8(mime_type), |
| 5083 WebString::fromUTF8(charset), | 5112 WebString::fromUTF8(charset), |
| 5084 base_url, | 5113 base_url, |
| 5114 // Needed to not identify only changing history url as reload. | |
|
Charlie Reis
2015/11/20 21:30:12
nit: Rephrase.
Needed so that history-url-only ch
boliu
2015/11/23 22:32:25
Done.
| |
| 5085 params.history_url_for_data_url, | 5115 params.history_url_for_data_url, |
| 5086 false); | 5116 replace); |
| 5087 } else { | 5117 } else { |
| 5088 CHECK(false) << "Invalid URL passed: " | 5118 CHECK(false) << "Invalid URL passed: " |
| 5089 << params.url.possibly_invalid_spec(); | 5119 << params.url.possibly_invalid_spec(); |
| 5090 } | 5120 } |
| 5091 } | 5121 } |
| 5092 | 5122 |
| 5093 void RenderFrameImpl::SendUpdateState() { | 5123 void RenderFrameImpl::SendUpdateState() { |
| 5094 DCHECK(SiteIsolationPolicy::UseSubframeNavigationEntries()); | 5124 DCHECK(SiteIsolationPolicy::UseSubframeNavigationEntries()); |
| 5095 if (current_history_item_.isNull()) | 5125 if (current_history_item_.isNull()) |
| 5096 return; | 5126 return; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5140 if (RenderThreadImpl::current() && | 5170 if (RenderThreadImpl::current() && |
| 5141 RenderThreadImpl::current()->layout_test_mode()) { | 5171 RenderThreadImpl::current()->layout_test_mode()) { |
| 5142 return false; | 5172 return false; |
| 5143 } | 5173 } |
| 5144 | 5174 |
| 5145 return true; | 5175 return true; |
| 5146 } | 5176 } |
| 5147 | 5177 |
| 5148 GURL RenderFrameImpl::GetLoadingUrl() const { | 5178 GURL RenderFrameImpl::GetLoadingUrl() const { |
| 5149 WebDataSource* ds = frame_->dataSource(); | 5179 WebDataSource* ds = frame_->dataSource(); |
| 5150 if (ds->hasUnreachableURL()) | 5180 |
| 5151 return ds->unreachableURL(); | 5181 GURL overriden_url; |
| 5182 if (MaybeGetURLOverride(ds, &overriden_url)) { | |
|
Charlie Reis
2015/11/20 21:30:12
nit: No braces.
boliu
2015/11/23 22:32:25
Done.
| |
| 5183 return overriden_url; | |
| 5184 } | |
| 5152 | 5185 |
| 5153 const WebURLRequest& request = ds->request(); | 5186 const WebURLRequest& request = ds->request(); |
| 5154 return request.url(); | 5187 return request.url(); |
| 5155 } | 5188 } |
| 5156 | 5189 |
| 5157 void RenderFrameImpl::PopulateDocumentStateFromPending( | 5190 void RenderFrameImpl::PopulateDocumentStateFromPending( |
| 5158 DocumentState* document_state) { | 5191 DocumentState* document_state) { |
| 5159 document_state->set_request_time( | 5192 document_state->set_request_time( |
| 5160 pending_navigation_params_->request_params.request_time); | 5193 pending_navigation_params_->request_params.request_time); |
| 5161 | 5194 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5208 | 5241 |
| 5209 void RenderFrameImpl::UpdateNavigationState(DocumentState* document_state) { | 5242 void RenderFrameImpl::UpdateNavigationState(DocumentState* document_state) { |
| 5210 if (pending_navigation_params_) { | 5243 if (pending_navigation_params_) { |
| 5211 // If this is a browser-initiated load that doesn't override | 5244 // If this is a browser-initiated load that doesn't override |
| 5212 // navigation_start, set it here. | 5245 // navigation_start, set it here. |
| 5213 if (pending_navigation_params_->common_params.navigation_start.is_null()) { | 5246 if (pending_navigation_params_->common_params.navigation_start.is_null()) { |
| 5214 pending_navigation_params_->common_params.navigation_start = | 5247 pending_navigation_params_->common_params.navigation_start = |
| 5215 base::TimeTicks::Now(); | 5248 base::TimeTicks::Now(); |
| 5216 } | 5249 } |
| 5217 document_state->set_navigation_state(CreateNavigationStateFromPending()); | 5250 document_state->set_navigation_state(CreateNavigationStateFromPending()); |
| 5251 | |
| 5252 const CommonNavigationParams& common_params = | |
| 5253 pending_navigation_params_->common_params; | |
| 5254 bool load_data = !common_params.base_url_for_data_url.is_empty() && | |
| 5255 !common_params.history_url_for_data_url.is_empty() && | |
| 5256 common_params.url.SchemeIs(url::kDataScheme); | |
| 5257 document_state->set_was_load_data_url_with_base_url_request(load_data); | |
| 5258 document_state->set_data_url(common_params.url); | |
|
Charlie Reis
2015/11/20 21:30:12
We should only do this if |load_data| is true. It
boliu
2015/11/23 22:32:25
Done
| |
| 5259 | |
| 5218 pending_navigation_params_.reset(); | 5260 pending_navigation_params_.reset(); |
| 5219 } else { | 5261 } else { |
| 5220 document_state->set_navigation_state( | 5262 document_state->set_navigation_state( |
| 5221 NavigationStateImpl::CreateContentInitiated()); | 5263 NavigationStateImpl::CreateContentInitiated()); |
| 5222 } | 5264 } |
| 5223 } | 5265 } |
| 5224 | 5266 |
| 5225 #if defined(OS_ANDROID) | 5267 #if defined(OS_ANDROID) |
| 5226 WebMediaPlayer* RenderFrameImpl::CreateAndroidWebMediaPlayer( | 5268 WebMediaPlayer* RenderFrameImpl::CreateAndroidWebMediaPlayer( |
| 5227 WebMediaPlayerClient* client, | 5269 WebMediaPlayerClient* client, |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5361 media::ConvertToSwitchOutputDeviceCB(web_callbacks); | 5403 media::ConvertToSwitchOutputDeviceCB(web_callbacks); |
| 5362 scoped_refptr<media::AudioOutputDevice> device = | 5404 scoped_refptr<media::AudioOutputDevice> device = |
| 5363 AudioDeviceFactory::NewOutputDevice(routing_id_, 0, sink_id.utf8(), | 5405 AudioDeviceFactory::NewOutputDevice(routing_id_, 0, sink_id.utf8(), |
| 5364 security_origin); | 5406 security_origin); |
| 5365 media::OutputDeviceStatus status = device->GetDeviceStatus(); | 5407 media::OutputDeviceStatus status = device->GetDeviceStatus(); |
| 5366 device->Stop(); | 5408 device->Stop(); |
| 5367 callback.Run(status); | 5409 callback.Run(status); |
| 5368 } | 5410 } |
| 5369 | 5411 |
| 5370 } // namespace content | 5412 } // namespace content |
| OLD | NEW |