OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/android/instantapps/instant_apps_infobar_delegate.h" |
| 6 |
| 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" |
| 9 #include "base/memory/ptr_util.h" |
| 10 #include "chrome/browser/infobars/infobar_service.h" |
| 11 #include "chrome/browser/ui/android/infobars/instant_apps_infobar.h" |
| 12 #include "components/infobars/core/infobar_delegate.h" |
| 13 #include "content/public/browser/web_contents.h" |
| 14 #include "jni/InstantAppsInfoBarDelegate_jni.h" |
| 15 |
| 16 InstantAppsInfoBarDelegate::~InstantAppsInfoBarDelegate() {} |
| 17 |
| 18 // static |
| 19 void InstantAppsInfoBarDelegate::Create(InfoBarService* infobar_service, |
| 20 jobject jdata) { |
| 21 infobar_service->AddInfoBar(base::MakeUnique<InstantAppsInfoBar>( |
| 22 std::unique_ptr<InstantAppsInfoBarDelegate>( |
| 23 new InstantAppsInfoBarDelegate(jdata)))); |
| 24 } |
| 25 |
| 26 InstantAppsInfoBarDelegate::InstantAppsInfoBarDelegate(jobject jdata) { |
| 27 JNIEnv* env = base::android::AttachCurrentThread(); |
| 28 java_delegate_.Reset(Java_InstantAppsInfoBarDelegate_create(env)); |
| 29 data_.Reset(env, jdata); |
| 30 } |
| 31 |
| 32 infobars::InfoBarDelegate::InfoBarIdentifier |
| 33 InstantAppsInfoBarDelegate::GetIdentifier() const { |
| 34 return INSTANT_APPS_INFOBAR_DELEGATE_ANDROID; |
| 35 } |
| 36 |
| 37 base::string16 InstantAppsInfoBarDelegate::GetMessageText() const { |
| 38 // Message is set in InstantAppInfobar.java |
| 39 return base::string16(); |
| 40 } |
| 41 |
| 42 bool InstantAppsInfoBarDelegate::Accept() { |
| 43 JNIEnv* env = base::android::AttachCurrentThread(); |
| 44 Java_InstantAppsInfoBarDelegate_openInstantApp(env, java_delegate_.obj()); |
| 45 return true; |
| 46 } |
| 47 |
| 48 bool InstantAppsInfoBarDelegate::EqualsDelegate( |
| 49 infobars::InfoBarDelegate* delegate) const { |
| 50 return delegate && delegate->GetIdentifier() == GetIdentifier(); |
| 51 } |
| 52 |
| 53 void Launch(JNIEnv* env, |
| 54 const base::android::JavaParamRef<jclass>& clazz, |
| 55 const base::android::JavaParamRef<jobject>& jweb_contents, |
| 56 const base::android::JavaParamRef<jobject>& jdata) { |
| 57 auto web_contents = content::WebContents::FromJavaWebContents(jweb_contents); |
| 58 InstantAppsInfoBarDelegate::Create( |
| 59 InfoBarService::FromWebContents(web_contents), |
| 60 jdata); |
| 61 } |
| 62 |
| 63 bool RegisterInstantAppsInfoBarDelegate(JNIEnv* env) { |
| 64 return RegisterNativesImpl(env); |
| 65 } |
OLD | NEW |