Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: chrome/browser/ui/views/download/download_item_view.cc

Issue 2363473002: A few more pre-MD code removal cleanups in DownloadItemView. (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/i18n/break_iterator.h" 15 #include "base/i18n/break_iterator.h"
16 #include "base/i18n/rtl.h" 16 #include "base/i18n/rtl.h"
17 #include "base/location.h"
18 #include "base/macros.h" 17 #include "base/macros.h"
19 #include "base/memory/ptr_util.h" 18 #include "base/memory/ptr_util.h"
20 #include "base/metrics/histogram_macros.h" 19 #include "base/metrics/histogram_macros.h"
21 #include "base/single_thread_task_runner.h" 20 #include "base/single_thread_task_runner.h"
22 #include "base/strings/string_util.h" 21 #include "base/strings/string_util.h"
23 #include "base/strings/stringprintf.h"
24 #include "base/strings/sys_string_conversions.h" 22 #include "base/strings/sys_string_conversions.h"
25 #include "base/strings/utf_string_conversions.h" 23 #include "base/strings/utf_string_conversions.h"
26 #include "base/threading/thread_task_runner_handle.h" 24 #include "base/threading/thread_task_runner_handle.h"
27 #include "chrome/browser/browser_process.h" 25 #include "chrome/browser/browser_process.h"
28 #include "chrome/browser/download/chrome_download_manager_delegate.h" 26 #include "chrome/browser/download/chrome_download_manager_delegate.h"
29 #include "chrome/browser/download/download_item_model.h" 27 #include "chrome/browser/download/download_item_model.h"
30 #include "chrome/browser/download/download_stats.h" 28 #include "chrome/browser/download/download_stats.h"
31 #include "chrome/browser/download/drag_download_item.h" 29 #include "chrome/browser/download/drag_download_item.h"
32 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s ampling.h" 30 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s ampling.h"
33 #include "chrome/browser/profiles/profile.h" 31 #include "chrome/browser/profiles/profile.h"
34 #include "chrome/browser/safe_browsing/download_feedback_service.h" 32 #include "chrome/browser/safe_browsing/download_feedback_service.h"
35 #include "chrome/browser/safe_browsing/download_protection_service.h" 33 #include "chrome/browser/safe_browsing/download_protection_service.h"
36 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 34 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
37 #include "chrome/browser/themes/theme_properties.h" 35 #include "chrome/browser/themes/theme_properties.h"
38 #include "chrome/browser/ui/views/download/download_feedback_dialog_view.h" 36 #include "chrome/browser/ui/views/download/download_feedback_dialog_view.h"
39 #include "chrome/browser/ui/views/download/download_shelf_context_menu_view.h" 37 #include "chrome/browser/ui/views/download/download_shelf_context_menu_view.h"
40 #include "chrome/browser/ui/views/download/download_shelf_view.h" 38 #include "chrome/browser/ui/views/download/download_shelf_view.h"
41 #include "chrome/browser/ui/views/frame/browser_view.h" 39 #include "chrome/browser/ui/views/frame/browser_view.h"
42 #include "chrome/common/pref_names.h" 40 #include "chrome/common/pref_names.h"
43 #include "chrome/grit/generated_resources.h" 41 #include "chrome/grit/generated_resources.h"
44 #include "components/prefs/pref_service.h" 42 #include "components/prefs/pref_service.h"
45 #include "content/public/browser/download_danger_type.h" 43 #include "content/public/browser/download_danger_type.h"
46 #include "third_party/icu/source/common/unicode/uchar.h" 44 #include "third_party/icu/source/common/unicode/uchar.h"
47 #include "ui/accessibility/ax_view_state.h" 45 #include "ui/accessibility/ax_view_state.h"
48 #include "ui/base/l10n/l10n_util.h" 46 #include "ui/base/l10n/l10n_util.h"
49 #include "ui/base/material_design/material_design_controller.h"
50 #include "ui/base/resource/resource_bundle.h" 47 #include "ui/base/resource/resource_bundle.h"
51 #include "ui/base/theme_provider.h" 48 #include "ui/base/theme_provider.h"
52 #include "ui/events/event.h" 49 #include "ui/events/event.h"
53 #include "ui/gfx/animation/slide_animation.h" 50 #include "ui/gfx/animation/slide_animation.h"
54 #include "ui/gfx/canvas.h" 51 #include "ui/gfx/canvas.h"
55 #include "ui/gfx/color_palette.h" 52 #include "ui/gfx/color_palette.h"
56 #include "ui/gfx/color_utils.h" 53 #include "ui/gfx/color_utils.h"
57 #include "ui/gfx/image/image.h" 54 #include "ui/gfx/image/image.h"
58 #include "ui/gfx/paint_vector_icon.h" 55 #include "ui/gfx/paint_vector_icon.h"
59 #include "ui/gfx/text_elider.h" 56 #include "ui/gfx/text_elider.h"
60 #include "ui/gfx/text_utils.h" 57 #include "ui/gfx/text_utils.h"
61 #include "ui/gfx/vector_icons_public.h" 58 #include "ui/gfx/vector_icons_public.h"
62 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" 59 #include "ui/views/animation/flood_fill_ink_drop_ripple.h"
63 #include "ui/views/animation/ink_drop_highlight.h" 60 #include "ui/views/animation/ink_drop_highlight.h"
64 #include "ui/views/border.h" 61 #include "ui/views/border.h"
65 #include "ui/views/controls/button/image_button.h"
66 #include "ui/views/controls/button/md_text_button.h" 62 #include "ui/views/controls/button/md_text_button.h"
67 #include "ui/views/controls/button/vector_icon_button.h" 63 #include "ui/views/controls/button/vector_icon_button.h"
68 #include "ui/views/controls/focusable_border.h" 64 #include "ui/views/controls/focusable_border.h"
69 #include "ui/views/controls/label.h" 65 #include "ui/views/controls/label.h"
70 #include "ui/views/mouse_constants.h" 66 #include "ui/views/mouse_constants.h"
71 #include "ui/views/widget/root_view.h" 67 #include "ui/views/widget/root_view.h"
72 #include "ui/views/widget/widget.h" 68 #include "ui/views/widget/widget.h"
73 69
74 using content::DownloadItem; 70 using content::DownloadItem;
75 using extensions::ExperienceSamplingEvent; 71 using extensions::ExperienceSamplingEvent;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 discard_button_(nullptr), 182 discard_button_(nullptr),
187 dropdown_button_(new DropDownButton(this)), 183 dropdown_button_(new DropDownButton(this)),
188 dangerous_download_label_(nullptr), 184 dangerous_download_label_(nullptr),
189 dangerous_download_label_sized_(false), 185 dangerous_download_label_sized_(false),
190 disabled_while_opening_(false), 186 disabled_while_opening_(false),
191 creation_time_(base::Time::Now()), 187 creation_time_(base::Time::Now()),
192 time_download_warning_shown_(base::Time()), 188 time_download_warning_shown_(base::Time()),
193 weak_ptr_factory_(this) { 189 weak_ptr_factory_(this) {
194 SetInkDropMode(InkDropMode::ON); 190 SetInkDropMode(InkDropMode::ON);
195 DCHECK(download()); 191 DCHECK(download());
196 DCHECK(ui::MaterialDesignController::IsModeMaterial());
197 download()->AddObserver(this); 192 download()->AddObserver(this);
198 set_context_menu_controller(this); 193 set_context_menu_controller(this);
199 194
200 dropdown_button_->SetBorder( 195 dropdown_button_->SetBorder(
201 views::Border::CreateEmptyBorder(gfx::Insets(kDropdownBorderWidth))); 196 views::Border::CreateEmptyBorder(gfx::Insets(kDropdownBorderWidth)));
202 dropdown_button_->set_ink_drop_size(gfx::Size(32, 32)); 197 dropdown_button_->set_ink_drop_size(gfx::Size(32, 32));
203 AddChildView(dropdown_button_); 198 AddChildView(dropdown_button_);
204 199
205 LoadIcon(); 200 LoadIcon();
206 201
(...skipping 11 matching lines...) Expand all
218 UpdateColorsFromTheme(); 213 UpdateColorsFromTheme();
219 } 214 }
220 215
221 DownloadItemView::~DownloadItemView() { 216 DownloadItemView::~DownloadItemView() {
222 StopDownloadProgress(); 217 StopDownloadProgress();
223 download()->RemoveObserver(this); 218 download()->RemoveObserver(this);
224 219
225 // ExperienceSampling: If the user took no action to remove the warning 220 // ExperienceSampling: If the user took no action to remove the warning
226 // before it disappeared, then the user effectively dismissed the download 221 // before it disappeared, then the user effectively dismissed the download
227 // without keeping it. 222 // without keeping it.
228 if (sampling_event_.get()) 223 if (sampling_event_)
229 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kIgnore); 224 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kIgnore);
230 } 225 }
231 226
232 // Progress animation handlers. 227 // Progress animation handlers.
233 228
234 void DownloadItemView::StartDownloadProgress() { 229 void DownloadItemView::StartDownloadProgress() {
235 if (progress_timer_.IsRunning()) 230 if (progress_timer_.IsRunning())
236 return; 231 return;
237 progress_start_time_ = base::TimeTicks::Now(); 232 progress_start_time_ = base::TimeTicks::Now();
238 progress_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds( 233 progress_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 drag_start_point_ = event.location(); 411 drag_start_point_ = event.location();
417 AnimateInkDrop(views::InkDropState::HIDDEN, &event); 412 AnimateInkDrop(views::InkDropState::HIDDEN, &event);
418 } 413 }
419 if (dragging_) { 414 if (dragging_) {
420 if (download()->GetState() == DownloadItem::COMPLETE) { 415 if (download()->GetState() == DownloadItem::COMPLETE) {
421 IconManager* im = g_browser_process->icon_manager(); 416 IconManager* im = g_browser_process->icon_manager();
422 gfx::Image* icon = im->LookupIconFromFilepath( 417 gfx::Image* icon = im->LookupIconFromFilepath(
423 download()->GetTargetFilePath(), IconLoader::SMALL); 418 download()->GetTargetFilePath(), IconLoader::SMALL);
424 views::Widget* widget = GetWidget(); 419 views::Widget* widget = GetWidget();
425 DragDownloadItem(download(), icon, 420 DragDownloadItem(download(), icon,
426 widget ? widget->GetNativeView() : NULL); 421 widget ? widget->GetNativeView() : nullptr);
427 } 422 }
428 } else if (ExceededDragThreshold(event.location() - drag_start_point_)) { 423 } else if (ExceededDragThreshold(event.location() - drag_start_point_)) {
429 dragging_ = true; 424 dragging_ = true;
430 } 425 }
431 return true; 426 return true;
432 } 427 }
433 428
434 void DownloadItemView::OnMouseReleased(const ui::MouseEvent& event) { 429 void DownloadItemView::OnMouseReleased(const ui::MouseEvent& event) {
435 HandleClickEvent(event, event.IsOnlyLeftMouseButton()); 430 HandleClickEvent(event, event.IsOnlyLeftMouseButton());
436 } 431 }
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 551
557 base::TimeDelta warning_duration; 552 base::TimeDelta warning_duration;
558 if (!time_download_warning_shown_.is_null()) 553 if (!time_download_warning_shown_.is_null())
559 warning_duration = base::Time::Now() - time_download_warning_shown_; 554 warning_duration = base::Time::Now() - time_download_warning_shown_;
560 555
561 if (save_button_ && sender == save_button_) { 556 if (save_button_ && sender == save_button_) {
562 // The user has confirmed a dangerous download. We'd record how quickly the 557 // The user has confirmed a dangerous download. We'd record how quickly the
563 // user did this to detect whether we're being clickjacked. 558 // user did this to detect whether we're being clickjacked.
564 UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download", warning_duration); 559 UMA_HISTOGRAM_LONG_TIMES("clickjacking.save_download", warning_duration);
565 // ExperienceSampling: User chose to proceed with a dangerous download. 560 // ExperienceSampling: User chose to proceed with a dangerous download.
566 if (sampling_event_.get()) { 561 if (sampling_event_) {
567 sampling_event_->CreateUserDecisionEvent( 562 sampling_event_->CreateUserDecisionEvent(
568 ExperienceSamplingEvent::kProceed); 563 ExperienceSamplingEvent::kProceed);
569 sampling_event_.reset(NULL); 564 sampling_event_.reset();
570 } 565 }
571 // This will change the state and notify us. 566 // This will change the state and notify us.
572 download()->ValidateDangerousDownload(); 567 download()->ValidateDangerousDownload();
573 return; 568 return;
574 } 569 }
575 570
576 // WARNING: all end states after this point delete |this|. 571 // WARNING: all end states after this point delete |this|.
577 DCHECK_EQ(discard_button_, sender); 572 DCHECK_EQ(discard_button_, sender);
578 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", warning_duration); 573 UMA_HISTOGRAM_LONG_TIMES("clickjacking.discard_download", warning_duration);
579 if (!model_.IsMalicious() && model_.ShouldAllowDownloadFeedback() && 574 if (!model_.IsMalicious() && model_.ShouldAllowDownloadFeedback() &&
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 814
820 void DownloadItemView::ShowContextMenuImpl(const gfx::Rect& rect, 815 void DownloadItemView::ShowContextMenuImpl(const gfx::Rect& rect,
821 ui::MenuSourceType source_type) { 816 ui::MenuSourceType source_type) {
822 // Similar hack as in MenuButton. 817 // Similar hack as in MenuButton.
823 // We're about to show the menu from a mouse press. By showing from the 818 // We're about to show the menu from a mouse press. By showing from the
824 // mouse press event we block RootView in mouse dispatching. This also 819 // mouse press event we block RootView in mouse dispatching. This also
825 // appears to cause RootView to get a mouse pressed BEFORE the mouse 820 // appears to cause RootView to get a mouse pressed BEFORE the mouse
826 // release is seen, which means RootView sends us another mouse press no 821 // release is seen, which means RootView sends us another mouse press no
827 // matter where the user pressed. To force RootView to recalculate the 822 // matter where the user pressed. To force RootView to recalculate the
828 // mouse target during the mouse press we explicitly set the mouse handler 823 // mouse target during the mouse press we explicitly set the mouse handler
829 // to NULL. 824 // to null.
830 static_cast<views::internal::RootView*>(GetWidget()->GetRootView()) 825 static_cast<views::internal::RootView*>(GetWidget()->GetRootView())
831 ->SetMouseHandler(NULL); 826 ->SetMouseHandler(nullptr);
832 827
833 if (!context_menu_.get()) 828 if (!context_menu_.get())
834 context_menu_.reset(new DownloadShelfContextMenuView(download())); 829 context_menu_.reset(new DownloadShelfContextMenuView(download()));
835 context_menu_->Run(GetWidget()->GetTopLevelWidget(), rect, source_type, 830 context_menu_->Run(GetWidget()->GetTopLevelWidget(), rect, source_type,
836 base::Bind(&DownloadItemView::ReleaseDropdown, 831 base::Bind(&DownloadItemView::ReleaseDropdown,
837 weak_ptr_factory_.GetWeakPtr())); 832 weak_ptr_factory_.GetWeakPtr()));
838 } 833 }
839 834
840 void DownloadItemView::HandlePressEvent(const ui::LocatedEvent& event, 835 void DownloadItemView::HandlePressEvent(const ui::LocatedEvent& event,
841 bool active_event) { 836 bool active_event) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 896
902 void DownloadItemView::ClearWarningDialog() { 897 void DownloadItemView::ClearWarningDialog() {
903 DCHECK(download()->GetDangerType() == 898 DCHECK(download()->GetDangerType() ==
904 content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED); 899 content::DOWNLOAD_DANGER_TYPE_USER_VALIDATED);
905 DCHECK(IsShowingWarningDialog()); 900 DCHECK(IsShowingWarningDialog());
906 901
907 mode_ = NORMAL_MODE; 902 mode_ = NORMAL_MODE;
908 dropdown_state_ = NORMAL; 903 dropdown_state_ = NORMAL;
909 904
910 // ExperienceSampling: User proceeded through the warning. 905 // ExperienceSampling: User proceeded through the warning.
911 if (sampling_event_.get()) { 906 if (sampling_event_) {
912 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kProceed); 907 sampling_event_->CreateUserDecisionEvent(ExperienceSamplingEvent::kProceed);
913 sampling_event_.reset(NULL); 908 sampling_event_.reset();
914 } 909 }
915 // Remove the views used by the warning dialog. 910 // Remove the views used by the warning dialog.
916 if (save_button_) { 911 delete save_button_;
917 RemoveChildView(save_button_); 912 save_button_ = nullptr;
918 delete save_button_;
919 save_button_ = NULL;
920 }
921 RemoveChildView(discard_button_);
922 delete discard_button_; 913 delete discard_button_;
923 discard_button_ = NULL; 914 discard_button_ = nullptr;
924 RemoveChildView(dangerous_download_label_);
925 delete dangerous_download_label_; 915 delete dangerous_download_label_;
926 dangerous_download_label_ = NULL; 916 dangerous_download_label_ = nullptr;
927 dangerous_download_label_sized_ = false; 917 dangerous_download_label_sized_ = false;
928 918
929 // We need to load the icon now that the download has the real path. 919 // We need to load the icon now that the download has the real path.
930 LoadIcon(); 920 LoadIcon();
931 921
932 dropdown_button_->SetVisible(true); 922 dropdown_button_->SetVisible(true);
933 } 923 }
934 924
935 void DownloadItemView::ShowWarningDialog() { 925 void DownloadItemView::ShowWarningDialog() {
936 DCHECK(mode_ != DANGEROUS_MODE && mode_ != MALICIOUS_MODE); 926 DCHECK(mode_ != DANGEROUS_MODE && mode_ != MALICIOUS_MODE);
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
1118 SchedulePaint(); 1108 SchedulePaint();
1119 } 1109 }
1120 1110
1121 SkColor DownloadItemView::GetTextColor() const { 1111 SkColor DownloadItemView::GetTextColor() const {
1122 return GetTextColorForThemeProvider(GetThemeProvider()); 1112 return GetTextColorForThemeProvider(GetThemeProvider());
1123 } 1113 }
1124 1114
1125 SkColor DownloadItemView::GetDimmedTextColor() const { 1115 SkColor DownloadItemView::GetDimmedTextColor() const {
1126 return SkColorSetA(GetTextColor(), 0xC7); 1116 return SkColorSetA(GetTextColor(), 0xC7);
1127 } 1117 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698