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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 if (base::win::GetVersion() < base::win::VERSION_VISTA) | 310 if (base::win::GetVersion() < base::win::VERSION_VISTA) |
311 web_font_size_id = IDS_WEB_FONT_SIZE_XP; | 311 web_font_size_id = IDS_WEB_FONT_SIZE_XP; |
312 #endif | 312 #endif |
313 localized_strings->SetString("fontsize", | 313 localized_strings->SetString("fontsize", |
314 l10n_util::GetStringUTF16(web_font_size_id)); | 314 l10n_util::GetStringUTF16(web_font_size_id)); |
315 | 315 |
316 localized_strings->SetString("textdirection", | 316 localized_strings->SetString("textdirection", |
317 base::i18n::IsRTL() ? "rtl" : "ltr"); | 317 base::i18n::IsRTL() ? "rtl" : "ltr"); |
318 } | 318 } |
319 | 319 |
320 URLRequestJob* ChromeURLDataManager::Factory(net::URLRequest* request, | 320 net::URLRequestJob* ChromeURLDataManager::Factory(net::URLRequest* request, |
321 const std::string& scheme) { | 321 const std::string& scheme) { |
322 // Try first with a file handler | 322 // Try first with a file handler |
323 FilePath path; | 323 FilePath path; |
324 if (ChromeURLDataManager::URLToFilePath(request->url(), &path)) | 324 if (ChromeURLDataManager::URLToFilePath(request->url(), &path)) |
325 return new URLRequestChromeFileJob(request, path); | 325 return new URLRequestChromeFileJob(request, path); |
326 | 326 |
327 // Next check for chrome://view-http-cache/*, which uses its own job type. | 327 // Next check for chrome://view-http-cache/*, which uses its own job type. |
328 if (ViewHttpCacheJobFactory::IsSupportedURL(request->url())) | 328 if (ViewHttpCacheJobFactory::IsSupportedURL(request->url())) |
329 return ViewHttpCacheJobFactory::CreateJobForRequest(request); | 329 return ViewHttpCacheJobFactory::CreateJobForRequest(request); |
330 | 330 |
331 // Next check for chrome://appcache-internals/, which uses its own job type. | 331 // Next check for chrome://appcache-internals/, which uses its own job type. |
332 if (ViewAppCacheInternalsJobFactory::IsSupportedURL(request->url())) | 332 if (ViewAppCacheInternalsJobFactory::IsSupportedURL(request->url())) |
333 return ViewAppCacheInternalsJobFactory::CreateJobForRequest(request); | 333 return ViewAppCacheInternalsJobFactory::CreateJobForRequest(request); |
334 | 334 |
335 // Next check for chrome://blob-internals/, which uses its own job type. | 335 // Next check for chrome://blob-internals/, which uses its own job type. |
336 if (ViewBlobInternalsJobFactory::IsSupportedURL(request->url())) | 336 if (ViewBlobInternalsJobFactory::IsSupportedURL(request->url())) |
337 return ViewBlobInternalsJobFactory::CreateJobForRequest(request); | 337 return ViewBlobInternalsJobFactory::CreateJobForRequest(request); |
338 | 338 |
339 // Fall back to using a custom handler | 339 // Fall back to using a custom handler |
340 return new URLRequestChromeJob(request); | 340 return new URLRequestChromeJob(request); |
341 } | 341 } |
342 | 342 |
343 URLRequestChromeJob::URLRequestChromeJob(net::URLRequest* request) | 343 URLRequestChromeJob::URLRequestChromeJob(net::URLRequest* request) |
344 : URLRequestJob(request), | 344 : net::URLRequestJob(request), |
345 data_offset_(0), | 345 data_offset_(0), |
346 pending_buf_size_(0) { | 346 pending_buf_size_(0) { |
347 } | 347 } |
348 | 348 |
349 URLRequestChromeJob::~URLRequestChromeJob() { | 349 URLRequestChromeJob::~URLRequestChromeJob() { |
350 CHECK(!Singleton<ChromeURLDataManager>()->HasPendingJob(this)); | 350 CHECK(!Singleton<ChromeURLDataManager>()->HasPendingJob(this)); |
351 } | 351 } |
352 | 352 |
353 void URLRequestChromeJob::Start() { | 353 void URLRequestChromeJob::Start() { |
354 // Start reading asynchronously so that all error reporting and data | 354 // Start reading asynchronously so that all error reporting and data |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 net::ERR_INVALID_URL)); | 425 net::ERR_INVALID_URL)); |
426 } | 426 } |
427 } | 427 } |
428 | 428 |
429 URLRequestChromeFileJob::URLRequestChromeFileJob(net::URLRequest* request, | 429 URLRequestChromeFileJob::URLRequestChromeFileJob(net::URLRequest* request, |
430 const FilePath& path) | 430 const FilePath& path) |
431 : URLRequestFileJob(request, path) { | 431 : URLRequestFileJob(request, path) { |
432 } | 432 } |
433 | 433 |
434 URLRequestChromeFileJob::~URLRequestChromeFileJob() { } | 434 URLRequestChromeFileJob::~URLRequestChromeFileJob() { } |
OLD | NEW |