| 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_util.h" | 10 #include "chrome/browser/extensions/extension_util.h" |
| 11 #include "chrome/browser/extensions/extension_view_host.h" | 11 #include "chrome/browser/extensions/extension_view_host.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" | |
| 15 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/browser_window.h" | 15 #include "chrome/browser/ui/browser_window.h" |
| 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 18 #include "chrome/browser/ui/view_ids.h" | 17 #include "chrome/browser/ui/view_ids.h" |
| 19 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" | 18 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" |
| 20 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views
.h" | 19 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views
.h" |
| 21 #include "chrome/browser/ui/views/extensions/extension_popup.h" | 20 #include "chrome/browser/ui/views/extensions/extension_popup.h" |
| 22 #include "chrome/browser/ui/views/toolbar/browser_actions_container_observer.h" | 21 #include "chrome/browser/ui/views/toolbar/browser_actions_container_observer.h" |
| 23 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 22 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
| 24 #include "chrome/common/extensions/command.h" | 23 #include "chrome/common/extensions/command.h" |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 model_->SetVisibleIconCount(WidthToIconCount(predefined_width)); | 206 model_->SetVisibleIconCount(WidthToIconCount(predefined_width)); |
| 208 } | 207 } |
| 209 if (model_ && model_->extensions_initialized()) | 208 if (model_ && model_->extensions_initialized()) |
| 210 SetContainerWidth(); | 209 SetContainerWidth(); |
| 211 } | 210 } |
| 212 | 211 |
| 213 BrowserActionView* BrowserActionsContainer::GetBrowserActionView( | 212 BrowserActionView* BrowserActionsContainer::GetBrowserActionView( |
| 214 ExtensionAction* action) { | 213 ExtensionAction* action) { |
| 215 for (BrowserActionViews::iterator i(browser_action_views_.begin()); | 214 for (BrowserActionViews::iterator i(browser_action_views_.begin()); |
| 216 i != browser_action_views_.end(); ++i) { | 215 i != browser_action_views_.end(); ++i) { |
| 217 if ((*i)->button()->browser_action() == action) | 216 if ((*i)->button()->extension_action() == action) |
| 218 return *i; | 217 return *i; |
| 219 } | 218 } |
| 220 return NULL; | 219 return NULL; |
| 221 } | 220 } |
| 222 | 221 |
| 223 void BrowserActionsContainer::RefreshBrowserActionViews() { | 222 void BrowserActionsContainer::RefreshBrowserActionViews() { |
| 224 for (size_t i = 0; i < browser_action_views_.size(); ++i) | 223 for (size_t i = 0; i < browser_action_views_.size(); ++i) |
| 225 browser_action_views_[i]->button()->UpdateState(); | 224 browser_action_views_[i]->button()->UpdateState(); |
| 226 } | 225 } |
| 227 | 226 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 } | 295 } |
| 297 | 296 |
| 298 void BrowserActionsContainer::SetPopupOwner(BrowserActionButton* popup_owner) { | 297 void BrowserActionsContainer::SetPopupOwner(BrowserActionButton* popup_owner) { |
| 299 // We should never be setting a popup owner when one already exists. | 298 // We should never be setting a popup owner when one already exists. |
| 300 DCHECK(!popup_owner_ || !popup_owner); | 299 DCHECK(!popup_owner_ || !popup_owner); |
| 301 popup_owner_ = popup_owner; | 300 popup_owner_ = popup_owner; |
| 302 } | 301 } |
| 303 | 302 |
| 304 void BrowserActionsContainer::HideActivePopup() { | 303 void BrowserActionsContainer::HideActivePopup() { |
| 305 if (popup_owner_) | 304 if (popup_owner_) |
| 306 popup_owner_->HidePopup(); | 305 popup_owner_->view_controller()->HidePopup(); |
| 307 } | |
| 308 | |
| 309 extensions::ExtensionToolbarModel* BrowserActionsContainer::GetModel() { | |
| 310 return model_; | |
| 311 } | 306 } |
| 312 | 307 |
| 313 void BrowserActionsContainer::AddObserver( | 308 void BrowserActionsContainer::AddObserver( |
| 314 BrowserActionsContainerObserver* observer) { | 309 BrowserActionsContainerObserver* observer) { |
| 315 observers_.AddObserver(observer); | 310 observers_.AddObserver(observer); |
| 316 } | 311 } |
| 317 | 312 |
| 318 void BrowserActionsContainer::RemoveObserver( | 313 void BrowserActionsContainer::RemoveObserver( |
| 319 BrowserActionsContainerObserver* observer) { | 314 BrowserActionsContainerObserver* observer) { |
| 320 observers_.RemoveObserver(observer); | 315 observers_.RemoveObserver(observer); |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 observers_, | 646 observers_, |
| 652 OnBrowserActionsContainerAnimationEnded()); | 647 OnBrowserActionsContainerAnimationEnded()); |
| 653 } | 648 } |
| 654 | 649 |
| 655 void BrowserActionsContainer::NotifyMenuDeleted( | 650 void BrowserActionsContainer::NotifyMenuDeleted( |
| 656 BrowserActionOverflowMenuController* controller) { | 651 BrowserActionOverflowMenuController* controller) { |
| 657 DCHECK_EQ(overflow_menu_, controller); | 652 DCHECK_EQ(overflow_menu_, controller); |
| 658 overflow_menu_ = NULL; | 653 overflow_menu_ = NULL; |
| 659 } | 654 } |
| 660 | 655 |
| 661 int BrowserActionsContainer::GetCurrentTabId() const { | 656 content::WebContents* BrowserActionsContainer::GetCurrentWebContents() { |
| 662 content::WebContents* active_tab = | 657 return browser_->tab_strip_model()->GetActiveWebContents(); |
| 663 browser_->tab_strip_model()->GetActiveWebContents(); | |
| 664 if (!active_tab) | |
| 665 return -1; | |
| 666 | |
| 667 return SessionTabHelper::FromWebContents(active_tab)->session_id().id(); | |
| 668 } | 658 } |
| 669 | 659 |
| 670 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() { | 660 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() { |
| 671 SetVisible(!browser_action_views_.empty()); | 661 SetVisible(!browser_action_views_.empty()); |
| 672 if (owner_view_) { | 662 if (owner_view_) { |
| 673 owner_view_->Layout(); | 663 owner_view_->Layout(); |
| 674 owner_view_->SchedulePaint(); | 664 owner_view_->SchedulePaint(); |
| 675 } | 665 } |
| 676 } | 666 } |
| 677 | 667 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 691 enabled_extensions().GetByID(extension_id); | 681 enabled_extensions().GetByID(extension_id); |
| 692 model_->MoveBrowserAction(extension, new_index); | 682 model_->MoveBrowserAction(extension, new_index); |
| 693 SchedulePaint(); | 683 SchedulePaint(); |
| 694 } | 684 } |
| 695 | 685 |
| 696 size_t BrowserActionsContainer::GetFirstVisibleIconIndex() const { | 686 size_t BrowserActionsContainer::GetFirstVisibleIconIndex() const { |
| 697 return in_overflow_mode() ? model_->GetVisibleIconCount() : 0; | 687 return in_overflow_mode() ? model_->GetVisibleIconCount() : 0; |
| 698 } | 688 } |
| 699 | 689 |
| 700 ExtensionPopup* BrowserActionsContainer::TestGetPopup() { | 690 ExtensionPopup* BrowserActionsContainer::TestGetPopup() { |
| 701 return popup_owner_ ? popup_owner_->popup() : NULL; | 691 return popup_owner_ ? popup_owner_->view_controller()->popup() : NULL; |
| 702 } | 692 } |
| 703 | 693 |
| 704 void BrowserActionsContainer::TestSetIconVisibilityCount(size_t icons) { | 694 void BrowserActionsContainer::TestSetIconVisibilityCount(size_t icons) { |
| 705 model_->SetVisibleIconCount(icons); | 695 model_->SetVisibleIconCount(icons); |
| 706 chevron_->SetVisible(icons < browser_action_views_.size()); | 696 chevron_->SetVisible(icons < browser_action_views_.size()); |
| 707 container_width_ = IconCountToWidth(icons, chevron_->visible()); | 697 container_width_ = IconCountToWidth(icons, chevron_->visible()); |
| 708 Layout(); | 698 Layout(); |
| 709 SchedulePaint(); | 699 SchedulePaint(); |
| 710 } | 700 } |
| 711 | 701 |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1050 (popup_owner_ || | 1040 (popup_owner_ || |
| 1051 !browser_->window()->IsActive() || | 1041 !browser_->window()->IsActive() || |
| 1052 !browser_->window()->IsToolbarVisible())) { | 1042 !browser_->window()->IsToolbarVisible())) { |
| 1053 return false; | 1043 return false; |
| 1054 } | 1044 } |
| 1055 | 1045 |
| 1056 for (BrowserActionViews::iterator iter = browser_action_views_.begin(); | 1046 for (BrowserActionViews::iterator iter = browser_action_views_.begin(); |
| 1057 iter != browser_action_views_.end(); ++iter) { | 1047 iter != browser_action_views_.end(); ++iter) { |
| 1058 BrowserActionButton* button = (*iter)->button(); | 1048 BrowserActionButton* button = (*iter)->button(); |
| 1059 if (button->extension() == extension) | 1049 if (button->extension() == extension) |
| 1060 return button->ShowPopup(ExtensionPopup::SHOW, grant_tab_permissions); | 1050 return button->view_controller()->ExecuteAction( |
| 1051 ExtensionPopup::SHOW, grant_tab_permissions); |
| 1061 } | 1052 } |
| 1062 return false; | 1053 return false; |
| 1063 } | 1054 } |
| OLD | NEW |