Chromium Code Reviews| Index: content/browser/appcache/appcache_request_handler.cc |
| diff --git a/content/browser/appcache/appcache_request_handler.cc b/content/browser/appcache/appcache_request_handler.cc |
| index 870fa7d35200c73a52989a24241190d1cd360aa3..f957a1661e9d929e900458e003b79f32f92fe24e 100644 |
| --- a/content/browser/appcache/appcache_request_handler.cc |
| +++ b/content/browser/appcache/appcache_request_handler.cc |
| @@ -9,10 +9,16 @@ |
| #include "base/bind.h" |
| #include "content/browser/appcache/appcache.h" |
| #include "content/browser/appcache/appcache_backend_impl.h" |
| +#include "content/browser/appcache/appcache_host.h" |
| +#include "content/browser/appcache/appcache_navigation_handle_core.h" |
| #include "content/browser/appcache/appcache_policy.h" |
| #include "content/browser/appcache/appcache_request.h" |
| +#include "content/browser/appcache/appcache_url_loader_factory.h" |
| +#include "content/browser/appcache/appcache_url_loader_job.h" |
| +#include "content/browser/appcache/appcache_url_loader_request.h" |
| #include "content/browser/appcache/appcache_url_request_job.h" |
| #include "content/browser/service_worker/service_worker_request_handler.h" |
| +#include "content/browser/url_loader_factory_getter.h" |
| #include "net/url_request/url_request.h" |
| #include "net/url_request/url_request_job.h" |
| @@ -223,6 +229,20 @@ void AppCacheRequestHandler::MaybeCompleteCrossSiteTransferInOldProcess( |
| CompleteCrossSiteTransfer(old_process_id_, old_host_id_); |
| } |
| +// static |
| +std::unique_ptr<AppCacheRequestHandler> |
| +AppCacheRequestHandler::InitializeForNavigationNetworkService( |
| + const ResourceRequest& request, |
| + AppCacheNavigationHandleCore* appcache_handle_core, |
| + URLLoaderFactoryGetter* url_loader_factory_getter) { |
| + std::unique_ptr<AppCacheRequestHandler> handler = |
|
jam
2017/06/07 01:42:17
I thought an earlier patchset didn't create an app
michaeln
2017/06/07 02:53:45
to support redirects to appcached pages, we can't
ananta
2017/06/07 20:57:16
You are correct there. However we decided to go wi
|
| + appcache_handle_core->host()->CreateRequestHandler( |
|
jam
2017/06/07 01:42:17
can't this return null?
michaeln
2017/06/07 02:53:45
yes, it can
ananta
2017/06/07 20:57:16
yes
|
| + AppCacheURLLoaderRequest::Create(request), request.resource_type, |
| + request.should_reset_appcache); |
| + handler->url_loader_factory_getter_ = url_loader_factory_getter; |
| + return handler; |
| +} |
| + |
| void AppCacheRequestHandler::OnDestructionImminent(AppCacheHost* host) { |
| storage()->CancelDelegateCallbacks(this); |
| host_ = NULL; // no need to RemoveObserver, the host is being deleted |
| @@ -264,6 +284,12 @@ void AppCacheRequestHandler::DeliverAppCachedResponse( |
| if (IsResourceTypeFrame(resource_type_) && !namespace_entry_url.is_empty()) |
| host_->NotifyMainResourceIsNamespaceEntry(namespace_entry_url); |
| + if (navigation_request_job_.get()) { |
| + appcache_factory_ = AppCacheURLLoaderFactory::CreateURLLoaderFactory( |
| + url_loader_factory_getter_.get(), |
| + navigation_request_job_.release()); |
| + std::move(loader_factory_callback_).Run(appcache_factory_.get()); |
|
michaeln
2017/06/07 02:53:45
Do we still need to retain the appcache_factory_ i
ananta
2017/06/07 20:57:16
Will look into that. I am not sure her patch lande
michaeln
2017/06/08 02:54:00
This logic also could be hoisted into the AppCache
ananta
2017/06/08 05:58:39
Done.
|
| + } |
| job_->DeliverAppCachedResponse(manifest_url, cache_id, entry, is_fallback); |
| } |
| @@ -278,6 +304,16 @@ void AppCacheRequestHandler::DeliverNetworkResponse() { |
| DCHECK(job_.get() && job_->IsWaiting()); |
| DCHECK_EQ(kAppCacheNoCacheId, cache_id_); |
| DCHECK(manifest_url_.is_empty()); |
| + |
| + // In network service land, if we are processing a navigation request, we |
| + // need to inform the loader callback that we are not going to handle this |
| + // request. |
| + if (navigation_request_job_.get()) { |
|
michaeln
2017/06/08 02:54:00
This bit of logic to call the loadercallback could
ananta
2017/06/08 05:58:39
Done.
|
| + std::move(loader_factory_callback_).Run(nullptr); |
| + navigation_request_job_.reset(nullptr); |
| + return; |
| + } |
| + |
| job_->DeliverNetworkResponse(); |
| } |
| @@ -316,12 +352,22 @@ std::unique_ptr<AppCacheJob> AppCacheRequestHandler::MaybeLoadMainResource( |
| // If a page falls into the scope of a ServiceWorker, any matching AppCaches |
| // should be ignored. This depends on the ServiceWorker handler being invoked |
| // prior to the AppCache handler. |
| - if (ServiceWorkerRequestHandler::IsControlledByServiceWorker( |
| + // TODO(ananta) |
| + // We need to handle this for AppCache requests initiated for the network |
| + // service |
| + if (request_->GetURLRequest() && |
| + ServiceWorkerRequestHandler::IsControlledByServiceWorker( |
| request_->GetURLRequest())) { |
| host_->enable_cache_selection(false); |
| return nullptr; |
| } |
| + if (storage()->IsInitialized() && |
| + service_->storage()->usage_map()->find(request_->GetURL().GetOrigin()) == |
|
michaeln
2017/06/07 02:53:45
@jam, this is where the origin test goes
|
| + service_->storage()->usage_map()->end()) { |
| + return nullptr; |
| + } |
| + |
| host_->enable_cache_selection(true); |
| const AppCacheHost* spawning_host = |
| @@ -503,4 +549,18 @@ void AppCacheRequestHandler::OnCacheSelectionComplete(AppCacheHost* host) { |
| ContinueMaybeLoadSubResource(); |
| } |
| +void AppCacheRequestHandler::MaybeCreateLoaderFactory( |
| + const ResourceRequest& resource_request, |
| + ResourceContext* resource_context, |
| + LoaderFactoryCallback callback) { |
| + navigation_request_job_ = MaybeLoadMainResource(nullptr); |
| + if (!navigation_request_job_.get()) { |
| + std::move(callback).Run(nullptr); |
| + return; |
| + } |
| + navigation_request_job_->AsURLLoaderJob()->SetURLLoaderFactoryGetter( |
| + url_loader_factory_getter_.get()); |
| + loader_factory_callback_ = std::move(callback); |
|
michaeln
2017/06/08 02:54:00
This datamember could go inside the AppCacheUrlLoa
ananta
2017/06/08 05:58:39
Done.
|
| +} |
| + |
| } // namespace content |