| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ui/android/infobars/app_banner_infobar.h" | 5 #include "chrome/browser/ui/android/infobars/app_banner_infobar.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/android/scoped_java_ref.h" | 9 #include "base/android/scoped_java_ref.h" |
| 10 #include "chrome/browser/android/banners/app_banner_infobar_delegate.h" | 10 #include "chrome/browser/android/banners/app_banner_infobar_delegate.h" |
| 11 #include "jni/AppBannerInfoBarDelegate_jni.h" | 11 #include "jni/AppBannerInfoBar_jni.h" |
| 12 #include "ui/gfx/android/java_bitmap.h" | 12 #include "ui/gfx/android/java_bitmap.h" |
| 13 #include "ui/gfx/image/image.h" | 13 #include "ui/gfx/image/image.h" |
| 14 | 14 |
| 15 AppBannerInfoBar::AppBannerInfoBar( | 15 AppBannerInfoBar::AppBannerInfoBar( |
| 16 scoped_ptr<banners::AppBannerInfoBarDelegate> delegate, | 16 scoped_ptr<banners::AppBannerInfoBarDelegate> delegate, |
| 17 const GURL& app_url) | 17 const GURL& app_url) |
| 18 : ConfirmInfoBar(delegate.Pass()), | 18 : ConfirmInfoBar(delegate.Pass()), |
| 19 app_url_(app_url) { | 19 app_url_(app_url) { |
| 20 } | 20 } |
| 21 | 21 |
| 22 AppBannerInfoBar::~AppBannerInfoBar() { | 22 AppBannerInfoBar::~AppBannerInfoBar() { |
| 23 } | 23 } |
| 24 | 24 |
| 25 base::android::ScopedJavaLocalRef<jobject> | 25 base::android::ScopedJavaLocalRef<jobject> |
| 26 AppBannerInfoBar::CreateRenderInfoBar(JNIEnv* env) { | 26 AppBannerInfoBar::CreateRenderInfoBar(JNIEnv* env) { |
| 27 java_delegate_.Reset(Java_AppBannerInfoBarDelegate_create(env)); | 27 ConfirmInfoBarDelegate* app_banner_infobar_delegate = GetDelegate(); |
| 28 | 28 |
| 29 base::android::ScopedJavaLocalRef<jstring> ok_button_text = | |
| 30 base::android::ConvertUTF16ToJavaString( | |
| 31 env, GetTextFor(ConfirmInfoBarDelegate::BUTTON_OK)); | |
| 32 | |
| 33 ConfirmInfoBarDelegate* delegate = GetDelegate(); | |
| 34 base::android::ScopedJavaLocalRef<jstring> app_title = | 29 base::android::ScopedJavaLocalRef<jstring> app_title = |
| 35 base::android::ConvertUTF16ToJavaString( | 30 base::android::ConvertUTF16ToJavaString( |
| 36 env, delegate->GetMessageText()); | 31 env, app_banner_infobar_delegate->GetMessageText()); |
| 37 | 32 |
| 33 base::android::ScopedJavaLocalRef<jobject> java_bitmap; |
| 34 if (!app_banner_infobar_delegate->GetIcon().IsEmpty()) { |
| 35 java_bitmap = gfx::ConvertToJavaBitmap( |
| 36 app_banner_infobar_delegate->GetIcon().ToSkBitmap()); |
| 37 } |
| 38 |
| 39 base::android::ScopedJavaLocalRef<jobject> infobar; |
| 38 base::android::ScopedJavaLocalRef<jstring> app_url = | 40 base::android::ScopedJavaLocalRef<jstring> app_url = |
| 39 base::android::ConvertUTF8ToJavaString(env, app_url_.spec()); | 41 base::android::ConvertUTF8ToJavaString(env, app_url_.spec()); |
| 40 | 42 |
| 41 ScopedJavaLocalRef<jobject> java_bitmap; | 43 infobar.Reset(Java_AppBannerInfoBar_createWebAppInfoBar( |
| 42 if (!delegate->GetIcon().IsEmpty()) { | |
| 43 java_bitmap = gfx::ConvertToJavaBitmap(delegate->GetIcon().ToSkBitmap()); | |
| 44 } | |
| 45 | |
| 46 return Java_AppBannerInfoBarDelegate_showInfoBar( | |
| 47 env, | 44 env, |
| 48 java_delegate_.obj(), | |
| 49 reinterpret_cast<intptr_t>(this), | 45 reinterpret_cast<intptr_t>(this), |
| 50 app_title.obj(), | 46 app_title.obj(), |
| 51 java_bitmap.obj(), | 47 java_bitmap.obj(), |
| 52 ok_button_text.obj(), | 48 app_url.obj())); |
| 53 app_url.obj()); | 49 |
| 50 java_infobar_.Reset(env, infobar.obj()); |
| 51 return infobar; |
| 54 } | 52 } |
| 55 | 53 |
| 56 // Native JNI methods --------------------------------------------------------- | 54 // Native JNI methods --------------------------------------------------------- |
| 57 | 55 |
| 58 bool RegisterAppBannerInfoBarDelegate(JNIEnv* env) { | 56 bool RegisterAppBannerInfoBarDelegate(JNIEnv* env) { |
| 59 return RegisterNativesImpl(env); | 57 return RegisterNativesImpl(env); |
| 60 } | 58 } |
| OLD | NEW |