| 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/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
| 10 #include "chrome/browser/extensions/extension_system.h" |
| 10 #include "chrome/browser/extensions/tab_helper.h" | 11 #include "chrome/browser/extensions/tab_helper.h" |
| 11 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/sessions/session_tab_helper.h" | 14 #include "chrome/browser/sessions/session_tab_helper.h" |
| 14 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_tabstrip.h" | 16 #include "chrome/browser/ui/browser_tabstrip.h" |
| 16 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 17 #include "chrome/browser/ui/tab_contents/tab_contents.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" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 chevron_(NULL), | 73 chevron_(NULL), |
| 73 overflow_menu_(NULL), | 74 overflow_menu_(NULL), |
| 74 suppress_chevron_(false), | 75 suppress_chevron_(false), |
| 75 resize_amount_(0), | 76 resize_amount_(0), |
| 76 animation_target_size_(0), | 77 animation_target_size_(0), |
| 77 drop_indicator_position_(-1), | 78 drop_indicator_position_(-1), |
| 78 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), | 79 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), |
| 79 ALLOW_THIS_IN_INITIALIZER_LIST(show_menu_task_factory_(this)) { | 80 ALLOW_THIS_IN_INITIALIZER_LIST(show_menu_task_factory_(this)) { |
| 80 set_id(VIEW_ID_BROWSER_ACTION_TOOLBAR); | 81 set_id(VIEW_ID_BROWSER_ACTION_TOOLBAR); |
| 81 | 82 |
| 82 if (profile_->GetExtensionService()) { | 83 ExtensionService* service = |
| 83 model_ = profile_->GetExtensionService()->toolbar_model(); | 84 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 85 if (service) { |
| 86 model_ = service->toolbar_model(); |
| 84 model_->AddObserver(this); | 87 model_->AddObserver(this); |
| 85 } | 88 } |
| 86 | 89 |
| 87 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews( | 90 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews( |
| 88 browser->profile(), | 91 browser->profile(), |
| 89 owner_view->GetFocusManager(), | 92 owner_view->GetFocusManager(), |
| 90 extensions::ExtensionKeybindingRegistry::ALL_EXTENSIONS, | 93 extensions::ExtensionKeybindingRegistry::ALL_EXTENSIONS, |
| 91 this)), | 94 this)), |
| 92 | 95 |
| 93 resize_animation_.reset(new ui::SlideAnimation(this)); | 96 resize_animation_.reset(new ui::SlideAnimation(this)); |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 BrowserActionsContainer::GetActiveTabPermissionGranter() { | 498 BrowserActionsContainer::GetActiveTabPermissionGranter() { |
| 496 content::WebContents* web_contents = chrome::GetActiveWebContents(browser_); | 499 content::WebContents* web_contents = chrome::GetActiveWebContents(browser_); |
| 497 if (!web_contents) | 500 if (!web_contents) |
| 498 return NULL; | 501 return NULL; |
| 499 return extensions::TabHelper::FromWebContents(web_contents)-> | 502 return extensions::TabHelper::FromWebContents(web_contents)-> |
| 500 active_tab_permission_granter(); | 503 active_tab_permission_granter(); |
| 501 } | 504 } |
| 502 | 505 |
| 503 void BrowserActionsContainer::MoveBrowserAction(const std::string& extension_id, | 506 void BrowserActionsContainer::MoveBrowserAction(const std::string& extension_id, |
| 504 size_t new_index) { | 507 size_t new_index) { |
| 505 ExtensionService* service = profile_->GetExtensionService(); | 508 ExtensionService* service = |
| 509 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 506 if (service) { | 510 if (service) { |
| 507 const Extension* extension = service->GetExtensionById(extension_id, false); | 511 const Extension* extension = service->GetExtensionById(extension_id, false); |
| 508 model_->MoveBrowserAction(extension, new_index); | 512 model_->MoveBrowserAction(extension, new_index); |
| 509 SchedulePaint(); | 513 SchedulePaint(); |
| 510 } | 514 } |
| 511 } | 515 } |
| 512 | 516 |
| 513 void BrowserActionsContainer::HidePopup() { | 517 void BrowserActionsContainer::HidePopup() { |
| 514 // Remove this as an observer and clear |popup_| and |popup_button_| here, | 518 // Remove this as an observer and clear |popup_| and |popup_button_| here, |
| 515 // since we might change them before OnWidgetClosing() gets called. | 519 // since we might change them before OnWidgetClosing() gets called. |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 browser_action_views_.insert(browser_action_views_.begin() + index, view); | 624 browser_action_views_.insert(browser_action_views_.begin() + index, view); |
| 621 AddChildViewAt(view, index); | 625 AddChildViewAt(view, index); |
| 622 | 626 |
| 623 // If we are still initializing the container, don't bother animating. | 627 // If we are still initializing the container, don't bother animating. |
| 624 if (!model_->extensions_initialized()) | 628 if (!model_->extensions_initialized()) |
| 625 return; | 629 return; |
| 626 | 630 |
| 627 // Enlarge the container if it was already at maximum size and we're not in | 631 // Enlarge the container if it was already at maximum size and we're not in |
| 628 // the middle of upgrading. | 632 // the middle of upgrading. |
| 629 if ((model_->GetVisibleIconCount() < 0) && | 633 if ((model_->GetVisibleIconCount() < 0) && |
| 630 !profile_->GetExtensionService()->IsBeingUpgraded(extension)) { | 634 !extensions::ExtensionSystem::Get(profile_)->extension_service()-> |
| 635 IsBeingUpgraded(extension)) { |
| 631 suppress_chevron_ = true; | 636 suppress_chevron_ = true; |
| 632 SaveDesiredSizeAndAnimate(ui::Tween::LINEAR, visible_actions + 1); | 637 SaveDesiredSizeAndAnimate(ui::Tween::LINEAR, visible_actions + 1); |
| 633 } else { | 638 } else { |
| 634 // Just redraw the (possibly modified) visible icon set. | 639 // Just redraw the (possibly modified) visible icon set. |
| 635 OnBrowserActionVisibilityChanged(); | 640 OnBrowserActionVisibilityChanged(); |
| 636 } | 641 } |
| 637 } | 642 } |
| 638 | 643 |
| 639 void BrowserActionsContainer::BrowserActionRemoved(const Extension* extension) { | 644 void BrowserActionsContainer::BrowserActionRemoved(const Extension* extension) { |
| 640 CloseOverflowMenu(); | 645 CloseOverflowMenu(); |
| 641 | 646 |
| 642 if (popup_ && popup_->host()->extension() == extension) | 647 if (popup_ && popup_->host()->extension() == extension) |
| 643 HidePopup(); | 648 HidePopup(); |
| 644 | 649 |
| 645 size_t visible_actions = VisibleBrowserActions(); | 650 size_t visible_actions = VisibleBrowserActions(); |
| 646 for (BrowserActionViews::iterator i(browser_action_views_.begin()); | 651 for (BrowserActionViews::iterator i(browser_action_views_.begin()); |
| 647 i != browser_action_views_.end(); ++i) { | 652 i != browser_action_views_.end(); ++i) { |
| 648 if ((*i)->button()->extension() == extension) { | 653 if ((*i)->button()->extension() == extension) { |
| 649 delete *i; | 654 delete *i; |
| 650 browser_action_views_.erase(i); | 655 browser_action_views_.erase(i); |
| 651 | 656 |
| 652 // If the extension is being upgraded we don't want the bar to shrink | 657 // If the extension is being upgraded we don't want the bar to shrink |
| 653 // because the icon is just going to get re-added to the same location. | 658 // because the icon is just going to get re-added to the same location. |
| 654 if (profile_->GetExtensionService()->IsBeingUpgraded(extension)) | 659 if (extensions::ExtensionSystem::Get(profile_)->extension_service()-> |
| 660 IsBeingUpgraded(extension)) |
| 655 return; | 661 return; |
| 656 | 662 |
| 657 if (browser_action_views_.size() > visible_actions) { | 663 if (browser_action_views_.size() > visible_actions) { |
| 658 // If we have more icons than we can show, then we must not be changing | 664 // If we have more icons than we can show, then we must not be changing |
| 659 // the container size (since we either removed an icon from the main | 665 // the container size (since we either removed an icon from the main |
| 660 // area and one from the overflow list will have shifted in, or we | 666 // area and one from the overflow list will have shifted in, or we |
| 661 // removed an entry directly from the overflow list). | 667 // removed an entry directly from the overflow list). |
| 662 OnBrowserActionVisibilityChanged(); | 668 OnBrowserActionVisibilityChanged(); |
| 663 } else { | 669 } else { |
| 664 // Either we went from overflow to no-overflow, or we shrunk the no- | 670 // Either we went from overflow to no-overflow, or we shrunk the no- |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 animation_target_size_ = target_size; | 809 animation_target_size_ = target_size; |
| 804 AnimationEnded(resize_animation_.get()); | 810 AnimationEnded(resize_animation_.get()); |
| 805 } | 811 } |
| 806 } | 812 } |
| 807 | 813 |
| 808 bool BrowserActionsContainer::ShouldDisplayBrowserAction( | 814 bool BrowserActionsContainer::ShouldDisplayBrowserAction( |
| 809 const Extension* extension) { | 815 const Extension* extension) { |
| 810 // Only display incognito-enabled extensions while in incognito mode. | 816 // Only display incognito-enabled extensions while in incognito mode. |
| 811 return | 817 return |
| 812 (!profile_->IsOffTheRecord() || | 818 (!profile_->IsOffTheRecord() || |
| 813 profile_->GetExtensionService()->IsIncognitoEnabled(extension->id())); | 819 extensions::ExtensionSystem::Get(profile_)->extension_service()-> |
| 820 IsIncognitoEnabled(extension->id())); |
| 814 } | 821 } |
| 815 | 822 |
| 816 void BrowserActionsContainer::ShowPopup( | 823 void BrowserActionsContainer::ShowPopup( |
| 817 BrowserActionButton* button, | 824 BrowserActionButton* button, |
| 818 ExtensionPopup::ShowAction show_action) { | 825 ExtensionPopup::ShowAction show_action) { |
| 819 const Extension* extension = button->extension(); | 826 const Extension* extension = button->extension(); |
| 820 GURL popup_url; | 827 GURL popup_url; |
| 821 if (model_->ExecuteBrowserAction(extension, browser_, &popup_url) != | 828 if (model_->ExecuteBrowserAction(extension, browser_, &popup_url) != |
| 822 ExtensionToolbarModel::ACTION_SHOW_POPUP) { | 829 ExtensionToolbarModel::ACTION_SHOW_POPUP) { |
| 823 return; | 830 return; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 841 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT; | 848 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT; |
| 842 popup_ = ExtensionPopup::ShowPopup(popup_url, | 849 popup_ = ExtensionPopup::ShowPopup(popup_url, |
| 843 browser_, | 850 browser_, |
| 844 reference_view, | 851 reference_view, |
| 845 arrow_location, | 852 arrow_location, |
| 846 show_action); | 853 show_action); |
| 847 popup_->GetWidget()->AddObserver(this); | 854 popup_->GetWidget()->AddObserver(this); |
| 848 popup_button_ = button; | 855 popup_button_ = button; |
| 849 popup_button_->SetButtonPushed(); | 856 popup_button_->SetButtonPushed(); |
| 850 } | 857 } |
| OLD | NEW |