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" |
11 #include "chrome/browser/extensions/extension_system.h" | 11 #include "chrome/browser/extensions/extension_system.h" |
12 #include "chrome/browser/extensions/tab_helper.h" | 12 #include "chrome/browser/extensions/tab_helper.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/sessions/session_tab_helper.h" | 14 #include "chrome/browser/sessions/session_tab_helper.h" |
15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/browser_window.h" | |
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
17 #include "chrome/browser/ui/view_ids.h" | 18 #include "chrome/browser/ui/view_ids.h" |
18 #include "chrome/browser/ui/views/browser_action_view.h" | 19 #include "chrome/browser/ui/views/browser_action_view.h" |
19 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" | 20 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" |
20 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h" | 21 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h" |
21 #include "chrome/browser/ui/views/extensions/extension_popup.h" | 22 #include "chrome/browser/ui/views/extensions/extension_popup.h" |
22 #include "chrome/browser/ui/views/toolbar_view.h" | 23 #include "chrome/browser/ui/views/toolbar_view.h" |
23 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
24 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
25 #include "grit/theme_resources.h" | 26 #include "grit/theme_resources.h" |
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
679 index = model_->OriginalIndexToIncognito(index); | 680 index = model_->OriginalIndexToIncognito(index); |
680 | 681 |
681 DCHECK(index >= 0 && index < static_cast<int>(browser_action_views_.size())); | 682 DCHECK(index >= 0 && index < static_cast<int>(browser_action_views_.size())); |
682 | 683 |
683 DeleteBrowserActionViews(); | 684 DeleteBrowserActionViews(); |
684 CreateBrowserActionViews(); | 685 CreateBrowserActionViews(); |
685 Layout(); | 686 Layout(); |
686 SchedulePaint(); | 687 SchedulePaint(); |
687 } | 688 } |
688 | 689 |
690 bool BrowserActionsContainer::BrowserActionShowPopup( | |
691 const extensions::Extension* extension) { | |
692 // Do not override other popups and only show in active window. The window | |
693 // must also have a toolbar, otherwise it should not be showing popups. | |
Finnur
2013/10/17 14:58:34
Document that you are checking for toolbar visibil
justinlin
2013/10/17 18:32:53
Done.
| |
694 if (popup_ || | |
695 !browser_->window()->IsActive() || | |
696 !browser_->window()->IsToolbarVisible()) { | |
697 return false; | |
698 } | |
699 | |
700 for (BrowserActionViews::iterator it = browser_action_views_.begin(); | |
701 it != browser_action_views_.end(); ++it) { | |
702 BrowserActionButton* button = (*it)->button(); | |
703 if (button && button->extension() == extension) | |
704 return ShowPopup(button, ExtensionPopup::SHOW, false); | |
705 } | |
706 return false; | |
707 } | |
708 | |
689 void BrowserActionsContainer::ModelLoaded() { | 709 void BrowserActionsContainer::ModelLoaded() { |
690 SetContainerWidth(); | 710 SetContainerWidth(); |
691 } | 711 } |
692 | 712 |
693 void BrowserActionsContainer::LoadImages() { | 713 void BrowserActionsContainer::LoadImages() { |
694 ui::ThemeProvider* tp = GetThemeProvider(); | 714 ui::ThemeProvider* tp = GetThemeProvider(); |
695 chevron_->SetIcon(*tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); | 715 chevron_->SetIcon(*tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); |
696 chevron_->SetHoverIcon(*tp->GetImageSkiaNamed( | 716 chevron_->SetHoverIcon(*tp->GetImageSkiaNamed( |
697 IDR_BROWSER_ACTIONS_OVERFLOW_H)); | 717 IDR_BROWSER_ACTIONS_OVERFLOW_H)); |
698 chevron_->SetPushedIcon(*tp->GetImageSkiaNamed( | 718 chevron_->SetPushedIcon(*tp->GetImageSkiaNamed( |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
805 | 825 |
806 bool BrowserActionsContainer::ShouldDisplayBrowserAction( | 826 bool BrowserActionsContainer::ShouldDisplayBrowserAction( |
807 const Extension* extension) { | 827 const Extension* extension) { |
808 // Only display incognito-enabled extensions while in incognito mode. | 828 // Only display incognito-enabled extensions while in incognito mode. |
809 return | 829 return |
810 (!profile_->IsOffTheRecord() || | 830 (!profile_->IsOffTheRecord() || |
811 extensions::ExtensionSystem::Get(profile_)->extension_service()-> | 831 extensions::ExtensionSystem::Get(profile_)->extension_service()-> |
812 IsIncognitoEnabled(extension->id())); | 832 IsIncognitoEnabled(extension->id())); |
813 } | 833 } |
814 | 834 |
815 void BrowserActionsContainer::ShowPopup( | 835 bool BrowserActionsContainer::ShowPopup( |
816 BrowserActionButton* button, | 836 BrowserActionButton* button, |
817 ExtensionPopup::ShowAction show_action) { | 837 ExtensionPopup::ShowAction show_action) { |
838 return ShowPopup(button, show_action, true); | |
839 } | |
840 | |
841 bool BrowserActionsContainer::ShowPopup( | |
842 BrowserActionButton* button, | |
843 ExtensionPopup::ShowAction show_action, | |
844 bool should_grant) { | |
818 const Extension* extension = button->extension(); | 845 const Extension* extension = button->extension(); |
819 GURL popup_url; | 846 GURL popup_url; |
820 if (model_->ExecuteBrowserAction(extension, browser_, &popup_url) != | 847 if (model_->ExecuteBrowserAction( |
848 extension, browser_, &popup_url, should_grant) != | |
821 ExtensionToolbarModel::ACTION_SHOW_POPUP) { | 849 ExtensionToolbarModel::ACTION_SHOW_POPUP) { |
822 return; | 850 return false; |
823 } | 851 } |
824 | 852 |
825 // If we're showing the same popup, just hide it and return. | 853 // If we're showing the same popup, just hide it and return. |
826 bool same_showing = popup_ && button == popup_button_; | 854 bool same_showing = popup_ && button == popup_button_; |
827 | 855 |
828 // Always hide the current popup, even if it's not the same. | 856 // Always hide the current popup, even if it's not the same. |
829 // Only one popup should be visible at a time. | 857 // Only one popup should be visible at a time. |
830 HidePopup(); | 858 HidePopup(); |
831 | 859 |
832 if (same_showing) | 860 if (same_showing) |
833 return; | 861 return false; |
834 | 862 |
835 // We can get the execute event for browser actions that are not visible, | 863 // 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 | 864 // since buttons can be activated from the overflow menu (chevron). In that |
837 // case we show the popup as originating from the chevron. | 865 // case we show the popup as originating from the chevron. |
838 View* reference_view = button->parent()->visible() ? button : chevron_; | 866 View* reference_view = button->parent()->visible() ? button : chevron_; |
839 views::BubbleBorder::Arrow arrow = base::i18n::IsRTL() ? | 867 views::BubbleBorder::Arrow arrow = base::i18n::IsRTL() ? |
840 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT; | 868 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT; |
841 popup_ = ExtensionPopup::ShowPopup(popup_url, | 869 popup_ = ExtensionPopup::ShowPopup(popup_url, |
842 browser_, | 870 browser_, |
843 reference_view, | 871 reference_view, |
844 arrow, | 872 arrow, |
845 show_action); | 873 show_action); |
846 popup_->GetWidget()->AddObserver(this); | 874 popup_->GetWidget()->AddObserver(this); |
847 popup_button_ = button; | 875 popup_button_ = button; |
848 popup_button_->SetButtonPushed(); | 876 |
877 // Only set button as pushed if it was triggered by a user click. | |
878 if (should_grant) | |
879 popup_button_->SetButtonPushed(); | |
880 return true; | |
849 } | 881 } |
OLD | NEW |