| 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" | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
| 32 #include "mojo/public/cpp/bindings/binding_set.h" | 32 #include "mojo/public/cpp/bindings/binding_set.h" | 
| 33 #include "third_party/zlib/google/compression_utils.h" | 33 #include "third_party/zlib/google/compression_utils.h" | 
| 34 #include "ui/base/template_expressions.h" | 34 #include "ui/base/template_expressions.h" | 
| 35 | 35 | 
| 36 namespace content { | 36 namespace content { | 
| 37 | 37 | 
| 38 namespace { | 38 namespace { | 
| 39 | 39 | 
| 40 class WebUIURLLoaderFactory; | 40 class WebUIURLLoaderFactory; | 
| 41 base::LazyInstance<std::map<int, std::unique_ptr<WebUIURLLoaderFactory>>>::Leaky | 41 base::LazyInstance<std::map<int, std::unique_ptr<WebUIURLLoaderFactory>>>::Leaky | 
| 42     g_factories = LAZY_INSTANCE_INITIALIZER; | 42     g_webui_url_loader_factories = LAZY_INSTANCE_INITIALIZER; | 
| 43 | 43 | 
| 44 void CallOnError(mojom::URLLoaderClientPtrInfo client_info, int error_code) { | 44 void CallOnError(mojom::URLLoaderClientPtrInfo client_info, int error_code) { | 
| 45   mojom::URLLoaderClientPtr client; | 45   mojom::URLLoaderClientPtr client; | 
| 46   client.Bind(std::move(client_info)); | 46   client.Bind(std::move(client_info)); | 
| 47 | 47 | 
| 48   ResourceRequestCompletionStatus status; | 48   ResourceRequestCompletionStatus status; | 
| 49   status.error_code = error_code; | 49   status.error_code = error_code; | 
| 50   client->OnComplete(status); | 50   client->OnComplete(status); | 
| 51 } | 51 } | 
| 52 | 52 | 
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 266             client.PassInterface(), | 266             client.PassInterface(), | 
| 267             storage_partition_->browser_context()->GetResourceContext())); | 267             storage_partition_->browser_context()->GetResourceContext())); | 
| 268   } | 268   } | 
| 269 | 269 | 
| 270   void Clone(mojom::URLLoaderFactoryRequest request) override { | 270   void Clone(mojom::URLLoaderFactoryRequest request) override { | 
| 271     loader_factory_bindings_.AddBinding(this, std::move(request)); | 271     loader_factory_bindings_.AddBinding(this, std::move(request)); | 
| 272   } | 272   } | 
| 273 | 273 | 
| 274   // FrameTreeNode::Observer implementation: | 274   // FrameTreeNode::Observer implementation: | 
| 275   void OnFrameTreeNodeDestroyed(FrameTreeNode* node) override { | 275   void OnFrameTreeNodeDestroyed(FrameTreeNode* node) override { | 
| 276     g_factories.Get().erase(frame_tree_node_id_); | 276     g_webui_url_loader_factories.Get().erase(frame_tree_node_id_); | 
| 277   } | 277   } | 
| 278 | 278 | 
| 279  private: | 279  private: | 
| 280   int frame_tree_node_id_; | 280   int frame_tree_node_id_; | 
| 281   StoragePartitionImpl* storage_partition_; | 281   StoragePartitionImpl* storage_partition_; | 
| 282   mojo::BindingSet<mojom::URLLoaderFactory> loader_factory_bindings_; | 282   mojo::BindingSet<mojom::URLLoaderFactory> loader_factory_bindings_; | 
| 283 | 283 | 
| 284   DISALLOW_COPY_AND_ASSIGN(WebUIURLLoaderFactory); | 284   DISALLOW_COPY_AND_ASSIGN(WebUIURLLoaderFactory); | 
| 285 }; | 285 }; | 
| 286 | 286 | 
| 287 }  // namespace | 287 }  // namespace | 
| 288 | 288 | 
| 289 mojom::URLLoaderFactoryPtr CreateWebUIURLLoader(FrameTreeNode* node) { | 289 mojom::URLLoaderFactoryPtr CreateWebUIURLLoader(FrameTreeNode* node) { | 
| 290   int ftn_id = node->frame_tree_node_id(); | 290   int ftn_id = node->frame_tree_node_id(); | 
| 291   if (g_factories.Get()[ftn_id].get() == nullptr) | 291   if (g_webui_url_loader_factories.Get()[ftn_id].get() == nullptr) | 
| 292     g_factories.Get()[ftn_id] = base::MakeUnique<WebUIURLLoaderFactory>(node); | 292     g_webui_url_loader_factories.Get()[ftn_id] = base::MakeUnique<WebUIURLLoader
     Factory>(node); | 
| 293   return g_factories.Get()[ftn_id]->CreateBinding(); | 293   return g_webui_url_loader_factories.Get()[ftn_id]->CreateBinding(); | 
| 294 } | 294 } | 
| 295 | 295 | 
| 296 }  // namespace content | 296 }  // namespace content | 
| OLD | NEW | 
|---|