Chromium Code Reviews| 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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 #include "third_party/WebKit/public/platform/WebMediaPlayer.h" | 180 #include "third_party/WebKit/public/platform/WebMediaPlayer.h" |
| 181 #include "third_party/WebKit/public/platform/WebMediaPlayerSource.h" | 181 #include "third_party/WebKit/public/platform/WebMediaPlayerSource.h" |
| 182 #include "third_party/WebKit/public/platform/WebPoint.h" | 182 #include "third_party/WebKit/public/platform/WebPoint.h" |
| 183 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 183 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
| 184 #include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h" | 184 #include "third_party/WebKit/public/platform/WebStorageQuotaCallbacks.h" |
| 185 #include "third_party/WebKit/public/platform/WebString.h" | 185 #include "third_party/WebKit/public/platform/WebString.h" |
| 186 #include "third_party/WebKit/public/platform/WebURL.h" | 186 #include "third_party/WebKit/public/platform/WebURL.h" |
| 187 #include "third_party/WebKit/public/platform/WebURLError.h" | 187 #include "third_party/WebKit/public/platform/WebURLError.h" |
| 188 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 188 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
| 189 #include "third_party/WebKit/public/platform/WebVector.h" | 189 #include "third_party/WebKit/public/platform/WebVector.h" |
| 190 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerNetworkProvider.h" | |
| 190 #include "third_party/WebKit/public/platform/scheduler/renderer/renderer_schedul er.h" | 191 #include "third_party/WebKit/public/platform/scheduler/renderer/renderer_schedul er.h" |
| 191 #include "third_party/WebKit/public/web/WebColorSuggestion.h" | 192 #include "third_party/WebKit/public/web/WebColorSuggestion.h" |
| 192 #include "third_party/WebKit/public/web/WebConsoleMessage.h" | 193 #include "third_party/WebKit/public/web/WebConsoleMessage.h" |
| 193 #include "third_party/WebKit/public/web/WebDocument.h" | 194 #include "third_party/WebKit/public/web/WebDocument.h" |
| 194 #include "third_party/WebKit/public/web/WebFindOptions.h" | 195 #include "third_party/WebKit/public/web/WebFindOptions.h" |
| 195 #include "third_party/WebKit/public/web/WebFrameOwnerProperties.h" | 196 #include "third_party/WebKit/public/web/WebFrameOwnerProperties.h" |
| 196 #include "third_party/WebKit/public/web/WebFrameSerializer.h" | 197 #include "third_party/WebKit/public/web/WebFrameSerializer.h" |
| 197 #include "third_party/WebKit/public/web/WebFrameSerializerCacheControlPolicy.h" | 198 #include "third_party/WebKit/public/web/WebFrameSerializerCacheControlPolicy.h" |
| 198 #include "third_party/WebKit/public/web/WebFrameWidget.h" | 199 #include "third_party/WebKit/public/web/WebFrameWidget.h" |
| 199 #include "third_party/WebKit/public/web/WebInputMethodController.h" | 200 #include "third_party/WebKit/public/web/WebInputMethodController.h" |
| (...skipping 2775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2975 return blame_context_.get(); | 2976 return blame_context_.get(); |
| 2976 } | 2977 } |
| 2977 | 2978 |
| 2978 blink::WebServiceWorkerProvider* | 2979 blink::WebServiceWorkerProvider* |
| 2979 RenderFrameImpl::createServiceWorkerProvider() { | 2980 RenderFrameImpl::createServiceWorkerProvider() { |
| 2980 // At this point we should have non-null data source. | 2981 // At this point we should have non-null data source. |
| 2981 DCHECK(frame_->dataSource()); | 2982 DCHECK(frame_->dataSource()); |
| 2982 if (!ChildThreadImpl::current()) | 2983 if (!ChildThreadImpl::current()) |
| 2983 return nullptr; // May be null in some tests. | 2984 return nullptr; // May be null in some tests. |
| 2984 ServiceWorkerNetworkProvider* provider = | 2985 ServiceWorkerNetworkProvider* provider = |
| 2985 ServiceWorkerNetworkProvider::FromDocumentState( | 2986 ServiceWorkerNetworkProvider::GetInwardProviderForNavigation( |
| 2986 DocumentState::FromDataSource(frame_->dataSource())); | 2987 frame_->dataSource()->getServiceWorkerNetworkProvider()); |
| 2987 DCHECK(provider); | |
| 2988 if (!provider->context()) { | 2988 if (!provider->context()) { |
| 2989 // The context can be null when the frame is sandboxed. | 2989 // The context can be null when the frame is sandboxed. |
| 2990 return nullptr; | 2990 return nullptr; |
| 2991 } | 2991 } |
| 2992 return new WebServiceWorkerProviderImpl( | 2992 return new WebServiceWorkerProviderImpl( |
| 2993 ChildThreadImpl::current()->thread_safe_sender(), | 2993 ChildThreadImpl::current()->thread_safe_sender(), provider->context()); |
| 2994 provider->context()); | |
| 2995 } | 2994 } |
| 2996 | 2995 |
| 2997 void RenderFrameImpl::didAccessInitialDocument() { | 2996 void RenderFrameImpl::didAccessInitialDocument() { |
| 2998 DCHECK(!frame_->parent()); | 2997 DCHECK(!frame_->parent()); |
| 2999 // NOTE: Do not call back into JavaScript here, since this call is made from a | 2998 // NOTE: Do not call back into JavaScript here, since this call is made from a |
| 3000 // V8 security check. | 2999 // V8 security check. |
| 3001 | 3000 |
| 3002 // If the request hasn't yet committed, notify the browser process that it is | 3001 // If the request hasn't yet committed, notify the browser process that it is |
| 3003 // no longer safe to show the pending URL of the main frame, since a URL spoof | 3002 // no longer safe to show the pending URL of the main frame, since a URL spoof |
| 3004 // is now possible. (If the request has committed, the browser already knows.) | 3003 // is now possible. (If the request has committed, the browser already knows.) |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3406 redirect_start, redirect_end, fetch_start, | 3405 redirect_start, redirect_end, fetch_start, |
| 3407 !navigation_state->request_params().redirects.empty()); | 3406 !navigation_state->request_params().redirects.empty()); |
| 3408 // TODO(clamy) We need to provide additional timing values for the | 3407 // TODO(clamy) We need to provide additional timing values for the |
| 3409 // Navigation Timing API to work with browser-side navigations. | 3408 // Navigation Timing API to work with browser-side navigations. |
| 3410 // UnloadEventStart and UnloadEventEnd are still missing. | 3409 // UnloadEventStart and UnloadEventEnd are still missing. |
| 3411 } | 3410 } |
| 3412 | 3411 |
| 3413 // Create the serviceworker's per-document network observing object if it | 3412 // Create the serviceworker's per-document network observing object if it |
| 3414 // does not exist (When navigation happens within a page, the provider already | 3413 // does not exist (When navigation happens within a page, the provider already |
| 3415 // exists). | 3414 // exists). |
| 3416 if (ServiceWorkerNetworkProvider::FromDocumentState( | 3415 if (datasource->getServiceWorkerNetworkProvider()) |
| 3417 DocumentState::FromDataSource(datasource))) | |
| 3418 return; | 3416 return; |
| 3419 | 3417 |
| 3420 ServiceWorkerNetworkProvider::AttachToDocumentState( | 3418 datasource->setServiceWorkerNetworkProvider( |
| 3421 DocumentState::FromDataSource(datasource), | |
| 3422 ServiceWorkerNetworkProvider::CreateForNavigation( | 3419 ServiceWorkerNetworkProvider::CreateForNavigation( |
| 3423 routing_id_, navigation_state->request_params(), frame, | 3420 routing_id_, navigation_state->request_params(), frame, |
| 3424 content_initiated)); | 3421 content_initiated)); |
| 3425 } | 3422 } |
| 3426 | 3423 |
| 3427 void RenderFrameImpl::didStartProvisionalLoad( | 3424 void RenderFrameImpl::didStartProvisionalLoad( |
| 3428 blink::WebDataSource* data_source) { | 3425 blink::WebDataSource* data_source) { |
| 3429 // In fast/loader/stop-provisional-loads.html, we abort the load before this | 3426 // In fast/loader/stop-provisional-loads.html, we abort the load before this |
| 3430 // callback is invoked. | 3427 // callback is invoked. |
| 3431 if (!data_source) | 3428 if (!data_source) |
| (...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4268 | 4265 |
| 4269 // Add an empty HTTP origin header for non GET methods if none is currently | 4266 // Add an empty HTTP origin header for non GET methods if none is currently |
| 4270 // present. | 4267 // present. |
| 4271 request.addHTTPOriginIfNeeded(WebSecurityOrigin::createUnique()); | 4268 request.addHTTPOriginIfNeeded(WebSecurityOrigin::createUnique()); |
| 4272 | 4269 |
| 4273 // Attach |should_replace_current_entry| state to requests so that, should | 4270 // Attach |should_replace_current_entry| state to requests so that, should |
| 4274 // this navigation later require a request transfer, all state is preserved | 4271 // this navigation later require a request transfer, all state is preserved |
| 4275 // when it is re-created in the new process. | 4272 // when it is re-created in the new process. |
| 4276 bool should_replace_current_entry = data_source->replacesCurrentHistoryItem(); | 4273 bool should_replace_current_entry = data_source->replacesCurrentHistoryItem(); |
| 4277 | 4274 |
| 4278 int provider_id = kInvalidServiceWorkerProviderId; | |
| 4279 if (request.getFrameType() == blink::WebURLRequest::FrameTypeTopLevel || | |
| 4280 request.getFrameType() == blink::WebURLRequest::FrameTypeNested) { | |
| 4281 // |provisionalDataSource| may be null in some content::ResourceFetcher | |
| 4282 // use cases, we don't hook those requests. | |
| 4283 if (frame->provisionalDataSource()) { | |
| 4284 ServiceWorkerNetworkProvider* provider = | |
| 4285 ServiceWorkerNetworkProvider::FromDocumentState( | |
| 4286 DocumentState::FromDataSource(frame->provisionalDataSource())); | |
| 4287 DCHECK(provider); | |
| 4288 provider_id = provider->provider_id(); | |
| 4289 } | |
| 4290 } else if (frame->dataSource()) { | |
| 4291 ServiceWorkerNetworkProvider* provider = | |
| 4292 ServiceWorkerNetworkProvider::FromDocumentState( | |
| 4293 DocumentState::FromDataSource(frame->dataSource())); | |
| 4294 DCHECK(provider); | |
| 4295 provider_id = provider->provider_id(); | |
| 4296 // If the provider does not have a controller at this point, the renderer | |
| 4297 // expects the request to never be handled by a controlling service worker, | |
| 4298 // so set the ServiceWorkerMode to skip local workers here. Otherwise, a | |
| 4299 // service worker that is in the process of becoming the controller (i.e., | |
| 4300 // via claim()) on the browser-side could handle the request and break | |
| 4301 // the assumptions of the renderer. | |
| 4302 if (!provider->IsControlledByServiceWorker() && | |
| 4303 request.getServiceWorkerMode() != | |
| 4304 blink::WebURLRequest::ServiceWorkerMode::None) { | |
| 4305 request.setServiceWorkerMode( | |
| 4306 blink::WebURLRequest::ServiceWorkerMode::Foreign); | |
| 4307 } | |
| 4308 } | |
| 4309 | |
| 4310 WebFrame* parent = frame->parent(); | 4275 WebFrame* parent = frame->parent(); |
| 4311 int parent_routing_id = parent ? GetRoutingIdForFrameOrProxy(parent) : -1; | 4276 int parent_routing_id = parent ? GetRoutingIdForFrameOrProxy(parent) : -1; |
| 4312 | 4277 |
| 4313 RequestExtraData* extra_data = new RequestExtraData(); | 4278 RequestExtraData* extra_data = new RequestExtraData(); |
| 4314 extra_data->set_visibility_state(visibilityState()); | 4279 extra_data->set_visibility_state(visibilityState()); |
| 4315 extra_data->set_custom_user_agent(custom_user_agent); | 4280 extra_data->set_custom_user_agent(custom_user_agent); |
| 4316 extra_data->set_requested_with(requested_with); | 4281 extra_data->set_requested_with(requested_with); |
| 4317 extra_data->set_render_frame_id(routing_id_); | 4282 extra_data->set_render_frame_id(routing_id_); |
| 4318 extra_data->set_is_main_frame(!parent); | 4283 extra_data->set_is_main_frame(!parent); |
| 4319 extra_data->set_frame_origin( | 4284 extra_data->set_frame_origin( |
| 4320 url::Origin(frame_document.getSecurityOrigin())); | 4285 url::Origin(frame_document.getSecurityOrigin())); |
| 4321 extra_data->set_parent_is_main_frame(parent && !parent->parent()); | 4286 extra_data->set_parent_is_main_frame(parent && !parent->parent()); |
| 4322 extra_data->set_parent_render_frame_id(parent_routing_id); | 4287 extra_data->set_parent_render_frame_id(parent_routing_id); |
| 4323 extra_data->set_allow_download( | 4288 extra_data->set_allow_download( |
| 4324 navigation_state->common_params().allow_download); | 4289 navigation_state->common_params().allow_download); |
| 4325 extra_data->set_transition_type(transition_type); | 4290 extra_data->set_transition_type(transition_type); |
| 4326 extra_data->set_should_replace_current_entry(should_replace_current_entry); | 4291 extra_data->set_should_replace_current_entry(should_replace_current_entry); |
| 4327 extra_data->set_service_worker_provider_id(provider_id); | |
| 4328 extra_data->set_stream_override(std::move(stream_override)); | 4292 extra_data->set_stream_override(std::move(stream_override)); |
| 4329 bool is_prefetch = | 4293 bool is_prefetch = |
| 4330 GetContentClient()->renderer()->IsPrefetchOnly(this, request); | 4294 GetContentClient()->renderer()->IsPrefetchOnly(this, request); |
| 4331 extra_data->set_is_prefetch(is_prefetch); | 4295 extra_data->set_is_prefetch(is_prefetch); |
| 4332 extra_data->set_download_to_network_cache_only( | 4296 extra_data->set_download_to_network_cache_only( |
| 4333 is_prefetch && | 4297 is_prefetch && |
| 4334 WebURLRequestToResourceType(request) != RESOURCE_TYPE_MAIN_FRAME); | 4298 WebURLRequestToResourceType(request) != RESOURCE_TYPE_MAIN_FRAME); |
| 4335 extra_data->set_initiated_in_secure_context( | 4299 extra_data->set_initiated_in_secure_context( |
| 4336 frame_document.isSecureContext()); | 4300 frame_document.isSecureContext()); |
| 4337 | 4301 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 4350 RequestExtraData* current_request_data = static_cast<RequestExtraData*>( | 4314 RequestExtraData* current_request_data = static_cast<RequestExtraData*>( |
| 4351 request.getExtraData()); | 4315 request.getExtraData()); |
| 4352 if (current_request_data) { | 4316 if (current_request_data) { |
| 4353 extra_data->set_navigation_initiated_by_renderer( | 4317 extra_data->set_navigation_initiated_by_renderer( |
| 4354 current_request_data->navigation_initiated_by_renderer()); | 4318 current_request_data->navigation_initiated_by_renderer()); |
| 4355 } | 4319 } |
| 4356 } | 4320 } |
| 4357 | 4321 |
| 4358 request.setExtraData(extra_data); | 4322 request.setExtraData(extra_data); |
| 4359 | 4323 |
| 4324 // Initializes service worker related request info. | |
| 4325 // This must be done after we set extra data. | |
|
falken
2017/03/10 04:26:00
Could you also write (briefly) why the order matte
kinuko
2017/03/10 05:52:28
Revised to make it order-independent.
| |
| 4326 if (request.getFrameType() == blink::WebURLRequest::FrameTypeTopLevel || | |
| 4327 request.getFrameType() == blink::WebURLRequest::FrameTypeNested) { | |
| 4328 // |provisionalDataSource| may be null in some content::ResourceFetcher | |
| 4329 // use cases, we don't hook those requests. | |
| 4330 if (frame->provisionalDataSource()) { | |
| 4331 blink::WebServiceWorkerNetworkProvider* provider = | |
| 4332 frame->provisionalDataSource()->getServiceWorkerNetworkProvider(); | |
| 4333 DCHECK(provider); | |
| 4334 provider->willSendRequest(request); | |
| 4335 } | |
| 4336 } else if (frame->dataSource()) { | |
| 4337 blink::WebServiceWorkerNetworkProvider* provider = | |
| 4338 frame->dataSource()->getServiceWorkerNetworkProvider(); | |
| 4339 DCHECK(provider); | |
| 4340 provider->willSendRequest(request); | |
| 4341 | |
| 4342 // If the provider does not have a controller at this point, the renderer | |
| 4343 // expects the request to never be handled by a controlling service worker, | |
| 4344 // so set the ServiceWorkerMode to skip local workers here. Otherwise, a | |
| 4345 // service worker that is in the process of becoming the controller (i.e., | |
| 4346 // via claim()) on the browser-side could handle the request and break | |
| 4347 // the assumptions of the renderer. | |
| 4348 if (!provider->isControlledByServiceWorker() && | |
| 4349 request.getServiceWorkerMode() != | |
| 4350 blink::WebURLRequest::ServiceWorkerMode::None) { | |
| 4351 request.setServiceWorkerMode( | |
| 4352 blink::WebURLRequest::ServiceWorkerMode::Foreign); | |
| 4353 } | |
| 4354 } | |
| 4355 | |
| 4360 if (request.getPreviewsState() == WebURLRequest::PreviewsUnspecified) { | 4356 if (request.getPreviewsState() == WebURLRequest::PreviewsUnspecified) { |
| 4361 if (is_main_frame_ && !navigation_state->request_committed()) { | 4357 if (is_main_frame_ && !navigation_state->request_committed()) { |
| 4362 request.setPreviewsState(static_cast<WebURLRequest::PreviewsState>( | 4358 request.setPreviewsState(static_cast<WebURLRequest::PreviewsState>( |
| 4363 navigation_state->common_params().previews_state)); | 4359 navigation_state->common_params().previews_state)); |
| 4364 } else { | 4360 } else { |
| 4365 request.setPreviewsState( | 4361 request.setPreviewsState( |
| 4366 previews_state_ == PREVIEWS_UNSPECIFIED | 4362 previews_state_ == PREVIEWS_UNSPECIFIED |
| 4367 ? WebURLRequest::PreviewsOff | 4363 ? WebURLRequest::PreviewsOff |
| 4368 : static_cast<WebURLRequest::PreviewsState>(previews_state_)); | 4364 : static_cast<WebURLRequest::PreviewsState>(previews_state_)); |
| 4369 } | 4365 } |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4649 return !blocked; | 4645 return !blocked; |
| 4650 } | 4646 } |
| 4651 | 4647 |
| 4652 blink::WebScreenOrientationClient* | 4648 blink::WebScreenOrientationClient* |
| 4653 RenderFrameImpl::webScreenOrientationClient() { | 4649 RenderFrameImpl::webScreenOrientationClient() { |
| 4654 if (!screen_orientation_dispatcher_) | 4650 if (!screen_orientation_dispatcher_) |
| 4655 screen_orientation_dispatcher_ = new ScreenOrientationDispatcher(this); | 4651 screen_orientation_dispatcher_ = new ScreenOrientationDispatcher(this); |
| 4656 return screen_orientation_dispatcher_; | 4652 return screen_orientation_dispatcher_; |
| 4657 } | 4653 } |
| 4658 | 4654 |
| 4659 bool RenderFrameImpl::isControlledByServiceWorker(WebDataSource& data_source) { | |
| 4660 ServiceWorkerNetworkProvider* provider = | |
| 4661 ServiceWorkerNetworkProvider::FromDocumentState( | |
| 4662 DocumentState::FromDataSource(&data_source)); | |
| 4663 return provider->IsControlledByServiceWorker(); | |
| 4664 } | |
| 4665 | |
| 4666 int64_t RenderFrameImpl::serviceWorkerID(WebDataSource& data_source) { | |
| 4667 ServiceWorkerNetworkProvider* provider = | |
| 4668 ServiceWorkerNetworkProvider::FromDocumentState( | |
| 4669 DocumentState::FromDataSource(&data_source)); | |
| 4670 if (provider->context() && provider->context()->controller()) | |
| 4671 return provider->context()->controller()->version_id(); | |
| 4672 return kInvalidServiceWorkerVersionId; | |
| 4673 } | |
| 4674 | |
| 4675 void RenderFrameImpl::postAccessibilityEvent(const blink::WebAXObject& obj, | 4655 void RenderFrameImpl::postAccessibilityEvent(const blink::WebAXObject& obj, |
| 4676 blink::WebAXEvent event) { | 4656 blink::WebAXEvent event) { |
| 4677 HandleWebAccessibilityEvent(obj, event); | 4657 HandleWebAccessibilityEvent(obj, event); |
| 4678 } | 4658 } |
| 4679 | 4659 |
| 4680 void RenderFrameImpl::handleAccessibilityFindInPageResult( | 4660 void RenderFrameImpl::handleAccessibilityFindInPageResult( |
| 4681 int identifier, | 4661 int identifier, |
| 4682 int match_index, | 4662 int match_index, |
| 4683 const blink::WebAXObject& start_object, | 4663 const blink::WebAXObject& start_object, |
| 4684 int start_offset, | 4664 int start_offset, |
| (...skipping 2186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6871 // event target. Potentially a Pepper plugin will receive the event. | 6851 // event target. Potentially a Pepper plugin will receive the event. |
| 6872 // In order to tell whether a plugin gets the last mouse event and which it | 6852 // In order to tell whether a plugin gets the last mouse event and which it |
| 6873 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets | 6853 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets |
| 6874 // the event, it will notify us via DidReceiveMouseEvent() and set itself as | 6854 // the event, it will notify us via DidReceiveMouseEvent() and set itself as |
| 6875 // |pepper_last_mouse_event_target_|. | 6855 // |pepper_last_mouse_event_target_|. |
| 6876 pepper_last_mouse_event_target_ = nullptr; | 6856 pepper_last_mouse_event_target_ = nullptr; |
| 6877 #endif | 6857 #endif |
| 6878 } | 6858 } |
| 6879 | 6859 |
| 6880 } // namespace content | 6860 } // namespace content |
| OLD | NEW |