| Index: chrome/browser/ui/views/location_bar/page_action_image_view.cc
|
| diff --git a/chrome/browser/ui/views/location_bar/page_action_image_view.cc b/chrome/browser/ui/views/location_bar/page_action_image_view.cc
|
| index a47b7310fe6a991acdb31d59827b96eb53135119..e690f066c594d4a33362309e8960c35abfc5b7d0 100644
|
| --- a/chrome/browser/ui/views/location_bar/page_action_image_view.cc
|
| +++ b/chrome/browser/ui/views/location_bar/page_action_image_view.cc
|
| @@ -5,33 +5,16 @@
|
| #include "chrome/browser/ui/views/location_bar/page_action_image_view.h"
|
|
|
| #include "base/strings/utf_string_conversions.h"
|
| -#include "chrome/browser/extensions/api/commands/command_service.h"
|
| #include "chrome/browser/extensions/extension_action.h"
|
| -#include "chrome/browser/extensions/extension_action_icon_factory.h"
|
| -#include "chrome/browser/extensions/extension_action_manager.h"
|
| -#include "chrome/browser/extensions/extension_context_menu_model.h"
|
| -#include "chrome/browser/extensions/extension_tab_util.h"
|
| -#include "chrome/browser/extensions/location_bar_controller.h"
|
| -#include "chrome/browser/extensions/tab_helper.h"
|
| #include "chrome/browser/platform_util.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| -#include "chrome/browser/sessions/session_id.h"
|
| -#include "chrome/browser/ui/browser_list.h"
|
| -#include "chrome/browser/ui/extensions/accelerator_priority.h"
|
| -#include "chrome/browser/ui/views/frame/browser_view.h"
|
| +#include "chrome/browser/ui/browser.h"
|
| #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
|
| -#include "chrome/browser/ui/webui/extensions/extension_info_ui.h"
|
| #include "extensions/browser/extension_registry.h"
|
| -#include "extensions/common/extension.h"
|
| #include "ui/accessibility/ax_view_state.h"
|
| #include "ui/events/event.h"
|
| #include "ui/gfx/canvas.h"
|
| #include "ui/gfx/image/image.h"
|
| -#include "ui/views/controls/menu/menu_runner.h"
|
| -
|
| -using content::WebContents;
|
| -using extensions::LocationBarController;
|
| -using extensions::Extension;
|
|
|
| // static
|
| const char PageActionImageView::kViewClassName[] = "PageActionImageView";
|
| @@ -39,81 +22,23 @@ const char PageActionImageView::kViewClassName[] = "PageActionImageView";
|
| PageActionImageView::PageActionImageView(LocationBarView* owner,
|
| ExtensionAction* page_action,
|
| Browser* browser)
|
| - : owner_(owner),
|
| - page_action_(page_action),
|
| - browser_(browser),
|
| - current_tab_id_(-1),
|
| - preview_enabled_(false),
|
| - popup_(NULL) {
|
| - const Extension* extension = extensions::ExtensionRegistry::Get(
|
| - owner_->profile())->enabled_extensions().GetByID(
|
| - page_action->extension_id());
|
| - DCHECK(extension);
|
| -
|
| - icon_factory_.reset(
|
| - new ExtensionActionIconFactory(
|
| - owner_->profile(), extension, page_action, this));
|
| -
|
| + : view_controller_(new ExtensionActionViewController(
|
| + extensions::ExtensionRegistry::Get(browser->profile())->
|
| + enabled_extensions().GetByID(page_action->extension_id()),
|
| + browser,
|
| + page_action,
|
| + this)),
|
| + owner_(owner),
|
| + preview_enabled_(false) {
|
| + // There should be an associated focus manager so that we can safely register
|
| + // accelerators for commands.
|
| + DCHECK(GetFocusManagerForAccelerator());
|
| SetAccessibilityFocusable(true);
|
| - set_context_menu_controller(this);
|
| -
|
| - extensions::CommandService* command_service =
|
| - extensions::CommandService::Get(browser_->profile());
|
| - extensions::Command page_action_command;
|
| - if (command_service->GetPageActionCommand(
|
| - extension->id(),
|
| - extensions::CommandService::ACTIVE_ONLY,
|
| - &page_action_command,
|
| - NULL)) {
|
| - page_action_keybinding_.reset(
|
| - new ui::Accelerator(page_action_command.accelerator()));
|
| - owner_->GetFocusManager()->RegisterAccelerator(
|
| - *page_action_keybinding_.get(),
|
| - GetAcceleratorPriority(page_action_command.accelerator(), extension),
|
| - this);
|
| - }
|
| + view_controller_->RegisterCommand();
|
| + set_context_menu_controller(view_controller_.get());
|
| }
|
|
|
| PageActionImageView::~PageActionImageView() {
|
| - if (owner_->GetFocusManager()) {
|
| - if (page_action_keybinding_.get()) {
|
| - owner_->GetFocusManager()->UnregisterAccelerator(
|
| - *page_action_keybinding_.get(), this);
|
| - }
|
| - }
|
| -
|
| - if (popup_)
|
| - popup_->GetWidget()->RemoveObserver(this);
|
| - HidePopup();
|
| -}
|
| -
|
| -void PageActionImageView::ExecuteAction(
|
| - ExtensionPopup::ShowAction show_action) {
|
| - WebContents* web_contents = owner_->GetWebContents();
|
| - if (!web_contents)
|
| - return;
|
| -
|
| - extensions::TabHelper* extensions_tab_helper =
|
| - extensions::TabHelper::FromWebContents(web_contents);
|
| - LocationBarController* controller =
|
| - extensions_tab_helper->location_bar_controller();
|
| -
|
| - switch (controller->OnClicked(page_action_)) {
|
| - case LocationBarController::ACTION_NONE:
|
| - break;
|
| -
|
| - case LocationBarController::ACTION_SHOW_POPUP:
|
| - ShowPopupWithURL(page_action_->GetPopupUrl(current_tab_id_), show_action);
|
| - break;
|
| -
|
| - case LocationBarController::ACTION_SHOW_CONTEXT_MENU:
|
| - // We are never passing OnClicked a right-click button, so assume that
|
| - // we're never going to be asked to show a context menu.
|
| - // TODO(kalman): if this changes, update this class to pass the real
|
| - // mouse button through to the LocationBarController.
|
| - NOTREACHED();
|
| - break;
|
| - }
|
| }
|
|
|
| const char* PageActionImageView::GetClassName() const {
|
| @@ -142,13 +67,13 @@ void PageActionImageView::OnMouseReleased(const ui::MouseEvent& event) {
|
| return;
|
| }
|
|
|
| - ExecuteAction(ExtensionPopup::SHOW);
|
| + view_controller_->ExecuteActionByUser();
|
| }
|
|
|
| bool PageActionImageView::OnKeyPressed(const ui::KeyEvent& event) {
|
| if (event.key_code() == ui::VKEY_SPACE ||
|
| event.key_code() == ui::VKEY_RETURN) {
|
| - ExecuteAction(ExtensionPopup::SHOW);
|
| + view_controller_->ExecuteActionByUser();
|
| return true;
|
| }
|
| return false;
|
| @@ -156,127 +81,72 @@ bool PageActionImageView::OnKeyPressed(const ui::KeyEvent& event) {
|
|
|
| void PageActionImageView::OnGestureEvent(ui::GestureEvent* event) {
|
| if (event->type() == ui::ET_GESTURE_TAP) {
|
| - ExecuteAction(ExtensionPopup::SHOW);
|
| + view_controller_->ExecuteActionByUser();
|
| event->SetHandled();
|
| }
|
| }
|
|
|
| -void PageActionImageView::ShowContextMenuForView(
|
| - View* source,
|
| - const gfx::Point& point,
|
| - ui::MenuSourceType source_type) {
|
| - const Extension* extension = extensions::ExtensionRegistry::Get(
|
| - owner_->profile())->enabled_extensions().GetByID(
|
| - page_action()->extension_id());
|
| - if (!extension->ShowConfigureContextMenus())
|
| - return;
|
| -
|
| - scoped_refptr<ExtensionContextMenuModel> context_menu_model(
|
| - new ExtensionContextMenuModel(extension, browser_, this));
|
| - menu_runner_.reset(new views::MenuRunner(
|
| - context_menu_model.get(),
|
| - views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU));
|
| - gfx::Point screen_loc;
|
| - views::View::ConvertPointToScreen(this, &screen_loc);
|
| - if (menu_runner_->RunMenuAt(GetWidget(),
|
| - NULL,
|
| - gfx::Rect(screen_loc, size()),
|
| - views::MENU_ANCHOR_TOPLEFT,
|
| - source_type) == views::MenuRunner::MENU_DELETED) {
|
| - return;
|
| - }
|
| -}
|
| -
|
| -bool PageActionImageView::AcceleratorPressed(
|
| - const ui::Accelerator& accelerator) {
|
| - DCHECK(visible()); // Should not have happened due to CanHandleAccelerator.
|
| -
|
| - const std::string extension_id = page_action()->extension_id();
|
| - const ui::AcceleratorManager::HandlerPriority priority =
|
| - GetAcceleratorPriorityById(accelerator, extension_id, owner_->profile());
|
| - // Normal priority shortcuts must be handled via standard browser commands
|
| - // to be processed at the proper time.
|
| - if (priority == ui::AcceleratorManager::kHighPriority)
|
| - ExecuteAction(ExtensionPopup::SHOW);
|
| - return priority == ui::AcceleratorManager::kHighPriority;
|
| -}
|
| -
|
| -bool PageActionImageView::CanHandleAccelerators() const {
|
| - // While visible, we don't handle accelerators and while so we also don't
|
| - // count as a priority accelerator handler.
|
| - return visible();
|
| -}
|
| -
|
| -void PageActionImageView::UpdateVisibility(WebContents* contents,
|
| - const GURL& url) {
|
| - // Save this off so we can pass it back to the extension when the action gets
|
| - // executed. See PageActionImageView::OnMousePressed.
|
| - current_tab_id_ =
|
| - contents ? extensions::ExtensionTabUtil::GetTabId(contents) : -1;
|
| - current_url_ = url;
|
| +void PageActionImageView::UpdateVisibility(content::WebContents* contents) {
|
| + int tab_id = view_controller_->GetCurrentTabId();
|
|
|
| if (!contents ||
|
| - (!preview_enabled_ && !page_action_->GetIsVisible(current_tab_id_))) {
|
| + tab_id == -1 ||
|
| + (!preview_enabled_ && !extension_action()->GetIsVisible(tab_id))) {
|
| SetVisible(false);
|
| return;
|
| }
|
|
|
| // Set the tooltip.
|
| - tooltip_ = page_action_->GetTitle(current_tab_id_);
|
| + tooltip_ = extension_action()->GetTitle(tab_id);
|
| SetTooltipText(base::UTF8ToUTF16(tooltip_));
|
|
|
| // Set the image.
|
| - gfx::Image icon = icon_factory_->GetIcon(current_tab_id_);
|
| + gfx::Image icon = view_controller_->GetIcon(tab_id);
|
| if (!icon.IsEmpty())
|
| SetImage(*icon.ToImageSkia());
|
|
|
| SetVisible(true);
|
| }
|
|
|
| -void PageActionImageView::InspectPopup() {
|
| - ExecuteAction(ExtensionPopup::SHOW_AND_INSPECT);
|
| -}
|
| -
|
| -void PageActionImageView::OnWidgetDestroying(views::Widget* widget) {
|
| - DCHECK_EQ(popup_->GetWidget(), widget);
|
| - popup_->GetWidget()->RemoveObserver(this);
|
| - popup_ = NULL;
|
| +void PageActionImageView::PaintChildren(gfx::Canvas* canvas,
|
| + const views::CullSet& cull_set) {
|
| + View::PaintChildren(canvas, cull_set);
|
| + int tab_id = view_controller_->GetCurrentTabId();
|
| + if (tab_id >= 0) {
|
| + view_controller_->extension_action()->PaintBadge(
|
| + canvas, GetLocalBounds(), tab_id);
|
| + }
|
| }
|
|
|
| void PageActionImageView::OnIconUpdated() {
|
| - WebContents* web_contents = owner_->GetWebContents();
|
| - if (web_contents)
|
| - UpdateVisibility(web_contents, current_url_);
|
| + UpdateVisibility(GetCurrentWebContents());
|
| }
|
|
|
| -void PageActionImageView::PaintChildren(gfx::Canvas* canvas,
|
| - const views::CullSet& cull_set) {
|
| - View::PaintChildren(canvas, cull_set);
|
| - if (current_tab_id_ >= 0)
|
| - page_action_->PaintBadge(canvas, GetLocalBounds(), current_tab_id_);
|
| +views::View* PageActionImageView::GetAsView() {
|
| + return this;
|
| }
|
|
|
| -void PageActionImageView::ShowPopupWithURL(
|
| - const GURL& popup_url,
|
| - ExtensionPopup::ShowAction show_action) {
|
| - bool popup_showing = popup_ != NULL;
|
| +bool PageActionImageView::IsShownInMenu() {
|
| + return false;
|
| +}
|
|
|
| - // Always hide the current popup. Only one popup at a time.
|
| - HidePopup();
|
| +views::FocusManager* PageActionImageView::GetFocusManagerForAccelerator() {
|
| + return owner_->GetFocusManager();
|
| +}
|
|
|
| - // If we were already showing, then treat this click as a dismiss.
|
| - if (popup_showing)
|
| - return;
|
| +views::Widget* PageActionImageView::GetParentForContextMenu() {
|
| + return GetWidget();
|
| +}
|
|
|
| - views::BubbleBorder::Arrow arrow = base::i18n::IsRTL() ?
|
| - views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT;
|
| +views::View* PageActionImageView::GetReferenceViewForPopup() {
|
| + return this;
|
| +}
|
|
|
| - popup_ = ExtensionPopup::ShowPopup(popup_url, browser_, this, arrow,
|
| - show_action);
|
| - popup_->GetWidget()->AddObserver(this);
|
| +content::WebContents* PageActionImageView::GetCurrentWebContents() {
|
| + return owner_->GetWebContents();
|
| }
|
|
|
| -void PageActionImageView::HidePopup() {
|
| - if (popup_)
|
| - popup_->GetWidget()->Close();
|
| +void PageActionImageView::HideActivePopup() {
|
| + // The only popup that will be active is this popup.
|
| + view_controller_->HidePopup();
|
| }
|
|
|