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

Unified Diff: chrome/browser/android/shortcut_helper.h

Issue 601433002: Use Manifest.icons instead of favicon in ShortcutHelper when possible. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@manifest_icons_sizes
Patch Set: Created 6 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/shortcut_helper.h
diff --git a/chrome/browser/android/shortcut_helper.h b/chrome/browser/android/shortcut_helper.h
index 48009608c1f622ad46add5cdb937d5f210d006d6..fda61b8d98c521cb09a6264643bb4898754aed39 100644
--- a/chrome/browser/android/shortcut_helper.h
+++ b/chrome/browser/android/shortcut_helper.h
@@ -58,41 +58,105 @@ class ShortcutHelper : public content::WebContentsObserver {
jstring title,
jint launcher_large_icon_size);
- void FinishAddingShortcut(
+ // Callback run when the requested Manifest icon is ready to be used.
+ void OnDidDownloadIcon(int id,
+ int http_status_code,
+ const GURL& url,
+ const std::vector<SkBitmap>& bitmaps,
+ const std::vector<gfx::Size>& sizes);
+
+ // Called after AddShortcut() and OnDidDownloadIcon() are run if
+ // OnDidDownloadIcon has a valid icon.
+ void AddShortcutUsingManifestIcon();
+
+ // Use FaviconService to get the best available favicon and create the
+ // shortcut using it. This is used when no Manifest icons are available or
+ // appropriate.
+ void AddShortcutUsingFavicon();
+
+ // Callback run when a favicon is received from GetFavicon() call.
+ void OnDidGetFavicon(
const favicon_base::FaviconRawBitmapResult& bitmap_result);
// WebContentsObserver
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
virtual void WebContentsDestroyed() OVERRIDE;
- // Adds a shortcut to the launcher. Must be called from a WorkerPool task.
- static void AddShortcutInBackground(
+ // Adds a shortcut to the launcher using a FaviconRawBitmapResult.
+ // Must be called from a WorkerPool task.
+ static void AddShortcutInBackgroundWithRawBitmap(
const GURL& url,
const base::string16& title,
content::Manifest::DisplayMode display,
const favicon_base::FaviconRawBitmapResult& bitmap_result,
blink::WebScreenOrientationLockType orientation);
+ // Adds a shortcut to the launcher using a SkBitmap.
+ // Must be called from a WorkerPool task.
+ static void AddShortcutInBackgroundWithSkBitmap(
+ const GURL& url,
+ const base::string16& title,
+ content::Manifest::DisplayMode display,
+ const SkBitmap& icon_bitmap,
+ blink::WebScreenOrientationLockType orientation);
+
// Registers JNI hooks.
static bool RegisterShortcutHelper(JNIEnv* env);
private:
+ enum ManifestIconStatus {
+ MANIFEST_ICON_STATUS_NONE,
+ MANIFEST_ICON_STATUS_FETCHING,
+ MANIFEST_ICON_STATUS_DONE
+ };
+
virtual ~ShortcutHelper();
void Destroy();
+ // Runs the algorithm to find the best matching icon in the icons listed in
+ // the Manifest.
+ // Returns the icon url if a suitable icon is found. An empty URL otherwise.
+ GURL FindBestMatchingIcon(
+ const std::vector<content::Manifest::Icon>& icons) const;
+
+ // Runs an algorithm only based on icon declared sizes. It will try to find
+ // size that is the closest to preferred_icon_size_in_px_ but bigger than
+ // preferred_icon_size_in_px_ if possible.
+ // Returns the icon url if a suitable icon is found. An empty URL otherwise.
+ GURL FindBestMatchingIcon(const std::vector<content::Manifest::Icon>& icons,
+ float density) const;
+
+ // Returns an array containing the items in |icons| without the unsupported
+ // image MIME types.
+ static std::vector<content::Manifest::Icon> FilterIconsByType(
+ const std::vector<content::Manifest::Icon>& icons);
+
+ // Returns whether the preferred_icon_size_in_px_ is in the given |sizes|.
+ bool IconSizesContainsPreferredSize(
+ const std::vector<gfx::Size>& sizes) const;
+
+ // Returns whether the 'any' (ie. gfx::Size(0,0)) is in the given |sizes|.
+ bool IconSizesContainsAny(const std::vector<gfx::Size>& sizes) const;
+
JavaObjectWeakGlobalRef java_ref_;
GURL url_;
base::string16 title_;
- int launcher_large_icon_size_;
content::Manifest::DisplayMode display_;
- favicon_base::FaviconRawBitmapResult icon_;
+ SkBitmap manifest_icon_;
base::CancelableTaskTracker cancelable_task_tracker_;
blink::WebScreenOrientationLockType orientation_;
+ bool add_shortcut_requested_;
+
+ ManifestIconStatus manifest_icon_status_;
+ const int preferred_icon_size_in_px_;
+ static const int kPreferredIconSizeInDp;
+
base::WeakPtrFactory<ShortcutHelper> weak_ptr_factory_;
+ friend class ShortcutHelperTest;
DISALLOW_COPY_AND_ASSIGN(ShortcutHelper);
};
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/ShortcutHelper.java ('k') | chrome/browser/android/shortcut_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698