| 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_base.h" | 11 #include "base/metrics/histogram_base.h" |
| 12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.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" | |
| 18 #include "chrome/browser/extensions/extension_action_manager.h" | 17 #include "chrome/browser/extensions/extension_action_manager.h" |
| 19 #include "chrome/browser/extensions/extension_message_bubble_controller.h" | 18 #include "chrome/browser/extensions/extension_message_bubble_controller.h" |
| 20 #include "chrome/browser/extensions/extension_tab_util.h" | 19 #include "chrome/browser/extensions/extension_tab_util.h" |
| 21 #include "chrome/browser/extensions/extension_util.h" | 20 #include "chrome/browser/extensions/extension_util.h" |
| 22 #include "chrome/browser/extensions/tab_helper.h" | 21 #include "chrome/browser/extensions/tab_helper.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
| 25 #include "chrome/browser/ui/extensions/extension_action_view_controller.h" | 24 #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/extensions/extension_message_bubble_factory.h" |
| 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 26 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 44 ToolbarActionsModel::ToolbarActionsModel( | 43 ToolbarActionsModel::ToolbarActionsModel( |
| 45 Profile* profile, | 44 Profile* profile, |
| 46 extensions::ExtensionPrefs* extension_prefs) | 45 extensions::ExtensionPrefs* extension_prefs) |
| 47 : profile_(profile), | 46 : profile_(profile), |
| 48 extension_prefs_(extension_prefs), | 47 extension_prefs_(extension_prefs), |
| 49 prefs_(profile_->GetPrefs()), | 48 prefs_(profile_->GetPrefs()), |
| 50 extension_action_api_(extensions::ExtensionActionAPI::Get(profile_)), | 49 extension_action_api_(extensions::ExtensionActionAPI::Get(profile_)), |
| 51 extension_registry_(extensions::ExtensionRegistry::Get(profile_)), | 50 extension_registry_(extensions::ExtensionRegistry::Get(profile_)), |
| 52 extension_action_manager_( | 51 extension_action_manager_( |
| 53 extensions::ExtensionActionManager::Get(profile_)), | 52 extensions::ExtensionActionManager::Get(profile_)), |
| 54 component_migration_helper_( | |
| 55 new extensions::ComponentMigrationHelper(profile_, this)), | |
| 56 actions_initialized_(false), | 53 actions_initialized_(false), |
| 57 use_redesign_( | 54 use_redesign_( |
| 58 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()), | 55 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()), |
| 59 highlight_type_(HIGHLIGHT_NONE), | 56 highlight_type_(HIGHLIGHT_NONE), |
| 60 has_active_bubble_(false), | 57 has_active_bubble_(false), |
| 61 extension_action_observer_(this), | 58 extension_action_observer_(this), |
| 62 extension_registry_observer_(this), | 59 extension_registry_observer_(this), |
| 63 weak_ptr_factory_(this) { | 60 weak_ptr_factory_(this) { |
| 64 ComponentToolbarActionsFactory::GetInstance()->RegisterComponentMigrations( | |
| 65 component_migration_helper_.get()); | |
| 66 extensions::ExtensionSystem::Get(profile_)->ready().Post( | 61 extensions::ExtensionSystem::Get(profile_)->ready().Post( |
| 67 FROM_HERE, base::Bind(&ToolbarActionsModel::OnReady, | 62 FROM_HERE, base::Bind(&ToolbarActionsModel::OnReady, |
| 68 weak_ptr_factory_.GetWeakPtr())); | 63 weak_ptr_factory_.GetWeakPtr())); |
| 69 visible_icon_count_ = | 64 visible_icon_count_ = |
| 70 prefs_->GetInteger(extensions::pref_names::kToolbarSize); | 65 prefs_->GetInteger(extensions::pref_names::kToolbarSize); |
| 71 | 66 |
| 72 // We only care about watching the prefs if not in incognito mode. | 67 // We only care about watching the prefs if not in incognito mode. |
| 73 if (!profile_->IsOffTheRecord()) { | 68 if (!profile_->IsOffTheRecord()) { |
| 74 pref_change_registrar_.Init(prefs_); | 69 pref_change_registrar_.Init(prefs_); |
| 75 pref_change_callback_ = | 70 pref_change_callback_ = |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 InitializeActionList(); | 261 InitializeActionList(); |
| 267 // Wait until the extension system is ready before observing any further | 262 // Wait until the extension system is ready before observing any further |
| 268 // changes so that the toolbar buttons can be shown in their stable ordering | 263 // changes so that the toolbar buttons can be shown in their stable ordering |
| 269 // taken from prefs. | 264 // taken from prefs. |
| 270 extension_registry_observer_.Add(extension_registry_); | 265 extension_registry_observer_.Add(extension_registry_); |
| 271 extension_action_observer_.Add(extension_action_api_); | 266 extension_action_observer_.Add(extension_action_api_); |
| 272 | 267 |
| 273 actions_initialized_ = true; | 268 actions_initialized_ = true; |
| 274 for (Observer& observer : observers_) | 269 for (Observer& observer : observers_) |
| 275 observer.OnToolbarModelInitialized(); | 270 observer.OnToolbarModelInitialized(); |
| 276 | |
| 277 if (use_redesign_) { | |
| 278 // Handle component action migrations. We must make sure that observers are | |
| 279 // notified of initialization first, so that the associated widgets are | |
| 280 // created. | |
| 281 ComponentToolbarActionsFactory::GetInstance()->HandleComponentMigrations( | |
| 282 component_migration_helper_.get(), profile_); | |
| 283 } | |
| 284 } | 271 } |
| 285 | 272 |
| 286 size_t ToolbarActionsModel::FindNewPositionFromLastKnownGood( | 273 size_t ToolbarActionsModel::FindNewPositionFromLastKnownGood( |
| 287 const ToolbarItem& action) { | 274 const ToolbarItem& action) { |
| 288 // See if we have last known good position for this action. | 275 // See if we have last known good position for this action. |
| 289 size_t new_index = 0; | 276 size_t new_index = 0; |
| 290 // Loop through the ID list of known positions, to count the number of | 277 // Loop through the ID list of known positions, to count the number of |
| 291 // visible action icons preceding |action|'s id. | 278 // visible action icons preceding |action|'s id. |
| 292 for (const std::string& last_pos_id : last_known_positions_) { | 279 for (const std::string& last_pos_id : last_known_positions_) { |
| 293 if (last_pos_id == action.id) | 280 if (last_pos_id == action.id) |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 return extension_registry_->enabled_extensions().GetByID(id); | 846 return extension_registry_->enabled_extensions().GetByID(id); |
| 860 } | 847 } |
| 861 | 848 |
| 862 bool ToolbarActionsModel::IsActionVisible(const std::string& action_id) const { | 849 bool ToolbarActionsModel::IsActionVisible(const std::string& action_id) const { |
| 863 size_t index = 0u; | 850 size_t index = 0u; |
| 864 while (toolbar_items().size() > index && | 851 while (toolbar_items().size() > index && |
| 865 toolbar_items()[index].id != action_id) | 852 toolbar_items()[index].id != action_id) |
| 866 ++index; | 853 ++index; |
| 867 return index < visible_icon_count(); | 854 return index < visible_icon_count(); |
| 868 } | 855 } |
| OLD | NEW |