| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_FOREIGN_FETCH_REQUEST_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_FOREIGN_FETCH_REQUEST_HANDLER_H_ |
| 6 #define CONTENT_BROWSER_SERVICE_WORKER_FOREIGN_FETCH_REQUEST_HANDLER_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_FOREIGN_FETCH_REQUEST_HANDLER_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/optional.h" | 10 #include "base/optional.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 class URLRequestInterceptor; | 25 class URLRequestInterceptor; |
| 26 } | 26 } |
| 27 | 27 |
| 28 namespace storage { | 28 namespace storage { |
| 29 class BlobStorageContext; | 29 class BlobStorageContext; |
| 30 } | 30 } |
| 31 | 31 |
| 32 namespace content { | 32 namespace content { |
| 33 | 33 |
| 34 class ResourceContext; | 34 class ResourceContext; |
| 35 class ResourceRequestBodyImpl; | 35 class ResourceRequestBody; |
| 36 class ServiceWorkerContextWrapper; | 36 class ServiceWorkerContextWrapper; |
| 37 class ServiceWorkerRegistration; | 37 class ServiceWorkerRegistration; |
| 38 | 38 |
| 39 // Class for routing network requests to ServiceWorkers for foreign fetch | 39 // Class for routing network requests to ServiceWorkers for foreign fetch |
| 40 // events. Created one per URLRequest and attached to each request. | 40 // events. Created one per URLRequest and attached to each request. |
| 41 // TODO(mek): Does this need something similar to ServiceWorkerRequestHandler's | 41 // TODO(mek): Does this need something similar to ServiceWorkerRequestHandler's |
| 42 // GetExtraResponseInfo method? | 42 // GetExtraResponseInfo method? |
| 43 class CONTENT_EXPORT ForeignFetchRequestHandler | 43 class CONTENT_EXPORT ForeignFetchRequestHandler |
| 44 : public base::SupportsUserData::Data, | 44 : public base::SupportsUserData::Data, |
| 45 public ServiceWorkerURLRequestJob::Delegate { | 45 public ServiceWorkerURLRequestJob::Delegate { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 58 storage::BlobStorageContext* blob_storage_context, | 58 storage::BlobStorageContext* blob_storage_context, |
| 59 int process_id, | 59 int process_id, |
| 60 int provider_id, | 60 int provider_id, |
| 61 ServiceWorkerMode service_worker_mode, | 61 ServiceWorkerMode service_worker_mode, |
| 62 FetchRequestMode request_mode, | 62 FetchRequestMode request_mode, |
| 63 FetchCredentialsMode credentials_mode, | 63 FetchCredentialsMode credentials_mode, |
| 64 FetchRedirectMode redirect_mode, | 64 FetchRedirectMode redirect_mode, |
| 65 ResourceType resource_type, | 65 ResourceType resource_type, |
| 66 RequestContextType request_context_type, | 66 RequestContextType request_context_type, |
| 67 RequestContextFrameType frame_type, | 67 RequestContextFrameType frame_type, |
| 68 scoped_refptr<ResourceRequestBodyImpl> body, | 68 scoped_refptr<ResourceRequestBody> body, |
| 69 bool initiated_in_secure_context); | 69 bool initiated_in_secure_context); |
| 70 | 70 |
| 71 // Returns the handler attached to |request|. This may return null | 71 // Returns the handler attached to |request|. This may return null |
| 72 // if no handler is attached. | 72 // if no handler is attached. |
| 73 static ForeignFetchRequestHandler* GetHandler(net::URLRequest* request); | 73 static ForeignFetchRequestHandler* GetHandler(net::URLRequest* request); |
| 74 | 74 |
| 75 // Creates a protocol interceptor for foreign fetch. | 75 // Creates a protocol interceptor for foreign fetch. |
| 76 static std::unique_ptr<net::URLRequestInterceptor> CreateInterceptor( | 76 static std::unique_ptr<net::URLRequestInterceptor> CreateInterceptor( |
| 77 ResourceContext* resource_context); | 77 ResourceContext* resource_context); |
| 78 | 78 |
| 79 ~ForeignFetchRequestHandler() override; | 79 ~ForeignFetchRequestHandler() override; |
| 80 | 80 |
| 81 // Called via custom URLRequestJobFactory. | 81 // Called via custom URLRequestJobFactory. |
| 82 net::URLRequestJob* MaybeCreateJob(net::URLRequest* request, | 82 net::URLRequestJob* MaybeCreateJob(net::URLRequest* request, |
| 83 net::NetworkDelegate* network_delegate, | 83 net::NetworkDelegate* network_delegate, |
| 84 ResourceContext* resource_context); | 84 ResourceContext* resource_context); |
| 85 | 85 |
| 86 private: | 86 private: |
| 87 friend class ForeignFetchRequestHandlerTest; | 87 friend class ForeignFetchRequestHandlerTest; |
| 88 | 88 |
| 89 ForeignFetchRequestHandler( | 89 ForeignFetchRequestHandler( |
| 90 ServiceWorkerContextWrapper* context, | 90 ServiceWorkerContextWrapper* context, |
| 91 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, | 91 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, |
| 92 FetchRequestMode request_mode, | 92 FetchRequestMode request_mode, |
| 93 FetchCredentialsMode credentials_mode, | 93 FetchCredentialsMode credentials_mode, |
| 94 FetchRedirectMode redirect_mode, | 94 FetchRedirectMode redirect_mode, |
| 95 ResourceType resource_type, | 95 ResourceType resource_type, |
| 96 RequestContextType request_context_type, | 96 RequestContextType request_context_type, |
| 97 RequestContextFrameType frame_type, | 97 RequestContextFrameType frame_type, |
| 98 scoped_refptr<ResourceRequestBodyImpl> body, | 98 scoped_refptr<ResourceRequestBody> body, |
| 99 const base::Optional<base::TimeDelta>& timeout); | 99 const base::Optional<base::TimeDelta>& timeout); |
| 100 | 100 |
| 101 // Called when a ServiceWorkerRegistration has (or hasn't) been found for the | 101 // Called when a ServiceWorkerRegistration has (or hasn't) been found for the |
| 102 // request being handled. | 102 // request being handled. |
| 103 void DidFindRegistration( | 103 void DidFindRegistration( |
| 104 const base::WeakPtr<ServiceWorkerURLRequestJob>& job, | 104 const base::WeakPtr<ServiceWorkerURLRequestJob>& job, |
| 105 ServiceWorkerStatusCode status, | 105 ServiceWorkerStatusCode status, |
| 106 scoped_refptr<ServiceWorkerRegistration> registration); | 106 scoped_refptr<ServiceWorkerRegistration> registration); |
| 107 | 107 |
| 108 // ServiceWorkerURLRequestJob::Delegate implementation: | 108 // ServiceWorkerURLRequestJob::Delegate implementation: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 121 const ServiceWorkerVersion* const active_version); | 121 const ServiceWorkerVersion* const active_version); |
| 122 | 122 |
| 123 scoped_refptr<ServiceWorkerContextWrapper> context_; | 123 scoped_refptr<ServiceWorkerContextWrapper> context_; |
| 124 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; | 124 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; |
| 125 ResourceType resource_type_; | 125 ResourceType resource_type_; |
| 126 FetchRequestMode request_mode_; | 126 FetchRequestMode request_mode_; |
| 127 FetchCredentialsMode credentials_mode_; | 127 FetchCredentialsMode credentials_mode_; |
| 128 FetchRedirectMode redirect_mode_; | 128 FetchRedirectMode redirect_mode_; |
| 129 RequestContextType request_context_type_; | 129 RequestContextType request_context_type_; |
| 130 RequestContextFrameType frame_type_; | 130 RequestContextFrameType frame_type_; |
| 131 scoped_refptr<ResourceRequestBodyImpl> body_; | 131 scoped_refptr<ResourceRequestBody> body_; |
| 132 ResourceContext* resource_context_; | 132 ResourceContext* resource_context_; |
| 133 base::Optional<base::TimeDelta> timeout_; | 133 base::Optional<base::TimeDelta> timeout_; |
| 134 | 134 |
| 135 base::WeakPtr<ServiceWorkerURLRequestJob> job_; | 135 base::WeakPtr<ServiceWorkerURLRequestJob> job_; |
| 136 scoped_refptr<ServiceWorkerVersion> target_worker_; | 136 scoped_refptr<ServiceWorkerVersion> target_worker_; |
| 137 | 137 |
| 138 // True if the next time this request is started, the response should be | 138 // True if the next time this request is started, the response should be |
| 139 // delivered from the network, bypassing the ServiceWorker. | 139 // delivered from the network, bypassing the ServiceWorker. |
| 140 bool use_network_ = false; | 140 bool use_network_ = false; |
| 141 | 141 |
| 142 base::WeakPtrFactory<ForeignFetchRequestHandler> weak_factory_; | 142 base::WeakPtrFactory<ForeignFetchRequestHandler> weak_factory_; |
| 143 | 143 |
| 144 DISALLOW_COPY_AND_ASSIGN(ForeignFetchRequestHandler); | 144 DISALLOW_COPY_AND_ASSIGN(ForeignFetchRequestHandler); |
| 145 }; | 145 }; |
| 146 | 146 |
| 147 } // namespace content | 147 } // namespace content |
| 148 | 148 |
| 149 #endif // CONTENT_BROWSER_SERVICE_WORKER_FOREIGN_FETCH_REQUEST_HANDLER_H_ | 149 #endif // CONTENT_BROWSER_SERVICE_WORKER_FOREIGN_FETCH_REQUEST_HANDLER_H_ |
| OLD | NEW |