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

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

Issue 2356093002: Move navigation specific logic in wilSendRequest to a separate method
Patch Set: Created 4 years, 3 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 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 3943 matching lines...) Expand 10 before | Expand all | Expand 10 after
3954 3954
3955 void RenderFrameImpl::saveImageFromDataURL(const blink::WebString& data_url) { 3955 void RenderFrameImpl::saveImageFromDataURL(const blink::WebString& data_url) {
3956 // Note: We should basically send GURL but we use size-limited string instead 3956 // Note: We should basically send GURL but we use size-limited string instead
3957 // in order to send a larger data url to save a image for <canvas> or <img>. 3957 // in order to send a larger data url to save a image for <canvas> or <img>.
3958 if (data_url.length() < kMaxLengthOfDataURLString) { 3958 if (data_url.length() < kMaxLengthOfDataURLString) {
3959 Send(new FrameHostMsg_SaveImageFromDataURL( 3959 Send(new FrameHostMsg_SaveImageFromDataURL(
3960 render_view_->GetRoutingID(), routing_id_, data_url.utf8())); 3960 render_view_->GetRoutingID(), routing_id_, data_url.utf8()));
3961 } 3961 }
3962 } 3962 }
3963 3963
3964 void RenderFrameImpl::willSendRequest(blink::WebLocalFrame* frame, 3964 // Navigation specific logic belonging in willSendRequest.
3965 blink::WebURLRequest& request) { 3965 void RenderFrameImpl::WillSendNavigationRequest(
3966 DCHECK_EQ(frame_, frame); 3966 blink::WebLocalFrame* frame,
3967 // The request my be empty during tests. 3967 blink::WebURLRequest& request,
3968 if (request.url().isEmpty()) 3968 blink::WebDataSource* data_source,
3969 return; 3969 RequestExtraData* new_extra_data) {
3970
3971 // Set the first party for cookies url if it has not been set yet (new 3970 // Set the first party for cookies url if it has not been set yet (new
3972 // requests). This value will be updated during redirects, consistent with 3971 // requests). This value will be updated during redirects, consistent with
3973 // https://tools.ietf.org/html/draft-west-first-party-cookies-04#section-2.1.1 3972 // https://tools.ietf.org/html/draft-west-first-party-cookies-04#section-2.1.1
3974 if (request.firstPartyForCookies().isEmpty()) { 3973 if (request.firstPartyForCookies().isEmpty()) {
3975 if (request.getFrameType() == blink::WebURLRequest::FrameTypeTopLevel) 3974 if (request.getFrameType() == blink::WebURLRequest::FrameTypeTopLevel)
3976 request.setFirstPartyForCookies(request.url()); 3975 request.setFirstPartyForCookies(request.url());
3977 else 3976 else
3978 request.setFirstPartyForCookies(frame->document().firstPartyForCookies()); 3977 request.setFirstPartyForCookies(frame->document().firstPartyForCookies());
3979 } 3978 }
3980 3979
3981 // Set the requestor origin to the same origin as the frame's document if it 3980 // Set the requestor origin to the same origin as the frame's document if it
3982 // hasn't yet been set. 3981 // hasn't yet been set.
3983 // 3982 //
3984 // TODO(mkwst): It would be cleaner to adjust blink::ResourceRequest to 3983 // TODO(mkwst): It would be cleaner to adjust blink::ResourceRequest to
3985 // initialize itself with a `nullptr` initiator so that this can be a simple 3984 // initialize itself with a `nullptr` initiator so that this can be a simple
3986 // `isNull()` check. https://crbug.com/625969 3985 // `isNull()` check. https://crbug.com/625969
3987 if (request.requestorOrigin().isUnique() && 3986 if (request.requestorOrigin().isUnique() &&
3988 !frame->document().getSecurityOrigin().isUnique()) { 3987 !frame->document().getSecurityOrigin().isUnique()) {
3989 request.setRequestorOrigin(frame->document().getSecurityOrigin()); 3988 request.setRequestorOrigin(frame->document().getSecurityOrigin());
3990 } 3989 }
3991 3990
3991 std::unique_ptr<StreamOverrideParameters> stream_override;
3992 if (request.getExtraData()) {
3993 stream_override = static_cast<RequestExtraData*>(request.getExtraData())
3994 ->TakeStreamOverrideOwnership();
3995 }
3996
3997 // Add an empty HTTP origin header for non GET methods if none is currently
3998 // present.
3999 request.addHTTPOriginIfNeeded(WebString());
4000
4001 // Attach |should_replace_current_entry| state to requests so that, should
4002 // this navigation later require a request transfer, all state is preserved
4003 // when it is re-created in the new process.
4004 new_extra_data->set_should_replace_current_entry(
4005 data_source->replacesCurrentHistoryItem());
4006
4007 DCHECK(stream_override || !IsBrowserSideNavigationEnabled());
4008 new_extra_data->set_stream_override(std::move(stream_override));
4009 }
4010
4011 void RenderFrameImpl::willSendRequest(blink::WebLocalFrame* frame,
4012 blink::WebURLRequest& request) {
4013 DCHECK_EQ(frame_, frame);
4014 // The request my be empty during tests.
4015 if (request.url().isEmpty())
4016 return;
4017
3992 WebDataSource* provisional_data_source = frame->provisionalDataSource(); 4018 WebDataSource* provisional_data_source = frame->provisionalDataSource();
3993 WebDataSource* data_source = 4019 WebDataSource* data_source =
3994 provisional_data_source ? provisional_data_source : frame->dataSource(); 4020 provisional_data_source ? provisional_data_source : frame->dataSource();
3995 4021
3996 DocumentState* document_state = DocumentState::FromDataSource(data_source); 4022 DocumentState* document_state = DocumentState::FromDataSource(data_source);
3997 DCHECK(document_state); 4023 DCHECK(document_state);
4024
3998 InternalDocumentStateData* internal_data = 4025 InternalDocumentStateData* internal_data =
3999 InternalDocumentStateData::FromDocumentState(document_state); 4026 InternalDocumentStateData::FromDocumentState(document_state);
4027 if (internal_data->is_cache_policy_override_set())
4028 request.setCachePolicy(internal_data->cache_policy_override());
4029
4000 NavigationStateImpl* navigation_state = 4030 NavigationStateImpl* navigation_state =
4001 static_cast<NavigationStateImpl*>(document_state->navigation_state()); 4031 static_cast<NavigationStateImpl*>(document_state->navigation_state());
4002 ui::PageTransition transition_type = navigation_state->GetTransitionType(); 4032 ui::PageTransition transition_type = navigation_state->GetTransitionType();
4003 if (provisional_data_source && provisional_data_source->isClientRedirect()) { 4033 if (provisional_data_source && provisional_data_source->isClientRedirect()) {
4004 transition_type = ui::PageTransitionFromInt( 4034 transition_type = ui::PageTransitionFromInt(
4005 transition_type | ui::PAGE_TRANSITION_CLIENT_REDIRECT); 4035 transition_type | ui::PAGE_TRANSITION_CLIENT_REDIRECT);
4006 } 4036 }
4007 4037
4008 GURL request_url(request.url()); 4038 GURL request_url(request.url());
4009 GURL new_url; 4039 GURL new_url;
4010 if (GetContentClient()->renderer()->WillSendRequest( 4040 if (GetContentClient()->renderer()->WillSendRequest(
4011 frame, 4041 frame,
4012 transition_type, 4042 transition_type,
4013 request_url, 4043 request_url,
4014 request.firstPartyForCookies(), 4044 request.firstPartyForCookies(),
4015 &new_url)) { 4045 &new_url)) {
4016 request.setURL(WebURL(new_url)); 4046 request.setURL(WebURL(new_url));
4017 } 4047 }
4018 4048
4019 if (internal_data->is_cache_policy_override_set())
4020 request.setCachePolicy(internal_data->cache_policy_override());
4021
4022 // The request's extra data may indicate that we should set a custom user 4049 // The request's extra data may indicate that we should set a custom user
4023 // agent. This needs to be done here, after WebKit is through with setting the 4050 // agent. This needs to be done here, after WebKit is through with setting the
4024 // user agent on its own. Similarly, it may indicate that we should set an 4051 // user agent on its own. Similarly, it may indicate that we should set an
4025 // X-Requested-With header. This must be done here to avoid breaking CORS 4052 // X-Requested-With header. This must be done here to avoid breaking CORS
4026 // checks. 4053 // checks.
4027 // PlzNavigate: there may also be a stream url associated with the request. 4054 // This is used by pepper.
4028 WebString custom_user_agent; 4055 WebString custom_user_agent;
4029 WebString requested_with; 4056 WebString requested_with;
4030 std::unique_ptr<StreamOverrideParameters> stream_override;
4031 if (request.getExtraData()) { 4057 if (request.getExtraData()) {
4032 RequestExtraData* old_extra_data = 4058 RequestExtraData* old_extra_data =
4033 static_cast<RequestExtraData*>(request.getExtraData()); 4059 static_cast<RequestExtraData*>(request.getExtraData());
4034 4060
4035 custom_user_agent = old_extra_data->custom_user_agent(); 4061 custom_user_agent = old_extra_data->custom_user_agent();
4036 if (!custom_user_agent.isNull()) { 4062 if (!custom_user_agent.isNull()) {
4037 if (custom_user_agent.isEmpty()) 4063 if (custom_user_agent.isEmpty())
4038 request.clearHTTPHeaderField("User-Agent"); 4064 request.clearHTTPHeaderField("User-Agent");
4039 else 4065 else
4040 request.setHTTPHeaderField("User-Agent", custom_user_agent); 4066 request.setHTTPHeaderField("User-Agent", custom_user_agent);
4041 } 4067 }
4042 4068
4043 requested_with = old_extra_data->requested_with(); 4069 requested_with = old_extra_data->requested_with();
4044 if (!requested_with.isNull()) { 4070 if (!requested_with.isNull()) {
4045 if (requested_with.isEmpty()) 4071 if (requested_with.isEmpty())
4046 request.clearHTTPHeaderField("X-Requested-With"); 4072 request.clearHTTPHeaderField("X-Requested-With");
4047 else 4073 else
4048 request.setHTTPHeaderField("X-Requested-With", requested_with); 4074 request.setHTTPHeaderField("X-Requested-With", requested_with);
4049 } 4075 }
4050 stream_override = old_extra_data->TakeStreamOverrideOwnership();
4051 } 4076 }
4052 4077
4053 // Add an empty HTTP origin header for non GET methods if none is currently
4054 // present.
4055 request.addHTTPOriginIfNeeded(WebString());
4056
4057 // Attach |should_replace_current_entry| state to requests so that, should
4058 // this navigation later require a request transfer, all state is preserved
4059 // when it is re-created in the new process.
4060 bool should_replace_current_entry = data_source->replacesCurrentHistoryItem();
4061
4062 int provider_id = kInvalidServiceWorkerProviderId; 4078 int provider_id = kInvalidServiceWorkerProviderId;
4063 if (request.getFrameType() == blink::WebURLRequest::FrameTypeTopLevel || 4079 if (request.getFrameType() == blink::WebURLRequest::FrameTypeTopLevel ||
4064 request.getFrameType() == blink::WebURLRequest::FrameTypeNested) { 4080 request.getFrameType() == blink::WebURLRequest::FrameTypeNested) {
4065 // |provisionalDataSource| may be null in some content::ResourceFetcher 4081 // |provisionalDataSource| may be null in some content::ResourceFetcher
4066 // use cases, we don't hook those requests. 4082 // use cases, we don't hook those requests.
4067 if (frame->provisionalDataSource()) { 4083 if (frame->provisionalDataSource()) {
4068 ServiceWorkerNetworkProvider* provider = 4084 ServiceWorkerNetworkProvider* provider =
4069 ServiceWorkerNetworkProvider::FromDocumentState( 4085 ServiceWorkerNetworkProvider::FromDocumentState(
4070 DocumentState::FromDataSource(frame->provisionalDataSource())); 4086 DocumentState::FromDataSource(frame->provisionalDataSource()));
4071 DCHECK(provider); 4087 DCHECK(provider);
4072 provider_id = provider->provider_id(); 4088 provider_id = provider->provider_id();
4073 } 4089 }
4074 } else if (frame->dataSource()) { 4090 } else if (frame->dataSource()) {
4075 ServiceWorkerNetworkProvider* provider = 4091 ServiceWorkerNetworkProvider* provider =
4076 ServiceWorkerNetworkProvider::FromDocumentState( 4092 ServiceWorkerNetworkProvider::FromDocumentState(
4077 DocumentState::FromDataSource(frame->dataSource())); 4093 DocumentState::FromDataSource(frame->dataSource()));
4078 DCHECK(provider); 4094 DCHECK(provider);
4079 provider_id = provider->provider_id(); 4095 provider_id = provider->provider_id();
4080 // Explicitly set the SkipServiceWorker flag here if the renderer process 4096 // Explicitly set the SkipServiceWorker flag here if the renderer process
4081 // hasn't received SetControllerServiceWorker message. 4097 // hasn't received SetControllerServiceWorker message.
4082 if (!provider->IsControlledByServiceWorker() && 4098 if (!provider->IsControlledByServiceWorker() &&
4083 request.skipServiceWorker() != 4099 request.skipServiceWorker() !=
4084 blink::WebURLRequest::SkipServiceWorker::All) 4100 blink::WebURLRequest::SkipServiceWorker::All)
4085 request.setSkipServiceWorker( 4101 request.setSkipServiceWorker(
4086 blink::WebURLRequest::SkipServiceWorker::Controlling); 4102 blink::WebURLRequest::SkipServiceWorker::Controlling);
4087 } 4103 }
4088 4104
4105 RequestExtraData* extra_data = new RequestExtraData();
4106 if (request.getFrameType() != WebURLRequest::FrameTypeNone)
4107 WillSendNavigationRequest(frame, request, data_source, extra_data);
4108
4089 WebFrame* parent = frame->parent(); 4109 WebFrame* parent = frame->parent();
4090 int parent_routing_id = parent ? GetRoutingIdForFrameOrProxy(parent) : -1; 4110 int parent_routing_id = parent ? GetRoutingIdForFrameOrProxy(parent) : -1;
4091 4111
4092 RequestExtraData* extra_data = new RequestExtraData();
4093 extra_data->set_visibility_state(visibilityState()); 4112 extra_data->set_visibility_state(visibilityState());
4094 extra_data->set_custom_user_agent(custom_user_agent); 4113 extra_data->set_custom_user_agent(custom_user_agent);
4095 extra_data->set_requested_with(requested_with); 4114 extra_data->set_requested_with(requested_with);
4096 extra_data->set_render_frame_id(routing_id_); 4115 extra_data->set_render_frame_id(routing_id_);
4097 extra_data->set_is_main_frame(!parent); 4116 extra_data->set_is_main_frame(!parent);
4098 extra_data->set_frame_origin( 4117 extra_data->set_frame_origin(
4099 blink::WebStringToGURL(frame->document().getSecurityOrigin().toString())); 4118 blink::WebStringToGURL(frame->document().getSecurityOrigin().toString()));
4100 extra_data->set_parent_is_main_frame(parent && !parent->parent()); 4119 extra_data->set_parent_is_main_frame(parent && !parent->parent());
4101 extra_data->set_parent_render_frame_id(parent_routing_id); 4120 extra_data->set_parent_render_frame_id(parent_routing_id);
4102 extra_data->set_allow_download( 4121 extra_data->set_allow_download(
4103 navigation_state->common_params().allow_download); 4122 navigation_state->common_params().allow_download);
4104 extra_data->set_transition_type(transition_type); 4123 extra_data->set_transition_type(transition_type);
4105 extra_data->set_should_replace_current_entry(should_replace_current_entry);
4106 extra_data->set_transferred_request_child_id( 4124 extra_data->set_transferred_request_child_id(
4107 navigation_state->start_params().transferred_request_child_id); 4125 navigation_state->start_params().transferred_request_child_id);
4108 extra_data->set_transferred_request_request_id( 4126 extra_data->set_transferred_request_request_id(
4109 navigation_state->start_params().transferred_request_request_id); 4127 navigation_state->start_params().transferred_request_request_id);
4110 extra_data->set_service_worker_provider_id(provider_id); 4128 extra_data->set_service_worker_provider_id(provider_id);
4111 extra_data->set_stream_override(std::move(stream_override));
4112 bool is_prefetch = 4129 bool is_prefetch =
4113 GetContentClient()->renderer()->IsPrefetchOnly(this, request); 4130 GetContentClient()->renderer()->IsPrefetchOnly(this, request);
4114 extra_data->set_is_prefetch(is_prefetch); 4131 extra_data->set_is_prefetch(is_prefetch);
4115 extra_data->set_download_to_network_cache_only( 4132 extra_data->set_download_to_network_cache_only(
4116 is_prefetch && 4133 is_prefetch &&
4117 WebURLRequestToResourceType(request) != RESOURCE_TYPE_MAIN_FRAME); 4134 WebURLRequestToResourceType(request) != RESOURCE_TYPE_MAIN_FRAME);
4118 WebString error; 4135 WebString error;
4119 extra_data->set_initiated_in_secure_context( 4136 extra_data->set_initiated_in_secure_context(
4120 frame->document().isSecureContext(error)); 4137 frame->document().isSecureContext(error));
4138
4121 request.setExtraData(extra_data); 4139 request.setExtraData(extra_data);
4122 4140
4123 if (request.getLoFiState() == WebURLRequest::LoFiUnspecified) { 4141 if (request.getLoFiState() == WebURLRequest::LoFiUnspecified) {
4124 if (is_main_frame_ && !navigation_state->request_committed()) { 4142 if (is_main_frame_ && !navigation_state->request_committed()) {
4125 request.setLoFiState(static_cast<WebURLRequest::LoFiState>( 4143 request.setLoFiState(static_cast<WebURLRequest::LoFiState>(
4126 navigation_state->common_params().lofi_state)); 4144 navigation_state->common_params().lofi_state));
4127 } else { 4145 } else {
4128 request.setLoFiState( 4146 request.setLoFiState(
4129 is_using_lofi_ ? WebURLRequest::LoFiOn : WebURLRequest::LoFiOff); 4147 is_using_lofi_ ? WebURLRequest::LoFiOn : WebURLRequest::LoFiOff);
4130 } 4148 }
(...skipping 2267 matching lines...) Expand 10 before | Expand all | Expand 10 after
6398 // event target. Potentially a Pepper plugin will receive the event. 6416 // event target. Potentially a Pepper plugin will receive the event.
6399 // In order to tell whether a plugin gets the last mouse event and which it 6417 // In order to tell whether a plugin gets the last mouse event and which it
6400 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets 6418 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets
6401 // the event, it will notify us via DidReceiveMouseEvent() and set itself as 6419 // the event, it will notify us via DidReceiveMouseEvent() and set itself as
6402 // |pepper_last_mouse_event_target_|. 6420 // |pepper_last_mouse_event_target_|.
6403 pepper_last_mouse_event_target_ = nullptr; 6421 pepper_last_mouse_event_target_ = nullptr;
6404 #endif 6422 #endif
6405 } 6423 }
6406 6424
6407 } // namespace content 6425 } // 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