Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: content/browser/webui/web_ui_url_loader_factory.cc

Issue 2874163004: Add support in the network service for different contexts. (Closed)
Patch Set: fixes Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 FROM_HERE, base::BindOnce(&URLDataSource::StartDataRequest, 217 FROM_HERE, base::BindOnce(&URLDataSource::StartDataRequest,
220 base::Unretained(source->source()), path, 218 base::Unretained(source->source()), path,
221 wc_getter, data_available_callback)); 219 wc_getter, data_available_callback));
222 } 220 }
223 221
224 class WebUIURLLoaderFactory : public mojom::URLLoaderFactory, 222 class WebUIURLLoaderFactory : public mojom::URLLoaderFactory,
225 public FrameTreeNode::Observer { 223 public FrameTreeNode::Observer {
226 public: 224 public:
227 WebUIURLLoaderFactory(FrameTreeNode* ftn) 225 WebUIURLLoaderFactory(FrameTreeNode* ftn)
228 : frame_tree_node_id_(ftn->frame_tree_node_id()), 226 : frame_tree_node_id_(ftn->frame_tree_node_id()),
229 browser_context_( 227 storage_partition_(static_cast<StoragePartitionImpl*>(
230 ftn->current_frame_host()->GetProcess()->GetBrowserContext()) { 228 ftn->current_frame_host()->GetProcess()->GetStoragePartition())) {
231 ftn->AddObserver(this); 229 ftn->AddObserver(this);
232 } 230 }
233 231
234 ~WebUIURLLoaderFactory() override {} 232 ~WebUIURLLoaderFactory() override {}
235 233
236 mojom::URLLoaderFactoryPtr CreateBinding() { 234 mojom::URLLoaderFactoryPtr CreateBinding() {
237 return loader_factory_bindings_.CreateInterfacePtrAndBind(this); 235 return loader_factory_bindings_.CreateInterfacePtrAndBind(this);
238 } 236 }
239 237
240 // mojom::URLLoaderFactory implementation: 238 // mojom::URLLoaderFactory implementation:
241 void CreateLoaderAndStart(mojom::URLLoaderAssociatedRequest loader, 239 void CreateLoaderAndStart(mojom::URLLoaderAssociatedRequest loader,
242 int32_t routing_id, 240 int32_t routing_id,
243 int32_t request_id, 241 int32_t request_id,
244 uint32_t options, 242 uint32_t options,
245 const ResourceRequest& request, 243 const ResourceRequest& request,
246 mojom::URLLoaderClientPtr client) override { 244 mojom::URLLoaderClientPtr client) override {
247 DCHECK_CURRENTLY_ON(BrowserThread::UI); 245 DCHECK_CURRENTLY_ON(BrowserThread::UI);
248 if (request.url.host_piece() == kChromeUINetworkViewCacheHost) { 246 if (request.url.host_piece() == kChromeUINetworkViewCacheHost) {
249 mojom::NetworkServicePtr network_service; 247 storage_partition_->network_context()->HandleViewCacheRequest(
250 ServiceManagerConnection::GetForProcess()->GetConnector()->BindInterface( 248 request.url, std::move(client));
251 mojom::kNetworkServiceName, &network_service);
252 network_service->HandleViewCacheRequest(request, std::move(client));
253 return; 249 return;
254 } 250 }
255 251
256 if (request.url.host_piece() == kChromeUIBlobInternalsHost) { 252 if (request.url.host_piece() == kChromeUIBlobInternalsHost) {
257 BrowserThread::PostTask( 253 BrowserThread::PostTask(
258 BrowserThread::IO, FROM_HERE, 254 BrowserThread::IO, FROM_HERE,
259 base::BindOnce( 255 base::BindOnce(&StartBlobInternalsURLLoader, request,
260 &StartBlobInternalsURLLoader, request, client.PassInterface(), 256 client.PassInterface(),
261 base::Unretained( 257 base::Unretained(ChromeBlobStorageContext::GetFor(
262 ChromeBlobStorageContext::GetFor(browser_context_)))); 258 storage_partition_->browser_context()))));
263 return; 259 return;
264 } 260 }
265 261
266 if (request.url.host_piece() == kChromeUINetworkErrorHost || 262 if (request.url.host_piece() == kChromeUINetworkErrorHost ||
267 request.url.host_piece() == kChromeUIDinoHost) { 263 request.url.host_piece() == kChromeUIDinoHost) {
268 StartNetworkErrorsURLLoader(request, std::move(client)); 264 StartNetworkErrorsURLLoader(request, std::move(client));
269 return; 265 return;
270 } 266 }
271 267
272 if (request.url.host_piece() == kChromeUIHistogramHost) { 268 if (request.url.host_piece() == kChromeUIHistogramHost) {
273 StartHistogramInternalsURLLoader(request, std::move(client)); 269 StartHistogramInternalsURLLoader(request, std::move(client));
274 return; 270 return;
275 } 271 }
276 272
277 BrowserThread::PostTask( 273 BrowserThread::PostTask(
278 BrowserThread::IO, FROM_HERE, 274 BrowserThread::IO, FROM_HERE,
279 base::BindOnce(&StartURLLoader, request, frame_tree_node_id_, 275 base::BindOnce(
280 client.PassInterface(), 276 &StartURLLoader, request, frame_tree_node_id_,
281 browser_context_->GetResourceContext())); 277 client.PassInterface(),
278 storage_partition_->browser_context()->GetResourceContext()));
282 } 279 }
283 280
284 void SyncLoad(int32_t routing_id, 281 void SyncLoad(int32_t routing_id,
285 int32_t request_id, 282 int32_t request_id,
286 const ResourceRequest& request, 283 const ResourceRequest& request,
287 SyncLoadCallback callback) override { 284 SyncLoadCallback callback) override {
288 NOTREACHED(); 285 NOTREACHED();
289 } 286 }
290 287
291 // FrameTreeNode::Observer implementation: 288 // FrameTreeNode::Observer implementation:
292 void OnFrameTreeNodeDestroyed(FrameTreeNode* node) override { 289 void OnFrameTreeNodeDestroyed(FrameTreeNode* node) override {
293 g_factories.Get().erase(frame_tree_node_id_); 290 g_factories.Get().erase(frame_tree_node_id_);
294 } 291 }
295 292
296 private: 293 private:
297 int frame_tree_node_id_; 294 int frame_tree_node_id_;
298 BrowserContext* browser_context_; 295 StoragePartitionImpl* storage_partition_;
299 mojo::BindingSet<mojom::URLLoaderFactory> loader_factory_bindings_; 296 mojo::BindingSet<mojom::URLLoaderFactory> loader_factory_bindings_;
300 297
301 DISALLOW_COPY_AND_ASSIGN(WebUIURLLoaderFactory); 298 DISALLOW_COPY_AND_ASSIGN(WebUIURLLoaderFactory);
302 }; 299 };
303 300
304 } // namespace 301 } // namespace
305 302
306 mojom::URLLoaderFactoryPtr GetWebUIURLLoader(FrameTreeNode* node) { 303 mojom::URLLoaderFactoryPtr GetWebUIURLLoader(FrameTreeNode* node) {
307 int ftn_id = node->frame_tree_node_id(); 304 int ftn_id = node->frame_tree_node_id();
308 if (g_factories.Get()[ftn_id].get() == nullptr) 305 if (g_factories.Get()[ftn_id].get() == nullptr)
309 g_factories.Get()[ftn_id] = base::MakeUnique<WebUIURLLoaderFactory>(node); 306 g_factories.Get()[ftn_id] = base::MakeUnique<WebUIURLLoaderFactory>(node);
310 return g_factories.Get()[ftn_id]->CreateBinding(); 307 return g_factories.Get()[ftn_id]->CreateBinding();
311 } 308 }
312 309
313 } // namespace content 310 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698