Commit 0bd5b1a3 authored by nancy's avatar nancy Committed by Commit Bot

Add ChromeAppIconLoader back to Load icons for extensions in Shelf.

There are some special extensions, e.g. hangouts, pen-as-Popup and
Speakeasy, opening windows when launch. But extensions are not managed
in AppService, so extensions icons are not added to Shelf when launch
those extensions.

Add ChromeAppIconLoader back to Load icons for extensions in Shelf.
Add LauncherExtensionAppUpdater to handle the extensions life-cycle
events.

BUG=1041493
BUG=b:147424621

Change-Id: Ia30440568c0920060aac479ad92ee54f81fceb7f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2006847
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarIstiaque Ahmed <lazyboy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#733809}
parent d9a71c4b
...@@ -44,7 +44,12 @@ ChromeAppIconLoader::~ChromeAppIconLoader() {} ...@@ -44,7 +44,12 @@ ChromeAppIconLoader::~ChromeAppIconLoader() {}
bool ChromeAppIconLoader::CanLoadImageForApp(const std::string& id) { bool ChromeAppIconLoader::CanLoadImageForApp(const std::string& id) {
if (map_.find(id) != map_.end()) if (map_.find(id) != map_.end())
return true; return true;
return GetExtensionByID(profile(), id) != nullptr;
const Extension* extension = GetExtensionByID(profile(), id);
if (!extension || (extensions_only_ && !extension->is_extension()))
return false;
return true;
} }
void ChromeAppIconLoader::FetchImage(const std::string& id) { void ChromeAppIconLoader::FetchImage(const std::string& id) {
...@@ -77,6 +82,10 @@ void ChromeAppIconLoader::UpdateImage(const std::string& id) { ...@@ -77,6 +82,10 @@ void ChromeAppIconLoader::UpdateImage(const std::string& id) {
it->second->UpdateIcon(); it->second->UpdateIcon();
} }
void ChromeAppIconLoader::SetExtensionsOnly() {
extensions_only_ = true;
}
void ChromeAppIconLoader::OnIconUpdated(ChromeAppIcon* icon) { void ChromeAppIconLoader::OnIconUpdated(ChromeAppIcon* icon) {
delegate()->OnAppImageUpdated(icon->app_id(), icon->image_skia()); delegate()->OnAppImageUpdated(icon->app_id(), icon->image_skia());
} }
......
...@@ -48,6 +48,9 @@ class ChromeAppIconLoader : public AppIconLoader, public ChromeAppIconDelegate { ...@@ -48,6 +48,9 @@ class ChromeAppIconLoader : public AppIconLoader, public ChromeAppIconDelegate {
void ClearImage(const std::string& id) override; void ClearImage(const std::string& id) override;
void UpdateImage(const std::string& id) override; void UpdateImage(const std::string& id) override;
// Sets |extensions_only_| as true to load icons for extensions only.
void SetExtensionsOnly();
private: private:
using ExtensionIDToChromeAppIconMap = using ExtensionIDToChromeAppIconMap =
std::map<std::string, std::unique_ptr<ChromeAppIcon>>; std::map<std::string, std::unique_ptr<ChromeAppIcon>>;
...@@ -62,6 +65,10 @@ class ChromeAppIconLoader : public AppIconLoader, public ChromeAppIconDelegate { ...@@ -62,6 +65,10 @@ class ChromeAppIconLoader : public AppIconLoader, public ChromeAppIconDelegate {
// resize will be performed by ImageLoader. // resize will be performed by ImageLoader.
const ResizeFunction resize_function_; const ResizeFunction resize_function_;
// Loads icons for extensions only if true, otherwise loads icon for both
// Chrome apps and extensions.
bool extensions_only_ = false;
DISALLOW_COPY_AND_ASSIGN(ChromeAppIconLoader); DISALLOW_COPY_AND_ASSIGN(ChromeAppIconLoader);
}; };
......
...@@ -21,7 +21,8 @@ ChromeAppIconService* ChromeAppIconService::Get( ...@@ -21,7 +21,8 @@ ChromeAppIconService* ChromeAppIconService::Get(
ChromeAppIconService::ChromeAppIconService(content::BrowserContext* context) ChromeAppIconService::ChromeAppIconService(content::BrowserContext* context)
: context_(context) { : context_(context) {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
app_updater_ = std::make_unique<LauncherExtensionAppUpdater>(this, context); app_updater_ = std::make_unique<LauncherExtensionAppUpdater>(
this, context, false /* extensions_only */);
#endif #endif
observer_.Add(ExtensionRegistry::Get(context_)); observer_.Add(ExtensionRegistry::Get(context_));
......
...@@ -35,6 +35,14 @@ bool AppServiceAppIconLoader::CanLoadImageForApp(const std::string& app_id) { ...@@ -35,6 +35,14 @@ bool AppServiceAppIconLoader::CanLoadImageForApp(const std::string& app_id) {
// Chrome, which should be hidden. // Chrome, which should be hidden.
if (app_id == kArcIntentHelperAppId) if (app_id == kArcIntentHelperAppId)
return false; return false;
apps::AppServiceProxy* proxy =
apps::AppServiceProxyFactory::GetForProfile(profile());
if (!proxy || proxy->AppRegistryCache().GetAppType(app_id) ==
apps::mojom::AppType::kUnknown) {
return false;
}
return true; return true;
} }
......
...@@ -1303,6 +1303,17 @@ void ChromeLauncherController::AttachProfile(Profile* profile_to_attach) { ...@@ -1303,6 +1303,17 @@ void ChromeLauncherController::AttachProfile(Profile* profile_to_attach) {
std::make_unique<AppServiceAppIconLoader>( std::make_unique<AppServiceAppIconLoader>(
profile_, extension_misc::EXTENSION_ICON_MEDIUM, this); profile_, extension_misc::EXTENSION_ICON_MEDIUM, this);
app_icon_loaders_.push_back(std::move(app_service_app_icon_loader)); app_icon_loaders_.push_back(std::move(app_service_app_icon_loader));
// Some special extensions open new windows, and on Chrome OS, those windows
// should show the extension icon in the shelf. Extensions are not present
// in the App Service, so try loading extensions icon using
// ChromeAppIconLoader.
std::unique_ptr<extensions::ChromeAppIconLoader> chrome_app_icon_loader =
std::make_unique<extensions::ChromeAppIconLoader>(
profile_, extension_misc::EXTENSION_ICON_MEDIUM,
base::BindRepeating(&app_list::MaybeResizeAndPadIconForMd), this);
chrome_app_icon_loader->SetExtensionsOnly();
app_icon_loaders_.push_back(std::move(chrome_app_icon_loader));
} else { } else {
// TODO(skuhne): The AppIconLoaderImpl has the same problem. Each loaded // TODO(skuhne): The AppIconLoaderImpl has the same problem. Each loaded
// image is associated with a profile (its loader requires the profile). // image is associated with a profile (its loader requires the profile).
...@@ -1352,9 +1363,19 @@ void ChromeLauncherController::AttachProfile(Profile* profile_to_attach) { ...@@ -1352,9 +1363,19 @@ void ChromeLauncherController::AttachProfile(Profile* profile_to_attach) {
std::unique_ptr<LauncherAppUpdater> app_service_app_updater( std::unique_ptr<LauncherAppUpdater> app_service_app_updater(
new LauncherAppServiceAppUpdater(this, profile())); new LauncherAppServiceAppUpdater(this, profile()));
app_updaters_.push_back(std::move(app_service_app_updater)); app_updaters_.push_back(std::move(app_service_app_updater));
// Some special extensions open new windows, and on Chrome OS, those windows
// should show the extension icon in the shelf. Extensions are not present
// in the App Service, so use LauncherExtensionAppUpdater to handle
// extensions life-cycle events.
std::unique_ptr<LauncherExtensionAppUpdater> extension_app_updater(
new LauncherExtensionAppUpdater(this, profile(),
true /* extensions_only */));
app_updaters_.push_back(std::move(extension_app_updater));
} else { } else {
std::unique_ptr<LauncherAppUpdater> extension_app_updater( std::unique_ptr<LauncherAppUpdater> extension_app_updater(
new LauncherExtensionAppUpdater(this, profile())); new LauncherExtensionAppUpdater(this, profile(),
false /* extensions_only */));
app_updaters_.push_back(std::move(extension_app_updater)); app_updaters_.push_back(std::move(extension_app_updater));
if (arc::IsArcAllowedForProfile(profile())) { if (arc::IsArcAllowedForProfile(profile())) {
......
...@@ -13,10 +13,15 @@ ...@@ -13,10 +13,15 @@
LauncherExtensionAppUpdater::LauncherExtensionAppUpdater( LauncherExtensionAppUpdater::LauncherExtensionAppUpdater(
Delegate* delegate, Delegate* delegate,
content::BrowserContext* browser_context) content::BrowserContext* browser_context,
: LauncherAppUpdater(delegate, browser_context) { bool extensions_only)
: LauncherAppUpdater(delegate, browser_context),
extensions_only_(extensions_only) {
StartObservingExtensionRegistry(); StartObservingExtensionRegistry();
if (extensions_only)
return;
ArcAppListPrefs* prefs = ArcAppListPrefs::Get(browser_context); ArcAppListPrefs* prefs = ArcAppListPrefs::Get(browser_context);
if (prefs) if (prefs)
prefs->AddObserver(this); prefs->AddObserver(this);
...@@ -25,6 +30,9 @@ LauncherExtensionAppUpdater::LauncherExtensionAppUpdater( ...@@ -25,6 +30,9 @@ LauncherExtensionAppUpdater::LauncherExtensionAppUpdater(
LauncherExtensionAppUpdater::~LauncherExtensionAppUpdater() { LauncherExtensionAppUpdater::~LauncherExtensionAppUpdater() {
StopObservingExtensionRegistry(); StopObservingExtensionRegistry();
if (extensions_only_)
return;
ArcAppListPrefs* prefs = ArcAppListPrefs::Get(browser_context()); ArcAppListPrefs* prefs = ArcAppListPrefs::Get(browser_context());
if (prefs) if (prefs)
prefs->RemoveObserver(this); prefs->RemoveObserver(this);
...@@ -33,13 +41,17 @@ LauncherExtensionAppUpdater::~LauncherExtensionAppUpdater() { ...@@ -33,13 +41,17 @@ LauncherExtensionAppUpdater::~LauncherExtensionAppUpdater() {
void LauncherExtensionAppUpdater::OnExtensionLoaded( void LauncherExtensionAppUpdater::OnExtensionLoaded(
content::BrowserContext* browser_context, content::BrowserContext* browser_context,
const extensions::Extension* extension) { const extensions::Extension* extension) {
delegate()->OnAppInstalled(browser_context, extension->id()); if (ShouldHandleExtension(extension))
delegate()->OnAppInstalled(browser_context, extension->id());
} }
void LauncherExtensionAppUpdater::OnExtensionUnloaded( void LauncherExtensionAppUpdater::OnExtensionUnloaded(
content::BrowserContext* browser_context, content::BrowserContext* browser_context,
const extensions::Extension* extension, const extensions::Extension* extension,
extensions::UnloadedExtensionReason reason) { extensions::UnloadedExtensionReason reason) {
if (!ShouldHandleExtension(extension))
return;
if (reason == extensions::UnloadedExtensionReason::UNINSTALL) if (reason == extensions::UnloadedExtensionReason::UNINSTALL)
delegate()->OnAppUninstalledPrepared(browser_context, extension->id()); delegate()->OnAppUninstalledPrepared(browser_context, extension->id());
else else
...@@ -50,7 +62,8 @@ void LauncherExtensionAppUpdater::OnExtensionUninstalled( ...@@ -50,7 +62,8 @@ void LauncherExtensionAppUpdater::OnExtensionUninstalled(
content::BrowserContext* browser_context, content::BrowserContext* browser_context,
const extensions::Extension* extension, const extensions::Extension* extension,
extensions::UninstallReason reason) { extensions::UninstallReason reason) {
delegate()->OnAppUninstalled(browser_context, extension->id()); if (ShouldHandleExtension(extension))
delegate()->OnAppUninstalled(browser_context, extension->id());
} }
void LauncherExtensionAppUpdater::OnShutdown( void LauncherExtensionAppUpdater::OnShutdown(
...@@ -102,3 +115,8 @@ void LauncherExtensionAppUpdater::UpdateEquivalentApp( ...@@ -102,3 +115,8 @@ void LauncherExtensionAppUpdater::UpdateEquivalentApp(
for (const auto& iter : extension_ids) for (const auto& iter : extension_ids)
UpdateApp(iter); UpdateApp(iter);
} }
bool LauncherExtensionAppUpdater::ShouldHandleExtension(
const extensions::Extension* extension) const {
return !extensions_only_ || extension->is_extension();
}
...@@ -18,7 +18,8 @@ class LauncherExtensionAppUpdater ...@@ -18,7 +18,8 @@ class LauncherExtensionAppUpdater
public ArcAppListPrefs::Observer { public ArcAppListPrefs::Observer {
public: public:
LauncherExtensionAppUpdater(Delegate* delegate, LauncherExtensionAppUpdater(Delegate* delegate,
content::BrowserContext* browser_context); content::BrowserContext* browser_context,
bool extensions_only);
~LauncherExtensionAppUpdater() override; ~LauncherExtensionAppUpdater() override;
// ExtensionRegistryObserver: // ExtensionRegistryObserver:
...@@ -46,8 +47,14 @@ class LauncherExtensionAppUpdater ...@@ -46,8 +47,14 @@ class LauncherExtensionAppUpdater
void UpdateApp(const std::string& app_id); void UpdateApp(const std::string& app_id);
void UpdateEquivalentApp(const std::string& arc_package_name); void UpdateEquivalentApp(const std::string& arc_package_name);
bool ShouldHandleExtension(const extensions::Extension* extension) const;
extensions::ExtensionRegistry* extension_registry_ = nullptr; extensions::ExtensionRegistry* extension_registry_ = nullptr;
// Handles life-cycle events for extensions only if true, otherwise handles
// life-cycle events for both Chrome apps and extensions.
const bool extensions_only_;
DISALLOW_COPY_AND_ASSIGN(LauncherExtensionAppUpdater); DISALLOW_COPY_AND_ASSIGN(LauncherExtensionAppUpdater);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment