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(env).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 // Hide() should delete |this| either via Java dismiss or directly. | |
58 delete this; | |
59 } | |
52 } | 60 } |
53 | 61 |
54 void AutofillPopupViewAndroid::UpdateBoundsAndRedrawPopup() { | 62 void AutofillPopupViewAndroid::UpdateBoundsAndRedrawPopup() { |
63 if (java_object_.is_null() || popup_view_.is_null()) | |
Ted C
2016/07/27 20:10:47
we are only null checking popup_view here because
Jinsuk Kim
2016/07/29 06:09:13
That's correct. Added the null checking in defensi
| |
64 return; | |
65 | |
66 ui::ViewAndroid* view_android = controller_->container_view(); | |
67 | |
68 DCHECK(view_android); | |
55 JNIEnv* env = base::android::AttachCurrentThread(); | 69 JNIEnv* env = base::android::AttachCurrentThread(); |
56 Java_AutofillPopupBridge_setAnchorRect( | 70 view_android->SetAnchorRect(popup_view_.view(env), |
boliu
2016/07/27 16:20:26
need null check
Ted C
2016/07/27 20:10:47
for view_android right? popup_view_ is null check
Jinsuk Kim
2016/07/29 06:09:13
Oh what Bo means by that is I need to change the w
| |
57 env, | 71 controller_->element_bounds()); |
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 | 72 |
64 size_t count = controller_->GetLineCount(); | 73 size_t count = controller_->GetLineCount(); |
65 ScopedJavaLocalRef<jobjectArray> data_array = | 74 ScopedJavaLocalRef<jobjectArray> data_array = |
66 Java_AutofillPopupBridge_createAutofillSuggestionArray(env, count); | 75 Java_AutofillPopupBridge_createAutofillSuggestionArray(env, count); |
67 | 76 |
68 for (size_t i = 0; i < count; ++i) { | 77 for (size_t i = 0; i < count; ++i) { |
69 ScopedJavaLocalRef<jstring> value = base::android::ConvertUTF16ToJavaString( | 78 ScopedJavaLocalRef<jstring> value = base::android::ConvertUTF16ToJavaString( |
70 env, controller_->GetElidedValueAt(i)); | 79 env, controller_->GetElidedValueAt(i)); |
71 ScopedJavaLocalRef<jstring> label = | 80 ScopedJavaLocalRef<jstring> label = |
72 base::android::ConvertUTF16ToJavaString( | 81 base::android::ConvertUTF16ToJavaString( |
(...skipping 26 matching lines...) Expand all Loading... | |
99 jint list_index) { | 108 jint list_index) { |
100 // Race: Hide() may have already run. | 109 // Race: Hide() may have already run. |
101 if (controller_) | 110 if (controller_) |
102 controller_->AcceptSuggestion(list_index); | 111 controller_->AcceptSuggestion(list_index); |
103 } | 112 } |
104 | 113 |
105 void AutofillPopupViewAndroid::DeletionRequested( | 114 void AutofillPopupViewAndroid::DeletionRequested( |
106 JNIEnv* env, | 115 JNIEnv* env, |
107 const JavaParamRef<jobject>& obj, | 116 const JavaParamRef<jobject>& obj, |
108 jint list_index) { | 117 jint list_index) { |
109 if (!controller_) | 118 if (!controller_ || java_object_.is_null()) |
110 return; | 119 return; |
111 | 120 |
112 base::string16 confirmation_title, confirmation_body; | 121 base::string16 confirmation_title, confirmation_body; |
113 if (!controller_->GetRemovalConfirmationText(list_index, &confirmation_title, | 122 if (!controller_->GetRemovalConfirmationText(list_index, &confirmation_title, |
114 &confirmation_body)) { | 123 &confirmation_body)) { |
115 return; | 124 return; |
116 } | 125 } |
117 | 126 |
118 deleting_index_ = list_index; | 127 deleting_index_ = list_index; |
119 Java_AutofillPopupBridge_confirmDeletion( | 128 Java_AutofillPopupBridge_confirmDeletion( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 // static | 163 // static |
155 AutofillPopupView* AutofillPopupView::Create( | 164 AutofillPopupView* AutofillPopupView::Create( |
156 AutofillPopupController* controller) { | 165 AutofillPopupController* controller) { |
157 if (IsKeyboardAccessoryEnabled()) | 166 if (IsKeyboardAccessoryEnabled()) |
158 return new AutofillKeyboardAccessoryView(controller); | 167 return new AutofillKeyboardAccessoryView(controller); |
159 | 168 |
160 return new AutofillPopupViewAndroid(controller); | 169 return new AutofillPopupViewAndroid(controller); |
161 } | 170 } |
162 | 171 |
163 } // namespace autofill | 172 } // namespace autofill |
OLD | NEW |