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/service_worker/service_worker_url_loader_factory.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" |
| 19 #include "content/common/url_loader_factory.mojom.h" |
18 #include "content/public/common/request_context_frame_type.h" | 20 #include "content/public/common/request_context_frame_type.h" |
19 #include "content/public/common/request_context_type.h" | 21 #include "content/public/common/request_context_type.h" |
20 #include "content/public/common/resource_type.h" | 22 #include "content/public/common/resource_type.h" |
21 #include "net/url_request/url_request_job_factory.h" | 23 #include "net/url_request/url_request_job_factory.h" |
22 | 24 |
23 namespace net { | 25 namespace net { |
24 class NetworkDelegate; | 26 class NetworkDelegate; |
25 class URLRequest; | 27 class URLRequest; |
26 class URLRequestInterceptor; | 28 class URLRequestInterceptor; |
27 } | 29 } |
28 | 30 |
29 namespace storage { | 31 namespace storage { |
30 class BlobStorageContext; | 32 class BlobStorageContext; |
31 } | 33 } |
32 | 34 |
33 namespace content { | 35 namespace content { |
34 | 36 |
35 class ResourceContext; | 37 class ResourceContext; |
| 38 struct ResourceRequest; |
36 class ResourceRequestBodyImpl; | 39 class ResourceRequestBodyImpl; |
37 class ServiceWorkerContextCore; | 40 class ServiceWorkerContextCore; |
38 class ServiceWorkerContextWrapper; | 41 class ServiceWorkerContextWrapper; |
39 class ServiceWorkerNavigationHandleCore; | 42 class ServiceWorkerNavigationHandleCore; |
40 class ServiceWorkerProviderHost; | 43 class ServiceWorkerProviderHost; |
41 class WebContents; | 44 class WebContents; |
42 | 45 |
43 // Abstract base class for routing network requests to ServiceWorkers. | 46 // Abstract base class for routing network requests to ServiceWorkers. |
44 // Created one per URLRequest and attached to each request. | 47 // Created one per URLRequest and attached to each request. |
45 class CONTENT_EXPORT ServiceWorkerRequestHandler | 48 class CONTENT_EXPORT ServiceWorkerRequestHandler |
46 : public base::SupportsUserData::Data { | 49 : public base::SupportsUserData::Data { |
47 public: | 50 public: |
48 // PlzNavigate | 51 // PlzNavigate |
49 // Attaches a newly created handler if the given |request| needs to be handled | 52 // Attaches a newly created handler if the given |request| needs to be handled |
50 // by ServiceWorker. | 53 // by ServiceWorker. |
51 static void InitializeForNavigation( | 54 static void InitializeForNavigation( |
52 net::URLRequest* request, | 55 net::URLRequest* url_request, |
53 ServiceWorkerNavigationHandleCore* navigation_handle_core, | 56 ServiceWorkerNavigationHandleCore* navigation_handle_core, |
54 storage::BlobStorageContext* blob_storage_context, | 57 storage::BlobStorageContext* blob_storage_context, |
55 bool skip_service_worker, | 58 bool skip_service_worker, |
| 59 ResourceType resource_type, |
| 60 RequestContextType request_context_type, |
| 61 RequestContextFrameType frame_type, |
| 62 bool is_parent_frame_secure, |
| 63 scoped_refptr<ResourceRequestBodyImpl> body, |
| 64 const base::Callback<WebContents*(void)>& web_contents_getter); |
| 65 |
| 66 // PlzNavigate and --enable-network-service |
| 67 // Same as InitializeForNavigation(), but instead of attaching to a request, |
| 68 // returns a URLLoaderFactoryPtr if the request needs to be handled. |
| 69 static mojom::URLLoaderFactoryPtrInfo InitializeForNavigationNetworkService( |
| 70 const ResourceRequest& resource_request, |
| 71 ResourceContext* resource_context, |
| 72 ServiceWorkerNavigationHandleCore* navigation_handle_core, |
| 73 storage::BlobStorageContext* blob_storage_context, |
| 74 bool skip_service_worker, |
56 ResourceType resource_type, | 75 ResourceType resource_type, |
57 RequestContextType request_context_type, | 76 RequestContextType request_context_type, |
58 RequestContextFrameType frame_type, | 77 RequestContextFrameType frame_type, |
59 bool is_parent_frame_secure, | 78 bool is_parent_frame_secure, |
60 scoped_refptr<ResourceRequestBodyImpl> body, | 79 scoped_refptr<ResourceRequestBodyImpl> body, |
61 const base::Callback<WebContents*(void)>& web_contents_getter); | 80 const base::Callback<WebContents*(void)>& web_contents_getter); |
62 | 81 |
63 // Attaches a newly created handler if the given |request| needs to | 82 // Attaches a newly created handler if the given |request| needs to |
64 // be handled by ServiceWorker. | 83 // be handled by ServiceWorker. |
65 // TODO(kinuko): While utilizing UserData to attach data to URLRequest | 84 // TODO(kinuko): While utilizing UserData to attach data to URLRequest |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 const net::URLRequest* request); | 121 const net::URLRequest* request); |
103 | 122 |
104 ~ServiceWorkerRequestHandler() override; | 123 ~ServiceWorkerRequestHandler() override; |
105 | 124 |
106 // Called via custom URLRequestJobFactory. | 125 // Called via custom URLRequestJobFactory. |
107 virtual net::URLRequestJob* MaybeCreateJob( | 126 virtual net::URLRequestJob* MaybeCreateJob( |
108 net::URLRequest* request, | 127 net::URLRequest* request, |
109 net::NetworkDelegate* network_delegate, | 128 net::NetworkDelegate* network_delegate, |
110 ResourceContext* context) = 0; | 129 ResourceContext* context) = 0; |
111 | 130 |
| 131 virtual mojom::URLLoaderFactoryPtrInfo MaybeCreateURLLoader( |
| 132 const ResourceRequest& resource_request, |
| 133 ResourceContext* resource_context, |
| 134 std::unique_ptr<ServiceWorkerRequestHandler> request_handler) { |
| 135 return mojom::URLLoaderFactoryPtrInfo(); |
| 136 } |
| 137 |
112 // Methods to support cross site navigations. | 138 // Methods to support cross site navigations. |
113 void PrepareForCrossSiteTransfer(int old_process_id); | 139 void PrepareForCrossSiteTransfer(int old_process_id); |
114 void CompleteCrossSiteTransfer(int new_process_id, | 140 void CompleteCrossSiteTransfer(int new_process_id, |
115 int new_provider_id); | 141 int new_provider_id); |
116 void MaybeCompleteCrossSiteTransferInOldProcess( | 142 void MaybeCompleteCrossSiteTransferInOldProcess( |
117 int old_process_id); | 143 int old_process_id); |
118 | 144 |
119 // Useful for detecting storage partition mismatches in the context of cross | 145 // Useful for detecting storage partition mismatches in the context of cross |
120 // site transfer navigations. | 146 // site transfer navigations. |
121 bool SanityCheckIsSameContext(ServiceWorkerContextWrapper* wrapper); | 147 bool SanityCheckIsSameContext(ServiceWorkerContextWrapper* wrapper); |
122 | 148 |
| 149 using HandlerCreated = |
| 150 base::Callback<void(std::unique_ptr<ServiceWorkerRequestHandler>)>; |
| 151 |
123 protected: | 152 protected: |
124 ServiceWorkerRequestHandler( | 153 ServiceWorkerRequestHandler( |
125 base::WeakPtr<ServiceWorkerContextCore> context, | 154 base::WeakPtr<ServiceWorkerContextCore> context, |
126 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | 155 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
127 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, | 156 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, |
128 ResourceType resource_type); | 157 ResourceType resource_type); |
129 | 158 |
130 base::WeakPtr<ServiceWorkerContextCore> context_; | 159 base::WeakPtr<ServiceWorkerContextCore> context_; |
131 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; | 160 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; |
132 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; | 161 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; |
133 ResourceType resource_type_; | 162 ResourceType resource_type_; |
134 | 163 |
135 private: | 164 private: |
| 165 static void InitializeForNavigationImpl( |
| 166 const GURL& url, |
| 167 ServiceWorkerNavigationHandleCore* navigation_handle_core, |
| 168 storage::BlobStorageContext* blob_storage_context, |
| 169 bool skip_service_worker, |
| 170 ResourceType resource_type, |
| 171 RequestContextType request_context_type, |
| 172 RequestContextFrameType frame_type, |
| 173 bool is_parent_frame_secure, |
| 174 scoped_refptr<ResourceRequestBodyImpl> body, |
| 175 const base::Callback<WebContents*(void)>& web_contents_getter, |
| 176 const HandlerCreated& on_handler_created); |
| 177 |
136 std::unique_ptr<ServiceWorkerProviderHost> host_for_cross_site_transfer_; | 178 std::unique_ptr<ServiceWorkerProviderHost> host_for_cross_site_transfer_; |
137 int old_process_id_; | 179 int old_process_id_; |
138 int old_provider_id_; | 180 int old_provider_id_; |
139 | 181 |
140 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRequestHandler); | 182 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRequestHandler); |
141 }; | 183 }; |
142 | 184 |
143 } // namespace content | 185 } // namespace content |
144 | 186 |
145 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REQUEST_HANDLER_H_ | 187 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REQUEST_HANDLER_H_ |
OLD | NEW |