Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: athena/extensions/extension_app_model_builder.cc

Issue 863033002: Delete athena/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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/browser/extension_registry.h"
12 #include "extensions/browser/extension_registry_factory.h"
13 #include "extensions/common/constants.h"
14 #include "extensions/common/extension_set.h"
15 #include "extensions/common/manifest_handlers/icons_handler.h"
16 #include "extensions/grit/extensions_browser_resources.h"
17 #include "ui/app_list/app_list_item.h"
18 #include "ui/app_list/app_list_model.h"
19 #include "ui/base/resource/resource_bundle.h"
20
21 namespace athena {
22
23 namespace {
24
25 // Copied from chrome/common/extensions/extension_constants.h
26 // TODO(mukai): move constants to src/extensions
27 const char kChromeAppId[] = "mgndgikekgjfcpckkfioiadnlibdjbkf";
28
29 class AppItem : public app_list::AppListItem {
30 public:
31 AppItem(scoped_refptr<const extensions::Extension> extension,
32 content::BrowserContext* browser_context)
33 : app_list::AppListItem(extension->id()),
34 browser_context_(browser_context) {
35 Reload(extension);
36 }
37
38 void Reload(scoped_refptr<const extensions::Extension> extension) {
39 extension_ = extension;
40 icon_image_.reset(new extensions::IconImage(
41 browser_context_,
42 extension.get(),
43 extensions::IconsInfo::GetIcons(extension.get()),
44 extension_misc::EXTENSION_ICON_MEDIUM,
45 *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
46 IDR_APP_DEFAULT_ICON),
47 nullptr));
48 icon_image_->image_skia().EnsureRepsForSupportedScales();
49 SetIcon(icon_image_->image_skia(), false);
50 SetName(extension->name());
51 }
52
53 private:
54 // Overridden from app_list::AppListItem:
55 void Activate(int event_flags) override {
56 ExtensionsDelegate::Get(browser_context_)->LaunchApp(extension_->id());
57 }
58
59 scoped_refptr<const extensions::Extension> extension_;
60 content::BrowserContext* browser_context_;
61 scoped_ptr<extensions::IconImage> icon_image_;
62
63 DISALLOW_COPY_AND_ASSIGN(AppItem);
64 };
65
66 } // namespace
67
68 ExtensionAppModelBuilder::ExtensionAppModelBuilder(
69 content::BrowserContext* browser_context)
70 : browser_context_(browser_context), model_(nullptr) {
71 extensions::ExtensionRegistryFactory::GetForBrowserContext(browser_context_)
72 ->AddObserver(this);
73 }
74
75 ExtensionAppModelBuilder::~ExtensionAppModelBuilder() {
76 extensions::ExtensionRegistryFactory::GetForBrowserContext(browser_context_)
77 ->RemoveObserver(this);
78 }
79
80 void ExtensionAppModelBuilder::RegisterAppListModel(
81 app_list::AppListModel* model) {
82 DCHECK(!model_);
83 model_ = model;
84
85 ExtensionsDelegate* bridge = ExtensionsDelegate::Get(browser_context_);
86 const extensions::ExtensionSet& extensions = bridge->GetInstalledExtensions();
87 for (extensions::ExtensionSet::const_iterator iter = extensions.begin();
88 iter != extensions.end();
89 ++iter) {
90 AddItem(*iter);
91 }
92 }
93
94 void ExtensionAppModelBuilder::AddItem(
95 scoped_refptr<const extensions::Extension> extension) {
96 // Chrome icon is currently disabled for homecard since it's not meaningful.
97 // http://crbug.com/421677
98 // TODO(mukai): use chrome/browser/extension_ui_util.
99 if (extension->ShouldDisplayInAppLauncher() &&
100 extension->id() != kChromeAppId) {
101 model_->AddItem(make_scoped_ptr(new AppItem(extension, browser_context_)));
102 }
103 }
104
105 void ExtensionAppModelBuilder::OnExtensionInstalled(
106 content::BrowserContext* browser_context,
107 const extensions::Extension* extension,
108 bool is_update) {
109 app_list::AppListItem* item = model_->FindItem(extension->id());
110 if (item)
111 static_cast<AppItem*>(item)->Reload(make_scoped_refptr(extension));
112 else
113 AddItem(make_scoped_refptr(extension));
114 }
115
116 void ExtensionAppModelBuilder::OnExtensionUninstalled(
117 content::BrowserContext* browser_context,
118 const extensions::Extension* extension,
119 extensions::UninstallReason reason) {
120 model_->DeleteItem(extension->id());
121 }
122
123 } // namespace athena
OLDNEW
« no previous file with comments | « athena/extensions/chrome/extensions_delegate_impl.cc ('k') | athena/extensions/extensions_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698