| 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/AppBannerInfoBar_jni.h" | 11 #include "jni/AppBannerInfoBar_jni.h" |
| 12 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 12 #include "ui/gfx/android/java_bitmap.h" | 13 #include "ui/gfx/android/java_bitmap.h" |
| 13 #include "ui/gfx/image/image.h" | 14 #include "ui/gfx/image/image.h" |
| 14 | 15 |
| 15 AppBannerInfoBar::AppBannerInfoBar( | 16 AppBannerInfoBar::AppBannerInfoBar( |
| 16 scoped_ptr<banners::AppBannerInfoBarDelegate> delegate, | 17 scoped_ptr<banners::AppBannerInfoBarDelegate> delegate, |
| 17 const GURL& app_url) | 18 const GURL& app_url) |
| 18 : ConfirmInfoBar(delegate.Pass()), | 19 : ConfirmInfoBar(delegate.Pass()), |
| 19 app_url_(app_url) { | 20 app_url_(app_url) { |
| 20 } | 21 } |
| 21 | 22 |
| 22 AppBannerInfoBar::~AppBannerInfoBar() { | 23 AppBannerInfoBar::~AppBannerInfoBar() { |
| 23 } | 24 } |
| 24 | 25 |
| 25 base::android::ScopedJavaLocalRef<jobject> | 26 base::android::ScopedJavaLocalRef<jobject> |
| 26 AppBannerInfoBar::CreateRenderInfoBar(JNIEnv* env) { | 27 AppBannerInfoBar::CreateRenderInfoBar(JNIEnv* env) { |
| 27 ConfirmInfoBarDelegate* app_banner_infobar_delegate = GetDelegate(); | 28 ConfirmInfoBarDelegate* app_banner_infobar_delegate = GetDelegate(); |
| 28 | 29 |
| 29 base::android::ScopedJavaLocalRef<jstring> app_title = | 30 base::android::ScopedJavaLocalRef<jstring> app_title = |
| 30 base::android::ConvertUTF16ToJavaString( | 31 base::android::ConvertUTF16ToJavaString( |
| 31 env, app_banner_infobar_delegate->GetMessageText()); | 32 env, app_banner_infobar_delegate->GetMessageText()); |
| 32 | 33 |
| 33 base::android::ScopedJavaLocalRef<jobject> java_bitmap; | 34 base::android::ScopedJavaLocalRef<jobject> java_bitmap; |
| 34 if (!app_banner_infobar_delegate->GetIcon().IsEmpty()) { | 35 if (!app_banner_infobar_delegate->GetIcon().IsEmpty()) { |
| 35 java_bitmap = gfx::ConvertToJavaBitmap( | 36 java_bitmap = gfx::ConvertToJavaBitmap( |
| 36 app_banner_infobar_delegate->GetIcon().ToSkBitmap()); | 37 app_banner_infobar_delegate->GetIcon().ToSkBitmap()); |
| 37 } | 38 } |
| 38 | 39 |
| 39 base::android::ScopedJavaLocalRef<jobject> infobar; | 40 base::android::ScopedJavaLocalRef<jobject> infobar; |
| 41 |
| 42 // Trim down the app URL to the domain and registry. |
| 43 std::string trimmed_url = |
| 44 net::registry_controlled_domains::GetDomainAndRegistry( |
| 45 app_url_, |
| 46 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); |
| 47 |
| 40 base::android::ScopedJavaLocalRef<jstring> app_url = | 48 base::android::ScopedJavaLocalRef<jstring> app_url = |
| 41 base::android::ConvertUTF8ToJavaString(env, app_url_.spec()); | 49 base::android::ConvertUTF8ToJavaString(env, trimmed_url); |
| 42 | 50 |
| 43 infobar.Reset(Java_AppBannerInfoBar_createWebAppInfoBar( | 51 infobar.Reset(Java_AppBannerInfoBar_createWebAppInfoBar( |
| 44 env, | 52 env, |
| 45 reinterpret_cast<intptr_t>(this), | 53 reinterpret_cast<intptr_t>(this), |
| 46 app_title.obj(), | 54 app_title.obj(), |
| 47 java_bitmap.obj(), | 55 java_bitmap.obj(), |
| 48 app_url.obj())); | 56 app_url.obj())); |
| 49 | 57 |
| 50 java_infobar_.Reset(env, infobar.obj()); | 58 java_infobar_.Reset(env, infobar.obj()); |
| 51 return infobar; | 59 return infobar; |
| 52 } | 60 } |
| 53 | 61 |
| 54 // Native JNI methods --------------------------------------------------------- | 62 // Native JNI methods --------------------------------------------------------- |
| 55 | 63 |
| 56 bool RegisterAppBannerInfoBarDelegate(JNIEnv* env) { | 64 bool RegisterAppBannerInfoBarDelegate(JNIEnv* env) { |
| 57 return RegisterNativesImpl(env); | 65 return RegisterNativesImpl(env); |
| 58 } | 66 } |
| OLD | NEW |