| 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/toolbar/toolbar_actions_model.h" | 5 #include "chrome/browser/ui/toolbar/toolbar_actions_model.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/metrics/histogram_base.h" | 12 #include "base/metrics/histogram_base.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
| 17 #include "chrome/browser/extensions/component_migration_helper.h" | 17 #include "chrome/browser/extensions/component_migration_helper.h" |
| 18 #include "chrome/browser/extensions/extension_action_manager.h" | 18 #include "chrome/browser/extensions/extension_action_manager.h" |
| 19 #include "chrome/browser/extensions/extension_message_bubble_controller.h" |
| 19 #include "chrome/browser/extensions/extension_tab_util.h" | 20 #include "chrome/browser/extensions/extension_tab_util.h" |
| 20 #include "chrome/browser/extensions/extension_util.h" | 21 #include "chrome/browser/extensions/extension_util.h" |
| 21 #include "chrome/browser/extensions/tab_helper.h" | 22 #include "chrome/browser/extensions/tab_helper.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
| 24 #include "chrome/browser/ui/extensions/extension_action_view_controller.h" | 25 #include "chrome/browser/ui/extensions/extension_action_view_controller.h" |
| 26 #include "chrome/browser/ui/extensions/extension_message_bubble_factory.h" |
| 25 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 26 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" | 28 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" |
| 27 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" | 29 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
| 28 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" | 30 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" |
| 29 #include "chrome/browser/ui/toolbar/toolbar_actions_model_factory.h" | 31 #include "chrome/browser/ui/toolbar/toolbar_actions_model_factory.h" |
| 30 #include "components/prefs/pref_service.h" | 32 #include "components/prefs/pref_service.h" |
| 31 #include "content/public/browser/notification_details.h" | 33 #include "content/public/browser/notification_details.h" |
| 32 #include "content/public/browser/notification_source.h" | 34 #include "content/public/browser/notification_source.h" |
| 33 #include "content/public/browser/web_contents.h" | 35 #include "content/public/browser/web_contents.h" |
| 34 #include "extensions/browser/extension_registry.h" | 36 #include "extensions/browser/extension_registry.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 45 : profile_(profile), | 47 : profile_(profile), |
| 46 extension_prefs_(extension_prefs), | 48 extension_prefs_(extension_prefs), |
| 47 prefs_(profile_->GetPrefs()), | 49 prefs_(profile_->GetPrefs()), |
| 48 extension_action_api_(extensions::ExtensionActionAPI::Get(profile_)), | 50 extension_action_api_(extensions::ExtensionActionAPI::Get(profile_)), |
| 49 extension_registry_(extensions::ExtensionRegistry::Get(profile_)), | 51 extension_registry_(extensions::ExtensionRegistry::Get(profile_)), |
| 50 extension_action_manager_( | 52 extension_action_manager_( |
| 51 extensions::ExtensionActionManager::Get(profile_)), | 53 extensions::ExtensionActionManager::Get(profile_)), |
| 52 component_migration_helper_( | 54 component_migration_helper_( |
| 53 new extensions::ComponentMigrationHelper(profile_, this)), | 55 new extensions::ComponentMigrationHelper(profile_, this)), |
| 54 actions_initialized_(false), | 56 actions_initialized_(false), |
| 55 use_redesign_(extensions::FeatureSwitch::extension_action_redesign() | 57 use_redesign_( |
| 56 ->IsEnabled()), | 58 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()), |
| 57 highlight_type_(HIGHLIGHT_NONE), | 59 highlight_type_(HIGHLIGHT_NONE), |
| 60 has_active_bubble_(false), |
| 58 extension_action_observer_(this), | 61 extension_action_observer_(this), |
| 59 extension_registry_observer_(this), | 62 extension_registry_observer_(this), |
| 60 weak_ptr_factory_(this) { | 63 weak_ptr_factory_(this) { |
| 61 ComponentToolbarActionsFactory::GetInstance()->RegisterComponentMigrations( | 64 ComponentToolbarActionsFactory::GetInstance()->RegisterComponentMigrations( |
| 62 component_migration_helper_.get()); | 65 component_migration_helper_.get()); |
| 63 extensions::ExtensionSystem::Get(profile_)->ready().Post( | 66 extensions::ExtensionSystem::Get(profile_)->ready().Post( |
| 64 FROM_HERE, base::Bind(&ToolbarActionsModel::OnReady, | 67 FROM_HERE, base::Bind(&ToolbarActionsModel::OnReady, |
| 65 weak_ptr_factory_.GetWeakPtr())); | 68 weak_ptr_factory_.GetWeakPtr())); |
| 66 visible_icon_count_ = | 69 visible_icon_count_ = |
| 67 prefs_->GetInteger(extensions::pref_names::kToolbarSize); | 70 prefs_->GetInteger(extensions::pref_names::kToolbarSize); |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 if (highlighted_items_.empty()) | 428 if (highlighted_items_.empty()) |
| 426 StopHighlighting(); | 429 StopHighlighting(); |
| 427 } | 430 } |
| 428 } else { | 431 } else { |
| 429 FOR_EACH_OBSERVER(Observer, observers_, OnToolbarActionRemoved(item.id)); | 432 FOR_EACH_OBSERVER(Observer, observers_, OnToolbarActionRemoved(item.id)); |
| 430 } | 433 } |
| 431 | 434 |
| 432 UpdatePrefs(); | 435 UpdatePrefs(); |
| 433 } | 436 } |
| 434 | 437 |
| 438 std::unique_ptr<extensions::ExtensionMessageBubbleController> |
| 439 ToolbarActionsModel::GetExtensionMessageBubbleController(Browser* browser) { |
| 440 std::unique_ptr<extensions::ExtensionMessageBubbleController> controller; |
| 441 if (has_active_bubble()) |
| 442 return controller; |
| 443 controller = ExtensionMessageBubbleFactory(browser).GetController(); |
| 444 if (controller) |
| 445 controller->SetIsActiveBubble(); |
| 446 return controller; |
| 447 } |
| 448 |
| 435 void ToolbarActionsModel::RemoveExtension( | 449 void ToolbarActionsModel::RemoveExtension( |
| 436 const extensions::Extension* extension) { | 450 const extensions::Extension* extension) { |
| 437 RemoveItem(ToolbarItem(extension->id(), EXTENSION_ACTION)); | 451 RemoveItem(ToolbarItem(extension->id(), EXTENSION_ACTION)); |
| 438 } | 452 } |
| 439 | 453 |
| 440 // Combine the currently enabled extensions that have browser actions (which | 454 // Combine the currently enabled extensions that have browser actions (which |
| 441 // we get from the ExtensionRegistry) and component actions (which we get from | 455 // we get from the ExtensionRegistry) and component actions (which we get from |
| 442 // ComponentToolbarActionsFactory) with the ordering we get from the pref | 456 // ComponentToolbarActionsFactory) with the ordering we get from the pref |
| 443 // service. For robustness we use a somewhat inefficient process: | 457 // service. For robustness we use a somewhat inefficient process: |
| 444 // 1. Create a vector of actions sorted by their pref values. This vector may | 458 // 1. Create a vector of actions sorted by their pref values. This vector may |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 prefs_->GetInteger(extensions::pref_names::kToolbarSize); | 838 prefs_->GetInteger(extensions::pref_names::kToolbarSize); |
| 825 if (saved_icon_count != visible_icon_count_) | 839 if (saved_icon_count != visible_icon_count_) |
| 826 SetVisibleIconCount(saved_icon_count); | 840 SetVisibleIconCount(saved_icon_count); |
| 827 } | 841 } |
| 828 } | 842 } |
| 829 | 843 |
| 830 const extensions::Extension* ToolbarActionsModel::GetExtensionById( | 844 const extensions::Extension* ToolbarActionsModel::GetExtensionById( |
| 831 const std::string& id) const { | 845 const std::string& id) const { |
| 832 return extension_registry_->enabled_extensions().GetByID(id); | 846 return extension_registry_->enabled_extensions().GetByID(id); |
| 833 } | 847 } |
| OLD | NEW |