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

Unified Diff: chrome/browser/ui/extensions/extension_action_view_controller.cc

Issue 1168383002: Implement sidebar support for extension action popups Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix assertion failure at extension_view_host.cc Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/extensions/extension_action_view_controller.cc
diff --git a/chrome/browser/ui/extensions/extension_action_view_controller.cc b/chrome/browser/ui/extensions/extension_action_view_controller.cc
index 77fe17118465f93a23daa36a3052f7a2b2e7cc87..984ed1eccf0e0895e05aea5865be079c24fefbd0 100644
--- a/chrome/browser/ui/extensions/extension_action_view_controller.cc
+++ b/chrome/browser/ui/extensions/extension_action_view_controller.cc
@@ -17,11 +17,12 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/extensions/accelerator_priority.h"
#include "chrome/browser/ui/extensions/extension_action_platform_delegate.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h"
#include "chrome/browser/ui/toolbar/toolbar_actions_bar.h"
-#include "chrome/browser/ui/toolbar/toolbar_actions_bar.h"
#include "chrome/common/extensions/api/extension_action/action_info.h"
#include "chrome/common/icon_with_badge_image_source.h"
+#include "chrome/common/pref_names.h"
#include "extensions/browser/extension_host.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension.h"
@@ -72,7 +73,7 @@ void ExtensionActionViewController::SetDelegate(
view_delegate_ = delegate;
platform_delegate_->OnDelegateSet();
} else {
- if (is_showing_popup())
+ if (popup_host_)
HidePopup();
platform_delegate_.reset();
view_delegate_ = nullptr;
@@ -138,15 +139,16 @@ bool ExtensionActionViewController::HasPopup(
}
void ExtensionActionViewController::HidePopup() {
- if (is_showing_popup()) {
- popup_host_->Close();
- // We need to do these actions synchronously (instead of closing and then
- // performing the rest of the cleanup in OnExtensionHostDestroyed()) because
- // the extension host may close asynchronously, and we need to keep the view
- // delegate up-to-date.
- if (popup_host_)
- OnPopupClosed();
- }
+ if (!is_showing_popup())
+ return;
+
+ popup_host_->Close();
+ // We need to do these actions synchronously (instead of closing and then
+ // performing the rest of the cleanup in OnExtensionHostDestroyed()) because
+ // the extension host may close asynchronously, and we need to keep the view
+ // delegate up-to-date.
+ if (popup_host_)
+ OnPopupClosed();
}
gfx::NativeView ExtensionActionViewController::GetPopupNativeView() {
@@ -202,8 +204,13 @@ bool ExtensionActionViewController::ExecuteAction(PopupShowAction show_action,
ExtensionAction::ACTION_SHOW_POPUP) {
GURL popup_url = extension_action_->GetPopupUrl(
SessionTabHelper::IdForTab(view_delegate_->GetCurrentWebContents()));
- return GetPreferredPopupViewController()
- ->TriggerPopupWithUrl(show_action, popup_url, grant_tab_permissions);
+
+ if (extension_action_->open_in_sidebar())
+ return GetPreferredPopupViewController()->TriggerSidebarWithUrl(
+ popup_url);
+ else
+ return GetPreferredPopupViewController()->TriggerPopupWithUrl(
+ show_action, popup_url, grant_tab_permissions);
}
return false;
}
@@ -288,20 +295,18 @@ bool ExtensionActionViewController::TriggerPopupWithUrl(
PopupShowAction show_action,
const GURL& popup_url,
bool grant_tab_permissions) {
- if (!ExtensionIsValid())
- return false;
-
- bool already_showing = is_showing_popup();
-
- // Always hide the current popup, even if it's not owned by this extension.
- // Only one popup should be visible at a time.
- HideActivePopup();
// If we were showing a popup already, then we treat the action to open the
// same one as a desire to close it (like clicking a menu button that was
// already open).
- if (already_showing)
+ if (is_showing_popup()) {
+ HideActivePopup();
return false;
+ }
+
+ // Always hide the current popup, even if it's not owned by this extension.
+ // Only one popup should be visible at a time.
+ HideActivePopup();
scoped_ptr<extensions::ExtensionViewHost> host(
extensions::ExtensionViewHostFactory::CreatePopupHost(popup_url,
@@ -314,21 +319,40 @@ bool ExtensionActionViewController::TriggerPopupWithUrl(
if (toolbar_actions_bar_)
toolbar_actions_bar_->SetPopupOwner(this);
- if (toolbar_actions_bar_ &&
- !toolbar_actions_bar_->IsActionVisibleOnMainBar(this) &&
- extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()) {
- platform_delegate_->CloseOverflowMenu();
- toolbar_actions_bar_->PopOutAction(
- this,
- base::Bind(&ExtensionActionViewController::ShowPopup,
- weak_factory_.GetWeakPtr(),
- base::Passed(host.Pass()),
- grant_tab_permissions,
- show_action));
- } else {
- ShowPopup(host.Pass(), grant_tab_permissions, show_action);
+ PressButtonWithSlideOutIfEnabled(base::Bind(
+ &ExtensionActionViewController::ShowPopup, weak_factory_.GetWeakPtr(),
+ base::Passed(host.Pass()), grant_tab_permissions, show_action));
+
+ return true;
+}
+
+bool ExtensionActionViewController::TriggerSidebarWithUrl(
+ const GURL& sidebar_url) {
+ // Sidebar is only allowed via browser action
+ if (ActionInfo::TYPE_BROWSER != extension_action_->action_type())
+ return false;
+
+ DCHECK(toolbar_actions_bar_);
+
+ if (sidebar_host_) {
+ HideActiveSidebar();
+ return false;
}
+ HideActiveSidebar();
+
+ sidebar_host_.reset(extensions::ExtensionViewHostFactory::CreateSidebarHost(
+ sidebar_url, browser_));
+
+ sidebar_host_->CreateRenderViewSoon();
+ sidebar_host_->host_contents()->SetInitialFocus();
+
+ DCHECK(toolbar_actions_bar_);
+ toolbar_actions_bar_->SetSidebarOwner(this);
+
+ PressButtonWithSlideOutIfEnabled(
+ base::Bind(&ExtensionActionViewController::PressButton,
+ weak_factory_.GetWeakPtr(), true));
return true;
}
@@ -342,21 +366,71 @@ void ExtensionActionViewController::ShowPopup(
return;
platform_delegate_->ShowPopup(
popup_host.Pass(), grant_tab_permissions, show_action);
- view_delegate_->OnPopupShown(grant_tab_permissions);
+ PressButton(grant_tab_permissions);
}
void ExtensionActionViewController::OnPopupClosed() {
- popup_host_observer_.Remove(popup_host_);
- popup_host_ = nullptr;
- if (toolbar_actions_bar_) {
+ if (popup_host_) {
+ popup_host_observer_.Remove(popup_host_);
+ popup_host_ = nullptr;
+ }
+ if (toolbar_actions_bar_)
toolbar_actions_bar_->SetPopupOwner(nullptr);
+
+ RaiseButton();
+}
+
+void ExtensionActionViewController::HideActiveSidebar() {
+ DCHECK(toolbar_actions_bar_);
+ DCHECK_EQ(ActionInfo::TYPE_BROWSER, extension_action_->action_type());
+ toolbar_actions_bar_->HideActiveSidebar();
+}
+
+void ExtensionActionViewController::HideSidebar() {
+ if (!sidebar_host_)
+ return;
+
+ sidebar_host_.reset();
+ if (toolbar_actions_bar_)
+ toolbar_actions_bar_->SetSidebarOwner(nullptr);
+
+ RaiseButton();
+}
+
+void ExtensionActionViewController::RaiseButton() {
+ // Reset button state
+ if (toolbar_actions_bar_) {
if (toolbar_actions_bar_->popped_out_action() == this &&
- !view_delegate_->IsMenuRunning())
+ !view_delegate_->IsMenuRunning()) {
toolbar_actions_bar_->UndoPopOut();
+ }
}
view_delegate_->OnPopupClosed();
}
+void ExtensionActionViewController::PressButtonWithSlideOutIfEnabled(
+ const base::Closure& closure) {
+ if (!toolbar_actions_bar_ ||
+ toolbar_actions_bar_->IsActionVisibleOnMainBar(this) ||
+ !extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()) {
+ closure.Run();
+ return;
+ }
+
+ // We disabled PopOutAction for sidebar
+ if (extension_action_->open_in_sidebar()) {
+ closure.Run();
+ return;
+ }
+
+ platform_delegate_->CloseOverflowMenu();
+ toolbar_actions_bar_->PopOutAction(this, closure);
+}
+
+void ExtensionActionViewController::PressButton(bool grant_tab_permissions) {
+ view_delegate_->OnPopupShown(grant_tab_permissions);
+}
+
scoped_ptr<IconWithBadgeImageSource>
ExtensionActionViewController::GetIconImageSource(
content::WebContents* web_contents,

Powered by Google App Engine
This is Rietveld 408576698