Chromium Code Reviews| OLD | NEW |
|---|---|
| 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> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/i18n/number_formatting.h" | 10 #include "base/i18n/number_formatting.h" |
| 11 #include "base/metrics/user_metrics.h" | 11 #include "base/metrics/user_metrics.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "chrome/app/chrome_command_ids.h" | 15 #include "chrome/app/chrome_command_ids.h" |
| 16 #include "chrome/app/vector_icons/vector_icons.h" | 16 #include "chrome/app/vector_icons/vector_icons.h" |
| 17 #include "chrome/browser/chrome_notification_types.h" | |
| 18 #include "chrome/browser/command_updater.h" | 17 #include "chrome/browser/command_updater.h" |
| 19 #include "chrome/browser/extensions/extension_util.h" | 18 #include "chrome/browser/extensions/extension_util.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/themes/theme_properties.h" | 20 #include "chrome/browser/themes/theme_properties.h" |
| 22 #include "chrome/browser/ui/bookmarks/bookmark_bubble_sign_in_delegate.h" | 21 #include "chrome/browser/ui/bookmarks/bookmark_bubble_sign_in_delegate.h" |
| 23 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 24 #include "chrome/browser/ui/browser_command_controller.h" | 23 #include "chrome/browser/ui/browser_command_controller.h" |
| 25 #include "chrome/browser/ui/browser_commands.h" | 24 #include "chrome/browser/ui/browser_commands.h" |
| 26 #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h" | 25 #include "chrome/browser/ui/browser_content_setting_bubble_model_delegate.h" |
| 27 #include "chrome/browser/ui/browser_tabstrip.h" | 26 #include "chrome/browser/ui/browser_tabstrip.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 38 #include "chrome/browser/ui/views/frame/browser_view.h" | 37 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 39 #include "chrome/browser/ui/views/location_bar/star_view.h" | 38 #include "chrome/browser/ui/views/location_bar/star_view.h" |
| 40 #include "chrome/browser/ui/views/outdated_upgrade_bubble_view.h" | 39 #include "chrome/browser/ui/views/outdated_upgrade_bubble_view.h" |
| 41 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" | 40 #include "chrome/browser/ui/views/toolbar/app_menu_button.h" |
| 42 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" | 41 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" |
| 43 #include "chrome/browser/ui/views/toolbar/home_button.h" | 42 #include "chrome/browser/ui/views/toolbar/home_button.h" |
| 44 #include "chrome/browser/ui/views/toolbar/reload_button.h" | 43 #include "chrome/browser/ui/views/toolbar/reload_button.h" |
| 45 #include "chrome/browser/ui/views/toolbar/toolbar_button.h" | 44 #include "chrome/browser/ui/views/toolbar/toolbar_button.h" |
| 46 #include "chrome/browser/ui/views/translate/translate_bubble_view.h" | 45 #include "chrome/browser/ui/views/translate/translate_bubble_view.h" |
| 47 #include "chrome/browser/ui/views/translate/translate_icon_view.h" | 46 #include "chrome/browser/ui/views/translate/translate_icon_view.h" |
| 47 #include "chrome/browser/upgrade_detector.h" | |
| 48 #include "chrome/common/chrome_switches.h" | 48 #include "chrome/common/chrome_switches.h" |
| 49 #include "chrome/common/pref_names.h" | 49 #include "chrome/common/pref_names.h" |
| 50 #include "chrome/grit/chromium_strings.h" | 50 #include "chrome/grit/chromium_strings.h" |
| 51 #include "chrome/grit/generated_resources.h" | 51 #include "chrome/grit/generated_resources.h" |
| 52 #include "components/omnibox/browser/omnibox_view.h" | 52 #include "components/omnibox/browser/omnibox_view.h" |
| 53 #include "components/prefs/pref_service.h" | 53 #include "components/prefs/pref_service.h" |
| 54 #include "components/strings/grit/components_strings.h" | 54 #include "components/strings/grit/components_strings.h" |
| 55 #include "content/public/browser/browser_accessibility_state.h" | 55 #include "content/public/browser/browser_accessibility_state.h" |
| 56 #include "content/public/browser/notification_service.h" | |
| 57 #include "content/public/browser/render_view_host.h" | 56 #include "content/public/browser/render_view_host.h" |
| 58 #include "content/public/browser/web_contents.h" | 57 #include "content/public/browser/web_contents.h" |
| 59 #include "ui/accessibility/ax_node_data.h" | 58 #include "ui/accessibility/ax_node_data.h" |
| 60 #include "ui/base/l10n/l10n_util.h" | 59 #include "ui/base/l10n/l10n_util.h" |
| 61 #include "ui/base/material_design/material_design_controller.h" | 60 #include "ui/base/material_design/material_design_controller.h" |
| 62 #include "ui/base/theme_provider.h" | 61 #include "ui/base/theme_provider.h" |
| 63 #include "ui/base/window_open_disposition.h" | 62 #include "ui/base/window_open_disposition.h" |
| 64 #include "ui/compositor/layer.h" | 63 #include "ui/compositor/layer.h" |
| 65 #include "ui/gfx/canvas.h" | 64 #include "ui/gfx/canvas.h" |
| 66 #include "ui/gfx/image/canvas_image_source.h" | 65 #include "ui/gfx/image/canvas_image_source.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 ? DISPLAYMODE_NORMAL | 127 ? DISPLAYMODE_NORMAL |
| 129 : DISPLAYMODE_LOCATION) { | 128 : DISPLAYMODE_LOCATION) { |
| 130 set_id(VIEW_ID_TOOLBAR); | 129 set_id(VIEW_ID_TOOLBAR); |
| 131 | 130 |
| 132 chrome::AddCommandObserver(browser_, IDC_BACK, this); | 131 chrome::AddCommandObserver(browser_, IDC_BACK, this); |
| 133 chrome::AddCommandObserver(browser_, IDC_FORWARD, this); | 132 chrome::AddCommandObserver(browser_, IDC_FORWARD, this); |
| 134 chrome::AddCommandObserver(browser_, IDC_RELOAD, this); | 133 chrome::AddCommandObserver(browser_, IDC_RELOAD, this); |
| 135 chrome::AddCommandObserver(browser_, IDC_HOME, this); | 134 chrome::AddCommandObserver(browser_, IDC_HOME, this); |
| 136 chrome::AddCommandObserver(browser_, IDC_LOAD_NEW_TAB_PAGE, this); | 135 chrome::AddCommandObserver(browser_, IDC_LOAD_NEW_TAB_PAGE, this); |
| 137 | 136 |
| 138 if (OutdatedUpgradeBubbleView::IsAvailable()) { | 137 UpgradeDetector::GetInstance()->AddObserver(this); |
| 139 registrar_.Add(this, chrome::NOTIFICATION_OUTDATED_INSTALL, | |
| 140 content::NotificationService::AllSources()); | |
| 141 registrar_.Add(this, chrome::NOTIFICATION_OUTDATED_INSTALL_NO_AU, | |
| 142 content::NotificationService::AllSources()); | |
| 143 } | |
| 144 #if defined(OS_WIN) | |
| 145 registrar_.Add(this, chrome::NOTIFICATION_CRITICAL_UPGRADE_INSTALLED, | |
| 146 content::NotificationService::AllSources()); | |
| 147 #endif | |
| 148 } | 138 } |
| 149 | 139 |
| 150 ToolbarView::~ToolbarView() { | 140 ToolbarView::~ToolbarView() { |
| 141 UpgradeDetector::GetInstance()->RemoveObserver(this); | |
| 142 | |
| 151 // NOTE: Don't remove the command observers here. This object gets destroyed | 143 // NOTE: Don't remove the command observers here. This object gets destroyed |
| 152 // after the Browser (which owns the CommandUpdater), so the CommandUpdater is | 144 // after the Browser (which owns the CommandUpdater), so the CommandUpdater is |
| 153 // already gone. | 145 // already gone. |
| 154 } | 146 } |
| 155 | 147 |
| 156 void ToolbarView::Init() { | 148 void ToolbarView::Init() { |
| 157 location_bar_ = | 149 location_bar_ = |
| 158 new LocationBarView(browser_, browser_->profile(), | 150 new LocationBarView(browser_, browser_->profile(), |
| 159 browser_->command_controller()->command_updater(), | 151 browser_->command_controller()->command_updater(), |
| 160 this, !is_display_mode_normal()); | 152 this, !is_display_mode_normal()); |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 444 //////////////////////////////////////////////////////////////////////////////// | 436 //////////////////////////////////////////////////////////////////////////////// |
| 445 // ToolbarView, views::Button::ButtonListener implementation: | 437 // ToolbarView, views::Button::ButtonListener implementation: |
| 446 | 438 |
| 447 void ToolbarView::ButtonPressed(views::Button* sender, | 439 void ToolbarView::ButtonPressed(views::Button* sender, |
| 448 const ui::Event& event) { | 440 const ui::Event& event) { |
| 449 chrome::ExecuteCommandWithDisposition( | 441 chrome::ExecuteCommandWithDisposition( |
| 450 browser_, sender->tag(), ui::DispositionFromEventFlags(event.flags())); | 442 browser_, sender->tag(), ui::DispositionFromEventFlags(event.flags())); |
| 451 } | 443 } |
| 452 | 444 |
| 453 //////////////////////////////////////////////////////////////////////////////// | 445 //////////////////////////////////////////////////////////////////////////////// |
| 454 // ToolbarView, content::NotificationObserver implementation: | 446 // ToolbarView, UpgradeObserver implementation: |
| 455 | 447 void ToolbarView::OnOutdatedInstall() { |
| 456 void ToolbarView::Observe(int type, | 448 if (OutdatedUpgradeBubbleView::IsAvailable()) { |
|
sky
2017/06/07 23:01:41
no {}
weidongg
2017/06/08 02:28:42
Done.
| |
| 457 const content::NotificationSource& source, | 449 ShowOutdatedInstallNotification(true); |
| 458 const content::NotificationDetails& details) { | |
| 459 switch (type) { | |
| 460 case chrome::NOTIFICATION_OUTDATED_INSTALL: | |
| 461 ShowOutdatedInstallNotification(true); | |
| 462 break; | |
| 463 case chrome::NOTIFICATION_OUTDATED_INSTALL_NO_AU: | |
| 464 ShowOutdatedInstallNotification(false); | |
| 465 break; | |
| 466 #if defined(OS_WIN) | |
| 467 case chrome::NOTIFICATION_CRITICAL_UPGRADE_INSTALLED: | |
| 468 ShowCriticalNotification(); | |
| 469 break; | |
| 470 #endif | |
| 471 default: | |
| 472 NOTREACHED(); | |
| 473 } | 450 } |
| 474 } | 451 } |
| 475 | 452 |
| 453 void ToolbarView::OnOutdatedInstallNoAU() { | |
| 454 if (OutdatedUpgradeBubbleView::IsAvailable()) { | |
|
sky
2017/06/07 23:01:41
no {}
weidongg
2017/06/08 02:28:42
Done.
| |
| 455 ShowOutdatedInstallNotification(false); | |
| 456 } | |
| 457 } | |
| 458 | |
| 459 #if defined(OS_WIN) | |
| 460 void ToolbarView::OnCriticalUpgradeInstalled() { | |
| 461 ShowCriticalNotification(); | |
| 462 } | |
| 463 #endif | |
| 464 | |
| 476 //////////////////////////////////////////////////////////////////////////////// | 465 //////////////////////////////////////////////////////////////////////////////// |
| 477 // ToolbarView, ui::AcceleratorProvider implementation: | 466 // ToolbarView, ui::AcceleratorProvider implementation: |
| 478 | 467 |
| 479 bool ToolbarView::GetAcceleratorForCommandId(int command_id, | 468 bool ToolbarView::GetAcceleratorForCommandId(int command_id, |
| 480 ui::Accelerator* accelerator) const { | 469 ui::Accelerator* accelerator) const { |
| 481 return GetWidget()->GetAccelerator(command_id, accelerator); | 470 return GetWidget()->GetAccelerator(command_id, accelerator); |
| 482 } | 471 } |
| 483 | 472 |
| 484 //////////////////////////////////////////////////////////////////////////////// | 473 //////////////////////////////////////////////////////////////////////////////// |
| 485 // ToolbarView, views::View overrides: | 474 // ToolbarView, views::View overrides: |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 757 if (OutdatedUpgradeBubbleView::IsAvailable()) { | 746 if (OutdatedUpgradeBubbleView::IsAvailable()) { |
| 758 OutdatedUpgradeBubbleView::ShowBubble(app_menu_button_, browser_, | 747 OutdatedUpgradeBubbleView::ShowBubble(app_menu_button_, browser_, |
| 759 auto_update_enabled); | 748 auto_update_enabled); |
| 760 } | 749 } |
| 761 } | 750 } |
| 762 | 751 |
| 763 void ToolbarView::OnShowHomeButtonChanged() { | 752 void ToolbarView::OnShowHomeButtonChanged() { |
| 764 Layout(); | 753 Layout(); |
| 765 SchedulePaint(); | 754 SchedulePaint(); |
| 766 } | 755 } |
| OLD | NEW |