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; |
32 | 35 |
33 // An instance is created for each net::URLRequest. The instance survives all | 36 // 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 | 37 // http transactions involved in the processing of its net::URLRequest, and is |
35 // given the opportunity to hijack the request along the way. Callers | 38 // given the opportunity to hijack the request along the way. Callers |
36 // should use AppCacheHost::CreateRequestHandler to manufacture instances | 39 // should use AppCacheHost::CreateRequestHandler to manufacture instances |
37 // that can retrieve resources for a particular host. | 40 // that can retrieve resources for a particular host. |
38 class CONTENT_EXPORT AppCacheRequestHandler | 41 class CONTENT_EXPORT AppCacheRequestHandler |
39 : public base::SupportsUserData::Data, | 42 : public base::SupportsUserData::Data, |
40 public AppCacheHost::Observer, | 43 public AppCacheHost::Observer, |
41 public AppCacheServiceImpl::Observer, | 44 public AppCacheServiceImpl::Observer, |
42 public AppCacheStorage::Delegate { | 45 public AppCacheStorage::Delegate, |
| 46 public URLLoaderRequestHandler { |
43 public: | 47 public: |
44 ~AppCacheRequestHandler() override; | 48 ~AppCacheRequestHandler() override; |
45 | 49 |
46 // These are called on each request intercept opportunity. | 50 // These are called on each request intercept opportunity. |
47 AppCacheJob* MaybeLoadResource(net::NetworkDelegate* network_delegate); | 51 AppCacheJob* MaybeLoadResource(net::NetworkDelegate* network_delegate); |
48 AppCacheJob* MaybeLoadFallbackForRedirect( | 52 AppCacheJob* MaybeLoadFallbackForRedirect( |
49 net::NetworkDelegate* network_delegate, | 53 net::NetworkDelegate* network_delegate, |
50 const GURL& location); | 54 const GURL& location); |
51 AppCacheJob* MaybeLoadFallbackForResponse( | 55 AppCacheJob* MaybeLoadFallbackForResponse( |
52 net::NetworkDelegate* network_delegate); | 56 net::NetworkDelegate* network_delegate); |
53 | 57 |
54 void GetExtraResponseInfo(int64_t* cache_id, GURL* manifest_url); | 58 void GetExtraResponseInfo(int64_t* cache_id, GURL* manifest_url); |
55 | 59 |
56 // Methods to support cross site navigations. | 60 // Methods to support cross site navigations. |
57 void PrepareForCrossSiteTransfer(int old_process_id); | 61 void PrepareForCrossSiteTransfer(int old_process_id); |
58 void CompleteCrossSiteTransfer(int new_process_id, int new_host_id); | 62 void CompleteCrossSiteTransfer(int new_process_id, int new_host_id); |
59 void MaybeCompleteCrossSiteTransferInOldProcess(int old_process_id); | 63 void MaybeCompleteCrossSiteTransferInOldProcess(int old_process_id); |
60 | 64 |
61 // Useful for detecting storage partition mismatches in the context | 65 // Useful for detecting storage partition mismatches in the context |
62 // of cross site transfer navigations. | 66 // of cross site transfer navigations. |
63 bool SanityCheckIsSameService(AppCacheService* service) { | 67 bool SanityCheckIsSameService(AppCacheService* service) { |
64 return !host_ || (host_->service() == service); | 68 return !host_ || (host_->service() == service); |
65 } | 69 } |
66 | 70 |
67 static bool IsMainResourceType(ResourceType type) { | 71 static bool IsMainResourceType(ResourceType type) { |
68 return IsResourceTypeFrame(type) || | 72 return IsResourceTypeFrame(type) || |
69 type == RESOURCE_TYPE_SHARED_WORKER; | 73 type == RESOURCE_TYPE_SHARED_WORKER; |
70 } | 74 } |
71 | 75 |
| 76 static std::unique_ptr<AppCacheRequestHandler> |
| 77 InitializeForNavigationNetworkService( |
| 78 const ResourceRequest& request, |
| 79 AppCacheNavigationHandleCore* appcache_handle_core); |
| 80 |
72 private: | 81 private: |
73 friend class AppCacheHost; | 82 friend class AppCacheHost; |
74 | 83 |
75 // Callers should use AppCacheHost::CreateRequestHandler. | 84 // Callers should use AppCacheHost::CreateRequestHandler. |
76 AppCacheRequestHandler(AppCacheHost* host, | 85 AppCacheRequestHandler(AppCacheHost* host, |
77 ResourceType resource_type, | 86 ResourceType resource_type, |
78 bool should_reset_appcache, | 87 bool should_reset_appcache, |
79 std::unique_ptr<AppCacheRequest> request); | 88 std::unique_ptr<AppCacheRequest> request); |
80 | 89 |
81 // AppCacheHost::Observer override | 90 // AppCacheHost::Observer override |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 // Sub-resource loading ------------------------------------- | 137 // Sub-resource loading ------------------------------------- |
129 // Dedicated worker and all manner of sub-resources are handled here. | 138 // Dedicated worker and all manner of sub-resources are handled here. |
130 | 139 |
131 std::unique_ptr<AppCacheJob> MaybeLoadSubResource( | 140 std::unique_ptr<AppCacheJob> MaybeLoadSubResource( |
132 net::NetworkDelegate* network_delegate); | 141 net::NetworkDelegate* network_delegate); |
133 void ContinueMaybeLoadSubResource(); | 142 void ContinueMaybeLoadSubResource(); |
134 | 143 |
135 // AppCacheHost::Observer override | 144 // AppCacheHost::Observer override |
136 void OnCacheSelectionComplete(AppCacheHost* host) override; | 145 void OnCacheSelectionComplete(AppCacheHost* host) override; |
137 | 146 |
| 147 // URLLoaderRequestHandler override |
| 148 void MaybeCreateLoader(const ResourceRequest& resource_request, |
| 149 ResourceContext* resource_context, |
| 150 LoaderCallback callback) override; |
| 151 |
138 // Data members ----------------------------------------------- | 152 // Data members ----------------------------------------------- |
139 | 153 |
140 // What host we're servicing a request for. | 154 // What host we're servicing a request for. |
141 AppCacheHost* host_; | 155 AppCacheHost* host_; |
142 | 156 |
143 // Frame vs subresource vs sharedworker loads are somewhat different. | 157 // Frame vs subresource vs sharedworker loads are somewhat different. |
144 ResourceType resource_type_; | 158 ResourceType resource_type_; |
145 | 159 |
146 // True if corresponding AppCache group should be resetted before load. | 160 // True if corresponding AppCache group should be resetted before load. |
147 bool should_reset_appcache_; | 161 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 | 202 // Cached information about the response being currently served by the |
189 // AppCache, if there is one. | 203 // AppCache, if there is one. |
190 int cache_id_; | 204 int cache_id_; |
191 GURL manifest_url_; | 205 GURL manifest_url_; |
192 | 206 |
193 // Backptr to the central service object. | 207 // Backptr to the central service object. |
194 AppCacheServiceImpl* service_; | 208 AppCacheServiceImpl* service_; |
195 | 209 |
196 std::unique_ptr<AppCacheRequest> request_; | 210 std::unique_ptr<AppCacheRequest> request_; |
197 | 211 |
| 212 // In the network service world we are queried via the URLLoaderRequestHandler |
| 213 // interface to see if the navigation request can be handled via the |
| 214 // AppCache. We hold onto the AppCache job created here until the client |
| 215 // binds to it (Serviced via AppCache). If the request cannot be handled via |
| 216 // the AppCache, we delete the job. |
| 217 std::unique_ptr<AppCacheJob> navigation_request_job_; |
| 218 |
198 friend class content::AppCacheRequestHandlerTest; | 219 friend class content::AppCacheRequestHandlerTest; |
199 DISALLOW_COPY_AND_ASSIGN(AppCacheRequestHandler); | 220 DISALLOW_COPY_AND_ASSIGN(AppCacheRequestHandler); |
200 }; | 221 }; |
201 | 222 |
202 } // namespace content | 223 } // namespace content |
203 | 224 |
204 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_REQUEST_HANDLER_H_ | 225 #endif // CONTENT_BROWSER_APPCACHE_APPCACHE_REQUEST_HANDLER_H_ |
OLD | NEW |