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 #include "chrome/browser/ui/android/infobars/infobar_android.h" | 5 #include "chrome/browser/ui/android/infobars/infobar_android.h" |
5 | 6 |
6 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
7 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
8 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
9 #include "chrome/browser/android/resource_mapper.h" | 10 #include "chrome/browser/android/resource_mapper.h" |
10 #include "chrome/browser/infobars/infobar.h" | 11 #include "chrome/browser/infobars/infobar.h" |
11 #include "chrome/browser/infobars/infobar_delegate.h" | 12 #include "chrome/browser/infobars/infobar_delegate.h" |
12 #include "chrome/browser/infobars/infobar_service.h" | 13 #include "chrome/browser/infobars/infobar_service.h" |
13 #include "jni/InfoBar_jni.h" | 14 #include "jni/InfoBar_jni.h" |
14 | 15 |
15 namespace gfx { | |
16 class Image; | |
17 } | |
18 | 16 |
19 using base::android::AttachCurrentThread; | 17 // InfoBar -------------------------------------------------------------------- |
20 using base::android::JavaRef; | |
21 | 18 |
22 | 19 // Static constants defined in infobar.h. We don't really use them for anything |
23 // static constants defined in infobar.h we don't really use them for anything | 20 // but they are required. The values are copied from the GTK implementation. |
24 // but they are required. The values are copied from the GTK implementation. | |
25 const int InfoBar::kSeparatorLineHeight = 1; | 21 const int InfoBar::kSeparatorLineHeight = 1; |
26 const int InfoBar::kDefaultArrowTargetHeight = 9; | 22 const int InfoBar::kDefaultArrowTargetHeight = 9; |
27 const int InfoBar::kMaximumArrowTargetHeight = 24; | 23 const int InfoBar::kMaximumArrowTargetHeight = 24; |
28 const int InfoBar::kDefaultArrowTargetHalfWidth = kDefaultArrowTargetHeight; | 24 const int InfoBar::kDefaultArrowTargetHalfWidth = kDefaultArrowTargetHeight; |
29 const int InfoBar::kMaximumArrowTargetHalfWidth = 14; | 25 const int InfoBar::kMaximumArrowTargetHalfWidth = 14; |
30 const int InfoBar::kDefaultBarTargetHeight = 36; | 26 const int InfoBar::kDefaultBarTargetHeight = 36; |
31 | 27 |
| 28 |
| 29 // InfoBarAndroid ------------------------------------------------------------- |
| 30 |
32 InfoBarAndroid::InfoBarAndroid(InfoBarService* owner, InfoBarDelegate* delegate) | 31 InfoBarAndroid::InfoBarAndroid(InfoBarService* owner, InfoBarDelegate* delegate) |
33 : InfoBar(owner, delegate), | 32 : InfoBar(owner, delegate), |
34 delegate_(delegate) { | 33 delegate_(delegate) { |
35 DCHECK(delegate_); | 34 DCHECK(delegate_); |
36 DCHECK(delegate_->owner()); | 35 DCHECK(delegate_->owner()); |
37 } | 36 } |
38 | 37 |
39 InfoBarAndroid::~InfoBarAndroid() {} | 38 InfoBarAndroid::~InfoBarAndroid() { |
| 39 } |
40 | 40 |
41 void InfoBarAndroid::ReassignJavaInfoBar(InfoBarAndroid* replacement) { | 41 void InfoBarAndroid::ReassignJavaInfoBar(InfoBarAndroid* replacement) { |
42 DCHECK(replacement); | 42 DCHECK(replacement); |
43 if (!java_info_bar_.is_null()) { | 43 if (!java_info_bar_.is_null()) { |
44 replacement->set_java_infobar(java_info_bar_); | 44 replacement->set_java_infobar(java_info_bar_); |
45 java_info_bar_.Reset(); | 45 java_info_bar_.Reset(); |
46 } | 46 } |
47 } | 47 } |
48 | 48 |
49 void InfoBarAndroid::set_java_infobar(const JavaRef<jobject>& java_info_bar) { | 49 void InfoBarAndroid::set_java_infobar( |
| 50 const base::android::JavaRef<jobject>& java_info_bar) { |
50 DCHECK(java_info_bar_.is_null()); | 51 DCHECK(java_info_bar_.is_null()); |
51 java_info_bar_.Reset(java_info_bar); | 52 java_info_bar_.Reset(java_info_bar); |
52 } | 53 } |
53 | 54 |
54 bool InfoBarAndroid::HasSetJavaInfoBar() const { | 55 bool InfoBarAndroid::HasSetJavaInfoBar() const { |
55 return !java_info_bar_.is_null(); | 56 return !java_info_bar_.is_null(); |
56 } | 57 } |
57 | 58 |
58 void InfoBarAndroid::OnButtonClicked( | 59 void InfoBarAndroid::OnButtonClicked(JNIEnv* env, |
59 JNIEnv* env, jobject obj, jint action, jstring action_value) { | 60 jobject obj, |
| 61 jint action, |
| 62 jstring action_value) { |
60 DCHECK(delegate_); | 63 DCHECK(delegate_); |
61 std::string value = base::android::ConvertJavaStringToUTF8(env, action_value); | 64 std::string value = base::android::ConvertJavaStringToUTF8(env, action_value); |
62 ProcessButton(action, value); | 65 ProcessButton(action, value); |
63 } | 66 } |
64 | 67 |
65 void InfoBarAndroid::OnCloseButtonClicked(JNIEnv* env, jobject obj) { | 68 void InfoBarAndroid::OnCloseButtonClicked(JNIEnv* env, jobject obj) { |
66 delegate_->InfoBarDismissed(); | 69 delegate_->InfoBarDismissed(); |
67 } | 70 } |
68 | 71 |
69 void InfoBarAndroid::OnInfoBarClosed(JNIEnv* env, jobject obj) { | 72 void InfoBarAndroid::OnInfoBarClosed(JNIEnv* env, jobject obj) { |
70 java_info_bar_.Reset(); // So we don't notify Java. | 73 java_info_bar_.Reset(); // So we don't notify Java. |
71 if (owner()) | 74 if (owner()) |
72 RemoveSelf(); | 75 RemoveSelf(); |
73 } | 76 } |
74 | 77 |
75 void InfoBarAndroid::CloseInfoBar() { | |
76 CloseJavaInfoBar(); | |
77 if (owner()) | |
78 RemoveSelf(); | |
79 } | |
80 | |
81 void InfoBarAndroid::CloseJavaInfoBar() { | 78 void InfoBarAndroid::CloseJavaInfoBar() { |
82 if (!java_info_bar_.is_null()) { | 79 if (!java_info_bar_.is_null()) { |
83 JNIEnv* env = AttachCurrentThread(); | 80 JNIEnv* env = base::android::AttachCurrentThread(); |
84 Java_InfoBar_closeInfoBar(env, java_info_bar_.obj()); | 81 Java_InfoBar_closeInfoBar(env, java_info_bar_.obj()); |
85 } | 82 } |
86 } | 83 } |
87 | 84 |
88 int InfoBarAndroid::GetEnumeratedIconId() { | 85 int InfoBarAndroid::GetEnumeratedIconId() { |
89 DCHECK(delegate_); | 86 DCHECK(delegate_); |
90 return ResourceMapper::MapFromChromiumId(delegate_->GetIconID()); | 87 return ResourceMapper::MapFromChromiumId(delegate_->GetIconID()); |
91 } | 88 } |
92 | 89 |
93 // ----------------------------------------------------------------------------- | 90 void InfoBarAndroid::CloseInfoBar() { |
94 // Native JNI methods | 91 CloseJavaInfoBar(); |
95 // ----------------------------------------------------------------------------- | 92 if (owner()) |
| 93 RemoveSelf(); |
| 94 } |
96 | 95 |
97 // Register native methods | 96 |
| 97 // Native JNI methods --------------------------------------------------------- |
| 98 |
98 bool RegisterNativeInfoBar(JNIEnv* env) { | 99 bool RegisterNativeInfoBar(JNIEnv* env) { |
99 return RegisterNativesImpl(env); | 100 return RegisterNativesImpl(env); |
100 } | 101 } |
OLD | NEW |