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_list.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 void BrowserActionsContainer::BrowserActionShowPopup( | |
691 const extensions::Extension* extension) { | |
692 // Do not override other popups and only show in active window. | |
693 if (popup_ || | |
694 BrowserList::GetInstance(chrome::GetActiveDesktop())->GetLastActive() != | |
sky
2013/10/16 14:19:25
browser_->window()->IsActive()?
justinlin
2013/10/16 19:31:29
Done.
| |
695 browser_) { | |
696 return; | |
697 } | |
698 | |
699 BrowserActionButton* button = NULL; | |
700 for (BrowserActionViews::iterator it = browser_action_views_.begin(); | |
701 it != browser_action_views_.end(); ++it) { | |
702 if ((*it)->button()->extension() == extension) { | |
703 button = (*it)->button(); | |
sky
2013/10/16 14:19:25
How about showing right here and returning?
justinlin
2013/10/16 19:31:29
Done.
| |
704 } | |
705 } | |
706 if (button != NULL) | |
707 ShowPopup(button, ExtensionPopup::SHOW, false); | |
708 } | |
709 | |
689 void BrowserActionsContainer::ModelLoaded() { | 710 void BrowserActionsContainer::ModelLoaded() { |
690 SetContainerWidth(); | 711 SetContainerWidth(); |
691 } | 712 } |
692 | 713 |
693 void BrowserActionsContainer::LoadImages() { | 714 void BrowserActionsContainer::LoadImages() { |
694 ui::ThemeProvider* tp = GetThemeProvider(); | 715 ui::ThemeProvider* tp = GetThemeProvider(); |
695 chevron_->SetIcon(*tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); | 716 chevron_->SetIcon(*tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); |
696 chevron_->SetHoverIcon(*tp->GetImageSkiaNamed( | 717 chevron_->SetHoverIcon(*tp->GetImageSkiaNamed( |
697 IDR_BROWSER_ACTIONS_OVERFLOW_H)); | 718 IDR_BROWSER_ACTIONS_OVERFLOW_H)); |
698 chevron_->SetPushedIcon(*tp->GetImageSkiaNamed( | 719 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. | 829 // Only display incognito-enabled extensions while in incognito mode. |
809 return | 830 return |
810 (!profile_->IsOffTheRecord() || | 831 (!profile_->IsOffTheRecord() || |
811 extensions::ExtensionSystem::Get(profile_)->extension_service()-> | 832 extensions::ExtensionSystem::Get(profile_)->extension_service()-> |
812 IsIncognitoEnabled(extension->id())); | 833 IsIncognitoEnabled(extension->id())); |
813 } | 834 } |
814 | 835 |
815 void BrowserActionsContainer::ShowPopup( | 836 void BrowserActionsContainer::ShowPopup( |
816 BrowserActionButton* button, | 837 BrowserActionButton* button, |
817 ExtensionPopup::ShowAction show_action) { | 838 ExtensionPopup::ShowAction show_action) { |
839 ShowPopup(button, show_action, true); | |
840 } | |
841 | |
842 void BrowserActionsContainer::ShowPopup( | |
843 BrowserActionButton* button, | |
844 ExtensionPopup::ShowAction show_action, | |
845 bool should_grant) { | |
818 const Extension* extension = button->extension(); | 846 const Extension* extension = button->extension(); |
819 GURL popup_url; | 847 GURL popup_url; |
820 if (model_->ExecuteBrowserAction(extension, browser_, &popup_url) != | 848 if (model_->ExecuteBrowserAction( |
849 extension, browser_, &popup_url, should_grant) != | |
821 ExtensionToolbarModel::ACTION_SHOW_POPUP) { | 850 ExtensionToolbarModel::ACTION_SHOW_POPUP) { |
822 return; | 851 return; |
823 } | 852 } |
824 | 853 |
825 // If we're showing the same popup, just hide it and return. | 854 // If we're showing the same popup, just hide it and return. |
826 bool same_showing = popup_ && button == popup_button_; | 855 bool same_showing = popup_ && button == popup_button_; |
827 | 856 |
828 // Always hide the current popup, even if it's not the same. | 857 // Always hide the current popup, even if it's not the same. |
829 // Only one popup should be visible at a time. | 858 // Only one popup should be visible at a time. |
830 HidePopup(); | 859 HidePopup(); |
831 | 860 |
832 if (same_showing) | 861 if (same_showing) |
833 return; | 862 return; |
834 | 863 |
835 // We can get the execute event for browser actions that are not visible, | 864 // 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 | 865 // since buttons can be activated from the overflow menu (chevron). In that |
837 // case we show the popup as originating from the chevron. | 866 // case we show the popup as originating from the chevron. |
838 View* reference_view = button->parent()->visible() ? button : chevron_; | 867 View* reference_view = button->parent()->visible() ? button : chevron_; |
839 views::BubbleBorder::Arrow arrow = base::i18n::IsRTL() ? | 868 views::BubbleBorder::Arrow arrow = base::i18n::IsRTL() ? |
840 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT; | 869 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT; |
841 popup_ = ExtensionPopup::ShowPopup(popup_url, | 870 popup_ = ExtensionPopup::ShowPopup(popup_url, |
842 browser_, | 871 browser_, |
843 reference_view, | 872 reference_view, |
844 arrow, | 873 arrow, |
845 show_action); | 874 show_action); |
846 popup_->GetWidget()->AddObserver(this); | 875 popup_->GetWidget()->AddObserver(this); |
847 popup_button_ = button; | 876 popup_button_ = button; |
848 popup_button_->SetButtonPushed(); | 877 |
878 // If the popup was triggered in such a way that the tab should not be | |
879 // granted tab permissions, then it was not by a user click. | |
Finnur
2013/10/16 15:01:26
nit: double negative. Can you reword?
justinlin
2013/10/16 19:31:29
Done.
| |
880 if (should_grant) | |
881 popup_button_->SetButtonPushed(); | |
849 } | 882 } |
OLD | NEW |