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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "chrome/browser/android/resource_mapper.h" | 12 #include "chrome/browser/android/resource_mapper.h" |
13 #include "chrome/browser/infobars/infobar_service.h" | 13 #include "chrome/browser/infobars/infobar_service.h" |
14 #include "components/infobars/core/infobar.h" | 14 #include "components/infobars/core/infobar.h" |
15 #include "components/infobars/core/infobar_delegate.h" | 15 #include "components/infobars/core/infobar_delegate.h" |
16 #include "jni/InfoBar_jni.h" | 16 #include "jni/InfoBar_jni.h" |
17 | 17 |
18 using base::android::JavaParamRef; | 18 using base::android::JavaParamRef; |
19 | 19 |
20 // InfoBarAndroid ------------------------------------------------------------- | 20 // InfoBarAndroid ------------------------------------------------------------- |
21 | 21 |
22 InfoBarAndroid::InfoBarAndroid( | 22 InfoBarAndroid::InfoBarAndroid( |
23 std::unique_ptr<infobars::InfoBarDelegate> delegate) | 23 std::unique_ptr<infobars::InfoBarDelegate> delegate) |
24 : infobars::InfoBar(std::move(delegate)) {} | 24 : infobars::InfoBar(std::move(delegate)) {} |
25 | 25 |
26 InfoBarAndroid::~InfoBarAndroid() { | 26 InfoBarAndroid::~InfoBarAndroid() { |
27 if (!java_info_bar_.is_null()) { | 27 if (!java_info_bar_.is_null()) { |
28 JNIEnv* env = base::android::AttachCurrentThread(); | 28 JNIEnv* env = base::android::AttachCurrentThread(); |
29 Java_InfoBar_onNativeDestroyed(env, java_info_bar_.obj()); | 29 Java_InfoBar_onNativeDestroyed(env, java_info_bar_); |
30 } | 30 } |
31 } | 31 } |
32 | 32 |
33 void InfoBarAndroid::ReassignJavaInfoBar(InfoBarAndroid* replacement) { | 33 void InfoBarAndroid::ReassignJavaInfoBar(InfoBarAndroid* replacement) { |
34 DCHECK(replacement); | 34 DCHECK(replacement); |
35 if (!java_info_bar_.is_null()) { | 35 if (!java_info_bar_.is_null()) { |
36 replacement->SetJavaInfoBar(java_info_bar_); | 36 replacement->SetJavaInfoBar(java_info_bar_); |
37 java_info_bar_.Reset(); | 37 java_info_bar_.Reset(); |
38 } | 38 } |
39 } | 39 } |
40 | 40 |
41 void InfoBarAndroid::SetJavaInfoBar( | 41 void InfoBarAndroid::SetJavaInfoBar( |
42 const base::android::JavaRef<jobject>& java_info_bar) { | 42 const base::android::JavaRef<jobject>& java_info_bar) { |
43 DCHECK(java_info_bar_.is_null()); | 43 DCHECK(java_info_bar_.is_null()); |
44 java_info_bar_.Reset(java_info_bar); | 44 java_info_bar_.Reset(java_info_bar); |
45 JNIEnv* env = base::android::AttachCurrentThread(); | 45 JNIEnv* env = base::android::AttachCurrentThread(); |
46 Java_InfoBar_setNativeInfoBar(env, java_info_bar.obj(), | 46 Java_InfoBar_setNativeInfoBar(env, java_info_bar, |
47 reinterpret_cast<intptr_t>(this)); | 47 reinterpret_cast<intptr_t>(this)); |
48 } | 48 } |
49 | 49 |
50 jobject InfoBarAndroid::GetJavaInfoBar() { | 50 jobject InfoBarAndroid::GetJavaInfoBar() { |
51 return java_info_bar_.obj(); | 51 return java_info_bar_.obj(); |
52 } | 52 } |
53 | 53 |
54 bool InfoBarAndroid::HasSetJavaInfoBar() const { | 54 bool InfoBarAndroid::HasSetJavaInfoBar() const { |
55 return !java_info_bar_.is_null(); | 55 return !java_info_bar_.is_null(); |
56 } | 56 } |
57 | 57 |
58 void InfoBarAndroid::OnButtonClicked(JNIEnv* env, | 58 void InfoBarAndroid::OnButtonClicked(JNIEnv* env, |
59 const JavaParamRef<jobject>& obj, | 59 const JavaParamRef<jobject>& obj, |
60 jint action) { | 60 jint action) { |
61 ProcessButton(action); | 61 ProcessButton(action); |
62 } | 62 } |
63 | 63 |
64 void InfoBarAndroid::OnCloseButtonClicked(JNIEnv* env, | 64 void InfoBarAndroid::OnCloseButtonClicked(JNIEnv* env, |
65 const JavaParamRef<jobject>& obj) { | 65 const JavaParamRef<jobject>& obj) { |
66 if (!owner()) | 66 if (!owner()) |
67 return; // We're closing; don't call anything, it might access the owner. | 67 return; // We're closing; don't call anything, it might access the owner. |
68 delegate()->InfoBarDismissed(); | 68 delegate()->InfoBarDismissed(); |
69 RemoveSelf(); | 69 RemoveSelf(); |
70 } | 70 } |
71 | 71 |
72 void InfoBarAndroid::CloseJavaInfoBar() { | 72 void InfoBarAndroid::CloseJavaInfoBar() { |
73 if (!java_info_bar_.is_null()) { | 73 if (!java_info_bar_.is_null()) { |
74 JNIEnv* env = base::android::AttachCurrentThread(); | 74 JNIEnv* env = base::android::AttachCurrentThread(); |
75 Java_InfoBar_closeInfoBar(env, java_info_bar_.obj()); | 75 Java_InfoBar_closeInfoBar(env, java_info_bar_); |
76 } | 76 } |
77 } | 77 } |
78 | 78 |
79 int InfoBarAndroid::GetEnumeratedIconId() { | 79 int InfoBarAndroid::GetEnumeratedIconId() { |
80 return ResourceMapper::MapFromChromiumId(delegate()->GetIconId()); | 80 return ResourceMapper::MapFromChromiumId(delegate()->GetIconId()); |
81 } | 81 } |
82 | 82 |
83 | 83 |
84 // Native JNI methods --------------------------------------------------------- | 84 // Native JNI methods --------------------------------------------------------- |
85 | 85 |
86 bool RegisterNativeInfoBar(JNIEnv* env) { | 86 bool RegisterNativeInfoBar(JNIEnv* env) { |
87 return RegisterNativesImpl(env); | 87 return RegisterNativesImpl(env); |
88 } | 88 } |
OLD | NEW |