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 23 matching lines...) Expand all Loading... |
34 #include "net/url_request/url_request.h" | 34 #include "net/url_request/url_request.h" |
35 #include "net/url_request/url_request_file_job.h" | 35 #include "net/url_request/url_request_file_job.h" |
36 #include "net/url_request/url_request_job.h" | 36 #include "net/url_request/url_request_job.h" |
37 | 37 |
38 // URLRequestChromeJob is a URLRequestJob that manages running chrome-internal | 38 // URLRequestChromeJob is a URLRequestJob that manages running chrome-internal |
39 // resource requests asynchronously. | 39 // resource requests asynchronously. |
40 // It hands off URL requests to ChromeURLDataManager, which asynchronously | 40 // It hands off URL requests to ChromeURLDataManager, which asynchronously |
41 // calls back once the data is available. | 41 // calls back once the data is available. |
42 class URLRequestChromeJob : public net::URLRequestJob { | 42 class URLRequestChromeJob : public net::URLRequestJob { |
43 public: | 43 public: |
44 explicit URLRequestChromeJob(URLRequest* request); | 44 explicit URLRequestChromeJob(net::URLRequest* request); |
45 | 45 |
46 // URLRequestJob implementation. | 46 // URLRequestJob implementation. |
47 virtual void Start(); | 47 virtual void Start(); |
48 virtual void Kill(); | 48 virtual void Kill(); |
49 virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int *bytes_read); | 49 virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int *bytes_read); |
50 virtual bool GetMimeType(std::string* mime_type) const; | 50 virtual bool GetMimeType(std::string* mime_type) const; |
51 | 51 |
52 // Called by ChromeURLDataManager to notify us that the data blob is ready | 52 // Called by ChromeURLDataManager to notify us that the data blob is ready |
53 // for us. | 53 // for us. |
54 void DataAvailable(RefCountedMemory* bytes); | 54 void DataAvailable(RefCountedMemory* bytes); |
(...skipping 24 matching lines...) Expand all Loading... |
79 scoped_refptr<net::IOBuffer> pending_buf_; | 79 scoped_refptr<net::IOBuffer> pending_buf_; |
80 int pending_buf_size_; | 80 int pending_buf_size_; |
81 std::string mime_type_; | 81 std::string mime_type_; |
82 | 82 |
83 DISALLOW_COPY_AND_ASSIGN(URLRequestChromeJob); | 83 DISALLOW_COPY_AND_ASSIGN(URLRequestChromeJob); |
84 }; | 84 }; |
85 | 85 |
86 // URLRequestChromeFileJob is a URLRequestJob that acts like a file:// URL | 86 // URLRequestChromeFileJob is a URLRequestJob that acts like a file:// URL |
87 class URLRequestChromeFileJob : public URLRequestFileJob { | 87 class URLRequestChromeFileJob : public URLRequestFileJob { |
88 public: | 88 public: |
89 URLRequestChromeFileJob(URLRequest* request, const FilePath& path); | 89 URLRequestChromeFileJob(net::URLRequest* request, const FilePath& path); |
90 | 90 |
91 private: | 91 private: |
92 virtual ~URLRequestChromeFileJob(); | 92 virtual ~URLRequestChromeFileJob(); |
93 | 93 |
94 DISALLOW_COPY_AND_ASSIGN(URLRequestChromeFileJob); | 94 DISALLOW_COPY_AND_ASSIGN(URLRequestChromeFileJob); |
95 }; | 95 }; |
96 | 96 |
97 void RegisterURLRequestChromeJob() { | 97 void RegisterURLRequestChromeJob() { |
98 FilePath inspector_dir; | 98 FilePath inspector_dir; |
99 if (PathService::Get(chrome::DIR_INSPECTOR, &inspector_dir)) { | 99 if (PathService::Get(chrome::DIR_INSPECTOR, &inspector_dir)) { |
100 Singleton<ChromeURLDataManager>()->AddFileSource( | 100 Singleton<ChromeURLDataManager>()->AddFileSource( |
101 chrome::kChromeUIDevToolsHost, inspector_dir); | 101 chrome::kChromeUIDevToolsHost, inspector_dir); |
102 } | 102 } |
103 | 103 |
104 SharedResourcesDataSource::Register(); | 104 SharedResourcesDataSource::Register(); |
105 URLRequest::RegisterProtocolFactory(chrome::kChromeDevToolsScheme, | 105 net::URLRequest::RegisterProtocolFactory(chrome::kChromeDevToolsScheme, |
106 &ChromeURLDataManager::Factory); | 106 &ChromeURLDataManager::Factory); |
107 URLRequest::RegisterProtocolFactory(chrome::kChromeUIScheme, | 107 net::URLRequest::RegisterProtocolFactory(chrome::kChromeUIScheme, |
108 &ChromeURLDataManager::Factory); | 108 &ChromeURLDataManager::Factory); |
109 } | 109 } |
110 | 110 |
111 void UnregisterURLRequestChromeJob() { | 111 void UnregisterURLRequestChromeJob() { |
112 FilePath inspector_dir; | 112 FilePath inspector_dir; |
113 if (PathService::Get(chrome::DIR_INSPECTOR, &inspector_dir)) { | 113 if (PathService::Get(chrome::DIR_INSPECTOR, &inspector_dir)) { |
114 Singleton<ChromeURLDataManager>()->RemoveFileSource( | 114 Singleton<ChromeURLDataManager>()->RemoveFileSource( |
115 chrome::kChromeUIDevToolsHost); | 115 chrome::kChromeUIDevToolsHost); |
116 } | 116 } |
117 } | 117 } |
118 | 118 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 if (i->second == job) { | 257 if (i->second == job) { |
258 pending_requests_.erase(i); | 258 pending_requests_.erase(i); |
259 return; | 259 return; |
260 } | 260 } |
261 } | 261 } |
262 } | 262 } |
263 | 263 |
264 void ChromeURLDataManager::DataAvailable( | 264 void ChromeURLDataManager::DataAvailable( |
265 RequestID request_id, | 265 RequestID request_id, |
266 scoped_refptr<RefCountedMemory> bytes) { | 266 scoped_refptr<RefCountedMemory> bytes) { |
267 // Forward this data on to the pending URLRequest, if it exists. | 267 // Forward this data on to the pending net::URLRequest, if it exists. |
268 PendingRequestMap::iterator i = pending_requests_.find(request_id); | 268 PendingRequestMap::iterator i = pending_requests_.find(request_id); |
269 if (i != pending_requests_.end()) { | 269 if (i != pending_requests_.end()) { |
270 // We acquire a reference to the job so that it doesn't disappear under the | 270 // We acquire a reference to the job so that it doesn't disappear under the |
271 // feet of any method invoked here (we could trigger a callback). | 271 // feet of any method invoked here (we could trigger a callback). |
272 scoped_refptr<URLRequestChromeJob> job(i->second); | 272 scoped_refptr<URLRequestChromeJob> job(i->second); |
273 pending_requests_.erase(i); | 273 pending_requests_.erase(i); |
274 job->DataAvailable(bytes); | 274 job->DataAvailable(bytes); |
275 } | 275 } |
276 } | 276 } |
277 | 277 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 if (base::win::GetVersion() < base::win::VERSION_VISTA) | 311 if (base::win::GetVersion() < base::win::VERSION_VISTA) |
312 web_font_size_id = IDS_WEB_FONT_SIZE_XP; | 312 web_font_size_id = IDS_WEB_FONT_SIZE_XP; |
313 #endif | 313 #endif |
314 localized_strings->SetString("fontsize", | 314 localized_strings->SetString("fontsize", |
315 l10n_util::GetStringUTF16(web_font_size_id)); | 315 l10n_util::GetStringUTF16(web_font_size_id)); |
316 | 316 |
317 localized_strings->SetString("textdirection", | 317 localized_strings->SetString("textdirection", |
318 base::i18n::IsRTL() ? "rtl" : "ltr"); | 318 base::i18n::IsRTL() ? "rtl" : "ltr"); |
319 } | 319 } |
320 | 320 |
321 URLRequestJob* ChromeURLDataManager::Factory(URLRequest* request, | 321 URLRequestJob* ChromeURLDataManager::Factory(net::URLRequest* request, |
322 const std::string& scheme) { | 322 const std::string& scheme) { |
323 // Try first with a file handler | 323 // Try first with a file handler |
324 FilePath path; | 324 FilePath path; |
325 if (ChromeURLDataManager::URLToFilePath(request->url(), &path)) | 325 if (ChromeURLDataManager::URLToFilePath(request->url(), &path)) |
326 return new URLRequestChromeFileJob(request, path); | 326 return new URLRequestChromeFileJob(request, path); |
327 | 327 |
328 // Next check for chrome://view-http-cache/*, which uses its own job type. | 328 // Next check for chrome://view-http-cache/*, which uses its own job type. |
329 if (ViewHttpCacheJobFactory::IsSupportedURL(request->url())) | 329 if (ViewHttpCacheJobFactory::IsSupportedURL(request->url())) |
330 return ViewHttpCacheJobFactory::CreateJobForRequest(request); | 330 return ViewHttpCacheJobFactory::CreateJobForRequest(request); |
331 | 331 |
332 // Next check for chrome://appcache-internals/, which uses its own job type. | 332 // Next check for chrome://appcache-internals/, which uses its own job type. |
333 if (ViewAppCacheInternalsJobFactory::IsSupportedURL(request->url())) | 333 if (ViewAppCacheInternalsJobFactory::IsSupportedURL(request->url())) |
334 return ViewAppCacheInternalsJobFactory::CreateJobForRequest(request); | 334 return ViewAppCacheInternalsJobFactory::CreateJobForRequest(request); |
335 | 335 |
336 // Next check for chrome://blob-internals/, which uses its own job type. | 336 // Next check for chrome://blob-internals/, which uses its own job type. |
337 if (ViewBlobInternalsJobFactory::IsSupportedURL(request->url())) | 337 if (ViewBlobInternalsJobFactory::IsSupportedURL(request->url())) |
338 return ViewBlobInternalsJobFactory::CreateJobForRequest(request); | 338 return ViewBlobInternalsJobFactory::CreateJobForRequest(request); |
339 | 339 |
340 // Fall back to using a custom handler | 340 // Fall back to using a custom handler |
341 return new URLRequestChromeJob(request); | 341 return new URLRequestChromeJob(request); |
342 } | 342 } |
343 | 343 |
344 URLRequestChromeJob::URLRequestChromeJob(URLRequest* request) | 344 URLRequestChromeJob::URLRequestChromeJob(net::URLRequest* request) |
345 : URLRequestJob(request), | 345 : URLRequestJob(request), |
346 data_offset_(0), | 346 data_offset_(0), |
347 pending_buf_size_(0) { | 347 pending_buf_size_(0) { |
348 } | 348 } |
349 | 349 |
350 URLRequestChromeJob::~URLRequestChromeJob() { | 350 URLRequestChromeJob::~URLRequestChromeJob() { |
351 CHECK(!Singleton<ChromeURLDataManager>()->HasPendingJob(this)); | 351 CHECK(!Singleton<ChromeURLDataManager>()->HasPendingJob(this)); |
352 } | 352 } |
353 | 353 |
354 void URLRequestChromeJob::Start() { | 354 void URLRequestChromeJob::Start() { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 return; | 420 return; |
421 | 421 |
422 if (Singleton<ChromeURLDataManager>()->StartRequest(request_->url(), this)) { | 422 if (Singleton<ChromeURLDataManager>()->StartRequest(request_->url(), this)) { |
423 NotifyHeadersComplete(); | 423 NotifyHeadersComplete(); |
424 } else { | 424 } else { |
425 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, | 425 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, |
426 net::ERR_INVALID_URL)); | 426 net::ERR_INVALID_URL)); |
427 } | 427 } |
428 } | 428 } |
429 | 429 |
430 URLRequestChromeFileJob::URLRequestChromeFileJob(URLRequest* request, | 430 URLRequestChromeFileJob::URLRequestChromeFileJob(net::URLRequest* request, |
431 const FilePath& path) | 431 const FilePath& path) |
432 : URLRequestFileJob(request, path) { | 432 : URLRequestFileJob(request, path) { |
433 } | 433 } |
434 | 434 |
435 URLRequestChromeFileJob::~URLRequestChromeFileJob() { } | 435 URLRequestChromeFileJob::~URLRequestChromeFileJob() { } |
OLD | NEW |