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

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

Issue 2733283004: Expose WebServiceWorkerNetworkProvider on DataSource (Closed)
Patch Set: consistency 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
« no previous file with comments | « content/renderer/render_frame_impl.h ('k') | content/renderer/render_view_browsertest.cc » ('j') | 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 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 2780 matching lines...) Expand 10 before | Expand all | Expand 10 after
2980 return blame_context_.get(); 2981 return blame_context_.get();
2981 } 2982 }
2982 2983
2983 blink::WebServiceWorkerProvider* 2984 blink::WebServiceWorkerProvider*
2984 RenderFrameImpl::createServiceWorkerProvider() { 2985 RenderFrameImpl::createServiceWorkerProvider() {
2985 // At this point we should have non-null data source. 2986 // At this point we should have non-null data source.
2986 DCHECK(frame_->dataSource()); 2987 DCHECK(frame_->dataSource());
2987 if (!ChildThreadImpl::current()) 2988 if (!ChildThreadImpl::current())
2988 return nullptr; // May be null in some tests. 2989 return nullptr; // May be null in some tests.
2989 ServiceWorkerNetworkProvider* provider = 2990 ServiceWorkerNetworkProvider* provider =
2990 ServiceWorkerNetworkProvider::FromDocumentState( 2991 ServiceWorkerNetworkProvider::FromWebServiceWorkerNetworkProvider(
2991 DocumentState::FromDataSource(frame_->dataSource())); 2992 frame_->dataSource()->getServiceWorkerNetworkProvider());
2992 DCHECK(provider);
2993 if (!provider->context()) { 2993 if (!provider->context()) {
2994 // The context can be null when the frame is sandboxed. 2994 // The context can be null when the frame is sandboxed.
2995 return nullptr; 2995 return nullptr;
2996 } 2996 }
2997 return new WebServiceWorkerProviderImpl( 2997 return new WebServiceWorkerProviderImpl(
2998 ChildThreadImpl::current()->thread_safe_sender(), 2998 ChildThreadImpl::current()->thread_safe_sender(), provider->context());
2999 provider->context());
3000 } 2999 }
3001 3000
3002 void RenderFrameImpl::didAccessInitialDocument() { 3001 void RenderFrameImpl::didAccessInitialDocument() {
3003 DCHECK(!frame_->parent()); 3002 DCHECK(!frame_->parent());
3004 // NOTE: Do not call back into JavaScript here, since this call is made from a 3003 // NOTE: Do not call back into JavaScript here, since this call is made from a
3005 // V8 security check. 3004 // V8 security check.
3006 3005
3007 // If the request hasn't yet committed, notify the browser process that it is 3006 // If the request hasn't yet committed, notify the browser process that it is
3008 // no longer safe to show the pending URL of the main frame, since a URL spoof 3007 // no longer safe to show the pending URL of the main frame, since a URL spoof
3009 // is now possible. (If the request has committed, the browser already knows.) 3008 // is now possible. (If the request has committed, the browser already knows.)
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
3411 redirect_start, redirect_end, fetch_start, 3410 redirect_start, redirect_end, fetch_start,
3412 !navigation_state->request_params().redirects.empty()); 3411 !navigation_state->request_params().redirects.empty());
3413 // TODO(clamy) We need to provide additional timing values for the 3412 // TODO(clamy) We need to provide additional timing values for the
3414 // Navigation Timing API to work with browser-side navigations. 3413 // Navigation Timing API to work with browser-side navigations.
3415 // UnloadEventStart and UnloadEventEnd are still missing. 3414 // UnloadEventStart and UnloadEventEnd are still missing.
3416 } 3415 }
3417 3416
3418 // Create the serviceworker's per-document network observing object if it 3417 // Create the serviceworker's per-document network observing object if it
3419 // does not exist (When navigation happens within a page, the provider already 3418 // does not exist (When navigation happens within a page, the provider already
3420 // exists). 3419 // exists).
3421 if (ServiceWorkerNetworkProvider::FromDocumentState( 3420 if (datasource->getServiceWorkerNetworkProvider())
3422 DocumentState::FromDataSource(datasource)))
3423 return; 3421 return;
3424 3422
3425 ServiceWorkerNetworkProvider::AttachToDocumentState( 3423 datasource->setServiceWorkerNetworkProvider(
3426 DocumentState::FromDataSource(datasource),
3427 ServiceWorkerNetworkProvider::CreateForNavigation( 3424 ServiceWorkerNetworkProvider::CreateForNavigation(
3428 routing_id_, navigation_state->request_params(), frame, 3425 routing_id_, navigation_state->request_params(), frame,
3429 content_initiated)); 3426 content_initiated));
3430 } 3427 }
3431 3428
3432 void RenderFrameImpl::didStartProvisionalLoad( 3429 void RenderFrameImpl::didStartProvisionalLoad(
3433 blink::WebDataSource* data_source) { 3430 blink::WebDataSource* data_source) {
3434 // In fast/loader/stop-provisional-loads.html, we abort the load before this 3431 // In fast/loader/stop-provisional-loads.html, we abort the load before this
3435 // callback is invoked. 3432 // callback is invoked.
3436 if (!data_source) 3433 if (!data_source)
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after
4273 4270
4274 // Add an empty HTTP origin header for non GET methods if none is currently 4271 // Add an empty HTTP origin header for non GET methods if none is currently
4275 // present. 4272 // present.
4276 request.addHTTPOriginIfNeeded(WebSecurityOrigin::createUnique()); 4273 request.addHTTPOriginIfNeeded(WebSecurityOrigin::createUnique());
4277 4274
4278 // Attach |should_replace_current_entry| state to requests so that, should 4275 // Attach |should_replace_current_entry| state to requests so that, should
4279 // this navigation later require a request transfer, all state is preserved 4276 // this navigation later require a request transfer, all state is preserved
4280 // when it is re-created in the new process. 4277 // when it is re-created in the new process.
4281 bool should_replace_current_entry = data_source->replacesCurrentHistoryItem(); 4278 bool should_replace_current_entry = data_source->replacesCurrentHistoryItem();
4282 4279
4283 int provider_id = kInvalidServiceWorkerProviderId; 4280 // Initializes service worker related request info.
4284 if (request.getFrameType() == blink::WebURLRequest::FrameTypeTopLevel || 4281 if (request.getFrameType() == blink::WebURLRequest::FrameTypeTopLevel ||
4285 request.getFrameType() == blink::WebURLRequest::FrameTypeNested) { 4282 request.getFrameType() == blink::WebURLRequest::FrameTypeNested) {
4286 // |provisionalDataSource| may be null in some content::ResourceFetcher 4283 // |provisionalDataSource| may be null in some content::ResourceFetcher
4287 // use cases, we don't hook those requests. 4284 // use cases, we don't hook those requests.
4288 if (frame->provisionalDataSource()) { 4285 if (frame->provisionalDataSource()) {
4289 ServiceWorkerNetworkProvider* provider = 4286 blink::WebServiceWorkerNetworkProvider* provider =
4290 ServiceWorkerNetworkProvider::FromDocumentState( 4287 frame->provisionalDataSource()->getServiceWorkerNetworkProvider();
4291 DocumentState::FromDataSource(frame->provisionalDataSource()));
4292 DCHECK(provider); 4288 DCHECK(provider);
4293 provider_id = provider->provider_id(); 4289 provider->willSendRequest(request);
4294 } 4290 }
4295 } else if (frame->dataSource()) { 4291 } else if (frame->dataSource()) {
4296 ServiceWorkerNetworkProvider* provider = 4292 blink::WebServiceWorkerNetworkProvider* provider =
4297 ServiceWorkerNetworkProvider::FromDocumentState( 4293 frame->dataSource()->getServiceWorkerNetworkProvider();
4298 DocumentState::FromDataSource(frame->dataSource()));
4299 DCHECK(provider); 4294 DCHECK(provider);
4300 provider_id = provider->provider_id(); 4295 provider->willSendRequest(request);
4296
4301 // If the provider does not have a controller at this point, the renderer 4297 // If the provider does not have a controller at this point, the renderer
4302 // expects the request to never be handled by a controlling service worker, 4298 // expects the request to never be handled by a controlling service worker,
4303 // so set the ServiceWorkerMode to skip local workers here. Otherwise, a 4299 // so set the ServiceWorkerMode to skip local workers here. Otherwise, a
4304 // service worker that is in the process of becoming the controller (i.e., 4300 // service worker that is in the process of becoming the controller (i.e.,
4305 // via claim()) on the browser-side could handle the request and break 4301 // via claim()) on the browser-side could handle the request and break
4306 // the assumptions of the renderer. 4302 // the assumptions of the renderer.
4307 if (!provider->IsControlledByServiceWorker() && 4303 if (!provider->isControlledByServiceWorker() &&
4308 request.getServiceWorkerMode() != 4304 request.getServiceWorkerMode() !=
4309 blink::WebURLRequest::ServiceWorkerMode::None) { 4305 blink::WebURLRequest::ServiceWorkerMode::None) {
4310 request.setServiceWorkerMode( 4306 request.setServiceWorkerMode(
4311 blink::WebURLRequest::ServiceWorkerMode::Foreign); 4307 blink::WebURLRequest::ServiceWorkerMode::Foreign);
4312 } 4308 }
4313 } 4309 }
4314 4310
4315 WebFrame* parent = frame->parent(); 4311 WebFrame* parent = frame->parent();
4316 int parent_routing_id = parent ? GetRoutingIdForFrameOrProxy(parent) : -1; 4312 int parent_routing_id = parent ? GetRoutingIdForFrameOrProxy(parent) : -1;
4317 4313
4318 RequestExtraData* extra_data = new RequestExtraData(); 4314 RequestExtraData* extra_data =
4315 static_cast<RequestExtraData*>(request.getExtraData());
4316 if (!extra_data)
4317 extra_data = new RequestExtraData();
4319 extra_data->set_visibility_state(visibilityState()); 4318 extra_data->set_visibility_state(visibilityState());
4320 extra_data->set_custom_user_agent(custom_user_agent); 4319 extra_data->set_custom_user_agent(custom_user_agent);
4321 extra_data->set_requested_with(requested_with); 4320 extra_data->set_requested_with(requested_with);
4322 extra_data->set_render_frame_id(routing_id_); 4321 extra_data->set_render_frame_id(routing_id_);
4323 extra_data->set_is_main_frame(!parent); 4322 extra_data->set_is_main_frame(!parent);
4324 extra_data->set_frame_origin( 4323 extra_data->set_frame_origin(
4325 url::Origin(frame_document.getSecurityOrigin())); 4324 url::Origin(frame_document.getSecurityOrigin()));
4326 extra_data->set_parent_is_main_frame(parent && !parent->parent()); 4325 extra_data->set_parent_is_main_frame(parent && !parent->parent());
4327 extra_data->set_parent_render_frame_id(parent_routing_id); 4326 extra_data->set_parent_render_frame_id(parent_routing_id);
4328 extra_data->set_allow_download( 4327 extra_data->set_allow_download(
4329 navigation_state->common_params().allow_download); 4328 navigation_state->common_params().allow_download);
4330 extra_data->set_transition_type(transition_type); 4329 extra_data->set_transition_type(transition_type);
4331 extra_data->set_should_replace_current_entry(should_replace_current_entry); 4330 extra_data->set_should_replace_current_entry(should_replace_current_entry);
4332 extra_data->set_service_worker_provider_id(provider_id);
4333 extra_data->set_stream_override(std::move(stream_override)); 4331 extra_data->set_stream_override(std::move(stream_override));
4334 bool is_prefetch = 4332 bool is_prefetch =
4335 GetContentClient()->renderer()->IsPrefetchOnly(this, request); 4333 GetContentClient()->renderer()->IsPrefetchOnly(this, request);
4336 extra_data->set_is_prefetch(is_prefetch); 4334 extra_data->set_is_prefetch(is_prefetch);
4337 extra_data->set_download_to_network_cache_only( 4335 extra_data->set_download_to_network_cache_only(
4338 is_prefetch && 4336 is_prefetch &&
4339 WebURLRequestToResourceType(request) != RESOURCE_TYPE_MAIN_FRAME); 4337 WebURLRequestToResourceType(request) != RESOURCE_TYPE_MAIN_FRAME);
4340 extra_data->set_initiated_in_secure_context( 4338 extra_data->set_initiated_in_secure_context(
4341 frame_document.isSecureContext()); 4339 frame_document.isSecureContext());
4342 4340
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
4654 return !blocked; 4652 return !blocked;
4655 } 4653 }
4656 4654
4657 blink::WebScreenOrientationClient* 4655 blink::WebScreenOrientationClient*
4658 RenderFrameImpl::webScreenOrientationClient() { 4656 RenderFrameImpl::webScreenOrientationClient() {
4659 if (!screen_orientation_dispatcher_) 4657 if (!screen_orientation_dispatcher_)
4660 screen_orientation_dispatcher_ = new ScreenOrientationDispatcher(this); 4658 screen_orientation_dispatcher_ = new ScreenOrientationDispatcher(this);
4661 return screen_orientation_dispatcher_; 4659 return screen_orientation_dispatcher_;
4662 } 4660 }
4663 4661
4664 bool RenderFrameImpl::isControlledByServiceWorker(WebDataSource& data_source) {
4665 ServiceWorkerNetworkProvider* provider =
4666 ServiceWorkerNetworkProvider::FromDocumentState(
4667 DocumentState::FromDataSource(&data_source));
4668 return provider->IsControlledByServiceWorker();
4669 }
4670
4671 int64_t RenderFrameImpl::serviceWorkerID(WebDataSource& data_source) {
4672 ServiceWorkerNetworkProvider* provider =
4673 ServiceWorkerNetworkProvider::FromDocumentState(
4674 DocumentState::FromDataSource(&data_source));
4675 if (provider->context() && provider->context()->controller())
4676 return provider->context()->controller()->version_id();
4677 return kInvalidServiceWorkerVersionId;
4678 }
4679
4680 void RenderFrameImpl::postAccessibilityEvent(const blink::WebAXObject& obj, 4662 void RenderFrameImpl::postAccessibilityEvent(const blink::WebAXObject& obj,
4681 blink::WebAXEvent event) { 4663 blink::WebAXEvent event) {
4682 HandleWebAccessibilityEvent(obj, event); 4664 HandleWebAccessibilityEvent(obj, event);
4683 } 4665 }
4684 4666
4685 void RenderFrameImpl::handleAccessibilityFindInPageResult( 4667 void RenderFrameImpl::handleAccessibilityFindInPageResult(
4686 int identifier, 4668 int identifier,
4687 int match_index, 4669 int match_index,
4688 const blink::WebAXObject& start_object, 4670 const blink::WebAXObject& start_object,
4689 int start_offset, 4671 int start_offset,
(...skipping 2180 matching lines...) Expand 10 before | Expand all | Expand 10 after
6870 // event target. Potentially a Pepper plugin will receive the event. 6852 // event target. Potentially a Pepper plugin will receive the event.
6871 // In order to tell whether a plugin gets the last mouse event and which it 6853 // In order to tell whether a plugin gets the last mouse event and which it
6872 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets 6854 // is, we set |pepper_last_mouse_event_target_| to null here. If a plugin gets
6873 // the event, it will notify us via DidReceiveMouseEvent() and set itself as 6855 // the event, it will notify us via DidReceiveMouseEvent() and set itself as
6874 // |pepper_last_mouse_event_target_|. 6856 // |pepper_last_mouse_event_target_|.
6875 pepper_last_mouse_event_target_ = nullptr; 6857 pepper_last_mouse_event_target_ = nullptr;
6876 #endif 6858 #endif
6877 } 6859 }
6878 6860
6879 } // namespace content 6861 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_frame_impl.h ('k') | content/renderer/render_view_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698