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