OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "athena/content/public/content_app_model_builder.h" | 5 #include "athena/content/public/content_app_model_builder.h" |
6 | 6 |
7 #include "apps/shell/browser/shell_extension_system.h" | 7 #include "apps/shell/browser/shell_extension_system.h" |
8 #include "athena/activity/public/activity_factory.h" | 8 #include "athena/activity/public/activity_factory.h" |
9 #include "athena/activity/public/activity_manager.h" | 9 #include "athena/activity/public/activity_manager.h" |
10 #include "extensions/browser/extension_icon_image.h" | |
11 #include "extensions/common/constants.h" | |
10 #include "extensions/common/extension.h" | 12 #include "extensions/common/extension.h" |
13 #include "extensions/common/manifest_handlers/icons_handler.h" | |
11 #include "ui/app_list/app_list_item.h" | 14 #include "ui/app_list/app_list_item.h" |
12 #include "ui/app_list/app_list_model.h" | 15 #include "ui/app_list/app_list_model.h" |
13 | 16 |
14 using extensions::ShellExtensionSystem; | 17 using extensions::ShellExtensionSystem; |
15 | 18 |
16 namespace athena { | 19 namespace athena { |
17 | 20 |
18 namespace { | 21 namespace { |
19 | 22 |
20 const int kIconSize = 64; | |
21 | |
22 ShellExtensionSystem* GetShellExtensionSystem( | 23 ShellExtensionSystem* GetShellExtensionSystem( |
23 content::BrowserContext* context) { | 24 content::BrowserContext* context) { |
24 return static_cast<ShellExtensionSystem*>( | 25 return static_cast<ShellExtensionSystem*>( |
25 extensions::ExtensionSystem::Get(context)); | 26 extensions::ExtensionSystem::Get(context)); |
26 } | 27 } |
27 | 28 |
28 gfx::ImageSkia CreateFlatColorImage(SkColor color) { | 29 gfx::ImageSkia CreateFlatColorImage(SkColor color) { |
29 SkBitmap bitmap; | 30 SkBitmap bitmap; |
30 bitmap.setConfig(SkBitmap::kARGB_8888_Config, kIconSize, kIconSize); | 31 bitmap.setConfig( |
32 SkBitmap::kARGB_8888_Config, | |
33 extension_misc::EXTENSION_ICON_MEDIUM, | |
34 extension_misc::EXTENSION_ICON_MEDIUM); | |
31 bitmap.allocPixels(); | 35 bitmap.allocPixels(); |
32 bitmap.eraseColor(color); | 36 bitmap.eraseColor(color); |
33 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap); | 37 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
34 } | 38 } |
35 | 39 |
36 // Same dummy item. | 40 // Same dummy item. |
37 class DummyItem : public app_list::AppListItem { | 41 class DummyItem : public app_list::AppListItem { |
38 public: | 42 public: |
39 DummyItem(const std::string& id, | 43 DummyItem(const std::string& id, |
40 const GURL& url, | 44 const GURL& url, |
(...skipping 19 matching lines...) Expand all Loading... | |
60 | 64 |
61 DISALLOW_COPY_AND_ASSIGN(DummyItem); | 65 DISALLOW_COPY_AND_ASSIGN(DummyItem); |
62 }; | 66 }; |
63 | 67 |
64 class AppItem : public app_list::AppListItem { | 68 class AppItem : public app_list::AppListItem { |
65 public: | 69 public: |
66 AppItem(scoped_refptr<extensions::Extension> extension, | 70 AppItem(scoped_refptr<extensions::Extension> extension, |
67 content::BrowserContext* browser_context) | 71 content::BrowserContext* browser_context) |
68 : app_list::AppListItem(extension->id()), | 72 : app_list::AppListItem(extension->id()), |
69 extension_(extension), | 73 extension_(extension), |
70 browser_context_(browser_context) { | 74 browser_context_(browser_context), |
71 // TODO(mukai): componentize extension_icon_image and use it. | 75 icon_image_(browser_context_, |
72 SetIcon(CreateFlatColorImage(SK_ColorBLACK), false); | 76 extension.get(), |
77 extensions::IconsInfo::GetIcons(extension.get()), | |
78 extension_misc::EXTENSION_ICON_MEDIUM, | |
79 // TODO(mukai): better default icon | |
James Cook
2014/06/20 14:48:45
Not for this CL, but there is an IDR_APP_DEFAULT_I
Jun Mukai
2014/06/20 16:33:31
Note that resource_bundle is still not yet initial
| |
80 CreateFlatColorImage(SK_ColorBLACK), | |
81 NULL) { | |
82 icon_image_.image_skia().EnsureRepsForSupportedScales(); | |
83 SetIcon(icon_image_.image_skia(), false); | |
73 SetName(extension->name()); | 84 SetName(extension->name()); |
74 } | 85 } |
75 | 86 |
76 private: | 87 private: |
77 // Overridden from app_list::AppListItem: | 88 // Overridden from app_list::AppListItem: |
78 virtual void Activate(int event_flags) OVERRIDE { | 89 virtual void Activate(int event_flags) OVERRIDE { |
79 // TODO(mukai): Pass |extension_| when the extension system supports | 90 // TODO(mukai): Pass |extension_| when the extension system supports |
80 // multiple extensions. | 91 // multiple extensions. |
81 GetShellExtensionSystem(browser_context_)->LaunchApp(); | 92 GetShellExtensionSystem(browser_context_)->LaunchApp(); |
82 } | 93 } |
83 | 94 |
84 scoped_refptr<extensions::Extension> extension_; | 95 scoped_refptr<extensions::Extension> extension_; |
85 content::BrowserContext* browser_context_; | 96 content::BrowserContext* browser_context_; |
97 extensions::IconImage icon_image_; | |
86 | 98 |
87 DISALLOW_COPY_AND_ASSIGN(AppItem); | 99 DISALLOW_COPY_AND_ASSIGN(AppItem); |
88 }; | 100 }; |
89 | 101 |
90 } // namespace | 102 } // namespace |
91 | 103 |
92 ContentAppModelBuilder::ContentAppModelBuilder( | 104 ContentAppModelBuilder::ContentAppModelBuilder( |
93 content::BrowserContext* browser_context) | 105 content::BrowserContext* browser_context) |
94 : browser_context_(browser_context) { | 106 : browser_context_(browser_context) { |
95 } | 107 } |
(...skipping 18 matching lines...) Expand all Loading... | |
114 | 126 |
115 ShellExtensionSystem* extension_system = | 127 ShellExtensionSystem* extension_system = |
116 GetShellExtensionSystem(browser_context_); | 128 GetShellExtensionSystem(browser_context_); |
117 if (extension_system && extension_system->extension()) { | 129 if (extension_system && extension_system->extension()) { |
118 model->AddItem(scoped_ptr<app_list::AppListItem>( | 130 model->AddItem(scoped_ptr<app_list::AppListItem>( |
119 new AppItem(extension_system->extension(), browser_context_))); | 131 new AppItem(extension_system->extension(), browser_context_))); |
120 } | 132 } |
121 } | 133 } |
122 | 134 |
123 } // namespace athena | 135 } // namespace athena |
OLD | NEW |