| 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 new appcache::ViewAppCacheInternalsJob(request, appcache_service_); | 269 return new appcache::ViewAppCacheInternalsJob(request, appcache_service_); |
| 264 | 270 |
| 265 // Next check for chrome://blob-internals/, which uses its own job type. | 271 // Next check for chrome://blob-internals/, which uses its own job type. |
| 266 if (ViewBlobInternalsJobFactory::IsSupportedURL(request->url())) | 272 if (ViewBlobInternalsJobFactory::IsSupportedURL(request->url())) |
| 267 return ViewBlobInternalsJobFactory::CreateJobForRequest(request); | 273 return ViewBlobInternalsJobFactory::CreateJobForRequest( |
| 274 request, blob_storage_controller_); |
| 268 | 275 |
| 269 // Fall back to using a custom handler | 276 // Fall back to using a custom handler |
| 270 return new URLRequestChromeJob(request, backend_); | 277 return new URLRequestChromeJob(request, backend_); |
| 271 } | 278 } |
| 272 | 279 |
| 273 } // namespace | 280 } // namespace |
| 274 | 281 |
| 275 ChromeURLDataManagerBackend::ChromeURLDataManagerBackend() | 282 ChromeURLDataManagerBackend::ChromeURLDataManagerBackend() |
| 276 : next_request_id_(0) { | 283 : next_request_id_(0) { |
| 277 AddDataSource(new SharedResourcesDataSource()); | 284 AddDataSource(new SharedResourcesDataSource()); |
| 278 } | 285 } |
| 279 | 286 |
| 280 ChromeURLDataManagerBackend::~ChromeURLDataManagerBackend() { | 287 ChromeURLDataManagerBackend::~ChromeURLDataManagerBackend() { |
| 281 for (DataSourceMap::iterator i = data_sources_.begin(); | 288 for (DataSourceMap::iterator i = data_sources_.begin(); |
| 282 i != data_sources_.end(); ++i) { | 289 i != data_sources_.end(); ++i) { |
| 283 i->second->backend_ = NULL; | 290 i->second->backend_ = NULL; |
| 284 } | 291 } |
| 285 data_sources_.clear(); | 292 data_sources_.clear(); |
| 286 } | 293 } |
| 287 | 294 |
| 288 // static | 295 // static |
| 289 net::URLRequestJobFactory::ProtocolHandler* | 296 net::URLRequestJobFactory::ProtocolHandler* |
| 290 ChromeURLDataManagerBackend::CreateProtocolHandler( | 297 ChromeURLDataManagerBackend::CreateProtocolHandler( |
| 291 ChromeURLDataManagerBackend* backend, | 298 ChromeURLDataManagerBackend* backend, |
| 292 ChromeAppCacheService* appcache_service) { | 299 ChromeAppCacheService* appcache_service, |
| 300 webkit_blob::BlobStorageController* blob_storage_controller) { |
| 293 DCHECK(appcache_service); | 301 DCHECK(appcache_service); |
| 302 DCHECK(blob_storage_controller); |
| 294 DCHECK(backend); | 303 DCHECK(backend); |
| 295 return new ChromeProtocolHandler(backend, appcache_service); | 304 return new ChromeProtocolHandler( |
| 305 backend, appcache_service, blob_storage_controller); |
| 296 } | 306 } |
| 297 | 307 |
| 298 void ChromeURLDataManagerBackend::AddDataSource( | 308 void ChromeURLDataManagerBackend::AddDataSource( |
| 299 ChromeURLDataManager::DataSource* source) { | 309 ChromeURLDataManager::DataSource* source) { |
| 300 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 310 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 301 DataSourceMap::iterator i = data_sources_.find(source->source_name()); | 311 DataSourceMap::iterator i = data_sources_.find(source->source_name()); |
| 302 if (i != data_sources_.end()) { | 312 if (i != data_sources_.end()) { |
| 303 if (!source->ShouldReplaceExistingSource()) | 313 if (!source->ShouldReplaceExistingSource()) |
| 304 return; | 314 return; |
| 305 i->second->backend_ = NULL; | 315 i->second->backend_ = NULL; |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 | 488 |
| 479 return new URLRequestChromeJob(request, backend_); | 489 return new URLRequestChromeJob(request, backend_); |
| 480 } | 490 } |
| 481 | 491 |
| 482 } // namespace | 492 } // namespace |
| 483 | 493 |
| 484 net::URLRequestJobFactory::ProtocolHandler* | 494 net::URLRequestJobFactory::ProtocolHandler* |
| 485 CreateDevToolsProtocolHandler(ChromeURLDataManagerBackend* backend) { | 495 CreateDevToolsProtocolHandler(ChromeURLDataManagerBackend* backend) { |
| 486 return new DevToolsJobFactory(backend); | 496 return new DevToolsJobFactory(backend); |
| 487 } | 497 } |
| OLD | NEW |