| 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/webui/web_ui_url_loader_factory.h" | 5 #include "content/browser/webui/web_ui_url_loader_factory.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/ref_counted_memory.h" | 12 #include "base/memory/ref_counted_memory.h" |
| 13 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
| 14 #include "content/browser/blob_storage/blob_internals_url_loader.h" | 14 #include "content/browser/blob_storage/blob_internals_url_loader.h" |
| 15 #include "content/browser/blob_storage/chrome_blob_storage_context.h" | 15 #include "content/browser/blob_storage/chrome_blob_storage_context.h" |
| 16 #include "content/browser/frame_host/frame_tree_node.h" | 16 #include "content/browser/frame_host/frame_tree_node.h" |
| 17 #include "content/browser/frame_host/render_frame_host_impl.h" | 17 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 18 #include "content/browser/histogram_internals_url_loader.h" | 18 #include "content/browser/histogram_internals_url_loader.h" |
| 19 #include "content/browser/resource_context_impl.h" | 19 #include "content/browser/resource_context_impl.h" |
| 20 #include "content/browser/storage_partition_impl.h" |
| 20 #include "content/browser/webui/network_error_url_loader.h" | 21 #include "content/browser/webui/network_error_url_loader.h" |
| 21 #include "content/browser/webui/url_data_manager_backend.h" | 22 #include "content/browser/webui/url_data_manager_backend.h" |
| 22 #include "content/browser/webui/url_data_source_impl.h" | 23 #include "content/browser/webui/url_data_source_impl.h" |
| 23 #include "content/common/network_service.mojom.h" | 24 #include "content/common/network_service.mojom.h" |
| 24 #include "content/public/browser/browser_context.h" | 25 #include "content/public/browser/browser_context.h" |
| 25 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 26 #include "content/public/browser/render_process_host.h" | 27 #include "content/public/browser/render_process_host.h" |
| 27 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 28 #include "content/public/common/service_manager_connection.h" | |
| 29 #include "content/public/common/service_names.mojom.h" | |
| 30 #include "content/public/common/url_constants.h" | 29 #include "content/public/common/url_constants.h" |
| 31 #include "mojo/public/cpp/bindings/binding_set.h" | 30 #include "mojo/public/cpp/bindings/binding_set.h" |
| 32 #include "services/service_manager/public/cpp/connector.h" | |
| 33 #include "third_party/zlib/google/compression_utils.h" | 31 #include "third_party/zlib/google/compression_utils.h" |
| 34 #include "ui/base/template_expressions.h" | 32 #include "ui/base/template_expressions.h" |
| 35 | 33 |
| 36 namespace content { | 34 namespace content { |
| 37 | 35 |
| 38 namespace { | 36 namespace { |
| 39 | 37 |
| 40 class WebUIURLLoaderFactory; | 38 class WebUIURLLoaderFactory; |
| 41 base::LazyInstance<std::map<int, std::unique_ptr<WebUIURLLoaderFactory>>>::Leaky | 39 base::LazyInstance<std::map<int, std::unique_ptr<WebUIURLLoaderFactory>>>::Leaky |
| 42 g_factories = LAZY_INSTANCE_INITIALIZER; | 40 g_factories = LAZY_INSTANCE_INITIALIZER; |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 FROM_HERE, base::BindOnce(&URLDataSource::StartDataRequest, | 202 FROM_HERE, base::BindOnce(&URLDataSource::StartDataRequest, |
| 205 base::Unretained(source->source()), path, | 203 base::Unretained(source->source()), path, |
| 206 wc_getter, data_available_callback)); | 204 wc_getter, data_available_callback)); |
| 207 } | 205 } |
| 208 | 206 |
| 209 class WebUIURLLoaderFactory : public mojom::URLLoaderFactory, | 207 class WebUIURLLoaderFactory : public mojom::URLLoaderFactory, |
| 210 public FrameTreeNode::Observer { | 208 public FrameTreeNode::Observer { |
| 211 public: | 209 public: |
| 212 WebUIURLLoaderFactory(FrameTreeNode* ftn) | 210 WebUIURLLoaderFactory(FrameTreeNode* ftn) |
| 213 : frame_tree_node_id_(ftn->frame_tree_node_id()), | 211 : frame_tree_node_id_(ftn->frame_tree_node_id()), |
| 214 browser_context_( | 212 storage_partition_(static_cast<StoragePartitionImpl*>( |
| 215 ftn->current_frame_host()->GetProcess()->GetBrowserContext()) { | 213 ftn->current_frame_host()->GetProcess()->GetStoragePartition())) { |
| 216 ftn->AddObserver(this); | 214 ftn->AddObserver(this); |
| 217 } | 215 } |
| 218 | 216 |
| 219 ~WebUIURLLoaderFactory() override {} | 217 ~WebUIURLLoaderFactory() override {} |
| 220 | 218 |
| 221 mojom::URLLoaderFactoryPtr CreateBinding() { | 219 mojom::URLLoaderFactoryPtr CreateBinding() { |
| 222 return loader_factory_bindings_.CreateInterfacePtrAndBind(this); | 220 return loader_factory_bindings_.CreateInterfacePtrAndBind(this); |
| 223 } | 221 } |
| 224 | 222 |
| 225 // mojom::URLLoaderFactory implementation: | 223 // mojom::URLLoaderFactory implementation: |
| 226 void CreateLoaderAndStart(mojom::URLLoaderAssociatedRequest loader, | 224 void CreateLoaderAndStart(mojom::URLLoaderAssociatedRequest loader, |
| 227 int32_t routing_id, | 225 int32_t routing_id, |
| 228 int32_t request_id, | 226 int32_t request_id, |
| 229 uint32_t options, | 227 uint32_t options, |
| 230 const ResourceRequest& request, | 228 const ResourceRequest& request, |
| 231 mojom::URLLoaderClientPtr client) override { | 229 mojom::URLLoaderClientPtr client) override { |
| 232 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 230 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 233 if (request.url.host_piece() == kChromeUINetworkViewCacheHost) { | 231 if (request.url.host_piece() == kChromeUINetworkViewCacheHost) { |
| 234 mojom::NetworkServicePtr network_service; | 232 storage_partition_->network_context()->HandleViewCacheRequest( |
| 235 ServiceManagerConnection::GetForProcess()->GetConnector()->BindInterface( | 233 request.url, std::move(client)); |
| 236 mojom::kNetworkServiceName, &network_service); | |
| 237 network_service->HandleViewCacheRequest(request, std::move(client)); | |
| 238 return; | 234 return; |
| 239 } | 235 } |
| 240 | 236 |
| 241 if (request.url.host_piece() == kChromeUIBlobInternalsHost) { | 237 if (request.url.host_piece() == kChromeUIBlobInternalsHost) { |
| 242 BrowserThread::PostTask( | 238 BrowserThread::PostTask( |
| 243 BrowserThread::IO, FROM_HERE, | 239 BrowserThread::IO, FROM_HERE, |
| 244 base::BindOnce( | 240 base::BindOnce(&StartBlobInternalsURLLoader, request, |
| 245 &StartBlobInternalsURLLoader, request, client.PassInterface(), | 241 client.PassInterface(), |
| 246 base::Unretained( | 242 base::Unretained(ChromeBlobStorageContext::GetFor( |
| 247 ChromeBlobStorageContext::GetFor(browser_context_)))); | 243 storage_partition_->browser_context())))); |
| 248 return; | 244 return; |
| 249 } | 245 } |
| 250 | 246 |
| 251 if (request.url.host_piece() == kChromeUINetworkErrorHost || | 247 if (request.url.host_piece() == kChromeUINetworkErrorHost || |
| 252 request.url.host_piece() == kChromeUIDinoHost) { | 248 request.url.host_piece() == kChromeUIDinoHost) { |
| 253 StartNetworkErrorsURLLoader(request, std::move(client)); | 249 StartNetworkErrorsURLLoader(request, std::move(client)); |
| 254 return; | 250 return; |
| 255 } | 251 } |
| 256 | 252 |
| 257 if (request.url.host_piece() == kChromeUIHistogramHost) { | 253 if (request.url.host_piece() == kChromeUIHistogramHost) { |
| 258 StartHistogramInternalsURLLoader(request, std::move(client)); | 254 StartHistogramInternalsURLLoader(request, std::move(client)); |
| 259 return; | 255 return; |
| 260 } | 256 } |
| 261 | 257 |
| 262 BrowserThread::PostTask( | 258 BrowserThread::PostTask( |
| 263 BrowserThread::IO, FROM_HERE, | 259 BrowserThread::IO, FROM_HERE, |
| 264 base::BindOnce(&StartURLLoader, request, frame_tree_node_id_, | 260 base::BindOnce( |
| 265 client.PassInterface(), | 261 &StartURLLoader, request, frame_tree_node_id_, |
| 266 browser_context_->GetResourceContext())); | 262 client.PassInterface(), |
| 263 storage_partition_->browser_context()->GetResourceContext())); |
| 267 } | 264 } |
| 268 | 265 |
| 269 void SyncLoad(int32_t routing_id, | 266 void SyncLoad(int32_t routing_id, |
| 270 int32_t request_id, | 267 int32_t request_id, |
| 271 const ResourceRequest& request, | 268 const ResourceRequest& request, |
| 272 SyncLoadCallback callback) override { | 269 SyncLoadCallback callback) override { |
| 273 NOTREACHED(); | 270 NOTREACHED(); |
| 274 } | 271 } |
| 275 | 272 |
| 276 // FrameTreeNode::Observer implementation: | 273 // FrameTreeNode::Observer implementation: |
| 277 void OnFrameTreeNodeDestroyed(FrameTreeNode* node) override { | 274 void OnFrameTreeNodeDestroyed(FrameTreeNode* node) override { |
| 278 g_factories.Get().erase(frame_tree_node_id_); | 275 g_factories.Get().erase(frame_tree_node_id_); |
| 279 } | 276 } |
| 280 | 277 |
| 281 private: | 278 private: |
| 282 int frame_tree_node_id_; | 279 int frame_tree_node_id_; |
| 283 BrowserContext* browser_context_; | 280 StoragePartitionImpl* storage_partition_; |
| 284 mojo::BindingSet<mojom::URLLoaderFactory> loader_factory_bindings_; | 281 mojo::BindingSet<mojom::URLLoaderFactory> loader_factory_bindings_; |
| 285 | 282 |
| 286 DISALLOW_COPY_AND_ASSIGN(WebUIURLLoaderFactory); | 283 DISALLOW_COPY_AND_ASSIGN(WebUIURLLoaderFactory); |
| 287 }; | 284 }; |
| 288 | 285 |
| 289 } // namespace | 286 } // namespace |
| 290 | 287 |
| 291 mojom::URLLoaderFactoryPtr GetWebUIURLLoader(FrameTreeNode* node) { | 288 mojom::URLLoaderFactoryPtr GetWebUIURLLoader(FrameTreeNode* node) { |
| 292 int ftn_id = node->frame_tree_node_id(); | 289 int ftn_id = node->frame_tree_node_id(); |
| 293 if (g_factories.Get()[ftn_id].get() == nullptr) | 290 if (g_factories.Get()[ftn_id].get() == nullptr) |
| 294 g_factories.Get()[ftn_id] = base::MakeUnique<WebUIURLLoaderFactory>(node); | 291 g_factories.Get()[ftn_id] = base::MakeUnique<WebUIURLLoaderFactory>(node); |
| 295 return g_factories.Get()[ftn_id]->CreateBinding(); | 292 return g_factories.Get()[ftn_id]->CreateBinding(); |
| 296 } | 293 } |
| 297 | 294 |
| 298 } // namespace content | 295 } // namespace content |
| OLD | NEW |