Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/views/download/download_item_view.h" | 5 #include "chrome/browser/ui/views/download/download_item_view.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 const ui::ThemeProvider* theme) { | 250 const ui::ThemeProvider* theme) { |
| 251 return theme ? theme->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT) | 251 return theme ? theme->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT) |
| 252 : gfx::kPlaceholderColor; | 252 : gfx::kPlaceholderColor; |
| 253 } | 253 } |
| 254 | 254 |
| 255 void DownloadItemView::OnExtractIconComplete(gfx::Image* icon_bitmap) { | 255 void DownloadItemView::OnExtractIconComplete(gfx::Image* icon_bitmap) { |
| 256 if (icon_bitmap) | 256 if (icon_bitmap) |
| 257 shelf_->SchedulePaint(); | 257 shelf_->SchedulePaint(); |
| 258 } | 258 } |
| 259 | 259 |
| 260 bool DownloadItemView::ShouldAllowDownloadFeedback() { | |
| 261 DCHECK(shelf_); | |
| 262 return model_.MightBeMalicious() && model_.ShouldAllowDownloadFeedback() && | |
| 263 !shelf_->browser()->profile()->IsOffTheRecord(); | |
| 264 } | |
| 265 | |
| 266 void DownloadItemView::MaybeSubmitDownloadToFeedbackService( | |
| 267 DownloadCommands::Command download_command) { | |
| 268 PrefService* prefs = shelf_->browser()->profile()->GetPrefs(); | |
| 269 if (!safe_browsing::ExtendedReportingPrefExists(*prefs)) { | |
|
Peter Kasting
2016/10/24 21:39:07
Nit: Remove ! and reverse conditional arms, so the
Jialiu Lin
2016/10/25 21:07:09
Done.
| |
| 270 // Show dialog, because the dialog hasn't been shown before. | |
| 271 DownloadFeedbackDialogView::Show( | |
| 272 shelf_->get_parent()->GetNativeWindow(), shelf_->browser()->profile(), | |
| 273 shelf_->GetNavigator(), | |
| 274 base::Bind(&DownloadItemView::PossiblySubmitDownloadToFeedbackService, | |
| 275 weak_ptr_factory_.GetWeakPtr(), download_command)); | |
| 276 } else { | |
| 277 PossiblySubmitDownloadToFeedbackService( | |
| 278 download_command, safe_browsing::IsExtendedReportingEnabled(*prefs)); | |
| 279 } | |
| 280 } | |
| 281 | |
| 260 // DownloadObserver interface. | 282 // DownloadObserver interface. |
| 261 | 283 |
| 262 // Update the progress graphic on the icon and our text status label | 284 // Update the progress graphic on the icon and our text status label |
| 263 // to reflect our current bytes downloaded, time remaining. | 285 // to reflect our current bytes downloaded, time remaining. |
| 264 void DownloadItemView::OnDownloadUpdated(DownloadItem* download_item) { | 286 void DownloadItemView::OnDownloadUpdated(DownloadItem* download_item) { |
| 265 DCHECK_EQ(download(), download_item); | 287 DCHECK_EQ(download(), download_item); |
| 266 | 288 |
| 267 if (!model_.ShouldShowInShelf()) { | 289 if (!model_.ShouldShowInShelf()) { |
| 268 shelf_->RemoveDownloadView(this); // This will delete us! | 290 shelf_->RemoveDownloadView(this); // This will delete us! |
| 269 return; | 291 return; |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 565 sampling_event_.reset(); | 587 sampling_event_.reset(); |
| 566 } | 588 } |
| 567 // This will change the state and notify us. | 589 // This will change the state and notify us. |
| 568 download()->ValidateDangerousDownload(); | 590 download()->ValidateDangerousDownload(); |
| 569 return; | 591 return; |
| 570 } | 592 } |
| 571 | 593 |
| 572 // WARNING: all end states after this point delete |this|. | 594 // WARNING: all end states after this point delete |this|. |
| 573 DCHECK_EQ(discard_button_, sender); | 595 DCHECK_EQ(discard_button_, sender); |
| 574 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", warning_duration); | 596 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", warning_duration); |
| 575 Profile* profile = shelf_->browser()->profile(); | 597 if (ShouldAllowDownloadFeedback()) { |
|
Peter Kasting
2016/10/24 21:39:07
Nit: No {}
Jialiu Lin
2016/10/25 21:07:09
Done.
| |
| 576 if (!model_.IsMalicious() && model_.ShouldAllowDownloadFeedback() && | 598 MaybeSubmitDownloadToFeedbackService(DownloadCommands::DISCARD); |
| 577 !profile->IsOffTheRecord()) { | 599 } else { |
| 578 if (!safe_browsing::ExtendedReportingPrefExists(*profile->GetPrefs())) { | 600 download()->Remove(); |
| 579 // Show dialog, because the dialog hasn't been shown before. | |
| 580 DownloadFeedbackDialogView::Show( | |
| 581 shelf_->get_parent()->GetNativeWindow(), profile, | |
| 582 shelf_->GetNavigator(), | |
| 583 base::Bind(&DownloadItemView::PossiblySubmitDownloadToFeedbackService, | |
| 584 weak_ptr_factory_.GetWeakPtr())); | |
| 585 } else { | |
| 586 PossiblySubmitDownloadToFeedbackService( | |
| 587 safe_browsing::IsExtendedReportingEnabled(*profile->GetPrefs())); | |
| 588 } | |
| 589 return; | |
| 590 } | 601 } |
| 591 download()->Remove(); | |
| 592 } | 602 } |
| 593 | 603 |
| 594 SkColor DownloadItemView::GetVectorIconBaseColor() const { | 604 SkColor DownloadItemView::GetVectorIconBaseColor() const { |
| 595 return GetTextColor(); | 605 return GetTextColor(); |
| 596 } | 606 } |
| 597 | 607 |
| 598 void DownloadItemView::AnimationProgressed(const gfx::Animation* animation) { | 608 void DownloadItemView::AnimationProgressed(const gfx::Animation* animation) { |
| 599 // We don't care if what animation (body button/drop button/complete), | 609 // We don't care if what animation (body button/drop button/complete), |
| 600 // is calling back, as they all have to go through the same paint call. | 610 // is calling back, as they all have to go through the same paint call. |
| 601 SchedulePaint(); | 611 SchedulePaint(); |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 766 download_protection_service->feedback_service()->BeginFeedbackForDownload( | 776 download_protection_service->feedback_service()->BeginFeedbackForDownload( |
| 767 download()); | 777 download()); |
| 768 // WARNING: we are deleted at this point. Don't access 'this'. | 778 // WARNING: we are deleted at this point. Don't access 'this'. |
| 769 return true; | 779 return true; |
| 770 #else | 780 #else |
| 771 NOTREACHED(); | 781 NOTREACHED(); |
| 772 return false; | 782 return false; |
| 773 #endif | 783 #endif |
| 774 } | 784 } |
| 775 | 785 |
| 776 void DownloadItemView::PossiblySubmitDownloadToFeedbackService(bool enabled) { | 786 void DownloadItemView::PossiblySubmitDownloadToFeedbackService( |
| 777 if (!enabled || !SubmitDownloadToFeedbackService()) | 787 DownloadCommands::Command download_command_id, |
| 788 bool enabled) { | |
| 789 if ((!enabled || !SubmitDownloadToFeedbackService()) && | |
|
Peter Kasting
2016/10/24 21:39:07
Doesn't this result in deleting the download when
asanka
2016/10/25 20:51:13
Yes. The StealDangerousDownload logic is meant to
Jialiu Lin
2016/10/25 21:07:09
oops, Thanks for catching this. Seems changes need
| |
| 790 download_command_id == DownloadCommands::DISCARD) | |
|
Peter Kasting
2016/10/24 21:39:07
Nit: This might be clearer if written like:
if
Jialiu Lin
2016/10/25 21:07:09
Done.
| |
| 778 download()->Remove(); | 791 download()->Remove(); |
| 779 // WARNING: 'this' is deleted at this point. Don't access 'this'. | 792 // WARNING: 'this' is deleted at this point. Don't access 'this'. |
| 780 } | 793 } |
| 781 | 794 |
| 782 void DownloadItemView::LoadIcon() { | 795 void DownloadItemView::LoadIcon() { |
| 783 IconManager* im = g_browser_process->icon_manager(); | 796 IconManager* im = g_browser_process->icon_manager(); |
| 784 last_download_item_path_ = download()->GetTargetFilePath(); | 797 last_download_item_path_ = download()->GetTargetFilePath(); |
| 785 im->LoadIcon(last_download_item_path_, IconLoader::SMALL, | 798 im->LoadIcon(last_download_item_path_, IconLoader::SMALL, |
| 786 base::Bind(&DownloadItemView::OnExtractIconComplete, | 799 base::Bind(&DownloadItemView::OnExtractIconComplete, |
| 787 base::Unretained(this)), | 800 base::Unretained(this)), |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 818 // mouse press event we block RootView in mouse dispatching. This also | 831 // mouse press event we block RootView in mouse dispatching. This also |
| 819 // appears to cause RootView to get a mouse pressed BEFORE the mouse | 832 // appears to cause RootView to get a mouse pressed BEFORE the mouse |
| 820 // release is seen, which means RootView sends us another mouse press no | 833 // release is seen, which means RootView sends us another mouse press no |
| 821 // matter where the user pressed. To force RootView to recalculate the | 834 // matter where the user pressed. To force RootView to recalculate the |
| 822 // mouse target during the mouse press we explicitly set the mouse handler | 835 // mouse target during the mouse press we explicitly set the mouse handler |
| 823 // to null. | 836 // to null. |
| 824 static_cast<views::internal::RootView*>(GetWidget()->GetRootView()) | 837 static_cast<views::internal::RootView*>(GetWidget()->GetRootView()) |
| 825 ->SetMouseHandler(nullptr); | 838 ->SetMouseHandler(nullptr); |
| 826 | 839 |
| 827 if (!context_menu_.get()) | 840 if (!context_menu_.get()) |
| 828 context_menu_.reset(new DownloadShelfContextMenuView(download())); | 841 context_menu_.reset(new DownloadShelfContextMenuView(this)); |
| 829 context_menu_->Run(GetWidget()->GetTopLevelWidget(), rect, source_type, | 842 context_menu_->Run(GetWidget()->GetTopLevelWidget(), rect, source_type, |
| 830 base::Bind(&DownloadItemView::ReleaseDropdown, | 843 base::Bind(&DownloadItemView::ReleaseDropdown, |
| 831 weak_ptr_factory_.GetWeakPtr())); | 844 weak_ptr_factory_.GetWeakPtr())); |
| 832 } | 845 } |
| 833 | 846 |
| 834 void DownloadItemView::HandlePressEvent(const ui::LocatedEvent& event, | 847 void DownloadItemView::HandlePressEvent(const ui::LocatedEvent& event, |
| 835 bool active_event) { | 848 bool active_event) { |
| 836 // The event should not activate us in dangerous/malicious mode. | 849 // The event should not activate us in dangerous/malicious mode. |
| 837 if (IsShowingWarningDialog()) | 850 if (IsShowingWarningDialog()) |
| 838 return; | 851 return; |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1107 SchedulePaint(); | 1120 SchedulePaint(); |
| 1108 } | 1121 } |
| 1109 | 1122 |
| 1110 SkColor DownloadItemView::GetTextColor() const { | 1123 SkColor DownloadItemView::GetTextColor() const { |
| 1111 return GetTextColorForThemeProvider(GetThemeProvider()); | 1124 return GetTextColorForThemeProvider(GetThemeProvider()); |
| 1112 } | 1125 } |
| 1113 | 1126 |
| 1114 SkColor DownloadItemView::GetDimmedTextColor() const { | 1127 SkColor DownloadItemView::GetDimmedTextColor() const { |
| 1115 return SkColorSetA(GetTextColor(), 0xC7); | 1128 return SkColorSetA(GetTextColor(), 0xC7); |
| 1116 } | 1129 } |
| OLD | NEW |