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 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
452 popup_ = NULL; | 453 popup_ = NULL; |
453 // |popup_button_| is NULL if the extension has been removed. | 454 // |popup_button_| is NULL if the extension has been removed. |
454 if (popup_button_) { | 455 if (popup_button_) { |
455 popup_button_->SetButtonNotPushed(); | 456 popup_button_->SetButtonNotPushed(); |
456 popup_button_ = NULL; | 457 popup_button_ = NULL; |
457 } | 458 } |
458 } | 459 } |
459 | 460 |
460 void BrowserActionsContainer::InspectPopup(ExtensionAction* action) { | 461 void BrowserActionsContainer::InspectPopup(ExtensionAction* action) { |
461 BrowserActionView* view = GetBrowserActionView(action); | 462 BrowserActionView* view = GetBrowserActionView(action); |
462 ShowPopup(view->button(), ExtensionPopup::SHOW_AND_INSPECT); | 463 ShowPopup(view->button(), ExtensionPopup::SHOW_AND_INSPECT, true); |
463 } | 464 } |
464 | 465 |
465 int BrowserActionsContainer::GetCurrentTabId() const { | 466 int BrowserActionsContainer::GetCurrentTabId() const { |
466 content::WebContents* active_tab = | 467 content::WebContents* active_tab = |
467 browser_->tab_strip_model()->GetActiveWebContents(); | 468 browser_->tab_strip_model()->GetActiveWebContents(); |
468 if (!active_tab) | 469 if (!active_tab) |
469 return -1; | 470 return -1; |
470 | 471 |
471 return SessionTabHelper::FromWebContents(active_tab)->session_id().id(); | 472 return SessionTabHelper::FromWebContents(active_tab)->session_id().id(); |
472 } | 473 } |
473 | 474 |
474 void BrowserActionsContainer::OnBrowserActionExecuted( | 475 void BrowserActionsContainer::OnBrowserActionExecuted( |
475 BrowserActionButton* button) { | 476 BrowserActionButton* button) { |
476 ShowPopup(button, ExtensionPopup::SHOW); | 477 ShowPopup(button, ExtensionPopup::SHOW, true); |
477 } | 478 } |
478 | 479 |
479 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() { | 480 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() { |
480 SetVisible(!browser_action_views_.empty()); | 481 SetVisible(!browser_action_views_.empty()); |
481 owner_view_->Layout(); | 482 owner_view_->Layout(); |
482 owner_view_->SchedulePaint(); | 483 owner_view_->SchedulePaint(); |
483 } | 484 } |
484 | 485 |
485 gfx::Point BrowserActionsContainer::GetViewContentOffset() const { | 486 gfx::Point BrowserActionsContainer::GetViewContentOffset() const { |
486 return gfx::Point(0, ToolbarView::kVertSpacing); | 487 return gfx::Point(0, ToolbarView::kVertSpacing); |
(...skipping 192 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. | |
694 // Can remove toolbar check when http://crbug.com/308645 is fixed. | |
Finnur
2013/10/18 10:31:01
TODO(justinlin): Remove toolbar check when ...
justinlin
2013/10/19 06:01:48
Done.
| |
695 if (popup_ || | |
696 !browser_->window()->IsActive() || | |
697 !browser_->window()->IsToolbarVisible()) { | |
698 return false; | |
699 } | |
700 | |
701 for (BrowserActionViews::iterator it = browser_action_views_.begin(); | |
702 it != browser_action_views_.end(); ++it) { | |
703 BrowserActionButton* button = (*it)->button(); | |
704 if (button && button->extension() == extension) | |
705 return ShowPopup(button, ExtensionPopup::SHOW, false); | |
706 } | |
707 return 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
805 | 826 |
806 bool BrowserActionsContainer::ShouldDisplayBrowserAction( | 827 bool BrowserActionsContainer::ShouldDisplayBrowserAction( |
807 const Extension* extension) { | 828 const Extension* extension) { |
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 bool BrowserActionsContainer::ShowPopup( |
816 BrowserActionButton* button, | 837 BrowserActionButton* button, |
817 ExtensionPopup::ShowAction show_action) { | 838 ExtensionPopup::ShowAction show_action, |
839 bool should_grant) { | |
818 const Extension* extension = button->extension(); | 840 const Extension* extension = button->extension(); |
819 GURL popup_url; | 841 GURL popup_url; |
820 if (model_->ExecuteBrowserAction(extension, browser_, &popup_url) != | 842 if (model_->ExecuteBrowserAction( |
843 extension, browser_, &popup_url, should_grant) != | |
821 ExtensionToolbarModel::ACTION_SHOW_POPUP) { | 844 ExtensionToolbarModel::ACTION_SHOW_POPUP) { |
822 return; | 845 return false; |
823 } | 846 } |
824 | 847 |
825 // If we're showing the same popup, just hide it and return. | 848 // If we're showing the same popup, just hide it and return. |
826 bool same_showing = popup_ && button == popup_button_; | 849 bool same_showing = popup_ && button == popup_button_; |
827 | 850 |
828 // Always hide the current popup, even if it's not the same. | 851 // Always hide the current popup, even if it's not the same. |
829 // Only one popup should be visible at a time. | 852 // Only one popup should be visible at a time. |
830 HidePopup(); | 853 HidePopup(); |
831 | 854 |
832 if (same_showing) | 855 if (same_showing) |
833 return; | 856 return false; |
834 | 857 |
835 // We can get the execute event for browser actions that are not visible, | 858 // 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 | 859 // since buttons can be activated from the overflow menu (chevron). In that |
837 // case we show the popup as originating from the chevron. | 860 // case we show the popup as originating from the chevron. |
838 View* reference_view = button->parent()->visible() ? button : chevron_; | 861 View* reference_view = button->parent()->visible() ? button : chevron_; |
839 views::BubbleBorder::Arrow arrow = base::i18n::IsRTL() ? | 862 views::BubbleBorder::Arrow arrow = base::i18n::IsRTL() ? |
840 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT; | 863 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT; |
841 popup_ = ExtensionPopup::ShowPopup(popup_url, | 864 popup_ = ExtensionPopup::ShowPopup(popup_url, |
842 browser_, | 865 browser_, |
843 reference_view, | 866 reference_view, |
844 arrow, | 867 arrow, |
845 show_action); | 868 show_action); |
846 popup_->GetWidget()->AddObserver(this); | 869 popup_->GetWidget()->AddObserver(this); |
847 popup_button_ = button; | 870 popup_button_ = button; |
848 popup_button_->SetButtonPushed(); | 871 |
872 // Only set button as pushed if it was triggered by a user click. | |
873 if (should_grant) | |
874 popup_button_->SetButtonPushed(); | |
875 return true; | |
849 } | 876 } |
OLD | NEW |