| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/toolbar/browser_actions_container.h" | 5 #include "chrome/browser/ui/views/toolbar/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" | |
| 11 #include "chrome/browser/extensions/extension_util.h" | 10 #include "chrome/browser/extensions/extension_util.h" |
| 12 #include "chrome/browser/extensions/extension_view_host.h" | 11 #include "chrome/browser/extensions/extension_view_host.h" |
| 13 #include "chrome/browser/extensions/tab_helper.h" | 12 #include "chrome/browser/extensions/tab_helper.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/sessions/session_tab_helper.h" | 14 #include "chrome/browser/sessions/session_tab_helper.h" |
| 16 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/browser_window.h" | 16 #include "chrome/browser/ui/browser_window.h" |
| 18 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 19 #include "chrome/browser/ui/view_ids.h" | 18 #include "chrome/browser/ui/view_ids.h" |
| 20 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" | 19 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" |
| 21 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views
.h" | 20 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views
.h" |
| 22 #include "chrome/browser/ui/views/extensions/extension_popup.h" | 21 #include "chrome/browser/ui/views/extensions/extension_popup.h" |
| 23 #include "chrome/browser/ui/views/toolbar/browser_action_view.h" | 22 #include "chrome/browser/ui/views/toolbar/browser_actions_container_observer.h" |
| 24 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 23 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| 25 #include "chrome/common/extensions/command.h" | 24 #include "chrome/common/extensions/command.h" |
| 26 #include "chrome/common/pref_names.h" | 25 #include "extensions/browser/extension_registry.h" |
| 27 #include "extensions/browser/extension_system.h" | 26 #include "extensions/browser/extension_system.h" |
| 28 #include "extensions/browser/pref_names.h" | 27 #include "extensions/browser/pref_names.h" |
| 29 #include "extensions/browser/runtime_data.h" | 28 #include "extensions/browser/runtime_data.h" |
| 30 #include "extensions/common/feature_switch.h" | 29 #include "extensions/common/feature_switch.h" |
| 31 #include "grit/generated_resources.h" | 30 #include "grit/generated_resources.h" |
| 32 #include "grit/theme_resources.h" | 31 #include "grit/theme_resources.h" |
| 33 #include "grit/ui_resources.h" | 32 #include "grit/ui_resources.h" |
| 34 #include "third_party/skia/include/core/SkColor.h" | 33 #include "third_party/skia/include/core/SkColor.h" |
| 35 #include "ui/accessibility/ax_view_state.h" | 34 #include "ui/accessibility/ax_view_state.h" |
| 36 #include "ui/base/dragdrop/drag_utils.h" | 35 #include "ui/base/dragdrop/drag_utils.h" |
| 37 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
| 38 #include "ui/base/nine_image_painter_factory.h" | 37 #include "ui/base/nine_image_painter_factory.h" |
| 39 #include "ui/base/resource/resource_bundle.h" | 38 #include "ui/base/resource/resource_bundle.h" |
| 40 #include "ui/base/theme_provider.h" | 39 #include "ui/base/theme_provider.h" |
| 41 #include "ui/gfx/animation/slide_animation.h" | 40 #include "ui/gfx/animation/slide_animation.h" |
| 42 #include "ui/gfx/canvas.h" | 41 #include "ui/gfx/canvas.h" |
| 43 #include "ui/gfx/geometry/rect.h" | 42 #include "ui/gfx/geometry/rect.h" |
| 44 #include "ui/views/controls/button/label_button_border.h" | 43 #include "ui/views/controls/button/label_button_border.h" |
| 44 #include "ui/views/controls/button/menu_button.h" |
| 45 #include "ui/views/controls/resize_area.h" | 45 #include "ui/views/controls/resize_area.h" |
| 46 #include "ui/views/metrics.h" | 46 #include "ui/views/metrics.h" |
| 47 #include "ui/views/painter.h" | 47 #include "ui/views/painter.h" |
| 48 #include "ui/views/widget/widget.h" | 48 #include "ui/views/widget/widget.h" |
| 49 | 49 |
| 50 using extensions::Extension; | 50 using extensions::Extension; |
| 51 | 51 |
| 52 namespace { | 52 namespace { |
| 53 | 53 |
| 54 // Horizontal spacing between most items in the container, as well as after the | 54 // Horizontal spacing between most items in the container, as well as after the |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 bool BrowserActionsContainer::disable_animations_during_testing_ = false; | 124 bool BrowserActionsContainer::disable_animations_during_testing_ = false; |
| 125 | 125 |
| 126 BrowserActionsContainer::BrowserActionsContainer( | 126 BrowserActionsContainer::BrowserActionsContainer( |
| 127 Browser* browser, | 127 Browser* browser, |
| 128 View* owner_view, | 128 View* owner_view, |
| 129 BrowserActionsContainer* main_container) | 129 BrowserActionsContainer* main_container) |
| 130 : profile_(browser->profile()), | 130 : profile_(browser->profile()), |
| 131 browser_(browser), | 131 browser_(browser), |
| 132 owner_view_(owner_view), | 132 owner_view_(owner_view), |
| 133 main_container_(main_container), | 133 main_container_(main_container), |
| 134 popup_(NULL), | 134 popup_owner_(NULL), |
| 135 popup_button_(NULL), | |
| 136 model_(NULL), | 135 model_(NULL), |
| 137 container_width_(0), | 136 container_width_(0), |
| 138 resize_area_(NULL), | 137 resize_area_(NULL), |
| 139 chevron_(NULL), | 138 chevron_(NULL), |
| 140 overflow_menu_(NULL), | 139 overflow_menu_(NULL), |
| 141 suppress_chevron_(false), | 140 suppress_chevron_(false), |
| 142 resize_amount_(0), | 141 resize_amount_(0), |
| 143 animation_target_size_(0), | 142 animation_target_size_(0), |
| 144 task_factory_(this), | 143 task_factory_(this), |
| 145 show_menu_task_factory_(this) { | 144 show_menu_task_factory_(this) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 BrowserActionsContainer::~BrowserActionsContainer() { | 180 BrowserActionsContainer::~BrowserActionsContainer() { |
| 182 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, | 181 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, |
| 183 observers_, | 182 observers_, |
| 184 OnBrowserActionsContainerDestroyed()); | 183 OnBrowserActionsContainerDestroyed()); |
| 185 | 184 |
| 186 if (overflow_menu_) | 185 if (overflow_menu_) |
| 187 overflow_menu_->set_observer(NULL); | 186 overflow_menu_->set_observer(NULL); |
| 188 if (model_) | 187 if (model_) |
| 189 model_->RemoveObserver(this); | 188 model_->RemoveObserver(this); |
| 190 StopShowFolderDropMenuTimer(); | 189 StopShowFolderDropMenuTimer(); |
| 191 if (popup_) | 190 HideActivePopup(); |
| 192 popup_->GetWidget()->RemoveObserver(this); | |
| 193 HidePopup(); | |
| 194 DeleteBrowserActionViews(); | 191 DeleteBrowserActionViews(); |
| 195 } | 192 } |
| 196 | 193 |
| 197 void BrowserActionsContainer::Init() { | 194 void BrowserActionsContainer::Init() { |
| 198 LoadImages(); | 195 LoadImages(); |
| 199 | 196 |
| 200 // We wait to set the container width until now so that the chevron images | 197 // We wait to set the container width until now so that the chevron images |
| 201 // will be loaded. The width calculation needs to know the chevron size. | 198 // will be loaded. The width calculation needs to know the chevron size. |
| 202 if (model_ && | 199 if (model_ && |
| 203 !profile_->GetPrefs()->HasPrefPath( | 200 !profile_->GetPrefs()->HasPrefPath( |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 if (!ShouldDisplayBrowserAction(i->get())) | 236 if (!ShouldDisplayBrowserAction(i->get())) |
| 240 continue; | 237 continue; |
| 241 | 238 |
| 242 BrowserActionView* view = new BrowserActionView(i->get(), browser_, this); | 239 BrowserActionView* view = new BrowserActionView(i->get(), browser_, this); |
| 243 browser_action_views_.push_back(view); | 240 browser_action_views_.push_back(view); |
| 244 AddChildView(view); | 241 AddChildView(view); |
| 245 } | 242 } |
| 246 } | 243 } |
| 247 | 244 |
| 248 void BrowserActionsContainer::DeleteBrowserActionViews() { | 245 void BrowserActionsContainer::DeleteBrowserActionViews() { |
| 249 HidePopup(); | 246 HideActivePopup(); |
| 250 if (overflow_menu_) | 247 if (overflow_menu_) |
| 251 overflow_menu_->NotifyBrowserActionViewsDeleting(); | 248 overflow_menu_->NotifyBrowserActionViewsDeleting(); |
| 252 STLDeleteElements(&browser_action_views_); | 249 STLDeleteElements(&browser_action_views_); |
| 253 } | 250 } |
| 254 | 251 |
| 255 size_t BrowserActionsContainer::VisibleBrowserActions() const { | 252 size_t BrowserActionsContainer::VisibleBrowserActions() const { |
| 256 size_t visible_actions = 0; | 253 size_t visible_actions = 0; |
| 257 for (size_t i = 0; i < browser_action_views_.size(); ++i) { | 254 for (size_t i = 0; i < browser_action_views_.size(); ++i) { |
| 258 if (browser_action_views_[i]->visible()) | 255 if (browser_action_views_[i]->visible()) |
| 259 ++visible_actions; | 256 ++visible_actions; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 284 | 281 |
| 285 void BrowserActionsContainer::OnBrowserActionViewDragDone() { | 282 void BrowserActionsContainer::OnBrowserActionViewDragDone() { |
| 286 // We notify here as well as in OnPerformDrop because the dragged view is | 283 // We notify here as well as in OnPerformDrop because the dragged view is |
| 287 // removed in OnPerformDrop, so it will never get its OnDragDone() call. | 284 // removed in OnPerformDrop, so it will never get its OnDragDone() call. |
| 288 // TODO(devlin): we should see about fixing that. | 285 // TODO(devlin): we should see about fixing that. |
| 289 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, | 286 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, |
| 290 observers_, | 287 observers_, |
| 291 OnBrowserActionDragDone()); | 288 OnBrowserActionDragDone()); |
| 292 } | 289 } |
| 293 | 290 |
| 291 views::View* BrowserActionsContainer::GetOverflowReferenceView() { |
| 292 // We should only need an overflow reference when using the traditional |
| 293 // chevron overflow. |
| 294 DCHECK(chevron_); |
| 295 return chevron_; |
| 296 } |
| 297 |
| 298 void BrowserActionsContainer::SetPopupOwner(BrowserActionButton* popup_owner) { |
| 299 // We should never be setting a popup owner when one already exists. |
| 300 DCHECK(!popup_owner_ || !popup_owner); |
| 301 popup_owner_ = popup_owner; |
| 302 } |
| 303 |
| 304 void BrowserActionsContainer::HideActivePopup() { |
| 305 if (popup_owner_) |
| 306 popup_owner_->HidePopup(); |
| 307 } |
| 308 |
| 309 extensions::ExtensionToolbarModel* BrowserActionsContainer::GetModel() { |
| 310 return model_; |
| 311 } |
| 312 |
| 294 void BrowserActionsContainer::AddObserver( | 313 void BrowserActionsContainer::AddObserver( |
| 295 BrowserActionsContainerObserver* observer) { | 314 BrowserActionsContainerObserver* observer) { |
| 296 observers_.AddObserver(observer); | 315 observers_.AddObserver(observer); |
| 297 } | 316 } |
| 298 | 317 |
| 299 void BrowserActionsContainer::RemoveObserver( | 318 void BrowserActionsContainer::RemoveObserver( |
| 300 BrowserActionsContainerObserver* observer) { | 319 BrowserActionsContainerObserver* observer) { |
| 301 observers_.RemoveObserver(observer); | 320 observers_.RemoveObserver(observer); |
| 302 } | 321 } |
| 303 | 322 |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 observers_, | 651 observers_, |
| 633 OnBrowserActionsContainerAnimationEnded()); | 652 OnBrowserActionsContainerAnimationEnded()); |
| 634 } | 653 } |
| 635 | 654 |
| 636 void BrowserActionsContainer::NotifyMenuDeleted( | 655 void BrowserActionsContainer::NotifyMenuDeleted( |
| 637 BrowserActionOverflowMenuController* controller) { | 656 BrowserActionOverflowMenuController* controller) { |
| 638 DCHECK_EQ(overflow_menu_, controller); | 657 DCHECK_EQ(overflow_menu_, controller); |
| 639 overflow_menu_ = NULL; | 658 overflow_menu_ = NULL; |
| 640 } | 659 } |
| 641 | 660 |
| 642 void BrowserActionsContainer::OnWidgetDestroying(views::Widget* widget) { | |
| 643 DCHECK_EQ(popup_->GetWidget(), widget); | |
| 644 popup_->GetWidget()->RemoveObserver(this); | |
| 645 popup_ = NULL; | |
| 646 // |popup_button_| is NULL if the extension has been removed. | |
| 647 if (popup_button_) { | |
| 648 popup_button_->SetButtonNotPushed(); | |
| 649 popup_button_ = NULL; | |
| 650 } | |
| 651 } | |
| 652 | |
| 653 void BrowserActionsContainer::InspectPopup(ExtensionAction* action) { | |
| 654 BrowserActionView* view = GetBrowserActionView(action); | |
| 655 ShowPopup(view->button(), ExtensionPopup::SHOW_AND_INSPECT, true); | |
| 656 } | |
| 657 | |
| 658 int BrowserActionsContainer::GetCurrentTabId() const { | 661 int BrowserActionsContainer::GetCurrentTabId() const { |
| 659 content::WebContents* active_tab = | 662 content::WebContents* active_tab = |
| 660 browser_->tab_strip_model()->GetActiveWebContents(); | 663 browser_->tab_strip_model()->GetActiveWebContents(); |
| 661 if (!active_tab) | 664 if (!active_tab) |
| 662 return -1; | 665 return -1; |
| 663 | 666 |
| 664 return SessionTabHelper::FromWebContents(active_tab)->session_id().id(); | 667 return SessionTabHelper::FromWebContents(active_tab)->session_id().id(); |
| 665 } | 668 } |
| 666 | 669 |
| 667 void BrowserActionsContainer::OnBrowserActionExecuted( | |
| 668 BrowserActionButton* button) { | |
| 669 ShowPopup(button, ExtensionPopup::SHOW, true); | |
| 670 } | |
| 671 | |
| 672 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() { | 670 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() { |
| 673 SetVisible(!browser_action_views_.empty()); | 671 SetVisible(!browser_action_views_.empty()); |
| 674 if (owner_view_) { | 672 if (owner_view_) { |
| 675 owner_view_->Layout(); | 673 owner_view_->Layout(); |
| 676 owner_view_->SchedulePaint(); | 674 owner_view_->SchedulePaint(); |
| 677 } | 675 } |
| 678 } | 676 } |
| 679 | 677 |
| 680 extensions::ActiveTabPermissionGranter* | 678 extensions::ActiveTabPermissionGranter* |
| 681 BrowserActionsContainer::GetActiveTabPermissionGranter() { | 679 BrowserActionsContainer::GetActiveTabPermissionGranter() { |
| 682 content::WebContents* web_contents = | 680 content::WebContents* web_contents = |
| 683 browser_->tab_strip_model()->GetActiveWebContents(); | 681 browser_->tab_strip_model()->GetActiveWebContents(); |
| 684 if (!web_contents) | 682 if (!web_contents) |
| 685 return NULL; | 683 return NULL; |
| 686 return extensions::TabHelper::FromWebContents(web_contents)-> | 684 return extensions::TabHelper::FromWebContents(web_contents)-> |
| 687 active_tab_permission_granter(); | 685 active_tab_permission_granter(); |
| 688 } | 686 } |
| 689 | 687 |
| 690 void BrowserActionsContainer::MoveBrowserAction(const std::string& extension_id, | 688 void BrowserActionsContainer::MoveBrowserAction(const std::string& extension_id, |
| 691 size_t new_index) { | 689 size_t new_index) { |
| 692 ExtensionService* service = | 690 const Extension* extension = extensions::ExtensionRegistry::Get(profile_)-> |
| 693 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 691 enabled_extensions().GetByID(extension_id); |
| 694 if (service) { | 692 model_->MoveBrowserAction(extension, new_index); |
| 695 const Extension* extension = service->GetExtensionById(extension_id, false); | 693 SchedulePaint(); |
| 696 model_->MoveBrowserAction(extension, new_index); | |
| 697 SchedulePaint(); | |
| 698 } | |
| 699 } | |
| 700 | |
| 701 bool BrowserActionsContainer::ShowPopup(const extensions::Extension* extension, | |
| 702 bool should_grant) { | |
| 703 // Do not override other popups and only show in active window. The window | |
| 704 // must also have a toolbar, otherwise it should not be showing popups. | |
| 705 // TODO(justinlin): Remove toolbar check when http://crbug.com/308645 is | |
| 706 // fixed. | |
| 707 if (popup_ || | |
| 708 !browser_->window()->IsActive() || | |
| 709 !browser_->window()->IsToolbarVisible()) { | |
| 710 return false; | |
| 711 } | |
| 712 | |
| 713 for (BrowserActionViews::iterator it = browser_action_views_.begin(); | |
| 714 it != browser_action_views_.end(); ++it) { | |
| 715 BrowserActionButton* button = (*it)->button(); | |
| 716 if (button && button->extension() == extension) | |
| 717 return ShowPopup(button, ExtensionPopup::SHOW, should_grant); | |
| 718 } | |
| 719 return false; | |
| 720 } | 694 } |
| 721 | 695 |
| 722 size_t BrowserActionsContainer::GetFirstVisibleIconIndex() const { | 696 size_t BrowserActionsContainer::GetFirstVisibleIconIndex() const { |
| 723 return in_overflow_mode() ? model_->GetVisibleIconCount() : 0; | 697 return in_overflow_mode() ? model_->GetVisibleIconCount() : 0; |
| 724 } | 698 } |
| 725 | 699 |
| 726 void BrowserActionsContainer::HidePopup() { | 700 ExtensionPopup* BrowserActionsContainer::TestGetPopup() { |
| 727 // Remove this as an observer and clear |popup_| and |popup_button_| here, | 701 return popup_owner_ ? popup_owner_->popup() : NULL; |
| 728 // since we might change them before OnWidgetDestroying() gets called. | |
| 729 if (popup_) { | |
| 730 popup_->GetWidget()->RemoveObserver(this); | |
| 731 popup_->GetWidget()->Close(); | |
| 732 popup_ = NULL; | |
| 733 } | |
| 734 if (popup_button_) { | |
| 735 popup_button_->SetButtonNotPushed(); | |
| 736 popup_button_ = NULL; | |
| 737 } | |
| 738 } | |
| 739 | |
| 740 void BrowserActionsContainer::TestExecuteBrowserAction(int index) { | |
| 741 BrowserActionButton* button = browser_action_views_[index]->button(); | |
| 742 OnBrowserActionExecuted(button); | |
| 743 } | 702 } |
| 744 | 703 |
| 745 void BrowserActionsContainer::TestSetIconVisibilityCount(size_t icons) { | 704 void BrowserActionsContainer::TestSetIconVisibilityCount(size_t icons) { |
| 746 model_->SetVisibleIconCount(icons); | 705 model_->SetVisibleIconCount(icons); |
| 747 chevron_->SetVisible(icons < browser_action_views_.size()); | 706 chevron_->SetVisible(icons < browser_action_views_.size()); |
| 748 container_width_ = IconCountToWidth(icons, chevron_->visible()); | 707 container_width_ = IconCountToWidth(icons, chevron_->visible()); |
| 749 Layout(); | 708 Layout(); |
| 750 SchedulePaint(); | 709 SchedulePaint(); |
| 751 } | 710 } |
| 752 | 711 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 876 SaveDesiredSizeAndAnimate(gfx::Tween::LINEAR, visible_actions + 1); | 835 SaveDesiredSizeAndAnimate(gfx::Tween::LINEAR, visible_actions + 1); |
| 877 } else { | 836 } else { |
| 878 // Just redraw the (possibly modified) visible icon set. | 837 // Just redraw the (possibly modified) visible icon set. |
| 879 OnBrowserActionVisibilityChanged(); | 838 OnBrowserActionVisibilityChanged(); |
| 880 } | 839 } |
| 881 } | 840 } |
| 882 | 841 |
| 883 void BrowserActionsContainer::BrowserActionRemoved(const Extension* extension) { | 842 void BrowserActionsContainer::BrowserActionRemoved(const Extension* extension) { |
| 884 CloseOverflowMenu(); | 843 CloseOverflowMenu(); |
| 885 | 844 |
| 886 if (popup_ && popup_->host()->extension() == extension) | |
| 887 HidePopup(); | |
| 888 | |
| 889 size_t visible_actions = VisibleBrowserActionsAfterAnimation(); | 845 size_t visible_actions = VisibleBrowserActionsAfterAnimation(); |
| 890 for (BrowserActionViews::iterator i(browser_action_views_.begin()); | 846 for (BrowserActionViews::iterator i(browser_action_views_.begin()); |
| 891 i != browser_action_views_.end(); ++i) { | 847 i != browser_action_views_.end(); ++i) { |
| 892 if ((*i)->button()->extension() == extension) { | 848 if ((*i)->button()->extension() == extension) { |
| 893 delete *i; | 849 delete *i; |
| 894 browser_action_views_.erase(i); | 850 browser_action_views_.erase(i); |
| 895 | 851 |
| 896 // If the extension is being upgraded we don't want the bar to shrink | 852 // If the extension is being upgraded we don't want the bar to shrink |
| 897 // because the icon is just going to get re-added to the same location. | 853 // because the icon is just going to get re-added to the same location. |
| 898 if (extensions::ExtensionSystem::Get(profile_)->runtime_data()-> | 854 if (extensions::ExtensionSystem::Get(profile_)->runtime_data()-> |
| (...skipping 29 matching lines...) Expand all Loading... |
| 928 | 884 |
| 929 DCHECK(index >= 0 && index < static_cast<int>(browser_action_views_.size())); | 885 DCHECK(index >= 0 && index < static_cast<int>(browser_action_views_.size())); |
| 930 | 886 |
| 931 DeleteBrowserActionViews(); | 887 DeleteBrowserActionViews(); |
| 932 CreateBrowserActionViews(); | 888 CreateBrowserActionViews(); |
| 933 Layout(); | 889 Layout(); |
| 934 SchedulePaint(); | 890 SchedulePaint(); |
| 935 } | 891 } |
| 936 | 892 |
| 937 bool BrowserActionsContainer::BrowserActionShowPopup( | 893 bool BrowserActionsContainer::BrowserActionShowPopup( |
| 938 const extensions::Extension* extension) { | 894 const Extension* extension) { |
| 939 return ShowPopup(extension, false); | 895 return ShowPopupForExtension(extension, false, false); |
| 940 } | 896 } |
| 941 | 897 |
| 942 void BrowserActionsContainer::VisibleCountChanged() { | 898 void BrowserActionsContainer::VisibleCountChanged() { |
| 943 SetContainerWidth(); | 899 SetContainerWidth(); |
| 944 } | 900 } |
| 945 | 901 |
| 946 void BrowserActionsContainer::HighlightModeChanged(bool is_highlighting) { | 902 void BrowserActionsContainer::HighlightModeChanged(bool is_highlighting) { |
| 947 // The visual highlighting is done in OnPaint(). It's a bit of a pain that | 903 // The visual highlighting is done in OnPaint(). It's a bit of a pain that |
| 948 // we delete and recreate everything here, but that's how it's done in | 904 // we delete and recreate everything here, but that's how it's done in |
| 949 // BrowserActionMoved(), too. If we want to optimize it, we could move the | 905 // BrowserActionMoved(), too. If we want to optimize it, we could move the |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1075 } | 1031 } |
| 1076 } | 1032 } |
| 1077 | 1033 |
| 1078 bool BrowserActionsContainer::ShouldDisplayBrowserAction( | 1034 bool BrowserActionsContainer::ShouldDisplayBrowserAction( |
| 1079 const Extension* extension) { | 1035 const Extension* extension) { |
| 1080 // Only display incognito-enabled extensions while in incognito mode. | 1036 // Only display incognito-enabled extensions while in incognito mode. |
| 1081 return !profile_->IsOffTheRecord() || | 1037 return !profile_->IsOffTheRecord() || |
| 1082 extensions::util::IsIncognitoEnabled(extension->id(), profile_); | 1038 extensions::util::IsIncognitoEnabled(extension->id(), profile_); |
| 1083 } | 1039 } |
| 1084 | 1040 |
| 1085 bool BrowserActionsContainer::ShowPopup( | 1041 bool BrowserActionsContainer::ShowPopupForExtension( |
| 1086 BrowserActionButton* button, | 1042 const extensions::Extension* extension, |
| 1087 ExtensionPopup::ShowAction show_action, | 1043 bool grant_tab_permissions, |
| 1088 bool should_grant) { | 1044 bool can_override) { |
| 1089 const Extension* extension = button->extension(); | 1045 // If the popup cannot override other views, then no other popups can be |
| 1090 GURL popup_url; | 1046 // showing, and it must be shown in the active widow with a visible toolbar. |
| 1091 if (model_->ExecuteBrowserAction( | 1047 // TODO(justinlin): Remove toolbar check when http://crbug.com/308645 is |
| 1092 extension, browser_, &popup_url, should_grant) != | 1048 // fixed. |
| 1093 extensions::ExtensionToolbarModel::ACTION_SHOW_POPUP) { | 1049 if (!can_override && |
| 1050 (popup_owner_ || |
| 1051 !browser_->window()->IsActive() || |
| 1052 !browser_->window()->IsToolbarVisible())) { |
| 1094 return false; | 1053 return false; |
| 1095 } | 1054 } |
| 1096 | 1055 |
| 1097 // If we're showing the same popup, just hide it and return. | 1056 for (BrowserActionViews::iterator iter = browser_action_views_.begin(); |
| 1098 bool same_showing = popup_ && button == popup_button_; | 1057 iter != browser_action_views_.end(); ++iter) { |
| 1099 | 1058 BrowserActionButton* button = (*iter)->button(); |
| 1100 // Always hide the current popup, even if it's not the same. | 1059 if (button->extension() == extension) |
| 1101 // Only one popup should be visible at a time. | 1060 return button->ShowPopup(ExtensionPopup::SHOW, grant_tab_permissions); |
| 1102 HidePopup(); | 1061 } |
| 1103 | 1062 return false; |
| 1104 if (same_showing) | |
| 1105 return false; | |
| 1106 | |
| 1107 // We can get the execute event for browser actions that are not visible, | |
| 1108 // since buttons can be activated from the overflow menu (chevron). In that | |
| 1109 // case we show the popup as originating from the chevron. | |
| 1110 View* reference_view = button->parent()->visible() ? button : chevron_; | |
| 1111 popup_ = ExtensionPopup::ShowPopup(popup_url, browser_, reference_view, | |
| 1112 views::BubbleBorder::TOP_RIGHT, | |
| 1113 show_action); | |
| 1114 popup_->GetWidget()->AddObserver(this); | |
| 1115 popup_button_ = button; | |
| 1116 | |
| 1117 // Only set button as pushed if it was triggered by a user click. | |
| 1118 if (should_grant) | |
| 1119 popup_button_->SetButtonPushed(); | |
| 1120 return true; | |
| 1121 } | 1063 } |
| OLD | NEW |