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

Side by Side Diff: chrome/browser/ui/views/toolbar/toolbar_view.cc

Issue 395193003: Create a cross-platform helper class for badging the wrench menu. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/toolbar/toolbar_view.h" 5 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
6 6
7 #include <algorithm>
8
7 #include "base/command_line.h" 9 #include "base/command_line.h"
8 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
9 #include "base/i18n/number_formatting.h" 11 #include "base/i18n/number_formatting.h"
10 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
11 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/app/chrome_command_ids.h" 14 #include "chrome/app/chrome_command_ids.h"
13 #include "chrome/browser/chrome_notification_types.h" 15 #include "chrome/browser/chrome_notification_types.h"
14 #include "chrome/browser/command_updater.h" 16 #include "chrome/browser/command_updater.h"
15 #include "chrome/browser/extensions/extension_action.h" 17 #include "chrome/browser/extensions/extension_action.h"
16 #include "chrome/browser/extensions/extension_action_manager.h" 18 #include "chrome/browser/extensions/extension_action_manager.h"
(...skipping 20 matching lines...) Expand all
37 #include "chrome/browser/ui/views/location_bar/star_view.h" 39 #include "chrome/browser/ui/views/location_bar/star_view.h"
38 #include "chrome/browser/ui/views/location_bar/translate_icon_view.h" 40 #include "chrome/browser/ui/views/location_bar/translate_icon_view.h"
39 #include "chrome/browser/ui/views/outdated_upgrade_bubble_view.h" 41 #include "chrome/browser/ui/views/outdated_upgrade_bubble_view.h"
40 #include "chrome/browser/ui/views/toolbar/back_button.h" 42 #include "chrome/browser/ui/views/toolbar/back_button.h"
41 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" 43 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h"
42 #include "chrome/browser/ui/views/toolbar/home_button.h" 44 #include "chrome/browser/ui/views/toolbar/home_button.h"
43 #include "chrome/browser/ui/views/toolbar/reload_button.h" 45 #include "chrome/browser/ui/views/toolbar/reload_button.h"
44 #include "chrome/browser/ui/views/toolbar/toolbar_button.h" 46 #include "chrome/browser/ui/views/toolbar/toolbar_button.h"
45 #include "chrome/browser/ui/views/toolbar/wrench_menu.h" 47 #include "chrome/browser/ui/views/toolbar/wrench_menu.h"
46 #include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h" 48 #include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h"
47 #include "chrome/browser/upgrade_detector.h"
48 #include "chrome/common/chrome_switches.h" 49 #include "chrome/common/chrome_switches.h"
49 #include "chrome/common/pref_names.h" 50 #include "chrome/common/pref_names.h"
50 #include "content/public/browser/browser_accessibility_state.h" 51 #include "content/public/browser/browser_accessibility_state.h"
51 #include "content/public/browser/notification_service.h" 52 #include "content/public/browser/notification_service.h"
52 #include "content/public/browser/render_view_host.h" 53 #include "content/public/browser/render_view_host.h"
53 #include "content/public/browser/user_metrics.h" 54 #include "content/public/browser/user_metrics.h"
54 #include "content/public/browser/web_contents.h" 55 #include "content/public/browser/web_contents.h"
55 #include "grit/chromium_strings.h" 56 #include "grit/chromium_strings.h"
56 #include "grit/generated_resources.h" 57 #include "grit/generated_resources.h"
57 #include "grit/theme_resources.h" 58 #include "grit/theme_resources.h"
58 #include "ui/accessibility/ax_view_state.h" 59 #include "ui/accessibility/ax_view_state.h"
59 #include "ui/aura/window.h" 60 #include "ui/aura/window.h"
60 #include "ui/base/l10n/l10n_util.h" 61 #include "ui/base/l10n/l10n_util.h"
61 #include "ui/base/theme_provider.h" 62 #include "ui/base/theme_provider.h"
62 #include "ui/base/window_open_disposition.h" 63 #include "ui/base/window_open_disposition.h"
63 #include "ui/compositor/layer.h" 64 #include "ui/compositor/layer.h"
64 #include "ui/gfx/canvas.h" 65 #include "ui/gfx/canvas.h"
65 #include "ui/gfx/image/canvas_image_source.h" 66 #include "ui/gfx/image/canvas_image_source.h"
66 #include "ui/keyboard/keyboard_controller.h" 67 #include "ui/keyboard/keyboard_controller.h"
67 #include "ui/native_theme/native_theme_aura.h" 68 #include "ui/native_theme/native_theme_aura.h"
68 #include "ui/views/controls/menu/menu_listener.h" 69 #include "ui/views/controls/menu/menu_listener.h"
69 #include "ui/views/focus/view_storage.h" 70 #include "ui/views/focus/view_storage.h"
70 #include "ui/views/view_targeter.h" 71 #include "ui/views/view_targeter.h"
71 #include "ui/views/widget/tooltip_manager.h" 72 #include "ui/views/widget/tooltip_manager.h"
72 #include "ui/views/widget/widget.h" 73 #include "ui/views/widget/widget.h"
73 #include "ui/views/window/non_client_view.h" 74 #include "ui/views/window/non_client_view.h"
74 75
75 #if defined(OS_WIN) 76 #if defined(OS_WIN)
76 #include "base/win/windows_version.h"
77 #include "chrome/browser/enumerate_modules_model_win.h"
78 #include "chrome/browser/ui/views/conflicting_module_view_win.h" 77 #include "chrome/browser/ui/views/conflicting_module_view_win.h"
79 #include "chrome/browser/ui/views/critical_notification_bubble_view.h" 78 #include "chrome/browser/ui/views/critical_notification_bubble_view.h"
80 #endif 79 #endif
81 80
82 #if !defined(OS_CHROMEOS) 81 #if !defined(OS_CHROMEOS)
83 #include "chrome/browser/signin/signin_global_error_factory.h" 82 #include "chrome/browser/signin/signin_global_error_factory.h"
84 #include "chrome/browser/sync/sync_global_error_factory.h" 83 #include "chrome/browser/sync/sync_global_error_factory.h"
85 #endif 84 #endif
86 85
87 #if defined(USE_ASH) 86 #if defined(USE_ASH)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 128
130 ToolbarView::ToolbarView(Browser* browser) 129 ToolbarView::ToolbarView(Browser* browser)
131 : back_(NULL), 130 : back_(NULL),
132 forward_(NULL), 131 forward_(NULL),
133 reload_(NULL), 132 reload_(NULL),
134 home_(NULL), 133 home_(NULL),
135 location_bar_(NULL), 134 location_bar_(NULL),
136 browser_actions_(NULL), 135 browser_actions_(NULL),
137 app_menu_(NULL), 136 app_menu_(NULL),
138 browser_(browser), 137 browser_(browser),
138 badge_controller_(browser->profile(), this),
139 extension_message_bubble_factory_( 139 extension_message_bubble_factory_(
140 new extensions::ExtensionMessageBubbleFactory(browser->profile(), 140 new extensions::ExtensionMessageBubbleFactory(browser->profile(),
141 this)) { 141 this)) {
142 set_id(VIEW_ID_TOOLBAR); 142 set_id(VIEW_ID_TOOLBAR);
143 143
144 SetEventTargeter( 144 SetEventTargeter(
145 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this))); 145 scoped_ptr<views::ViewTargeter>(new views::ViewTargeter(this)));
146 146
147 chrome::AddCommandObserver(browser_, IDC_BACK, this); 147 chrome::AddCommandObserver(browser_, IDC_BACK, this);
148 chrome::AddCommandObserver(browser_, IDC_FORWARD, this); 148 chrome::AddCommandObserver(browser_, IDC_FORWARD, this);
(...skipping 10 matching lines...) Expand all
159 content::NotificationService::AllSources()); 159 content::NotificationService::AllSources());
160 if (OutdatedUpgradeBubbleView::IsAvailable()) { 160 if (OutdatedUpgradeBubbleView::IsAvailable()) {
161 registrar_.Add(this, chrome::NOTIFICATION_OUTDATED_INSTALL, 161 registrar_.Add(this, chrome::NOTIFICATION_OUTDATED_INSTALL,
162 content::NotificationService::AllSources()); 162 content::NotificationService::AllSources());
163 registrar_.Add(this, chrome::NOTIFICATION_OUTDATED_INSTALL_NO_AU, 163 registrar_.Add(this, chrome::NOTIFICATION_OUTDATED_INSTALL_NO_AU,
164 content::NotificationService::AllSources()); 164 content::NotificationService::AllSources());
165 } 165 }
166 #if defined(OS_WIN) 166 #if defined(OS_WIN)
167 registrar_.Add(this, chrome::NOTIFICATION_CRITICAL_UPGRADE_INSTALLED, 167 registrar_.Add(this, chrome::NOTIFICATION_CRITICAL_UPGRADE_INSTALLED,
168 content::NotificationService::AllSources()); 168 content::NotificationService::AllSources());
169 if (base::win::GetVersion() == base::win::VERSION_XP) {
170 registrar_.Add(this, chrome::NOTIFICATION_MODULE_LIST_ENUMERATED,
171 content::NotificationService::AllSources());
172 }
173 #endif 169 #endif
174 registrar_.Add(this,
175 chrome::NOTIFICATION_MODULE_INCOMPATIBILITY_BADGE_CHANGE,
176 content::NotificationService::AllSources());
177 registrar_.Add(this, chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED,
178 content::Source<Profile>(browser_->profile()));
179 } 170 }
180 171
181 ToolbarView::~ToolbarView() { 172 ToolbarView::~ToolbarView() {
182 // NOTE: Don't remove the command observers here. This object gets destroyed 173 // NOTE: Don't remove the command observers here. This object gets destroyed
183 // after the Browser (which owns the CommandUpdater), so the CommandUpdater is 174 // after the Browser (which owns the CommandUpdater), so the CommandUpdater is
184 // already gone. 175 // already gone.
185 } 176 }
186 177
187 void ToolbarView::Init() { 178 void ToolbarView::Init() {
188 GetWidget()->AddObserver(this); 179 GetWidget()->AddObserver(this);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 SigninGlobalErrorFactory::GetForProfile(browser_->profile()); 248 SigninGlobalErrorFactory::GetForProfile(browser_->profile());
258 #if !defined(OS_ANDROID) 249 #if !defined(OS_ANDROID)
259 SyncGlobalErrorFactory::GetForProfile(browser_->profile()); 250 SyncGlobalErrorFactory::GetForProfile(browser_->profile());
260 #endif 251 #endif
261 } 252 }
262 #endif // OS_CHROMEOS 253 #endif // OS_CHROMEOS
263 254
264 // Add any necessary badges to the menu item based on the system state. 255 // Add any necessary badges to the menu item based on the system state.
265 // Do this after |app_menu_| has been added as a bubble may be shown that 256 // Do this after |app_menu_| has been added as a bubble may be shown that
266 // needs the widget (widget found by way of app_menu_->GetWidget()). 257 // needs the widget (widget found by way of app_menu_->GetWidget()).
267 UpdateAppMenuState(); 258 badge_controller_.UpdateDelegate();
268 259
269 location_bar_->Init(); 260 location_bar_->Init();
270 261
271 show_home_button_.Init(prefs::kShowHomeButton, 262 show_home_button_.Init(prefs::kShowHomeButton,
272 browser_->profile()->GetPrefs(), 263 browser_->profile()->GetPrefs(),
273 base::Bind(&ToolbarView::OnShowHomeButtonChanged, 264 base::Bind(&ToolbarView::OnShowHomeButtonChanged,
274 base::Unretained(this))); 265 base::Unretained(this)));
275 266
276 browser_actions_->Init(); 267 browser_actions_->Init();
277 268
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 browser_, sender->tag(), ui::DispositionFromEventFlags(event.flags())); 474 browser_, sender->tag(), ui::DispositionFromEventFlags(event.flags()));
484 } 475 }
485 476
486 //////////////////////////////////////////////////////////////////////////////// 477 ////////////////////////////////////////////////////////////////////////////////
487 // ToolbarView, content::NotificationObserver implementation: 478 // ToolbarView, content::NotificationObserver implementation:
488 479
489 void ToolbarView::Observe(int type, 480 void ToolbarView::Observe(int type,
490 const content::NotificationSource& source, 481 const content::NotificationSource& source,
491 const content::NotificationDetails& details) { 482 const content::NotificationDetails& details) {
492 switch (type) { 483 switch (type) {
493 case chrome::NOTIFICATION_UPGRADE_RECOMMENDED:
494 case chrome::NOTIFICATION_MODULE_INCOMPATIBILITY_BADGE_CHANGE:
495 case chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED:
496 case chrome::NOTIFICATION_MODULE_LIST_ENUMERATED:
497 UpdateAppMenuState();
498 break;
499 case chrome::NOTIFICATION_OUTDATED_INSTALL: 484 case chrome::NOTIFICATION_OUTDATED_INSTALL:
500 ShowOutdatedInstallNotification(true); 485 ShowOutdatedInstallNotification(true);
501 break; 486 break;
502 case chrome::NOTIFICATION_OUTDATED_INSTALL_NO_AU: 487 case chrome::NOTIFICATION_OUTDATED_INSTALL_NO_AU:
503 ShowOutdatedInstallNotification(false); 488 ShowOutdatedInstallNotification(false);
504 break; 489 break;
505 #if defined(OS_WIN) 490 #if defined(OS_WIN)
506 case chrome::NOTIFICATION_CRITICAL_UPGRADE_INSTALLED: 491 case chrome::NOTIFICATION_CRITICAL_UPGRADE_INSTALLED:
507 ShowCriticalNotification(); 492 ShowCriticalNotification();
508 break; 493 break;
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 692
708 // Fall through to the tab strip above us if none of |rect| intersects 693 // Fall through to the tab strip above us if none of |rect| intersects
709 // with this view (intersection with the top shadow edge does not 694 // with this view (intersection with the top shadow edge does not
710 // count as intersection with this view). 695 // count as intersection with this view).
711 if (rect.bottom() < content_shadow_height()) 696 if (rect.bottom() < content_shadow_height())
712 return false; 697 return false;
713 // Otherwise let our superclass take care of it. 698 // Otherwise let our superclass take care of it.
714 return ViewTargeterDelegate::DoesIntersectRect(this, rect); 699 return ViewTargeterDelegate::DoesIntersectRect(this, rect);
715 } 700 }
716 701
717 bool ToolbarView::ShouldShowUpgradeRecommended() { 702 void ToolbarView::UpdateBadgeSeverity(WrenchMenuBadgeController::BadgeType type,
718 #if defined(OS_CHROMEOS) 703 WrenchIconPainter::Severity severity,
719 // In chromeos, the update recommendation is shown in the system tray. So it 704 bool animate) {
720 // should not be displayed in the wrench menu. 705 // Showing the bubble requires |app_menu_| to be in a widget. See comment
721 return false; 706 // in ConflictingModuleView for details.
722 #else 707 DCHECK(app_menu_->GetWidget());
723 return (UpgradeDetector::GetInstance()->notify_upgrade()); 708
709 base::string16 accname_app = l10n_util::GetStringUTF16(IDS_ACCNAME_APP);
710 if (type == WrenchMenuBadgeController::UPGRADE_NOTIFICATION) {
711 accname_app = l10n_util::GetStringFUTF16(
712 IDS_ACCNAME_APP_UPGRADE_RECOMMENDED, accname_app);
713 }
714 app_menu_->SetAccessibleName(accname_app);
715 app_menu_->SetSeverity(severity, animate);
716 SchedulePaint();
sky 2014/07/17 19:54:28 I realize you're copying code here, but it seems l
Alexei Svitkine (slow) 2014/07/17 21:35:28 Done.
717
718 // Keep track of whether we were showing the badge before, so we don't send
719 // multiple UMA events for example when multiple Chrome windows are open.
720 static bool incompatibility_badge_showing = false;
721 // Save the old value before resetting it.
722 bool was_showing = incompatibility_badge_showing;
723 incompatibility_badge_showing = false;
724
725 if (type == WrenchMenuBadgeController::INCOMPATIBILITY_WARNING) {
726 if (!was_showing) {
727 content::RecordAction(UserMetricsAction("ConflictBadge"));
728 #if defined(OS_WIN)
729 ConflictingModuleView::MaybeShow(browser_, app_menu_);
724 #endif 730 #endif
725 } 731 }
726 732 incompatibility_badge_showing = true;
727 bool ToolbarView::ShouldShowIncompatibilityWarning() { 733 return;
728 #if defined(OS_WIN) 734 }
729 EnumerateModulesModel* loaded_modules = EnumerateModulesModel::GetInstance();
730 loaded_modules->MaybePostScanningTask();
731 return loaded_modules->ShouldShowConflictWarning();
732 #else
733 return false;
734 #endif
735 } 735 }
736 736
737 int ToolbarView::PopupTopSpacing() const { 737 int ToolbarView::PopupTopSpacing() const {
738 const int kPopupTopSpacingNonGlass = 3; 738 const int kPopupTopSpacingNonGlass = 3;
739 return GetWidget()->ShouldWindowContentsBeTransparent() ? 739 return GetWidget()->ShouldWindowContentsBeTransparent() ?
740 0 : kPopupTopSpacingNonGlass; 740 0 : kPopupTopSpacingNonGlass;
741 } 741 }
742 742
743 gfx::Size ToolbarView::SizeForContentSize(gfx::Size size) const { 743 gfx::Size ToolbarView::SizeForContentSize(gfx::Size size) const {
744 if (is_display_mode_normal()) { 744 if (is_display_mode_normal()) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 #endif 784 #endif
785 } 785 }
786 786
787 void ToolbarView::ShowOutdatedInstallNotification(bool auto_update_enabled) { 787 void ToolbarView::ShowOutdatedInstallNotification(bool auto_update_enabled) {
788 if (OutdatedUpgradeBubbleView::IsAvailable()) { 788 if (OutdatedUpgradeBubbleView::IsAvailable()) {
789 OutdatedUpgradeBubbleView::ShowBubble( 789 OutdatedUpgradeBubbleView::ShowBubble(
790 app_menu_, browser_, auto_update_enabled); 790 app_menu_, browser_, auto_update_enabled);
791 } 791 }
792 } 792 }
793 793
794 void ToolbarView::UpdateAppMenuState() {
795 base::string16 accname_app = l10n_util::GetStringUTF16(IDS_ACCNAME_APP);
796 if (ShouldShowUpgradeRecommended()) {
797 accname_app = l10n_util::GetStringFUTF16(
798 IDS_ACCNAME_APP_UPGRADE_RECOMMENDED, accname_app);
799 }
800 app_menu_->SetAccessibleName(accname_app);
801
802 UpdateWrenchButtonSeverity();
803 SchedulePaint();
804 }
805
806 void ToolbarView::UpdateWrenchButtonSeverity() {
807 // Showing the bubble requires |app_menu_| to be in a widget. See comment
808 // in ConflictingModuleView for details.
809 DCHECK(app_menu_->GetWidget());
810
811 // Keep track of whether we were showing the badge before, so we don't send
812 // multiple UMA events for example when multiple Chrome windows are open.
813 static bool incompatibility_badge_showing = false;
814 // Save the old value before resetting it.
815 bool was_showing = incompatibility_badge_showing;
816 incompatibility_badge_showing = false;
817
818 if (ShouldShowUpgradeRecommended()) {
819 UpgradeDetector::UpgradeNotificationAnnoyanceLevel level =
820 UpgradeDetector::GetInstance()->upgrade_notification_stage();
821 app_menu_->SetSeverity(WrenchIconPainter::SeverityFromUpgradeLevel(level),
822 WrenchIconPainter::ShouldAnimateUpgradeLevel(level));
823 return;
824 }
825
826 if (ShouldShowIncompatibilityWarning()) {
827 if (!was_showing) {
828 content::RecordAction(UserMetricsAction("ConflictBadge"));
829 #if defined(OS_WIN)
830 ConflictingModuleView::MaybeShow(browser_, app_menu_);
831 #endif
832 }
833 app_menu_->SetSeverity(WrenchIconPainter::SEVERITY_MEDIUM, true);
834 incompatibility_badge_showing = true;
835 return;
836 }
837
838 GlobalErrorService* service =
839 GlobalErrorServiceFactory::GetForProfile(browser_->profile());
840 GlobalError* error =
841 service->GetHighestSeverityGlobalErrorWithWrenchMenuItem();
842 if (error) {
843 app_menu_->SetSeverity(WrenchIconPainter::GlobalErrorSeverity(), true);
844 return;
845 }
846
847 app_menu_->SetSeverity(WrenchIconPainter::SEVERITY_NONE, true);
848 }
849
850 void ToolbarView::OnShowHomeButtonChanged() { 794 void ToolbarView::OnShowHomeButtonChanged() {
851 Layout(); 795 Layout();
852 SchedulePaint(); 796 SchedulePaint();
853 } 797 }
854 798
855 int ToolbarView::content_shadow_height() const { 799 int ToolbarView::content_shadow_height() const {
856 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ? 800 return browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH ?
857 kContentShadowHeightAsh : kContentShadowHeight; 801 kContentShadowHeightAsh : kContentShadowHeight;
858 } 802 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698