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" |
11 #include "chrome/browser/extensions/extension_sorting.h" | 11 #include "chrome/browser/extensions/extension_sorting.h" |
12 #include "chrome/browser/extensions/extension_system.h" | 12 #include "chrome/browser/extensions/extension_system.h" |
13 #include "chrome/browser/extensions/extension_uninstall_dialog.h" | 13 #include "chrome/browser/extensions/extension_uninstall_dialog.h" |
14 #include "chrome/browser/extensions/management_policy.h" | 14 #include "chrome/browser/extensions/management_policy.h" |
15 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 15 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/ui/app_list/app_list_controller.h" | 17 #include "chrome/browser/ui/app_list/app_list_controller.h" |
18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
19 #include "chrome/browser/ui/browser_navigator.h" | 19 #include "chrome/browser/ui/browser_navigator.h" |
20 #include "chrome/browser/ui/browser_tabstrip.h" | 20 #include "chrome/browser/ui/browser_tabstrip.h" |
21 #include "chrome/browser/ui/browser_window.h" | 21 #include "chrome/browser/ui/browser_window.h" |
22 #include "chrome/common/extensions/extension.h" | 22 #include "chrome/common/extensions/extension.h" |
23 #include "chrome/common/extensions/extension_constants.h" | 23 #include "chrome/common/extensions/extension_constants.h" |
24 #include "chrome/common/extensions/extension_icon_set.h" | 24 #include "chrome/common/extensions/extension_icon_set.h" |
25 #include "content/public/common/context_menu_params.h" | 25 #include "content/public/common/context_menu_params.h" |
26 #include "grit/chromium_strings.h" | 26 #include "grit/chromium_strings.h" |
27 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
| 28 #include "grit/theme_resources.h" |
28 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
| 30 #include "ui/base/resource/resource_bundle.h" |
| 31 #include "ui/gfx/canvas.h" |
29 #include "ui/gfx/image/image.h" | 32 #include "ui/gfx/image/image.h" |
30 | 33 |
31 using extensions::Extension; | 34 using extensions::Extension; |
32 | 35 |
33 namespace { | 36 namespace { |
34 | 37 |
35 enum CommandId { | 38 enum CommandId { |
36 LAUNCH_NEW = 100, | 39 LAUNCH_NEW = 100, |
37 TOGGLE_PIN, | 40 TOGGLE_PIN, |
38 CREATE_SHORTCUTS, | 41 CREATE_SHORTCUTS, |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 // Otherwise, go with |next|. This is okay because app list does not split | 208 // Otherwise, go with |next|. This is okay because app list does not split |
206 // page based ntp page ordinal. | 209 // page based ntp page ordinal. |
207 // TODO(xiyuan): Revisit this when implementing paging support. | 210 // TODO(xiyuan): Revisit this when implementing paging support. |
208 GetExtensionSorting(profile_)->SetPageOrdinal(extension_id_, prev_page); | 211 GetExtensionSorting(profile_)->SetPageOrdinal(extension_id_, prev_page); |
209 service->OnExtensionMoved(extension_id_, | 212 service->OnExtensionMoved(extension_id_, |
210 prev->extension_id(), | 213 prev->extension_id(), |
211 std::string()); | 214 std::string()); |
212 } | 215 } |
213 | 216 |
214 void ExtensionAppItem::LoadImage(const Extension* extension) { | 217 void ExtensionAppItem::LoadImage(const Extension* extension) { |
| 218 int icon_size = extension_misc::EXTENSION_ICON_MEDIUM; |
| 219 if (HasOverlay()) |
| 220 icon_size = extension_misc::EXTENSION_ICON_SMALL; |
| 221 |
215 icon_.reset(new extensions::IconImage( | 222 icon_.reset(new extensions::IconImage( |
216 extension, | 223 extension, |
217 extension->icons(), | 224 extension->icons(), |
218 extension_misc::EXTENSION_ICON_MEDIUM, | 225 icon_size, |
219 Extension::GetDefaultIcon(true), | 226 Extension::GetDefaultIcon(true), |
220 this)); | 227 this)); |
221 SetIcon(icon_->image_skia()); | 228 SetIconWithOverlay(icon_->image_skia()); |
| 229 } |
| 230 |
| 231 bool ExtensionAppItem::HasOverlay() { |
| 232 #if defined(OS_CHROMEOS) |
| 233 return false; |
| 234 #else |
| 235 return !GetExtension()->is_platform_app(); |
| 236 #endif |
| 237 } |
| 238 |
| 239 void ExtensionAppItem::SetIconWithOverlay(const gfx::ImageSkia& icon) { |
| 240 using extension_misc::EXTENSION_ICON_SMALL; |
| 241 using extension_misc::EXTENSION_ICON_MEDIUM; |
| 242 |
| 243 if (!HasOverlay()) { |
| 244 SetIcon(icon); |
| 245 return; |
| 246 } |
| 247 |
| 248 const int kIconOffset = (EXTENSION_ICON_MEDIUM - EXTENSION_ICON_SMALL) / 2; |
| 249 |
| 250 // The tab overlay is not vertically symmetric, to position the app in the |
| 251 // middle of the overlay we need a slight adjustment. |
| 252 const int kVerticalAdjust = 4; |
| 253 gfx::Canvas icon_canvas(gfx::Size(EXTENSION_ICON_MEDIUM, |
| 254 EXTENSION_ICON_MEDIUM), |
| 255 ui::SCALE_FACTOR_100P, false); |
| 256 icon_canvas.DrawImageInt(icon, kIconOffset, kIconOffset + kVerticalAdjust); |
| 257 icon_canvas.DrawImageInt( |
| 258 *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 259 IDR_APP_LIST_TAB_OVERLAY), |
| 260 0, 0); |
| 261 SetIcon(gfx::ImageSkia(icon_canvas.ExtractImageRep())); |
222 } | 262 } |
223 | 263 |
224 void ExtensionAppItem::ShowExtensionOptions() { | 264 void ExtensionAppItem::ShowExtensionOptions() { |
225 const Extension* extension = GetExtension(); | 265 const Extension* extension = GetExtension(); |
226 if (!extension) | 266 if (!extension) |
227 return; | 267 return; |
228 | 268 |
229 chrome::NavigateParams params(profile_, | 269 chrome::NavigateParams params(profile_, |
230 extension->options_url(), | 270 extension->options_url(), |
231 content::PAGE_TRANSITION_LINK); | 271 content::PAGE_TRANSITION_LINK); |
(...skipping 15 matching lines...) Expand all Loading... |
247 // ExtensionUninstall deletes itself when done or aborted. | 287 // ExtensionUninstall deletes itself when done or aborted. |
248 ExtensionUninstaller* uninstaller = new ExtensionUninstaller(profile_, | 288 ExtensionUninstaller* uninstaller = new ExtensionUninstaller(profile_, |
249 extension_id_, | 289 extension_id_, |
250 controller_); | 290 controller_); |
251 uninstaller->Run(); | 291 uninstaller->Run(); |
252 } | 292 } |
253 | 293 |
254 void ExtensionAppItem::OnExtensionIconImageChanged( | 294 void ExtensionAppItem::OnExtensionIconImageChanged( |
255 extensions::IconImage* image) { | 295 extensions::IconImage* image) { |
256 DCHECK(icon_.get() == image); | 296 DCHECK(icon_.get() == image); |
257 SetIcon(icon_->image_skia()); | 297 SetIconWithOverlay(icon_->image_skia()); |
258 } | 298 } |
259 | 299 |
260 bool ExtensionAppItem::IsItemForCommandIdDynamic(int command_id) const { | 300 bool ExtensionAppItem::IsItemForCommandIdDynamic(int command_id) const { |
261 return command_id == TOGGLE_PIN || command_id == LAUNCH_NEW; | 301 return command_id == TOGGLE_PIN || command_id == LAUNCH_NEW; |
262 } | 302 } |
263 | 303 |
264 string16 ExtensionAppItem::GetLabelForCommandId(int command_id) const { | 304 string16 ExtensionAppItem::GetLabelForCommandId(int command_id) const { |
265 if (command_id == TOGGLE_PIN) { | 305 if (command_id == TOGGLE_PIN) { |
266 return controller_->IsAppPinned(extension_id_) ? | 306 return controller_->IsAppPinned(extension_id_) ? |
267 l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_UNPIN) : | 307 l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_UNPIN) : |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 } | 495 } |
456 | 496 |
457 context_menu_model_->AddItemWithStringId(UNINSTALL, | 497 context_menu_model_->AddItemWithStringId(UNINSTALL, |
458 extension->is_platform_app() ? | 498 extension->is_platform_app() ? |
459 IDS_APP_LIST_UNINSTALL_ITEM : | 499 IDS_APP_LIST_UNINSTALL_ITEM : |
460 IDS_EXTENSIONS_UNINSTALL); | 500 IDS_EXTENSIONS_UNINSTALL); |
461 } | 501 } |
462 | 502 |
463 return context_menu_model_.get(); | 503 return context_menu_model_.get(); |
464 } | 504 } |
OLD | NEW |