| OLD | NEW |
| 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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 } | 276 } |
| 277 | 277 |
| 278 // static | 278 // static |
| 279 bool ShortcutHelper::IsWebApkInstalled(const GURL& url) { | 279 bool ShortcutHelper::IsWebApkInstalled(const GURL& url) { |
| 280 JNIEnv* env = base::android::AttachCurrentThread(); | 280 JNIEnv* env = base::android::AttachCurrentThread(); |
| 281 ScopedJavaLocalRef<jstring> java_url = | 281 ScopedJavaLocalRef<jstring> java_url = |
| 282 base::android::ConvertUTF8ToJavaString(env, url.spec()); | 282 base::android::ConvertUTF8ToJavaString(env, url.spec()); |
| 283 return Java_ShortcutHelper_isWebApkInstalled(env, java_url.obj()); | 283 return Java_ShortcutHelper_isWebApkInstalled(env, java_url.obj()); |
| 284 } | 284 } |
| 285 | 285 |
| 286 GURL ShortcutHelper::GetScopeFromURL(const GURL& url) { |
| 287 JNIEnv* env = base::android::AttachCurrentThread(); |
| 288 ScopedJavaLocalRef<jstring> java_url = |
| 289 base::android::ConvertUTF8ToJavaString(env, url.spec()); |
| 290 ScopedJavaLocalRef<jstring> java_scope_url = |
| 291 Java_ShortcutHelper_getScopeFromUrl(env, java_url.obj()); |
| 292 return GURL(base::android::ConvertJavaStringToUTF16(env, java_scope_url)); |
| 293 } |
| 294 |
| 286 // Callback used by Java when the shortcut has been created. | 295 // Callback used by Java when the shortcut has been created. |
| 287 // |splash_image_callback| is a pointer to a base::Closure allocated in | 296 // |splash_image_callback| is a pointer to a base::Closure allocated in |
| 288 // AddShortcutInBackgroundWithSkBitmap, so reinterpret_cast it back and run it. | 297 // AddShortcutInBackgroundWithSkBitmap, so reinterpret_cast it back and run it. |
| 289 // | 298 // |
| 290 // This callback should only ever be called when the shortcut was for a | 299 // This callback should only ever be called when the shortcut was for a |
| 291 // webapp-capable site; otherwise, |splash_image_callback| will have never been | 300 // webapp-capable site; otherwise, |splash_image_callback| will have never been |
| 292 // allocated and doesn't need to be run or deleted. | 301 // allocated and doesn't need to be run or deleted. |
| 293 void OnWebappDataStored(JNIEnv* env, | 302 void OnWebappDataStored(JNIEnv* env, |
| 294 const JavaParamRef<jclass>& clazz, | 303 const JavaParamRef<jclass>& clazz, |
| 295 jlong jsplash_image_callback) { | 304 jlong jsplash_image_callback) { |
| 296 DCHECK(jsplash_image_callback); | 305 DCHECK(jsplash_image_callback); |
| 297 base::Closure* splash_image_callback = | 306 base::Closure* splash_image_callback = |
| 298 reinterpret_cast<base::Closure*>(jsplash_image_callback); | 307 reinterpret_cast<base::Closure*>(jsplash_image_callback); |
| 299 splash_image_callback->Run(); | 308 splash_image_callback->Run(); |
| 300 delete splash_image_callback; | 309 delete splash_image_callback; |
| 301 } | 310 } |
| 302 | 311 |
| 303 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { | 312 bool ShortcutHelper::RegisterShortcutHelper(JNIEnv* env) { |
| 304 return RegisterNativesImpl(env); | 313 return RegisterNativesImpl(env); |
| 305 } | 314 } |
| OLD | NEW |