| OLD | NEW | 
|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/dom_ui/chrome_url_data_manager.h" | 5 #include "chrome/browser/dom_ui/chrome_url_data_manager.h" | 
| 6 | 6 | 
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" | 
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" | 
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" | 
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
| 27 #include "chrome/common/ref_counted_util.h" | 27 #include "chrome/common/ref_counted_util.h" | 
| 28 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" | 
| 29 #include "googleurl/src/url_util.h" | 29 #include "googleurl/src/url_util.h" | 
| 30 #include "grit/platform_locale_settings.h" | 30 #include "grit/platform_locale_settings.h" | 
| 31 #include "net/base/io_buffer.h" | 31 #include "net/base/io_buffer.h" | 
| 32 #include "net/base/net_errors.h" | 32 #include "net/base/net_errors.h" | 
| 33 #include "net/url_request/url_request.h" | 33 #include "net/url_request/url_request.h" | 
| 34 #include "net/url_request/url_request_file_job.h" | 34 #include "net/url_request/url_request_file_job.h" | 
| 35 #include "net/url_request/url_request_job.h" | 35 #include "net/url_request/url_request_job.h" | 
| 36 | 36 | 
| 37 // URLRequestChromeJob is a URLRequestJob that manages running chrome-internal | 37 // URLRequestChromeJob is a net::URLRequestJob that manages running | 
| 38 // resource requests asynchronously. | 38 // chrome-internal resource requests asynchronously. | 
| 39 // It hands off URL requests to ChromeURLDataManager, which asynchronously | 39 // It hands off URL requests to ChromeURLDataManager, which asynchronously | 
| 40 // calls back once the data is available. | 40 // calls back once the data is available. | 
| 41 class URLRequestChromeJob : public net::URLRequestJob { | 41 class URLRequestChromeJob : public net::URLRequestJob { | 
| 42  public: | 42  public: | 
| 43   explicit URLRequestChromeJob(net::URLRequest* request); | 43   explicit URLRequestChromeJob(net::URLRequest* request); | 
| 44 | 44 | 
| 45   // URLRequestJob implementation. | 45   // net::URLRequestJob implementation. | 
| 46   virtual void Start(); | 46   virtual void Start(); | 
| 47   virtual void Kill(); | 47   virtual void Kill(); | 
| 48   virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int *bytes_read); | 48   virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int *bytes_read); | 
| 49   virtual bool GetMimeType(std::string* mime_type) const; | 49   virtual bool GetMimeType(std::string* mime_type) const; | 
| 50 | 50 | 
| 51   // Called by ChromeURLDataManager to notify us that the data blob is ready | 51   // Called by ChromeURLDataManager to notify us that the data blob is ready | 
| 52   // for us. | 52   // for us. | 
| 53   void DataAvailable(RefCountedMemory* bytes); | 53   void DataAvailable(RefCountedMemory* bytes); | 
| 54 | 54 | 
| 55   void SetMimeType(const std::string& mime_type) { | 55   void SetMimeType(const std::string& mime_type) { | 
| 56     mime_type_ = mime_type; | 56     mime_type_ = mime_type; | 
| 57   } | 57   } | 
| 58 | 58 | 
| 59  private: | 59  private: | 
| 60   virtual ~URLRequestChromeJob(); | 60   virtual ~URLRequestChromeJob(); | 
| 61 | 61 | 
| 62   // Helper for Start(), to let us start asynchronously. | 62   // Helper for Start(), to let us start asynchronously. | 
| 63   // (This pattern is shared by most URLRequestJob implementations.) | 63   // (This pattern is shared by most net::URLRequestJob implementations.) | 
| 64   void StartAsync(); | 64   void StartAsync(); | 
| 65 | 65 | 
| 66   // Do the actual copy from data_ (the data we're serving) into |buf|. | 66   // Do the actual copy from data_ (the data we're serving) into |buf|. | 
| 67   // Separate from ReadRawData so we can handle async I/O. | 67   // Separate from ReadRawData so we can handle async I/O. | 
| 68   void CompleteRead(net::IOBuffer* buf, int buf_size, int* bytes_read); | 68   void CompleteRead(net::IOBuffer* buf, int buf_size, int* bytes_read); | 
| 69 | 69 | 
| 70   // The actual data we're serving.  NULL until it's been fetched. | 70   // The actual data we're serving.  NULL until it's been fetched. | 
| 71   scoped_refptr<RefCountedMemory> data_; | 71   scoped_refptr<RefCountedMemory> data_; | 
| 72   // The current offset into the data that we're handing off to our | 72   // The current offset into the data that we're handing off to our | 
| 73   // callers via the Read interfaces. | 73   // callers via the Read interfaces. | 
| 74   int data_offset_; | 74   int data_offset_; | 
| 75 | 75 | 
| 76   // For async reads, we keep around a pointer to the buffer that | 76   // For async reads, we keep around a pointer to the buffer that | 
| 77   // we're reading into. | 77   // we're reading into. | 
| 78   scoped_refptr<net::IOBuffer> pending_buf_; | 78   scoped_refptr<net::IOBuffer> pending_buf_; | 
| 79   int pending_buf_size_; | 79   int pending_buf_size_; | 
| 80   std::string mime_type_; | 80   std::string mime_type_; | 
| 81 | 81 | 
| 82   DISALLOW_COPY_AND_ASSIGN(URLRequestChromeJob); | 82   DISALLOW_COPY_AND_ASSIGN(URLRequestChromeJob); | 
| 83 }; | 83 }; | 
| 84 | 84 | 
| 85 // URLRequestChromeFileJob is a URLRequestJob that acts like a file:// URL | 85 // URLRequestChromeFileJob is a net::URLRequestJob that acts like a file:// URL | 
| 86 class URLRequestChromeFileJob : public URLRequestFileJob { | 86 class URLRequestChromeFileJob : public URLRequestFileJob { | 
| 87  public: | 87  public: | 
| 88   URLRequestChromeFileJob(net::URLRequest* request, const FilePath& path); | 88   URLRequestChromeFileJob(net::URLRequest* request, const FilePath& path); | 
| 89 | 89 | 
| 90  private: | 90  private: | 
| 91   virtual ~URLRequestChromeFileJob(); | 91   virtual ~URLRequestChromeFileJob(); | 
| 92 | 92 | 
| 93   DISALLOW_COPY_AND_ASSIGN(URLRequestChromeFileJob); | 93   DISALLOW_COPY_AND_ASSIGN(URLRequestChromeFileJob); | 
| 94 }; | 94 }; | 
| 95 | 95 | 
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 315   if (base::win::GetVersion() < base::win::VERSION_VISTA) | 315   if (base::win::GetVersion() < base::win::VERSION_VISTA) | 
| 316     web_font_size_id = IDS_WEB_FONT_SIZE_XP; | 316     web_font_size_id = IDS_WEB_FONT_SIZE_XP; | 
| 317 #endif | 317 #endif | 
| 318   localized_strings->SetString("fontsize", | 318   localized_strings->SetString("fontsize", | 
| 319       l10n_util::GetStringUTF16(web_font_size_id)); | 319       l10n_util::GetStringUTF16(web_font_size_id)); | 
| 320 | 320 | 
| 321   localized_strings->SetString("textdirection", | 321   localized_strings->SetString("textdirection", | 
| 322       base::i18n::IsRTL() ? "rtl" : "ltr"); | 322       base::i18n::IsRTL() ? "rtl" : "ltr"); | 
| 323 } | 323 } | 
| 324 | 324 | 
| 325 URLRequestJob* ChromeURLDataManager::Factory(net::URLRequest* request, | 325 net::URLRequestJob* ChromeURLDataManager::Factory(net::URLRequest* request, | 
| 326                                              const std::string& scheme) { | 326                                                   const std::string& scheme) { | 
| 327   // Try first with a file handler | 327   // Try first with a file handler | 
| 328   FilePath path; | 328   FilePath path; | 
| 329   if (ChromeURLDataManager::URLToFilePath(request->url(), &path)) | 329   if (ChromeURLDataManager::URLToFilePath(request->url(), &path)) | 
| 330     return new URLRequestChromeFileJob(request, path); | 330     return new URLRequestChromeFileJob(request, path); | 
| 331 | 331 | 
| 332   // Next check for chrome://view-http-cache/*, which uses its own job type. | 332   // Next check for chrome://view-http-cache/*, which uses its own job type. | 
| 333   if (ViewHttpCacheJobFactory::IsSupportedURL(request->url())) | 333   if (ViewHttpCacheJobFactory::IsSupportedURL(request->url())) | 
| 334     return ViewHttpCacheJobFactory::CreateJobForRequest(request); | 334     return ViewHttpCacheJobFactory::CreateJobForRequest(request); | 
| 335 | 335 | 
| 336   // Next check for chrome://appcache-internals/, which uses its own job type. | 336   // Next check for chrome://appcache-internals/, which uses its own job type. | 
| 337   if (ViewAppCacheInternalsJobFactory::IsSupportedURL(request->url())) | 337   if (ViewAppCacheInternalsJobFactory::IsSupportedURL(request->url())) | 
| 338     return ViewAppCacheInternalsJobFactory::CreateJobForRequest(request); | 338     return ViewAppCacheInternalsJobFactory::CreateJobForRequest(request); | 
| 339 | 339 | 
| 340   // Next check for chrome://blob-internals/, which uses its own job type. | 340   // Next check for chrome://blob-internals/, which uses its own job type. | 
| 341   if (ViewBlobInternalsJobFactory::IsSupportedURL(request->url())) | 341   if (ViewBlobInternalsJobFactory::IsSupportedURL(request->url())) | 
| 342     return ViewBlobInternalsJobFactory::CreateJobForRequest(request); | 342     return ViewBlobInternalsJobFactory::CreateJobForRequest(request); | 
| 343 | 343 | 
| 344   // Fall back to using a custom handler | 344   // Fall back to using a custom handler | 
| 345   return new URLRequestChromeJob(request); | 345   return new URLRequestChromeJob(request); | 
| 346 } | 346 } | 
| 347 | 347 | 
| 348 URLRequestChromeJob::URLRequestChromeJob(net::URLRequest* request) | 348 URLRequestChromeJob::URLRequestChromeJob(net::URLRequest* request) | 
| 349     : URLRequestJob(request), | 349     : net::URLRequestJob(request), | 
| 350       data_offset_(0), | 350       data_offset_(0), | 
| 351       pending_buf_size_(0) { | 351       pending_buf_size_(0) { | 
| 352 } | 352 } | 
| 353 | 353 | 
| 354 URLRequestChromeJob::~URLRequestChromeJob() { | 354 URLRequestChromeJob::~URLRequestChromeJob() { | 
| 355   CHECK(!ChromeURLDataManager::GetInstance()->HasPendingJob(this)); | 355   CHECK(!ChromeURLDataManager::GetInstance()->HasPendingJob(this)); | 
| 356 } | 356 } | 
| 357 | 357 | 
| 358 void URLRequestChromeJob::Start() { | 358 void URLRequestChromeJob::Start() { | 
| 359   // Start reading asynchronously so that all error reporting and data | 359   // Start reading asynchronously so that all error reporting and data | 
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 431                                       net::ERR_INVALID_URL)); | 431                                       net::ERR_INVALID_URL)); | 
| 432   } | 432   } | 
| 433 } | 433 } | 
| 434 | 434 | 
| 435 URLRequestChromeFileJob::URLRequestChromeFileJob(net::URLRequest* request, | 435 URLRequestChromeFileJob::URLRequestChromeFileJob(net::URLRequest* request, | 
| 436                                                  const FilePath& path) | 436                                                  const FilePath& path) | 
| 437     : URLRequestFileJob(request, path) { | 437     : URLRequestFileJob(request, path) { | 
| 438 } | 438 } | 
| 439 | 439 | 
| 440 URLRequestChromeFileJob::~URLRequestChromeFileJob() { } | 440 URLRequestChromeFileJob::~URLRequestChromeFileJob() { } | 
| OLD | NEW | 
|---|