Support V1 app
[chromium-blink-merge.git] / athena / content / content_app_model_builder.cc
blob14ece4f93d985759a4f59c7b565ec6236aae44b7
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"
17 namespace athena {
19 namespace {
21 gfx::ImageSkia CreateFlatColorImage(SkColor color) {
22 SkBitmap bitmap;
23 bitmap.allocN32Pixels(extension_misc::EXTENSION_ICON_MEDIUM,
24 extension_misc::EXTENSION_ICON_MEDIUM);
25 bitmap.eraseColor(color);
26 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
29 // Same dummy item.
30 class DummyItem : public app_list::AppListItem {
31 public:
32 DummyItem(const std::string& id,
33 const GURL& url,
34 SkColor color,
35 content::BrowserContext* browser_context)
36 : app_list::AppListItem(id),
37 url_(url),
38 browser_context_(browser_context) {
40 SetIcon(CreateFlatColorImage(color), false /* has_shadow */);
41 SetName(id);
44 private:
45 // Overridden from app_list::AppListItem:
46 virtual void Activate(int event_flags) OVERRIDE {
47 ActivityManager::Get()->AddActivity(
48 ActivityFactory::Get()->CreateWebActivity(
49 browser_context_, base::string16(), url_));
52 GURL url_;
53 content::BrowserContext* browser_context_;
55 DISALLOW_COPY_AND_ASSIGN(DummyItem);
58 class AppItem : public app_list::AppListItem {
59 public:
60 AppItem(scoped_refptr<const extensions::Extension> extension,
61 content::BrowserContext* browser_context)
62 : app_list::AppListItem(extension->id()),
63 extension_(extension),
64 browser_context_(browser_context),
65 icon_image_(browser_context_,
66 extension.get(),
67 extensions::IconsInfo::GetIcons(extension.get()),
68 extension_misc::EXTENSION_ICON_MEDIUM,
69 // TODO(mukai): better default icon
70 CreateFlatColorImage(SK_ColorBLACK),
71 NULL) {
72 icon_image_.image_skia().EnsureRepsForSupportedScales();
73 SetIcon(icon_image_.image_skia(), false);
74 SetName(extension->name());
77 private:
78 // Overridden from app_list::AppListItem:
79 virtual void Activate(int event_flags) OVERRIDE {
80 ExtensionsDelegate::Get(browser_context_)->LaunchApp(extension_->id());
83 scoped_refptr<const extensions::Extension> extension_;
84 content::BrowserContext* browser_context_;
85 extensions::IconImage icon_image_;
87 DISALLOW_COPY_AND_ASSIGN(AppItem);
90 } // namespace
92 ContentAppModelBuilder::ContentAppModelBuilder(
93 content::BrowserContext* browser_context)
94 : browser_context_(browser_context) {
97 ContentAppModelBuilder::~ContentAppModelBuilder() {
100 void ContentAppModelBuilder::PopulateApps(app_list::AppListModel* model) {
101 ExtensionsDelegate* bridge = ExtensionsDelegate::Get(browser_context_);
102 const extensions::ExtensionSet& extensions = bridge->GetInstalledExtensions();
103 for (extensions::ExtensionSet::const_iterator iter = extensions.begin();
104 iter != extensions.end();
105 ++iter) {
106 // TODO(mukai): use chrome/browser/extension_ui_util.
107 if ((*iter)->ShouldDisplayInAppLauncher()) {
108 model->AddItem(scoped_ptr<app_list::AppListItem>(
109 new AppItem(*iter, browser_context_)));
113 model->AddItem(scoped_ptr<app_list::AppListItem>(new DummyItem(
114 "mail", GURL("http://gmail.com/"), SK_ColorRED, browser_context_)));
115 model->AddItem(scoped_ptr<app_list::AppListItem>(new DummyItem(
116 "calendar", GURL("https://calendar.google.com/"),
117 SK_ColorBLUE, browser_context_)));
118 model->AddItem(scoped_ptr<app_list::AppListItem>(new DummyItem(
119 "video", GURL("http://youtube.com/"), SK_ColorGREEN, browser_context_)));
120 model->AddItem(scoped_ptr<app_list::AppListItem>(new DummyItem(
121 "music", GURL("http://play.google.com/music"),
122 SK_ColorYELLOW, browser_context_)));
123 model->AddItem(scoped_ptr<app_list::AppListItem>(new DummyItem(
124 "contact", GURL("https://www.google.com/contacts"),
125 SK_ColorCYAN, browser_context_)));
128 } // namespace athena