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

Side by Side Diff: chrome/browser/ui/views/browser_actions_container.cc

Issue 25305002: Implement initial chrome.browserAction.openPopup API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move to interactive_ui_test Created 7 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/browser_actions_container.h" 5 #include "chrome/browser/ui/views/browser_actions_container.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/extensions/extension_system.h" 11 #include "chrome/browser/extensions/extension_system.h"
12 #include "chrome/browser/extensions/extension_util.h" 12 #include "chrome/browser/extensions/extension_util.h"
13 #include "chrome/browser/extensions/tab_helper.h" 13 #include "chrome/browser/extensions/tab_helper.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/sessions/session_tab_helper.h" 15 #include "chrome/browser/sessions/session_tab_helper.h"
16 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_window.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model.h" 18 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "chrome/browser/ui/view_ids.h" 19 #include "chrome/browser/ui/view_ids.h"
19 #include "chrome/browser/ui/views/browser_action_view.h" 20 #include "chrome/browser/ui/views/browser_action_view.h"
20 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" 21 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h"
21 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h" 22 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h"
22 #include "chrome/browser/ui/views/extensions/extension_popup.h" 23 #include "chrome/browser/ui/views/extensions/extension_popup.h"
23 #include "chrome/browser/ui/views/toolbar_view.h" 24 #include "chrome/browser/ui/views/toolbar_view.h"
24 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
25 #include "grit/generated_resources.h" 26 #include "grit/generated_resources.h"
26 #include "grit/theme_resources.h" 27 #include "grit/theme_resources.h"
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 popup_ = NULL; 454 popup_ = NULL;
454 // |popup_button_| is NULL if the extension has been removed. 455 // |popup_button_| is NULL if the extension has been removed.
455 if (popup_button_) { 456 if (popup_button_) {
456 popup_button_->SetButtonNotPushed(); 457 popup_button_->SetButtonNotPushed();
457 popup_button_ = NULL; 458 popup_button_ = NULL;
458 } 459 }
459 } 460 }
460 461
461 void BrowserActionsContainer::InspectPopup(ExtensionAction* action) { 462 void BrowserActionsContainer::InspectPopup(ExtensionAction* action) {
462 BrowserActionView* view = GetBrowserActionView(action); 463 BrowserActionView* view = GetBrowserActionView(action);
463 ShowPopup(view->button(), ExtensionPopup::SHOW_AND_INSPECT); 464 ShowPopup(view->button(), ExtensionPopup::SHOW_AND_INSPECT, true);
464 } 465 }
465 466
466 int BrowserActionsContainer::GetCurrentTabId() const { 467 int BrowserActionsContainer::GetCurrentTabId() const {
467 content::WebContents* active_tab = 468 content::WebContents* active_tab =
468 browser_->tab_strip_model()->GetActiveWebContents(); 469 browser_->tab_strip_model()->GetActiveWebContents();
469 if (!active_tab) 470 if (!active_tab)
470 return -1; 471 return -1;
471 472
472 return SessionTabHelper::FromWebContents(active_tab)->session_id().id(); 473 return SessionTabHelper::FromWebContents(active_tab)->session_id().id();
473 } 474 }
474 475
475 void BrowserActionsContainer::OnBrowserActionExecuted( 476 void BrowserActionsContainer::OnBrowserActionExecuted(
476 BrowserActionButton* button) { 477 BrowserActionButton* button) {
477 ShowPopup(button, ExtensionPopup::SHOW); 478 ShowPopup(button, ExtensionPopup::SHOW, true);
478 } 479 }
479 480
480 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() { 481 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() {
481 SetVisible(!browser_action_views_.empty()); 482 SetVisible(!browser_action_views_.empty());
482 owner_view_->Layout(); 483 owner_view_->Layout();
483 owner_view_->SchedulePaint(); 484 owner_view_->SchedulePaint();
484 } 485 }
485 486
486 gfx::Point BrowserActionsContainer::GetViewContentOffset() const { 487 gfx::Point BrowserActionsContainer::GetViewContentOffset() const {
487 return gfx::Point(0, ToolbarView::kVertSpacing); 488 return gfx::Point(0, ToolbarView::kVertSpacing);
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 index = model_->OriginalIndexToIncognito(index); 681 index = model_->OriginalIndexToIncognito(index);
681 682
682 DCHECK(index >= 0 && index < static_cast<int>(browser_action_views_.size())); 683 DCHECK(index >= 0 && index < static_cast<int>(browser_action_views_.size()));
683 684
684 DeleteBrowserActionViews(); 685 DeleteBrowserActionViews();
685 CreateBrowserActionViews(); 686 CreateBrowserActionViews();
686 Layout(); 687 Layout();
687 SchedulePaint(); 688 SchedulePaint();
688 } 689 }
689 690
691 bool BrowserActionsContainer::BrowserActionShowPopup(
692 const extensions::Extension* extension) {
693 // Do not override other popups and only show in active window. The window
694 // must also have a toolbar, otherwise it should not be showing popups.
695 // TODO(justinlin): Remove toolbar check when http://crbug.com/308645 is
696 // fixed.
697 if (popup_ ||
698 !browser_->window()->IsActive() ||
699 !browser_->window()->IsToolbarVisible()) {
700 return false;
701 }
702
703 for (BrowserActionViews::iterator it = browser_action_views_.begin();
704 it != browser_action_views_.end(); ++it) {
705 BrowserActionButton* button = (*it)->button();
706 if (button && button->extension() == extension)
707 return ShowPopup(button, ExtensionPopup::SHOW, false);
708 }
709 return false;
710 }
711
690 void BrowserActionsContainer::ModelLoaded() { 712 void BrowserActionsContainer::ModelLoaded() {
691 SetContainerWidth(); 713 SetContainerWidth();
692 } 714 }
693 715
694 void BrowserActionsContainer::LoadImages() { 716 void BrowserActionsContainer::LoadImages() {
695 ui::ThemeProvider* tp = GetThemeProvider(); 717 ui::ThemeProvider* tp = GetThemeProvider();
696 chevron_->SetIcon(*tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); 718 chevron_->SetIcon(*tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW));
697 chevron_->SetHoverIcon(*tp->GetImageSkiaNamed( 719 chevron_->SetHoverIcon(*tp->GetImageSkiaNamed(
698 IDR_BROWSER_ACTIONS_OVERFLOW_H)); 720 IDR_BROWSER_ACTIONS_OVERFLOW_H));
699 chevron_->SetPushedIcon(*tp->GetImageSkiaNamed( 721 chevron_->SetPushedIcon(*tp->GetImageSkiaNamed(
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 bool BrowserActionsContainer::ShouldDisplayBrowserAction( 829 bool BrowserActionsContainer::ShouldDisplayBrowserAction(
808 const Extension* extension) { 830 const Extension* extension) {
809 // Only display incognito-enabled extensions while in incognito mode. 831 // Only display incognito-enabled extensions while in incognito mode.
810 return 832 return
811 (!profile_->IsOffTheRecord() || 833 (!profile_->IsOffTheRecord() ||
812 extension_util::IsIncognitoEnabled( 834 extension_util::IsIncognitoEnabled(
813 extension->id(), 835 extension->id(),
814 extensions::ExtensionSystem::Get(profile_)->extension_service())); 836 extensions::ExtensionSystem::Get(profile_)->extension_service()));
815 } 837 }
816 838
817 void BrowserActionsContainer::ShowPopup( 839 bool BrowserActionsContainer::ShowPopup(
818 BrowserActionButton* button, 840 BrowserActionButton* button,
819 ExtensionPopup::ShowAction show_action) { 841 ExtensionPopup::ShowAction show_action,
842 bool should_grant) {
820 const Extension* extension = button->extension(); 843 const Extension* extension = button->extension();
821 GURL popup_url; 844 GURL popup_url;
822 if (model_->ExecuteBrowserAction(extension, browser_, &popup_url) != 845 if (model_->ExecuteBrowserAction(
846 extension, browser_, &popup_url, should_grant) !=
823 ExtensionToolbarModel::ACTION_SHOW_POPUP) { 847 ExtensionToolbarModel::ACTION_SHOW_POPUP) {
824 return; 848 return false;
825 } 849 }
826 850
827 // If we're showing the same popup, just hide it and return. 851 // If we're showing the same popup, just hide it and return.
828 bool same_showing = popup_ && button == popup_button_; 852 bool same_showing = popup_ && button == popup_button_;
829 853
830 // Always hide the current popup, even if it's not the same. 854 // Always hide the current popup, even if it's not the same.
831 // Only one popup should be visible at a time. 855 // Only one popup should be visible at a time.
832 HidePopup(); 856 HidePopup();
833 857
834 if (same_showing) 858 if (same_showing)
835 return; 859 return false;
836 860
837 // We can get the execute event for browser actions that are not visible, 861 // We can get the execute event for browser actions that are not visible,
838 // since buttons can be activated from the overflow menu (chevron). In that 862 // since buttons can be activated from the overflow menu (chevron). In that
839 // case we show the popup as originating from the chevron. 863 // case we show the popup as originating from the chevron.
840 View* reference_view = button->parent()->visible() ? button : chevron_; 864 View* reference_view = button->parent()->visible() ? button : chevron_;
841 views::BubbleBorder::Arrow arrow = base::i18n::IsRTL() ? 865 views::BubbleBorder::Arrow arrow = base::i18n::IsRTL() ?
842 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT; 866 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT;
843 popup_ = ExtensionPopup::ShowPopup(popup_url, 867 popup_ = ExtensionPopup::ShowPopup(popup_url,
844 browser_, 868 browser_,
845 reference_view, 869 reference_view,
846 arrow, 870 arrow,
847 show_action); 871 show_action);
848 popup_->GetWidget()->AddObserver(this); 872 popup_->GetWidget()->AddObserver(this);
849 popup_button_ = button; 873 popup_button_ = button;
850 popup_button_->SetButtonPushed(); 874
875 // Only set button as pushed if it was triggered by a user click.
876 if (should_grant)
877 popup_button_->SetButtonPushed();
878 return true;
851 } 879 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698