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_android.h" | 5 #include "chrome/browser/ui/android/infobars/infobar_android.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "chrome/browser/android/resource_mapper.h" | 10 #include "chrome/browser/android/resource_mapper.h" |
11 #include "chrome/browser/infobars/infobar_service.h" | 11 #include "chrome/browser/infobars/infobar_service.h" |
12 #include "components/infobars/core/infobar.h" | 12 #include "components/infobars/core/infobar.h" |
13 #include "components/infobars/core/infobar_delegate.h" | 13 #include "components/infobars/core/infobar_delegate.h" |
14 #include "jni/InfoBar_jni.h" | 14 #include "jni/InfoBar_jni.h" |
15 | 15 |
16 | 16 |
17 // InfoBarAndroid ------------------------------------------------------------- | 17 // InfoBarAndroid ------------------------------------------------------------- |
18 | 18 |
19 InfoBarAndroid::InfoBarAndroid(scoped_ptr<infobars::InfoBarDelegate> delegate) | 19 InfoBarAndroid::InfoBarAndroid(scoped_ptr<infobars::InfoBarDelegate> delegate) |
20 : infobars::InfoBar(delegate.Pass()) { | 20 : infobars::InfoBar(delegate.Pass()) { |
21 } | 21 } |
22 | 22 |
23 InfoBarAndroid::~InfoBarAndroid() { | 23 InfoBarAndroid::~InfoBarAndroid() { |
| 24 if (!java_info_bar_.is_null()) { |
| 25 JNIEnv* env = base::android::AttachCurrentThread(); |
| 26 Java_InfoBar_onNativeDestroyed(env, java_info_bar_.obj()); |
| 27 } |
24 } | 28 } |
25 | 29 |
26 void InfoBarAndroid::ReassignJavaInfoBar(InfoBarAndroid* replacement) { | 30 void InfoBarAndroid::ReassignJavaInfoBar(InfoBarAndroid* replacement) { |
27 DCHECK(replacement); | 31 DCHECK(replacement); |
28 if (!java_info_bar_.is_null()) { | 32 if (!java_info_bar_.is_null()) { |
29 replacement->set_java_infobar(java_info_bar_); | 33 replacement->SetJavaInfoBar(java_info_bar_); |
30 java_info_bar_.Reset(); | 34 java_info_bar_.Reset(); |
31 } | 35 } |
32 } | 36 } |
33 | 37 |
34 void InfoBarAndroid::set_java_infobar( | 38 void InfoBarAndroid::SetJavaInfoBar( |
35 const base::android::JavaRef<jobject>& java_info_bar) { | 39 const base::android::JavaRef<jobject>& java_info_bar) { |
36 DCHECK(java_info_bar_.is_null()); | 40 DCHECK(java_info_bar_.is_null()); |
37 java_info_bar_.Reset(java_info_bar); | 41 java_info_bar_.Reset(java_info_bar); |
| 42 JNIEnv* env = base::android::AttachCurrentThread(); |
| 43 Java_InfoBar_setNativeInfoBar(env, java_info_bar.obj(), |
| 44 reinterpret_cast<intptr_t>(this)); |
| 45 } |
| 46 |
| 47 jobject InfoBarAndroid::GetJavaInfoBar() { |
| 48 return java_info_bar_.obj(); |
38 } | 49 } |
39 | 50 |
40 bool InfoBarAndroid::HasSetJavaInfoBar() const { | 51 bool InfoBarAndroid::HasSetJavaInfoBar() const { |
41 return !java_info_bar_.is_null(); | 52 return !java_info_bar_.is_null(); |
42 } | 53 } |
43 | 54 |
44 void InfoBarAndroid::OnButtonClicked(JNIEnv* env, | 55 void InfoBarAndroid::OnButtonClicked(JNIEnv* env, |
45 jobject obj, | 56 jobject obj, |
46 jint action, | 57 jint action, |
47 jstring action_value) { | 58 jstring action_value) { |
(...skipping 18 matching lines...) Expand all Loading... |
66 int InfoBarAndroid::GetEnumeratedIconId() { | 77 int InfoBarAndroid::GetEnumeratedIconId() { |
67 return ResourceMapper::MapFromChromiumId(delegate()->GetIconID()); | 78 return ResourceMapper::MapFromChromiumId(delegate()->GetIconID()); |
68 } | 79 } |
69 | 80 |
70 | 81 |
71 // Native JNI methods --------------------------------------------------------- | 82 // Native JNI methods --------------------------------------------------------- |
72 | 83 |
73 bool RegisterNativeInfoBar(JNIEnv* env) { | 84 bool RegisterNativeInfoBar(JNIEnv* env) { |
74 return RegisterNativesImpl(env); | 85 return RegisterNativesImpl(env); |
75 } | 86 } |
OLD | NEW |