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 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 4127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4138 void RenderFrameImpl::SaveImageFromDataURL(const blink::WebString& data_url) { | 4138 void RenderFrameImpl::SaveImageFromDataURL(const blink::WebString& data_url) { |
4139 // Note: We should basically send GURL but we use size-limited string instead | 4139 // Note: We should basically send GURL but we use size-limited string instead |
4140 // in order to send a larger data url to save a image for <canvas> or <img>. | 4140 // in order to send a larger data url to save a image for <canvas> or <img>. |
4141 if (data_url.length() < kMaxLengthOfDataURLString) { | 4141 if (data_url.length() < kMaxLengthOfDataURLString) { |
4142 Send(new FrameHostMsg_SaveImageFromDataURL(render_view_->GetRoutingID(), | 4142 Send(new FrameHostMsg_SaveImageFromDataURL(render_view_->GetRoutingID(), |
4143 routing_id_, data_url.Utf8())); | 4143 routing_id_, data_url.Utf8())); |
4144 } | 4144 } |
4145 } | 4145 } |
4146 | 4146 |
4147 void RenderFrameImpl::WillSendRequest(blink::WebURLRequest& request) { | 4147 void RenderFrameImpl::WillSendRequest(blink::WebURLRequest& request) { |
4148 // Set the first party for cookies url if it has not been set yet (new | |
4149 // requests). This value will be updated during redirects, consistent with | |
4150 // https://tools.ietf.org/html/draft-west-first-party-cookies-04#section-2.1.1 | |
4151 if (request.FirstPartyForCookies().IsEmpty()) { | |
4152 if (request.GetFrameType() == blink::WebURLRequest::kFrameTypeTopLevel) | |
4153 request.SetFirstPartyForCookies(request.Url()); | |
4154 else | |
4155 request.SetFirstPartyForCookies( | |
4156 frame_->GetDocument().FirstPartyForCookies()); | |
4157 } | |
4158 | |
4159 // Set the requestor origin to the same origin as the frame's document if it | |
4160 // hasn't yet been set. | |
4161 // | |
4162 // TODO(mkwst): It would be cleaner to adjust blink::ResourceRequest to | |
4163 // initialize itself with a `nullptr` initiator so that this can be a simple | |
4164 // `isNull()` check. https://crbug.com/625969 | |
4165 WebDocument frame_document = frame_->GetDocument(); | |
4166 if (request.RequestorOrigin().IsUnique() && | |
4167 !frame_document.GetSecurityOrigin().IsUnique()) { | |
4168 request.SetRequestorOrigin(frame_document.GetSecurityOrigin()); | |
4169 } | |
4170 | |
4171 WebDataSource* provisional_data_source = frame_->ProvisionalDataSource(); | 4148 WebDataSource* provisional_data_source = frame_->ProvisionalDataSource(); |
4172 WebDataSource* data_source = | 4149 WebDataSource* data_source = |
4173 provisional_data_source ? provisional_data_source : frame_->DataSource(); | 4150 provisional_data_source ? provisional_data_source : frame_->DataSource(); |
4174 | 4151 |
4175 DocumentState* document_state = DocumentState::FromDataSource(data_source); | 4152 DocumentState* document_state = DocumentState::FromDataSource(data_source); |
4176 DCHECK(document_state); | 4153 DCHECK(document_state); |
4177 InternalDocumentStateData* internal_data = | 4154 InternalDocumentStateData* internal_data = |
4178 InternalDocumentStateData::FromDocumentState(document_state); | 4155 InternalDocumentStateData::FromDocumentState(document_state); |
4179 NavigationStateImpl* navigation_state = | 4156 NavigationStateImpl* navigation_state = |
4180 static_cast<NavigationStateImpl*>(document_state->navigation_state()); | 4157 static_cast<NavigationStateImpl*>(document_state->navigation_state()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4230 | 4207 |
4231 // Attach |should_replace_current_entry| state to requests so that, should | 4208 // Attach |should_replace_current_entry| state to requests so that, should |
4232 // this navigation later require a request transfer, all state is preserved | 4209 // this navigation later require a request transfer, all state is preserved |
4233 // when it is re-created in the new process. | 4210 // when it is re-created in the new process. |
4234 bool should_replace_current_entry = data_source->ReplacesCurrentHistoryItem(); | 4211 bool should_replace_current_entry = data_source->ReplacesCurrentHistoryItem(); |
4235 | 4212 |
4236 WebFrame* parent = frame_->Parent(); | 4213 WebFrame* parent = frame_->Parent(); |
4237 int parent_routing_id = | 4214 int parent_routing_id = |
4238 parent ? RenderFrame::GetRoutingIdForWebFrame(parent) : -1; | 4215 parent ? RenderFrame::GetRoutingIdForWebFrame(parent) : -1; |
4239 | 4216 |
| 4217 WebDocument frame_document = frame_->GetDocument(); |
4240 RequestExtraData* extra_data = | 4218 RequestExtraData* extra_data = |
4241 static_cast<RequestExtraData*>(request.GetExtraData()); | 4219 static_cast<RequestExtraData*>(request.GetExtraData()); |
4242 if (!extra_data) | 4220 if (!extra_data) |
4243 extra_data = new RequestExtraData(); | 4221 extra_data = new RequestExtraData(); |
4244 extra_data->set_visibility_state(VisibilityState()); | 4222 extra_data->set_visibility_state(VisibilityState()); |
4245 extra_data->set_custom_user_agent(custom_user_agent); | 4223 extra_data->set_custom_user_agent(custom_user_agent); |
4246 extra_data->set_requested_with(requested_with); | 4224 extra_data->set_requested_with(requested_with); |
4247 extra_data->set_render_frame_id(routing_id_); | 4225 extra_data->set_render_frame_id(routing_id_); |
4248 extra_data->set_is_main_frame(!parent); | 4226 extra_data->set_is_main_frame(!parent); |
4249 extra_data->set_frame_origin(url::Origin(frame_document.GetSecurityOrigin())); | 4227 extra_data->set_frame_origin(url::Origin(frame_document.GetSecurityOrigin())); |
(...skipping 1940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6190 if (request_params.should_clear_history_list) { | 6168 if (request_params.should_clear_history_list) { |
6191 CHECK_EQ(-1, render_view_->history_list_offset_); | 6169 CHECK_EQ(-1, render_view_->history_list_offset_); |
6192 CHECK_EQ(0, render_view_->history_list_length_); | 6170 CHECK_EQ(0, render_view_->history_list_length_); |
6193 } | 6171 } |
6194 } | 6172 } |
6195 | 6173 |
6196 void RenderFrameImpl::BeginNavigation(const NavigationPolicyInfo& info) { | 6174 void RenderFrameImpl::BeginNavigation(const NavigationPolicyInfo& info) { |
6197 CHECK(IsBrowserSideNavigationEnabled()); | 6175 CHECK(IsBrowserSideNavigationEnabled()); |
6198 browser_side_navigation_pending_ = true; | 6176 browser_side_navigation_pending_ = true; |
6199 | 6177 |
| 6178 blink::WebURLRequest& request = info.url_request; |
| 6179 |
6200 // Note: At this stage, the goal is to apply all the modifications the | 6180 // Note: At this stage, the goal is to apply all the modifications the |
6201 // renderer wants to make to the request, and then send it to the browser, so | 6181 // renderer wants to make to the request, and then send it to the browser, so |
6202 // that the actual network request can be started. Ideally, all such | 6182 // that the actual network request can be started. Ideally, all such |
6203 // modifications should take place in willSendRequest, and in the | 6183 // modifications should take place in willSendRequest, and in the |
6204 // implementation of willSendRequest for the various InspectorAgents | 6184 // implementation of willSendRequest for the various InspectorAgents |
6205 // (devtools). | 6185 // (devtools). |
6206 // | 6186 // |
6207 // TODO(clamy): Apply devtools override. | 6187 // TODO(clamy): Apply devtools override. |
6208 // TODO(clamy): Make sure that navigation requests are not modified somewhere | 6188 // TODO(clamy): Make sure that navigation requests are not modified somewhere |
6209 // else in blink. | 6189 // else in blink. |
6210 WillSendRequest(info.url_request); | 6190 WillSendRequest(request); |
| 6191 |
| 6192 // Set RequestorInfo and FirstPartyForCookies. |
| 6193 WebDocument frame_document = frame_->GetDocument(); |
| 6194 if (request.GetFrameType() == blink::WebURLRequest::kFrameTypeTopLevel) |
| 6195 request.SetFirstPartyForCookies(request.Url()); |
| 6196 else |
| 6197 request.SetFirstPartyForCookies(frame_document.FirstPartyForCookies()); |
| 6198 request.SetRequestorOrigin(frame_document.GetSecurityOrigin()); |
6211 | 6199 |
6212 // Update the transition type of the request for client side redirects. | 6200 // Update the transition type of the request for client side redirects. |
6213 if (!info.url_request.GetExtraData()) | 6201 if (!info.url_request.GetExtraData()) |
6214 info.url_request.SetExtraData(new RequestExtraData()); | 6202 info.url_request.SetExtraData(new RequestExtraData()); |
6215 if (info.is_client_redirect) { | 6203 if (info.is_client_redirect) { |
6216 RequestExtraData* extra_data = | 6204 RequestExtraData* extra_data = |
6217 static_cast<RequestExtraData*>(info.url_request.GetExtraData()); | 6205 static_cast<RequestExtraData*>(info.url_request.GetExtraData()); |
6218 extra_data->set_transition_type(ui::PageTransitionFromInt( | 6206 extra_data->set_transition_type(ui::PageTransitionFromInt( |
6219 extra_data->transition_type() | ui::PAGE_TRANSITION_CLIENT_REDIRECT)); | 6207 extra_data->transition_type() | ui::PAGE_TRANSITION_CLIENT_REDIRECT)); |
6220 } | 6208 } |
6221 | 6209 |
6222 // TODO(clamy): Same-document navigations should not be sent back to the | 6210 // TODO(clamy): Same-document navigations should not be sent back to the |
6223 // browser. | 6211 // browser. |
6224 // TODO(clamy): Data urls should not be sent back to the browser either. | 6212 // TODO(clamy): Data urls should not be sent back to the browser either. |
6225 // These values are assumed on the browser side for navigations. These checks | 6213 // These values are assumed on the browser side for navigations. These checks |
6226 // ensure the renderer has the correct values. | 6214 // ensure the renderer has the correct values. |
6227 DCHECK_EQ(FETCH_REQUEST_MODE_NAVIGATE, | 6215 DCHECK_EQ(FETCH_REQUEST_MODE_NAVIGATE, |
6228 GetFetchRequestModeForWebURLRequest(info.url_request)); | 6216 GetFetchRequestModeForWebURLRequest(info.url_request)); |
6229 DCHECK_EQ(FETCH_CREDENTIALS_MODE_INCLUDE, | 6217 DCHECK_EQ(FETCH_CREDENTIALS_MODE_INCLUDE, |
6230 GetFetchCredentialsModeForWebURLRequest(info.url_request)); | 6218 GetFetchCredentialsModeForWebURLRequest(info.url_request)); |
6231 DCHECK(GetFetchRedirectModeForWebURLRequest(info.url_request) == | 6219 DCHECK(GetFetchRedirectModeForWebURLRequest(info.url_request) == |
6232 FetchRedirectMode::MANUAL_MODE); | 6220 FetchRedirectMode::MANUAL_MODE); |
6233 DCHECK(frame_->Parent() || | 6221 DCHECK(frame_->Parent() || |
6234 GetRequestContextFrameTypeForWebURLRequest(info.url_request) == | 6222 GetRequestContextFrameTypeForWebURLRequest(info.url_request) == |
6235 REQUEST_CONTEXT_FRAME_TYPE_TOP_LEVEL); | 6223 REQUEST_CONTEXT_FRAME_TYPE_TOP_LEVEL); |
6236 DCHECK(!frame_->Parent() || | 6224 DCHECK(!frame_->Parent() || |
6237 GetRequestContextFrameTypeForWebURLRequest(info.url_request) == | 6225 GetRequestContextFrameTypeForWebURLRequest(info.url_request) == |
6238 REQUEST_CONTEXT_FRAME_TYPE_NESTED); | 6226 REQUEST_CONTEXT_FRAME_TYPE_NESTED); |
6239 | 6227 |
| 6228 DCHECK(!info.url_request.RequestorOrigin().IsNull()); |
6240 base::Optional<url::Origin> initiator_origin = | 6229 base::Optional<url::Origin> initiator_origin = |
6241 info.url_request.RequestorOrigin().IsNull() | 6230 base::Optional<url::Origin>(info.url_request.RequestorOrigin()); |
6242 ? base::Optional<url::Origin>() | |
6243 : base::Optional<url::Origin>(info.url_request.RequestorOrigin()); | |
6244 | 6231 |
6245 int load_flags = GetLoadFlagsForWebURLRequest(info.url_request); | 6232 int load_flags = GetLoadFlagsForWebURLRequest(info.url_request); |
6246 | 6233 |
6247 // Requests initiated via devtools can have caching disabled. | 6234 // Requests initiated via devtools can have caching disabled. |
6248 if (info.is_cache_disabled) { | 6235 if (info.is_cache_disabled) { |
6249 // Turn off all caching related flags and set LOAD_BYPASS_CACHE. | 6236 // Turn off all caching related flags and set LOAD_BYPASS_CACHE. |
6250 load_flags &= ~(net::LOAD_VALIDATE_CACHE | net::LOAD_SKIP_CACHE_VALIDATION | | 6237 load_flags &= ~(net::LOAD_VALIDATE_CACHE | net::LOAD_SKIP_CACHE_VALIDATION | |
6251 net::LOAD_ONLY_FROM_CACHE | net::LOAD_DISABLE_CACHE); | 6238 net::LOAD_ONLY_FROM_CACHE | net::LOAD_DISABLE_CACHE); |
6252 load_flags |= net::LOAD_BYPASS_CACHE; | 6239 load_flags |= net::LOAD_BYPASS_CACHE; |
6253 } | 6240 } |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6764 policy(info.default_policy), | 6751 policy(info.default_policy), |
6765 replaces_current_history_item(info.replaces_current_history_item), | 6752 replaces_current_history_item(info.replaces_current_history_item), |
6766 history_navigation_in_new_child_frame( | 6753 history_navigation_in_new_child_frame( |
6767 info.is_history_navigation_in_new_child_frame), | 6754 info.is_history_navigation_in_new_child_frame), |
6768 client_redirect(info.is_client_redirect), | 6755 client_redirect(info.is_client_redirect), |
6769 cache_disabled(info.is_cache_disabled), | 6756 cache_disabled(info.is_cache_disabled), |
6770 form(info.form), | 6757 form(info.form), |
6771 source_location(info.source_location) {} | 6758 source_location(info.source_location) {} |
6772 | 6759 |
6773 } // namespace content | 6760 } // namespace content |
OLD | NEW |