| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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/instantapps/instant_apps_infobar_delegate.h" | 5 #include "chrome/browser/android/instantapps/instant_apps_infobar_delegate.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/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/metrics/user_metrics.h" | 10 #include "base/metrics/user_metrics.h" |
| 11 #include "chrome/browser/android/instantapps/instant_apps_settings.h" |
| 11 #include "chrome/browser/infobars/infobar_service.h" | 12 #include "chrome/browser/infobars/infobar_service.h" |
| 12 #include "chrome/browser/ui/android/infobars/instant_apps_infobar.h" | 13 #include "chrome/browser/ui/android/infobars/instant_apps_infobar.h" |
| 13 #include "components/infobars/core/infobar_delegate.h" | 14 #include "components/infobars/core/infobar_delegate.h" |
| 14 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 15 #include "jni/InstantAppsInfoBarDelegate_jni.h" | 16 #include "jni/InstantAppsInfoBarDelegate_jni.h" |
| 16 | 17 |
| 17 InstantAppsInfoBarDelegate::~InstantAppsInfoBarDelegate() {} | 18 InstantAppsInfoBarDelegate::~InstantAppsInfoBarDelegate() {} |
| 18 | 19 |
| 19 // static | 20 // static |
| 20 void InstantAppsInfoBarDelegate::Create(InfoBarService* infobar_service, | 21 void InstantAppsInfoBarDelegate::Create(InfoBarService* infobar_service, |
| 21 jobject jdata) { | 22 const jobject jdata, |
| 23 const std::string& url) { |
| 22 infobar_service->AddInfoBar(base::MakeUnique<InstantAppsInfoBar>( | 24 infobar_service->AddInfoBar(base::MakeUnique<InstantAppsInfoBar>( |
| 23 std::unique_ptr<InstantAppsInfoBarDelegate>( | 25 std::unique_ptr<InstantAppsInfoBarDelegate>( |
| 24 new InstantAppsInfoBarDelegate(jdata)))); | 26 new InstantAppsInfoBarDelegate(jdata, url)))); |
| 25 base::RecordAction(base::UserMetricsAction( | |
| 26 "Android.InstantApps.BannerShown")); | |
| 27 } | 27 } |
| 28 | 28 |
| 29 InstantAppsInfoBarDelegate::InstantAppsInfoBarDelegate(jobject jdata) { | 29 InstantAppsInfoBarDelegate::InstantAppsInfoBarDelegate(const jobject jdata, |
| 30 const std::string& url) |
| 31 : url_(url) { |
| 30 JNIEnv* env = base::android::AttachCurrentThread(); | 32 JNIEnv* env = base::android::AttachCurrentThread(); |
| 31 java_delegate_.Reset(Java_InstantAppsInfoBarDelegate_create(env)); | 33 java_delegate_.Reset(Java_InstantAppsInfoBarDelegate_create(env)); |
| 32 data_.Reset(env, jdata); | 34 data_.Reset(env, jdata); |
| 33 } | 35 } |
| 34 | 36 |
| 35 infobars::InfoBarDelegate::InfoBarIdentifier | 37 infobars::InfoBarDelegate::InfoBarIdentifier |
| 36 InstantAppsInfoBarDelegate::GetIdentifier() const { | 38 InstantAppsInfoBarDelegate::GetIdentifier() const { |
| 37 return INSTANT_APPS_INFOBAR_DELEGATE_ANDROID; | 39 return INSTANT_APPS_INFOBAR_DELEGATE_ANDROID; |
| 38 } | 40 } |
| 39 | 41 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 52 return true; | 54 return true; |
| 53 } | 55 } |
| 54 | 56 |
| 55 bool InstantAppsInfoBarDelegate::EqualsDelegate( | 57 bool InstantAppsInfoBarDelegate::EqualsDelegate( |
| 56 infobars::InfoBarDelegate* delegate) const { | 58 infobars::InfoBarDelegate* delegate) const { |
| 57 return delegate && delegate->GetIdentifier() == GetIdentifier(); | 59 return delegate && delegate->GetIdentifier() == GetIdentifier(); |
| 58 } | 60 } |
| 59 | 61 |
| 60 | 62 |
| 61 void InstantAppsInfoBarDelegate::InfoBarDismissed() { | 63 void InstantAppsInfoBarDelegate::InfoBarDismissed() { |
| 64 content::WebContents* web_contents = |
| 65 InfoBarService::WebContentsFromInfoBar(infobar()); |
| 66 InstantAppsSettings::RecordInfoBarDismissEvent(web_contents, url_); |
| 62 base::RecordAction(base::UserMetricsAction( | 67 base::RecordAction(base::UserMetricsAction( |
| 63 "Android.InstantApps.BannerDismissed")); | 68 "Android.InstantApps.BannerDismissed")); |
| 64 } | 69 } |
| 65 | 70 |
| 66 void Launch(JNIEnv* env, | 71 void Launch(JNIEnv* env, |
| 67 const base::android::JavaParamRef<jclass>& clazz, | 72 const base::android::JavaParamRef<jclass>& clazz, |
| 68 const base::android::JavaParamRef<jobject>& jweb_contents, | 73 const base::android::JavaParamRef<jobject>& jweb_contents, |
| 69 const base::android::JavaParamRef<jobject>& jdata) { | 74 const base::android::JavaParamRef<jobject>& jdata, |
| 75 const base::android::JavaParamRef<jstring>& jurl) { |
| 70 auto web_contents = content::WebContents::FromJavaWebContents(jweb_contents); | 76 auto web_contents = content::WebContents::FromJavaWebContents(jweb_contents); |
| 77 std::string url(base::android::ConvertJavaStringToUTF8(env, jurl)); |
| 71 InstantAppsInfoBarDelegate::Create( | 78 InstantAppsInfoBarDelegate::Create( |
| 72 InfoBarService::FromWebContents(web_contents), | 79 InfoBarService::FromWebContents(web_contents), |
| 73 jdata); | 80 jdata, |
| 81 url); |
| 82 InstantAppsSettings::RecordInfoBarShowEvent(web_contents, url); |
| 83 base::RecordAction(base::UserMetricsAction( |
| 84 "Android.InstantApps.BannerShown")); |
| 74 } | 85 } |
| 75 | 86 |
| 76 bool RegisterInstantAppsInfoBarDelegate(JNIEnv* env) { | 87 bool RegisterInstantAppsInfoBarDelegate(JNIEnv* env) { |
| 77 return RegisterNativesImpl(env); | 88 return RegisterNativesImpl(env); |
| 78 } | 89 } |
| OLD | NEW |