1 // Copyright 2013 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.
5 #include "chrome/browser/ui/android/infobars/infobar_container_android.h"
7 #include "base/android/jni_android.h"
8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h"
10 #include "chrome/browser/infobars/infobar_service.h"
11 #include "chrome/browser/ui/android/infobars/infobar_android.h"
12 #include "components/infobars/core/infobar.h"
13 #include "components/infobars/core/infobar_delegate.h"
14 #include "content/public/browser/web_contents.h"
15 #include "jni/InfoBarContainer_jni.h"
18 // InfoBarContainerAndroid ----------------------------------------------------
20 InfoBarContainerAndroid::InfoBarContainerAndroid(JNIEnv
* env
,
22 : infobars::InfoBarContainer(NULL
),
23 weak_java_infobar_container_(env
, obj
) {}
25 InfoBarContainerAndroid::~InfoBarContainerAndroid() {
26 RemoveAllInfoBarsForDestruction();
29 void InfoBarContainerAndroid::SetWebContents(JNIEnv
* env
,
31 jobject web_contents
) {
32 InfoBarService
* infobar_service
= InfoBarService::FromWebContents(
33 content::WebContents::FromJavaWebContents(web_contents
));
34 ChangeInfoBarManager(infobar_service
);
37 void InfoBarContainerAndroid::Destroy(JNIEnv
* env
, jobject obj
) {
41 void InfoBarContainerAndroid::PlatformSpecificAddInfoBar(
42 infobars::InfoBar
* infobar
,
45 InfoBarAndroid
* android_bar
= static_cast<InfoBarAndroid
*>(infobar
);
47 // TODO(bulach): CLANK: implement other types of InfoBars.
48 // TODO(jrg): this will always print out WARNING_TYPE as an int.
49 // Try and be more helpful.
50 NOTIMPLEMENTED() << "CLANK: infobar type "
51 << infobar
->delegate()->GetInfoBarType();
55 AttachJavaInfoBar(android_bar
);
58 void InfoBarContainerAndroid::AttachJavaInfoBar(InfoBarAndroid
* android_bar
) {
59 if (android_bar
->HasSetJavaInfoBar())
61 JNIEnv
* env
= base::android::AttachCurrentThread();
62 base::android::ScopedJavaLocalRef
<jobject
> java_infobar
=
63 android_bar
->CreateRenderInfoBar(env
);
64 Java_InfoBarContainer_addInfoBar(
65 env
, weak_java_infobar_container_
.get(env
).obj(), java_infobar
.obj());
66 android_bar
->SetJavaInfoBar(java_infobar
);
69 void InfoBarContainerAndroid::PlatformSpecificReplaceInfoBar(
70 infobars::InfoBar
* old_infobar
,
71 infobars::InfoBar
* new_infobar
) {
72 static_cast<InfoBarAndroid
*>(new_infobar
)->PassJavaInfoBar(
73 static_cast<InfoBarAndroid
*>(old_infobar
));
76 void InfoBarContainerAndroid::PlatformSpecificRemoveInfoBar(
77 infobars::InfoBar
* infobar
) {
78 InfoBarAndroid
* android_infobar
= static_cast<InfoBarAndroid
*>(infobar
);
79 android_infobar
->CloseJavaInfoBar();
83 // Native JNI methods ---------------------------------------------------------
85 static jlong
Init(JNIEnv
* env
, const JavaParamRef
<jobject
>& obj
) {
86 InfoBarContainerAndroid
* infobar_container
=
87 new InfoBarContainerAndroid(env
, obj
);
88 return reinterpret_cast<intptr_t>(infobar_container
);
91 bool RegisterInfoBarContainer(JNIEnv
* env
) {
92 return RegisterNativesImpl(env
);