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, |
56 ResourceType resource_type, | 58 ResourceType resource_type, |
57 RequestContextType request_context_type, | 59 RequestContextType request_context_type, |
58 RequestContextFrameType frame_type, | 60 RequestContextFrameType frame_type, |
59 bool is_parent_frame_secure, | 61 bool is_parent_frame_secure, |
60 scoped_refptr<ResourceRequestBodyImpl> body, | 62 scoped_refptr<ResourceRequestBodyImpl> body, |
61 const base::Callback<WebContents*(void)>& web_contents_getter); | 63 const base::Callback<WebContents*(void)>& web_contents_getter); |
62 | 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, |
| 74 ResourceType resource_type, |
| 75 RequestContextType request_context_type, |
| 76 RequestContextFrameType frame_type, |
| 77 bool is_parent_frame_secure, |
| 78 scoped_refptr<ResourceRequestBodyImpl> body, |
| 79 const base::Callback<WebContents*(void)>& web_contents_getter, |
| 80 NetworkFallbackCallback network_fallback_callback); |
| 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 |
66 // has some precedence, it might be better to attach this handler in a more | 85 // has some precedence, it might be better to attach this handler in a more |
67 // explicit way within content layer, e.g. have ResourceRequestInfoImpl | 86 // explicit way within content layer, e.g. have ResourceRequestInfoImpl |
68 // own it. | 87 // own it. |
69 static void InitializeHandler( | 88 static void InitializeHandler( |
70 net::URLRequest* request, | 89 net::URLRequest* request, |
71 ServiceWorkerContextWrapper* context_wrapper, | 90 ServiceWorkerContextWrapper* context_wrapper, |
72 storage::BlobStorageContext* blob_storage_context, | 91 storage::BlobStorageContext* blob_storage_context, |
(...skipping 29 matching lines...) Expand all 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 MaybeGetURLLoaderFactory( |
| 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 |
123 protected: | 149 protected: |
124 ServiceWorkerRequestHandler( | 150 ServiceWorkerRequestHandler( |
125 base::WeakPtr<ServiceWorkerContextCore> context, | 151 base::WeakPtr<ServiceWorkerContextCore> context, |
126 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | 152 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
127 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, | 153 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, |
128 ResourceType resource_type); | 154 ResourceType resource_type); |
129 | 155 |
130 base::WeakPtr<ServiceWorkerContextCore> context_; | 156 base::WeakPtr<ServiceWorkerContextCore> context_; |
131 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; | 157 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; |
132 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; | 158 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; |
133 ResourceType resource_type_; | 159 ResourceType resource_type_; |
134 | 160 |
135 private: | 161 private: |
| 162 static std::unique_ptr<ServiceWorkerRequestHandler> |
| 163 InitializeForNavigationInternal( |
| 164 const GURL& url, |
| 165 ServiceWorkerNavigationHandleCore* navigation_handle_core, |
| 166 storage::BlobStorageContext* blob_storage_context, |
| 167 bool skip_service_worker, |
| 168 ResourceType resource_type, |
| 169 RequestContextType request_context_type, |
| 170 RequestContextFrameType frame_type, |
| 171 bool is_parent_frame_secure, |
| 172 scoped_refptr<ResourceRequestBodyImpl> body, |
| 173 const base::Callback<WebContents*(void)>& web_contents_getter, |
| 174 NetworkFallbackCallback network_fallback_callback); |
| 175 |
136 std::unique_ptr<ServiceWorkerProviderHost> host_for_cross_site_transfer_; | 176 std::unique_ptr<ServiceWorkerProviderHost> host_for_cross_site_transfer_; |
137 int old_process_id_; | 177 int old_process_id_; |
138 int old_provider_id_; | 178 int old_provider_id_; |
139 | 179 |
140 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRequestHandler); | 180 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRequestHandler); |
141 }; | 181 }; |
142 | 182 |
143 } // namespace content | 183 } // namespace content |
144 | 184 |
145 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REQUEST_HANDLER_H_ | 185 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REQUEST_HANDLER_H_ |
OLD | NEW |