OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/webui/chrome_url_data_manager_backend.h" | 5 #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
15 #include "base/memory/ref_counted_memory.h" | 15 #include "base/memory/ref_counted_memory.h" |
16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
17 #include "base/message_loop.h" | 17 #include "base/message_loop.h" |
18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
19 #include "base/string_util.h" | 19 #include "base/string_util.h" |
20 #include "chrome/browser/net/chrome_url_request_context.h" | 20 #include "chrome/browser/net/chrome_url_request_context.h" |
21 #include "chrome/browser/net/view_blob_internals_job_factory.h" | |
22 #include "chrome/browser/net/view_http_cache_job_factory.h" | |
23 #include "chrome/browser/ui/webui/shared_resources_data_source.h" | 21 #include "chrome/browser/ui/webui/shared_resources_data_source.h" |
24 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
25 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
27 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
28 #include "googleurl/src/url_util.h" | 26 #include "googleurl/src/url_util.h" |
29 #include "grit/platform_locale_settings.h" | 27 #include "grit/platform_locale_settings.h" |
30 #include "net/base/io_buffer.h" | 28 #include "net/base/io_buffer.h" |
31 #include "net/base/net_errors.h" | 29 #include "net/base/net_errors.h" |
32 #include "net/http/http_response_headers.h" | 30 #include "net/http/http_response_headers.h" |
33 #include "net/url_request/url_request.h" | 31 #include "net/url_request/url_request.h" |
34 #include "net/url_request/url_request_file_job.h" | 32 #include "net/url_request/url_request_file_job.h" |
35 #include "net/url_request/url_request_job.h" | 33 #include "net/url_request/url_request_job.h" |
36 #include "net/url_request/url_request_job_factory.h" | 34 #include "net/url_request/url_request_job_factory.h" |
37 #include "webkit/appcache/appcache_service.h" | |
38 #include "webkit/appcache/view_appcache_internals_job.h" | |
39 | 35 |
40 using content::BrowserThread; | 36 using content::BrowserThread; |
41 | 37 |
42 namespace { | 38 namespace { |
43 | 39 |
44 // X-WebKit-CSP is our development name for Content-Security-Policy. | 40 // X-WebKit-CSP is our development name for Content-Security-Policy. |
45 // TODO(tsepez) rename when Content-security-policy is done. | 41 // TODO(tsepez) rename when Content-security-policy is done. |
46 // TODO(tsepez) remove unsafe-eval when bidichecker_packaged.js fixed. | 42 // TODO(tsepez) remove unsafe-eval when bidichecker_packaged.js fixed. |
47 // TODO(tsepez) chrome-extension: permits the ChromeVox screen reader | 43 // TODO(tsepez) chrome-extension: permits the ChromeVox screen reader |
48 // extension to function on these pages. Remove it when the extension | 44 // extension to function on these pages. Remove it when the extension |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 if (backend_->StartRequest(request_->url(), this)) { | 308 if (backend_->StartRequest(request_->url(), this)) { |
313 NotifyHeadersComplete(); | 309 NotifyHeadersComplete(); |
314 } else { | 310 } else { |
315 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, | 311 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, |
316 net::ERR_INVALID_URL)); | 312 net::ERR_INVALID_URL)); |
317 } | 313 } |
318 } | 314 } |
319 | 315 |
320 namespace { | 316 namespace { |
321 | 317 |
322 bool IsViewAppCacheInternalsURL(const GURL& url) { | |
323 return url.SchemeIs(chrome::kChromeUIScheme) && | |
324 url.host() == chrome::kChromeUIAppCacheInternalsHost; | |
325 } | |
326 | |
327 class ChromeProtocolHandler | 318 class ChromeProtocolHandler |
328 : public net::URLRequestJobFactory::ProtocolHandler { | 319 : public net::URLRequestJobFactory::ProtocolHandler { |
329 public: | 320 public: |
330 ChromeProtocolHandler( | 321 explicit ChromeProtocolHandler(ChromeURLDataManagerBackend* backend); |
331 ChromeURLDataManagerBackend* backend, | |
332 appcache::AppCacheService* appcache_service, | |
333 webkit_blob::BlobStorageController* blob_storage_controller); | |
334 ~ChromeProtocolHandler(); | 322 ~ChromeProtocolHandler(); |
335 | 323 |
336 virtual net::URLRequestJob* MaybeCreateJob( | 324 virtual net::URLRequestJob* MaybeCreateJob( |
337 net::URLRequest* request) const OVERRIDE; | 325 net::URLRequest* request) const OVERRIDE; |
338 | 326 |
339 private: | 327 private: |
340 // These members are owned by ProfileIOData, which owns this ProtocolHandler. | 328 // These members are owned by ProfileIOData, which owns this ProtocolHandler. |
341 ChromeURLDataManagerBackend* const backend_; | 329 ChromeURLDataManagerBackend* const backend_; |
342 appcache::AppCacheService* const appcache_service_; | |
343 webkit_blob::BlobStorageController* const blob_storage_controller_; | |
344 | 330 |
345 DISALLOW_COPY_AND_ASSIGN(ChromeProtocolHandler); | 331 DISALLOW_COPY_AND_ASSIGN(ChromeProtocolHandler); |
346 }; | 332 }; |
347 | 333 |
348 ChromeProtocolHandler::ChromeProtocolHandler( | 334 ChromeProtocolHandler::ChromeProtocolHandler( |
349 ChromeURLDataManagerBackend* backend, | 335 ChromeURLDataManagerBackend* backend) |
350 appcache::AppCacheService* appcache_service, | 336 : backend_(backend) {} |
351 webkit_blob::BlobStorageController* blob_storage_controller) | |
352 : backend_(backend), | |
353 appcache_service_(appcache_service), | |
354 blob_storage_controller_(blob_storage_controller) {} | |
355 | 337 |
356 ChromeProtocolHandler::~ChromeProtocolHandler() {} | 338 ChromeProtocolHandler::~ChromeProtocolHandler() {} |
357 | 339 |
358 net::URLRequestJob* ChromeProtocolHandler::MaybeCreateJob( | 340 net::URLRequestJob* ChromeProtocolHandler::MaybeCreateJob( |
359 net::URLRequest* request) const { | 341 net::URLRequest* request) const { |
360 DCHECK(request); | 342 DCHECK(request); |
361 | 343 |
362 // Next check for chrome://view-http-cache/*, which uses its own job type. | |
363 if (ViewHttpCacheJobFactory::IsSupportedURL(request->url())) | |
364 return ViewHttpCacheJobFactory::CreateJobForRequest(request); | |
365 | |
366 // Next check for chrome://appcache-internals/, which uses its own job type. | |
367 if (IsViewAppCacheInternalsURL(request->url())) | |
368 return appcache::ViewAppCacheInternalsJobFactory::CreateJobForRequest( | |
369 request, appcache_service_); | |
370 | |
371 // Next check for chrome://blob-internals/, which uses its own job type. | |
372 if (ViewBlobInternalsJobFactory::IsSupportedURL(request->url())) | |
373 return ViewBlobInternalsJobFactory::CreateJobForRequest( | |
374 request, blob_storage_controller_); | |
375 | |
376 // Fall back to using a custom handler | 344 // Fall back to using a custom handler |
377 return new URLRequestChromeJob(request, backend_); | 345 return new URLRequestChromeJob(request, backend_); |
378 } | 346 } |
379 | 347 |
380 } // namespace | 348 } // namespace |
381 | 349 |
382 ChromeURLDataManagerBackend::ChromeURLDataManagerBackend() | 350 ChromeURLDataManagerBackend::ChromeURLDataManagerBackend() |
383 : next_request_id_(0) { | 351 : next_request_id_(0) { |
384 AddDataSource(new SharedResourcesDataSource()); | 352 AddDataSource(new SharedResourcesDataSource()); |
385 } | 353 } |
386 | 354 |
387 ChromeURLDataManagerBackend::~ChromeURLDataManagerBackend() { | 355 ChromeURLDataManagerBackend::~ChromeURLDataManagerBackend() { |
388 for (DataSourceMap::iterator i = data_sources_.begin(); | 356 for (DataSourceMap::iterator i = data_sources_.begin(); |
389 i != data_sources_.end(); ++i) { | 357 i != data_sources_.end(); ++i) { |
390 i->second->backend_ = NULL; | 358 i->second->backend_ = NULL; |
391 } | 359 } |
392 data_sources_.clear(); | 360 data_sources_.clear(); |
393 } | 361 } |
394 | 362 |
395 // static | 363 // static |
396 net::URLRequestJobFactory::ProtocolHandler* | 364 net::URLRequestJobFactory::ProtocolHandler* |
397 ChromeURLDataManagerBackend::CreateProtocolHandler( | 365 ChromeURLDataManagerBackend::CreateProtocolHandler( |
398 ChromeURLDataManagerBackend* backend, | 366 ChromeURLDataManagerBackend* backend) { |
399 appcache::AppCacheService* appcache_service, | |
400 webkit_blob::BlobStorageController* blob_storage_controller) { | |
401 DCHECK(appcache_service); | |
402 DCHECK(blob_storage_controller); | |
403 DCHECK(backend); | 367 DCHECK(backend); |
404 return new ChromeProtocolHandler( | 368 return new ChromeProtocolHandler(backend); |
405 backend, appcache_service, blob_storage_controller); | |
406 } | 369 } |
407 | 370 |
408 void ChromeURLDataManagerBackend::AddDataSource( | 371 void ChromeURLDataManagerBackend::AddDataSource( |
409 ChromeURLDataManager::DataSource* source) { | 372 ChromeURLDataManager::DataSource* source) { |
410 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 373 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
411 DataSourceMap::iterator i = data_sources_.find(source->source_name()); | 374 DataSourceMap::iterator i = data_sources_.find(source->source_name()); |
412 if (i != data_sources_.end()) { | 375 if (i != data_sources_.end()) { |
413 if (!source->ShouldReplaceExistingSource()) | 376 if (!source->ShouldReplaceExistingSource()) |
414 return; | 377 return; |
415 i->second->backend_ = NULL; | 378 i->second->backend_ = NULL; |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 | 550 |
588 return new URLRequestChromeJob(request, backend_); | 551 return new URLRequestChromeJob(request, backend_); |
589 } | 552 } |
590 | 553 |
591 } // namespace | 554 } // namespace |
592 | 555 |
593 net::URLRequestJobFactory::ProtocolHandler* | 556 net::URLRequestJobFactory::ProtocolHandler* |
594 CreateDevToolsProtocolHandler(ChromeURLDataManagerBackend* backend) { | 557 CreateDevToolsProtocolHandler(ChromeURLDataManagerBackend* backend) { |
595 return new DevToolsJobFactory(backend); | 558 return new DevToolsJobFactory(backend); |
596 } | 559 } |
OLD | NEW |