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" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 const int InfoBar::kSeparatorLineHeight = 1; | 21 const int InfoBar::kSeparatorLineHeight = 1; |
22 const int InfoBar::kDefaultArrowTargetHeight = 9; | 22 const int InfoBar::kDefaultArrowTargetHeight = 9; |
23 const int InfoBar::kMaximumArrowTargetHeight = 24; | 23 const int InfoBar::kMaximumArrowTargetHeight = 24; |
24 const int InfoBar::kDefaultArrowTargetHalfWidth = kDefaultArrowTargetHeight; | 24 const int InfoBar::kDefaultArrowTargetHalfWidth = kDefaultArrowTargetHeight; |
25 const int InfoBar::kMaximumArrowTargetHalfWidth = 14; | 25 const int InfoBar::kMaximumArrowTargetHalfWidth = 14; |
26 const int InfoBar::kDefaultBarTargetHeight = 36; | 26 const int InfoBar::kDefaultBarTargetHeight = 36; |
27 | 27 |
28 | 28 |
29 // InfoBarAndroid ------------------------------------------------------------- | 29 // InfoBarAndroid ------------------------------------------------------------- |
30 | 30 |
31 InfoBarAndroid::InfoBarAndroid(InfoBarService* owner, InfoBarDelegate* delegate) | 31 InfoBarAndroid::InfoBarAndroid(scoped_ptr<InfoBarDelegate> delegate) |
32 : InfoBar(owner, delegate), | 32 : InfoBar(delegate.Pass()) { |
33 delegate_(delegate) { | |
34 DCHECK(delegate_); | |
35 DCHECK(delegate_->owner()); | |
36 } | 33 } |
37 | 34 |
38 InfoBarAndroid::~InfoBarAndroid() { | 35 InfoBarAndroid::~InfoBarAndroid() { |
39 } | 36 } |
40 | 37 |
41 void InfoBarAndroid::ReassignJavaInfoBar(InfoBarAndroid* replacement) { | 38 void InfoBarAndroid::ReassignJavaInfoBar(InfoBarAndroid* replacement) { |
42 DCHECK(replacement); | 39 DCHECK(replacement); |
43 if (!java_info_bar_.is_null()) { | 40 if (!java_info_bar_.is_null()) { |
44 replacement->set_java_infobar(java_info_bar_); | 41 replacement->set_java_infobar(java_info_bar_); |
45 java_info_bar_.Reset(); | 42 java_info_bar_.Reset(); |
46 } | 43 } |
47 } | 44 } |
48 | 45 |
49 void InfoBarAndroid::set_java_infobar( | 46 void InfoBarAndroid::set_java_infobar( |
50 const base::android::JavaRef<jobject>& java_info_bar) { | 47 const base::android::JavaRef<jobject>& java_info_bar) { |
51 DCHECK(java_info_bar_.is_null()); | 48 DCHECK(java_info_bar_.is_null()); |
52 java_info_bar_.Reset(java_info_bar); | 49 java_info_bar_.Reset(java_info_bar); |
53 } | 50 } |
54 | 51 |
55 bool InfoBarAndroid::HasSetJavaInfoBar() const { | 52 bool InfoBarAndroid::HasSetJavaInfoBar() const { |
56 return !java_info_bar_.is_null(); | 53 return !java_info_bar_.is_null(); |
57 } | 54 } |
58 | 55 |
59 void InfoBarAndroid::OnButtonClicked(JNIEnv* env, | 56 void InfoBarAndroid::OnButtonClicked(JNIEnv* env, |
60 jobject obj, | 57 jobject obj, |
61 jint action, | 58 jint action, |
62 jstring action_value) { | 59 jstring action_value) { |
63 DCHECK(delegate_); | |
64 std::string value = base::android::ConvertJavaStringToUTF8(env, action_value); | 60 std::string value = base::android::ConvertJavaStringToUTF8(env, action_value); |
65 ProcessButton(action, value); | 61 ProcessButton(action, value); |
66 } | 62 } |
67 | 63 |
68 void InfoBarAndroid::OnCloseButtonClicked(JNIEnv* env, jobject obj) { | 64 void InfoBarAndroid::OnCloseButtonClicked(JNIEnv* env, jobject obj) { |
69 delegate_->InfoBarDismissed(); | 65 delegate()->InfoBarDismissed(); |
66 CloseInfoBar(); // TODO(pkasting): Is this correct? | |
Miguel Garcia
2013/10/07 15:19:00
This method is being removed in https://codereview
Peter Kasting
2013/10/07 20:19:24
Sounds like I should just wait for that to go in a
| |
70 } | 67 } |
71 | 68 |
72 void InfoBarAndroid::OnInfoBarClosed(JNIEnv* env, jobject obj) { | 69 void InfoBarAndroid::OnInfoBarClosed(JNIEnv* env, jobject obj) { |
73 java_info_bar_.Reset(); // So we don't notify Java. | 70 java_info_bar_.Reset(); // So we don't notify Java. |
74 if (owner()) | 71 RemoveSelf(); |
75 RemoveSelf(); | |
76 } | 72 } |
77 | 73 |
78 void InfoBarAndroid::CloseJavaInfoBar() { | 74 void InfoBarAndroid::CloseJavaInfoBar() { |
79 if (!java_info_bar_.is_null()) { | 75 if (!java_info_bar_.is_null()) { |
80 JNIEnv* env = base::android::AttachCurrentThread(); | 76 JNIEnv* env = base::android::AttachCurrentThread(); |
81 Java_InfoBar_closeInfoBar(env, java_info_bar_.obj()); | 77 Java_InfoBar_closeInfoBar(env, java_info_bar_.obj()); |
82 } | 78 } |
83 } | 79 } |
84 | 80 |
85 int InfoBarAndroid::GetEnumeratedIconId() { | 81 int InfoBarAndroid::GetEnumeratedIconId() { |
86 DCHECK(delegate_); | 82 return ResourceMapper::MapFromChromiumId(delegate()->GetIconID()); |
87 return ResourceMapper::MapFromChromiumId(delegate_->GetIconID()); | |
88 } | 83 } |
89 | 84 |
90 void InfoBarAndroid::CloseInfoBar() { | 85 void InfoBarAndroid::CloseInfoBar() { |
91 CloseJavaInfoBar(); | 86 CloseJavaInfoBar(); |
92 if (owner()) | 87 RemoveSelf(); |
93 RemoveSelf(); | |
94 } | 88 } |
95 | 89 |
96 | 90 |
97 // Native JNI methods --------------------------------------------------------- | 91 // Native JNI methods --------------------------------------------------------- |
98 | 92 |
99 bool RegisterNativeInfoBar(JNIEnv* env) { | 93 bool RegisterNativeInfoBar(JNIEnv* env) { |
100 return RegisterNativesImpl(env); | 94 return RegisterNativesImpl(env); |
101 } | 95 } |
OLD | NEW |