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

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

Issue 2629573004: Add a chrome://webapks page. (Closed)
Patch Set: Add a chrome://webapks page. 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::RetrieveWebApks(const WebApkInfoCallback& callback) {
286 uintptr_t callback_pointer =
287 reinterpret_cast<uintptr_t>(new WebApkInfoCallback(callback));
288 Java_ShortcutHelper_retrieveWebApks(base::android::AttachCurrentThread(),
289 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 OnWebApksRetrieved(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 DCHECK(short_names.size() == package_names.size());
330 DCHECK(short_names.size() == shell_apk_versions.size());
331 DCHECK(short_names.size() == version_codes.size());
332
333 std::vector<WebApkInfo> webapk_list;
334 webapk_list.reserve(short_names.size());
335 for (size_t i = 0; i < short_names.size(); ++i) {
336 webapk_list.push_back(WebApkInfo(std::move(short_names[i]),
337 std::move(package_names[i]),
338 shell_apk_versions[i], version_codes[i]));
339 }
340
341 ShortcutHelper::WebApkInfoCallback* webapk_list_callback =
342 reinterpret_cast<ShortcutHelper::WebApkInfoCallback*>(jcallback_pointer);
343 webapk_list_callback->Run(webapk_list);
344 delete webapk_list_callback;
345 }
346
302 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { 347 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) {
303 return RegisterNativesImpl(env); 348 return RegisterNativesImpl(env);
304 } 349 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698