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

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

Issue 2733283004: Expose WebServiceWorkerNetworkProvider on DataSource (Closed)
Patch Set: addressed comments Created 3 years, 9 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 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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::FromWebServiceWorkerNetworkProvider(
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
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
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; 4275 // Initializes service worker related request info.
4279 if (request.getFrameType() == blink::WebURLRequest::FrameTypeTopLevel || 4276 if (request.getFrameType() == blink::WebURLRequest::FrameTypeTopLevel ||
4280 request.getFrameType() == blink::WebURLRequest::FrameTypeNested) { 4277 request.getFrameType() == blink::WebURLRequest::FrameTypeNested) {
4281 // |provisionalDataSource| may be null in some content::ResourceFetcher 4278 // |provisionalDataSource| may be null in some content::ResourceFetcher
4282 // use cases, we don't hook those requests. 4279 // use cases, we don't hook those requests.
4283 if (frame->provisionalDataSource()) { 4280 if (frame->provisionalDataSource()) {
4284 ServiceWorkerNetworkProvider* provider = 4281 blink::WebServiceWorkerNetworkProvider* provider =
4285 ServiceWorkerNetworkProvider::FromDocumentState( 4282 frame->provisionalDataSource()->getServiceWorkerNetworkProvider();
4286 DocumentState::FromDataSource(frame->provisionalDataSource()));
4287 DCHECK(provider); 4283 DCHECK(provider);
4288 provider_id = provider->provider_id(); 4284 provider->willSendRequest(request);
4289 } 4285 }
4290 } else if (frame->dataSource()) { 4286 } else if (frame->dataSource()) {
4291 ServiceWorkerNetworkProvider* provider = 4287 blink::WebServiceWorkerNetworkProvider* provider =
4292 ServiceWorkerNetworkProvider::FromDocumentState( 4288 frame->dataSource()->getServiceWorkerNetworkProvider();
4293 DocumentState::FromDataSource(frame->dataSource()));
4294 DCHECK(provider); 4289 DCHECK(provider);
4295 provider_id = provider->provider_id(); 4290 provider->willSendRequest(request);
4291
4296 // If the provider does not have a controller at this point, the renderer 4292 // 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, 4293 // expects the request to never be handled by a controlling service worker,
4298 // so set the ServiceWorkerMode to skip local workers here. Otherwise, a 4294 // 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., 4295 // 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 4296 // via claim()) on the browser-side could handle the request and break
4301 // the assumptions of the renderer. 4297 // the assumptions of the renderer.
4302 if (!provider->IsControlledByServiceWorker() && 4298 if (!provider->isControlledByServiceWorker() &&
4303 request.getServiceWorkerMode() != 4299 request.getServiceWorkerMode() !=
4304 blink::WebURLRequest::ServiceWorkerMode::None) { 4300 blink::WebURLRequest::ServiceWorkerMode::None) {
4305 request.setServiceWorkerMode( 4301 request.setServiceWorkerMode(
4306 blink::WebURLRequest::ServiceWorkerMode::Foreign); 4302 blink::WebURLRequest::ServiceWorkerMode::Foreign);
4307 } 4303 }
4308 } 4304 }
4309 4305
4310 WebFrame* parent = frame->parent(); 4306 WebFrame* parent = frame->parent();
4311 int parent_routing_id = parent ? GetRoutingIdForFrameOrProxy(parent) : -1; 4307 int parent_routing_id = parent ? GetRoutingIdForFrameOrProxy(parent) : -1;
4312 4308
4313 RequestExtraData* extra_data = new RequestExtraData(); 4309 RequestExtraData* extra_data =
4310 static_cast<RequestExtraData*>(request.getExtraData());
4311 if (!extra_data)
4312 extra_data = new RequestExtraData();
4313
4314 extra_data->set_visibility_state(visibilityState()); 4314 extra_data->set_visibility_state(visibilityState());
4315 extra_data->set_custom_user_agent(custom_user_agent); 4315 extra_data->set_custom_user_agent(custom_user_agent);
4316 extra_data->set_requested_with(requested_with); 4316 extra_data->set_requested_with(requested_with);
4317 extra_data->set_render_frame_id(routing_id_); 4317 extra_data->set_render_frame_id(routing_id_);
4318 extra_data->set_is_main_frame(!parent); 4318 extra_data->set_is_main_frame(!parent);
4319 extra_data->set_frame_origin( 4319 extra_data->set_frame_origin(
4320 url::Origin(frame_document.getSecurityOrigin())); 4320 url::Origin(frame_document.getSecurityOrigin()));
4321 extra_data->set_parent_is_main_frame(parent && !parent->parent()); 4321 extra_data->set_parent_is_main_frame(parent && !parent->parent());
4322 extra_data->set_parent_render_frame_id(parent_routing_id); 4322 extra_data->set_parent_render_frame_id(parent_routing_id);
4323 extra_data->set_allow_download( 4323 extra_data->set_allow_download(
4324 navigation_state->common_params().allow_download); 4324 navigation_state->common_params().allow_download);
4325 extra_data->set_transition_type(transition_type); 4325 extra_data->set_transition_type(transition_type);
4326 extra_data->set_should_replace_current_entry(should_replace_current_entry); 4326 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)); 4327 extra_data->set_stream_override(std::move(stream_override));
4329 bool is_prefetch = 4328 bool is_prefetch =
4330 GetContentClient()->renderer()->IsPrefetchOnly(this, request); 4329 GetContentClient()->renderer()->IsPrefetchOnly(this, request);
4331 extra_data->set_is_prefetch(is_prefetch); 4330 extra_data->set_is_prefetch(is_prefetch);
4332 extra_data->set_download_to_network_cache_only( 4331 extra_data->set_download_to_network_cache_only(
4333 is_prefetch && 4332 is_prefetch &&
4334 WebURLRequestToResourceType(request) != RESOURCE_TYPE_MAIN_FRAME); 4333 WebURLRequestToResourceType(request) != RESOURCE_TYPE_MAIN_FRAME);
4335 extra_data->set_initiated_in_secure_context( 4334 extra_data->set_initiated_in_secure_context(
4336 frame_document.isSecureContext()); 4335 frame_document.isSecureContext());
4337 4336
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
4649 return !blocked; 4648 return !blocked;
4650 } 4649 }
4651 4650
4652 blink::WebScreenOrientationClient* 4651 blink::WebScreenOrientationClient*
4653 RenderFrameImpl::webScreenOrientationClient() { 4652 RenderFrameImpl::webScreenOrientationClient() {
4654 if (!screen_orientation_dispatcher_) 4653 if (!screen_orientation_dispatcher_)
4655 screen_orientation_dispatcher_ = new ScreenOrientationDispatcher(this); 4654 screen_orientation_dispatcher_ = new ScreenOrientationDispatcher(this);
4656 return screen_orientation_dispatcher_; 4655 return screen_orientation_dispatcher_;
4657 } 4656 }
4658 4657
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, 4658 void RenderFrameImpl::postAccessibilityEvent(const blink::WebAXObject& obj,
4676 blink::WebAXEvent event) { 4659 blink::WebAXEvent event) {
4677 HandleWebAccessibilityEvent(obj, event); 4660 HandleWebAccessibilityEvent(obj, event);
4678 } 4661 }
4679 4662
4680 void RenderFrameImpl::handleAccessibilityFindInPageResult( 4663 void RenderFrameImpl::handleAccessibilityFindInPageResult(
4681 int identifier, 4664 int identifier,
4682 int match_index, 4665 int match_index,
4683 const blink::WebAXObject& start_object, 4666 const blink::WebAXObject& start_object,
4684 int start_offset, 4667 int start_offset,
(...skipping 2186 matching lines...) Expand 10 before | Expand all | Expand 10 after
6871 // event target. Potentially a Pepper plugin will receive the event. 6854 // 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 6855 // 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 6856 // 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 6857 // the event, it will notify us via DidReceiveMouseEvent() and set itself as
6875 // |pepper_last_mouse_event_target_|. 6858 // |pepper_last_mouse_event_target_|.
6876 pepper_last_mouse_event_target_ = nullptr; 6859 pepper_last_mouse_event_target_ = nullptr;
6877 #endif 6860 #endif
6878 } 6861 }
6879 6862
6880 } // namespace content 6863 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698