extension_app_model_builder.cc revision 1320f92c476a1ad9d19dba2a48c72b75566198e9
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.
4
5#include "athena/extensions/public/extension_app_model_builder.h"
6
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"
18
19namespace athena {
20
21namespace {
22
23class AppItem : public app_list::AppListItem {
24 public:
25  AppItem(scoped_refptr<const extensions::Extension> extension,
26          content::BrowserContext* browser_context)
27      : app_list::AppListItem(extension->id()),
28        extension_(extension),
29        browser_context_(browser_context),
30        icon_image_(browser_context_,
31                    extension.get(),
32                    extensions::IconsInfo::GetIcons(extension.get()),
33                    extension_misc::EXTENSION_ICON_MEDIUM,
34                    *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
35                        IDR_APP_DEFAULT_ICON),
36                    NULL) {
37    icon_image_.image_skia().EnsureRepsForSupportedScales();
38    SetIcon(icon_image_.image_skia(), false);
39    SetName(extension->name());
40  }
41
42 private:
43  // Overridden from app_list::AppListItem:
44  virtual void Activate(int event_flags) OVERRIDE {
45    ExtensionsDelegate::Get(browser_context_)->LaunchApp(extension_->id());
46  }
47
48  scoped_refptr<const extensions::Extension> extension_;
49  content::BrowserContext* browser_context_;
50  extensions::IconImage icon_image_;
51
52  DISALLOW_COPY_AND_ASSIGN(AppItem);
53};
54
55}  // namespace
56
57ExtensionAppModelBuilder::ExtensionAppModelBuilder(
58    content::BrowserContext* browser_context)
59    : browser_context_(browser_context) {
60}
61
62ExtensionAppModelBuilder::~ExtensionAppModelBuilder() {
63}
64
65void ExtensionAppModelBuilder::PopulateApps(app_list::AppListModel* model) {
66  ExtensionsDelegate* bridge = ExtensionsDelegate::Get(browser_context_);
67  const extensions::ExtensionSet& extensions = bridge->GetInstalledExtensions();
68  for (extensions::ExtensionSet::const_iterator iter = extensions.begin();
69       iter != extensions.end();
70       ++iter) {
71    // TODO(mukai): use chrome/browser/extension_ui_util.
72    if ((*iter)->ShouldDisplayInAppLauncher()) {
73      model->AddItem(scoped_ptr<app_list::AppListItem>(
74          new AppItem(*iter, browser_context_)));
75    }
76  }
77}
78
79}  // namespace athena
80