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 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 WebString web_referrer = WebSecurityPolicy::generateReferrerHeader( | 417 WebString web_referrer = WebSecurityPolicy::generateReferrerHeader( |
418 common_params.referrer.policy, | 418 common_params.referrer.policy, |
419 common_params.url, | 419 common_params.url, |
420 WebString::fromUTF8(common_params.referrer.url.spec())); | 420 WebString::fromUTF8(common_params.referrer.url.spec())); |
421 if (!web_referrer.isEmpty()) | 421 if (!web_referrer.isEmpty()) |
422 request.setHTTPReferrer(web_referrer, common_params.referrer.policy); | 422 request.setHTTPReferrer(web_referrer, common_params.referrer.policy); |
423 } | 423 } |
424 | 424 |
425 RequestExtraData* extra_data = new RequestExtraData(); | 425 RequestExtraData* extra_data = new RequestExtraData(); |
426 extra_data->set_stream_override(stream_override.Pass()); | 426 extra_data->set_stream_override(stream_override.Pass()); |
| 427 extra_data->set_lofi_state(common_params.lofi_state); |
427 request.setExtraData(extra_data); | 428 request.setExtraData(extra_data); |
428 | 429 |
429 // Set the ui timestamp for this navigation. Currently the timestamp here is | 430 // Set the ui timestamp for this navigation. Currently the timestamp here is |
430 // only non empty when the navigation was triggered by an Android intent. The | 431 // only non empty when the navigation was triggered by an Android intent. The |
431 // timestamp is converted to a double version supported by blink. It will be | 432 // timestamp is converted to a double version supported by blink. It will be |
432 // passed back to the browser in the DidCommitProvisionalLoad and the | 433 // passed back to the browser in the DidCommitProvisionalLoad and the |
433 // DocumentLoadComplete IPCs. | 434 // DocumentLoadComplete IPCs. |
434 base::TimeDelta ui_timestamp = common_params.ui_timestamp - base::TimeTicks(); | 435 base::TimeDelta ui_timestamp = common_params.ui_timestamp - base::TimeTicks(); |
435 request.setUiStartTime(ui_timestamp.InSecondsF()); | 436 request.setUiStartTime(ui_timestamp.InSecondsF()); |
436 request.setInputPerfMetricReportPolicy( | 437 request.setInputPerfMetricReportPolicy( |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 #endif | 712 #endif |
712 has_played_media_(false), | 713 has_played_media_(false), |
713 devtools_agent_(nullptr), | 714 devtools_agent_(nullptr), |
714 geolocation_dispatcher_(NULL), | 715 geolocation_dispatcher_(NULL), |
715 push_messaging_dispatcher_(NULL), | 716 push_messaging_dispatcher_(NULL), |
716 presentation_dispatcher_(NULL), | 717 presentation_dispatcher_(NULL), |
717 screen_orientation_dispatcher_(NULL), | 718 screen_orientation_dispatcher_(NULL), |
718 manifest_manager_(NULL), | 719 manifest_manager_(NULL), |
719 accessibility_mode_(AccessibilityModeOff), | 720 accessibility_mode_(AccessibilityModeOff), |
720 renderer_accessibility_(NULL), | 721 renderer_accessibility_(NULL), |
| 722 is_lofi_(false), |
721 weak_factory_(this) { | 723 weak_factory_(this) { |
722 std::pair<RoutingIDFrameMap::iterator, bool> result = | 724 std::pair<RoutingIDFrameMap::iterator, bool> result = |
723 g_routing_id_frame_map.Get().insert(std::make_pair(routing_id_, this)); | 725 g_routing_id_frame_map.Get().insert(std::make_pair(routing_id_, this)); |
724 CHECK(result.second) << "Inserting a duplicate item."; | 726 CHECK(result.second) << "Inserting a duplicate item."; |
725 | 727 |
726 RenderThread::Get()->AddRoute(routing_id_, this); | 728 RenderThread::Get()->AddRoute(routing_id_, this); |
727 | 729 |
728 render_view_->RegisterRenderFrame(this); | 730 render_view_->RegisterRenderFrame(this); |
729 | 731 |
730 // Everything below subclasses RenderFrameObserver and is automatically | 732 // Everything below subclasses RenderFrameObserver and is automatically |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 void RenderFrameImpl::SetWebFrame(blink::WebLocalFrame* web_frame) { | 783 void RenderFrameImpl::SetWebFrame(blink::WebLocalFrame* web_frame) { |
782 DCHECK(!frame_); | 784 DCHECK(!frame_); |
783 | 785 |
784 std::pair<FrameMap::iterator, bool> result = g_frame_map.Get().insert( | 786 std::pair<FrameMap::iterator, bool> result = g_frame_map.Get().insert( |
785 std::make_pair(web_frame, this)); | 787 std::make_pair(web_frame, this)); |
786 CHECK(result.second) << "Inserting a duplicate item."; | 788 CHECK(result.second) << "Inserting a duplicate item."; |
787 | 789 |
788 frame_ = web_frame; | 790 frame_ = web_frame; |
789 } | 791 } |
790 | 792 |
791 void RenderFrameImpl::Initialize() { | 793 void RenderFrameImpl::Initialize(bool is_lofi) { |
792 is_subframe_ = !!frame_->parent(); | 794 is_subframe_ = !!frame_->parent(); |
793 is_local_root_ = !frame_->parent() || frame_->parent()->isWebRemoteFrame(); | 795 is_local_root_ = !frame_->parent() || frame_->parent()->isWebRemoteFrame(); |
| 796 is_lofi_ = is_lofi; |
794 | 797 |
795 #if defined(ENABLE_PLUGINS) | 798 #if defined(ENABLE_PLUGINS) |
796 new PepperBrowserConnection(this); | 799 new PepperBrowserConnection(this); |
797 #endif | 800 #endif |
798 new SharedWorkerRepository(this); | 801 new SharedWorkerRepository(this); |
799 | 802 |
800 if (is_local_root_ && !render_frame_proxy_) { | 803 if (is_local_root_ && !render_frame_proxy_) { |
801 // DevToolsAgent is a RenderFrameObserver, and will destruct itself | 804 // DevToolsAgent is a RenderFrameObserver, and will destruct itself |
802 // when |this| is deleted. | 805 // when |this| is deleted. |
803 devtools_agent_ = new DevToolsAgent(this); | 806 devtools_agent_ = new DevToolsAgent(this); |
(...skipping 1184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1988 ServiceRegistryJsWrapper::kModuleName, | 1991 ServiceRegistryJsWrapper::kModuleName, |
1989 ServiceRegistryJsWrapper::Create(isolate, &service_registry_).ToV8()); | 1992 ServiceRegistryJsWrapper::Create(isolate, &service_registry_).ToV8()); |
1990 } | 1993 } |
1991 | 1994 |
1992 void RenderFrameImpl::AddMessageToConsole(ConsoleMessageLevel level, | 1995 void RenderFrameImpl::AddMessageToConsole(ConsoleMessageLevel level, |
1993 const std::string& message) { | 1996 const std::string& message) { |
1994 if (devtools_agent_) | 1997 if (devtools_agent_) |
1995 devtools_agent_->AddMessageToConsole(level, message); | 1998 devtools_agent_->AddMessageToConsole(level, message); |
1996 } | 1999 } |
1997 | 2000 |
| 2001 bool RenderFrameImpl::IsLoFiOn() { |
| 2002 return is_lofi_; |
| 2003 } |
| 2004 |
1998 // blink::WebFrameClient implementation ---------------------------------------- | 2005 // blink::WebFrameClient implementation ---------------------------------------- |
1999 | 2006 |
2000 blink::WebPlugin* RenderFrameImpl::createPlugin( | 2007 blink::WebPlugin* RenderFrameImpl::createPlugin( |
2001 blink::WebLocalFrame* frame, | 2008 blink::WebLocalFrame* frame, |
2002 const blink::WebPluginParams& params) { | 2009 const blink::WebPluginParams& params) { |
2003 DCHECK_EQ(frame_, frame); | 2010 DCHECK_EQ(frame_, frame); |
2004 blink::WebPlugin* plugin = NULL; | 2011 blink::WebPlugin* plugin = NULL; |
2005 if (GetContentClient()->renderer()->OverrideCreatePlugin( | 2012 if (GetContentClient()->renderer()->OverrideCreatePlugin( |
2006 this, frame, params, &plugin)) { | 2013 this, frame, params, &plugin)) { |
2007 return plugin; | 2014 return plugin; |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2207 | 2214 |
2208 // Create the RenderFrame and WebLocalFrame, linking the two. | 2215 // Create the RenderFrame and WebLocalFrame, linking the two. |
2209 RenderFrameImpl* child_render_frame = RenderFrameImpl::Create( | 2216 RenderFrameImpl* child_render_frame = RenderFrameImpl::Create( |
2210 render_view_.get(), child_routing_id); | 2217 render_view_.get(), child_routing_id); |
2211 blink::WebLocalFrame* web_frame = | 2218 blink::WebLocalFrame* web_frame = |
2212 WebLocalFrame::create(scope, child_render_frame); | 2219 WebLocalFrame::create(scope, child_render_frame); |
2213 child_render_frame->SetWebFrame(web_frame); | 2220 child_render_frame->SetWebFrame(web_frame); |
2214 | 2221 |
2215 // Add the frame to the frame tree and initialize it. | 2222 // Add the frame to the frame tree and initialize it. |
2216 parent->appendChild(web_frame); | 2223 parent->appendChild(web_frame); |
2217 child_render_frame->Initialize(); | 2224 child_render_frame->Initialize(is_lofi_); |
2218 | 2225 |
2219 return web_frame; | 2226 return web_frame; |
2220 } | 2227 } |
2221 | 2228 |
2222 void RenderFrameImpl::didChangeOpener(blink::WebFrame* opener) { | 2229 void RenderFrameImpl::didChangeOpener(blink::WebFrame* opener) { |
2223 // Only active frames are able to disown their opener. | 2230 // Only active frames are able to disown their opener. |
2224 if (!opener && is_swapped_out_) | 2231 if (!opener && is_swapped_out_) |
2225 return; | 2232 return; |
2226 | 2233 |
2227 // Only a local frame should be able to update another frame's opener. | 2234 // 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 Loading... |
2679 const blink::WebHistoryItem& item, | 2686 const blink::WebHistoryItem& item, |
2680 blink::WebHistoryCommitType commit_type) { | 2687 blink::WebHistoryCommitType commit_type) { |
2681 TRACE_EVENT2("navigation", "RenderFrameImpl::didCommitProvisionalLoad", | 2688 TRACE_EVENT2("navigation", "RenderFrameImpl::didCommitProvisionalLoad", |
2682 "id", routing_id_, | 2689 "id", routing_id_, |
2683 "url", GetLoadingUrl().possibly_invalid_spec()); | 2690 "url", GetLoadingUrl().possibly_invalid_spec()); |
2684 DCHECK(!frame_ || frame_ == frame); | 2691 DCHECK(!frame_ || frame_ == frame); |
2685 DocumentState* document_state = | 2692 DocumentState* document_state = |
2686 DocumentState::FromDataSource(frame->dataSource()); | 2693 DocumentState::FromDataSource(frame->dataSource()); |
2687 NavigationStateImpl* navigation_state = | 2694 NavigationStateImpl* navigation_state = |
2688 static_cast<NavigationStateImpl*>(document_state->navigation_state()); | 2695 static_cast<NavigationStateImpl*>(document_state->navigation_state()); |
| 2696 WebURLResponseExtraDataImpl* extra_data = GetExtraDataFromResponse( |
| 2697 frame->dataSource()->response()); |
| 2698 is_lofi_ = extra_data && extra_data->is_lofi(); |
2689 | 2699 |
2690 if (proxy_routing_id_ != MSG_ROUTING_NONE) { | 2700 if (proxy_routing_id_ != MSG_ROUTING_NONE) { |
2691 RenderFrameProxy* proxy = | 2701 RenderFrameProxy* proxy = |
2692 RenderFrameProxy::FromRoutingID(proxy_routing_id_); | 2702 RenderFrameProxy::FromRoutingID(proxy_routing_id_); |
2693 CHECK(proxy); | 2703 CHECK(proxy); |
2694 proxy->web_frame()->swap(frame_); | 2704 proxy->web_frame()->swap(frame_); |
2695 proxy_routing_id_ = MSG_ROUTING_NONE; | 2705 proxy_routing_id_ = MSG_ROUTING_NONE; |
2696 | 2706 |
2697 // If this is the main frame going from a remote frame to a local frame, | 2707 // If this is the main frame going from a remote frame to a local frame, |
2698 // it needs to set RenderViewImpl's pointer for the main frame to itself | 2708 // 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 Loading... |
3235 | 3245 |
3236 // The request's extra data may indicate that we should set a custom user | 3246 // The request's extra data may indicate that we should set a custom user |
3237 // agent. This needs to be done here, after WebKit is through with setting the | 3247 // agent. This needs to be done here, after WebKit is through with setting the |
3238 // user agent on its own. Similarly, it may indicate that we should set an | 3248 // user agent on its own. Similarly, it may indicate that we should set an |
3239 // X-Requested-With header. This must be done here to avoid breaking CORS | 3249 // X-Requested-With header. This must be done here to avoid breaking CORS |
3240 // checks. | 3250 // checks. |
3241 // PlzNavigate: there may also be a stream url associated with the request. | 3251 // PlzNavigate: there may also be a stream url associated with the request. |
3242 WebString custom_user_agent; | 3252 WebString custom_user_agent; |
3243 WebString requested_with; | 3253 WebString requested_with; |
3244 scoped_ptr<StreamOverrideParameters> stream_override; | 3254 scoped_ptr<StreamOverrideParameters> stream_override; |
| 3255 LoFiState lofi_state = LOFI_DEFAULT; |
3245 if (request.extraData()) { | 3256 if (request.extraData()) { |
3246 RequestExtraData* old_extra_data = | 3257 RequestExtraData* old_extra_data = |
3247 static_cast<RequestExtraData*>(request.extraData()); | 3258 static_cast<RequestExtraData*>(request.extraData()); |
3248 | 3259 |
3249 custom_user_agent = old_extra_data->custom_user_agent(); | 3260 custom_user_agent = old_extra_data->custom_user_agent(); |
3250 if (!custom_user_agent.isNull()) { | 3261 if (!custom_user_agent.isNull()) { |
3251 if (custom_user_agent.isEmpty()) | 3262 if (custom_user_agent.isEmpty()) |
3252 request.clearHTTPHeaderField("User-Agent"); | 3263 request.clearHTTPHeaderField("User-Agent"); |
3253 else | 3264 else |
3254 request.setHTTPHeaderField("User-Agent", custom_user_agent); | 3265 request.setHTTPHeaderField("User-Agent", custom_user_agent); |
3255 } | 3266 } |
3256 | 3267 |
3257 requested_with = old_extra_data->requested_with(); | 3268 requested_with = old_extra_data->requested_with(); |
3258 if (!requested_with.isNull()) { | 3269 if (!requested_with.isNull()) { |
3259 if (requested_with.isEmpty()) | 3270 if (requested_with.isEmpty()) |
3260 request.clearHTTPHeaderField("X-Requested-With"); | 3271 request.clearHTTPHeaderField("X-Requested-With"); |
3261 else | 3272 else |
3262 request.setHTTPHeaderField("X-Requested-With", requested_with); | 3273 request.setHTTPHeaderField("X-Requested-With", requested_with); |
3263 } | 3274 } |
3264 stream_override = old_extra_data->TakeStreamOverrideOwnership(); | 3275 stream_override = old_extra_data->TakeStreamOverrideOwnership(); |
| 3276 lofi_state = old_extra_data->lofi_state(); |
3265 } | 3277 } |
3266 | 3278 |
3267 // Add the default accept header for frame request if it has not been set | 3279 // Add the default accept header for frame request if it has not been set |
3268 // already. | 3280 // already. |
3269 if ((request.frameType() == blink::WebURLRequest::FrameTypeTopLevel || | 3281 if ((request.frameType() == blink::WebURLRequest::FrameTypeTopLevel || |
3270 request.frameType() == blink::WebURLRequest::FrameTypeNested) && | 3282 request.frameType() == blink::WebURLRequest::FrameTypeNested) && |
3271 request.httpHeaderField(WebString::fromUTF8(kAcceptHeader)).isEmpty()) { | 3283 request.httpHeaderField(WebString::fromUTF8(kAcceptHeader)).isEmpty()) { |
3272 request.setHTTPHeaderField(WebString::fromUTF8(kAcceptHeader), | 3284 request.setHTTPHeaderField(WebString::fromUTF8(kAcceptHeader), |
3273 WebString::fromUTF8(kDefaultAcceptHeader)); | 3285 WebString::fromUTF8(kDefaultAcceptHeader)); |
3274 } | 3286 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3338 extra_data->set_allow_download( | 3350 extra_data->set_allow_download( |
3339 navigation_state->common_params().allow_download); | 3351 navigation_state->common_params().allow_download); |
3340 extra_data->set_transition_type(transition_type); | 3352 extra_data->set_transition_type(transition_type); |
3341 extra_data->set_should_replace_current_entry(should_replace_current_entry); | 3353 extra_data->set_should_replace_current_entry(should_replace_current_entry); |
3342 extra_data->set_transferred_request_child_id( | 3354 extra_data->set_transferred_request_child_id( |
3343 navigation_state->start_params().transferred_request_child_id); | 3355 navigation_state->start_params().transferred_request_child_id); |
3344 extra_data->set_transferred_request_request_id( | 3356 extra_data->set_transferred_request_request_id( |
3345 navigation_state->start_params().transferred_request_request_id); | 3357 navigation_state->start_params().transferred_request_request_id); |
3346 extra_data->set_service_worker_provider_id(provider_id); | 3358 extra_data->set_service_worker_provider_id(provider_id); |
3347 extra_data->set_stream_override(stream_override.Pass()); | 3359 extra_data->set_stream_override(stream_override.Pass()); |
| 3360 // TODO(megjablon): Set the navigation params for single image loads to |
| 3361 // LOFI_OFF and remove the dependency on ReloadBypassingCache. |
| 3362 if (request.cachePolicy() == WebURLRequest::ReloadBypassingCache) |
| 3363 extra_data->set_lofi_state(LOFI_OFF); |
| 3364 else if (!navigation_state->request_committed()) |
| 3365 extra_data->set_lofi_state(lofi_state); |
| 3366 else |
| 3367 extra_data->set_lofi_state(is_lofi_ ? LOFI_ON : LOFI_OFF); |
3348 request.setExtraData(extra_data); | 3368 request.setExtraData(extra_data); |
3349 | 3369 |
3350 // TODO(creis): Update prefetching to work with out-of-process iframes. | 3370 // TODO(creis): Update prefetching to work with out-of-process iframes. |
3351 WebFrame* top_frame = frame->top(); | 3371 WebFrame* top_frame = frame->top(); |
3352 if (top_frame && top_frame->isWebLocalFrame()) { | 3372 if (top_frame && top_frame->isWebLocalFrame()) { |
3353 DocumentState* top_document_state = | 3373 DocumentState* top_document_state = |
3354 DocumentState::FromDataSource(top_frame->dataSource()); | 3374 DocumentState::FromDataSource(top_frame->dataSource()); |
3355 if (top_document_state) { | 3375 if (top_document_state) { |
3356 // TODO(gavinp): separate out prefetching and prerender field trials | 3376 // TODO(gavinp): separate out prefetching and prerender field trials |
3357 // if the rel=prerender rel type is sticking around. | 3377 // if the rel=prerender rel type is sticking around. |
(...skipping 1747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5105 mojo::ServiceProviderPtr service_provider; | 5125 mojo::ServiceProviderPtr service_provider; |
5106 mojo::URLRequestPtr request(mojo::URLRequest::New()); | 5126 mojo::URLRequestPtr request(mojo::URLRequest::New()); |
5107 request->url = mojo::String::From(url); | 5127 request->url = mojo::String::From(url); |
5108 mojo_shell_->ConnectToApplication(request.Pass(), GetProxy(&service_provider), | 5128 mojo_shell_->ConnectToApplication(request.Pass(), GetProxy(&service_provider), |
5109 nullptr, nullptr, | 5129 nullptr, nullptr, |
5110 base::Bind(&OnGotContentHandlerID)); | 5130 base::Bind(&OnGotContentHandlerID)); |
5111 return service_provider.Pass(); | 5131 return service_provider.Pass(); |
5112 } | 5132 } |
5113 | 5133 |
5114 } // namespace content | 5134 } // namespace content |
OLD | NEW |