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