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