OLD | NEW |
---|---|
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" |
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
679 index = model_->OriginalIndexToIncognito(index); | 679 index = model_->OriginalIndexToIncognito(index); |
680 | 680 |
681 DCHECK(index >= 0 && index < static_cast<int>(browser_action_views_.size())); | 681 DCHECK(index >= 0 && index < static_cast<int>(browser_action_views_.size())); |
682 | 682 |
683 DeleteBrowserActionViews(); | 683 DeleteBrowserActionViews(); |
684 CreateBrowserActionViews(); | 684 CreateBrowserActionViews(); |
685 Layout(); | 685 Layout(); |
686 SchedulePaint(); | 686 SchedulePaint(); |
687 } | 687 } |
688 | 688 |
689 void BrowserActionsContainer::BrowserActionShowPopup( | |
690 const extensions::Extension* extension) { | |
691 // Do not override other popups and only show in active window. | |
692 if (popup_ || !browser_->window()->IsActive()) | |
693 return; | |
694 | |
695 BrowserActionButton* button = NULL; | |
sky
2013/10/16 22:26:07
Did you try this? I think you want to nuke button,
justinlin
2013/10/17 04:14:52
err, right. Was *just* about to compile it and tes
Finnur
2013/10/17 14:58:34
Wait? A window is created for extension's backgrou
justinlin
2013/10/17 18:32:53
I mean when opening the console view of the backgr
| |
696 for (BrowserActionViews::iterator it = browser_action_views_.begin(); | |
697 it != browser_action_views_.end(); ++it) { | |
698 if ((*it)->button()->extension() == extension) { | |
699 if (button != NULL) | |
700 ShowPopup(button, ExtensionPopup::SHOW, false); | |
701 return; | |
702 } | |
703 } | |
704 } | |
705 | |
689 void BrowserActionsContainer::ModelLoaded() { | 706 void BrowserActionsContainer::ModelLoaded() { |
690 SetContainerWidth(); | 707 SetContainerWidth(); |
691 } | 708 } |
692 | 709 |
693 void BrowserActionsContainer::LoadImages() { | 710 void BrowserActionsContainer::LoadImages() { |
694 ui::ThemeProvider* tp = GetThemeProvider(); | 711 ui::ThemeProvider* tp = GetThemeProvider(); |
695 chevron_->SetIcon(*tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); | 712 chevron_->SetIcon(*tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); |
696 chevron_->SetHoverIcon(*tp->GetImageSkiaNamed( | 713 chevron_->SetHoverIcon(*tp->GetImageSkiaNamed( |
697 IDR_BROWSER_ACTIONS_OVERFLOW_H)); | 714 IDR_BROWSER_ACTIONS_OVERFLOW_H)); |
698 chevron_->SetPushedIcon(*tp->GetImageSkiaNamed( | 715 chevron_->SetPushedIcon(*tp->GetImageSkiaNamed( |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
808 // Only display incognito-enabled extensions while in incognito mode. | 825 // Only display incognito-enabled extensions while in incognito mode. |
809 return | 826 return |
810 (!profile_->IsOffTheRecord() || | 827 (!profile_->IsOffTheRecord() || |
811 extensions::ExtensionSystem::Get(profile_)->extension_service()-> | 828 extensions::ExtensionSystem::Get(profile_)->extension_service()-> |
812 IsIncognitoEnabled(extension->id())); | 829 IsIncognitoEnabled(extension->id())); |
813 } | 830 } |
814 | 831 |
815 void BrowserActionsContainer::ShowPopup( | 832 void BrowserActionsContainer::ShowPopup( |
816 BrowserActionButton* button, | 833 BrowserActionButton* button, |
817 ExtensionPopup::ShowAction show_action) { | 834 ExtensionPopup::ShowAction show_action) { |
835 ShowPopup(button, show_action, true); | |
836 } | |
837 | |
838 void BrowserActionsContainer::ShowPopup( | |
839 BrowserActionButton* button, | |
840 ExtensionPopup::ShowAction show_action, | |
841 bool should_grant) { | |
818 const Extension* extension = button->extension(); | 842 const Extension* extension = button->extension(); |
819 GURL popup_url; | 843 GURL popup_url; |
820 if (model_->ExecuteBrowserAction(extension, browser_, &popup_url) != | 844 if (model_->ExecuteBrowserAction( |
845 extension, browser_, &popup_url, should_grant) != | |
821 ExtensionToolbarModel::ACTION_SHOW_POPUP) { | 846 ExtensionToolbarModel::ACTION_SHOW_POPUP) { |
822 return; | 847 return; |
823 } | 848 } |
824 | 849 |
825 // If we're showing the same popup, just hide it and return. | 850 // If we're showing the same popup, just hide it and return. |
826 bool same_showing = popup_ && button == popup_button_; | 851 bool same_showing = popup_ && button == popup_button_; |
827 | 852 |
828 // Always hide the current popup, even if it's not the same. | 853 // Always hide the current popup, even if it's not the same. |
829 // Only one popup should be visible at a time. | 854 // Only one popup should be visible at a time. |
830 HidePopup(); | 855 HidePopup(); |
831 | 856 |
832 if (same_showing) | 857 if (same_showing) |
833 return; | 858 return; |
834 | 859 |
835 // We can get the execute event for browser actions that are not visible, | 860 // We can get the execute event for browser actions that are not visible, |
836 // since buttons can be activated from the overflow menu (chevron). In that | 861 // since buttons can be activated from the overflow menu (chevron). In that |
837 // case we show the popup as originating from the chevron. | 862 // case we show the popup as originating from the chevron. |
838 View* reference_view = button->parent()->visible() ? button : chevron_; | 863 View* reference_view = button->parent()->visible() ? button : chevron_; |
839 views::BubbleBorder::Arrow arrow = base::i18n::IsRTL() ? | 864 views::BubbleBorder::Arrow arrow = base::i18n::IsRTL() ? |
840 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT; | 865 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT; |
841 popup_ = ExtensionPopup::ShowPopup(popup_url, | 866 popup_ = ExtensionPopup::ShowPopup(popup_url, |
842 browser_, | 867 browser_, |
843 reference_view, | 868 reference_view, |
844 arrow, | 869 arrow, |
845 show_action); | 870 show_action); |
846 popup_->GetWidget()->AddObserver(this); | 871 popup_->GetWidget()->AddObserver(this); |
847 popup_button_ = button; | 872 popup_button_ = button; |
848 popup_button_->SetButtonPushed(); | 873 |
874 // Only set button as pushed if it was triggered by a user click. | |
875 if (should_grant) | |
876 popup_button_->SetButtonPushed(); | |
849 } | 877 } |
OLD | NEW |