| 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" |
| 15 #include "content/browser/blob_storage/chrome_blob_storage_context.h" |
| 14 #include "content/browser/frame_host/frame_tree_node.h" | 16 #include "content/browser/frame_host/frame_tree_node.h" |
| 15 #include "content/browser/frame_host/render_frame_host_impl.h" | 17 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 16 #include "content/browser/resource_context_impl.h" | 18 #include "content/browser/resource_context_impl.h" |
| 17 #include "content/browser/webui/url_data_manager_backend.h" | 19 #include "content/browser/webui/url_data_manager_backend.h" |
| 18 #include "content/browser/webui/url_data_source_impl.h" | 20 #include "content/browser/webui/url_data_source_impl.h" |
| 19 #include "content/public/browser/browser_context.h" | 21 #include "content/public/browser/browser_context.h" |
| 20 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/render_process_host.h" | 23 #include "content/public/browser/render_process_host.h" |
| 22 #include "content/public/browser/web_contents.h" | 24 #include "content/public/browser/web_contents.h" |
| 25 #include "content/public/common/url_constants.h" |
| 23 #include "mojo/public/cpp/bindings/binding_set.h" | 26 #include "mojo/public/cpp/bindings/binding_set.h" |
| 24 #include "third_party/zlib/google/compression_utils.h" | 27 #include "third_party/zlib/google/compression_utils.h" |
| 25 #include "ui/base/template_expressions.h" | 28 #include "ui/base/template_expressions.h" |
| 26 | 29 |
| 27 namespace content { | 30 namespace content { |
| 28 | 31 |
| 29 namespace { | 32 namespace { |
| 30 | 33 |
| 31 class WebUIURLLoaderFactory; | 34 class WebUIURLLoaderFactory; |
| 32 base::LazyInstance<std::map<int, std::unique_ptr<WebUIURLLoaderFactory>>>::Leaky | 35 base::LazyInstance<std::map<int, std::unique_ptr<WebUIURLLoaderFactory>>>::Leaky |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 FROM_HERE, base::BindOnce(&URLDataSource::StartDataRequest, | 213 FROM_HERE, base::BindOnce(&URLDataSource::StartDataRequest, |
| 211 base::Unretained(source->source()), path, | 214 base::Unretained(source->source()), path, |
| 212 wc_getter, data_available_callback)); | 215 wc_getter, data_available_callback)); |
| 213 } | 216 } |
| 214 | 217 |
| 215 class WebUIURLLoaderFactory : public mojom::URLLoaderFactory, | 218 class WebUIURLLoaderFactory : public mojom::URLLoaderFactory, |
| 216 public FrameTreeNode::Observer { | 219 public FrameTreeNode::Observer { |
| 217 public: | 220 public: |
| 218 WebUIURLLoaderFactory(FrameTreeNode* ftn) | 221 WebUIURLLoaderFactory(FrameTreeNode* ftn) |
| 219 : frame_tree_node_id_(ftn->frame_tree_node_id()), | 222 : frame_tree_node_id_(ftn->frame_tree_node_id()), |
| 220 resource_context_(ftn->current_frame_host() | 223 browser_context_( |
| 221 ->GetProcess() | 224 ftn->current_frame_host()->GetProcess()->GetBrowserContext()) { |
| 222 ->GetBrowserContext() | |
| 223 ->GetResourceContext()) { | |
| 224 ftn->AddObserver(this); | 225 ftn->AddObserver(this); |
| 225 } | 226 } |
| 226 | 227 |
| 227 ~WebUIURLLoaderFactory() override {} | 228 ~WebUIURLLoaderFactory() override {} |
| 228 | 229 |
| 229 mojom::URLLoaderFactoryPtr CreateBinding() { | 230 mojom::URLLoaderFactoryPtr CreateBinding() { |
| 230 return loader_factory_bindings_.CreateInterfacePtrAndBind(this); | 231 return loader_factory_bindings_.CreateInterfacePtrAndBind(this); |
| 231 } | 232 } |
| 232 | 233 |
| 233 // mojom::URLLoaderFactory implementation: | 234 // mojom::URLLoaderFactory implementation: |
| 234 void CreateLoaderAndStart(mojom::URLLoaderAssociatedRequest loader, | 235 void CreateLoaderAndStart(mojom::URLLoaderAssociatedRequest loader, |
| 235 int32_t routing_id, | 236 int32_t routing_id, |
| 236 int32_t request_id, | 237 int32_t request_id, |
| 237 uint32_t options, | 238 uint32_t options, |
| 238 const ResourceRequest& request, | 239 const ResourceRequest& request, |
| 239 mojom::URLLoaderClientPtr client) override { | 240 mojom::URLLoaderClientPtr client) override { |
| 240 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 241 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 242 if (request.url.host_piece() == kChromeUIBlobInternalsHost) { |
| 243 BrowserThread::PostTask( |
| 244 BrowserThread::IO, FROM_HERE, |
| 245 base::BindOnce( |
| 246 &StartBlobInternalsURLLoader, request, client.PassInterface(), |
| 247 base::Unretained( |
| 248 ChromeBlobStorageContext::GetFor(browser_context_)))); |
| 249 return; |
| 250 } |
| 251 |
| 241 BrowserThread::PostTask( | 252 BrowserThread::PostTask( |
| 242 BrowserThread::IO, FROM_HERE, | 253 BrowserThread::IO, FROM_HERE, |
| 243 base::BindOnce(&StartURLLoader, request, frame_tree_node_id_, | 254 base::BindOnce(&StartURLLoader, request, frame_tree_node_id_, |
| 244 client.PassInterface(), resource_context_)); | 255 client.PassInterface(), |
| 256 browser_context_->GetResourceContext())); |
| 245 } | 257 } |
| 246 | 258 |
| 247 void SyncLoad(int32_t routing_id, | 259 void SyncLoad(int32_t routing_id, |
| 248 int32_t request_id, | 260 int32_t request_id, |
| 249 const ResourceRequest& request, | 261 const ResourceRequest& request, |
| 250 SyncLoadCallback callback) override { | 262 SyncLoadCallback callback) override { |
| 251 NOTREACHED(); | 263 NOTREACHED(); |
| 252 } | 264 } |
| 253 | 265 |
| 254 // FrameTreeNode::Observer implementation: | 266 // FrameTreeNode::Observer implementation: |
| 255 void OnFrameTreeNodeDestroyed(FrameTreeNode* node) override { | 267 void OnFrameTreeNodeDestroyed(FrameTreeNode* node) override { |
| 256 g_factories.Get().erase(frame_tree_node_id_); | 268 g_factories.Get().erase(frame_tree_node_id_); |
| 257 } | 269 } |
| 258 | 270 |
| 259 private: | 271 private: |
| 260 int frame_tree_node_id_; | 272 int frame_tree_node_id_; |
| 261 ResourceContext* resource_context_; | 273 BrowserContext* browser_context_; |
| 262 mojo::BindingSet<mojom::URLLoaderFactory> loader_factory_bindings_; | 274 mojo::BindingSet<mojom::URLLoaderFactory> loader_factory_bindings_; |
| 263 | 275 |
| 264 DISALLOW_COPY_AND_ASSIGN(WebUIURLLoaderFactory); | 276 DISALLOW_COPY_AND_ASSIGN(WebUIURLLoaderFactory); |
| 265 }; | 277 }; |
| 266 | 278 |
| 267 } // namespace | 279 } // namespace |
| 268 | 280 |
| 269 mojom::URLLoaderFactoryPtr GetWebUIURLLoader(FrameTreeNode* node) { | 281 mojom::URLLoaderFactoryPtr GetWebUIURLLoader(FrameTreeNode* node) { |
| 270 int ftn_id = node->frame_tree_node_id(); | 282 int ftn_id = node->frame_tree_node_id(); |
| 271 if (g_factories.Get()[ftn_id].get() == nullptr) | 283 if (g_factories.Get()[ftn_id].get() == nullptr) |
| 272 g_factories.Get()[ftn_id] = base::MakeUnique<WebUIURLLoaderFactory>(node); | 284 g_factories.Get()[ftn_id] = base::MakeUnique<WebUIURLLoaderFactory>(node); |
| 273 return g_factories.Get()[ftn_id]->CreateBinding(); | 285 return g_factories.Get()[ftn_id]->CreateBinding(); |
| 274 } | 286 } |
| 275 | 287 |
| 276 } // namespace content | 288 } // namespace content |
| OLD | NEW |