Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Side by Side Diff: chrome/browser/ui/views/toolbar/browser_actions_container.cc

Issue 419023002: Move ShowPopup logic from BrowserActionsContainer to BrowserActionView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 // BrowserActionsContainer 106 // BrowserActionsContainer
107 107
108 BrowserActionsContainer::BrowserActionsContainer( 108 BrowserActionsContainer::BrowserActionsContainer(
109 Browser* browser, 109 Browser* browser,
110 View* owner_view, 110 View* owner_view,
111 BrowserActionsContainer* main_container) 111 BrowserActionsContainer* main_container)
112 : profile_(browser->profile()), 112 : profile_(browser->profile()),
113 browser_(browser), 113 browser_(browser),
114 owner_view_(owner_view), 114 owner_view_(owner_view),
115 main_container_(main_container), 115 main_container_(main_container),
116 popup_(NULL), 116 popup_owner_(NULL),
117 popup_button_(NULL),
118 model_(NULL), 117 model_(NULL),
119 container_width_(0), 118 container_width_(0),
120 resize_area_(NULL), 119 resize_area_(NULL),
121 chevron_(NULL), 120 chevron_(NULL),
122 overflow_menu_(NULL), 121 overflow_menu_(NULL),
123 suppress_chevron_(false), 122 suppress_chevron_(false),
124 resize_amount_(0), 123 resize_amount_(0),
125 animation_target_size_(0), 124 animation_target_size_(0),
126 drop_indicator_position_(-1), 125 drop_indicator_position_(-1),
127 task_factory_(this), 126 task_factory_(this),
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 BrowserActionsContainer::~BrowserActionsContainer() { 163 BrowserActionsContainer::~BrowserActionsContainer() {
165 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, 164 FOR_EACH_OBSERVER(BrowserActionsContainerObserver,
166 observers_, 165 observers_,
167 OnBrowserActionsContainerDestroyed()); 166 OnBrowserActionsContainerDestroyed());
168 167
169 if (overflow_menu_) 168 if (overflow_menu_)
170 overflow_menu_->set_observer(NULL); 169 overflow_menu_->set_observer(NULL);
171 if (model_) 170 if (model_)
172 model_->RemoveObserver(this); 171 model_->RemoveObserver(this);
173 StopShowFolderDropMenuTimer(); 172 StopShowFolderDropMenuTimer();
174 if (popup_) 173 HideActivePopup();
175 popup_->GetWidget()->RemoveObserver(this);
176 HidePopup();
177 DeleteBrowserActionViews(); 174 DeleteBrowserActionViews();
178 } 175 }
179 176
180 void BrowserActionsContainer::Init() { 177 void BrowserActionsContainer::Init() {
181 LoadImages(); 178 LoadImages();
182 179
183 // We wait to set the container width until now so that the chevron images 180 // We wait to set the container width until now so that the chevron images
184 // will be loaded. The width calculation needs to know the chevron size. 181 // will be loaded. The width calculation needs to know the chevron size.
185 if (model_ && 182 if (model_ &&
186 !profile_->GetPrefs()->HasPrefPath( 183 !profile_->GetPrefs()->HasPrefPath(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 if (!ShouldDisplayBrowserAction(i->get())) 219 if (!ShouldDisplayBrowserAction(i->get()))
223 continue; 220 continue;
224 221
225 BrowserActionView* view = new BrowserActionView(i->get(), browser_, this); 222 BrowserActionView* view = new BrowserActionView(i->get(), browser_, this);
226 browser_action_views_.push_back(view); 223 browser_action_views_.push_back(view);
227 AddChildView(view); 224 AddChildView(view);
228 } 225 }
229 } 226 }
230 227
231 void BrowserActionsContainer::DeleteBrowserActionViews() { 228 void BrowserActionsContainer::DeleteBrowserActionViews() {
232 HidePopup(); 229 HideActivePopup();
233 if (overflow_menu_) 230 if (overflow_menu_)
234 overflow_menu_->NotifyBrowserActionViewsDeleting(); 231 overflow_menu_->NotifyBrowserActionViewsDeleting();
235 STLDeleteElements(&browser_action_views_); 232 STLDeleteElements(&browser_action_views_);
236 } 233 }
237 234
238 size_t BrowserActionsContainer::VisibleBrowserActions() const { 235 size_t BrowserActionsContainer::VisibleBrowserActions() const {
239 size_t visible_actions = 0; 236 size_t visible_actions = 0;
240 for (size_t i = 0; i < browser_action_views_.size(); ++i) { 237 for (size_t i = 0; i < browser_action_views_.size(); ++i) {
241 if (browser_action_views_[i]->visible()) 238 if (browser_action_views_[i]->visible())
242 ++visible_actions; 239 ++visible_actions;
(...skipping 24 matching lines...) Expand all
267 264
268 void BrowserActionsContainer::OnBrowserActionViewDragDone() { 265 void BrowserActionsContainer::OnBrowserActionViewDragDone() {
269 // We notify here as well as in OnPerformDrop because the dragged view is 266 // We notify here as well as in OnPerformDrop because the dragged view is
270 // removed in OnPerformDrop, so it will never get its OnDragDone() call. 267 // removed in OnPerformDrop, so it will never get its OnDragDone() call.
271 // TODO(devlin): we should see about fixing that. 268 // TODO(devlin): we should see about fixing that.
272 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, 269 FOR_EACH_OBSERVER(BrowserActionsContainerObserver,
273 observers_, 270 observers_,
274 OnBrowserActionDragDone()); 271 OnBrowserActionDragDone());
275 } 272 }
276 273
274 views::View* BrowserActionsContainer::GetOverflowReferenceView() {
275 // We should only need an overflow reference when using the traditional
276 // chevron overflow.
277 DCHECK(chevron_);
278 return chevron_;
279 }
280
281 void BrowserActionsContainer::SetPopupOwner(BrowserActionButton* popup_owner) {
282 // We should never be setting a popup owner when one already exists.
283 DCHECK(!popup_owner_);
284 popup_owner_ = popup_owner;
285 }
286
287 void BrowserActionsContainer::HideActivePopup() {
288 if (popup_owner_)
289 popup_owner_->HidePopup();
290 }
291
292 extensions::ExtensionToolbarModel* BrowserActionsContainer::GetModel() {
293 return model_;
294 }
295
277 void BrowserActionsContainer::AddObserver( 296 void BrowserActionsContainer::AddObserver(
278 BrowserActionsContainerObserver* observer) { 297 BrowserActionsContainerObserver* observer) {
279 observers_.AddObserver(observer); 298 observers_.AddObserver(observer);
280 } 299 }
281 300
282 void BrowserActionsContainer::RemoveObserver( 301 void BrowserActionsContainer::RemoveObserver(
283 BrowserActionsContainerObserver* observer) { 302 BrowserActionsContainerObserver* observer) {
284 observers_.RemoveObserver(observer); 303 observers_.RemoveObserver(observer);
285 } 304 }
286 305
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 observers_, 622 observers_,
604 OnBrowserActionsContainerAnimationEnded()); 623 OnBrowserActionsContainerAnimationEnded());
605 } 624 }
606 625
607 void BrowserActionsContainer::NotifyMenuDeleted( 626 void BrowserActionsContainer::NotifyMenuDeleted(
608 BrowserActionOverflowMenuController* controller) { 627 BrowserActionOverflowMenuController* controller) {
609 DCHECK_EQ(overflow_menu_, controller); 628 DCHECK_EQ(overflow_menu_, controller);
610 overflow_menu_ = NULL; 629 overflow_menu_ = NULL;
611 } 630 }
612 631
613 void BrowserActionsContainer::OnWidgetDestroying(views::Widget* widget) {
614 DCHECK_EQ(popup_->GetWidget(), widget);
615 popup_->GetWidget()->RemoveObserver(this);
616 popup_ = NULL;
617 // |popup_button_| is NULL if the extension has been removed.
618 if (popup_button_) {
619 popup_button_->SetButtonNotPushed();
620 popup_button_ = NULL;
621 }
622 }
623
624 void BrowserActionsContainer::InspectPopup(ExtensionAction* action) {
625 BrowserActionView* view = GetBrowserActionView(action);
626 ShowPopup(view->button(), ExtensionPopup::SHOW_AND_INSPECT, true);
627 }
628
629 int BrowserActionsContainer::GetCurrentTabId() const { 632 int BrowserActionsContainer::GetCurrentTabId() const {
630 content::WebContents* active_tab = 633 content::WebContents* active_tab =
631 browser_->tab_strip_model()->GetActiveWebContents(); 634 browser_->tab_strip_model()->GetActiveWebContents();
632 if (!active_tab) 635 if (!active_tab)
633 return -1; 636 return -1;
634 637
635 return SessionTabHelper::FromWebContents(active_tab)->session_id().id(); 638 return SessionTabHelper::FromWebContents(active_tab)->session_id().id();
636 } 639 }
637 640
638 void BrowserActionsContainer::OnBrowserActionExecuted(
639 BrowserActionButton* button) {
640 ShowPopup(button, ExtensionPopup::SHOW, true);
641 }
642
643 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() { 641 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() {
644 SetVisible(!browser_action_views_.empty()); 642 SetVisible(!browser_action_views_.empty());
645 if (owner_view_) { 643 if (owner_view_) {
646 owner_view_->Layout(); 644 owner_view_->Layout();
647 owner_view_->SchedulePaint(); 645 owner_view_->SchedulePaint();
648 } 646 }
649 } 647 }
650 648
651 extensions::ActiveTabPermissionGranter* 649 extensions::ActiveTabPermissionGranter*
652 BrowserActionsContainer::GetActiveTabPermissionGranter() { 650 BrowserActionsContainer::GetActiveTabPermissionGranter() {
653 content::WebContents* web_contents = 651 content::WebContents* web_contents =
654 browser_->tab_strip_model()->GetActiveWebContents(); 652 browser_->tab_strip_model()->GetActiveWebContents();
655 if (!web_contents) 653 if (!web_contents)
656 return NULL; 654 return NULL;
657 return extensions::TabHelper::FromWebContents(web_contents)-> 655 return extensions::TabHelper::FromWebContents(web_contents)->
658 active_tab_permission_granter(); 656 active_tab_permission_granter();
659 } 657 }
660 658
661 void BrowserActionsContainer::MoveBrowserAction(const std::string& extension_id, 659 void BrowserActionsContainer::MoveBrowserAction(const std::string& extension_id,
662 size_t new_index) { 660 size_t new_index) {
663 ExtensionService* service = 661 const Extension* extension = extensions::ExtensionRegistry::Get(profile_)
664 extensions::ExtensionSystem::Get(profile_)->extension_service(); 662 ->enabled_extensions().GetByID(extension_id);
Peter Kasting 2014/07/26 02:33:20 Nit: See prior nit about -> wrapping
Devlin 2014/07/29 19:07:15 Done.
665 if (service) { 663 model_->MoveBrowserAction(extension, new_index);
666 const Extension* extension = service->GetExtensionById(extension_id, false); 664 SchedulePaint();
667 model_->MoveBrowserAction(extension, new_index);
668 SchedulePaint();
669 }
670 } 665 }
671 666
672 bool BrowserActionsContainer::ShowPopup(const extensions::Extension* extension, 667 ExtensionPopup* BrowserActionsContainer::TestGetPopup() {
673 bool should_grant) { 668 return popup_owner_ ? popup_owner_->popup() : NULL;
674 // Do not override other popups and only show in active window. The window
675 // must also have a toolbar, otherwise it should not be showing popups.
676 // TODO(justinlin): Remove toolbar check when http://crbug.com/308645 is
677 // fixed.
678 if (popup_ ||
679 !browser_->window()->IsActive() ||
680 !browser_->window()->IsToolbarVisible()) {
681 return false;
682 }
683
684 for (BrowserActionViews::iterator it = browser_action_views_.begin();
685 it != browser_action_views_.end(); ++it) {
686 BrowserActionButton* button = (*it)->button();
687 if (button && button->extension() == extension)
688 return ShowPopup(button, ExtensionPopup::SHOW, should_grant);
689 }
690 return false;
691 }
692
693 void BrowserActionsContainer::HidePopup() {
694 // Remove this as an observer and clear |popup_| and |popup_button_| here,
695 // since we might change them before OnWidgetDestroying() gets called.
696 if (popup_) {
697 popup_->GetWidget()->RemoveObserver(this);
698 popup_->GetWidget()->Close();
699 popup_ = NULL;
700 }
701 if (popup_button_) {
702 popup_button_->SetButtonNotPushed();
703 popup_button_ = NULL;
704 }
705 }
706
707 void BrowserActionsContainer::TestExecuteBrowserAction(int index) {
708 BrowserActionButton* button = browser_action_views_[index]->button();
709 OnBrowserActionExecuted(button);
710 } 669 }
711 670
712 void BrowserActionsContainer::TestSetIconVisibilityCount(size_t icons) { 671 void BrowserActionsContainer::TestSetIconVisibilityCount(size_t icons) {
713 model_->SetVisibleIconCount(icons); 672 model_->SetVisibleIconCount(icons);
714 chevron_->SetVisible(icons < browser_action_views_.size()); 673 chevron_->SetVisible(icons < browser_action_views_.size());
715 container_width_ = IconCountToWidth(icons, chevron_->visible()); 674 container_width_ = IconCountToWidth(icons, chevron_->visible());
716 Layout(); 675 Layout();
717 SchedulePaint(); 676 SchedulePaint();
718 } 677 }
719 678
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 SaveDesiredSizeAndAnimate(gfx::Tween::LINEAR, visible_actions + 1); 780 SaveDesiredSizeAndAnimate(gfx::Tween::LINEAR, visible_actions + 1);
822 } else { 781 } else {
823 // Just redraw the (possibly modified) visible icon set. 782 // Just redraw the (possibly modified) visible icon set.
824 OnBrowserActionVisibilityChanged(); 783 OnBrowserActionVisibilityChanged();
825 } 784 }
826 } 785 }
827 786
828 void BrowserActionsContainer::BrowserActionRemoved(const Extension* extension) { 787 void BrowserActionsContainer::BrowserActionRemoved(const Extension* extension) {
829 CloseOverflowMenu(); 788 CloseOverflowMenu();
830 789
831 if (popup_ && popup_->host()->extension() == extension)
832 HidePopup();
833
834 size_t visible_actions = VisibleBrowserActionsAfterAnimation(); 790 size_t visible_actions = VisibleBrowserActionsAfterAnimation();
835 for (BrowserActionViews::iterator i(browser_action_views_.begin()); 791 for (BrowserActionViews::iterator i(browser_action_views_.begin());
836 i != browser_action_views_.end(); ++i) { 792 i != browser_action_views_.end(); ++i) {
837 if ((*i)->button()->extension() == extension) { 793 if ((*i)->button()->extension() == extension) {
838 delete *i; 794 delete *i;
839 browser_action_views_.erase(i); 795 browser_action_views_.erase(i);
840 796
841 // If the extension is being upgraded we don't want the bar to shrink 797 // If the extension is being upgraded we don't want the bar to shrink
842 // because the icon is just going to get re-added to the same location. 798 // because the icon is just going to get re-added to the same location.
843 if (extensions::ExtensionSystem::Get(profile_)->runtime_data()-> 799 if (extensions::ExtensionSystem::Get(profile_)->runtime_data()->
(...skipping 28 matching lines...) Expand all
872 index = model_->OriginalIndexToIncognito(index); 828 index = model_->OriginalIndexToIncognito(index);
873 829
874 DCHECK(index >= 0 && index < static_cast<int>(browser_action_views_.size())); 830 DCHECK(index >= 0 && index < static_cast<int>(browser_action_views_.size()));
875 831
876 DeleteBrowserActionViews(); 832 DeleteBrowserActionViews();
877 CreateBrowserActionViews(); 833 CreateBrowserActionViews();
878 Layout(); 834 Layout();
879 SchedulePaint(); 835 SchedulePaint();
880 } 836 }
881 837
882 bool BrowserActionsContainer::BrowserActionShowPopup(
883 const extensions::Extension* extension) {
884 return ShowPopup(extension, false);
885 }
886
887 void BrowserActionsContainer::VisibleCountChanged() { 838 void BrowserActionsContainer::VisibleCountChanged() {
888 SetContainerWidth(); 839 SetContainerWidth();
889 } 840 }
890 841
891 void BrowserActionsContainer::HighlightModeChanged(bool is_highlighting) { 842 void BrowserActionsContainer::HighlightModeChanged(bool is_highlighting) {
892 // The visual highlighting is done in OnPaint(). It's a bit of a pain that 843 // The visual highlighting is done in OnPaint(). It's a bit of a pain that
893 // we delete and recreate everything here, but that's how it's done in 844 // we delete and recreate everything here, but that's how it's done in
894 // BrowserActionMoved(), too. If we want to optimize it, we could move the 845 // BrowserActionMoved(), too. If we want to optimize it, we could move the
895 // existing icons, instead of deleting it all. 846 // existing icons, instead of deleting it all.
896 DeleteBrowserActionViews(); 847 DeleteBrowserActionViews();
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 } 978 }
1028 } 979 }
1029 980
1030 bool BrowserActionsContainer::ShouldDisplayBrowserAction( 981 bool BrowserActionsContainer::ShouldDisplayBrowserAction(
1031 const Extension* extension) { 982 const Extension* extension) {
1032 // Only display incognito-enabled extensions while in incognito mode. 983 // Only display incognito-enabled extensions while in incognito mode.
1033 return !profile_->IsOffTheRecord() || 984 return !profile_->IsOffTheRecord() ||
1034 extensions::util::IsIncognitoEnabled(extension->id(), profile_); 985 extensions::util::IsIncognitoEnabled(extension->id(), profile_);
1035 } 986 }
1036 987
1037 bool BrowserActionsContainer::ShowPopup( 988 bool BrowserActionsContainer::ShowPopupForExtension(
1038 BrowserActionButton* button, 989 const extensions::Extension* extension,
1039 ExtensionPopup::ShowAction show_action, 990 bool grant_tab_permissions,
1040 bool should_grant) { 991 bool can_override) {
1041 const Extension* extension = button->extension(); 992 if (!can_override) {
1042 GURL popup_url; 993 // If the popup cannot override other views, then no other popups can be
Peter Kasting 2014/07/26 02:33:20 Nit: Hoist this comment above the above conditiona
Devlin 2014/07/29 19:07:14 Done.
1043 if (model_->ExecuteBrowserAction( 994 // showing, and it must be shown in the active widow with a visible toolbar.
1044 extension, browser_, &popup_url, should_grant) != 995 // TODO(justinlin): Remove toolbar check when http://crbug.com/308645 is
1045 extensions::ExtensionToolbarModel::ACTION_SHOW_POPUP) { 996 // fixed.
1046 return false; 997 if (popup_owner_ ||
998 !browser_->window()->IsActive() ||
999 !browser_->window()->IsToolbarVisible()) {
1000 return false;
1001 }
1047 } 1002 }
1048 1003
1049 // If we're showing the same popup, just hide it and return. 1004 for (BrowserActionViews::iterator iter = browser_action_views_.begin();
1050 bool same_showing = popup_ && button == popup_button_; 1005 iter != browser_action_views_.end(); ++iter) {
1051 1006 if ((*iter)->button()->extension() == extension)
1052 // Always hide the current popup, even if it's not the same. 1007 return (*iter)->button()->ShowPopup(ExtensionPopup::SHOW,
1053 // Only one popup should be visible at a time. 1008 grant_tab_permissions);
Peter Kasting 2014/07/26 02:33:20 Nit: Same length, but feels a little nicer to me:
Devlin 2014/07/29 19:07:15 Done.
1054 HidePopup(); 1009 }
1055 1010 return false;
1056 if (same_showing)
1057 return false;
1058
1059 // We can get the execute event for browser actions that are not visible,
1060 // since buttons can be activated from the overflow menu (chevron). In that
1061 // case we show the popup as originating from the chevron.
1062 View* reference_view = button->parent()->visible() ? button : chevron_;
1063 popup_ = ExtensionPopup::ShowPopup(popup_url, browser_, reference_view,
1064 views::BubbleBorder::TOP_RIGHT,
1065 show_action);
1066 popup_->GetWidget()->AddObserver(this);
1067 popup_button_ = button;
1068
1069 // Only set button as pushed if it was triggered by a user click.
1070 if (should_grant)
1071 popup_button_->SetButtonPushed();
1072 return true;
1073 } 1011 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698