Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / android / infobars / infobar_container_android.cc
blob6288aabe6487c4d811540a9203fffaa876984363
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,
21 jobject obj)
22 : infobars::InfoBarContainer(NULL),
23 weak_java_infobar_container_(env, obj) {}
25 InfoBarContainerAndroid::~InfoBarContainerAndroid() {
26 RemoveAllInfoBarsForDestruction();
29 void InfoBarContainerAndroid::SetWebContents(JNIEnv* env,
30 jobject obj,
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) {
38 delete this;
41 void InfoBarContainerAndroid::PlatformSpecificAddInfoBar(
42 infobars::InfoBar* infobar,
43 size_t position) {
44 DCHECK(infobar);
45 InfoBarAndroid* android_bar = static_cast<InfoBarAndroid*>(infobar);
46 if (!android_bar) {
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();
52 return;
55 AttachJavaInfoBar(android_bar);
58 void InfoBarContainerAndroid::AttachJavaInfoBar(InfoBarAndroid* android_bar) {
59 if (android_bar->HasSetJavaInfoBar())
60 return;
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);