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/supports_user_data.h" | 10 #include "base/supports_user_data.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 class URLRequestInterceptor; | 24 class URLRequestInterceptor; |
25 } | 25 } |
26 | 26 |
27 namespace storage { | 27 namespace storage { |
28 class BlobStorageContext; | 28 class BlobStorageContext; |
29 } | 29 } |
30 | 30 |
31 namespace content { | 31 namespace content { |
32 | 32 |
33 class ResourceContext; | 33 class ResourceContext; |
34 class ResourceRequestBody; | 34 class ResourceRequestBodyImpl; |
35 class ServiceWorkerContextCore; | 35 class ServiceWorkerContextCore; |
36 class ServiceWorkerContextWrapper; | 36 class ServiceWorkerContextWrapper; |
37 class ServiceWorkerProviderHost; | 37 class ServiceWorkerProviderHost; |
38 class ServiceWorkerRegistration; | 38 class ServiceWorkerRegistration; |
39 struct ResourceResponseInfo; | 39 struct ResourceResponseInfo; |
40 | 40 |
41 // Class for routing network requests to ServiceWorkers for foreign fetch | 41 // Class for routing network requests to ServiceWorkers for foreign fetch |
42 // events. Created one per URLRequest and attached to each request. | 42 // events. Created one per URLRequest and attached to each request. |
43 // TODO(mek): Does this need something similar to ServiceWorkerRequestHandler's | 43 // TODO(mek): Does this need something similar to ServiceWorkerRequestHandler's |
44 // GetExtraResponseInfo method? | 44 // GetExtraResponseInfo method? |
45 class CONTENT_EXPORT ForeignFetchRequestHandler | 45 class CONTENT_EXPORT ForeignFetchRequestHandler |
46 : public base::SupportsUserData::Data, | 46 : public base::SupportsUserData::Data, |
47 public ServiceWorkerURLRequestJob::Delegate { | 47 public ServiceWorkerURLRequestJob::Delegate { |
48 public: | 48 public: |
49 // Attaches a newly created handler if the given |request| needs to | 49 // Attaches a newly created handler if the given |request| needs to |
50 // be handled by a foreign fetch handling ServiceWorker. | 50 // be handled by a foreign fetch handling ServiceWorker. |
51 static void InitializeHandler( | 51 static void InitializeHandler( |
52 net::URLRequest* request, | 52 net::URLRequest* request, |
53 ServiceWorkerContextWrapper* context_wrapper, | 53 ServiceWorkerContextWrapper* context_wrapper, |
54 storage::BlobStorageContext* blob_storage_context, | 54 storage::BlobStorageContext* blob_storage_context, |
55 int process_id, | 55 int process_id, |
56 int provider_id, | 56 int provider_id, |
57 bool skip_service_worker, | 57 bool skip_service_worker, |
58 FetchRequestMode request_mode, | 58 FetchRequestMode request_mode, |
59 FetchCredentialsMode credentials_mode, | 59 FetchCredentialsMode credentials_mode, |
60 FetchRedirectMode redirect_mode, | 60 FetchRedirectMode redirect_mode, |
61 ResourceType resource_type, | 61 ResourceType resource_type, |
62 RequestContextType request_context_type, | 62 RequestContextType request_context_type, |
63 RequestContextFrameType frame_type, | 63 RequestContextFrameType frame_type, |
64 scoped_refptr<ResourceRequestBody> body); | 64 scoped_refptr<ResourceRequestBodyImpl> body); |
65 | 65 |
66 // Returns the handler attached to |request|. This may return null | 66 // Returns the handler attached to |request|. This may return null |
67 // if no handler is attached. | 67 // if no handler is attached. |
68 static ForeignFetchRequestHandler* GetHandler(net::URLRequest* request); | 68 static ForeignFetchRequestHandler* GetHandler(net::URLRequest* request); |
69 | 69 |
70 // Creates a protocol interceptor for foreign fetch. | 70 // Creates a protocol interceptor for foreign fetch. |
71 static std::unique_ptr<net::URLRequestInterceptor> CreateInterceptor( | 71 static std::unique_ptr<net::URLRequestInterceptor> CreateInterceptor( |
72 ResourceContext* resource_context); | 72 ResourceContext* resource_context); |
73 | 73 |
74 ~ForeignFetchRequestHandler() override; | 74 ~ForeignFetchRequestHandler() override; |
75 | 75 |
76 // Called via custom URLRequestJobFactory. | 76 // Called via custom URLRequestJobFactory. |
77 net::URLRequestJob* MaybeCreateJob(net::URLRequest* request, | 77 net::URLRequestJob* MaybeCreateJob(net::URLRequest* request, |
78 net::NetworkDelegate* network_delegate, | 78 net::NetworkDelegate* network_delegate, |
79 ResourceContext* resource_context); | 79 ResourceContext* resource_context); |
80 | 80 |
81 private: | 81 private: |
82 ForeignFetchRequestHandler( | 82 ForeignFetchRequestHandler( |
83 ServiceWorkerContextWrapper* context, | 83 ServiceWorkerContextWrapper* context, |
84 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, | 84 base::WeakPtr<storage::BlobStorageContext> blob_storage_context, |
85 FetchRequestMode request_mode, | 85 FetchRequestMode request_mode, |
86 FetchCredentialsMode credentials_mode, | 86 FetchCredentialsMode credentials_mode, |
87 FetchRedirectMode redirect_mode, | 87 FetchRedirectMode redirect_mode, |
88 ResourceType resource_type, | 88 ResourceType resource_type, |
89 RequestContextType request_context_type, | 89 RequestContextType request_context_type, |
90 RequestContextFrameType frame_type, | 90 RequestContextFrameType frame_type, |
91 scoped_refptr<ResourceRequestBody> body); | 91 scoped_refptr<ResourceRequestBodyImpl> body); |
92 | 92 |
93 // Called when a ServiceWorkerRegistration has (or hasn't) been found for the | 93 // Called when a ServiceWorkerRegistration has (or hasn't) been found for the |
94 // request being handled. | 94 // request being handled. |
95 void DidFindRegistration( | 95 void DidFindRegistration( |
96 const base::WeakPtr<ServiceWorkerURLRequestJob>& job, | 96 const base::WeakPtr<ServiceWorkerURLRequestJob>& job, |
97 ServiceWorkerStatusCode status, | 97 ServiceWorkerStatusCode status, |
98 const scoped_refptr<ServiceWorkerRegistration>& registration); | 98 const scoped_refptr<ServiceWorkerRegistration>& registration); |
99 | 99 |
100 // ServiceWorkerURLRequestJob::Delegate implementation: | 100 // ServiceWorkerURLRequestJob::Delegate implementation: |
101 void OnPrepareToRestart() override; | 101 void OnPrepareToRestart() override; |
102 ServiceWorkerVersion* GetServiceWorkerVersion( | 102 ServiceWorkerVersion* GetServiceWorkerVersion( |
103 ServiceWorkerMetrics::URLRequestJobResult* result) override; | 103 ServiceWorkerMetrics::URLRequestJobResult* result) override; |
104 | 104 |
105 // Sets |job_| to nullptr, and clears all extra response info associated with | 105 // Sets |job_| to nullptr, and clears all extra response info associated with |
106 // that job. | 106 // that job. |
107 void ClearJob(); | 107 void ClearJob(); |
108 | 108 |
109 scoped_refptr<ServiceWorkerContextWrapper> context_; | 109 scoped_refptr<ServiceWorkerContextWrapper> context_; |
110 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; | 110 base::WeakPtr<storage::BlobStorageContext> blob_storage_context_; |
111 ResourceType resource_type_; | 111 ResourceType resource_type_; |
112 FetchRequestMode request_mode_; | 112 FetchRequestMode request_mode_; |
113 FetchCredentialsMode credentials_mode_; | 113 FetchCredentialsMode credentials_mode_; |
114 FetchRedirectMode redirect_mode_; | 114 FetchRedirectMode redirect_mode_; |
115 RequestContextType request_context_type_; | 115 RequestContextType request_context_type_; |
116 RequestContextFrameType frame_type_; | 116 RequestContextFrameType frame_type_; |
117 scoped_refptr<ResourceRequestBody> body_; | 117 scoped_refptr<ResourceRequestBodyImpl> body_; |
118 | 118 |
119 base::WeakPtr<ServiceWorkerURLRequestJob> job_; | 119 base::WeakPtr<ServiceWorkerURLRequestJob> job_; |
120 scoped_refptr<ServiceWorkerVersion> target_worker_; | 120 scoped_refptr<ServiceWorkerVersion> target_worker_; |
121 | 121 |
122 // True if the next time this request is started, the response should be | 122 // True if the next time this request is started, the response should be |
123 // delivered from the network, bypassing the ServiceWorker. | 123 // delivered from the network, bypassing the ServiceWorker. |
124 bool use_network_ = false; | 124 bool use_network_ = false; |
125 | 125 |
126 base::WeakPtrFactory<ForeignFetchRequestHandler> weak_factory_; | 126 base::WeakPtrFactory<ForeignFetchRequestHandler> weak_factory_; |
127 | 127 |
128 DISALLOW_COPY_AND_ASSIGN(ForeignFetchRequestHandler); | 128 DISALLOW_COPY_AND_ASSIGN(ForeignFetchRequestHandler); |
129 }; | 129 }; |
130 | 130 |
131 } // namespace content | 131 } // namespace content |
132 | 132 |
133 #endif // CONTENT_BROWSER_SERVICE_WORKER_FOREIGN_FETCH_REQUEST_HANDLER_H_ | 133 #endif // CONTENT_BROWSER_SERVICE_WORKER_FOREIGN_FETCH_REQUEST_HANDLER_H_ |
OLD | NEW |