| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #include "content/browser/appcache/appcache_subresource_url_factory.h" | 5 #include "content/browser/appcache/appcache_subresource_url_factory.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "content/browser/appcache/appcache_host.h" |
| 9 #include "content/browser/appcache/appcache_request_handler.h" | 10 #include "content/browser/appcache/appcache_request_handler.h" |
| 10 #include "content/browser/appcache/appcache_url_loader_job.h" | 11 #include "content/browser/appcache/appcache_url_loader_job.h" |
| 11 #include "content/browser/appcache/appcache_url_loader_request.h" | 12 #include "content/browser/appcache/appcache_url_loader_request.h" |
| 12 #include "content/browser/url_loader_factory_getter.h" | 13 #include "content/browser/url_loader_factory_getter.h" |
| 13 #include "content/common/resource_request.h" | 14 #include "content/common/resource_request.h" |
| 14 #include "content/common/url_loader_factory.mojom.h" | 15 #include "content/common/url_loader_factory.mojom.h" |
| 15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 16 #include "mojo/public/cpp/bindings/binding.h" | 17 #include "mojo/public/cpp/bindings/binding.h" |
| 17 #include "mojo/public/cpp/bindings/binding_set.h" | 18 #include "mojo/public/cpp/bindings/binding_set.h" |
| 18 #include "mojo/public/cpp/bindings/interface_ptr.h" | 19 #include "mojo/public/cpp/bindings/interface_ptr.h" |
| 19 #include "net/traffic_annotation/network_traffic_annotation.h" | 20 #include "net/traffic_annotation/network_traffic_annotation.h" |
| 20 | 21 |
| 21 namespace content { | 22 namespace content { |
| 22 | 23 |
| 24 SubresourceLoadInfo::SubresourceLoadInfo() |
| 25 : routing_id(-1), request_id(-1), options(0) {} |
| 26 |
| 27 SubresourceLoadInfo::~SubresourceLoadInfo() {} |
| 28 |
| 23 // Implements the URLLoaderFactory mojom for AppCache requests. | 29 // Implements the URLLoaderFactory mojom for AppCache requests. |
| 24 AppCacheSubresourceURLFactory::AppCacheSubresourceURLFactory( | 30 AppCacheSubresourceURLFactory::AppCacheSubresourceURLFactory( |
| 25 mojom::URLLoaderFactoryRequest request, | 31 mojom::URLLoaderFactoryRequest request, |
| 26 URLLoaderFactoryGetter* default_url_loader_factory_getter) | 32 URLLoaderFactoryGetter* default_url_loader_factory_getter, |
| 33 base::WeakPtr<AppCacheHost> host) |
| 27 : binding_(this, std::move(request)), | 34 : binding_(this, std::move(request)), |
| 28 default_url_loader_factory_getter_(default_url_loader_factory_getter) { | 35 default_url_loader_factory_getter_(default_url_loader_factory_getter), |
| 36 appcache_host_(host->GetWeakPtr()) { |
| 29 binding_.set_connection_error_handler( | 37 binding_.set_connection_error_handler( |
| 30 base::Bind(&AppCacheSubresourceURLFactory::OnConnectionError, | 38 base::Bind(&AppCacheSubresourceURLFactory::OnConnectionError, |
| 31 base::Unretained(this))); | 39 base::Unretained(this))); |
| 32 } | 40 } |
| 33 | 41 |
| 34 AppCacheSubresourceURLFactory::~AppCacheSubresourceURLFactory() {} | 42 AppCacheSubresourceURLFactory::~AppCacheSubresourceURLFactory() {} |
| 35 | 43 |
| 36 // static | 44 // static |
| 37 mojom::URLLoaderFactoryPtr | 45 AppCacheSubresourceURLFactory* |
| 38 AppCacheSubresourceURLFactory::CreateURLLoaderFactory( | 46 AppCacheSubresourceURLFactory::CreateURLLoaderFactory( |
| 39 URLLoaderFactoryGetter* default_url_loader_factory_getter) { | 47 URLLoaderFactoryGetter* default_url_loader_factory_getter, |
| 40 mojom::URLLoaderFactoryPtr loader_factory; | 48 base::WeakPtr<AppCacheHost> host, |
| 41 mojom::URLLoaderFactoryRequest request = mojo::MakeRequest(&loader_factory); | 49 mojom::URLLoaderFactoryPtr* loader_factory) { |
| 50 mojom::URLLoaderFactoryRequest request = mojo::MakeRequest(loader_factory); |
| 42 | 51 |
| 43 // This instance will get deleted when the client drops the connection. | 52 // This instance will get deleted when the client drops the connection. |
| 44 // Please see OnConnectionError() for details. | 53 // Please see OnConnectionError() for details. |
| 45 new AppCacheSubresourceURLFactory(std::move(request), | 54 return new AppCacheSubresourceURLFactory( |
| 46 default_url_loader_factory_getter); | 55 std::move(request), default_url_loader_factory_getter, host); |
| 47 return loader_factory; | |
| 48 } | 56 } |
| 49 | 57 |
| 50 void AppCacheSubresourceURLFactory::CreateLoaderAndStart( | 58 void AppCacheSubresourceURLFactory::CreateLoaderAndStart( |
| 51 mojom::URLLoaderAssociatedRequest url_loader_request, | 59 mojom::URLLoaderAssociatedRequest url_loader_request, |
| 52 int32_t routing_id, | 60 int32_t routing_id, |
| 53 int32_t request_id, | 61 int32_t request_id, |
| 54 uint32_t options, | 62 uint32_t options, |
| 55 const ResourceRequest& request, | 63 const ResourceRequest& request, |
| 56 mojom::URLLoaderClientPtr client, | 64 mojom::URLLoaderClientPtr client, |
| 57 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) { | 65 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) { |
| 58 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 66 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 59 DLOG(WARNING) << "Received request for loading : " << request.url.spec(); | 67 DLOG(WARNING) << "Received request for loading : " << request.url.spec(); |
| 60 default_url_loader_factory_getter_->GetNetworkFactory() | 68 |
| 61 ->get() | 69 // If the host is invalid, it means that the renderer has probably died. |
| 62 ->CreateLoaderAndStart(mojom::URLLoaderAssociatedRequest(), routing_id, | 70 // (Frame has navigated elsewhere?) |
| 63 request_id, options, request, std::move(client), | 71 if (!appcache_host_.get()) |
| 64 traffic_annotation); | 72 return; |
| 73 |
| 74 std::unique_ptr<AppCacheRequestHandler> handler = |
| 75 appcache_host_->CreateRequestHandler( |
| 76 AppCacheURLLoaderRequest::Create(request), request.resource_type, |
| 77 request.should_reset_appcache); |
| 78 if (!handler) |
| 79 return; |
| 80 |
| 81 handler->set_network_url_loader_factory_getter( |
| 82 default_url_loader_factory_getter_.get()); |
| 83 |
| 84 std::unique_ptr<SubresourceLoadInfo> load_info(new SubresourceLoadInfo()); |
| 85 load_info->url_loader_request = std::move(url_loader_request); |
| 86 load_info->routing_id = routing_id; |
| 87 load_info->request_id = request_id; |
| 88 load_info->options = options; |
| 89 load_info->request = request; |
| 90 load_info->client = std::move(client); |
| 91 load_info->traffic_annotation = traffic_annotation; |
| 92 |
| 93 handler->set_subresource_request_load_info(std::move(load_info)); |
| 94 |
| 95 handler->MaybeLoadResource(nullptr); |
| 96 // The handler is owned by the job. |
| 97 handler.release(); |
| 65 } | 98 } |
| 66 | 99 |
| 67 void AppCacheSubresourceURLFactory::SyncLoad(int32_t routing_id, | 100 void AppCacheSubresourceURLFactory::SyncLoad(int32_t routing_id, |
| 68 int32_t request_id, | 101 int32_t request_id, |
| 69 const ResourceRequest& request, | 102 const ResourceRequest& request, |
| 70 SyncLoadCallback callback) { | 103 SyncLoadCallback callback) { |
| 71 NOTREACHED(); | 104 NOTREACHED(); |
| 72 } | 105 } |
| 73 | 106 |
| 74 void AppCacheSubresourceURLFactory::OnConnectionError() { | 107 void AppCacheSubresourceURLFactory::OnConnectionError() { |
| 75 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); | 108 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); |
| 76 } | 109 } |
| 77 | 110 |
| 78 } // namespace content | 111 } // namespace content |
| OLD | NEW |