Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(586)

Side by Side Diff: content/renderer/render_frame_impl.cc

Issue 1304373007: Browser test for LoadDataWithBaseURL reload (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
311 // (if any), storing it in |output|. Returns true if there is an override URL.
312 bool MaybeGetOverriddenURL(WebDataSource* ds, GURL* output) {
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 (MaybeGetOverriddenURL(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 4503 matching lines...) Expand 10 before | Expand all | Expand 10 after
4833 4854
4834 if (should_load_request) { 4855 if (should_load_request) {
4835 // Sanitize navigation start now that we know the load_type. 4856 // Sanitize navigation start now that we know the load_type.
4836 pending_navigation_params_->common_params.navigation_start = 4857 pending_navigation_params_->common_params.navigation_start =
4837 SanitizeNavigationTiming(load_type, common_params.navigation_start, 4858 SanitizeNavigationTiming(load_type, common_params.navigation_start,
4838 renderer_navigation_start); 4859 renderer_navigation_start);
4839 // Perform a navigation to a data url if needed. 4860 // Perform a navigation to a data url if needed.
4840 if (!common_params.base_url_for_data_url.is_empty() || 4861 if (!common_params.base_url_for_data_url.is_empty() ||
4841 (browser_side_navigation && 4862 (browser_side_navigation &&
4842 common_params.url.SchemeIs(url::kDataScheme))) { 4863 common_params.url.SchemeIs(url::kDataScheme))) {
4843 LoadDataURL(common_params, frame_); 4864 LoadDataURL(common_params, frame_, load_type);
4844 } else { 4865 } else {
4845 // Load the request. 4866 // Load the request.
4846 frame_->toWebLocalFrame()->load(request, load_type, 4867 frame_->toWebLocalFrame()->load(request, load_type,
4847 item_for_history_navigation); 4868 item_for_history_navigation);
4848 } 4869 }
4849 } 4870 }
4850 4871
4851 // In case LoadRequest failed before didCreateDataSource was called. 4872 // In case LoadRequest failed before didCreateDataSource was called.
4852 pending_navigation_params_.reset(); 4873 pending_navigation_params_.reset();
4853 } 4874 }
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
5073 MakeCommonNavigationParams(request, should_replace_current_entry), 5094 MakeCommonNavigationParams(request, should_replace_current_entry),
5074 BeginNavigationParams( 5095 BeginNavigationParams(
5075 request->httpMethod().latin1(), GetWebURLRequestHeaders(*request), 5096 request->httpMethod().latin1(), GetWebURLRequestHeaders(*request),
5076 GetLoadFlagsForWebURLRequest(*request), request->hasUserGesture(), 5097 GetLoadFlagsForWebURLRequest(*request), request->hasUserGesture(),
5077 request->skipServiceWorker(), 5098 request->skipServiceWorker(),
5078 GetRequestContextTypeForWebURLRequest(*request)), 5099 GetRequestContextTypeForWebURLRequest(*request)),
5079 GetRequestBodyForWebURLRequest(*request))); 5100 GetRequestBodyForWebURLRequest(*request)));
5080 } 5101 }
5081 5102
5082 void RenderFrameImpl::LoadDataURL(const CommonNavigationParams& params, 5103 void RenderFrameImpl::LoadDataURL(const CommonNavigationParams& params,
5083 WebFrame* frame) { 5104 WebFrame* frame,
5105 blink::WebFrameLoadType load_type) {
5084 // A loadData request with a specified base URL. 5106 // A loadData request with a specified base URL.
5085 std::string mime_type, charset, data; 5107 std::string mime_type, charset, data;
5086 if (net::DataURL::Parse(params.url, &mime_type, &charset, &data)) { 5108 if (net::DataURL::Parse(params.url, &mime_type, &charset, &data)) {
5087 const GURL base_url = params.base_url_for_data_url.is_empty() ? 5109 const GURL base_url = params.base_url_for_data_url.is_empty() ?
5088 params.url : params.base_url_for_data_url; 5110 params.url : params.base_url_for_data_url;
5111 bool replace = load_type == blink::WebFrameLoadType::ReloadFromOrigin ||
5112 load_type == blink::WebFrameLoadType::Reload;
5089 frame->loadData( 5113 frame->loadData(
5090 WebData(data.c_str(), data.length()), 5114 WebData(data.c_str(), data.length()),
5091 WebString::fromUTF8(mime_type), 5115 WebString::fromUTF8(mime_type),
5092 WebString::fromUTF8(charset), 5116 WebString::fromUTF8(charset),
5093 base_url, 5117 base_url,
5118 // Needed so that history-url-only changes don't become reloads.
5094 params.history_url_for_data_url, 5119 params.history_url_for_data_url,
5095 false); 5120 replace);
5096 } else { 5121 } else {
5097 CHECK(false) << "Invalid URL passed: " 5122 CHECK(false) << "Invalid URL passed: "
5098 << params.url.possibly_invalid_spec(); 5123 << params.url.possibly_invalid_spec();
5099 } 5124 }
5100 } 5125 }
5101 5126
5102 void RenderFrameImpl::SendUpdateState() { 5127 void RenderFrameImpl::SendUpdateState() {
5103 DCHECK(SiteIsolationPolicy::UseSubframeNavigationEntries()); 5128 DCHECK(SiteIsolationPolicy::UseSubframeNavigationEntries());
5104 if (current_history_item_.isNull()) 5129 if (current_history_item_.isNull())
5105 return; 5130 return;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
5149 if (RenderThreadImpl::current() && 5174 if (RenderThreadImpl::current() &&
5150 RenderThreadImpl::current()->layout_test_mode()) { 5175 RenderThreadImpl::current()->layout_test_mode()) {
5151 return false; 5176 return false;
5152 } 5177 }
5153 5178
5154 return true; 5179 return true;
5155 } 5180 }
5156 5181
5157 GURL RenderFrameImpl::GetLoadingUrl() const { 5182 GURL RenderFrameImpl::GetLoadingUrl() const {
5158 WebDataSource* ds = frame_->dataSource(); 5183 WebDataSource* ds = frame_->dataSource();
5159 if (ds->hasUnreachableURL()) 5184
5160 return ds->unreachableURL(); 5185 GURL overriden_url;
5186 if (MaybeGetOverriddenURL(ds, &overriden_url))
5187 return overriden_url;
5161 5188
5162 const WebURLRequest& request = ds->request(); 5189 const WebURLRequest& request = ds->request();
5163 return request.url(); 5190 return request.url();
5164 } 5191 }
5165 5192
5166 void RenderFrameImpl::PopulateDocumentStateFromPending( 5193 void RenderFrameImpl::PopulateDocumentStateFromPending(
5167 DocumentState* document_state) { 5194 DocumentState* document_state) {
5168 document_state->set_request_time( 5195 document_state->set_request_time(
5169 pending_navigation_params_->request_params.request_time); 5196 pending_navigation_params_->request_params.request_time);
5170 5197
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
5217 5244
5218 void RenderFrameImpl::UpdateNavigationState(DocumentState* document_state) { 5245 void RenderFrameImpl::UpdateNavigationState(DocumentState* document_state) {
5219 if (pending_navigation_params_) { 5246 if (pending_navigation_params_) {
5220 // If this is a browser-initiated load that doesn't override 5247 // If this is a browser-initiated load that doesn't override
5221 // navigation_start, set it here. 5248 // navigation_start, set it here.
5222 if (pending_navigation_params_->common_params.navigation_start.is_null()) { 5249 if (pending_navigation_params_->common_params.navigation_start.is_null()) {
5223 pending_navigation_params_->common_params.navigation_start = 5250 pending_navigation_params_->common_params.navigation_start =
5224 base::TimeTicks::Now(); 5251 base::TimeTicks::Now();
5225 } 5252 }
5226 document_state->set_navigation_state(CreateNavigationStateFromPending()); 5253 document_state->set_navigation_state(CreateNavigationStateFromPending());
5254
5255 const CommonNavigationParams& common_params =
5256 pending_navigation_params_->common_params;
5257 bool load_data = !common_params.base_url_for_data_url.is_empty() &&
5258 !common_params.history_url_for_data_url.is_empty() &&
5259 common_params.url.SchemeIs(url::kDataScheme);
5260 document_state->set_was_load_data_with_base_url_request(load_data);
5261 if (load_data)
5262 document_state->set_data_url(common_params.url);
5263
5227 pending_navigation_params_.reset(); 5264 pending_navigation_params_.reset();
5228 } else { 5265 } else {
5229 document_state->set_navigation_state( 5266 document_state->set_navigation_state(
5230 NavigationStateImpl::CreateContentInitiated()); 5267 NavigationStateImpl::CreateContentInitiated());
5231 } 5268 }
5232 } 5269 }
5233 5270
5234 #if defined(OS_ANDROID) 5271 #if defined(OS_ANDROID)
5235 WebMediaPlayer* RenderFrameImpl::CreateAndroidWebMediaPlayer( 5272 WebMediaPlayer* RenderFrameImpl::CreateAndroidWebMediaPlayer(
5236 WebMediaPlayerClient* client, 5273 WebMediaPlayerClient* client,
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
5370 media::ConvertToSwitchOutputDeviceCB(web_callbacks); 5407 media::ConvertToSwitchOutputDeviceCB(web_callbacks);
5371 scoped_refptr<media::AudioOutputDevice> device = 5408 scoped_refptr<media::AudioOutputDevice> device =
5372 AudioDeviceFactory::NewOutputDevice(routing_id_, 0, sink_id.utf8(), 5409 AudioDeviceFactory::NewOutputDevice(routing_id_, 0, sink_id.utf8(),
5373 security_origin); 5410 security_origin);
5374 media::OutputDeviceStatus status = device->GetDeviceStatus(); 5411 media::OutputDeviceStatus status = device->GetDeviceStatus();
5375 device->Stop(); 5412 device->Stop();
5376 callback.Run(status); 5413 callback.Run(status);
5377 } 5414 }
5378 5415
5379 } // namespace content 5416 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_frame_impl.h ('k') | extensions/browser/guest_view/web_view/web_view_guest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698