diff options
author | rafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-17 18:20:31 +0000 |
---|---|---|
committer | rafaelw@chromium.org <rafaelw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-17 18:20:31 +0000 |
commit | 01f829ab3cc802b79942f5a988f6a72e7a2b594d (patch) | |
tree | 8d5566ebfa133239e7947cac02b685df95d5b66f /chrome/browser/views/browser_actions_container.cc | |
parent | 5715c63e814adcf7d0515ea08c16955d49615a33 (diff) | |
download | chromium_src-01f829ab3cc802b79942f5a988f6a72e7a2b594d.zip chromium_src-01f829ab3cc802b79942f5a988f6a72e7a2b594d.tar.gz chromium_src-01f829ab3cc802b79942f5a988f6a72e7a2b594d.tar.bz2 |
Initial support for inspecting extension popups.
The primary change in this CL is a refactor which makes ExtensionPopup a bit more self-contained WRT its clients. It adds the ability to specify an "inspect_with_devtools" flag to its Show() method which will cause the popup to remain open regardless of losing focus and to focus a devtools window on the popup's render view host.
This CL also pulls apart some aspects of the extension_popup_api from ExtensionFunctionDispatcher and ExtensionHost.
Still remaining to be done are:
1) Also the popup to stay open when the host window drags (it current closes)
2) Support for GTK
3) Support for Mac
BUG=24477
Review URL: http://codereview.chromium.org/1001002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41854 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/browser_actions_container.cc')
-rw-r--r-- | chrome/browser/views/browser_actions_container.cc | 116 |
1 files changed, 31 insertions, 85 deletions
diff --git a/chrome/browser/views/browser_actions_container.cc b/chrome/browser/views/browser_actions_container.cc index a8fa362..32f0f02 100644 --- a/chrome/browser/views/browser_actions_container.cc +++ b/chrome/browser/views/browser_actions_container.cc @@ -13,6 +13,7 @@ #include "chrome/browser/browser_theme_provider.h" #include "chrome/browser/browser_window.h" #include "chrome/browser/extensions/extension_browser_event_router.h" +#include "chrome/browser/extensions/extension_host.h" #include "chrome/browser/extensions/extensions_service.h" #include "chrome/browser/extensions/extension_tabs_module.h" #include "chrome/browser/renderer_host/render_widget_host_view.h" @@ -133,9 +134,9 @@ gfx::Insets BrowserActionButton::GetInsets() const { return zero_inset; } -void BrowserActionButton::ButtonPressed( - views::Button* sender, const views::Event& event) { - panel_->OnBrowserActionExecuted(this); +void BrowserActionButton::ButtonPressed(views::Button* sender, + const views::Event& event) { + panel_->OnBrowserActionExecuted(this, false); // inspect_with_devtools } void BrowserActionButton::OnImageLoaded(SkBitmap* image, size_t index) { @@ -198,7 +199,7 @@ GURL BrowserActionButton::GetPopupUrl() { bool BrowserActionButton::Activate() { if (IsPopup()) { - panel_->OnBrowserActionExecuted(this); + panel_->OnBrowserActionExecuted(this, false); // inspect_with_devtools // TODO(erikkay): Run a nested modal loop while the mouse is down to // enable menu-like drag-select behavior. @@ -224,7 +225,8 @@ bool BrowserActionButton::OnMousePressed(const views::MouseEvent& e) { // Make the menu appear below the button. point.Offset(0, height()); - panel_->GetContextMenu()->Run(extension(), point); + panel_->GetContextMenu()->Run(extension(), extension()->browser_action(), + panel_, panel_->profile()->GetPrefs(), point); SetButtonNotPushed(); return false; @@ -340,9 +342,6 @@ BrowserActionsContainer::BrowserActionsContainer( if (!extension_service) // The |extension_service| can be NULL in Incognito. return; - registrar_.Add(this, NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE, - Source<Profile>(profile_)); - model_ = extension_service->toolbar_model(); model_->AddObserver(this); @@ -484,29 +483,13 @@ void BrowserActionsContainer::OnBrowserActionVisibilityChanged() { } void BrowserActionsContainer::HidePopup() { - if (popup_) { - // This sometimes gets called via a timer (See BubbleLostFocus), so clear - // the task factory in case one is pending. - task_factory_.RevokeAll(); - - // Save these variables in local temporaries since destroying the popup - // calls BubbleLostFocus to be called, which will try to call HidePopup() - // again if popup_ is non-null. - ExtensionPopup* closing_popup = popup_; - BrowserActionButton* closing_button = popup_button_; - popup_ = NULL; - popup_button_ = NULL; - - closing_popup->DetachFromBrowser(); - delete closing_popup; - closing_button->SetButtonNotPushed(); - return; - } + if (popup_) + popup_->Close(); } void BrowserActionsContainer::TestExecuteBrowserAction(int index) { BrowserActionButton* button = browser_action_views_[index]->button(); - OnBrowserActionExecuted(button); + OnBrowserActionExecuted(button, false); // inspect_with_devtools } void BrowserActionsContainer::TestSetIconVisibilityCount(size_t icons) { @@ -517,7 +500,7 @@ void BrowserActionsContainer::TestSetIconVisibilityCount(size_t icons) { } void BrowserActionsContainer::OnBrowserActionExecuted( - BrowserActionButton* button) { + BrowserActionButton* button, bool inspect_with_devtools) { ExtensionAction* browser_action = button->browser_action(); // Popups just display. No notification to the extension. @@ -548,18 +531,15 @@ void BrowserActionsContainer::OnBrowserActionExecuted( BubbleBorder::ArrowLocation arrow_location = UILayoutIsRightToLeft() ? BubbleBorder::TOP_LEFT : BubbleBorder::TOP_RIGHT; - popup_ = ExtensionPopup::Show( - button->GetPopupUrl(), - browser_, - browser_->profile(), - frame_window, - rect, - arrow_location, + popup_ = ExtensionPopup::Show(button->GetPopupUrl(), browser_, + browser_->profile(), frame_window, rect, arrow_location, true, // Activate the popup window. - ExtensionPopup::BUBBLE_CHROME); - popup_->set_delegate(this); + inspect_with_devtools, + ExtensionPopup::BUBBLE_CHROME, + this); // ExtensionPopupDelegate popup_button_ = button; popup_button_->SetButtonPushed(); + return; } @@ -809,54 +789,6 @@ void BrowserActionsContainer::MoveBrowserAction( SchedulePaint(); } -void BrowserActionsContainer::Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - switch (type.value) { - case NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE: - // If we aren't the host of the popup, then disregard the notification. - if (!popup_ || Details<ExtensionHost>(popup_->host()) != details) - return; - - HidePopup(); - break; - - default: - NOTREACHED() << "Unexpected notification"; - } -} - -void BrowserActionsContainer::BubbleBrowserWindowMoved(BrowserBubble* bubble) { -} - -void BrowserActionsContainer::BubbleBrowserWindowClosing( - BrowserBubble* bubble) { - HidePopup(); -} - -void BrowserActionsContainer::BubbleGotFocus(BrowserBubble* bubble) { - if (!popup_) - return; - - // Forward the focus to the renderer. - popup_->host()->render_view_host()->view()->Focus(); -} - -void BrowserActionsContainer::BubbleLostFocus(BrowserBubble* bubble, - bool lost_focus_to_child) { - // Don't close when we are losing focus to a child window, this is the case - // for select popups and alert for example. - if (!popup_ || lost_focus_to_child) - return; - - // This is a bit annoying. If you click on the button that generated the - // current popup, then we first get this lost focus message, and then - // we get the click action. This results in the popup being immediately - // shown again. To workaround this, we put in a delay. - MessageLoop::current()->PostTask(FROM_HERE, - task_factory_.NewRunnableMethod(&BrowserActionsContainer::HidePopup)); -} - void BrowserActionsContainer::RunMenu(View* source, const gfx::Point& pt) { if (source == chevron_) { overflow_menu_ = new BrowserActionOverflowMenuController( @@ -1142,6 +1074,20 @@ void BrowserActionsContainer::NotifyMenuDeleted( overflow_menu_ = NULL; } +void BrowserActionsContainer::ShowPopupForDevToolsWindow(Extension* extension, + ExtensionAction* extension_action) { + OnBrowserActionExecuted(GetBrowserActionView(extension)->button(), + true); // inspect_with_devtools +} + +void BrowserActionsContainer::ExtensionPopupClosed(ExtensionPopup* popup) { + // ExtensionPopup is ref-counted, so we don't need to delete it. + DCHECK_EQ(popup_, popup); + popup_ = NULL; + popup_button_->SetButtonNotPushed(); + popup_button_ = NULL; +} + bool BrowserActionsContainer::ShouldDisplayBrowserAction(Extension* extension) { // Only display incognito-enabled extensions while in incognito mode. return (!profile_->IsOffTheRecord() || |