| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REQUEST_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REQUEST_HANDLER_H_ |
| 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REQUEST_HANDLER_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REQUEST_HANDLER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/supports_user_data.h" | 13 #include "base/supports_user_data.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "content/browser/loader/url_loader_request_handler.h" |
| 15 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
| 16 #include "content/common/service_worker/service_worker_status_code.h" | 17 #include "content/common/service_worker/service_worker_status_code.h" |
| 17 #include "content/common/service_worker/service_worker_types.h" | 18 #include "content/common/service_worker/service_worker_types.h" |
| 18 #include "content/common/url_loader_factory.mojom.h" | |
| 19 #include "content/public/common/request_context_frame_type.h" | 19 #include "content/public/common/request_context_frame_type.h" |
| 20 #include "content/public/common/request_context_type.h" | 20 #include "content/public/common/request_context_type.h" |
| 21 #include "content/public/common/resource_type.h" | 21 #include "content/public/common/resource_type.h" |
| 22 #include "net/url_request/url_request_job_factory.h" | 22 #include "net/url_request/url_request_job_factory.h" |
| 23 | 23 |
| 24 namespace net { | 24 namespace net { |
| 25 class NetworkDelegate; | 25 class NetworkDelegate; |
| 26 class URLRequest; | 26 class URLRequest; |
| 27 class URLRequestInterceptor; | 27 class URLRequestInterceptor; |
| 28 } | 28 } |
| 29 | 29 |
| 30 namespace storage { | 30 namespace storage { |
| 31 class BlobStorageContext; | 31 class BlobStorageContext; |
| 32 } | 32 } |
| 33 | 33 |
| 34 namespace content { | 34 namespace content { |
| 35 | 35 |
| 36 class ResourceContext; | 36 class ResourceContext; |
| 37 class ResourceRequestBodyImpl; | 37 class ResourceRequestBodyImpl; |
| 38 class ServiceWorkerContextCore; | 38 class ServiceWorkerContextCore; |
| 39 class ServiceWorkerContextWrapper; | 39 class ServiceWorkerContextWrapper; |
| 40 class ServiceWorkerNavigationHandleCore; | 40 class ServiceWorkerNavigationHandleCore; |
| 41 class ServiceWorkerProviderHost; | 41 class ServiceWorkerProviderHost; |
| 42 class WebContents; | 42 class WebContents; |
| 43 | 43 |
| 44 // Abstract base class for routing network requests to ServiceWorkers. | 44 // Abstract base class for routing network requests to ServiceWorkers. |
| 45 // Created one per URLRequest and attached to each request. | 45 // Created one per URLRequest and attached to each request. |
| 46 class CONTENT_EXPORT ServiceWorkerRequestHandler | 46 class CONTENT_EXPORT ServiceWorkerRequestHandler |
| 47 : public base::SupportsUserData::Data { | 47 : public base::SupportsUserData::Data, |
| 48 public URLLoaderRequestHandler { |
| 48 public: | 49 public: |
| 49 // PlzNavigate | 50 // PlzNavigate |
| 50 // Attaches a newly created handler if the given |request| needs to be handled | 51 // Attaches a newly created handler if the given |request| needs to be handled |
| 51 // by ServiceWorker. | 52 // by ServiceWorker. |
| 52 static void InitializeForNavigation( | 53 static void InitializeForNavigation( |
| 53 net::URLRequest* request, | 54 net::URLRequest* request, |
| 54 ServiceWorkerNavigationHandleCore* navigation_handle_core, | 55 ServiceWorkerNavigationHandleCore* navigation_handle_core, |
| 55 storage::BlobStorageContext* blob_storage_context, | 56 storage::BlobStorageContext* blob_storage_context, |
| 56 bool skip_service_worker, | 57 bool skip_service_worker, |
| 57 ResourceType resource_type, | 58 ResourceType resource_type, |
| 58 RequestContextType request_context_type, | 59 RequestContextType request_context_type, |
| 59 RequestContextFrameType frame_type, | 60 RequestContextFrameType frame_type, |
| 60 bool is_parent_frame_secure, | 61 bool is_parent_frame_secure, |
| 61 scoped_refptr<ResourceRequestBodyImpl> body, | 62 scoped_refptr<ResourceRequestBodyImpl> body, |
| 62 const base::Callback<WebContents*(void)>& web_contents_getter); | 63 const base::Callback<WebContents*(void)>& web_contents_getter); |
| 63 | 64 |
| 64 // PlzNavigate and --enable-network-service. | 65 // PlzNavigate and --enable-network-service. |
| 65 // Same as InitializeForNavigation() but instead of attaching to a URLRequest, | 66 // Same as InitializeForNavigation() but instead of attaching to a URLRequest, |
| 66 // returns a URLLoaderFactoryPtrInfo if the request needs to be handled. | 67 // just creates a URLLoaderRequestHandler and returns it. |
| 67 static mojom::URLLoaderFactoryPtr InitializeForNavigationNetworkService( | 68 static std::unique_ptr<URLLoaderRequestHandler> |
| 69 InitializeForNavigationNetworkService( |
| 68 const ResourceRequest& resource_request, | 70 const ResourceRequest& resource_request, |
| 69 ResourceContext* resource_context, | 71 ResourceContext* resource_context, |
| 70 ServiceWorkerNavigationHandleCore* navigation_handle_core, | 72 ServiceWorkerNavigationHandleCore* navigation_handle_core, |
| 71 storage::BlobStorageContext* blob_storage_context, | 73 storage::BlobStorageContext* blob_storage_context, |
| 72 bool skip_service_worker, | 74 bool skip_service_worker, |
| 73 ResourceType resource_type, | 75 ResourceType resource_type, |
| 74 RequestContextType request_context_type, | 76 RequestContextType request_context_type, |
| 75 RequestContextFrameType frame_type, | 77 RequestContextFrameType frame_type, |
| 76 bool is_parent_frame_secure, | 78 bool is_parent_frame_secure, |
| 77 scoped_refptr<ResourceRequestBodyImpl> body, | 79 scoped_refptr<ResourceRequestBodyImpl> body, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 const net::URLRequest* request); | 121 const net::URLRequest* request); |
| 120 | 122 |
| 121 ~ServiceWorkerRequestHandler() override; | 123 ~ServiceWorkerRequestHandler() override; |
| 122 | 124 |
| 123 // Called via custom URLRequestJobFactory. | 125 // Called via custom URLRequestJobFactory. |
| 124 virtual net::URLRequestJob* MaybeCreateJob( | 126 virtual net::URLRequestJob* MaybeCreateJob( |
| 125 net::URLRequest* request, | 127 net::URLRequest* request, |
| 126 net::NetworkDelegate* network_delegate, | 128 net::NetworkDelegate* network_delegate, |
| 127 ResourceContext* context) = 0; | 129 ResourceContext* context) = 0; |
| 128 | 130 |
| 131 // URLLoaderRequestHandler overrides. (Just a placeholder for NOTREACHED |
| 132 // for now). |
| 133 void Start(const ResourceRequest& request, |
| 134 Controller* controller, |
| 135 ResourceContext* resource_context, |
| 136 mojom::URLLoaderAssociatedRequest loader_request, |
| 137 mojom::URLLoaderClientPtr loader_client_ptr) override; |
| 138 |
| 129 // Methods to support cross site navigations. | 139 // Methods to support cross site navigations. |
| 130 void PrepareForCrossSiteTransfer(int old_process_id); | 140 void PrepareForCrossSiteTransfer(int old_process_id); |
| 131 void CompleteCrossSiteTransfer(int new_process_id, | 141 void CompleteCrossSiteTransfer(int new_process_id, |
| 132 int new_provider_id); | 142 int new_provider_id); |
| 133 void MaybeCompleteCrossSiteTransferInOldProcess( | 143 void MaybeCompleteCrossSiteTransferInOldProcess( |
| 134 int old_process_id); | 144 int old_process_id); |
| 135 | 145 |
| 136 // Useful for detecting storage partition mismatches in the context of cross | 146 // Useful for detecting storage partition mismatches in the context of cross |
| 137 // site transfer navigations. | 147 // site transfer navigations. |
| 138 bool SanityCheckIsSameContext(ServiceWorkerContextWrapper* wrapper); | 148 bool SanityCheckIsSameContext(ServiceWorkerContextWrapper* wrapper); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 153 std::unique_ptr<ServiceWorkerProviderHost> host_for_cross_site_transfer_; | 163 std::unique_ptr<ServiceWorkerProviderHost> host_for_cross_site_transfer_; |
| 154 int old_process_id_; | 164 int old_process_id_; |
| 155 int old_provider_id_; | 165 int old_provider_id_; |
| 156 | 166 |
| 157 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRequestHandler); | 167 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRequestHandler); |
| 158 }; | 168 }; |
| 159 | 169 |
| 160 } // namespace content | 170 } // namespace content |
| 161 | 171 |
| 162 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REQUEST_HANDLER_H_ | 172 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REQUEST_HANDLER_H_ |
| OLD | NEW |