| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/metrics/user_metrics.h" | 10 #include "base/metrics/user_metrics.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "extensions/common/extension.h" | 26 #include "extensions/common/extension.h" |
| 27 #include "extensions/common/extension_icon_set.h" | 27 #include "extensions/common/extension_icon_set.h" |
| 28 #include "extensions/common/manifest_handlers/icons_handler.h" | 28 #include "extensions/common/manifest_handlers/icons_handler.h" |
| 29 #include "extensions/common/manifest_url_handlers.h" | 29 #include "extensions/common/manifest_url_handlers.h" |
| 30 #include "ui/base/resource/resource_bundle.h" | 30 #include "ui/base/resource/resource_bundle.h" |
| 31 #include "ui/events/event_constants.h" | 31 #include "ui/events/event_constants.h" |
| 32 #include "ui/gfx/canvas.h" | 32 #include "ui/gfx/canvas.h" |
| 33 #include "ui/gfx/geometry/rect.h" | 33 #include "ui/gfx/geometry/rect.h" |
| 34 #include "ui/gfx/image/canvas_image_source.h" | 34 #include "ui/gfx/image/canvas_image_source.h" |
| 35 #include "ui/gfx/skia_util.h" | 35 #include "ui/gfx/skia_util.h" |
| 36 | |
| 37 #if defined(OS_CHROMEOS) | |
| 38 #include "chrome/browser/chromeos/extensions/gfx_utils.h" | 36 #include "chrome/browser/chromeos/extensions/gfx_utils.h" |
| 39 #endif | |
| 40 | 37 |
| 41 using extensions::Extension; | 38 using extensions::Extension; |
| 42 | 39 |
| 43 namespace { | 40 namespace { |
| 44 | 41 |
| 45 // Overlays a shortcut icon over the bottom left corner of a given image. | 42 // Overlays a shortcut icon over the bottom left corner of a given image. |
| 46 class ShortcutOverlayImageSource : public gfx::CanvasImageSource { | 43 class ShortcutOverlayImageSource : public gfx::CanvasImageSource { |
| 47 public: | 44 public: |
| 48 explicit ShortcutOverlayImageSource(const gfx::ImageSkia& icon) | 45 explicit ShortcutOverlayImageSource(const gfx::ImageSkia& icon) |
| 49 : gfx::CanvasImageSource(icon.size(), false), | 46 : gfx::CanvasImageSource(icon.size(), false), |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 Profile* profile, | 105 Profile* profile, |
| 109 const app_list::AppListSyncableService::SyncItem* sync_item, | 106 const app_list::AppListSyncableService::SyncItem* sync_item, |
| 110 const std::string& extension_id, | 107 const std::string& extension_id, |
| 111 const std::string& extension_name, | 108 const std::string& extension_name, |
| 112 const gfx::ImageSkia& installing_icon, | 109 const gfx::ImageSkia& installing_icon, |
| 113 bool is_platform_app) | 110 bool is_platform_app) |
| 114 : ChromeAppListItem(profile, extension_id), | 111 : ChromeAppListItem(profile, extension_id), |
| 115 extension_enable_flow_controller_(NULL), | 112 extension_enable_flow_controller_(NULL), |
| 116 extension_name_(extension_name), | 113 extension_name_(extension_name), |
| 117 installing_icon_(CreateDisabledIcon(installing_icon)), | 114 installing_icon_(CreateDisabledIcon(installing_icon)), |
| 118 is_platform_app_(is_platform_app), | 115 is_platform_app_(is_platform_app) { |
| 119 has_overlay_(false) { | |
| 120 Reload(); | 116 Reload(); |
| 121 if (sync_item && sync_item->item_ordinal.IsValid()) | 117 if (sync_item && sync_item->item_ordinal.IsValid()) |
| 122 UpdateFromSync(sync_item); | 118 UpdateFromSync(sync_item); |
| 123 else | 119 else |
| 124 SetDefaultPositionIfApplicable(); | 120 SetDefaultPositionIfApplicable(); |
| 125 } | 121 } |
| 126 | 122 |
| 127 ExtensionAppItem::~ExtensionAppItem() { | 123 ExtensionAppItem::~ExtensionAppItem() { |
| 128 } | 124 } |
| 129 | 125 |
| 130 bool ExtensionAppItem::NeedsOverlay() const { | |
| 131 #if defined(OS_CHROMEOS) | |
| 132 // The overlay is disabled completely in ChromeOS. | |
| 133 return false; | |
| 134 #endif | |
| 135 | |
| 136 extensions::LaunchType launch_type = GetExtension() | |
| 137 ? extensions::GetLaunchType(extensions::ExtensionPrefs::Get(profile()), | |
| 138 GetExtension()) | |
| 139 : extensions::LAUNCH_TYPE_WINDOW; | |
| 140 | |
| 141 // The overlay icon is disabled for hosted apps in windowed mode with | |
| 142 // bookmark apps enabled. | |
| 143 return !is_platform_app_ && extension_id() != extension_misc::kChromeAppId && | |
| 144 (!extensions::util::IsNewBookmarkAppsEnabled() || | |
| 145 launch_type != extensions::LAUNCH_TYPE_WINDOW); | |
| 146 } | |
| 147 | |
| 148 void ExtensionAppItem::Reload() { | 126 void ExtensionAppItem::Reload() { |
| 149 const Extension* extension = GetExtension(); | 127 const Extension* extension = GetExtension(); |
| 150 bool is_installing = !extension; | 128 bool is_installing = !extension; |
| 151 SetIsInstalling(is_installing); | 129 SetIsInstalling(is_installing); |
| 152 if (is_installing) { | 130 if (is_installing) { |
| 153 SetName(extension_name_); | 131 SetName(extension_name_); |
| 154 UpdateIcon(); | 132 UpdateIcon(); |
| 155 return; | 133 return; |
| 156 } | 134 } |
| 157 SetNameAndShortName(extension->name(), extension->short_name()); | 135 SetNameAndShortName(extension->name(), extension->short_name()); |
| 158 LoadImage(extension); | 136 LoadImage(extension); |
| 159 } | 137 } |
| 160 | 138 |
| 161 void ExtensionAppItem::UpdateIcon() { | 139 void ExtensionAppItem::UpdateIcon() { |
| 162 gfx::ImageSkia icon = installing_icon_; | 140 gfx::ImageSkia icon = installing_icon_; |
| 163 | 141 |
| 164 // Use the app icon if the app exists. Turn the image greyscale if the app is | 142 // Use the app icon if the app exists. Turn the image greyscale if the app is |
| 165 // not launchable. | 143 // not launchable. |
| 166 if (GetExtension() && icon_) { | 144 if (GetExtension() && icon_) { |
| 167 icon = icon_->image_skia(); | 145 icon = icon_->image_skia(); |
| 168 const bool enabled = extensions::util::IsAppLaunchable(extension_id(), | 146 const bool enabled = extensions::util::IsAppLaunchable(extension_id(), |
| 169 profile()); | 147 profile()); |
| 170 #if defined(OS_CHROMEOS) | |
| 171 extensions::util::MaybeApplyChromeBadge(profile(), id(), &icon); | 148 extensions::util::MaybeApplyChromeBadge(profile(), id(), &icon); |
| 172 #endif | |
| 173 | 149 |
| 174 if (!enabled) | 150 if (!enabled) |
| 175 icon = CreateDisabledIcon(icon); | 151 icon = CreateDisabledIcon(icon); |
| 176 | 152 |
| 177 if (GetExtension()->from_bookmark()) | 153 if (GetExtension()->from_bookmark()) |
| 178 icon = gfx::ImageSkia(new RoundedCornersImageSource(icon), icon.size()); | 154 icon = gfx::ImageSkia(new RoundedCornersImageSource(icon), icon.size()); |
| 179 } | 155 } |
| 180 // Paint the shortcut overlay if necessary. | |
| 181 has_overlay_ = NeedsOverlay(); | |
| 182 if (has_overlay_) | |
| 183 icon = gfx::ImageSkia(new ShortcutOverlayImageSource(icon), icon.size()); | |
| 184 | |
| 185 SetIcon(icon); | 156 SetIcon(icon); |
| 186 } | 157 } |
| 187 | 158 |
| 188 const Extension* ExtensionAppItem::GetExtension() const { | 159 const Extension* ExtensionAppItem::GetExtension() const { |
| 189 const extensions::ExtensionRegistry* registry = | 160 const extensions::ExtensionRegistry* registry = |
| 190 extensions::ExtensionRegistry::Get(profile()); | 161 extensions::ExtensionRegistry::Get(profile()); |
| 191 const Extension* extension = registry->GetInstalledExtension( | 162 const Extension* extension = registry->GetInstalledExtension( |
| 192 extension_id()); | 163 extension_id()); |
| 193 return extension; | 164 return extension; |
| 194 } | 165 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 | 260 |
| 290 ui::MenuModel* ExtensionAppItem::GetContextMenuModel() { | 261 ui::MenuModel* ExtensionAppItem::GetContextMenuModel() { |
| 291 context_menu_.reset(new app_list::ExtensionAppContextMenu(this, | 262 context_menu_.reset(new app_list::ExtensionAppContextMenu(this, |
| 292 profile(), | 263 profile(), |
| 293 extension_id(), | 264 extension_id(), |
| 294 GetController())); | 265 GetController())); |
| 295 context_menu_->set_is_platform_app(is_platform_app_); | 266 context_menu_->set_is_platform_app(is_platform_app_); |
| 296 return context_menu_->GetMenuModel(); | 267 return context_menu_->GetMenuModel(); |
| 297 } | 268 } |
| 298 | 269 |
| 299 void ExtensionAppItem::OnExtensionPreferenceChanged() { | |
| 300 if (has_overlay_ != NeedsOverlay()) | |
| 301 UpdateIcon(); | |
| 302 } | |
| 303 | |
| 304 // static | 270 // static |
| 305 const char ExtensionAppItem::kItemType[] = "ExtensionAppItem"; | 271 const char ExtensionAppItem::kItemType[] = "ExtensionAppItem"; |
| 306 | 272 |
| 307 const char* ExtensionAppItem::GetItemType() const { | 273 const char* ExtensionAppItem::GetItemType() const { |
| 308 return ExtensionAppItem::kItemType; | 274 return ExtensionAppItem::kItemType; |
| 309 } | 275 } |
| 310 | 276 |
| 311 void ExtensionAppItem::ExecuteLaunchCommand(int event_flags) { | 277 void ExtensionAppItem::ExecuteLaunchCommand(int event_flags) { |
| 312 Launch(event_flags); | 278 Launch(event_flags); |
| 313 } | 279 } |
| OLD | NEW |