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
3 // found in the LICENSE file.
5 #include "athena/content/public/content_app_model_builder.h"
7 #include "athena/activity/public/activity_factory.h"
8 #include "athena/activity/public/activity_manager.h"
9 #include "athena/extensions/public/extensions_delegate.h"
10 #include "extensions/browser/extension_icon_image.h"
11 #include "extensions/common/constants.h"
12 #include "extensions/common/extension_set.h"
13 #include "extensions/common/manifest_handlers/icons_handler.h"
14 #include "ui/app_list/app_list_item.h"
15 #include "ui/app_list/app_list_model.h"
21 gfx::ImageSkia
CreateFlatColorImage(SkColor color
) {
23 bitmap
.allocN32Pixels(extension_misc::EXTENSION_ICON_MEDIUM
,
24 extension_misc::EXTENSION_ICON_MEDIUM
);
25 bitmap
.eraseColor(color
);
26 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap
);
30 class DummyItem
: public app_list::AppListItem
{
32 DummyItem(const std::string
& id
,
35 content::BrowserContext
* browser_context
)
36 : app_list::AppListItem(id
),
38 browser_context_(browser_context
) {
40 SetIcon(CreateFlatColorImage(color
), false /* has_shadow */);
45 // Overridden from app_list::AppListItem:
46 virtual void Activate(int event_flags
) OVERRIDE
{
47 ActivityManager::Get()->AddActivity(
48 ActivityFactory::Get()->CreateWebActivity(browser_context_
, url_
));
52 content::BrowserContext
* browser_context_
;
54 DISALLOW_COPY_AND_ASSIGN(DummyItem
);
57 class AppItem
: public app_list::AppListItem
{
59 AppItem(scoped_refptr
<const extensions::Extension
> extension
,
60 content::BrowserContext
* browser_context
)
61 : app_list::AppListItem(extension
->id()),
62 extension_(extension
),
63 browser_context_(browser_context
),
64 icon_image_(browser_context_
,
66 extensions::IconsInfo::GetIcons(extension
.get()),
67 extension_misc::EXTENSION_ICON_MEDIUM
,
68 // TODO(mukai): better default icon
69 CreateFlatColorImage(SK_ColorBLACK
),
71 icon_image_
.image_skia().EnsureRepsForSupportedScales();
72 SetIcon(icon_image_
.image_skia(), false);
73 SetName(extension
->name());
77 // Overridden from app_list::AppListItem:
78 virtual void Activate(int event_flags
) OVERRIDE
{
79 ExtensionsDelegate::Get(browser_context_
)->LaunchApp(extension_
->id());
82 scoped_refptr
<const extensions::Extension
> extension_
;
83 content::BrowserContext
* browser_context_
;
84 extensions::IconImage icon_image_
;
86 DISALLOW_COPY_AND_ASSIGN(AppItem
);
91 ContentAppModelBuilder::ContentAppModelBuilder(
92 content::BrowserContext
* browser_context
)
93 : browser_context_(browser_context
) {
96 ContentAppModelBuilder::~ContentAppModelBuilder() {
99 void ContentAppModelBuilder::PopulateApps(app_list::AppListModel
* model
) {
100 ExtensionsDelegate
* bridge
= ExtensionsDelegate::Get(browser_context_
);
101 const extensions::ExtensionSet
& extensions
= bridge
->GetInstalledExtensions();
102 for (extensions::ExtensionSet::const_iterator iter
= extensions
.begin();
103 iter
!= extensions
.end();
105 model
->AddItem(scoped_ptr
<app_list::AppListItem
>(
106 new AppItem(*iter
, browser_context_
)));
109 model
->AddItem(scoped_ptr
<app_list::AppListItem
>(new DummyItem(
110 "mail", GURL("http://gmail.com/"), SK_ColorRED
, browser_context_
)));
111 model
->AddItem(scoped_ptr
<app_list::AppListItem
>(new DummyItem(
112 "calendar", GURL("https://calendar.google.com/"),
113 SK_ColorBLUE
, browser_context_
)));
114 model
->AddItem(scoped_ptr
<app_list::AppListItem
>(new DummyItem(
115 "video", GURL("http://youtube.com/"), SK_ColorGREEN
, browser_context_
)));
116 model
->AddItem(scoped_ptr
<app_list::AppListItem
>(new DummyItem(
117 "music", GURL("http://play.google.com/music"),
118 SK_ColorYELLOW
, browser_context_
)));
119 model
->AddItem(scoped_ptr
<app_list::AppListItem
>(new DummyItem(
120 "contact", GURL("https://www.google.com/contacts"),
121 SK_ColorCYAN
, browser_context_
)));
124 } // namespace athena