OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/ui/android/infobars/infobar_container_android.h" | 5 #include "chrome/browser/ui/android/infobars/infobar_container_android.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "chrome/browser/infobars/infobar.h" | |
11 #include "chrome/browser/infobars/infobar_delegate.h" | |
12 #include "chrome/browser/infobars/infobar_service.h" | 10 #include "chrome/browser/infobars/infobar_service.h" |
13 #include "chrome/browser/ui/android/infobars/auto_login_infobar_delegate_android
.h" | 11 #include "chrome/browser/ui/android/infobars/auto_login_infobar_delegate_android
.h" |
14 #include "chrome/browser/ui/android/infobars/infobar_android.h" | 12 #include "chrome/browser/ui/android/infobars/infobar_android.h" |
| 13 #include "components/infobars/core/infobar.h" |
| 14 #include "components/infobars/core/infobar_delegate.h" |
15 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
16 #include "jni/InfoBarContainer_jni.h" | 16 #include "jni/InfoBarContainer_jni.h" |
17 | 17 |
18 | 18 |
19 // InfoBarContainerAndroid ---------------------------------------------------- | 19 // InfoBarContainerAndroid ---------------------------------------------------- |
20 | 20 |
21 InfoBarContainerAndroid::InfoBarContainerAndroid(JNIEnv* env, | 21 InfoBarContainerAndroid::InfoBarContainerAndroid(JNIEnv* env, |
22 jobject obj, | 22 jobject obj, |
23 jobject auto_login_delegate) | 23 jobject auto_login_delegate) |
24 : InfoBarContainer(NULL), | 24 : infobars::InfoBarContainer(NULL), |
25 weak_java_infobar_container_(env, obj), | 25 weak_java_infobar_container_(env, obj), |
26 weak_java_auto_login_delegate_(env, auto_login_delegate) { | 26 weak_java_auto_login_delegate_(env, auto_login_delegate) {} |
27 } | |
28 | 27 |
29 InfoBarContainerAndroid::~InfoBarContainerAndroid() { | 28 InfoBarContainerAndroid::~InfoBarContainerAndroid() { |
30 RemoveAllInfoBarsForDestruction(); | 29 RemoveAllInfoBarsForDestruction(); |
31 } | 30 } |
32 | 31 |
33 void InfoBarContainerAndroid::Destroy(JNIEnv* env, jobject obj) { | 32 void InfoBarContainerAndroid::Destroy(JNIEnv* env, jobject obj) { |
34 delete this; | 33 delete this; |
35 } | 34 } |
36 | 35 |
37 void InfoBarContainerAndroid::PlatformSpecificAddInfoBar(InfoBar* infobar, | 36 void InfoBarContainerAndroid::PlatformSpecificAddInfoBar( |
38 size_t position) { | 37 infobars::InfoBar* infobar, |
| 38 size_t position) { |
39 DCHECK(infobar); | 39 DCHECK(infobar); |
40 InfoBarAndroid* android_bar = static_cast<InfoBarAndroid*>(infobar); | 40 InfoBarAndroid* android_bar = static_cast<InfoBarAndroid*>(infobar); |
41 if (!android_bar) { | 41 if (!android_bar) { |
42 // TODO(bulach): CLANK: implement other types of InfoBars. | 42 // TODO(bulach): CLANK: implement other types of InfoBars. |
43 // TODO(jrg): this will always print out WARNING_TYPE as an int. | 43 // TODO(jrg): this will always print out WARNING_TYPE as an int. |
44 // Try and be more helpful. | 44 // Try and be more helpful. |
45 NOTIMPLEMENTED() << "CLANK: infobar type " | 45 NOTIMPLEMENTED() << "CLANK: infobar type " |
46 << infobar->delegate()->GetInfoBarType(); | 46 << infobar->delegate()->GetInfoBarType(); |
47 return; | 47 return; |
48 } | 48 } |
(...skipping 14 matching lines...) Expand all Loading... |
63 return; | 63 return; |
64 JNIEnv* env = base::android::AttachCurrentThread(); | 64 JNIEnv* env = base::android::AttachCurrentThread(); |
65 base::android::ScopedJavaLocalRef<jobject> java_infobar = | 65 base::android::ScopedJavaLocalRef<jobject> java_infobar = |
66 android_bar->CreateRenderInfoBar(env); | 66 android_bar->CreateRenderInfoBar(env); |
67 Java_InfoBarContainer_addInfoBar( | 67 Java_InfoBarContainer_addInfoBar( |
68 env, weak_java_infobar_container_.get(env).obj(), java_infobar.obj()); | 68 env, weak_java_infobar_container_.get(env).obj(), java_infobar.obj()); |
69 android_bar->set_java_infobar(java_infobar); | 69 android_bar->set_java_infobar(java_infobar); |
70 } | 70 } |
71 | 71 |
72 void InfoBarContainerAndroid::PlatformSpecificReplaceInfoBar( | 72 void InfoBarContainerAndroid::PlatformSpecificReplaceInfoBar( |
73 InfoBar* old_infobar, | 73 infobars::InfoBar* old_infobar, |
74 InfoBar* new_infobar) { | 74 infobars::InfoBar* new_infobar) { |
75 static_cast<InfoBarAndroid*>(new_infobar)->PassJavaInfoBar( | 75 static_cast<InfoBarAndroid*>(new_infobar)->PassJavaInfoBar( |
76 static_cast<InfoBarAndroid*>(old_infobar)); | 76 static_cast<InfoBarAndroid*>(old_infobar)); |
77 } | 77 } |
78 | 78 |
79 void InfoBarContainerAndroid::PlatformSpecificRemoveInfoBar(InfoBar* infobar) { | 79 void InfoBarContainerAndroid::PlatformSpecificRemoveInfoBar( |
| 80 infobars::InfoBar* infobar) { |
80 InfoBarAndroid* android_infobar = static_cast<InfoBarAndroid*>(infobar); | 81 InfoBarAndroid* android_infobar = static_cast<InfoBarAndroid*>(infobar); |
81 android_infobar->CloseJavaInfoBar(); | 82 android_infobar->CloseJavaInfoBar(); |
82 } | 83 } |
83 | 84 |
84 | 85 |
85 // Native JNI methods --------------------------------------------------------- | 86 // Native JNI methods --------------------------------------------------------- |
86 | 87 |
87 static jlong Init(JNIEnv* env, | 88 static jlong Init(JNIEnv* env, |
88 jobject obj, | 89 jobject obj, |
89 jobject web_contents, | 90 jobject web_contents, |
90 jobject auto_login_delegate) { | 91 jobject auto_login_delegate) { |
91 InfoBarContainerAndroid* infobar_container = | 92 InfoBarContainerAndroid* infobar_container = |
92 new InfoBarContainerAndroid(env, obj, auto_login_delegate); | 93 new InfoBarContainerAndroid(env, obj, auto_login_delegate); |
93 InfoBarService* infobar_service = InfoBarService::FromWebContents( | 94 InfoBarService* infobar_service = InfoBarService::FromWebContents( |
94 content::WebContents::FromJavaWebContents(web_contents)); | 95 content::WebContents::FromJavaWebContents(web_contents)); |
95 infobar_container->ChangeInfoBarManager(infobar_service); | 96 infobar_container->ChangeInfoBarManager(infobar_service); |
96 return reinterpret_cast<intptr_t>(infobar_container); | 97 return reinterpret_cast<intptr_t>(infobar_container); |
97 } | 98 } |
98 | 99 |
99 bool RegisterInfoBarContainer(JNIEnv* env) { | 100 bool RegisterInfoBarContainer(JNIEnv* env) { |
100 return RegisterNativesImpl(env); | 101 return RegisterNativesImpl(env); |
101 } | 102 } |
OLD | NEW |