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