Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_APPCACHE_APPCACHE_REQUEST_HANDLER_H_ | 5 #ifndef CONTENT_BROWSER_APPCACHE_APPCACHE_REQUEST_HANDLER_H_ |
| 6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_REQUEST_HANDLER_H_ | 6 #define CONTENT_BROWSER_APPCACHE_APPCACHE_REQUEST_HANDLER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
| 15 #include "base/supports_user_data.h" | 15 #include "base/supports_user_data.h" |
| 16 #include "content/browser/appcache/appcache_entry.h" | 16 #include "content/browser/appcache/appcache_entry.h" |
| 17 #include "content/browser/appcache/appcache_host.h" | 17 #include "content/browser/appcache/appcache_host.h" |
| 18 #include "content/browser/appcache/appcache_service_impl.h" | 18 #include "content/browser/appcache/appcache_service_impl.h" |
| 19 #include "content/browser/loader/url_loader_request_handler.h" | |
| 19 #include "content/common/content_export.h" | 20 #include "content/common/content_export.h" |
| 20 #include "content/public/common/resource_type.h" | 21 #include "content/public/common/resource_type.h" |
| 21 | 22 |
| 22 namespace net { | 23 namespace net { |
| 23 class NetworkDelegate; | 24 class NetworkDelegate; |
| 24 class URLRequest; | 25 class URLRequest; |
| 25 } // namespace net | 26 } // namespace net |
| 26 | 27 |
| 27 namespace content { | 28 namespace content { |
| 28 class AppCacheJob; | 29 class AppCacheJob; |
| 30 class AppCacheNavigationHandleCore; | |
| 29 class AppCacheRequest; | 31 class AppCacheRequest; |
| 30 class AppCacheRequestHandlerTest; | 32 class AppCacheRequestHandlerTest; |
| 31 class AppCacheURLRequestJob; | 33 class AppCacheURLRequestJob; |
| 34 struct ResourceRequest; | |
| 35 class URLLoaderFactoryGetter; | |
| 32 | 36 |
| 33 // An instance is created for each net::URLRequest. The instance survives all | 37 // An instance is created for each net::URLRequest. The instance survives all |
| 34 // http transactions involved in the processing of its net::URLRequest, and is | 38 // http transactions involved in the processing of its net::URLRequest, and is |
| 35 // given the opportunity to hijack the request along the way. Callers | 39 // given the opportunity to hijack the request along the way. Callers |
| 36 // should use AppCacheHost::CreateRequestHandler to manufacture instances | 40 // should use AppCacheHost::CreateRequestHandler to manufacture instances |
| 37 // that can retrieve resources for a particular host. | 41 // that can retrieve resources for a particular host. |
| 38 class CONTENT_EXPORT AppCacheRequestHandler | 42 class CONTENT_EXPORT AppCacheRequestHandler |
| 39 : public base::SupportsUserData::Data, | 43 : public base::SupportsUserData::Data, |
| 40 public AppCacheHost::Observer, | 44 public AppCacheHost::Observer, |
| 41 public AppCacheServiceImpl::Observer, | 45 public AppCacheServiceImpl::Observer, |
| 42 public AppCacheStorage::Delegate { | 46 public AppCacheStorage::Delegate, |
| 47 public URLLoaderRequestHandler { | |
| 43 public: | 48 public: |
| 44 ~AppCacheRequestHandler() override; | 49 ~AppCacheRequestHandler() override; |
| 45 | 50 |
| 46 // These are called on each request intercept opportunity. | 51 // These are called on each request intercept opportunity. |
| 47 AppCacheJob* MaybeLoadResource(net::NetworkDelegate* network_delegate); | 52 AppCacheJob* MaybeLoadResource(net::NetworkDelegate* network_delegate); |
| 48 AppCacheJob* MaybeLoadFallbackForRedirect( | 53 AppCacheJob* MaybeLoadFallbackForRedirect( |
| 49 net::NetworkDelegate* network_delegate, | 54 net::NetworkDelegate* network_delegate, |
| 50 const GURL& location); | 55 const GURL& location); |
| 51 AppCacheJob* MaybeLoadFallbackForResponse( | 56 AppCacheJob* MaybeLoadFallbackForResponse( |
| 52 net::NetworkDelegate* network_delegate); | 57 net::NetworkDelegate* network_delegate); |
| 53 | 58 |
| 54 void GetExtraResponseInfo(int64_t* cache_id, GURL* manifest_url); | 59 void GetExtraResponseInfo(int64_t* cache_id, GURL* manifest_url); |
| 55 | 60 |
| 56 // Methods to support cross site navigations. | 61 // Methods to support cross site navigations. |
| 57 void PrepareForCrossSiteTransfer(int old_process_id); | 62 void PrepareForCrossSiteTransfer(int old_process_id); |
| 58 void CompleteCrossSiteTransfer(int new_process_id, int new_host_id); | 63 void CompleteCrossSiteTransfer(int new_process_id, int new_host_id); |
| 59 void MaybeCompleteCrossSiteTransferInOldProcess(int old_process_id); | 64 void MaybeCompleteCrossSiteTransferInOldProcess(int old_process_id); |
| 60 | 65 |
| 61 // Useful for detecting storage partition mismatches in the context | 66 // Useful for detecting storage partition mismatches in the context |
| 62 // of cross site transfer navigations. | 67 // of cross site transfer navigations. |
| 63 bool SanityCheckIsSameService(AppCacheService* service) { | 68 bool SanityCheckIsSameService(AppCacheService* service) { |
| 64 return !host_ || (host_->service() == service); | 69 return !host_ || (host_->service() == service); |
| 65 } | 70 } |
| 66 | 71 |
| 67 static bool IsMainResourceType(ResourceType type) { | 72 static bool IsMainResourceType(ResourceType type) { |
| 68 return IsResourceTypeFrame(type) || | 73 return IsResourceTypeFrame(type) || |
| 69 type == RESOURCE_TYPE_SHARED_WORKER; | 74 type == RESOURCE_TYPE_SHARED_WORKER; |
| 70 } | 75 } |
| 71 | 76 |
| 77 static std::unique_ptr<AppCacheRequestHandler> | |
| 78 InitializeForNavigationNetworkService( | |
| 79 const ResourceRequest& request, | |
| 80 AppCacheNavigationHandleCore* appcache_handle_core, | |
| 81 URLLoaderFactoryGetter* url_loader_factory_getter); | |
|
kinuko
2017/06/06 08:07:30
Yeah thanks for making this look similar to SW cas
ananta
2017/06/06 20:49:15
+1
| |
| 82 | |
| 72 private: | 83 private: |
| 73 friend class AppCacheHost; | 84 friend class AppCacheHost; |
| 74 | 85 |
| 75 // Callers should use AppCacheHost::CreateRequestHandler. | 86 // Callers should use AppCacheHost::CreateRequestHandler. |
| 76 AppCacheRequestHandler(AppCacheHost* host, | 87 AppCacheRequestHandler(AppCacheHost* host, |
| 77 ResourceType resource_type, | 88 ResourceType resource_type, |
| 78 bool should_reset_appcache, | 89 bool should_reset_appcache, |
| 79 std::unique_ptr<AppCacheRequest> request); | 90 std::unique_ptr<AppCacheRequest> request); |
| 80 | 91 |
| 81 // AppCacheHost::Observer override | 92 // AppCacheHost::Observer override |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 // Sub-resource loading ------------------------------------- | 139 // Sub-resource loading ------------------------------------- |
| 129 // Dedicated worker and all manner of sub-resources are handled here. | 140 // Dedicated worker and all manner of sub-resources are handled here. |
| 130 | 141 |
| 131 std::unique_ptr<AppCacheJob> MaybeLoadSubResource( | 142 std::unique_ptr<AppCacheJob> MaybeLoadSubResource( |
| 132 net::NetworkDelegate* network_delegate); | 143 net::NetworkDelegate* network_delegate); |
| 133 void ContinueMaybeLoadSubResource(); | 144 void ContinueMaybeLoadSubResource(); |
| 134 | 145 |
| 135 // AppCacheHost::Observer override | 146 // AppCacheHost::Observer override |
| 136 void OnCacheSelectionComplete(AppCacheHost* host) override; | 147 void OnCacheSelectionComplete(AppCacheHost* host) override; |
| 137 | 148 |
| 149 // URLLoaderRequestHandler override | |
| 150 void MaybeCreateLoaderFactory(const ResourceRequest& resource_request, | |
| 151 ResourceContext* resource_context, | |
| 152 LoaderFactoryCallback callback) override; | |
| 153 | |
| 138 // Data members ----------------------------------------------- | 154 // Data members ----------------------------------------------- |
| 139 | 155 |
| 140 // What host we're servicing a request for. | 156 // What host we're servicing a request for. |
| 141 AppCacheHost* host_; | 157 AppCacheHost* host_; |
| 142 | 158 |
| 143 // Frame vs subresource vs sharedworker loads are somewhat different. | 159 // Frame vs subresource vs sharedworker loads are somewhat different. |
| 144 ResourceType resource_type_; | 160 ResourceType resource_type_; |
| 145 | 161 |
| 146 // True if corresponding AppCache group should be resetted before load. | 162 // True if corresponding AppCache group should be resetted before load. |
| 147 bool should_reset_appcache_; | 163 bool should_reset_appcache_; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 // Cached information about the response being currently served by the | 204 // Cached information about the response being currently served by the |
| 189 // AppCache, if there is one. | 205 // AppCache, if there is one. |
| 190 int cache_id_; | 206 int cache_id_; |
| 191 GURL manifest_url_; | 207 GURL manifest_url_; |
| 192 | 208 |
| 193 // Backptr to the central service object. | 209 // Backptr to the central service object. |
| 194 AppCacheServiceImpl* service_; | 210 AppCacheServiceImpl* service_; |
| 195 | 211 |
| 196 std::unique_ptr<AppCacheRequest> request_; | 212 std::unique_ptr<AppCacheRequest> request_; |
| 197 | 213 |
| 214 // In the network service world we are queried via the URLLoaderRequestHandler | |
| 215 // interface to see if the navigation request can be serviced via the | |
| 216 // AppCache. We hold onto the AppCache job created here until the client | |
| 217 // binds to it (Serviced via AppCache). If the request cannot be serviced via | |
| 218 // the AppCache, we delete the job. | |
| 219 std::unique_ptr<AppCacheJob> navigation_request_job_; | |
| 220 | |
| 221 // The Callback to be invoked in the network service land to indicate if | |
| 222 // the request can be serviced via the AppCache. | |
| 223 LoaderFactoryCallback loader_factory_callback_; | |
| 224 | |
| 225 // In network service world used to to get the default network service. | |
| 226 scoped_refptr<URLLoaderFactoryGetter> url_loader_factory_getter_; | |
| 227 | |
| 228 mojom::URLLoaderFactoryPtr appcache_factory_; | |
| 229 | |
| 198 friend class content::AppCacheRequestHandlerTest; | 230 friend class content::AppCacheRequestHandlerTest; |
| 199 DISALLOW_COPY_AND_ASSIGN(AppCacheRequestHandler); | 231 DISALLOW_COPY_AND_ASSIGN(AppCacheRequestHandler); |
| 200 }; | 232 }; |
| 201 | 233 |
| 202 } // namespace content | 234 } // namespace content |
| 203 | 235 |
| 204 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_REQUEST_HANDLER_H_ | 236 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_REQUEST_HANDLER_H_ |
| OLD | NEW |