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

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

Issue 2629573004: Add a chrome://webapks page. (Closed)
Patch Set: Makes the listWebApks method receive a callback on the Java side Created 3 years, 11 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 #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 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_array.h" 10 #include "base/android/jni_array.h"
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 275
276 GURL ShortcutHelper::GetScopeFromURL(const GURL& url) { 276 GURL ShortcutHelper::GetScopeFromURL(const GURL& url) {
277 JNIEnv* env = base::android::AttachCurrentThread(); 277 JNIEnv* env = base::android::AttachCurrentThread();
278 ScopedJavaLocalRef<jstring> java_url = 278 ScopedJavaLocalRef<jstring> java_url =
279 base::android::ConvertUTF8ToJavaString(env, url.spec()); 279 base::android::ConvertUTF8ToJavaString(env, url.spec());
280 ScopedJavaLocalRef<jstring> java_scope_url = 280 ScopedJavaLocalRef<jstring> java_scope_url =
281 Java_ShortcutHelper_getScopeFromUrl(env, java_url); 281 Java_ShortcutHelper_getScopeFromUrl(env, java_url);
282 return GURL(base::android::ConvertJavaStringToUTF16(env, java_scope_url)); 282 return GURL(base::android::ConvertJavaStringToUTF16(env, java_scope_url));
283 } 283 }
284 284
285 void ShortcutHelper::ListWebApks(JNIEnv* env,
pkotwicz 2017/01/18 02:08:21 Nit: Remove the JNIEnv* parameter and call AttachC
gonzalon 2017/01/18 15:29:32 Done.
286 const base::Callback<void(std::vector<WebApkInfo*>)>& callback) {
287 uintptr_t callback_pointer = reinterpret_cast<uintptr_t>(
288 new base::Callback<void(std::vector<WebApkInfo*>)>(callback));
289 Java_ShortcutHelper_listWebApks(env, callback_pointer);
290 }
291
285 // Callback used by Java when the shortcut has been created. 292 // Callback used by Java when the shortcut has been created.
286 // |splash_image_callback| is a pointer to a base::Closure allocated in 293 // |splash_image_callback| is a pointer to a base::Closure allocated in
287 // AddShortcutWithSkBitmap, so reinterpret_cast it back and run it. 294 // AddShortcutWithSkBitmap, so reinterpret_cast it back and run it.
288 // 295 //
289 // This callback should only ever be called when the shortcut was for a 296 // This callback should only ever be called when the shortcut was for a
290 // webapp-capable site; otherwise, |splash_image_callback| will have never been 297 // webapp-capable site; otherwise, |splash_image_callback| will have never been
291 // allocated and doesn't need to be run or deleted. 298 // allocated and doesn't need to be run or deleted.
292 void OnWebappDataStored(JNIEnv* env, 299 void OnWebappDataStored(JNIEnv* env,
293 const JavaParamRef<jclass>& clazz, 300 const JavaParamRef<jclass>& clazz,
294 jlong jsplash_image_callback) { 301 jlong jsplash_image_callback) {
295 DCHECK(jsplash_image_callback); 302 DCHECK(jsplash_image_callback);
296 base::Closure* splash_image_callback = 303 base::Closure* splash_image_callback =
297 reinterpret_cast<base::Closure*>(jsplash_image_callback); 304 reinterpret_cast<base::Closure*>(jsplash_image_callback);
298 splash_image_callback->Run(); 305 splash_image_callback->Run();
299 delete splash_image_callback; 306 delete splash_image_callback;
300 } 307 }
301 308
309 void OnWebApksFound(JNIEnv* env,
310 const JavaParamRef<jclass>& clazz,
311 const jlong jcallback_pointer,
312 const JavaParamRef<jobjectArray>& jshort_names,
313 const JavaParamRef<jobjectArray>& jpackage_names,
314 const JavaParamRef<jintArray>& jshell_apk_versions,
315 const JavaParamRef<jintArray>& jversion_codes) {
316 DCHECK(jcallback_pointer);
317 std::vector<std::string> short_names;
318 base::android::AppendJavaStringArrayToStringVector(env, jshort_names,
319 &short_names);
320 std::vector<std::string> package_names;
321 base::android::AppendJavaStringArrayToStringVector(env, jpackage_names,
322 &package_names);
323 std::vector<int> shell_apk_versions;
324 base::android::JavaIntArrayToIntVector(env, jshell_apk_versions,
325 &shell_apk_versions);
326 std::vector<int> version_codes;
327 base::android::JavaIntArrayToIntVector(env, jversion_codes, &version_codes);
328
329 std::vector<WebApkInfo*> webapks_list;
pkotwicz 2017/01/18 02:08:21 Can this be std::vector<WebApkInfo> instead?
gonzalon 2017/01/18 15:29:32 Done.
330 for (size_t i = 0; i < short_names.size(); ++i) {
331 WebApkInfo* webapk_info =
332 new WebApkInfo(short_names[i], package_names[i], shell_apk_versions[i],
333 version_codes[i]);
334 webapks_list.push_back(webapk_info);
335 }
336
337 base::Callback<void(std::vector<WebApkInfo*>)>* webapks_list_callback =
338 reinterpret_cast<base::Callback<void(std::vector<WebApkInfo*>)>*>(
339 jcallback_pointer);
340 webapks_list_callback->Run(webapks_list);
341 delete webapks_list_callback;
342 }
343
302 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { 344 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) {
303 return RegisterNativesImpl(env); 345 return RegisterNativesImpl(env);
304 } 346 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698