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 13 matching lines...) Expand all Loading... | |
54 ActivityManager::Get()->AddActivity( | 58 ActivityManager::Get()->AddActivity( |
55 ActivityFactory::Get()->CreateWebActivity(browser_context_, url_)); | 59 ActivityFactory::Get()->CreateWebActivity(browser_context_, url_)); |
56 } | 60 } |
57 | 61 |
58 GURL url_; | 62 GURL url_; |
59 content::BrowserContext* browser_context_; | 63 content::BrowserContext* browser_context_; |
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, |
69 public extensions::IconImage::Observer { | |
oshima
2014/06/19 23:06:22
is this observer used?
Jun Mukai
2014/06/19 23:08:32
oops, removed. thanks for catching this.
| |
65 public: | 70 public: |
66 AppItem(scoped_refptr<extensions::Extension> extension, | 71 AppItem(scoped_refptr<extensions::Extension> extension, |
67 content::BrowserContext* browser_context) | 72 content::BrowserContext* browser_context) |
68 : app_list::AppListItem(extension->id()), | 73 : app_list::AppListItem(extension->id()), |
69 extension_(extension), | 74 extension_(extension), |
70 browser_context_(browser_context) { | 75 browser_context_(browser_context), |
71 // TODO(mukai): componentize extension_icon_image and use it. | 76 icon_image_(browser_context_, |
72 SetIcon(CreateFlatColorImage(SK_ColorBLACK), false); | 77 extension.get(), |
78 extensions::IconsInfo::GetIcons(extension.get()), | |
79 extension_misc::EXTENSION_ICON_MEDIUM, | |
80 // TODO(mukai): better default icon | |
81 CreateFlatColorImage(SK_ColorBLACK), | |
82 NULL) { | |
83 icon_image_.image_skia().EnsureRepsForSupportedScales(); | |
84 SetIcon(icon_image_.image_skia(), false); | |
73 SetName(extension->name()); | 85 SetName(extension->name()); |
74 } | 86 } |
75 | 87 |
76 private: | 88 private: |
77 // Overridden from app_list::AppListItem: | 89 // Overridden from app_list::AppListItem: |
78 virtual void Activate(int event_flags) OVERRIDE { | 90 virtual void Activate(int event_flags) OVERRIDE { |
79 // TODO(mukai): Pass |extension_| when the extension system supports | 91 // TODO(mukai): Pass |extension_| when the extension system supports |
80 // multiple extensions. | 92 // multiple extensions. |
81 GetShellExtensionSystem(browser_context_)->LaunchApp(); | 93 GetShellExtensionSystem(browser_context_)->LaunchApp(); |
82 } | 94 } |
83 | 95 |
84 scoped_refptr<extensions::Extension> extension_; | 96 scoped_refptr<extensions::Extension> extension_; |
85 content::BrowserContext* browser_context_; | 97 content::BrowserContext* browser_context_; |
98 extensions::IconImage icon_image_; | |
86 | 99 |
87 DISALLOW_COPY_AND_ASSIGN(AppItem); | 100 DISALLOW_COPY_AND_ASSIGN(AppItem); |
88 }; | 101 }; |
89 | 102 |
90 } // namespace | 103 } // namespace |
91 | 104 |
92 ContentAppModelBuilder::ContentAppModelBuilder( | 105 ContentAppModelBuilder::ContentAppModelBuilder( |
93 content::BrowserContext* browser_context) | 106 content::BrowserContext* browser_context) |
94 : browser_context_(browser_context) { | 107 : browser_context_(browser_context) { |
95 } | 108 } |
(...skipping 18 matching lines...) Expand all Loading... | |
114 | 127 |
115 ShellExtensionSystem* extension_system = | 128 ShellExtensionSystem* extension_system = |
116 GetShellExtensionSystem(browser_context_); | 129 GetShellExtensionSystem(browser_context_); |
117 if (extension_system && extension_system->extension()) { | 130 if (extension_system && extension_system->extension()) { |
118 model->AddItem(scoped_ptr<app_list::AppListItem>( | 131 model->AddItem(scoped_ptr<app_list::AppListItem>( |
119 new AppItem(extension_system->extension(), browser_context_))); | 132 new AppItem(extension_system->extension(), browser_context_))); |
120 } | 133 } |
121 } | 134 } |
122 | 135 |
123 } // namespace athena | 136 } // namespace athena |
OLD | NEW |