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

Side by Side 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, 2 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #ifndef CHROME_BROWSER_ANDROID_SHORTCUT_HELPER_H_ 5 #ifndef CHROME_BROWSER_ANDROID_SHORTCUT_HELPER_H_
6 #define CHROME_BROWSER_ANDROID_SHORTCUT_HELPER_H_ 6 #define CHROME_BROWSER_ANDROID_SHORTCUT_HELPER_H_
7 7
8 #include "base/android/jni_android.h" 8 #include "base/android/jni_android.h"
9 #include "base/android/jni_weak_ref.h" 9 #include "base/android/jni_weak_ref.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 // Callback run when the Manifest is ready to be used. 52 // Callback run when the Manifest is ready to be used.
53 void OnDidGetManifest(const content::Manifest& manifest); 53 void OnDidGetManifest(const content::Manifest& manifest);
54 54
55 // Adds a shortcut to the current URL to the Android home screen. 55 // Adds a shortcut to the current URL to the Android home screen.
56 void AddShortcut(JNIEnv* env, 56 void AddShortcut(JNIEnv* env,
57 jobject obj, 57 jobject obj,
58 jstring title, 58 jstring title,
59 jint launcher_large_icon_size); 59 jint launcher_large_icon_size);
60 60
61 void FinishAddingShortcut( 61 // Callback run when the requested Manifest icon is ready to be used.
62 void OnDidDownloadIcon(int id,
63 int http_status_code,
64 const GURL& url,
65 const std::vector<SkBitmap>& bitmaps,
66 const std::vector<gfx::Size>& sizes);
67
68 // Called after AddShortcut() and OnDidDownloadIcon() are run if
69 // OnDidDownloadIcon has a valid icon.
70 void AddShortcutUsingManifestIcon();
71
72 // Use FaviconService to get the best available favicon and create the
73 // shortcut using it. This is used when no Manifest icons are available or
74 // appropriate.
75 void AddShortcutUsingFavicon();
76
77 // Callback run when a favicon is received from GetFavicon() call.
78 void OnDidGetFavicon(
62 const favicon_base::FaviconRawBitmapResult& bitmap_result); 79 const favicon_base::FaviconRawBitmapResult& bitmap_result);
63 80
64 // WebContentsObserver 81 // WebContentsObserver
65 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 82 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
66 virtual void WebContentsDestroyed() OVERRIDE; 83 virtual void WebContentsDestroyed() OVERRIDE;
67 84
68 // Adds a shortcut to the launcher. Must be called from a WorkerPool task. 85 // Adds a shortcut to the launcher using a FaviconRawBitmapResult.
69 static void AddShortcutInBackground( 86 // Must be called from a WorkerPool task.
87 static void AddShortcutInBackgroundWithRawBitmap(
70 const GURL& url, 88 const GURL& url,
71 const base::string16& title, 89 const base::string16& title,
72 content::Manifest::DisplayMode display, 90 content::Manifest::DisplayMode display,
73 const favicon_base::FaviconRawBitmapResult& bitmap_result, 91 const favicon_base::FaviconRawBitmapResult& bitmap_result,
74 blink::WebScreenOrientationLockType orientation); 92 blink::WebScreenOrientationLockType orientation);
75 93
94 // Adds a shortcut to the launcher using a SkBitmap.
95 // Must be called from a WorkerPool task.
96 static void AddShortcutInBackgroundWithSkBitmap(
97 const GURL& url,
98 const base::string16& title,
99 content::Manifest::DisplayMode display,
100 const SkBitmap& icon_bitmap,
101 blink::WebScreenOrientationLockType orientation);
102
76 // Registers JNI hooks. 103 // Registers JNI hooks.
77 static bool RegisterShortcutHelper(JNIEnv* env); 104 static bool RegisterShortcutHelper(JNIEnv* env);
78 105
79 private: 106 private:
107 enum ManifestIconStatus {
108 MANIFEST_ICON_STATUS_NONE,
109 MANIFEST_ICON_STATUS_FETCHING,
110 MANIFEST_ICON_STATUS_DONE
111 };
112
80 virtual ~ShortcutHelper(); 113 virtual ~ShortcutHelper();
81 114
82 void Destroy(); 115 void Destroy();
83 116
117 // Runs the algorithm to find the best matching icon in the icons listed in
118 // the Manifest.
119 // Returns the icon url if a suitable icon is found. An empty URL otherwise.
120 GURL FindBestMatchingIcon(
121 const std::vector<content::Manifest::Icon>& icons) const;
122
123 // Runs an algorithm only based on icon declared sizes. It will try to find
124 // size that is the closest to preferred_icon_size_in_px_ but bigger than
125 // preferred_icon_size_in_px_ if possible.
126 // Returns the icon url if a suitable icon is found. An empty URL otherwise.
127 GURL FindBestMatchingIcon(const std::vector<content::Manifest::Icon>& icons,
128 float density) const;
129
130 // Returns an array containing the items in |icons| without the unsupported
131 // image MIME types.
132 static std::vector<content::Manifest::Icon> FilterIconsByType(
133 const std::vector<content::Manifest::Icon>& icons);
134
135 // Returns whether the preferred_icon_size_in_px_ is in the given |sizes|.
136 bool IconSizesContainsPreferredSize(
137 const std::vector<gfx::Size>& sizes) const;
138
139 // Returns whether the 'any' (ie. gfx::Size(0,0)) is in the given |sizes|.
140 bool IconSizesContainsAny(const std::vector<gfx::Size>& sizes) const;
141
84 JavaObjectWeakGlobalRef java_ref_; 142 JavaObjectWeakGlobalRef java_ref_;
85 143
86 GURL url_; 144 GURL url_;
87 base::string16 title_; 145 base::string16 title_;
88 int launcher_large_icon_size_;
89 content::Manifest::DisplayMode display_; 146 content::Manifest::DisplayMode display_;
90 favicon_base::FaviconRawBitmapResult icon_; 147 SkBitmap manifest_icon_;
91 base::CancelableTaskTracker cancelable_task_tracker_; 148 base::CancelableTaskTracker cancelable_task_tracker_;
92 blink::WebScreenOrientationLockType orientation_; 149 blink::WebScreenOrientationLockType orientation_;
93 150
151 bool add_shortcut_requested_;
152
153 ManifestIconStatus manifest_icon_status_;
154 const int preferred_icon_size_in_px_;
155 static const int kPreferredIconSizeInDp;
156
94 base::WeakPtrFactory<ShortcutHelper> weak_ptr_factory_; 157 base::WeakPtrFactory<ShortcutHelper> weak_ptr_factory_;
95 158
159 friend class ShortcutHelperTest;
96 DISALLOW_COPY_AND_ASSIGN(ShortcutHelper); 160 DISALLOW_COPY_AND_ASSIGN(ShortcutHelper);
97 }; 161 };
98 162
99 #endif // CHROME_BROWSER_ANDROID_SHORTCUT_HELPER_H_ 163 #endif // CHROME_BROWSER_ANDROID_SHORTCUT_HELPER_H_
OLDNEW
« 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