| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/search/extension_app_result.h" | 5 #include "chrome/browser/ui/app_list/search/extension_app_result.h" |
| 6 | 6 |
| 7 #include "base/metrics/user_metrics.h" | 7 #include "base/metrics/user_metrics.h" |
| 8 #include "chrome/browser/extensions/chrome_app_icon.h" |
| 9 #include "chrome/browser/extensions/chrome_app_icon_service.h" |
| 8 #include "chrome/browser/extensions/extension_util.h" | 10 #include "chrome/browser/extensions/extension_util.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" | 12 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" |
| 11 #include "chrome/browser/ui/app_list/extension_app_context_menu.h" | 13 #include "chrome/browser/ui/app_list/extension_app_context_menu.h" |
| 12 #include "chrome/browser/ui/app_list/search/search_util.h" | 14 #include "chrome/browser/ui/app_list/search/search_util.h" |
| 13 #include "chrome/browser/ui/extensions/extension_enable_flow.h" | 15 #include "chrome/browser/ui/extensions/extension_enable_flow.h" |
| 14 #include "chrome/common/extensions/extension_metrics.h" | 16 #include "chrome/common/extensions/extension_metrics.h" |
| 15 #include "extensions/browser/extension_registry.h" | 17 #include "extensions/browser/extension_registry.h" |
| 16 #include "extensions/browser/extension_system_provider.h" | 18 #include "extensions/browser/extension_system_provider.h" |
| 17 #include "extensions/browser/extensions_browser_client.h" | 19 #include "extensions/browser/extensions_browser_client.h" |
| 18 #include "extensions/common/constants.h" | 20 #include "extensions/common/constants.h" |
| 19 #include "extensions/common/extension.h" | 21 #include "extensions/common/extension.h" |
| 20 #include "extensions/common/extension_icon_set.h" | 22 #include "extensions/common/extension_icon_set.h" |
| 21 #include "extensions/common/manifest_handlers/icons_handler.h" | 23 #include "extensions/common/manifest_handlers/icons_handler.h" |
| 22 #include "ui/app_list/app_list_switches.h" | 24 #include "ui/app_list/app_list_switches.h" |
| 23 #include "ui/events/event_constants.h" | 25 #include "ui/events/event_constants.h" |
| 24 #include "ui/gfx/color_utils.h" | |
| 25 #include "ui/gfx/image/image_skia_operations.h" | |
| 26 #include "chrome/browser/chromeos/extensions/gfx_utils.h" | |
| 27 | 26 |
| 28 namespace app_list { | 27 namespace app_list { |
| 29 | 28 |
| 30 ExtensionAppResult::ExtensionAppResult(Profile* profile, | 29 ExtensionAppResult::ExtensionAppResult(Profile* profile, |
| 31 const std::string& app_id, | 30 const std::string& app_id, |
| 32 AppListControllerDelegate* controller, | 31 AppListControllerDelegate* controller, |
| 33 bool is_recommendation) | 32 bool is_recommendation) |
| 34 : AppResult(profile, app_id, controller, is_recommendation) { | 33 : AppResult(profile, app_id, controller, is_recommendation) { |
| 35 set_id(extensions::Extension::GetBaseURLFromExtensionId(app_id).spec()); | 34 set_id(extensions::Extension::GetBaseURLFromExtensionId(app_id).spec()); |
| 36 | 35 |
| 37 const extensions::Extension* extension = | 36 const extensions::Extension* extension = |
| 38 extensions::ExtensionRegistry::Get(profile)->GetInstalledExtension( | 37 extensions::ExtensionRegistry::Get(profile)->GetInstalledExtension( |
| 39 app_id); | 38 app_id); |
| 40 DCHECK(extension); | 39 DCHECK(extension); |
| 41 | 40 |
| 42 is_platform_app_ = extension->is_platform_app(); | 41 is_platform_app_ = extension->is_platform_app(); |
| 43 | 42 icon_ = extensions::ChromeAppIconService::Get(profile)->CreateIcon( |
| 44 CreateOrUpdateIcon(); | 43 this, app_id, GetPreferredIconDimension()); |
| 45 | 44 |
| 46 StartObservingExtensionRegistry(); | 45 StartObservingExtensionRegistry(); |
| 47 } | 46 } |
| 48 | 47 |
| 49 ExtensionAppResult::~ExtensionAppResult() { | 48 ExtensionAppResult::~ExtensionAppResult() { |
| 50 StopObservingExtensionRegistry(); | 49 StopObservingExtensionRegistry(); |
| 51 } | 50 } |
| 52 | 51 |
| 53 void ExtensionAppResult::CreateOrUpdateIcon() { | |
| 54 if (icon_ && icon_->is_valid()) { | |
| 55 UpdateIcon(); | |
| 56 return; | |
| 57 } | |
| 58 | |
| 59 const extensions::Extension* extension = | |
| 60 extensions::ExtensionRegistry::Get(profile())->GetInstalledExtension( | |
| 61 app_id()); | |
| 62 DCHECK(extension); | |
| 63 | |
| 64 icon_ = base::MakeUnique<extensions::IconImage>( | |
| 65 profile(), extension, extensions::IconsInfo::GetIcons(extension), | |
| 66 GetPreferredIconDimension(), extensions::util::GetDefaultAppIcon(), this); | |
| 67 UpdateIcon(); | |
| 68 } | |
| 69 | |
| 70 void ExtensionAppResult::Open(int event_flags) { | 52 void ExtensionAppResult::Open(int event_flags) { |
| 71 RecordHistogram(APP_SEARCH_RESULT); | 53 RecordHistogram(APP_SEARCH_RESULT); |
| 72 const extensions::Extension* extension = | 54 const extensions::Extension* extension = |
| 73 extensions::ExtensionRegistry::Get(profile())->GetInstalledExtension( | 55 extensions::ExtensionRegistry::Get(profile())->GetInstalledExtension( |
| 74 app_id()); | 56 app_id()); |
| 75 if (!extension) | 57 if (!extension) |
| 76 return; | 58 return; |
| 77 | 59 |
| 78 // Don't auto-enable apps that cannot be launched. | 60 // Don't auto-enable apps that cannot be launched. |
| 79 if (!extensions::util::IsAppLaunchable(app_id(), profile())) | 61 if (!extensions::util::IsAppLaunchable(app_id(), profile())) |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 controller()->OnShowChildDialog(); | 119 controller()->OnShowChildDialog(); |
| 138 | 120 |
| 139 extension_enable_flow_.reset(new ExtensionEnableFlow( | 121 extension_enable_flow_.reset(new ExtensionEnableFlow( |
| 140 profile(), app_id(), this)); | 122 profile(), app_id(), this)); |
| 141 extension_enable_flow_->StartForNativeWindow( | 123 extension_enable_flow_->StartForNativeWindow( |
| 142 controller()->GetAppListWindow()); | 124 controller()->GetAppListWindow()); |
| 143 } | 125 } |
| 144 return true; | 126 return true; |
| 145 } | 127 } |
| 146 | 128 |
| 147 void ExtensionAppResult::UpdateIcon() { | 129 void ExtensionAppResult::OnIconUpdated(extensions::ChromeAppIcon* icon) { |
| 148 gfx::ImageSkia icon = icon_->image_skia(); | 130 SetIcon(icon->image_skia()); |
| 149 | |
| 150 extensions::util::MaybeApplyChromeBadge(profile(), app_id(), &icon); | |
| 151 | |
| 152 if (!extensions::util::IsAppLaunchable(app_id(), profile())) { | |
| 153 const color_utils::HSL shift = {-1, 0, 0.6}; | |
| 154 icon = gfx::ImageSkiaOperations::CreateHSLShiftedImage(icon, shift); | |
| 155 } | |
| 156 | |
| 157 SetIcon(icon); | |
| 158 } | |
| 159 | |
| 160 void ExtensionAppResult::OnExtensionIconImageChanged( | |
| 161 extensions::IconImage* image) { | |
| 162 DCHECK_EQ(icon_.get(), image); | |
| 163 UpdateIcon(); | |
| 164 } | |
| 165 | |
| 166 void ExtensionAppResult::OnExtensionIconImageDestroyed( | |
| 167 extensions::IconImage* image) { | |
| 168 SetIcon(gfx::ImageSkia()); | |
| 169 } | 131 } |
| 170 | 132 |
| 171 void ExtensionAppResult::ExecuteLaunchCommand(int event_flags) { | 133 void ExtensionAppResult::ExecuteLaunchCommand(int event_flags) { |
| 172 Open(event_flags); | 134 Open(event_flags); |
| 173 } | 135 } |
| 174 | 136 |
| 175 void ExtensionAppResult::ExtensionEnableFlowFinished() { | 137 void ExtensionAppResult::ExtensionEnableFlowFinished() { |
| 176 extension_enable_flow_.reset(); | 138 extension_enable_flow_.reset(); |
| 177 controller()->OnCloseChildDialog(); | 139 controller()->OnCloseChildDialog(); |
| 178 | 140 |
| 179 // Automatically open app after enabling. | 141 // Automatically open app after enabling. |
| 180 Open(ui::EF_NONE); | 142 Open(ui::EF_NONE); |
| 181 } | 143 } |
| 182 | 144 |
| 183 void ExtensionAppResult::ExtensionEnableFlowAborted(bool user_initiated) { | 145 void ExtensionAppResult::ExtensionEnableFlowAborted(bool user_initiated) { |
| 184 extension_enable_flow_.reset(); | 146 extension_enable_flow_.reset(); |
| 185 controller()->OnCloseChildDialog(); | 147 controller()->OnCloseChildDialog(); |
| 186 } | 148 } |
| 187 | 149 |
| 188 void ExtensionAppResult::OnExtensionLoaded( | 150 void ExtensionAppResult::OnExtensionLoaded( |
| 189 content::BrowserContext* browser_context, | 151 content::BrowserContext* browser_context, |
| 190 const extensions::Extension* extension) { | 152 const extensions::Extension* extension) { |
| 191 // Old |icon_| might be invalidated for forever in case extension gets | 153 // Old |icon_| might be invalidated for forever in case extension gets |
| 192 // updated. In this case we need re-create icon again. | 154 // updated. In this case we need re-create icon again. |
| 193 CreateOrUpdateIcon(); | 155 if (!icon_->IsValid()) |
| 156 icon_->Reload(); |
| 194 } | 157 } |
| 195 | 158 |
| 196 void ExtensionAppResult::OnShutdown(extensions::ExtensionRegistry* registry) { | 159 void ExtensionAppResult::OnShutdown(extensions::ExtensionRegistry* registry) { |
| 197 DCHECK_EQ(extension_registry_, registry); | 160 DCHECK_EQ(extension_registry_, registry); |
| 198 StopObservingExtensionRegistry(); | 161 StopObservingExtensionRegistry(); |
| 199 } | 162 } |
| 200 | 163 |
| 201 } // namespace app_list | 164 } // namespace app_list |
| OLD | NEW |