Index: chrome/browser/android/instantapps/instant_apps_infobar_delegate.cc |
diff --git a/chrome/browser/android/instantapps/instant_apps_infobar_delegate.cc b/chrome/browser/android/instantapps/instant_apps_infobar_delegate.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..26483db6c3a34be4d7697d5b1e79db769cbee7af |
--- /dev/null |
+++ b/chrome/browser/android/instantapps/instant_apps_infobar_delegate.cc |
@@ -0,0 +1,62 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/android/instantapps/instant_apps_infobar_delegate.h" |
+ |
+#include "base/android/jni_android.h" |
+#include "base/android/jni_string.h" |
+#include "base/memory/ptr_util.h" |
+#include "chrome/browser/infobars/infobar_service.h" |
+#include "chrome/browser/ui/android/infobars/instant_apps_infobar.h" |
+#include "components/infobars/core/infobar_delegate.h" |
+#include "content/public/browser/web_contents.h" |
+#include "jni/InstantAppsInfoBarDelegate_jni.h" |
+ |
+InstantAppsInfoBarDelegate::~InstantAppsInfoBarDelegate() {} |
+ |
+// static |
+void InstantAppsInfoBarDelegate::Create(InfoBarService* infobar_service, |
+ jobject jdata) { |
+ std::unique_ptr<InstantAppsInfoBarDelegate> delegate( |
+ new InstantAppsInfoBarDelegate(jdata)); |
+ infobar_service->AddInfoBar(base::MakeUnique<InstantAppsInfoBar>( |
+ std::move(delegate))); |
Peter Kasting
2016/08/24 04:04:06
Nit: Optional shorter version:
infobar_service-
Maria
2016/08/24 17:53:49
Done.
|
+} |
+ |
+InstantAppsInfoBarDelegate::InstantAppsInfoBarDelegate(jobject jdata) { |
+ JNIEnv* env = base::android::AttachCurrentThread(); |
+ data_.Reset(env, jdata); |
+ java_delegate_.Reset(Java_InstantAppsInfoBarDelegate_create(env)); |
Peter Kasting
2016/08/24 04:04:06
Nit: I suggest keeping the init order here and the
Maria
2016/08/24 17:53:49
Done.
|
+} |
+ |
+infobars::InfoBarDelegate::InfoBarIdentifier |
+InstantAppsInfoBarDelegate::GetIdentifier() const { |
+ return INSTANT_APPS_INFOBAR_DELEGATE_ANDROID; |
+} |
+ |
+base::string16 InstantAppsInfoBarDelegate::GetMessageText() const { |
+ // Message is set in InstantAppInfobar.java |
+ return base::string16(); |
Peter Kasting
2016/08/24 04:04:06
OK, returning string16() here is fine, but this re
Maria
2016/08/24 17:53:49
Done.
|
+} |
+ |
+bool InstantAppsInfoBarDelegate::Accept() { |
+ JNIEnv* env = base::android::AttachCurrentThread(); |
+ Java_InstantAppsInfoBarDelegate_openInstantApp(env, java_delegate_.obj()); |
+ return true; |
+} |
+ |
+void Launch(JNIEnv* env, |
+ const base::android::JavaParamRef<jclass>& clazz, |
+ const base::android::JavaParamRef<jobject>& jweb_contents, |
+ const base::android::JavaParamRef<jobject>& jdata) { |
+ content::WebContents* web_contents = |
+ content::WebContents::FromJavaWebContents(jweb_contents); |
+ InfoBarService* infobar_service = |
+ InfoBarService::FromWebContents(web_contents); |
Peter Kasting
2016/08/24 04:04:06
Nit: I'd probably inline this statement into the n
Maria
2016/08/24 17:53:49
Done.
|
+ InstantAppsInfoBarDelegate::Create(infobar_service, jdata); |
+} |
+ |
+bool RegisterInstantAppsInfoBarDelegate(JNIEnv* env) { |
+ return RegisterNativesImpl(env); |
+} |