Move application:chromium bindings to mojo/application/
[chromium-blink-merge.git] / athena / extensions / extension_app_model_builder.cc
blob0aa5c6e9ab54d1002f20f15e5406c4826af94553
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/extensions/public/extension_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 "extensions/grit/extensions_browser_resources.h"
15 #include "ui/app_list/app_list_item.h"
16 #include "ui/app_list/app_list_model.h"
17 #include "ui/base/resource/resource_bundle.h"
19 namespace athena {
21 namespace {
23 gfx::ImageSkia CreateFlatColorImage(SkColor color) {
24 SkBitmap bitmap;
25 bitmap.allocN32Pixels(extension_misc::EXTENSION_ICON_MEDIUM,
26 extension_misc::EXTENSION_ICON_MEDIUM);
27 bitmap.eraseColor(color);
28 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
31 // Same dummy item.
32 class DummyItem : public app_list::AppListItem {
33 public:
34 DummyItem(const std::string& id,
35 const GURL& url,
36 SkColor color,
37 content::BrowserContext* browser_context)
38 : app_list::AppListItem(id),
39 url_(url),
40 browser_context_(browser_context) {
42 SetIcon(CreateFlatColorImage(color), false /* has_shadow */);
43 SetName(id);
46 private:
47 // Overridden from app_list::AppListItem:
48 virtual void Activate(int event_flags) OVERRIDE {
49 ActivityManager::Get()->AddActivity(
50 ActivityFactory::Get()->CreateWebActivity(
51 browser_context_, base::string16(), url_));
54 GURL url_;
55 content::BrowserContext* browser_context_;
57 DISALLOW_COPY_AND_ASSIGN(DummyItem);
60 class AppItem : public app_list::AppListItem {
61 public:
62 AppItem(scoped_refptr<const extensions::Extension> extension,
63 content::BrowserContext* browser_context)
64 : app_list::AppListItem(extension->id()),
65 extension_(extension),
66 browser_context_(browser_context),
67 icon_image_(browser_context_,
68 extension.get(),
69 extensions::IconsInfo::GetIcons(extension.get()),
70 extension_misc::EXTENSION_ICON_MEDIUM,
71 *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
72 IDR_APP_DEFAULT_ICON),
73 NULL) {
74 icon_image_.image_skia().EnsureRepsForSupportedScales();
75 SetIcon(icon_image_.image_skia(), false);
76 SetName(extension->name());
79 private:
80 // Overridden from app_list::AppListItem:
81 virtual void Activate(int event_flags) OVERRIDE {
82 ExtensionsDelegate::Get(browser_context_)->LaunchApp(extension_->id());
85 scoped_refptr<const extensions::Extension> extension_;
86 content::BrowserContext* browser_context_;
87 extensions::IconImage icon_image_;
89 DISALLOW_COPY_AND_ASSIGN(AppItem);
92 } // namespace
94 ExtensionAppModelBuilder::ExtensionAppModelBuilder(
95 content::BrowserContext* browser_context)
96 : browser_context_(browser_context) {
99 ExtensionAppModelBuilder::~ExtensionAppModelBuilder() {
102 void ExtensionAppModelBuilder::PopulateApps(app_list::AppListModel* model) {
103 ExtensionsDelegate* bridge = ExtensionsDelegate::Get(browser_context_);
104 const extensions::ExtensionSet& extensions = bridge->GetInstalledExtensions();
105 for (extensions::ExtensionSet::const_iterator iter = extensions.begin();
106 iter != extensions.end();
107 ++iter) {
108 // TODO(mukai): use chrome/browser/extension_ui_util.
109 if ((*iter)->ShouldDisplayInAppLauncher()) {
110 model->AddItem(scoped_ptr<app_list::AppListItem>(
111 new AppItem(*iter, browser_context_)));
115 model->AddItem(scoped_ptr<app_list::AppListItem>(new DummyItem(
116 "mail", GURL("http://gmail.com/"), SK_ColorRED, browser_context_)));
117 model->AddItem(scoped_ptr<app_list::AppListItem>(new DummyItem(
118 "calendar", GURL("https://calendar.google.com/"),
119 SK_ColorBLUE, browser_context_)));
120 model->AddItem(scoped_ptr<app_list::AppListItem>(new DummyItem(
121 "video", GURL("http://youtube.com/"), SK_ColorGREEN, browser_context_)));
122 model->AddItem(scoped_ptr<app_list::AppListItem>(new DummyItem(
123 "music", GURL("http://play.google.com/music"),
124 SK_ColorYELLOW, browser_context_)));
125 model->AddItem(scoped_ptr<app_list::AppListItem>(new DummyItem(
126 "contact", GURL("https://www.google.com/contacts"),
127 SK_ColorCYAN, browser_context_)));
130 } // namespace athena