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 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 if (sampling_event_) { | 584 if (sampling_event_) { |
563 sampling_event_->CreateUserDecisionEvent( | 585 sampling_event_->CreateUserDecisionEvent( |
564 ExperienceSamplingEvent::kProceed); | 586 ExperienceSamplingEvent::kProceed); |
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|. | |
573 DCHECK_EQ(discard_button_, sender); | 594 DCHECK_EQ(discard_button_, sender); |
574 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", warning_duration); | 595 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", warning_duration); |
575 Profile* profile = shelf_->browser()->profile(); | 596 MaybeSubmitDownloadToFeedbackService(DownloadCommands::DISCARD); |
576 if (!model_.IsMalicious() && model_.ShouldAllowDownloadFeedback() && | 597 // WARNING: 'this' maybe deleted at this point. Don't access 'this'. |
577 !profile->IsOffTheRecord()) { | |
578 if (!safe_browsing::ExtendedReportingPrefExists(*profile->GetPrefs())) { | |
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 } | |
591 download()->Remove(); | |
592 } | 598 } |
593 | 599 |
594 SkColor DownloadItemView::GetVectorIconBaseColor() const { | 600 SkColor DownloadItemView::GetVectorIconBaseColor() const { |
595 return GetTextColor(); | 601 return GetTextColor(); |
596 } | 602 } |
597 | 603 |
598 void DownloadItemView::AnimationProgressed(const gfx::Animation* animation) { | 604 void DownloadItemView::AnimationProgressed(const gfx::Animation* animation) { |
599 // We don't care if what animation (body button/drop button/complete), | 605 // 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. | 606 // is calling back, as they all have to go through the same paint call. |
601 SchedulePaint(); | 607 SchedulePaint(); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 UMA_HISTOGRAM_LONG_TIMES("clickjacking.open_download", | 752 UMA_HISTOGRAM_LONG_TIMES("clickjacking.open_download", |
747 base::Time::Now() - creation_time_); | 753 base::Time::Now() - creation_time_); |
748 | 754 |
749 UpdateAccessibleName(); | 755 UpdateAccessibleName(); |
750 | 756 |
751 // Calling download()->OpenDownload may delete this, so this must be | 757 // Calling download()->OpenDownload may delete this, so this must be |
752 // the last thing we do. | 758 // the last thing we do. |
753 download()->OpenDownload(); | 759 download()->OpenDownload(); |
754 } | 760 } |
755 | 761 |
756 bool DownloadItemView::SubmitDownloadToFeedbackService() { | 762 bool DownloadItemView::SubmitDownloadToFeedbackService( |
| 763 DownloadCommands::Command download_command) { |
757 #if defined(FULL_SAFE_BROWSING) | 764 #if defined(FULL_SAFE_BROWSING) |
758 safe_browsing::SafeBrowsingService* sb_service = | 765 safe_browsing::SafeBrowsingService* sb_service = |
759 g_browser_process->safe_browsing_service(); | 766 g_browser_process->safe_browsing_service(); |
760 if (!sb_service) | 767 if (!sb_service) |
761 return false; | 768 return false; |
762 safe_browsing::DownloadProtectionService* download_protection_service = | 769 safe_browsing::DownloadProtectionService* download_protection_service = |
763 sb_service->download_protection_service(); | 770 sb_service->download_protection_service(); |
764 if (!download_protection_service) | 771 if (!download_protection_service) |
765 return false; | 772 return false; |
766 download_protection_service->feedback_service()->BeginFeedbackForDownload( | 773 download_protection_service->feedback_service()->BeginFeedbackForDownload( |
767 download()); | 774 download(), download_command); |
768 // WARNING: we are deleted at this point. Don't access 'this'. | 775 // WARNING: we are deleted at this point. Don't access 'this'. |
769 return true; | 776 return true; |
770 #else | 777 #else |
771 NOTREACHED(); | 778 NOTREACHED(); |
772 return false; | 779 return false; |
773 #endif | 780 #endif |
774 } | 781 } |
775 | 782 |
776 void DownloadItemView::PossiblySubmitDownloadToFeedbackService(bool enabled) { | 783 void DownloadItemView::SubmitDownloadWhenFeedbackServiceEnabled( |
777 if (!enabled || !SubmitDownloadToFeedbackService()) | 784 DownloadCommands::Command download_command, |
778 download()->Remove(); | 785 bool feedback_enabled) { |
| 786 if (feedback_enabled && SubmitDownloadToFeedbackService(download_command)) |
| 787 return; |
| 788 |
| 789 DownloadCommands(download()).ExecuteCommand(download_command); |
779 // WARNING: 'this' is deleted at this point. Don't access 'this'. | 790 // WARNING: 'this' is deleted at this point. Don't access 'this'. |
780 } | 791 } |
781 | 792 |
782 void DownloadItemView::LoadIcon() { | 793 void DownloadItemView::LoadIcon() { |
783 IconManager* im = g_browser_process->icon_manager(); | 794 IconManager* im = g_browser_process->icon_manager(); |
784 last_download_item_path_ = download()->GetTargetFilePath(); | 795 last_download_item_path_ = download()->GetTargetFilePath(); |
785 im->LoadIcon(last_download_item_path_, IconLoader::SMALL, | 796 im->LoadIcon(last_download_item_path_, IconLoader::SMALL, |
786 base::Bind(&DownloadItemView::OnExtractIconComplete, | 797 base::Bind(&DownloadItemView::OnExtractIconComplete, |
787 base::Unretained(this)), | 798 base::Unretained(this)), |
788 &cancelable_task_tracker_); | 799 &cancelable_task_tracker_); |
(...skipping 29 matching lines...) Expand all Loading... |
818 // mouse press event we block RootView in mouse dispatching. This also | 829 // mouse press event we block RootView in mouse dispatching. This also |
819 // appears to cause RootView to get a mouse pressed BEFORE the mouse | 830 // 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 | 831 // release is seen, which means RootView sends us another mouse press no |
821 // matter where the user pressed. To force RootView to recalculate the | 832 // matter where the user pressed. To force RootView to recalculate the |
822 // mouse target during the mouse press we explicitly set the mouse handler | 833 // mouse target during the mouse press we explicitly set the mouse handler |
823 // to null. | 834 // to null. |
824 static_cast<views::internal::RootView*>(GetWidget()->GetRootView()) | 835 static_cast<views::internal::RootView*>(GetWidget()->GetRootView()) |
825 ->SetMouseHandler(nullptr); | 836 ->SetMouseHandler(nullptr); |
826 | 837 |
827 if (!context_menu_.get()) | 838 if (!context_menu_.get()) |
828 context_menu_.reset(new DownloadShelfContextMenuView(download())); | 839 context_menu_.reset(new DownloadShelfContextMenuView(this)); |
829 context_menu_->Run(GetWidget()->GetTopLevelWidget(), rect, source_type, | 840 context_menu_->Run(GetWidget()->GetTopLevelWidget(), rect, source_type, |
830 base::Bind(&DownloadItemView::ReleaseDropdown, | 841 base::Bind(&DownloadItemView::ReleaseDropdown, |
831 weak_ptr_factory_.GetWeakPtr())); | 842 weak_ptr_factory_.GetWeakPtr())); |
832 } | 843 } |
833 | 844 |
834 void DownloadItemView::HandlePressEvent(const ui::LocatedEvent& event, | 845 void DownloadItemView::HandlePressEvent(const ui::LocatedEvent& event, |
835 bool active_event) { | 846 bool active_event) { |
836 // The event should not activate us in dangerous/malicious mode. | 847 // The event should not activate us in dangerous/malicious mode. |
837 if (IsShowingWarningDialog()) | 848 if (IsShowingWarningDialog()) |
838 return; | 849 return; |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1104 SchedulePaint(); | 1115 SchedulePaint(); |
1105 } | 1116 } |
1106 | 1117 |
1107 SkColor DownloadItemView::GetTextColor() const { | 1118 SkColor DownloadItemView::GetTextColor() const { |
1108 return GetTextColorForThemeProvider(GetThemeProvider()); | 1119 return GetTextColorForThemeProvider(GetThemeProvider()); |
1109 } | 1120 } |
1110 | 1121 |
1111 SkColor DownloadItemView::GetDimmedTextColor() const { | 1122 SkColor DownloadItemView::GetDimmedTextColor() const { |
1112 return SkColorSetA(GetTextColor(), 0xC7); | 1123 return SkColorSetA(GetTextColor(), 0xC7); |
1113 } | 1124 } |
OLD | NEW |