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 | |
17 InstantAppsInfoBarDelegate::InstantAppsInfoBarDelegate( | |
18 const base::android::ScopedJavaGlobalRef<jobject>& jdata) : data_(jdata) { | |
Peter Kasting
2016/08/23 07:59:22
Don't expose a public constructor. Infobar delega
Maria
2016/08/23 21:30:27
Done.
| |
19 JNIEnv* env = base::android::AttachCurrentThread(); | |
20 java_delegate_.Reset(Java_InstantAppsInfoBarDelegate_create( | |
Peter Kasting
2016/08/23 07:59:22
Do we really need both a Java infobar and a Java i
Maria
2016/08/23 21:30:27
Many Java infobars actually do have java infobar d
Peter Kasting
2016/08/23 22:10:57
Are you sure it will need this in the future? If
Maria
2016/08/23 23:55:59
Done.
| |
21 env, | |
22 reinterpret_cast<intptr_t>(this))); | |
23 } | |
24 | |
25 InstantAppsInfoBarDelegate::~InstantAppsInfoBarDelegate() {} | |
26 | |
27 infobars::InfoBarDelegate::InfoBarIdentifier | |
28 InstantAppsInfoBarDelegate::GetIdentifier() const { | |
29 return INSTANT_APPS_INFOBAR_DELEGATE_ANDROID; | |
30 } | |
31 | |
32 base::string16 InstantAppsInfoBarDelegate::GetMessageText() const { | |
33 // Message is set in InstantAppInfobar.java | |
Peter Kasting
2016/08/23 07:59:22
So why are we overriding this method?
Maria
2016/08/23 21:30:27
Because ConfirmInfoBar only provides a pure virtua
| |
34 return base::string16(); | |
35 } | |
36 | |
37 bool InstantAppsInfoBarDelegate::Accept() { | |
38 JNIEnv* env = base::android::AttachCurrentThread(); | |
39 Java_InstantAppsInfoBarDelegate_openInstantApp(env, java_delegate_.obj()); | |
40 return true; | |
41 } | |
42 | |
43 void Launch(JNIEnv* env, | |
44 const base::android::JavaParamRef<jclass>& clazz, | |
45 const base::android::JavaParamRef<jobject>& jweb_contents, | |
46 const base::android::JavaParamRef<jobject>& jdata) { | |
47 content::WebContents* web_contents = | |
48 content::WebContents::FromJavaWebContents(jweb_contents); | |
49 InfoBarService* infobar_service = | |
50 InfoBarService::FromWebContents(web_contents); | |
51 std::unique_ptr<InstantAppsInfoBarDelegate> delegate( | |
52 new InstantAppsInfoBarDelegate( | |
53 base::android::ScopedJavaGlobalRef<jobject>(jdata))); | |
Peter Kasting
2016/08/23 07:59:22
AndroidDownloadManagerOverwriteInfoBarDelegate jus
Maria
2016/08/23 21:30:27
No, this data is used by InstantAppsInfoBar::Creat
Peter Kasting
2016/08/23 22:10:57
Right, and that's why the delegate wraps this in a
Maria
2016/08/23 23:55:59
Done.
| |
54 infobar_service->AddInfoBar(base::WrapUnique( | |
Peter Kasting
2016/08/23 07:59:22
Nit: Use MakeUnique() rather than WrapUnique(new()
Maria
2016/08/23 21:30:27
Done.
| |
55 new InstantAppsInfoBar(std::move(delegate)))); | |
56 } | |
57 | |
58 bool RegisterInstantAppsInfoBarDelegate(JNIEnv* env) { | |
59 return RegisterNativesImpl(env); | |
60 } | |
OLD | NEW |