| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/memory/ref_counted_memory.h" | 11 #include "base/memory/ref_counted_memory.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "chrome/browser/net/chrome_url_request_context.h" | 15 #include "chrome/browser/net/chrome_url_request_context.h" |
| 16 #include "chrome/browser/net/view_blob_internals_job_factory.h" | 16 #include "chrome/browser/net/view_blob_internals_job_factory.h" |
| 17 #include "chrome/browser/net/view_http_cache_job_factory.h" | 17 #include "chrome/browser/net/view_http_cache_job_factory.h" |
| 18 #include "chrome/browser/ui/webui/shared_resources_data_source.h" | 18 #include "chrome/browser/ui/webui/shared_resources_data_source.h" |
| 19 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
| 20 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
| 21 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
| 22 #include "content/browser/appcache/chrome_appcache_service.h" |
| 22 #include "content/browser/browser_thread.h" | 23 #include "content/browser/browser_thread.h" |
| 23 #include "googleurl/src/url_util.h" | 24 #include "googleurl/src/url_util.h" |
| 24 #include "grit/platform_locale_settings.h" | 25 #include "grit/platform_locale_settings.h" |
| 25 #include "net/base/io_buffer.h" | 26 #include "net/base/io_buffer.h" |
| 26 #include "net/base/net_errors.h" | 27 #include "net/base/net_errors.h" |
| 27 #include "net/http/http_response_headers.h" | 28 #include "net/http/http_response_headers.h" |
| 28 #include "net/url_request/url_request.h" | 29 #include "net/url_request/url_request.h" |
| 29 #include "net/url_request/url_request_file_job.h" | 30 #include "net/url_request/url_request_file_job.h" |
| 30 #include "net/url_request/url_request_job.h" | 31 #include "net/url_request/url_request_job.h" |
| 31 #include "net/url_request/url_request_job_factory.h" | 32 #include "net/url_request/url_request_job_factory.h" |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 namespace { | 221 namespace { |
| 221 | 222 |
| 222 bool IsViewAppCacheInternalsURL(const GURL& url) { | 223 bool IsViewAppCacheInternalsURL(const GURL& url) { |
| 223 return url.SchemeIs(chrome::kChromeUIScheme) && | 224 return url.SchemeIs(chrome::kChromeUIScheme) && |
| 224 url.host() == chrome::kChromeUIAppCacheInternalsHost; | 225 url.host() == chrome::kChromeUIAppCacheInternalsHost; |
| 225 } | 226 } |
| 226 | 227 |
| 227 class ChromeProtocolHandler | 228 class ChromeProtocolHandler |
| 228 : public net::URLRequestJobFactory::ProtocolHandler { | 229 : public net::URLRequestJobFactory::ProtocolHandler { |
| 229 public: | 230 public: |
| 230 ChromeProtocolHandler(ChromeURLDataManagerBackend* backend, | 231 ChromeProtocolHandler( |
| 231 ChromeAppCacheService* appcache_service); | 232 ChromeURLDataManagerBackend* backend, |
| 233 ChromeAppCacheService* appcache_service, |
| 234 webkit_blob::BlobStorageController* blob_storage_controller); |
| 232 ~ChromeProtocolHandler(); | 235 ~ChromeProtocolHandler(); |
| 233 | 236 |
| 234 virtual net::URLRequestJob* MaybeCreateJob( | 237 virtual net::URLRequestJob* MaybeCreateJob( |
| 235 net::URLRequest* request) const OVERRIDE; | 238 net::URLRequest* request) const OVERRIDE; |
| 236 | 239 |
| 237 private: | 240 private: |
| 238 // These members are owned by ProfileIOData, which owns this ProtocolHandler. | 241 // These members are owned by ProfileIOData, which owns this ProtocolHandler. |
| 239 ChromeURLDataManagerBackend* const backend_; | 242 ChromeURLDataManagerBackend* const backend_; |
| 240 ChromeAppCacheService* const appcache_service_; | 243 ChromeAppCacheService* const appcache_service_; |
| 244 webkit_blob::BlobStorageController* const blob_storage_controller_; |
| 241 | 245 |
| 242 DISALLOW_COPY_AND_ASSIGN(ChromeProtocolHandler); | 246 DISALLOW_COPY_AND_ASSIGN(ChromeProtocolHandler); |
| 243 }; | 247 }; |
| 244 | 248 |
| 245 ChromeProtocolHandler::ChromeProtocolHandler( | 249 ChromeProtocolHandler::ChromeProtocolHandler( |
| 246 ChromeURLDataManagerBackend* backend, | 250 ChromeURLDataManagerBackend* backend, |
| 247 ChromeAppCacheService* appcache_service) | 251 ChromeAppCacheService* appcache_service, |
| 252 webkit_blob::BlobStorageController* blob_storage_controller) |
| 248 : backend_(backend), | 253 : backend_(backend), |
| 249 appcache_service_(appcache_service) {} | 254 appcache_service_(appcache_service), |
| 255 blob_storage_controller_(blob_storage_controller) {} |
| 250 | 256 |
| 251 ChromeProtocolHandler::~ChromeProtocolHandler() {} | 257 ChromeProtocolHandler::~ChromeProtocolHandler() {} |
| 252 | 258 |
| 253 net::URLRequestJob* ChromeProtocolHandler::MaybeCreateJob( | 259 net::URLRequestJob* ChromeProtocolHandler::MaybeCreateJob( |
| 254 net::URLRequest* request) const { | 260 net::URLRequest* request) const { |
| 255 DCHECK(request); | 261 DCHECK(request); |
| 256 | 262 |
| 257 // Next check for chrome://view-http-cache/*, which uses its own job type. | 263 // Next check for chrome://view-http-cache/*, which uses its own job type. |
| 258 if (ViewHttpCacheJobFactory::IsSupportedURL(request->url())) | 264 if (ViewHttpCacheJobFactory::IsSupportedURL(request->url())) |
| 259 return ViewHttpCacheJobFactory::CreateJobForRequest(request); | 265 return ViewHttpCacheJobFactory::CreateJobForRequest(request); |
| 260 | 266 |
| 261 // Next check for chrome://appcache-internals/, which uses its own job type. | 267 // Next check for chrome://appcache-internals/, which uses its own job type. |
| 262 if (IsViewAppCacheInternalsURL(request->url())) | 268 if (IsViewAppCacheInternalsURL(request->url())) |
| 263 return appcache::ViewAppCacheInternalsJobFactory::CreateJobForRequest( | 269 return appcache::ViewAppCacheInternalsJobFactory::CreateJobForRequest( |
| 264 request, appcache_service_); | 270 request, appcache_service_); |
| 265 | 271 |
| 266 // Next check for chrome://blob-internals/, which uses its own job type. | 272 // Next check for chrome://blob-internals/, which uses its own job type. |
| 267 if (ViewBlobInternalsJobFactory::IsSupportedURL(request->url())) | 273 if (ViewBlobInternalsJobFactory::IsSupportedURL(request->url())) |
| 268 return ViewBlobInternalsJobFactory::CreateJobForRequest(request); | 274 return ViewBlobInternalsJobFactory::CreateJobForRequest( |
| 275 request, blob_storage_controller_); |
| 269 | 276 |
| 270 // Fall back to using a custom handler | 277 // Fall back to using a custom handler |
| 271 return new URLRequestChromeJob(request, backend_); | 278 return new URLRequestChromeJob(request, backend_); |
| 272 } | 279 } |
| 273 | 280 |
| 274 } // namespace | 281 } // namespace |
| 275 | 282 |
| 276 ChromeURLDataManagerBackend::ChromeURLDataManagerBackend() | 283 ChromeURLDataManagerBackend::ChromeURLDataManagerBackend() |
| 277 : next_request_id_(0) { | 284 : next_request_id_(0) { |
| 278 AddDataSource(new SharedResourcesDataSource()); | 285 AddDataSource(new SharedResourcesDataSource()); |
| 279 } | 286 } |
| 280 | 287 |
| 281 ChromeURLDataManagerBackend::~ChromeURLDataManagerBackend() { | 288 ChromeURLDataManagerBackend::~ChromeURLDataManagerBackend() { |
| 282 for (DataSourceMap::iterator i = data_sources_.begin(); | 289 for (DataSourceMap::iterator i = data_sources_.begin(); |
| 283 i != data_sources_.end(); ++i) { | 290 i != data_sources_.end(); ++i) { |
| 284 i->second->backend_ = NULL; | 291 i->second->backend_ = NULL; |
| 285 } | 292 } |
| 286 data_sources_.clear(); | 293 data_sources_.clear(); |
| 287 } | 294 } |
| 288 | 295 |
| 289 // static | 296 // static |
| 290 net::URLRequestJobFactory::ProtocolHandler* | 297 net::URLRequestJobFactory::ProtocolHandler* |
| 291 ChromeURLDataManagerBackend::CreateProtocolHandler( | 298 ChromeURLDataManagerBackend::CreateProtocolHandler( |
| 292 ChromeURLDataManagerBackend* backend, | 299 ChromeURLDataManagerBackend* backend, |
| 293 ChromeAppCacheService* appcache_service) { | 300 ChromeAppCacheService* appcache_service, |
| 301 webkit_blob::BlobStorageController* blob_storage_controller) { |
| 294 DCHECK(appcache_service); | 302 DCHECK(appcache_service); |
| 303 DCHECK(blob_storage_controller); |
| 295 DCHECK(backend); | 304 DCHECK(backend); |
| 296 return new ChromeProtocolHandler(backend, appcache_service); | 305 return new ChromeProtocolHandler( |
| 306 backend, appcache_service, blob_storage_controller); |
| 297 } | 307 } |
| 298 | 308 |
| 299 void ChromeURLDataManagerBackend::AddDataSource( | 309 void ChromeURLDataManagerBackend::AddDataSource( |
| 300 ChromeURLDataManager::DataSource* source) { | 310 ChromeURLDataManager::DataSource* source) { |
| 301 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 311 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 302 DataSourceMap::iterator i = data_sources_.find(source->source_name()); | 312 DataSourceMap::iterator i = data_sources_.find(source->source_name()); |
| 303 if (i != data_sources_.end()) { | 313 if (i != data_sources_.end()) { |
| 304 if (!source->ShouldReplaceExistingSource()) | 314 if (!source->ShouldReplaceExistingSource()) |
| 305 return; | 315 return; |
| 306 i->second->backend_ = NULL; | 316 i->second->backend_ = NULL; |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 | 489 |
| 480 return new URLRequestChromeJob(request, backend_); | 490 return new URLRequestChromeJob(request, backend_); |
| 481 } | 491 } |
| 482 | 492 |
| 483 } // namespace | 493 } // namespace |
| 484 | 494 |
| 485 net::URLRequestJobFactory::ProtocolHandler* | 495 net::URLRequestJobFactory::ProtocolHandler* |
| 486 CreateDevToolsProtocolHandler(ChromeURLDataManagerBackend* backend) { | 496 CreateDevToolsProtocolHandler(ChromeURLDataManagerBackend* backend) { |
| 487 return new DevToolsJobFactory(backend); | 497 return new DevToolsJobFactory(backend); |
| 488 } | 498 } |
| OLD | NEW |