summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorestade <estade@chromium.org>2016-02-04 12:38:17 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-04 20:40:22 +0000
commit78a3685d7b92e6ebf4a91b3cbea78b702f567fa3 (patch)
tree7c62f6e1e6450a88e58cd8df9a88c3d6a64c1445
parentee805c1eeab8ed56cdac0020ba41948279bdbd05 (diff)
downloadchromium_src-78a3685d7b92e6ebf4a91b3cbea78b702f567fa3.zip
chromium_src-78a3685d7b92e6ebf4a91b3cbea78b702f567fa3.tar.gz
chromium_src-78a3685d7b92e6ebf4a91b3cbea78b702f567fa3.tar.bz2
Revert of Views - init less stuff in tabless browsers. (patchset #3 id:40001 of https://codereview.chromium.org/1654223002/ )
Reason for revert: this is causing a lot of crashes on canary, revert for now and reland later with a fix Original issue's description: > Views - init less stuff in tabless browsers. > > There's no need to create views that are hidden, register listeners relevant to > those views, etc. in popup windows. > > The one part of BrowserActionsContainer that we do want in popup windows is the ExtensionKeybindingRegistryViews instance. Move this to BrowserView. > > BUG=560345 > > Committed: https://crrev.com/845adff50786ff3c7515d51d04370825ad9e3a8b > Cr-Commit-Position: refs/heads/master@{#373344} TBR=pkasting@chromium.org,rdevlin.cronin@chromium.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true BUG=560345 Review URL: https://codereview.chromium.org/1670663002 Cr-Commit-Position: refs/heads/master@{#373609}
-rw-r--r--chrome/browser/ui/views/frame/browser_view.cc38
-rw-r--r--chrome/browser/ui/views/frame/browser_view.h15
-rw-r--r--chrome/browser/ui/views/toolbar/browser_actions_container.cc28
-rw-r--r--chrome/browser/ui/views/toolbar/browser_actions_container.h32
-rw-r--r--chrome/browser/ui/views/toolbar/toolbar_view.cc64
-rw-r--r--chrome/browser/ui/views/toolbar/toolbar_view.h14
6 files changed, 108 insertions, 83 deletions
diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc
index 2b316d6..a9d0508 100644
--- a/chrome/browser/ui/views/frame/browser_view.cc
+++ b/chrome/browser/ui/views/frame/browser_view.cc
@@ -68,7 +68,6 @@
#include "chrome/browser/ui/views/download/download_shelf_view.h"
#include "chrome/browser/ui/views/exclusive_access_bubble_views.h"
#include "chrome/browser/ui/views/extensions/bookmark_app_bubble_view.h"
-#include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views.h"
#include "chrome/browser/ui/views/frame/browser_view_layout.h"
#include "chrome/browser/ui/views/frame/browser_view_layout_delegate.h"
#include "chrome/browser/ui/views/frame/contents_layout_manager.h"
@@ -99,7 +98,6 @@
#include "chrome/browser/ui/website_settings/permission_bubble_manager.h"
#include "chrome/browser/ui/window_sizer/window_sizer.h"
#include "chrome/common/chrome_switches.h"
-#include "chrome/common/extensions/command.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/chromium_strings.h"
@@ -1108,11 +1106,8 @@ void BrowserView::SetFocusToLocationBar(bool select_all) {
}
void BrowserView::UpdateReloadStopState(bool is_loading, bool force) {
- if (toolbar_->reload_button()) {
- toolbar_->reload_button()->ChangeMode(
- is_loading ? ReloadButton::MODE_STOP : ReloadButton::MODE_RELOAD,
- force);
- }
+ toolbar_->reload_button()->ChangeMode(
+ is_loading ? ReloadButton::MODE_STOP : ReloadButton::MODE_RELOAD, force);
}
void BrowserView::UpdateToolbar(content::WebContents* contents) {
@@ -1852,23 +1847,6 @@ void BrowserView::OnWidgetActivationChanged(views::Widget* widget,
bool active) {
if (active)
BrowserList::SetLastActive(browser_.get());
-
- if (!extension_keybinding_registry_ &&
- GetFocusManager()) { // focus manager can be null in tests.
- extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews(
- browser_->profile(), GetFocusManager(),
- extensions::ExtensionKeybindingRegistry::ALL_EXTENSIONS, this));
- }
-
- extensions::ExtensionCommandsGlobalRegistry* registry =
- extensions::ExtensionCommandsGlobalRegistry::Get(browser_->profile());
- if (active) {
- registry->set_registry_for_active_window(
- extension_keybinding_registry_.get());
- } else if (registry->registry_for_active_window() ==
- extension_keybinding_registry_.get()) {
- registry->set_registry_for_active_window(nullptr);
- }
}
void BrowserView::OnWindowBeginUserBoundsChange() {
@@ -2632,8 +2610,7 @@ int BrowserView::GetRenderViewHeightInsetWithDetachedBookmarkBar() {
void BrowserView::ExecuteExtensionCommand(
const extensions::Extension* extension,
const extensions::Command& command) {
- extension_keybinding_registry_->ExecuteCommand(extension->id(),
- command.accelerator());
+ toolbar_->ExecuteExtensionCommand(extension, command);
}
ExclusiveAccessContext* BrowserView::GetExclusiveAccessContext() {
@@ -2746,12 +2723,3 @@ bool BrowserView::IsImmersiveModeEnabled() {
gfx::Rect BrowserView::GetTopContainerBoundsInScreen() {
return top_container_->GetBoundsInScreen();
}
-
-extensions::ActiveTabPermissionGranter*
-BrowserView::GetActiveTabPermissionGranter() {
- content::WebContents* web_contents = GetActiveWebContents();
- if (!web_contents)
- return nullptr;
- return extensions::TabHelper::FromWebContents(web_contents)
- ->active_tab_permission_granter();
-}
diff --git a/chrome/browser/ui/views/frame/browser_view.h b/chrome/browser/ui/views/frame/browser_view.h
index d2fce2f..5d4341a 100644
--- a/chrome/browser/ui/views/frame/browser_view.h
+++ b/chrome/browser/ui/views/frame/browser_view.h
@@ -16,15 +16,12 @@
#include "base/timer/timer.h"
#include "build/build_config.h"
#include "chrome/browser/devtools/devtools_window.h"
-#include "chrome/browser/extensions/extension_commands_global_registry.h"
-#include "chrome/browser/extensions/extension_keybinding_registry.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/exclusive_access/exclusive_access_context.h"
#include "chrome/browser/ui/infobar_container_delegate.h"
#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
#include "chrome/browser/ui/views/exclusive_access_bubble_views_context.h"
-#include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views.h"
#include "chrome/browser/ui/views/frame/browser_frame.h"
#include "chrome/browser/ui/views/frame/contents_web_view.h"
#include "chrome/browser/ui/views/frame/immersive_mode_controller.h"
@@ -68,8 +65,6 @@ class JumpList;
#endif
namespace extensions {
-class ActiveTabPermissionGranter;
-class Command;
class Extension;
}
@@ -95,8 +90,7 @@ class BrowserView : public BrowserWindow,
public LoadCompleteListener::Delegate,
public OmniboxPopupModelObserver,
public ExclusiveAccessContext,
- public ExclusiveAccessBubbleViewsContext,
- public extensions::ExtensionKeybindingRegistry::Delegate {
+ public ExclusiveAccessBubbleViewsContext {
public:
// The browser view's class name.
static const char kViewClassName[];
@@ -472,10 +466,6 @@ class BrowserView : public BrowserWindow,
bool IsImmersiveModeEnabled() override;
gfx::Rect GetTopContainerBoundsInScreen() override;
- // extension::ExtensionKeybindingRegistry::Delegate overrides
- extensions::ActiveTabPermissionGranter* GetActiveTabPermissionGranter()
- override;
-
// Testing interface:
views::View* GetContentsContainerForTest() { return contents_container_; }
views::WebView* GetContentsWebViewForTest() { return contents_web_view_; }
@@ -731,9 +721,6 @@ class BrowserView : public BrowserWindow,
SigninViewController signin_view_controller_;
- // The class that registers for keyboard shortcuts for extension commands.
- scoped_ptr<ExtensionKeybindingRegistryViews> extension_keybinding_registry_;
-
mutable base::WeakPtrFactory<BrowserView> activate_modal_dialog_factory_;
DISALLOW_COPY_AND_ASSIGN(BrowserView);
diff --git a/chrome/browser/ui/views/toolbar/browser_actions_container.cc b/chrome/browser/ui/views/toolbar/browser_actions_container.cc
index b37b111..71e57f5 100644
--- a/chrome/browser/ui/views/toolbar/browser_actions_container.cc
+++ b/chrome/browser/ui/views/toolbar/browser_actions_container.cc
@@ -177,6 +177,16 @@ size_t BrowserActionsContainer::VisibleBrowserActionsAfterAnimation() const {
return toolbar_actions_bar_->WidthToIconCount(animation_target_size_);
}
+void BrowserActionsContainer::ExecuteExtensionCommand(
+ const extensions::Extension* extension,
+ const extensions::Command& command) {
+ // Global commands are handled by the ExtensionCommandsGlobalRegistry
+ // instance.
+ DCHECK(!command.global());
+ extension_keybinding_registry_->ExecuteCommand(extension->id(),
+ command.accelerator());
+}
+
bool BrowserActionsContainer::ShownInsideMenu() const {
return in_overflow_mode();
}
@@ -675,6 +685,15 @@ content::WebContents* BrowserActionsContainer::GetCurrentWebContents() {
return browser_->tab_strip_model()->GetActiveWebContents();
}
+extensions::ActiveTabPermissionGranter*
+ BrowserActionsContainer::GetActiveTabPermissionGranter() {
+ content::WebContents* web_contents = GetCurrentWebContents();
+ if (!web_contents)
+ return NULL;
+ return extensions::TabHelper::FromWebContents(web_contents)->
+ active_tab_permission_granter();
+}
+
void BrowserActionsContainer::OnPaint(gfx::Canvas* canvas) {
// If the views haven't been initialized yet, wait for the next call to
// paint (one will be triggered by entering highlight mode).
@@ -733,6 +752,15 @@ void BrowserActionsContainer::ViewHierarchyChanged(
return;
if (details.is_add && details.child == this) {
+ if (!in_overflow_mode() && // We only need one keybinding registry.
+ parent()->GetFocusManager()) { // focus manager can be null in tests.
+ extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews(
+ browser_->profile(),
+ parent()->GetFocusManager(),
+ extensions::ExtensionKeybindingRegistry::ALL_EXTENSIONS,
+ this));
+ }
+
// Initial toolbar button creation and placement in the widget hierarchy.
// We do this here instead of in the constructor because adding views
// calls Layout on the Toolbar, which needs this object to be constructed
diff --git a/chrome/browser/ui/views/toolbar/browser_actions_container.h b/chrome/browser/ui/views/toolbar/browser_actions_container.h
index 14517aa..b433a3f 100644
--- a/chrome/browser/ui/views/toolbar/browser_actions_container.h
+++ b/chrome/browser/ui/views/toolbar/browser_actions_container.h
@@ -9,8 +9,10 @@
#include "base/macros.h"
#include "base/observer_list.h"
+#include "chrome/browser/extensions/extension_keybinding_registry.h"
#include "chrome/browser/ui/toolbar/toolbar_actions_bar.h"
#include "chrome/browser/ui/toolbar/toolbar_actions_bar_delegate.h"
+#include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views.h"
#include "chrome/browser/ui/views/toolbar/chevron_menu_button.h"
#include "chrome/browser/ui/views/toolbar/toolbar_action_view.h"
#include "ui/gfx/animation/animation_delegate.h"
@@ -122,12 +124,14 @@ class ResizeArea;
// growing the container.
//
////////////////////////////////////////////////////////////////////////////////
-class BrowserActionsContainer : public views::View,
- public ToolbarActionsBarDelegate,
- public views::ResizeAreaDelegate,
- public gfx::AnimationDelegate,
- public ToolbarActionView::Delegate,
- public views::WidgetObserver {
+class BrowserActionsContainer
+ : public views::View,
+ public ToolbarActionsBarDelegate,
+ public views::ResizeAreaDelegate,
+ public gfx::AnimationDelegate,
+ public ToolbarActionView::Delegate,
+ public views::WidgetObserver,
+ public extensions::ExtensionKeybindingRegistry::Delegate {
public:
// Constructs a BrowserActionContainer for a particular |browser| object. For
// documentation of |main_container|, see class comments.
@@ -151,6 +155,11 @@ class BrowserActionsContainer : public views::View,
return toolbar_actions_bar_.get();
}
+ // The class that registers for keyboard shortcuts for extension commands.
+ extensions::ExtensionKeybindingRegistry* extension_keybinding_registry() {
+ return extension_keybinding_registry_.get();
+ }
+
// Get a particular toolbar action view.
ToolbarActionView* GetToolbarActionViewAt(int index) {
return toolbar_action_views_[index];
@@ -180,6 +189,10 @@ class BrowserActionsContainer : public views::View,
// animating to a new size, or (if not animating) the currently visible icons.
size_t VisibleBrowserActionsAfterAnimation() const;
+ // Executes |command| registered by |extension|.
+ void ExecuteExtensionCommand(const extensions::Extension* extension,
+ const extensions::Command& command);
+
// Returns the preferred width given the limit of |max_width|. (Unlike most
// views, since we don't want to show part of an icon or a large space after
// the omnibox, this is probably *not* |max_width|).
@@ -247,6 +260,10 @@ class BrowserActionsContainer : public views::View,
void OnWidgetClosing(views::Widget* widget) override;
void OnWidgetDestroying(views::Widget* widget) override;
+ // Overridden from extension::ExtensionKeybindingRegistry::Delegate:
+ extensions::ActiveTabPermissionGranter* GetActiveTabPermissionGranter()
+ override;
+
views::BubbleDelegateView* active_bubble() { return active_bubble_; }
ChevronMenuButton* chevron_for_testing() { return chevron_; }
@@ -331,6 +348,9 @@ class BrowserActionsContainer : public views::View,
// is none.
scoped_ptr<DropPosition> drop_position_;
+ // The class that registers for keyboard shortcuts for extension commands.
+ scoped_ptr<ExtensionKeybindingRegistryViews> extension_keybinding_registry_;
+
// The extension bubble that is actively showing, if any.
views::BubbleDelegateView* active_bubble_;
diff --git a/chrome/browser/ui/views/toolbar/toolbar_view.cc b/chrome/browser/ui/views/toolbar/toolbar_view.cc
index d057283c..a94a409 100644
--- a/chrome/browser/ui/views/toolbar/toolbar_view.cc
+++ b/chrome/browser/ui/views/toolbar/toolbar_view.cc
@@ -14,6 +14,7 @@
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/command_updater.h"
+#include "chrome/browser/extensions/extension_commands_global_registry.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/themes/theme_properties.h"
@@ -121,18 +122,15 @@ const char ToolbarView::kViewClassName[] = "ToolbarView";
// ToolbarView, public:
ToolbarView::ToolbarView(Browser* browser)
- : back_(nullptr),
- forward_(nullptr),
- reload_(nullptr),
- home_(nullptr),
- location_bar_(nullptr),
- browser_actions_(nullptr),
- app_menu_button_(nullptr),
+ : back_(NULL),
+ forward_(NULL),
+ reload_(NULL),
+ home_(NULL),
+ location_bar_(NULL),
+ browser_actions_(NULL),
+ app_menu_button_(NULL),
browser_(browser),
- badge_controller_(browser->profile(), this),
- display_mode_(browser->SupportsWindowFeature(Browser::FEATURE_TABSTRIP)
- ? DISPLAYMODE_NORMAL
- : DISPLAYMODE_LOCATION) {
+ badge_controller_(browser->profile(), this) {
set_id(VIEW_ID_TOOLBAR);
SetEventTargeter(
@@ -144,6 +142,10 @@ ToolbarView::ToolbarView(Browser* browser)
chrome::AddCommandObserver(browser_, IDC_HOME, this);
chrome::AddCommandObserver(browser_, IDC_LOAD_NEW_TAB_PAGE, this);
+ display_mode_ = DISPLAYMODE_LOCATION;
+ if (browser->SupportsWindowFeature(Browser::FEATURE_TABSTRIP))
+ display_mode_ = DISPLAYMODE_NORMAL;
+
if (OutdatedUpgradeBubbleView::IsAvailable()) {
registrar_.Add(this, chrome::NOTIFICATION_OUTDATED_INSTALL,
content::NotificationService::AllSources());
@@ -163,16 +165,7 @@ ToolbarView::~ToolbarView() {
}
void ToolbarView::Init() {
- location_bar_ =
- new LocationBarView(browser_, browser_->profile(),
- browser_->command_controller()->command_updater(),
- this, !is_display_mode_normal());
-
- if (!is_display_mode_normal()) {
- AddChildView(location_bar_);
- location_bar_->Init();
- return;
- }
+ GetWidget()->AddObserver(this);
back_ = new BackButton(
browser_->profile(), this,
@@ -196,6 +189,11 @@ void ToolbarView::Init() {
forward_->set_id(VIEW_ID_FORWARD_BUTTON);
forward_->Init();
+ location_bar_ = new LocationBarView(
+ browser_, browser_->profile(),
+ browser_->command_controller()->command_updater(), this,
+ display_mode_ == DISPLAYMODE_LOCATION);
+
reload_ = new ReloadButton(browser_->profile(),
browser_->command_controller()->command_updater());
reload_->set_triggerable_event_flags(
@@ -276,6 +274,19 @@ void ToolbarView::Init() {
}
}
+void ToolbarView::OnWidgetActivationChanged(views::Widget* widget,
+ bool active) {
+ extensions::ExtensionCommandsGlobalRegistry* registry =
+ extensions::ExtensionCommandsGlobalRegistry::Get(browser_->profile());
+ if (active) {
+ registry->set_registry_for_active_window(
+ browser_actions_->extension_keybinding_registry());
+ } else if (registry->registry_for_active_window() ==
+ browser_actions_->extension_keybinding_registry()) {
+ registry->set_registry_for_active_window(nullptr);
+ }
+}
+
void ToolbarView::Update(WebContents* tab) {
if (location_bar_)
location_bar_->Update(tab);
@@ -329,6 +340,12 @@ void ToolbarView::OnBubbleCreatedForAnchor(views::View* anchor_view,
}
}
+void ToolbarView::ExecuteExtensionCommand(
+ const extensions::Extension* extension,
+ const extensions::Command& command) {
+ browser_actions_->ExecuteExtensionCommand(extension, command);
+}
+
int ToolbarView::GetMaxBrowserActionsWidth() const {
// The browser actions container is allowed to grow, but only up until the
// omnibox reaches its minimum size. So its maximum allowed width is its
@@ -483,7 +500,7 @@ gfx::Size ToolbarView::GetMinimumSize() const {
void ToolbarView::Layout() {
// If we have not been initialized yet just do nothing.
- if (!location_bar_)
+ if (back_ == NULL)
return;
if (!is_display_mode_normal()) {
@@ -592,8 +609,7 @@ void ToolbarView::Layout() {
}
void ToolbarView::OnThemeChanged() {
- if (is_display_mode_normal())
- LoadImages();
+ LoadImages();
}
const char* ToolbarView::GetClassName() const {
diff --git a/chrome/browser/ui/views/toolbar/toolbar_view.h b/chrome/browser/ui/views/toolbar/toolbar_view.h
index d41a446..2c54a9d 100644
--- a/chrome/browser/ui/views/toolbar/toolbar_view.h
+++ b/chrome/browser/ui/views/toolbar/toolbar_view.h
@@ -40,6 +40,7 @@ class ToolbarView : public views::AccessiblePaneView,
public content::NotificationObserver,
public CommandObserver,
public views::ButtonListener,
+ public views::WidgetObserver,
public views::ViewTargeterDelegate,
public AppMenuBadgeController::Delegate {
public:
@@ -85,6 +86,10 @@ class ToolbarView : public views::AccessiblePaneView,
void OnBubbleCreatedForAnchor(views::View* anchor_view,
views::Widget* bubble_widget);
+ // Executes |command| registered by |extension|.
+ void ExecuteExtensionCommand(const extensions::Extension* extension,
+ const extensions::Command& command);
+
// Returns the maximum width the browser actions container can have.
int GetMaxBrowserActionsWidth() const;
@@ -130,6 +135,9 @@ class ToolbarView : public views::AccessiblePaneView,
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
+ // views::WidgetObserver:
+ void OnWidgetActivationChanged(views::Widget* widget, bool active) override;
+
// content::NotificationObserver:
void Observe(int type,
const content::NotificationSource& source,
@@ -199,8 +207,7 @@ class ToolbarView : public views::AccessiblePaneView,
int content_shadow_height() const;
- // Controls. Most of these can be null, e.g. in popup windows. Only
- // |location_bar_| is guaranteed to exist.
+ // Controls
BackButton* back_;
ToolbarButton* forward_;
ReloadButton* reload_;
@@ -208,7 +215,6 @@ class ToolbarView : public views::AccessiblePaneView,
LocationBarView* location_bar_;
BrowserActionsContainer* browser_actions_;
AppMenuButton* app_menu_button_;
-
Browser* browser_;
AppMenuBadgeController badge_controller_;
@@ -217,7 +223,7 @@ class ToolbarView : public views::AccessiblePaneView,
BooleanPrefMember show_home_button_;
// The display mode used when laying out the toolbar.
- const DisplayMode display_mode_;
+ DisplayMode display_mode_;
content::NotificationRegistrar registrar_;