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

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

Issue 1310743003: Consistently use LoFi for an entire page (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mmenke comments Created 5 years, 2 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
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 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 WebString web_referrer = WebSecurityPolicy::generateReferrerHeader( 421 WebString web_referrer = WebSecurityPolicy::generateReferrerHeader(
422 common_params.referrer.policy, 422 common_params.referrer.policy,
423 common_params.url, 423 common_params.url,
424 WebString::fromUTF8(common_params.referrer.url.spec())); 424 WebString::fromUTF8(common_params.referrer.url.spec()));
425 if (!web_referrer.isEmpty()) 425 if (!web_referrer.isEmpty())
426 request.setHTTPReferrer(web_referrer, common_params.referrer.policy); 426 request.setHTTPReferrer(web_referrer, common_params.referrer.policy);
427 } 427 }
428 428
429 RequestExtraData* extra_data = new RequestExtraData(); 429 RequestExtraData* extra_data = new RequestExtraData();
430 extra_data->set_stream_override(stream_override.Pass()); 430 extra_data->set_stream_override(stream_override.Pass());
431 extra_data->set_lofi_state(common_params.lofi_state);
431 request.setExtraData(extra_data); 432 request.setExtraData(extra_data);
432 433
433 // Set the ui timestamp for this navigation. Currently the timestamp here is 434 // Set the ui timestamp for this navigation. Currently the timestamp here is
434 // only non empty when the navigation was triggered by an Android intent. The 435 // only non empty when the navigation was triggered by an Android intent. The
435 // timestamp is converted to a double version supported by blink. It will be 436 // timestamp is converted to a double version supported by blink. It will be
436 // passed back to the browser in the DidCommitProvisionalLoad and the 437 // passed back to the browser in the DidCommitProvisionalLoad and the
437 // DocumentLoadComplete IPCs. 438 // DocumentLoadComplete IPCs.
438 base::TimeDelta ui_timestamp = common_params.ui_timestamp - base::TimeTicks(); 439 base::TimeDelta ui_timestamp = common_params.ui_timestamp - base::TimeTicks();
439 request.setUiStartTime(ui_timestamp.InSecondsF()); 440 request.setUiStartTime(ui_timestamp.InSecondsF());
440 request.setInputPerfMetricReportPolicy( 441 request.setInputPerfMetricReportPolicy(
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
714 #endif 715 #endif
715 has_played_media_(false), 716 has_played_media_(false),
716 devtools_agent_(nullptr), 717 devtools_agent_(nullptr),
717 geolocation_dispatcher_(NULL), 718 geolocation_dispatcher_(NULL),
718 push_messaging_dispatcher_(NULL), 719 push_messaging_dispatcher_(NULL),
719 presentation_dispatcher_(NULL), 720 presentation_dispatcher_(NULL),
720 screen_orientation_dispatcher_(NULL), 721 screen_orientation_dispatcher_(NULL),
721 manifest_manager_(NULL), 722 manifest_manager_(NULL),
722 accessibility_mode_(AccessibilityModeOff), 723 accessibility_mode_(AccessibilityModeOff),
723 renderer_accessibility_(NULL), 724 renderer_accessibility_(NULL),
725 is_using_lofi_(false),
724 weak_factory_(this) { 726 weak_factory_(this) {
725 std::pair<RoutingIDFrameMap::iterator, bool> result = 727 std::pair<RoutingIDFrameMap::iterator, bool> result =
726 g_routing_id_frame_map.Get().insert(std::make_pair(routing_id_, this)); 728 g_routing_id_frame_map.Get().insert(std::make_pair(routing_id_, this));
727 CHECK(result.second) << "Inserting a duplicate item."; 729 CHECK(result.second) << "Inserting a duplicate item.";
728 730
729 RenderThread::Get()->AddRoute(routing_id_, this); 731 RenderThread::Get()->AddRoute(routing_id_, this);
730 732
731 render_view_->RegisterRenderFrame(this); 733 render_view_->RegisterRenderFrame(this);
732 734
733 // Everything below subclasses RenderFrameObserver and is automatically 735 // Everything below subclasses RenderFrameObserver and is automatically
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 void RenderFrameImpl::SetWebFrame(blink::WebLocalFrame* web_frame) { 786 void RenderFrameImpl::SetWebFrame(blink::WebLocalFrame* web_frame) {
785 DCHECK(!frame_); 787 DCHECK(!frame_);
786 788
787 std::pair<FrameMap::iterator, bool> result = g_frame_map.Get().insert( 789 std::pair<FrameMap::iterator, bool> result = g_frame_map.Get().insert(
788 std::make_pair(web_frame, this)); 790 std::make_pair(web_frame, this));
789 CHECK(result.second) << "Inserting a duplicate item."; 791 CHECK(result.second) << "Inserting a duplicate item.";
790 792
791 frame_ = web_frame; 793 frame_ = web_frame;
792 } 794 }
793 795
794 void RenderFrameImpl::Initialize() { 796 void RenderFrameImpl::Initialize(bool is_using_lofi) {
795 is_main_frame_ = !frame_->parent(); 797 is_main_frame_ = !frame_->parent();
796 is_local_root_ = is_main_frame_ || frame_->parent()->isWebRemoteFrame(); 798 is_local_root_ = is_main_frame_ || frame_->parent()->isWebRemoteFrame();
799 is_using_lofi_ = is_using_lofi;
797 800
798 bool is_tracing = false; 801 bool is_tracing = false;
799 TRACE_EVENT_CATEGORY_GROUP_ENABLED("navigation", &is_tracing); 802 TRACE_EVENT_CATEGORY_GROUP_ENABLED("navigation", &is_tracing);
800 if (is_tracing) { 803 if (is_tracing) {
801 int parent_id = MSG_ROUTING_NONE; 804 int parent_id = MSG_ROUTING_NONE;
802 if (!is_main_frame_) { 805 if (!is_main_frame_) {
803 if (frame_->parent()->isWebRemoteFrame()) { 806 if (frame_->parent()->isWebRemoteFrame()) {
804 RenderFrameProxy* parent_proxy = RenderFrameProxy::FromWebFrame( 807 RenderFrameProxy* parent_proxy = RenderFrameProxy::FromWebFrame(
805 frame_->parent()); 808 frame_->parent());
806 if (parent_proxy) 809 if (parent_proxy)
(...skipping 1203 matching lines...) Expand 10 before | Expand all | Expand 10 after
2010 ServiceRegistryJsWrapper::kModuleName, 2013 ServiceRegistryJsWrapper::kModuleName,
2011 ServiceRegistryJsWrapper::Create(isolate, &service_registry_).ToV8()); 2014 ServiceRegistryJsWrapper::Create(isolate, &service_registry_).ToV8());
2012 } 2015 }
2013 2016
2014 void RenderFrameImpl::AddMessageToConsole(ConsoleMessageLevel level, 2017 void RenderFrameImpl::AddMessageToConsole(ConsoleMessageLevel level,
2015 const std::string& message) { 2018 const std::string& message) {
2016 if (devtools_agent_) 2019 if (devtools_agent_)
2017 devtools_agent_->AddMessageToConsole(level, message); 2020 devtools_agent_->AddMessageToConsole(level, message);
2018 } 2021 }
2019 2022
2023 bool RenderFrameImpl::IsUsingLoFi() {
2024 return is_using_lofi_;
2025 }
2026
2020 // blink::WebFrameClient implementation ---------------------------------------- 2027 // blink::WebFrameClient implementation ----------------------------------------
2021 2028
2022 blink::WebPlugin* RenderFrameImpl::createPlugin( 2029 blink::WebPlugin* RenderFrameImpl::createPlugin(
2023 blink::WebLocalFrame* frame, 2030 blink::WebLocalFrame* frame,
2024 const blink::WebPluginParams& params) { 2031 const blink::WebPluginParams& params) {
2025 DCHECK_EQ(frame_, frame); 2032 DCHECK_EQ(frame_, frame);
2026 blink::WebPlugin* plugin = NULL; 2033 blink::WebPlugin* plugin = NULL;
2027 if (GetContentClient()->renderer()->OverrideCreatePlugin( 2034 if (GetContentClient()->renderer()->OverrideCreatePlugin(
2028 this, frame, params, &plugin)) { 2035 this, frame, params, &plugin)) {
2029 return plugin; 2036 return plugin;
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
2237 2244
2238 // Create the RenderFrame and WebLocalFrame, linking the two. 2245 // Create the RenderFrame and WebLocalFrame, linking the two.
2239 RenderFrameImpl* child_render_frame = RenderFrameImpl::Create( 2246 RenderFrameImpl* child_render_frame = RenderFrameImpl::Create(
2240 render_view_.get(), child_routing_id); 2247 render_view_.get(), child_routing_id);
2241 blink::WebLocalFrame* web_frame = 2248 blink::WebLocalFrame* web_frame =
2242 WebLocalFrame::create(scope, child_render_frame); 2249 WebLocalFrame::create(scope, child_render_frame);
2243 child_render_frame->SetWebFrame(web_frame); 2250 child_render_frame->SetWebFrame(web_frame);
2244 2251
2245 // Add the frame to the frame tree and initialize it. 2252 // Add the frame to the frame tree and initialize it.
2246 parent->appendChild(web_frame); 2253 parent->appendChild(web_frame);
2247 child_render_frame->Initialize(); 2254 child_render_frame->Initialize(is_using_lofi_);
2248 2255
2249 return web_frame; 2256 return web_frame;
2250 } 2257 }
2251 2258
2252 void RenderFrameImpl::didChangeOpener(blink::WebFrame* opener) { 2259 void RenderFrameImpl::didChangeOpener(blink::WebFrame* opener) {
2253 // Only active frames are able to disown their opener. 2260 // Only active frames are able to disown their opener.
2254 if (!opener && is_swapped_out_) 2261 if (!opener && is_swapped_out_)
2255 return; 2262 return;
2256 2263
2257 // Only a local frame should be able to update another frame's opener. 2264 // Only a local frame should be able to update another frame's opener.
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
2709 const blink::WebHistoryItem& item, 2716 const blink::WebHistoryItem& item,
2710 blink::WebHistoryCommitType commit_type) { 2717 blink::WebHistoryCommitType commit_type) {
2711 TRACE_EVENT2("navigation", "RenderFrameImpl::didCommitProvisionalLoad", 2718 TRACE_EVENT2("navigation", "RenderFrameImpl::didCommitProvisionalLoad",
2712 "id", routing_id_, 2719 "id", routing_id_,
2713 "url", GetLoadingUrl().possibly_invalid_spec()); 2720 "url", GetLoadingUrl().possibly_invalid_spec());
2714 DCHECK(!frame_ || frame_ == frame); 2721 DCHECK(!frame_ || frame_ == frame);
2715 DocumentState* document_state = 2722 DocumentState* document_state =
2716 DocumentState::FromDataSource(frame->dataSource()); 2723 DocumentState::FromDataSource(frame->dataSource());
2717 NavigationStateImpl* navigation_state = 2724 NavigationStateImpl* navigation_state =
2718 static_cast<NavigationStateImpl*>(document_state->navigation_state()); 2725 static_cast<NavigationStateImpl*>(document_state->navigation_state());
2726 WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse(
2727 frame->dataSource()->response());
2728 is_using_lofi_ = extra_data && extra_data->is_using_lofi();
2719 2729
2720 if (proxy_routing_id_ != MSG_ROUTING_NONE) { 2730 if (proxy_routing_id_ != MSG_ROUTING_NONE) {
2721 RenderFrameProxy* proxy = 2731 RenderFrameProxy* proxy =
2722 RenderFrameProxy::FromRoutingID(proxy_routing_id_); 2732 RenderFrameProxy::FromRoutingID(proxy_routing_id_);
2723 CHECK(proxy); 2733 CHECK(proxy);
2724 proxy->web_frame()->swap(frame_); 2734 proxy->web_frame()->swap(frame_);
2725 proxy_routing_id_ = MSG_ROUTING_NONE; 2735 proxy_routing_id_ = MSG_ROUTING_NONE;
2726 2736
2727 // If this is the main frame going from a remote frame to a local frame, 2737 // If this is the main frame going from a remote frame to a local frame,
2728 // it needs to set RenderViewImpl's pointer for the main frame to itself 2738 // it needs to set RenderViewImpl's pointer for the main frame to itself
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
3265 3275
3266 // The request's extra data may indicate that we should set a custom user 3276 // The request's extra data may indicate that we should set a custom user
3267 // agent. This needs to be done here, after WebKit is through with setting the 3277 // agent. This needs to be done here, after WebKit is through with setting the
3268 // user agent on its own. Similarly, it may indicate that we should set an 3278 // user agent on its own. Similarly, it may indicate that we should set an
3269 // X-Requested-With header. This must be done here to avoid breaking CORS 3279 // X-Requested-With header. This must be done here to avoid breaking CORS
3270 // checks. 3280 // checks.
3271 // PlzNavigate: there may also be a stream url associated with the request. 3281 // PlzNavigate: there may also be a stream url associated with the request.
3272 WebString custom_user_agent; 3282 WebString custom_user_agent;
3273 WebString requested_with; 3283 WebString requested_with;
3274 scoped_ptr<StreamOverrideParameters> stream_override; 3284 scoped_ptr<StreamOverrideParameters> stream_override;
3285 LoFiState lofi_state = LOFI_UNSPECIFIED;
3275 if (request.extraData()) { 3286 if (request.extraData()) {
3276 RequestExtraData* old_extra_data = 3287 RequestExtraData* old_extra_data =
3277 static_cast<RequestExtraData*>(request.extraData()); 3288 static_cast<RequestExtraData*>(request.extraData());
3278 3289
3279 custom_user_agent = old_extra_data->custom_user_agent(); 3290 custom_user_agent = old_extra_data->custom_user_agent();
3280 if (!custom_user_agent.isNull()) { 3291 if (!custom_user_agent.isNull()) {
3281 if (custom_user_agent.isEmpty()) 3292 if (custom_user_agent.isEmpty())
3282 request.clearHTTPHeaderField("User-Agent"); 3293 request.clearHTTPHeaderField("User-Agent");
3283 else 3294 else
3284 request.setHTTPHeaderField("User-Agent", custom_user_agent); 3295 request.setHTTPHeaderField("User-Agent", custom_user_agent);
3285 } 3296 }
3286 3297
3287 requested_with = old_extra_data->requested_with(); 3298 requested_with = old_extra_data->requested_with();
3288 if (!requested_with.isNull()) { 3299 if (!requested_with.isNull()) {
3289 if (requested_with.isEmpty()) 3300 if (requested_with.isEmpty())
3290 request.clearHTTPHeaderField("X-Requested-With"); 3301 request.clearHTTPHeaderField("X-Requested-With");
3291 else 3302 else
3292 request.setHTTPHeaderField("X-Requested-With", requested_with); 3303 request.setHTTPHeaderField("X-Requested-With", requested_with);
3293 } 3304 }
3294 stream_override = old_extra_data->TakeStreamOverrideOwnership(); 3305 stream_override = old_extra_data->TakeStreamOverrideOwnership();
3306 lofi_state = old_extra_data->lofi_state();
3295 } 3307 }
3296 3308
3297 // Add the default accept header for frame request if it has not been set 3309 // Add the default accept header for frame request if it has not been set
3298 // already. 3310 // already.
3299 if ((request.frameType() == blink::WebURLRequest::FrameTypeTopLevel || 3311 if ((request.frameType() == blink::WebURLRequest::FrameTypeTopLevel ||
3300 request.frameType() == blink::WebURLRequest::FrameTypeNested) && 3312 request.frameType() == blink::WebURLRequest::FrameTypeNested) &&
3301 request.httpHeaderField(WebString::fromUTF8(kAcceptHeader)).isEmpty()) { 3313 request.httpHeaderField(WebString::fromUTF8(kAcceptHeader)).isEmpty()) {
3302 request.setHTTPHeaderField(WebString::fromUTF8(kAcceptHeader), 3314 request.setHTTPHeaderField(WebString::fromUTF8(kAcceptHeader),
3303 WebString::fromUTF8(kDefaultAcceptHeader)); 3315 WebString::fromUTF8(kDefaultAcceptHeader));
3304 } 3316 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
3368 extra_data->set_allow_download( 3380 extra_data->set_allow_download(
3369 navigation_state->common_params().allow_download); 3381 navigation_state->common_params().allow_download);
3370 extra_data->set_transition_type(transition_type); 3382 extra_data->set_transition_type(transition_type);
3371 extra_data->set_should_replace_current_entry(should_replace_current_entry); 3383 extra_data->set_should_replace_current_entry(should_replace_current_entry);
3372 extra_data->set_transferred_request_child_id( 3384 extra_data->set_transferred_request_child_id(
3373 navigation_state->start_params().transferred_request_child_id); 3385 navigation_state->start_params().transferred_request_child_id);
3374 extra_data->set_transferred_request_request_id( 3386 extra_data->set_transferred_request_request_id(
3375 navigation_state->start_params().transferred_request_request_id); 3387 navigation_state->start_params().transferred_request_request_id);
3376 extra_data->set_service_worker_provider_id(provider_id); 3388 extra_data->set_service_worker_provider_id(provider_id);
3377 extra_data->set_stream_override(stream_override.Pass()); 3389 extra_data->set_stream_override(stream_override.Pass());
3390 // TODO(megjablon): Set the navigation params for single image loads to
3391 // LOFI_OFF and remove the dependency on ReloadBypassingCache.
3392 if (request.cachePolicy() == WebURLRequest::ReloadBypassingCache)
3393 extra_data->set_lofi_state(LOFI_OFF);
3394 else if (!navigation_state->request_committed())
3395 extra_data->set_lofi_state(lofi_state);
3396 else
3397 extra_data->set_lofi_state(is_using_lofi_ ? LOFI_ON : LOFI_OFF);
mmenke 2015/09/30 19:33:41 We should have tests for each of these cases.
megjablon 2015/09/30 22:14:08 I'm unfamiliar with the test infrastructure in con
3378 request.setExtraData(extra_data); 3398 request.setExtraData(extra_data);
3379 3399
3380 // TODO(creis): Update prefetching to work with out-of-process iframes. 3400 // TODO(creis): Update prefetching to work with out-of-process iframes.
3381 WebFrame* top_frame = frame->top(); 3401 WebFrame* top_frame = frame->top();
3382 if (top_frame && top_frame->isWebLocalFrame()) { 3402 if (top_frame && top_frame->isWebLocalFrame()) {
3383 DocumentState* top_document_state = 3403 DocumentState* top_document_state =
3384 DocumentState::FromDataSource(top_frame->dataSource()); 3404 DocumentState::FromDataSource(top_frame->dataSource());
3385 if (top_document_state) { 3405 if (top_document_state) {
3386 // TODO(gavinp): separate out prefetching and prerender field trials 3406 // TODO(gavinp): separate out prefetching and prerender field trials
3387 // if the rel=prerender rel type is sticking around. 3407 // if the rel=prerender rel type is sticking around.
(...skipping 1785 matching lines...) Expand 10 before | Expand all | Expand 10 after
5173 mojo::ServiceProviderPtr service_provider; 5193 mojo::ServiceProviderPtr service_provider;
5174 mojo::URLRequestPtr request(mojo::URLRequest::New()); 5194 mojo::URLRequestPtr request(mojo::URLRequest::New());
5175 request->url = mojo::String::From(url); 5195 request->url = mojo::String::From(url);
5176 mojo_shell_->ConnectToApplication(request.Pass(), GetProxy(&service_provider), 5196 mojo_shell_->ConnectToApplication(request.Pass(), GetProxy(&service_provider),
5177 nullptr, nullptr, 5197 nullptr, nullptr,
5178 base::Bind(&OnGotContentHandlerID)); 5198 base::Bind(&OnGotContentHandlerID));
5179 return service_provider.Pass(); 5199 return service_provider.Pass();
5180 } 5200 }
5181 5201
5182 } // namespace content 5202 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698