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" |
(...skipping 16 matching lines...) Expand all Loading... |
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 struct ResourceRequest; |
37 class ResourceRequestBodyImpl; | 38 class ResourceRequestBodyImpl; |
38 class ServiceWorkerContextCore; | 39 class ServiceWorkerContextCore; |
39 class ServiceWorkerContextWrapper; | 40 class ServiceWorkerContextWrapper; |
40 class ServiceWorkerNavigationHandleCore; | 41 class ServiceWorkerNavigationHandleCore; |
41 class ServiceWorkerProviderHost; | 42 class ServiceWorkerProviderHost; |
42 class WebContents; | 43 class WebContents; |
43 | 44 |
44 // Abstract base class for routing network requests to ServiceWorkers. | 45 // Abstract base class for routing network requests to ServiceWorkers. |
45 // Created one per URLRequest and attached to each request. | 46 // Created one per URLRequest and attached to each request. |
46 class CONTENT_EXPORT ServiceWorkerRequestHandler | 47 class CONTENT_EXPORT ServiceWorkerRequestHandler |
47 : public base::SupportsUserData::Data { | 48 : public base::SupportsUserData::Data { |
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* url_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 // TODO(falken): is comment wrong? |
67 static mojom::URLLoaderFactoryPtr InitializeForNavigationNetworkService( | 68 static mojom::URLLoaderFactoryPtr InitializeForNavigationNetworkService( |
68 const ResourceRequest& resource_request, | 69 const ResourceRequest& resource_request, |
69 ResourceContext* resource_context, | 70 ResourceContext* resource_context, |
70 ServiceWorkerNavigationHandleCore* navigation_handle_core, | 71 ServiceWorkerNavigationHandleCore* navigation_handle_core, |
71 storage::BlobStorageContext* blob_storage_context, | 72 storage::BlobStorageContext* blob_storage_context, |
72 bool skip_service_worker, | 73 bool skip_service_worker, |
73 ResourceType resource_type, | 74 ResourceType resource_type, |
74 RequestContextType request_context_type, | 75 RequestContextType request_context_type, |
75 RequestContextFrameType frame_type, | 76 RequestContextFrameType frame_type, |
76 bool is_parent_frame_secure, | 77 bool is_parent_frame_secure, |
77 scoped_refptr<ResourceRequestBodyImpl> body, | 78 scoped_refptr<ResourceRequestBodyImpl> body, |
| 79 #if 0 |
| 80 const base::Callback<WebContents*(void)>& web_contents_getter, |
| 81 NetworkFallbackCallback network_fallback_callback); |
| 82 #endif |
78 const base::Callback<WebContents*(void)>& web_contents_getter); | 83 const base::Callback<WebContents*(void)>& web_contents_getter); |
79 | 84 |
80 // Attaches a newly created handler if the given |request| needs to | 85 // Attaches a newly created handler if the given |request| needs to |
81 // be handled by ServiceWorker. | 86 // be handled by ServiceWorker. |
82 // TODO(kinuko): While utilizing UserData to attach data to URLRequest | 87 // TODO(kinuko): While utilizing UserData to attach data to URLRequest |
83 // has some precedence, it might be better to attach this handler in a more | 88 // has some precedence, it might be better to attach this handler in a more |
84 // explicit way within content layer, e.g. have ResourceRequestInfoImpl | 89 // explicit way within content layer, e.g. have ResourceRequestInfoImpl |
85 // own it. | 90 // own it. |
86 static void InitializeHandler( | 91 static void InitializeHandler( |
87 net::URLRequest* request, | 92 net::URLRequest* request, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 const net::URLRequest* request); | 124 const net::URLRequest* request); |
120 | 125 |
121 ~ServiceWorkerRequestHandler() override; | 126 ~ServiceWorkerRequestHandler() override; |
122 | 127 |
123 // Called via custom URLRequestJobFactory. | 128 // Called via custom URLRequestJobFactory. |
124 virtual net::URLRequestJob* MaybeCreateJob( | 129 virtual net::URLRequestJob* MaybeCreateJob( |
125 net::URLRequest* request, | 130 net::URLRequest* request, |
126 net::NetworkDelegate* network_delegate, | 131 net::NetworkDelegate* network_delegate, |
127 ResourceContext* context) = 0; | 132 ResourceContext* context) = 0; |
128 | 133 |
| 134 virtual mojom::URLLoaderFactoryPtr MaybeGetURLLoaderFactory( |
| 135 const ResourceRequest& resource_request, |
| 136 ResourceContext* resource_context, |
| 137 std::unique_ptr<ServiceWorkerRequestHandler> request_handler); |
| 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); |
139 | 149 |
140 protected: | 150 protected: |
141 ServiceWorkerRequestHandler( | 151 ServiceWorkerRequestHandler( |
142 base::WeakPtr<ServiceWorkerContextCore> context, | 152 base::WeakPtr<ServiceWorkerContextCore> context, |
143 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | 153 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
144 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, | 154 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, |
145 ResourceType resource_type); | 155 ResourceType resource_type); |
146 | 156 |
147 base::WeakPtr<ServiceWorkerContextCore> context_; | 157 base::WeakPtr<ServiceWorkerContextCore> context_; |
148 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; | 158 base::WeakPtr<ServiceWorkerProviderHost> provider_host_; |
149 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; | 159 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; |
150 ResourceType resource_type_; | 160 ResourceType resource_type_; |
151 | 161 |
152 private: | 162 private: |
| 163 static std::unique_ptr<ServiceWorkerRequestHandler> |
| 164 InitializeForNavigationInternal( |
| 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 #if 0 |
| 175 const base::Callback<WebContents*(void)>& web_contents_getter, |
| 176 NetworkFallbackCallback network_fallback_callback); |
| 177 #endif |
| 178 const base::Callback<WebContents*(void)>& web_contents_getter); |
| 179 |
153 std::unique_ptr<ServiceWorkerProviderHost> host_for_cross_site_transfer_; | 180 std::unique_ptr<ServiceWorkerProviderHost> host_for_cross_site_transfer_; |
154 int old_process_id_; | 181 int old_process_id_; |
155 int old_provider_id_; | 182 int old_provider_id_; |
156 | 183 |
157 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRequestHandler); | 184 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerRequestHandler); |
158 }; | 185 }; |
159 | 186 |
160 } // namespace content | 187 } // namespace content |
161 | 188 |
162 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REQUEST_HANDLER_H_ | 189 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_REQUEST_HANDLER_H_ |
OLD | NEW |