| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "athena/extensions/public/extension_app_model_builder.h" | 5 #include "athena/extensions/public/extension_app_model_builder.h" |
| 6 | 6 |
| 7 #include "athena/activity/public/activity_factory.h" | 7 #include "athena/activity/public/activity_factory.h" |
| 8 #include "athena/activity/public/activity_manager.h" | 8 #include "athena/activity/public/activity_manager.h" |
| 9 #include "athena/extensions/public/extensions_delegate.h" | 9 #include "athena/extensions/public/extensions_delegate.h" |
| 10 #include "extensions/browser/extension_icon_image.h" | 10 #include "extensions/browser/extension_icon_image.h" |
| 11 #include "extensions/common/constants.h" | 11 #include "extensions/common/constants.h" |
| 12 #include "extensions/common/extension_set.h" | 12 #include "extensions/common/extension_set.h" |
| 13 #include "extensions/common/manifest_handlers/icons_handler.h" | 13 #include "extensions/common/manifest_handlers/icons_handler.h" |
| 14 #include "extensions/grit/extensions_browser_resources.h" | 14 #include "extensions/grit/extensions_browser_resources.h" |
| 15 #include "ui/app_list/app_list_item.h" | 15 #include "ui/app_list/app_list_item.h" |
| 16 #include "ui/app_list/app_list_model.h" | 16 #include "ui/app_list/app_list_model.h" |
| 17 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
| 18 | 18 |
| 19 namespace athena { | 19 namespace athena { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 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); | |
| 29 } | |
| 30 | |
| 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) { | |
| 41 | |
| 42 SetIcon(CreateFlatColorImage(color), false /* has_shadow */); | |
| 43 SetName(id); | |
| 44 } | |
| 45 | |
| 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_)); | |
| 52 } | |
| 53 | |
| 54 GURL url_; | |
| 55 content::BrowserContext* browser_context_; | |
| 56 | |
| 57 DISALLOW_COPY_AND_ASSIGN(DummyItem); | |
| 58 }; | |
| 59 | |
| 60 class AppItem : public app_list::AppListItem { | 23 class AppItem : public app_list::AppListItem { |
| 61 public: | 24 public: |
| 62 AppItem(scoped_refptr<const extensions::Extension> extension, | 25 AppItem(scoped_refptr<const extensions::Extension> extension, |
| 63 content::BrowserContext* browser_context) | 26 content::BrowserContext* browser_context) |
| 64 : app_list::AppListItem(extension->id()), | 27 : app_list::AppListItem(extension->id()), |
| 65 extension_(extension), | 28 extension_(extension), |
| 66 browser_context_(browser_context), | 29 browser_context_(browser_context), |
| 67 icon_image_(browser_context_, | 30 icon_image_(browser_context_, |
| 68 extension.get(), | 31 extension.get(), |
| 69 extensions::IconsInfo::GetIcons(extension.get()), | 32 extensions::IconsInfo::GetIcons(extension.get()), |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 const extensions::ExtensionSet& extensions = bridge->GetInstalledExtensions(); | 67 const extensions::ExtensionSet& extensions = bridge->GetInstalledExtensions(); |
| 105 for (extensions::ExtensionSet::const_iterator iter = extensions.begin(); | 68 for (extensions::ExtensionSet::const_iterator iter = extensions.begin(); |
| 106 iter != extensions.end(); | 69 iter != extensions.end(); |
| 107 ++iter) { | 70 ++iter) { |
| 108 // TODO(mukai): use chrome/browser/extension_ui_util. | 71 // TODO(mukai): use chrome/browser/extension_ui_util. |
| 109 if ((*iter)->ShouldDisplayInAppLauncher()) { | 72 if ((*iter)->ShouldDisplayInAppLauncher()) { |
| 110 model->AddItem(scoped_ptr<app_list::AppListItem>( | 73 model->AddItem(scoped_ptr<app_list::AppListItem>( |
| 111 new AppItem(*iter, browser_context_))); | 74 new AppItem(*iter, browser_context_))); |
| 112 } | 75 } |
| 113 } | 76 } |
| 114 | |
| 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_))); | |
| 128 } | 77 } |
| 129 | 78 |
| 130 } // namespace athena | 79 } // namespace athena |
| OLD | NEW |