Have LoadIconFromExtension process icon images

Image processing includes converting to gray (for disabled extensions)
and rounding the corners (for bookmark apps).

BUG=826982

Change-Id: Ie49a8928678abd884302eacb7bef5f2c21e46a35
Reviewed-on: https://chromium-review.googlesource.com/c/1366462
Commit-Queue: Nigel Tao <[email protected]>
Reviewed-by: Devlin <[email protected]>
Reviewed-by: Dominick Ng <[email protected]>
Cr-Commit-Position: refs/heads/master@{#615745}
diff --git a/chrome/browser/extensions/chrome_app_icon.cc b/chrome/browser/extensions/chrome_app_icon.cc
index bda3466f..c318eb05 100644
--- a/chrome/browser/extensions/chrome_app_icon.cc
+++ b/chrome/browser/extensions/chrome_app_icon.cc
@@ -61,6 +61,37 @@
 
 }  // namespace
 
+// static
+void ChromeAppIcon::ApplyEffects(int resource_size_in_dip,
+                                 const ResizeFunction& resize_function,
+                                 bool apply_chrome_badge,
+                                 bool app_launchable,
+                                 bool from_bookmark,
+                                 gfx::ImageSkia* image_skia) {
+  if (!resize_function.is_null()) {
+    resize_function.Run(gfx::Size(resource_size_in_dip, resource_size_in_dip),
+                        image_skia);
+  }
+
+#if defined(OS_CHROMEOS)
+  if (apply_chrome_badge) {
+    util::ApplyChromeBadge(image_skia);
+  }
+#endif
+
+  if (!app_launchable) {
+    constexpr color_utils::HSL shift = {-1, 0, 0.6};
+    *image_skia =
+        gfx::ImageSkiaOperations::CreateHSLShiftedImage(*image_skia, shift);
+  }
+
+  if (from_bookmark) {
+    *image_skia =
+        gfx::ImageSkia(std::make_unique<RoundedCornersImageSource>(*image_skia),
+                       image_skia->size());
+  }
+}
+
 ChromeAppIcon::ChromeAppIcon(ChromeAppIconDelegate* delegate,
                              content::BrowserContext* browser_context,
                              DestroyedCallback destroyed_callback,
@@ -110,27 +141,21 @@
   DCHECK(icon_);
 
   image_skia_ = icon_->image_skia();
-  if (!resize_function_.is_null()) {
-    resize_function_.Run(
-        gfx::Size(resource_size_in_dip_, resource_size_in_dip_), &image_skia_);
-  }
+
+  bool apply_chrome_badge = false;
 #if defined(OS_CHROMEOS)
-  icon_is_badged_ =
-      util::MaybeApplyChromeBadge(browser_context_, app_id_, &image_skia_);
+  icon_is_badged_ = util::ShouldApplyChromeBadge(browser_context_, app_id_);
+  apply_chrome_badge = icon_is_badged_;
 #endif
 
-  if (!util::IsAppLaunchable(app_id_, browser_context_)) {
-    const color_utils::HSL shift = {-1, 0, 0.6};
-    image_skia_ =
-        gfx::ImageSkiaOperations::CreateHSLShiftedImage(image_skia_, shift);
-  }
+  bool app_launchable = util::IsAppLaunchable(app_id_, browser_context_);
 
-  const Extension* extension = GetExtension();
-  if (extension && extension->from_bookmark()) {
-    image_skia_ =
-        gfx::ImageSkia(std::make_unique<RoundedCornersImageSource>(image_skia_),
-                       image_skia_.size());
-  }
+  const Extension* extension =
+      ExtensionRegistry::Get(browser_context_)->GetInstalledExtension(app_id_);
+  bool from_bookmark = extension && extension->from_bookmark();
+
+  ApplyEffects(resource_size_in_dip_, resize_function_, apply_chrome_badge,
+               app_launchable, from_bookmark, &image_skia_);
 
   delegate_->OnIconUpdated(this);
 }