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 void DownloadItemView::MaybeSubmitDownloadToFeedbackService( |
| 261 DownloadCommands::Command download_command) { |
| 262 PrefService* prefs = shelf_->browser()->profile()->GetPrefs(); |
| 263 if (model_.MightBeMalicious() && model_.ShouldAllowDownloadFeedback() && |
| 264 !shelf_->browser()->profile()->IsOffTheRecord()) { |
| 265 if (safe_browsing::ExtendedReportingPrefExists(*prefs)) { |
| 266 SubmitDownloadWhenFeedbackServiceEnabled( |
| 267 download_command, safe_browsing::IsExtendedReportingEnabled(*prefs)); |
| 268 } else { |
| 269 // Show dialog, because the dialog hasn't been shown before. |
| 270 DownloadFeedbackDialogView::Show( |
| 271 shelf_->get_parent()->GetNativeWindow(), shelf_->browser()->profile(), |
| 272 shelf_->GetNavigator(), |
| 273 base::Bind( |
| 274 &DownloadItemView::SubmitDownloadWhenFeedbackServiceEnabled, |
| 275 weak_ptr_factory_.GetWeakPtr(), download_command)); |
| 276 } |
| 277 } else { |
| 278 DownloadCommands(download()).ExecuteCommand(download_command); |
| 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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 if (sampling_event_) { | 588 if (sampling_event_) { |
567 sampling_event_->CreateUserDecisionEvent( | 589 sampling_event_->CreateUserDecisionEvent( |
568 ExperienceSamplingEvent::kProceed); | 590 ExperienceSamplingEvent::kProceed); |
569 sampling_event_.reset(); | 591 sampling_event_.reset(); |
570 } | 592 } |
571 // This will change the state and notify us. | 593 // This will change the state and notify us. |
572 download()->ValidateDangerousDownload(); | 594 download()->ValidateDangerousDownload(); |
573 return; | 595 return; |
574 } | 596 } |
575 | 597 |
576 // WARNING: all end states after this point delete |this|. | |
577 DCHECK_EQ(discard_button_, sender); | 598 DCHECK_EQ(discard_button_, sender); |
578 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", warning_duration); | 599 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", warning_duration); |
579 Profile* profile = shelf_->browser()->profile(); | 600 MaybeSubmitDownloadToFeedbackService(DownloadCommands::DISCARD); |
580 if (!model_.IsMalicious() && model_.ShouldAllowDownloadFeedback() && | 601 // WARNING: 'this' maybe deleted at this point. Don't access 'this'. |
581 !profile->IsOffTheRecord()) { | |
582 if (!safe_browsing::ExtendedReportingPrefExists(*profile->GetPrefs())) { | |
583 // Show dialog, because the dialog hasn't been shown before. | |
584 DownloadFeedbackDialogView::Show( | |
585 shelf_->get_parent()->GetNativeWindow(), profile, | |
586 shelf_->GetNavigator(), | |
587 base::Bind(&DownloadItemView::PossiblySubmitDownloadToFeedbackService, | |
588 weak_ptr_factory_.GetWeakPtr())); | |
589 } else { | |
590 PossiblySubmitDownloadToFeedbackService( | |
591 safe_browsing::IsExtendedReportingEnabled(*profile->GetPrefs())); | |
592 } | |
593 return; | |
594 } | |
595 download()->Remove(); | |
596 } | 602 } |
597 | 603 |
598 SkColor DownloadItemView::GetVectorIconBaseColor() const { | 604 SkColor DownloadItemView::GetVectorIconBaseColor() const { |
599 return GetTextColor(); | 605 return GetTextColor(); |
600 } | 606 } |
601 | 607 |
602 void DownloadItemView::AnimationProgressed(const gfx::Animation* animation) { | 608 void DownloadItemView::AnimationProgressed(const gfx::Animation* animation) { |
603 // 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), |
604 // 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. |
605 SchedulePaint(); | 611 SchedulePaint(); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
750 UMA_HISTOGRAM_LONG_TIMES("clickjacking.open_download", | 756 UMA_HISTOGRAM_LONG_TIMES("clickjacking.open_download", |
751 base::Time::Now() - creation_time_); | 757 base::Time::Now() - creation_time_); |
752 | 758 |
753 UpdateAccessibleName(); | 759 UpdateAccessibleName(); |
754 | 760 |
755 // Calling download()->OpenDownload may delete this, so this must be | 761 // Calling download()->OpenDownload may delete this, so this must be |
756 // the last thing we do. | 762 // the last thing we do. |
757 download()->OpenDownload(); | 763 download()->OpenDownload(); |
758 } | 764 } |
759 | 765 |
760 bool DownloadItemView::SubmitDownloadToFeedbackService() { | 766 bool DownloadItemView::SubmitDownloadToFeedbackService( |
| 767 DownloadCommands::Command download_command) { |
761 #if defined(FULL_SAFE_BROWSING) | 768 #if defined(FULL_SAFE_BROWSING) |
762 safe_browsing::SafeBrowsingService* sb_service = | 769 safe_browsing::SafeBrowsingService* sb_service = |
763 g_browser_process->safe_browsing_service(); | 770 g_browser_process->safe_browsing_service(); |
764 if (!sb_service) | 771 if (!sb_service) |
765 return false; | 772 return false; |
766 safe_browsing::DownloadProtectionService* download_protection_service = | 773 safe_browsing::DownloadProtectionService* download_protection_service = |
767 sb_service->download_protection_service(); | 774 sb_service->download_protection_service(); |
768 if (!download_protection_service) | 775 if (!download_protection_service) |
769 return false; | 776 return false; |
770 download_protection_service->feedback_service()->BeginFeedbackForDownload( | 777 download_protection_service->feedback_service()->BeginFeedbackForDownload( |
771 download()); | 778 download(), download_command); |
772 // WARNING: we are deleted at this point. Don't access 'this'. | 779 // WARNING: we are deleted at this point. Don't access 'this'. |
773 return true; | 780 return true; |
774 #else | 781 #else |
775 NOTREACHED(); | 782 NOTREACHED(); |
776 return false; | 783 return false; |
777 #endif | 784 #endif |
778 } | 785 } |
779 | 786 |
780 void DownloadItemView::PossiblySubmitDownloadToFeedbackService(bool enabled) { | 787 void DownloadItemView::SubmitDownloadWhenFeedbackServiceEnabled( |
781 if (!enabled || !SubmitDownloadToFeedbackService()) | 788 DownloadCommands::Command download_command, |
782 download()->Remove(); | 789 bool feedback_enabled) { |
| 790 if (feedback_enabled && SubmitDownloadToFeedbackService(download_command)) |
| 791 return; |
| 792 |
| 793 DownloadCommands(download()).ExecuteCommand(download_command); |
783 // WARNING: 'this' is deleted at this point. Don't access 'this'. | 794 // WARNING: 'this' is deleted at this point. Don't access 'this'. |
784 } | 795 } |
785 | 796 |
786 void DownloadItemView::LoadIcon() { | 797 void DownloadItemView::LoadIcon() { |
787 IconManager* im = g_browser_process->icon_manager(); | 798 IconManager* im = g_browser_process->icon_manager(); |
788 last_download_item_path_ = download()->GetTargetFilePath(); | 799 last_download_item_path_ = download()->GetTargetFilePath(); |
789 im->LoadIcon(last_download_item_path_, IconLoader::SMALL, | 800 im->LoadIcon(last_download_item_path_, IconLoader::SMALL, |
790 base::Bind(&DownloadItemView::OnExtractIconComplete, | 801 base::Bind(&DownloadItemView::OnExtractIconComplete, |
791 base::Unretained(this)), | 802 base::Unretained(this)), |
792 &cancelable_task_tracker_); | 803 &cancelable_task_tracker_); |
(...skipping 29 matching lines...) Expand all Loading... |
822 // mouse press event we block RootView in mouse dispatching. This also | 833 // mouse press event we block RootView in mouse dispatching. This also |
823 // appears to cause RootView to get a mouse pressed BEFORE the mouse | 834 // appears to cause RootView to get a mouse pressed BEFORE the mouse |
824 // release is seen, which means RootView sends us another mouse press no | 835 // release is seen, which means RootView sends us another mouse press no |
825 // matter where the user pressed. To force RootView to recalculate the | 836 // matter where the user pressed. To force RootView to recalculate the |
826 // mouse target during the mouse press we explicitly set the mouse handler | 837 // mouse target during the mouse press we explicitly set the mouse handler |
827 // to null. | 838 // to null. |
828 static_cast<views::internal::RootView*>(GetWidget()->GetRootView()) | 839 static_cast<views::internal::RootView*>(GetWidget()->GetRootView()) |
829 ->SetMouseHandler(nullptr); | 840 ->SetMouseHandler(nullptr); |
830 | 841 |
831 if (!context_menu_.get()) | 842 if (!context_menu_.get()) |
832 context_menu_.reset(new DownloadShelfContextMenuView(download())); | 843 context_menu_.reset(new DownloadShelfContextMenuView(this)); |
833 context_menu_->Run(GetWidget()->GetTopLevelWidget(), rect, source_type, | 844 context_menu_->Run(GetWidget()->GetTopLevelWidget(), rect, source_type, |
834 base::Bind(&DownloadItemView::ReleaseDropdown, | 845 base::Bind(&DownloadItemView::ReleaseDropdown, |
835 weak_ptr_factory_.GetWeakPtr())); | 846 weak_ptr_factory_.GetWeakPtr())); |
836 } | 847 } |
837 | 848 |
838 void DownloadItemView::HandlePressEvent(const ui::LocatedEvent& event, | 849 void DownloadItemView::HandlePressEvent(const ui::LocatedEvent& event, |
839 bool active_event) { | 850 bool active_event) { |
840 // The event should not activate us in dangerous/malicious mode. | 851 // The event should not activate us in dangerous/malicious mode. |
841 if (IsShowingWarningDialog()) | 852 if (IsShowingWarningDialog()) |
842 return; | 853 return; |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1108 SchedulePaint(); | 1119 SchedulePaint(); |
1109 } | 1120 } |
1110 | 1121 |
1111 SkColor DownloadItemView::GetTextColor() const { | 1122 SkColor DownloadItemView::GetTextColor() const { |
1112 return GetTextColorForThemeProvider(GetThemeProvider()); | 1123 return GetTextColorForThemeProvider(GetThemeProvider()); |
1113 } | 1124 } |
1114 | 1125 |
1115 SkColor DownloadItemView::GetDimmedTextColor() const { | 1126 SkColor DownloadItemView::GetDimmedTextColor() const { |
1116 return SkColorSetA(GetTextColor(), 0xC7); | 1127 return SkColorSetA(GetTextColor(), 0xC7); |
1117 } | 1128 } |
OLD | NEW |