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

Side by Side Diff: chrome/browser/android/shortcut_helper.cc

Issue 899543003: Break out more manifest parsing logic from ShortcutHelper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing Created 5 years, 10 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
« no previous file with comments | « chrome/browser/android/shortcut_helper.h ('k') | chrome/browser/android/shortcut_info.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "chrome/browser/android/shortcut_helper.h" 5 #include "chrome/browser/android/shortcut_helper.h"
6 6
7 #include <jni.h> 7 #include <jni.h>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/android/jni_android.h" 10 #include "base/android/jni_android.h"
(...skipping 13 matching lines...) Expand all
24 #include "chrome/common/render_messages.h" 24 #include "chrome/common/render_messages.h"
25 #include "chrome/common/web_application_info.h" 25 #include "chrome/common/web_application_info.h"
26 #include "components/dom_distiller/core/url_utils.h" 26 #include "components/dom_distiller/core/url_utils.h"
27 #include "content/public/browser/user_metrics.h" 27 #include "content/public/browser/user_metrics.h"
28 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
29 #include "content/public/browser/web_contents_observer.h" 29 #include "content/public/browser/web_contents_observer.h"
30 #include "content/public/common/frame_navigate_params.h" 30 #include "content/public/common/frame_navigate_params.h"
31 #include "content/public/common/manifest.h" 31 #include "content/public/common/manifest.h"
32 #include "jni/ShortcutHelper_jni.h" 32 #include "jni/ShortcutHelper_jni.h"
33 #include "net/base/mime_util.h" 33 #include "net/base/mime_util.h"
34 #include "third_party/WebKit/public/platform/WebScreenOrientationLockType.h"
34 #include "ui/gfx/android/java_bitmap.h" 35 #include "ui/gfx/android/java_bitmap.h"
35 #include "ui/gfx/codec/png_codec.h" 36 #include "ui/gfx/codec/png_codec.h"
36 #include "ui/gfx/color_analysis.h" 37 #include "ui/gfx/color_analysis.h"
37 #include "ui/gfx/favicon_size.h" 38 #include "ui/gfx/favicon_size.h"
38 #include "ui/gfx/screen.h" 39 #include "ui/gfx/screen.h"
39 #include "url/gurl.h" 40 #include "url/gurl.h"
40 41
41 using content::Manifest; 42 using content::Manifest;
42 43
43 // Android's preferred icon size in DP is 48, as defined in 44 // Android's preferred icon size in DP is 48, as defined in
44 // http://developer.android.com/design/style/iconography.html 45 // http://developer.android.com/design/style/iconography.html
45 const int ShortcutHelper::kPreferredIconSizeInDp = 48; 46 const int ShortcutHelper::kPreferredIconSizeInDp = 48;
46 47
47 jlong Initialize(JNIEnv* env, jobject obj, jlong tab_android_ptr) { 48 jlong Initialize(JNIEnv* env, jobject obj, jlong tab_android_ptr) {
48 TabAndroid* tab = reinterpret_cast<TabAndroid*>(tab_android_ptr); 49 TabAndroid* tab = reinterpret_cast<TabAndroid*>(tab_android_ptr);
49 50
50 ShortcutHelper* shortcut_helper = 51 ShortcutHelper* shortcut_helper =
51 new ShortcutHelper(env, obj, tab->web_contents()); 52 new ShortcutHelper(env, obj, tab->web_contents());
52 shortcut_helper->Initialize(); 53 shortcut_helper->Initialize();
53 54
54 return reinterpret_cast<intptr_t>(shortcut_helper); 55 return reinterpret_cast<intptr_t>(shortcut_helper);
55 } 56 }
56 57
57 ShortcutHelper::ShortcutHelper(JNIEnv* env, 58 ShortcutHelper::ShortcutHelper(JNIEnv* env,
58 jobject obj, 59 jobject obj,
59 content::WebContents* web_contents) 60 content::WebContents* web_contents)
60 : WebContentsObserver(web_contents), 61 : WebContentsObserver(web_contents),
61 java_ref_(env, obj), 62 java_ref_(env, obj),
62 url_(dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl( 63 shortcut_info_(dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl(
63 web_contents->GetURL())), 64 web_contents->GetURL())),
64 display_(content::Manifest::DISPLAY_MODE_BROWSER),
65 orientation_(blink::WebScreenOrientationLockDefault),
66 add_shortcut_requested_(false), 65 add_shortcut_requested_(false),
67 manifest_icon_status_(MANIFEST_ICON_STATUS_NONE), 66 manifest_icon_status_(MANIFEST_ICON_STATUS_NONE),
68 preferred_icon_size_in_px_(kPreferredIconSizeInDp * 67 preferred_icon_size_in_px_(kPreferredIconSizeInDp *
69 gfx::Screen::GetScreenFor(web_contents->GetNativeView())-> 68 gfx::Screen::GetScreenFor(web_contents->GetNativeView())->
70 GetPrimaryDisplay().device_scale_factor()), 69 GetPrimaryDisplay().device_scale_factor()),
71 weak_ptr_factory_(this) { 70 weak_ptr_factory_(this) {
72 } 71 }
73 72
74 void ShortcutHelper::Initialize() { 73 void ShortcutHelper::Initialize() {
75 // Send a message to the renderer to retrieve information about the page. 74 // Send a message to the renderer to retrieve information about the page.
76 Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id())); 75 Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id()));
77 } 76 }
78 77
79 ShortcutHelper::~ShortcutHelper() { 78 ShortcutHelper::~ShortcutHelper() {
80 } 79 }
81 80
82 void ShortcutHelper::OnDidGetWebApplicationInfo( 81 void ShortcutHelper::OnDidGetWebApplicationInfo(
83 const WebApplicationInfo& received_web_app_info) { 82 const WebApplicationInfo& received_web_app_info) {
84 // Sanitize received_web_app_info. 83 // Sanitize received_web_app_info.
85 WebApplicationInfo web_app_info = received_web_app_info; 84 WebApplicationInfo web_app_info = received_web_app_info;
86 web_app_info.title = 85 web_app_info.title =
87 web_app_info.title.substr(0, chrome::kMaxMetaTagAttributeLength); 86 web_app_info.title.substr(0, chrome::kMaxMetaTagAttributeLength);
88 web_app_info.description = 87 web_app_info.description =
89 web_app_info.description.substr(0, chrome::kMaxMetaTagAttributeLength); 88 web_app_info.description.substr(0, chrome::kMaxMetaTagAttributeLength);
90 89
91 title_ = web_app_info.title.empty() ? web_contents()->GetTitle() 90 shortcut_info_.title = web_app_info.title.empty() ? web_contents()->GetTitle()
92 : web_app_info.title; 91 : web_app_info.title;
93 92
94 if (web_app_info.mobile_capable == WebApplicationInfo::MOBILE_CAPABLE || 93 if (web_app_info.mobile_capable == WebApplicationInfo::MOBILE_CAPABLE ||
95 web_app_info.mobile_capable == WebApplicationInfo::MOBILE_CAPABLE_APPLE) { 94 web_app_info.mobile_capable == WebApplicationInfo::MOBILE_CAPABLE_APPLE) {
96 display_ = content::Manifest::DISPLAY_MODE_STANDALONE; 95 shortcut_info_.display = content::Manifest::DISPLAY_MODE_STANDALONE;
97 } 96 }
98 97
99 // Record what type of shortcut was added by the user. 98 // Record what type of shortcut was added by the user.
100 switch (web_app_info.mobile_capable) { 99 switch (web_app_info.mobile_capable) {
101 case WebApplicationInfo::MOBILE_CAPABLE: 100 case WebApplicationInfo::MOBILE_CAPABLE:
102 content::RecordAction( 101 content::RecordAction(
103 base::UserMetricsAction("webapps.AddShortcut.AppShortcut")); 102 base::UserMetricsAction("webapps.AddShortcut.AppShortcut"));
104 break; 103 break;
105 case WebApplicationInfo::MOBILE_CAPABLE_APPLE: 104 case WebApplicationInfo::MOBILE_CAPABLE_APPLE:
106 content::RecordAction( 105 content::RecordAction(
107 base::UserMetricsAction("webapps.AddShortcut.AppShortcutApple")); 106 base::UserMetricsAction("webapps.AddShortcut.AppShortcutApple"));
108 break; 107 break;
109 case WebApplicationInfo::MOBILE_CAPABLE_UNSPECIFIED: 108 case WebApplicationInfo::MOBILE_CAPABLE_UNSPECIFIED:
110 content::RecordAction( 109 content::RecordAction(
111 base::UserMetricsAction("webapps.AddShortcut.Bookmark")); 110 base::UserMetricsAction("webapps.AddShortcut.Bookmark"));
112 break; 111 break;
113 } 112 }
114 113
115 web_contents()->GetManifest(base::Bind(&ShortcutHelper::OnDidGetManifest, 114 web_contents()->GetManifest(base::Bind(&ShortcutHelper::OnDidGetManifest,
116 weak_ptr_factory_.GetWeakPtr())); 115 weak_ptr_factory_.GetWeakPtr()));
117 } 116 }
118 117
119 void ShortcutHelper::OnDidGetManifest(const content::Manifest& manifest) { 118 void ShortcutHelper::OnDidGetManifest(const content::Manifest& manifest) {
120 if (!manifest.IsEmpty()) { 119 if (!manifest.IsEmpty()) {
121 content::RecordAction( 120 content::RecordAction(
122 base::UserMetricsAction("webapps.AddShortcut.Manifest")); 121 base::UserMetricsAction("webapps.AddShortcut.Manifest"));
123 } 122 }
124 123
125 // Set the title based on the manifest value, if any. 124 shortcut_info_.UpdateFromManifest(manifest);
126 if (!manifest.short_name.is_null())
127 title_ = manifest.short_name.string();
128 else if (!manifest.name.is_null())
129 title_ = manifest.name.string();
130
131 // Set the url based on the manifest value, if any.
132 if (manifest.start_url.is_valid())
133 url_ = manifest.start_url;
134
135 // Set the display based on the manifest value, if any.
136 if (manifest.display != content::Manifest::DISPLAY_MODE_UNSPECIFIED)
137 display_ = manifest.display;
138
139 // 'fullscreen' and 'minimal-ui' are not yet supported, fallback to the right
140 // mode in those cases.
141 if (manifest.display == content::Manifest::DISPLAY_MODE_FULLSCREEN)
142 display_ = content::Manifest::DISPLAY_MODE_STANDALONE;
143 if (manifest.display == content::Manifest::DISPLAY_MODE_MINIMAL_UI)
144 display_ = content::Manifest::DISPLAY_MODE_BROWSER;
145
146 // Set the orientation based on the manifest value, if any.
147 if (manifest.orientation != blink::WebScreenOrientationLockDefault) {
148 // Ignore the orientation if the display mode is different from
149 // 'standalone'.
150 // TODO(mlamouri): send a message to the developer console about this.
151 if (display_ == content::Manifest::DISPLAY_MODE_STANDALONE)
152 orientation_ = manifest.orientation;
153 }
154 125
155 GURL icon_src = ManifestIconSelector::FindBestMatchingIcon( 126 GURL icon_src = ManifestIconSelector::FindBestMatchingIcon(
156 manifest.icons, 127 manifest.icons,
157 kPreferredIconSizeInDp, 128 kPreferredIconSizeInDp,
158 gfx::Screen::GetScreenFor(web_contents()->GetNativeView())); 129 gfx::Screen::GetScreenFor(web_contents()->GetNativeView()));
159 if (icon_src.is_valid()) { 130 if (icon_src.is_valid()) {
160 web_contents()->DownloadImage(icon_src, 131 web_contents()->DownloadImage(icon_src,
161 false, 132 false,
162 preferred_icon_size_in_px_, 133 preferred_icon_size_in_px_,
163 base::Bind(&ShortcutHelper::OnDidDownloadIcon, 134 base::Bind(&ShortcutHelper::OnDidDownloadIcon,
164 weak_ptr_factory_.GetWeakPtr())); 135 weak_ptr_factory_.GetWeakPtr()));
165 manifest_icon_status_ = MANIFEST_ICON_STATUS_FETCHING; 136 manifest_icon_status_ = MANIFEST_ICON_STATUS_FETCHING;
166 } 137 }
167 138
168 // The ShortcutHelper is now able to notify its Java counterpart that it is 139 // The ShortcutHelper is now able to notify its Java counterpart that it is
169 // initialized. OnInitialized method is not conceptually part of getting the 140 // initialized. OnInitialized method is not conceptually part of getting the
170 // manifest data but it happens that the initialization is finalized when 141 // manifest data but it happens that the initialization is finalized when
171 // these data are available. 142 // these data are available.
172 JNIEnv* env = base::android::AttachCurrentThread(); 143 JNIEnv* env = base::android::AttachCurrentThread();
173 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env); 144 ScopedJavaLocalRef<jobject> j_obj = java_ref_.get(env);
174 ScopedJavaLocalRef<jstring> j_title = 145 ScopedJavaLocalRef<jstring> j_title =
175 base::android::ConvertUTF16ToJavaString(env, title_); 146 base::android::ConvertUTF16ToJavaString(env, shortcut_info_.title);
176 147
177 Java_ShortcutHelper_onInitialized(env, j_obj.obj(), j_title.obj()); 148 Java_ShortcutHelper_onInitialized(env, j_obj.obj(), j_title.obj());
178 } 149 }
179 150
180 void ShortcutHelper::OnDidDownloadIcon(int id, 151 void ShortcutHelper::OnDidDownloadIcon(int id,
181 int http_status_code, 152 int http_status_code,
182 const GURL& url, 153 const GURL& url,
183 const std::vector<SkBitmap>& bitmaps, 154 const std::vector<SkBitmap>& bitmaps,
184 const std::vector<gfx::Size>& sizes) { 155 const std::vector<gfx::Size>& sizes) {
185 // If getting the candidate manifest icon failed, the ShortcutHelper should 156 // If getting the candidate manifest icon failed, the ShortcutHelper should
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 192
222 void ShortcutHelper::AddShortcut( 193 void ShortcutHelper::AddShortcut(
223 JNIEnv* env, 194 JNIEnv* env,
224 jobject obj, 195 jobject obj,
225 jstring jtitle, 196 jstring jtitle,
226 jint launcher_large_icon_size) { 197 jint launcher_large_icon_size) {
227 add_shortcut_requested_ = true; 198 add_shortcut_requested_ = true;
228 199
229 base::string16 title = base::android::ConvertJavaStringToUTF16(env, jtitle); 200 base::string16 title = base::android::ConvertJavaStringToUTF16(env, jtitle);
230 if (!title.empty()) 201 if (!title.empty())
231 title_ = title; 202 shortcut_info_.title = title;
232 203
233 switch (manifest_icon_status_) { 204 switch (manifest_icon_status_) {
234 case MANIFEST_ICON_STATUS_NONE: 205 case MANIFEST_ICON_STATUS_NONE:
235 AddShortcutUsingFavicon(); 206 AddShortcutUsingFavicon();
236 break; 207 break;
237 case MANIFEST_ICON_STATUS_FETCHING: 208 case MANIFEST_ICON_STATUS_FETCHING:
238 // ::OnDidDownloadIcon() will call AddShortcutUsingManifestIcon(). 209 // ::OnDidDownloadIcon() will call AddShortcutUsingManifestIcon().
239 break; 210 break;
240 case MANIFEST_ICON_STATUS_DONE: 211 case MANIFEST_ICON_STATUS_DONE:
241 AddShortcutUsingManifestIcon(); 212 AddShortcutUsingManifestIcon();
242 break; 213 break;
243 } 214 }
244 } 215 }
245 216
246 void ShortcutHelper::AddShortcutUsingManifestIcon() { 217 void ShortcutHelper::AddShortcutUsingManifestIcon() {
247 // Stop observing so we don't get destroyed while doing the last steps. 218 // Stop observing so we don't get destroyed while doing the last steps.
248 Observe(NULL); 219 Observe(NULL);
249 220
250 base::WorkerPool::PostTask( 221 base::WorkerPool::PostTask(
251 FROM_HERE, 222 FROM_HERE,
252 base::Bind(&ShortcutHelper::AddShortcutInBackgroundWithSkBitmap, 223 base::Bind(&ShortcutHelper::AddShortcutInBackgroundWithSkBitmap,
253 url_, 224 shortcut_info_,
254 title_, 225 manifest_icon_),
255 display_,
256 manifest_icon_,
257 orientation_),
258 true); 226 true);
259 227
260 Destroy(); 228 Destroy();
261 } 229 }
262 230
263 void ShortcutHelper::AddShortcutUsingFavicon() { 231 void ShortcutHelper::AddShortcutUsingFavicon() {
264 Profile* profile = 232 Profile* profile =
265 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 233 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
266 234
267 // Grab the best, largest icon we can find to represent this bookmark. 235 // Grab the best, largest icon we can find to represent this bookmark.
268 // TODO(dfalcantara): Try combining with the new BookmarksHandler once its 236 // TODO(dfalcantara): Try combining with the new BookmarksHandler once its
269 // rewrite is further along. 237 // rewrite is further along.
270 std::vector<int> icon_types; 238 std::vector<int> icon_types;
271 icon_types.push_back(favicon_base::FAVICON); 239 icon_types.push_back(favicon_base::FAVICON);
272 icon_types.push_back(favicon_base::TOUCH_PRECOMPOSED_ICON | 240 icon_types.push_back(favicon_base::TOUCH_PRECOMPOSED_ICON |
273 favicon_base::TOUCH_ICON); 241 favicon_base::TOUCH_ICON);
274 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( 242 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile(
275 profile, ServiceAccessType::EXPLICIT_ACCESS); 243 profile, ServiceAccessType::EXPLICIT_ACCESS);
276 244
277 // Using favicon if its size is not smaller than platform required size, 245 // Using favicon if its size is not smaller than platform required size,
278 // otherwise using the largest icon among all avaliable icons. 246 // otherwise using the largest icon among all avaliable icons.
279 int threshold_to_get_any_largest_icon = preferred_icon_size_in_px_ - 1; 247 int threshold_to_get_any_largest_icon = preferred_icon_size_in_px_ - 1;
280 favicon_service->GetLargestRawFaviconForPageURL(url_, icon_types, 248 favicon_service->GetLargestRawFaviconForPageURL(
249 shortcut_info_.url,
250 icon_types,
281 threshold_to_get_any_largest_icon, 251 threshold_to_get_any_largest_icon,
282 base::Bind(&ShortcutHelper::OnDidGetFavicon, 252 base::Bind(&ShortcutHelper::OnDidGetFavicon,
283 base::Unretained(this)), 253 base::Unretained(this)),
284 &cancelable_task_tracker_); 254 &cancelable_task_tracker_);
285 } 255 }
286 256
287 void ShortcutHelper::OnDidGetFavicon( 257 void ShortcutHelper::OnDidGetFavicon(
288 const favicon_base::FaviconRawBitmapResult& bitmap_result) { 258 const favicon_base::FaviconRawBitmapResult& bitmap_result) {
289 // Stop observing so we don't get destroyed while doing the last steps. 259 // Stop observing so we don't get destroyed while doing the last steps.
290 Observe(NULL); 260 Observe(NULL);
291 261
292 base::WorkerPool::PostTask( 262 base::WorkerPool::PostTask(
293 FROM_HERE, 263 FROM_HERE,
294 base::Bind(&ShortcutHelper::AddShortcutInBackgroundWithRawBitmap, 264 base::Bind(&ShortcutHelper::AddShortcutInBackgroundWithRawBitmap,
295 url_, 265 shortcut_info_,
296 title_, 266 bitmap_result),
297 display_,
298 bitmap_result,
299 orientation_),
300 true); 267 true);
301 268
302 Destroy(); 269 Destroy();
303 } 270 }
304 271
305 bool ShortcutHelper::OnMessageReceived(const IPC::Message& message) { 272 bool ShortcutHelper::OnMessageReceived(const IPC::Message& message) {
306 bool handled = true; 273 bool handled = true;
307 274
308 IPC_BEGIN_MESSAGE_MAP(ShortcutHelper, message) 275 IPC_BEGIN_MESSAGE_MAP(ShortcutHelper, message)
309 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidGetWebApplicationInfo, 276 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DidGetWebApplicationInfo,
310 OnDidGetWebApplicationInfo) 277 OnDidGetWebApplicationInfo)
311 IPC_MESSAGE_UNHANDLED(handled = false) 278 IPC_MESSAGE_UNHANDLED(handled = false)
312 IPC_END_MESSAGE_MAP() 279 IPC_END_MESSAGE_MAP()
313 280
314 return handled; 281 return handled;
315 } 282 }
316 283
317 void ShortcutHelper::WebContentsDestroyed() { 284 void ShortcutHelper::WebContentsDestroyed() {
318 Destroy(); 285 Destroy();
319 } 286 }
320 287
321 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { 288 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) {
322 return RegisterNativesImpl(env); 289 return RegisterNativesImpl(env);
323 } 290 }
324 291
325 void ShortcutHelper::AddShortcutInBackgroundWithRawBitmap( 292 void ShortcutHelper::AddShortcutInBackgroundWithRawBitmap(
326 const GURL& url, 293 const ShortcutInfo& info,
327 const base::string16& title, 294 const favicon_base::FaviconRawBitmapResult& bitmap_result) {
328 content::Manifest::DisplayMode display,
329 const favicon_base::FaviconRawBitmapResult& bitmap_result,
330 blink::WebScreenOrientationLockType orientation) {
331 DCHECK(base::WorkerPool::RunsTasksOnCurrentThread()); 295 DCHECK(base::WorkerPool::RunsTasksOnCurrentThread());
332 296
333 SkBitmap icon_bitmap; 297 SkBitmap icon_bitmap;
334 if (bitmap_result.is_valid()) { 298 if (bitmap_result.is_valid()) {
335 gfx::PNGCodec::Decode(bitmap_result.bitmap_data->front(), 299 gfx::PNGCodec::Decode(bitmap_result.bitmap_data->front(),
336 bitmap_result.bitmap_data->size(), 300 bitmap_result.bitmap_data->size(),
337 &icon_bitmap); 301 &icon_bitmap);
338 } 302 }
339 303
340 AddShortcutInBackgroundWithSkBitmap( 304 AddShortcutInBackgroundWithSkBitmap(info, icon_bitmap);
341 url, title, display, icon_bitmap, orientation);
342 } 305 }
343 306
344 void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap( 307 void ShortcutHelper::AddShortcutInBackgroundWithSkBitmap(
345 const GURL& url, 308 const ShortcutInfo& info,
346 const base::string16& title, 309 const SkBitmap& icon_bitmap) {
347 content::Manifest::DisplayMode display,
348 const SkBitmap& icon_bitmap,
349 blink::WebScreenOrientationLockType orientation) {
350 DCHECK(base::WorkerPool::RunsTasksOnCurrentThread()); 310 DCHECK(base::WorkerPool::RunsTasksOnCurrentThread());
351 311
352 SkColor color = color_utils::CalculateKMeanColorOfBitmap(icon_bitmap); 312 SkColor color = color_utils::CalculateKMeanColorOfBitmap(icon_bitmap);
353 int r_value = SkColorGetR(color); 313 int r_value = SkColorGetR(color);
354 int g_value = SkColorGetG(color); 314 int g_value = SkColorGetG(color);
355 int b_value = SkColorGetB(color); 315 int b_value = SkColorGetB(color);
356 316
357 // Send the data to the Java side to create the shortcut. 317 // Send the data to the Java side to create the shortcut.
358 JNIEnv* env = base::android::AttachCurrentThread(); 318 JNIEnv* env = base::android::AttachCurrentThread();
359 ScopedJavaLocalRef<jstring> java_url = 319 ScopedJavaLocalRef<jstring> java_url =
360 base::android::ConvertUTF8ToJavaString(env, url.spec()); 320 base::android::ConvertUTF8ToJavaString(env, info.url.spec());
361 ScopedJavaLocalRef<jstring> java_title = 321 ScopedJavaLocalRef<jstring> java_title =
362 base::android::ConvertUTF16ToJavaString(env, title); 322 base::android::ConvertUTF16ToJavaString(env, info.title);
363 ScopedJavaLocalRef<jobject> java_bitmap; 323 ScopedJavaLocalRef<jobject> java_bitmap;
364 if (icon_bitmap.getSize()) 324 if (icon_bitmap.getSize())
365 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap); 325 java_bitmap = gfx::ConvertToJavaBitmap(&icon_bitmap);
366 326
367 Java_ShortcutHelper_addShortcut( 327 Java_ShortcutHelper_addShortcut(
368 env, 328 env,
369 base::android::GetApplicationContext(), 329 base::android::GetApplicationContext(),
370 java_url.obj(), 330 java_url.obj(),
371 java_title.obj(), 331 java_title.obj(),
372 java_bitmap.obj(), 332 java_bitmap.obj(),
373 r_value, 333 r_value,
374 g_value, 334 g_value,
375 b_value, 335 b_value,
376 display == content::Manifest::DISPLAY_MODE_STANDALONE, 336 info.display == content::Manifest::DISPLAY_MODE_STANDALONE,
377 orientation); 337 info.orientation);
378 } 338 }
OLDNEW
« no previous file with comments | « chrome/browser/android/shortcut_helper.h ('k') | chrome/browser/android/shortcut_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698