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

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

Issue 906283003: PlzNavigate: Support data urls (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase + change to unit test Created 5 years, 9 months 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
« no previous file with comments | « content/renderer/render_frame_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1075 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 // We must know the page ID of the page we are navigating back to. 1086 // We must know the page ID of the page we are navigating back to.
1087 DCHECK_NE(params.page_id, -1); 1087 DCHECK_NE(params.page_id, -1);
1088 scoped_ptr<HistoryEntry> entry = 1088 scoped_ptr<HistoryEntry> entry =
1089 PageStateToHistoryEntry(params.commit_params.page_state); 1089 PageStateToHistoryEntry(params.commit_params.page_state);
1090 if (entry) { 1090 if (entry) {
1091 // Ensure we didn't save the swapped out URL in UpdateState, since the 1091 // Ensure we didn't save the swapped out URL in UpdateState, since the
1092 // browser should never be telling us to navigate to swappedout://. 1092 // browser should never be telling us to navigate to swappedout://.
1093 CHECK(entry->root().urlString() != WebString::fromUTF8(kSwappedOutURL)); 1093 CHECK(entry->root().urlString() != WebString::fromUTF8(kSwappedOutURL));
1094 render_view_->history_controller()->GoToEntry(entry.Pass(), cache_policy); 1094 render_view_->history_controller()->GoToEntry(entry.Pass(), cache_policy);
1095 } 1095 }
1096 } else if (!params.base_url_for_data_url.is_empty()) { 1096 } else if (!params.common_params.base_url_for_data_url.is_empty()) {
1097 // A loadData request with a specified base URL. 1097 LoadDataURL(params.common_params, frame);
1098 std::string mime_type, charset, data;
1099 if (net::DataURL::Parse(
1100 params.common_params.url, &mime_type, &charset, &data)) {
1101 frame->loadData(
1102 WebData(data.c_str(), data.length()),
1103 WebString::fromUTF8(mime_type),
1104 WebString::fromUTF8(charset),
1105 params.base_url_for_data_url,
1106 params.history_url_for_data_url,
1107 false);
1108 } else {
1109 CHECK(false) << "Invalid URL passed: "
1110 << params.common_params.url.possibly_invalid_spec();
1111 }
1112 } else { 1098 } else {
1113 // Navigate to the given URL. 1099 // Navigate to the given URL.
1114 WebURLRequest request = 1100 WebURLRequest request =
1115 CreateURLRequestForNavigation(params.common_params, 1101 CreateURLRequestForNavigation(params.common_params,
1116 scoped_ptr<StreamOverrideParameters>(), 1102 scoped_ptr<StreamOverrideParameters>(),
1117 frame->isViewSourceModeEnabled()); 1103 frame->isViewSourceModeEnabled());
1118 1104
1119 if (!params.extra_headers.empty()) { 1105 if (!params.extra_headers.empty()) {
1120 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(), 1106 for (net::HttpUtil::HeadersIterator i(params.extra_headers.begin(),
1121 params.extra_headers.end(), 1107 params.extra_headers.end(),
(...skipping 2755 matching lines...) Expand 10 before | Expand all | Expand 10 after
3877 WebURLRequest::UseProtocolCachePolicy; 3863 WebURLRequest::UseProtocolCachePolicy;
3878 if (!RenderFrameImpl::PrepareRenderViewForNavigation( 3864 if (!RenderFrameImpl::PrepareRenderViewForNavigation(
3879 common_params.url, false /* check_for_stale_navigation */, 3865 common_params.url, false /* check_for_stale_navigation */,
3880 is_history_navigation, -1 /* current_history_list_offset; TODO(clamy)*/, 3866 is_history_navigation, -1 /* current_history_list_offset; TODO(clamy)*/,
3881 &is_reload, &cache_policy)) { 3867 &is_reload, &cache_policy)) {
3882 return; 3868 return;
3883 } 3869 }
3884 3870
3885 GetContentClient()->SetActiveURL(common_params.url); 3871 GetContentClient()->SetActiveURL(common_params.url);
3886 3872
3873 if (!common_params.base_url_for_data_url.is_empty() ||
3874 common_params.url.SchemeIs(url::kDataScheme)) {
3875 LoadDataURL(common_params, frame_);
3876 return;
3877 }
3878
3887 // Create a WebURLRequest that blink can use to get access to the body of the 3879 // Create a WebURLRequest that blink can use to get access to the body of the
3888 // response through a stream in the browser. Blink will then commit the 3880 // response through a stream in the browser. Blink will then commit the
3889 // navigation. 3881 // navigation.
3890 // TODO(clamy): Have the navigation commit directly, without going through 3882 // TODO(clamy): Have the navigation commit directly, without going through
3891 // loading a WebURLRequest. 3883 // loading a WebURLRequest.
3892 scoped_ptr<StreamOverrideParameters> stream_override( 3884 scoped_ptr<StreamOverrideParameters> stream_override(
3893 new StreamOverrideParameters()); 3885 new StreamOverrideParameters());
3894 stream_override->stream_url = stream_url; 3886 stream_override->stream_url = stream_url;
3895 stream_override->response = response; 3887 stream_override->response = response;
3896 WebURLRequest request = 3888 WebURLRequest request =
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
4372 Send(new FrameHostMsg_DidStartLoading(routing_id_, true)); 4364 Send(new FrameHostMsg_DidStartLoading(routing_id_, true));
4373 Send(new FrameHostMsg_BeginNavigation( 4365 Send(new FrameHostMsg_BeginNavigation(
4374 routing_id_, MakeCommonNavigationParams(request), 4366 routing_id_, MakeCommonNavigationParams(request),
4375 BeginNavigationParams(request->httpMethod().latin1(), 4367 BeginNavigationParams(request->httpMethod().latin1(),
4376 GetWebURLRequestHeaders(*request), 4368 GetWebURLRequestHeaders(*request),
4377 GetLoadFlagsForWebURLRequest(*request), 4369 GetLoadFlagsForWebURLRequest(*request),
4378 request->hasUserGesture()), 4370 request->hasUserGesture()),
4379 GetRequestBodyForWebURLRequest(*request))); 4371 GetRequestBodyForWebURLRequest(*request)));
4380 } 4372 }
4381 4373
4374 void RenderFrameImpl::LoadDataURL(const CommonNavigationParams& params,
4375 WebFrame* frame) {
4376 // A loadData request with a specified base URL.
4377 std::string mime_type, charset, data;
4378 if (net::DataURL::Parse(params.url, &mime_type, &charset, &data)) {
4379 const GURL base_url = params.base_url_for_data_url.is_empty() ?
4380 params.url : params.base_url_for_data_url;
4381 frame->loadData(
4382 WebData(data.c_str(), data.length()),
4383 WebString::fromUTF8(mime_type),
4384 WebString::fromUTF8(charset),
4385 base_url,
4386 params.history_url_for_data_url,
4387 false);
4388 } else {
4389 CHECK(false) << "Invalid URL passed: "
4390 << params.url.possibly_invalid_spec();
4391 }
4392 }
4393
4382 GURL RenderFrameImpl::GetLoadingUrl() const { 4394 GURL RenderFrameImpl::GetLoadingUrl() const {
4383 WebDataSource* ds = frame_->dataSource(); 4395 WebDataSource* ds = frame_->dataSource();
4384 if (ds->hasUnreachableURL()) 4396 if (ds->hasUnreachableURL())
4385 return ds->unreachableURL(); 4397 return ds->unreachableURL();
4386 4398
4387 const WebURLRequest& request = ds->request(); 4399 const WebURLRequest& request = ds->request();
4388 return request.url(); 4400 return request.url();
4389 } 4401 }
4390 4402
4391 #if defined(OS_ANDROID) 4403 #if defined(OS_ANDROID)
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
4443 4455
4444 #if defined(ENABLE_BROWSER_CDMS) 4456 #if defined(ENABLE_BROWSER_CDMS)
4445 RendererCdmManager* RenderFrameImpl::GetCdmManager() { 4457 RendererCdmManager* RenderFrameImpl::GetCdmManager() {
4446 if (!cdm_manager_) 4458 if (!cdm_manager_)
4447 cdm_manager_ = new RendererCdmManager(this); 4459 cdm_manager_ = new RendererCdmManager(this);
4448 return cdm_manager_; 4460 return cdm_manager_;
4449 } 4461 }
4450 #endif // defined(ENABLE_BROWSER_CDMS) 4462 #endif // defined(ENABLE_BROWSER_CDMS)
4451 4463
4452 } // namespace content 4464 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_frame_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698