OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/views/download_tab_view.h" | 5 #include "chrome/browser/views/download_tab_view.h" |
6 | 6 |
7 #include <time.h> | 7 #include <time.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <functional> | 10 #include <functional> |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 discard_button_->SetEnabled(false); | 278 discard_button_->SetEnabled(false); |
279 | 279 |
280 LayoutDate(); | 280 LayoutDate(); |
281 int dx = kDownloadIconOffset - parent_->big_icon_offset() + | 281 int dx = kDownloadIconOffset - parent_->big_icon_offset() + |
282 parent_->big_icon_size() + kInfoPadding; | 282 parent_->big_icon_size() + kInfoPadding; |
283 | 283 |
284 // File name and URL | 284 // File name and URL |
285 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 285 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
286 ChromeFont font = rb.GetFont(ResourceBundle::WebFont); | 286 ChromeFont font = rb.GetFont(ResourceBundle::WebFont); |
287 file_name_->SetText( | 287 file_name_->SetText( |
288 gfx::ElideFilename(model_->GetFileName(), font, kFilenameSize)); | 288 gfx::ElideFilename(model_->GetFileName().ToWStringHack(), font, |
| 289 kFilenameSize)); |
289 | 290 |
290 gfx::Size file_name_size = file_name_->GetPreferredSize(); | 291 gfx::Size file_name_size = file_name_->GetPreferredSize(); |
291 | 292 |
292 file_name_->SetBounds(dx, parent_->big_icon_offset(), | 293 file_name_->SetBounds(dx, parent_->big_icon_offset(), |
293 std::min(kFilenameSize, | 294 std::min(kFilenameSize, |
294 static_cast<int>(file_name_size.width())), | 295 static_cast<int>(file_name_size.width())), |
295 file_name_size.height()); | 296 file_name_size.height()); |
296 file_name_->SetVisible(true); | 297 file_name_->SetVisible(true); |
297 file_name_->SetEnabled(true); | 298 file_name_->SetEnabled(true); |
298 | 299 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 discard_button_->SetVisible(false); | 333 discard_button_->SetVisible(false); |
333 discard_button_->SetEnabled(false); | 334 discard_button_->SetEnabled(false); |
334 | 335 |
335 LayoutDate(); | 336 LayoutDate(); |
336 int dx = kDownloadIconOffset - parent_->big_icon_offset() + | 337 int dx = kDownloadIconOffset - parent_->big_icon_offset() + |
337 parent_->big_icon_size() + kInfoPadding; | 338 parent_->big_icon_size() + kInfoPadding; |
338 | 339 |
339 // File name and URL, truncated to show cancelled status | 340 // File name and URL, truncated to show cancelled status |
340 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 341 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
341 ChromeFont font = rb.GetFont(ResourceBundle::WebFont); | 342 ChromeFont font = rb.GetFont(ResourceBundle::WebFont); |
342 file_name_->SetText(gfx::ElideFilename(model_->GetFileName(), | 343 file_name_->SetText(gfx::ElideFilename(model_->GetFileName().ToWStringHack(), |
343 font, | 344 font, |
344 kFilenameSize)); | 345 kFilenameSize)); |
345 gfx::Size file_name_size = file_name_->GetPreferredSize(); | 346 gfx::Size file_name_size = file_name_->GetPreferredSize(); |
346 file_name_->SetBounds(dx, parent_->big_icon_offset(), | 347 file_name_->SetBounds(dx, parent_->big_icon_offset(), |
347 kFilenameSize - kProgressSize - kSpacer, | 348 kFilenameSize - kProgressSize - kSpacer, |
348 file_name_size.height()); | 349 file_name_size.height()); |
349 file_name_->SetVisible(true); | 350 file_name_->SetVisible(true); |
350 file_name_->SetEnabled(false); | 351 file_name_->SetEnabled(false); |
351 | 352 |
352 GURL url(model_->url()); | 353 GURL url(model_->url()); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 discard_button_->SetVisible(false); | 424 discard_button_->SetVisible(false); |
424 discard_button_->SetEnabled(false); | 425 discard_button_->SetEnabled(false); |
425 | 426 |
426 LayoutDate(); | 427 LayoutDate(); |
427 int dx = kDownloadIconOffset - parent_->big_icon_offset() + | 428 int dx = kDownloadIconOffset - parent_->big_icon_offset() + |
428 parent_->big_icon_size() + kInfoPadding; | 429 parent_->big_icon_size() + kInfoPadding; |
429 | 430 |
430 // File name and URL, truncated to show progress status | 431 // File name and URL, truncated to show progress status |
431 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 432 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
432 ChromeFont font = rb.GetFont(ResourceBundle::WebFont); | 433 ChromeFont font = rb.GetFont(ResourceBundle::WebFont); |
433 file_name_->SetText(gfx::ElideFilename(model_->GetFileName(), | 434 file_name_->SetText(gfx::ElideFilename(model_->GetFileName().ToWStringHack(), |
434 font, | 435 font, |
435 kFilenameSize)); | 436 kFilenameSize)); |
436 gfx::Size file_name_size = file_name_->GetPreferredSize(); | 437 gfx::Size file_name_size = file_name_->GetPreferredSize(); |
437 file_name_->SetBounds(dx, parent_->big_icon_offset(), | 438 file_name_->SetBounds(dx, parent_->big_icon_offset(), |
438 kFilenameSize - kProgressSize - kSpacer, | 439 kFilenameSize - kProgressSize - kSpacer, |
439 file_name_size.height()); | 440 file_name_size.height()); |
440 file_name_->SetVisible(true); | 441 file_name_->SetVisible(true); |
441 file_name_->SetEnabled(false); | 442 file_name_->SetEnabled(false); |
442 | 443 |
443 GURL url(model_->url()); | 444 GURL url(model_->url()); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 cancel_->SetEnabled(false); | 584 cancel_->SetEnabled(false); |
584 time_remaining_->SetVisible(false); | 585 time_remaining_->SetVisible(false); |
585 download_progress_->SetVisible(false); | 586 download_progress_->SetVisible(false); |
586 | 587 |
587 LayoutDate(); | 588 LayoutDate(); |
588 int dx = kDownloadIconOffset - parent_->big_icon_offset() + | 589 int dx = kDownloadIconOffset - parent_->big_icon_offset() + |
589 parent_->big_icon_size() + kInfoPadding; | 590 parent_->big_icon_size() + kInfoPadding; |
590 | 591 |
591 // Warning message and URL. | 592 // Warning message and URL. |
592 std::wstring file_name; | 593 std::wstring file_name; |
593 ElideString(model_->original_name(), kFileNameMaxLength, &file_name); | 594 ElideString(model_->original_name().ToWStringHack(), kFileNameMaxLength, &file
_name); |
594 dangerous_download_warning_->SetText( | 595 dangerous_download_warning_->SetText( |
595 l10n_util::GetStringF(IDS_PROMPT_DANGEROUS_DOWNLOAD, file_name)); | 596 l10n_util::GetStringF(IDS_PROMPT_DANGEROUS_DOWNLOAD, file_name)); |
596 gfx::Size warning_size = dangerous_download_warning_->GetPreferredSize(); | 597 gfx::Size warning_size = dangerous_download_warning_->GetPreferredSize(); |
597 dangerous_download_warning_->SetBounds(dx, 0, | 598 dangerous_download_warning_->SetBounds(dx, 0, |
598 kFilenameSize, warning_size.height()); | 599 kFilenameSize, warning_size.height()); |
599 dangerous_download_warning_->SetVisible(true); | 600 dangerous_download_warning_->SetVisible(true); |
600 | 601 |
601 GURL url(model_->url()); | 602 GURL url(model_->url()); |
602 download_url_->SetURL(url); | 603 download_url_->SetURL(url); |
603 gfx::Size url_size = download_url_->GetPreferredSize(); | 604 gfx::Size url_size = download_url_->GetPreferredSize(); |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1067 GetParent()->GetParent()->Layout(); | 1068 GetParent()->GetParent()->Layout(); |
1068 SchedulePaint(); | 1069 SchedulePaint(); |
1069 } | 1070 } |
1070 | 1071 |
1071 | 1072 |
1072 // If we have the icon in our cache, then return it. If not, look it up via the | 1073 // If we have the icon in our cache, then return it. If not, look it up via the |
1073 // IconManager. Ignore in progress requests (duplicates). | 1074 // IconManager. Ignore in progress requests (duplicates). |
1074 SkBitmap* DownloadTabView::LookupIcon(DownloadItem* download) { | 1075 SkBitmap* DownloadTabView::LookupIcon(DownloadItem* download) { |
1075 IconManager* im = g_browser_process->icon_manager(); | 1076 IconManager* im = g_browser_process->icon_manager(); |
1076 // Fast look up. | 1077 // Fast look up. |
1077 SkBitmap* icon = im->LookupIcon(download->full_path(), IconLoader::NORMAL); | 1078 SkBitmap* icon = im->LookupIcon(download->full_path().ToWStringHack(), |
| 1079 IconLoader::NORMAL); |
1078 | 1080 |
1079 // Expensive look up. | 1081 // Expensive look up. |
1080 if (!icon) | 1082 if (!icon) |
1081 LoadIcon(download); | 1083 LoadIcon(download); |
1082 | 1084 |
1083 return icon; | 1085 return icon; |
1084 } | 1086 } |
1085 | 1087 |
1086 // Bypass the caches and perform the Icon extraction directly. This is useful in | 1088 // Bypass the caches and perform the Icon extraction directly. This is useful in |
1087 // the case where the download has completed and we want to re-check the file | 1089 // the case where the download has completed and we want to re-check the file |
1088 // to see if it has an embedded icon (which we couldn't do at download start). | 1090 // to see if it has an embedded icon (which we couldn't do at download start). |
1089 void DownloadTabView::LoadIcon(DownloadItem* download) { | 1091 void DownloadTabView::LoadIcon(DownloadItem* download) { |
1090 IconManager* im = g_browser_process->icon_manager(); | 1092 IconManager* im = g_browser_process->icon_manager(); |
1091 IconManager::Handle h = | 1093 IconManager::Handle h = |
1092 im->LoadIcon(download->full_path(), IconLoader::NORMAL, | 1094 im->LoadIcon(download->full_path().ToWStringHack(), IconLoader::NORMAL, |
1093 &icon_consumer_, | 1095 &icon_consumer_, |
1094 NewCallback(this, &DownloadTabView::OnExtractIconComplete)); | 1096 NewCallback(this, &DownloadTabView::OnExtractIconComplete)); |
1095 icon_consumer_.SetClientData(im, h, download); | 1097 icon_consumer_.SetClientData(im, h, download); |
1096 } | 1098 } |
1097 | 1099 |
1098 void DownloadTabView::ClearDownloadInProgress() { | 1100 void DownloadTabView::ClearDownloadInProgress() { |
1099 for (base::hash_set<DownloadItem*>::iterator it = in_progress_.begin(); | 1101 for (base::hash_set<DownloadItem*>::iterator it = in_progress_.begin(); |
1100 it != in_progress_.end(); ++it) | 1102 it != in_progress_.end(); ++it) |
1101 (*it)->RemoveObserver(this); | 1103 (*it)->RemoveObserver(this); |
1102 in_progress_.clear(); | 1104 in_progress_.clear(); |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1329 case NOTIFY_DOWNLOAD_STOP: | 1331 case NOTIFY_DOWNLOAD_STOP: |
1330 DCHECK(profile()->HasCreatedDownloadManager()); | 1332 DCHECK(profile()->HasCreatedDownloadManager()); |
1331 contents_->SetIsLoading( | 1333 contents_->SetIsLoading( |
1332 profile()->GetDownloadManager()->in_progress_count() > 0, | 1334 profile()->GetDownloadManager()->in_progress_count() > 0, |
1333 NULL); | 1335 NULL); |
1334 break; | 1336 break; |
1335 default: | 1337 default: |
1336 break; | 1338 break; |
1337 } | 1339 } |
1338 } | 1340 } |
OLD | NEW |