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 command(download()); | |
279 command.ExecuteCommand(download_command); | |
280 } | |
281 } | |
282 | |
260 // DownloadObserver interface. | 283 // DownloadObserver interface. |
261 | 284 |
262 // Update the progress graphic on the icon and our text status label | 285 // Update the progress graphic on the icon and our text status label |
263 // to reflect our current bytes downloaded, time remaining. | 286 // to reflect our current bytes downloaded, time remaining. |
264 void DownloadItemView::OnDownloadUpdated(DownloadItem* download_item) { | 287 void DownloadItemView::OnDownloadUpdated(DownloadItem* download_item) { |
265 DCHECK_EQ(download(), download_item); | 288 DCHECK_EQ(download(), download_item); |
266 | 289 |
267 if (!model_.ShouldShowInShelf()) { | 290 if (!model_.ShouldShowInShelf()) { |
268 shelf_->RemoveDownloadView(this); // This will delete us! | 291 shelf_->RemoveDownloadView(this); // This will delete us! |
269 return; | 292 return; |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
562 if (sampling_event_) { | 585 if (sampling_event_) { |
563 sampling_event_->CreateUserDecisionEvent( | 586 sampling_event_->CreateUserDecisionEvent( |
564 ExperienceSamplingEvent::kProceed); | 587 ExperienceSamplingEvent::kProceed); |
565 sampling_event_.reset(); | 588 sampling_event_.reset(); |
566 } | 589 } |
567 // This will change the state and notify us. | 590 // This will change the state and notify us. |
568 download()->ValidateDangerousDownload(); | 591 download()->ValidateDangerousDownload(); |
569 return; | 592 return; |
570 } | 593 } |
571 | 594 |
572 // WARNING: all end states after this point delete |this|. | 595 // WARNING: all end states after this point delete |this|. |
Peter Kasting
2016/11/01 23:48:32
I think this lies; when MaybeSubmit...() calls Dow
Jialiu Lin
2016/11/03 20:16:50
Done.
| |
573 DCHECK_EQ(discard_button_, sender); | 596 DCHECK_EQ(discard_button_, sender); |
574 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", warning_duration); | 597 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", warning_duration); |
575 Profile* profile = shelf_->browser()->profile(); | 598 MaybeSubmitDownloadToFeedbackService(DownloadCommands::DISCARD); |
576 if (!model_.IsMalicious() && model_.ShouldAllowDownloadFeedback() && | |
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 } | 599 } |
593 | 600 |
594 SkColor DownloadItemView::GetVectorIconBaseColor() const { | 601 SkColor DownloadItemView::GetVectorIconBaseColor() const { |
595 return GetTextColor(); | 602 return GetTextColor(); |
596 } | 603 } |
597 | 604 |
598 void DownloadItemView::AnimationProgressed(const gfx::Animation* animation) { | 605 void DownloadItemView::AnimationProgressed(const gfx::Animation* animation) { |
599 // We don't care if what animation (body button/drop button/complete), | 606 // 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. | 607 // is calling back, as they all have to go through the same paint call. |
601 SchedulePaint(); | 608 SchedulePaint(); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
746 UMA_HISTOGRAM_LONG_TIMES("clickjacking.open_download", | 753 UMA_HISTOGRAM_LONG_TIMES("clickjacking.open_download", |
747 base::Time::Now() - creation_time_); | 754 base::Time::Now() - creation_time_); |
748 | 755 |
749 UpdateAccessibleName(); | 756 UpdateAccessibleName(); |
750 | 757 |
751 // Calling download()->OpenDownload may delete this, so this must be | 758 // Calling download()->OpenDownload may delete this, so this must be |
752 // the last thing we do. | 759 // the last thing we do. |
753 download()->OpenDownload(); | 760 download()->OpenDownload(); |
754 } | 761 } |
755 | 762 |
756 bool DownloadItemView::SubmitDownloadToFeedbackService() { | 763 bool DownloadItemView::SubmitDownloadToFeedbackService( |
764 DownloadCommands::Command download_command) { | |
757 #if defined(FULL_SAFE_BROWSING) | 765 #if defined(FULL_SAFE_BROWSING) |
758 safe_browsing::SafeBrowsingService* sb_service = | 766 safe_browsing::SafeBrowsingService* sb_service = |
759 g_browser_process->safe_browsing_service(); | 767 g_browser_process->safe_browsing_service(); |
760 if (!sb_service) | 768 if (!sb_service) |
761 return false; | 769 return false; |
762 safe_browsing::DownloadProtectionService* download_protection_service = | 770 safe_browsing::DownloadProtectionService* download_protection_service = |
763 sb_service->download_protection_service(); | 771 sb_service->download_protection_service(); |
764 if (!download_protection_service) | 772 if (!download_protection_service) |
765 return false; | 773 return false; |
766 download_protection_service->feedback_service()->BeginFeedbackForDownload( | 774 download_protection_service->feedback_service()->BeginFeedbackForDownload( |
767 download()); | 775 download(), download_command); |
768 // WARNING: we are deleted at this point. Don't access 'this'. | 776 // WARNING: we are deleted at this point. Don't access 'this'. |
769 return true; | 777 return true; |
770 #else | 778 #else |
771 NOTREACHED(); | 779 NOTREACHED(); |
772 return false; | 780 return false; |
773 #endif | 781 #endif |
774 } | 782 } |
775 | 783 |
776 void DownloadItemView::PossiblySubmitDownloadToFeedbackService(bool enabled) { | 784 void DownloadItemView::SubmitDownloadWhenFeedbackServiceEnabled( |
777 if (!enabled || !SubmitDownloadToFeedbackService()) | 785 DownloadCommands::Command download_command, |
778 download()->Remove(); | 786 bool feedback_enabled) { |
787 if (feedback_enabled && SubmitDownloadToFeedbackService(download_command)) | |
788 return; | |
789 | |
790 DownloadCommands command(download()); | |
791 command.ExecuteCommand(download_command); | |
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)), |
788 &cancelable_task_tracker_); | 801 &cancelable_task_tracker_); |
(...skipping 29 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 |