| 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/app_list/extension_app_item.h" | 5 #include "chrome/browser/ui/app_list/extension_app_item.h" |
| 6 | 6 |
| 7 #include "chrome/app/chrome_command_ids.h" | 7 #include "chrome/app/chrome_command_ids.h" |
| 8 #include "chrome/browser/extensions/context_menu_matcher.h" | 8 #include "chrome/browser/extensions/context_menu_matcher.h" |
| 9 #include "chrome/browser/extensions/extension_prefs.h" | 9 #include "chrome/browser/extensions/extension_prefs.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 ExtensionUninstaller(Profile* profile, | 58 ExtensionUninstaller(Profile* profile, |
| 59 const std::string& extension_id, | 59 const std::string& extension_id, |
| 60 AppListControllerDelegate* controller) | 60 AppListControllerDelegate* controller) |
| 61 : profile_(profile), | 61 : profile_(profile), |
| 62 extension_id_(extension_id), | 62 extension_id_(extension_id), |
| 63 controller_(controller) { | 63 controller_(controller) { |
| 64 } | 64 } |
| 65 | 65 |
| 66 void Run() { | 66 void Run() { |
| 67 const Extension* extension = | 67 const Extension* extension = |
| 68 profile_->GetExtensionService()->GetExtensionById(extension_id_, true); | 68 extensions::ExtensionSystem::Get(profile_)->extension_service()-> |
| 69 GetExtensionById(extension_id_, true); |
| 69 if (!extension) { | 70 if (!extension) { |
| 70 CleanUp(); | 71 CleanUp(); |
| 71 return; | 72 return; |
| 72 } | 73 } |
| 73 controller_->AboutToUninstallApp(); | 74 controller_->AboutToUninstallApp(); |
| 74 dialog_.reset(ExtensionUninstallDialog::Create(NULL, this)); | 75 dialog_.reset(ExtensionUninstallDialog::Create(NULL, this)); |
| 75 dialog_->ConfirmUninstall(extension); | 76 dialog_->ConfirmUninstall(extension); |
| 76 } | 77 } |
| 77 | 78 |
| 78 private: | 79 private: |
| 79 // Overridden from ExtensionUninstallDialog::Delegate: | 80 // Overridden from ExtensionUninstallDialog::Delegate: |
| 80 virtual void ExtensionUninstallAccepted() OVERRIDE { | 81 virtual void ExtensionUninstallAccepted() OVERRIDE { |
| 81 ExtensionService* service = profile_->GetExtensionService(); | 82 ExtensionService* service = |
| 83 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 82 const Extension* extension = service->GetExtensionById(extension_id_, true); | 84 const Extension* extension = service->GetExtensionById(extension_id_, true); |
| 83 if (extension) { | 85 if (extension) { |
| 84 service->UninstallExtension(extension_id_, | 86 service->UninstallExtension(extension_id_, |
| 85 false, /* external_uninstall*/ | 87 false, /* external_uninstall*/ |
| 86 NULL); | 88 NULL); |
| 87 } | 89 } |
| 88 controller_->UninstallAppCompleted(); | 90 controller_->UninstallAppCompleted(); |
| 89 CleanUp(); | 91 CleanUp(); |
| 90 } | 92 } |
| 91 | 93 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 102 std::string extension_id_; | 104 std::string extension_id_; |
| 103 AppListControllerDelegate* controller_; | 105 AppListControllerDelegate* controller_; |
| 104 scoped_ptr<ExtensionUninstallDialog> dialog_; | 106 scoped_ptr<ExtensionUninstallDialog> dialog_; |
| 105 | 107 |
| 106 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstaller); | 108 DISALLOW_COPY_AND_ASSIGN(ExtensionUninstaller); |
| 107 }; | 109 }; |
| 108 | 110 |
| 109 extensions::ExtensionPrefs::LaunchType GetExtensionLaunchType( | 111 extensions::ExtensionPrefs::LaunchType GetExtensionLaunchType( |
| 110 Profile* profile, | 112 Profile* profile, |
| 111 const Extension* extension) { | 113 const Extension* extension) { |
| 112 return profile->GetExtensionService()->extension_prefs()->GetLaunchType( | 114 return extensions::ExtensionSystem::Get(profile)->extension_service()-> |
| 113 extension, extensions::ExtensionPrefs::LAUNCH_DEFAULT); | 115 extension_prefs()->GetLaunchType(extension, |
| 116 extensions::ExtensionPrefs::LAUNCH_DEFAULT); |
| 114 } | 117 } |
| 115 | 118 |
| 116 void SetExtensionLaunchType( | 119 void SetExtensionLaunchType( |
| 117 Profile* profile, | 120 Profile* profile, |
| 118 const std::string& extension_id, | 121 const std::string& extension_id, |
| 119 extensions::ExtensionPrefs::LaunchType launch_type) { | 122 extensions::ExtensionPrefs::LaunchType launch_type) { |
| 120 profile->GetExtensionService()->extension_prefs()->SetLaunchType( | 123 extensions::ExtensionSystem::Get(profile)->extension_service()-> |
| 121 extension_id, launch_type); | 124 extension_prefs()->SetLaunchType(extension_id, launch_type); |
| 122 } | 125 } |
| 123 | 126 |
| 124 bool IsExtensionEnabled(Profile* profile, const std::string& extension_id) { | 127 bool IsExtensionEnabled(Profile* profile, const std::string& extension_id) { |
| 125 ExtensionService* service = profile->GetExtensionService(); | 128 ExtensionService* service = |
| 129 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 126 return service->IsExtensionEnabled(extension_id) && | 130 return service->IsExtensionEnabled(extension_id) && |
| 127 !service->GetTerminatedExtension(extension_id); | 131 !service->GetTerminatedExtension(extension_id); |
| 128 } | 132 } |
| 129 | 133 |
| 130 ExtensionSorting* GetExtensionSorting(Profile* profile) { | 134 ExtensionSorting* GetExtensionSorting(Profile* profile) { |
| 131 return profile->GetExtensionService()->extension_prefs()->extension_sorting(); | 135 return extensions::ExtensionSystem::Get(profile)->extension_service()-> |
| 136 extension_prefs()->extension_sorting(); |
| 132 } | 137 } |
| 133 | 138 |
| 134 bool MenuItemHasLauncherContext(const extensions::MenuItem* item) { | 139 bool MenuItemHasLauncherContext(const extensions::MenuItem* item) { |
| 135 return item->contexts().Contains(extensions::MenuItem::LAUNCHER); | 140 return item->contexts().Contains(extensions::MenuItem::LAUNCHER); |
| 136 } | 141 } |
| 137 | 142 |
| 138 } // namespace | 143 } // namespace |
| 139 | 144 |
| 140 ExtensionAppItem::ExtensionAppItem(Profile* profile, | 145 ExtensionAppItem::ExtensionAppItem(Profile* profile, |
| 141 const Extension* extension, | 146 const Extension* extension, |
| 142 AppListControllerDelegate* controller) | 147 AppListControllerDelegate* controller) |
| 143 : ChromeAppListItem(TYPE_APP), | 148 : ChromeAppListItem(TYPE_APP), |
| 144 profile_(profile), | 149 profile_(profile), |
| 145 extension_id_(extension->id()), | 150 extension_id_(extension->id()), |
| 146 controller_(controller) { | 151 controller_(controller) { |
| 147 SetTitle(extension->name()); | 152 SetTitle(extension->name()); |
| 148 LoadImage(extension); | 153 LoadImage(extension); |
| 149 } | 154 } |
| 150 | 155 |
| 151 ExtensionAppItem::~ExtensionAppItem() { | 156 ExtensionAppItem::~ExtensionAppItem() { |
| 152 } | 157 } |
| 153 | 158 |
| 154 const Extension* ExtensionAppItem::GetExtension() const { | 159 const Extension* ExtensionAppItem::GetExtension() const { |
| 155 const Extension* extension = | 160 const Extension* extension = extensions::ExtensionSystem::Get(profile_)-> |
| 156 profile_->GetExtensionService()->GetInstalledExtension(extension_id_); | 161 extension_service()->GetInstalledExtension(extension_id_); |
| 157 return extension; | 162 return extension; |
| 158 } | 163 } |
| 159 | 164 |
| 160 syncer::StringOrdinal ExtensionAppItem::GetPageOrdinal() const { | 165 syncer::StringOrdinal ExtensionAppItem::GetPageOrdinal() const { |
| 161 return GetExtensionSorting(profile_)->GetPageOrdinal(extension_id_); | 166 return GetExtensionSorting(profile_)->GetPageOrdinal(extension_id_); |
| 162 } | 167 } |
| 163 | 168 |
| 164 syncer::StringOrdinal ExtensionAppItem::GetAppLaunchOrdinal() const { | 169 syncer::StringOrdinal ExtensionAppItem::GetAppLaunchOrdinal() const { |
| 165 return GetExtensionSorting(profile_)->GetAppLaunchOrdinal(extension_id_); | 170 return GetExtensionSorting(profile_)->GetAppLaunchOrdinal(extension_id_); |
| 166 } | 171 } |
| 167 | 172 |
| 168 void ExtensionAppItem::Move(const ExtensionAppItem* prev, | 173 void ExtensionAppItem::Move(const ExtensionAppItem* prev, |
| 169 const ExtensionAppItem* next) { | 174 const ExtensionAppItem* next) { |
| 170 // Does nothing if no predecessor nor successor. | 175 // Does nothing if no predecessor nor successor. |
| 171 if (!prev && !next) | 176 if (!prev && !next) |
| 172 return; | 177 return; |
| 173 | 178 |
| 174 ExtensionService* service = profile_->GetExtensionService(); | 179 ExtensionService* service = |
| 180 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 175 service->extension_prefs()->SetAppDraggedByUser(extension_id_); | 181 service->extension_prefs()->SetAppDraggedByUser(extension_id_); |
| 176 | 182 |
| 177 // Handles only predecessor or only successor case. | 183 // Handles only predecessor or only successor case. |
| 178 if (!prev || !next) { | 184 if (!prev || !next) { |
| 179 syncer::StringOrdinal page = prev ? prev->GetPageOrdinal() : | 185 syncer::StringOrdinal page = prev ? prev->GetPageOrdinal() : |
| 180 next->GetPageOrdinal(); | 186 next->GetPageOrdinal(); |
| 181 GetExtensionSorting(profile_)->SetPageOrdinal(extension_id_, page); | 187 GetExtensionSorting(profile_)->SetPageOrdinal(extension_id_, page); |
| 182 service->OnExtensionMoved(extension_id_, | 188 service->OnExtensionMoved(extension_id_, |
| 183 prev ? prev->extension_id() : std::string(), | 189 prev ? prev->extension_id() : std::string(), |
| 184 next ? next->extension_id() : std::string()); | 190 next ? next->extension_id() : std::string()); |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 } | 455 } |
| 450 | 456 |
| 451 context_menu_model_->AddItemWithStringId(UNINSTALL, | 457 context_menu_model_->AddItemWithStringId(UNINSTALL, |
| 452 extension->is_platform_app() ? | 458 extension->is_platform_app() ? |
| 453 IDS_APP_LIST_UNINSTALL_ITEM : | 459 IDS_APP_LIST_UNINSTALL_ITEM : |
| 454 IDS_EXTENSIONS_UNINSTALL); | 460 IDS_EXTENSIONS_UNINSTALL); |
| 455 } | 461 } |
| 456 | 462 |
| 457 return context_menu_model_.get(); | 463 return context_menu_model_.get(); |
| 458 } | 464 } |
| OLD | NEW |