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