| Index: chrome/browser/ui/ash/launcher/chrome_mash_shelf_controller.cc
|
| diff --git a/chrome/browser/ui/ash/launcher/chrome_mash_shelf_controller.cc b/chrome/browser/ui/ash/launcher/chrome_mash_shelf_controller.cc
|
| index c212264dee2d6905d9526ed14ee3a44f522900b3..17ebb395a1d557b7ded8f1b86d084d82da1dd245 100644
|
| --- a/chrome/browser/ui/ash/launcher/chrome_mash_shelf_controller.cc
|
| +++ b/chrome/browser/ui/ash/launcher/chrome_mash_shelf_controller.cc
|
| @@ -4,15 +4,25 @@
|
|
|
| #include "chrome/browser/ui/ash/launcher/chrome_mash_shelf_controller.h"
|
|
|
| +#include "chrome/browser/extensions/extension_app_icon_loader.h"
|
| #include "chrome/browser/profiles/profile_manager.h"
|
| #include "chrome/browser/ui/ash/chrome_launcher_prefs.h"
|
| +#include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h"
|
| +#include "chrome/browser/ui/ash/launcher/launcher_item_controller.h"
|
| #include "chrome/grit/theme_resources.h"
|
| #include "content/public/common/mojo_shell_connection.h"
|
| +#include "extensions/common/constants.h"
|
| +#include "extensions/grit/extensions_browser_resources.h"
|
| +#include "mojo/common/common_type_converters.h"
|
| #include "services/shell/public/cpp/connector.h"
|
| #include "skia/public/type_converters.h"
|
| #include "ui/base/resource/resource_bundle.h"
|
| #include "ui/display/screen.h"
|
|
|
| +#if defined(OS_CHROMEOS)
|
| +#include "chrome/browser/ui/app_list/arc/arc_app_icon_loader.h"
|
| +#endif
|
| +
|
| class ChromeShelfItemDelegate : public mash::shelf::mojom::ShelfItemDelegate {
|
| public:
|
| ChromeShelfItemDelegate() : item_delegate_binding_(this) {}
|
| @@ -71,20 +81,23 @@ void ChromeMashShelfController::Init() {
|
| static_cast<mash::shelf::mojom::AutoHideBehavior>(
|
| ash::GetShelfAutoHideBehaviorPref(profile->GetPrefs(), display_id)));
|
|
|
| - // Create a test shortcut item to a fake application.
|
| - mash::shelf::mojom::ShelfItemPtr item(mash::shelf::mojom::ShelfItem::New());
|
| - std::string item_id("mojo:fake_app");
|
| - item->app_id = item_id;
|
| - item->app_title = "Fake Mojo App (test pinned shelf item)";
|
| - ResourceBundle& rb = ResourceBundle::GetSharedInstance();
|
| - const gfx::Image& image = rb.GetImageNamed(IDR_PRODUCT_LOGO_32);
|
| - item->image = skia::mojom::Bitmap::From(*image.ToSkBitmap());
|
| - std::unique_ptr<ChromeShelfItemDelegate> delegate(
|
| - new ChromeShelfItemDelegate());
|
| - shelf_controller_->PinItem(std::move(item),
|
| - delegate->CreateInterfacePtrInfoAndBind(
|
| - shelf_controller_.associated_group()));
|
| - app_id_to_item_delegate_.insert(std::make_pair(item_id, std::move(delegate)));
|
| + // TODO(skuhne): The AppIconLoaderImpl has the same problem. Each loaded
|
| + // image is associated with a profile (its loader requires the profile).
|
| + // Since icon size changes are possible, the icon could be requested to be
|
| + // reloaded. However - having it not multi profile aware would cause problems
|
| + // if the icon cache gets deleted upon user switch.
|
| + std::unique_ptr<AppIconLoader> extension_app_icon_loader(
|
| + new extensions::ExtensionAppIconLoader(
|
| + profile, extension_misc::EXTENSION_ICON_SMALL, this));
|
| + app_icon_loaders_.push_back(std::move(extension_app_icon_loader));
|
| +
|
| +#if defined(OS_CHROMEOS)
|
| + std::unique_ptr<AppIconLoader> arc_app_icon_loader(new ArcAppIconLoader(
|
| + profile, extension_misc::EXTENSION_ICON_SMALL, this));
|
| + app_icon_loaders_.push_back(std::move(arc_app_icon_loader));
|
| +#endif
|
| +
|
| + PinAppsFromPrefs();
|
|
|
| // Start observing the shelf now that it has been initialized.
|
| mash::shelf::mojom::ShelfObserverAssociatedPtrInfo ptr_info;
|
| @@ -92,6 +105,47 @@ void ChromeMashShelfController::Init() {
|
| shelf_controller_->AddObserver(std::move(ptr_info));
|
| }
|
|
|
| +void ChromeMashShelfController::PinAppsFromPrefs() {
|
| + Profile* profile = ProfileManager::GetActiveUserProfile();
|
| + LauncherControllerHelper helper(profile);
|
| + std::vector<std::string> pinned_apps =
|
| + ash::GetPinnedAppsFromPrefs(profile->GetPrefs(), &helper);
|
| +
|
| + for (const auto& app : pinned_apps) {
|
| + if (app == ash::kPinnedAppsPlaceholder)
|
| + continue;
|
| +
|
| + mash::shelf::mojom::ShelfItemPtr item(mash::shelf::mojom::ShelfItem::New());
|
| + item->app_id = app;
|
| + item->app_title = mojo::String::From(helper.GetAppTitle(profile, app));
|
| + ResourceBundle& rb = ResourceBundle::GetSharedInstance();
|
| + const gfx::Image& image = rb.GetImageNamed(IDR_APP_DEFAULT_ICON);
|
| + item->image = skia::mojom::Bitmap::From(*image.ToSkBitmap());
|
| + std::unique_ptr<ChromeShelfItemDelegate> delegate(
|
| + new ChromeShelfItemDelegate());
|
| + shelf_controller_->PinItem(std::move(item),
|
| + delegate->CreateInterfacePtrInfoAndBind(
|
| + shelf_controller_.associated_group()));
|
| + app_id_to_item_delegate_.insert(std::make_pair(app, std::move(delegate)));
|
| +
|
| + AppIconLoader* app_icon_loader = GetAppIconLoaderForApp(app);
|
| + if (app_icon_loader) {
|
| + app_icon_loader->FetchImage(app);
|
| + app_icon_loader->UpdateImage(app);
|
| + }
|
| + }
|
| +}
|
| +
|
| +AppIconLoader* ChromeMashShelfController::GetAppIconLoaderForApp(
|
| + const std::string& app_id) {
|
| + for (const auto& app_icon_loader : app_icon_loaders_) {
|
| + if (app_icon_loader->CanLoadImageForApp(app_id))
|
| + return app_icon_loader.get();
|
| + }
|
| +
|
| + return nullptr;
|
| +}
|
| +
|
| void ChromeMashShelfController::OnAlignmentChanged(
|
| mash::shelf::mojom::Alignment alignment) {
|
| ash::SetShelfAlignmentPref(
|
| @@ -107,3 +161,9 @@ void ChromeMashShelfController::OnAutoHideBehaviorChanged(
|
| display::Screen::GetScreen()->GetPrimaryDisplay().id(),
|
| static_cast<ash::ShelfAutoHideBehavior>(auto_hide));
|
| }
|
| +
|
| +void ChromeMashShelfController::OnAppImageUpdated(const std::string& app_id,
|
| + const gfx::ImageSkia& image) {
|
| + shelf_controller_->SetItemImage(app_id,
|
| + skia::mojom::Bitmap::From(*image.bitmap()));
|
| +}
|
|
|