OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/autofill/autofill_popup_view_android.h" | 5 #include "chrome/browser/ui/android/autofill/autofill_popup_view_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/command_line.h" | 9 #include "base/command_line.h" |
10 #include "chrome/browser/android/resource_mapper.h" | 10 #include "chrome/browser/android/resource_mapper.h" |
(...skipping 18 matching lines...) Expand all Loading... | |
29 AutofillPopupController* controller) | 29 AutofillPopupController* controller) |
30 : controller_(controller), deleting_index_(-1) {} | 30 : controller_(controller), deleting_index_(-1) {} |
31 | 31 |
32 AutofillPopupViewAndroid::~AutofillPopupViewAndroid() {} | 32 AutofillPopupViewAndroid::~AutofillPopupViewAndroid() {} |
33 | 33 |
34 void AutofillPopupViewAndroid::Show() { | 34 void AutofillPopupViewAndroid::Show() { |
35 JNIEnv* env = base::android::AttachCurrentThread(); | 35 JNIEnv* env = base::android::AttachCurrentThread(); |
36 ui::ViewAndroid* view_android = controller_->container_view(); | 36 ui::ViewAndroid* view_android = controller_->container_view(); |
37 | 37 |
38 DCHECK(view_android); | 38 DCHECK(view_android); |
39 popup_view_ = view_android->AcquireAnchorView(); | |
40 if (popup_view_.is_null()) | |
41 return; | |
39 | 42 |
40 java_object_.Reset(Java_AutofillPopupBridge_create( | 43 java_object_.Reset(Java_AutofillPopupBridge_create( |
41 env, reinterpret_cast<intptr_t>(this), | 44 env, popup_view_.view().obj(), controller_->element_bounds().width(), |
42 view_android->GetWindowAndroid()->GetJavaObject().obj(), | 45 reinterpret_cast<intptr_t>(this), |
43 view_android->GetViewAndroidDelegate().obj())); | 46 view_android->GetWindowAndroid()->GetJavaObject().obj())); |
44 | 47 |
45 UpdateBoundsAndRedrawPopup(); | 48 UpdateBoundsAndRedrawPopup(); |
46 } | 49 } |
47 | 50 |
48 void AutofillPopupViewAndroid::Hide() { | 51 void AutofillPopupViewAndroid::Hide() { |
49 controller_ = NULL; | 52 controller_ = NULL; |
50 JNIEnv* env = base::android::AttachCurrentThread(); | 53 JNIEnv* env = base::android::AttachCurrentThread(); |
51 Java_AutofillPopupBridge_dismiss(env, java_object_.obj()); | 54 if (!java_object_.is_null()) { |
55 Java_AutofillPopupBridge_dismiss(env, java_object_.obj()); | |
56 } else { | |
57 PopupDismissedInternal(); | |
no sievers
2016/07/20 18:46:04
Yes, good catch to not leak |this| here.
But now
Jinsuk Kim
2016/07/20 23:19:03
Acknowledged. Called |delete this| directly and ad
| |
58 } | |
52 } | 59 } |
53 | 60 |
54 void AutofillPopupViewAndroid::UpdateBoundsAndRedrawPopup() { | 61 void AutofillPopupViewAndroid::UpdateBoundsAndRedrawPopup() { |
62 if (java_object_.is_null() || popup_view_.is_null()) | |
63 return; | |
64 | |
65 ui::ViewAndroid* view_android = controller_->container_view(); | |
66 | |
67 DCHECK(view_android); | |
68 view_android->SetAnchorRect(popup_view_.view(), | |
69 controller_->element_bounds()); | |
70 | |
55 JNIEnv* env = base::android::AttachCurrentThread(); | 71 JNIEnv* env = base::android::AttachCurrentThread(); |
56 Java_AutofillPopupBridge_setAnchorRect( | |
57 env, | |
58 java_object_.obj(), | |
59 controller_->element_bounds().x(), | |
60 controller_->element_bounds().y(), | |
61 controller_->element_bounds().width(), | |
62 controller_->element_bounds().height()); | |
63 | |
64 size_t count = controller_->GetLineCount(); | 72 size_t count = controller_->GetLineCount(); |
65 ScopedJavaLocalRef<jobjectArray> data_array = | 73 ScopedJavaLocalRef<jobjectArray> data_array = |
66 Java_AutofillPopupBridge_createAutofillSuggestionArray(env, count); | 74 Java_AutofillPopupBridge_createAutofillSuggestionArray(env, count); |
67 | 75 |
68 for (size_t i = 0; i < count; ++i) { | 76 for (size_t i = 0; i < count; ++i) { |
69 ScopedJavaLocalRef<jstring> value = base::android::ConvertUTF16ToJavaString( | 77 ScopedJavaLocalRef<jstring> value = base::android::ConvertUTF16ToJavaString( |
70 env, controller_->GetElidedValueAt(i)); | 78 env, controller_->GetElidedValueAt(i)); |
71 ScopedJavaLocalRef<jstring> label = | 79 ScopedJavaLocalRef<jstring> label = |
72 base::android::ConvertUTF16ToJavaString( | 80 base::android::ConvertUTF16ToJavaString( |
73 env, controller_->GetElidedLabelAt(i)); | 81 env, controller_->GetElidedLabelAt(i)); |
(...skipping 24 matching lines...) Expand all Loading... | |
98 jint list_index) { | 106 jint list_index) { |
99 // Race: Hide() may have already run. | 107 // Race: Hide() may have already run. |
100 if (controller_) | 108 if (controller_) |
101 controller_->AcceptSuggestion(list_index); | 109 controller_->AcceptSuggestion(list_index); |
102 } | 110 } |
103 | 111 |
104 void AutofillPopupViewAndroid::DeletionRequested( | 112 void AutofillPopupViewAndroid::DeletionRequested( |
105 JNIEnv* env, | 113 JNIEnv* env, |
106 const JavaParamRef<jobject>& obj, | 114 const JavaParamRef<jobject>& obj, |
107 jint list_index) { | 115 jint list_index) { |
108 if (!controller_) | 116 if (!controller_ || java_object_.is_null()) |
109 return; | 117 return; |
110 | 118 |
111 base::string16 confirmation_title, confirmation_body; | 119 base::string16 confirmation_title, confirmation_body; |
112 if (!controller_->GetRemovalConfirmationText(list_index, &confirmation_title, | 120 if (!controller_->GetRemovalConfirmationText(list_index, &confirmation_title, |
113 &confirmation_body)) { | 121 &confirmation_body)) { |
114 return; | 122 return; |
115 } | 123 } |
116 | 124 |
117 deleting_index_ = list_index; | 125 deleting_index_ = list_index; |
118 Java_AutofillPopupBridge_confirmDeletion( | 126 Java_AutofillPopupBridge_confirmDeletion( |
(...skipping 11 matching lines...) Expand all Loading... | |
130 if (!controller_) | 138 if (!controller_) |
131 return; | 139 return; |
132 | 140 |
133 CHECK_GE(deleting_index_, 0); | 141 CHECK_GE(deleting_index_, 0); |
134 controller_->RemoveSuggestion(deleting_index_); | 142 controller_->RemoveSuggestion(deleting_index_); |
135 } | 143 } |
136 | 144 |
137 void AutofillPopupViewAndroid::PopupDismissed( | 145 void AutofillPopupViewAndroid::PopupDismissed( |
138 JNIEnv* env, | 146 JNIEnv* env, |
139 const JavaParamRef<jobject>& obj) { | 147 const JavaParamRef<jobject>& obj) { |
148 PopupDismissedInternal(); | |
149 } | |
150 | |
151 void AutofillPopupViewAndroid::PopupDismissedInternal() { | |
140 if (controller_) | 152 if (controller_) |
141 controller_->ViewDestroyed(); | 153 controller_->ViewDestroyed(); |
142 | 154 |
143 delete this; | 155 delete this; |
144 } | 156 } |
145 | 157 |
146 void AutofillPopupViewAndroid::InvalidateRow(size_t) {} | 158 void AutofillPopupViewAndroid::InvalidateRow(size_t) {} |
147 | 159 |
148 // static | 160 // static |
149 bool AutofillPopupViewAndroid::RegisterAutofillPopupViewAndroid(JNIEnv* env) { | 161 bool AutofillPopupViewAndroid::RegisterAutofillPopupViewAndroid(JNIEnv* env) { |
150 return RegisterNativesImpl(env); | 162 return RegisterNativesImpl(env); |
151 } | 163 } |
152 | 164 |
153 // static | 165 // static |
154 AutofillPopupView* AutofillPopupView::Create( | 166 AutofillPopupView* AutofillPopupView::Create( |
155 AutofillPopupController* controller) { | 167 AutofillPopupController* controller) { |
156 if (IsKeyboardAccessoryEnabled()) | 168 if (IsKeyboardAccessoryEnabled()) |
157 return new AutofillKeyboardAccessoryView(controller); | 169 return new AutofillKeyboardAccessoryView(controller); |
158 | 170 |
159 return new AutofillPopupViewAndroid(controller); | 171 return new AutofillPopupViewAndroid(controller); |
160 } | 172 } |
161 | 173 |
162 } // namespace autofill | 174 } // namespace autofill |
OLD | NEW |