OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/android/autofill/password_generation_popup_view_andr
oid.h" |
| 6 |
| 7 #include <jni.h> |
| 8 |
| 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_string.h" |
| 11 #include "base/android/scoped_java_ref.h" |
| 12 #include "base/logging.h" |
| 13 #include "chrome/browser/ui/android/window_android_helper.h" |
| 14 #include "chrome/browser/ui/autofill/password_generation_popup_controller.h" |
| 15 #include "content/public/browser/android/content_view_core.h" |
| 16 #include "jni/PasswordGenerationPopupBridge_jni.h" |
| 17 #include "ui/base/android/view_android.h" |
| 18 #include "ui/base/android/window_android.h" |
| 19 #include "ui/gfx/range/range.h" |
| 20 #include "ui/gfx/rect.h" |
| 21 |
| 22 namespace autofill { |
| 23 |
| 24 PasswordGenerationPopupViewAndroid::PasswordGenerationPopupViewAndroid( |
| 25 PasswordGenerationPopupController* controller) |
| 26 : controller_(controller) {} |
| 27 |
| 28 void PasswordGenerationPopupViewAndroid::SavedPasswordsLinkClicked( |
| 29 JNIEnv* env, jobject obj) { |
| 30 if (controller_) |
| 31 controller_->OnSavedPasswordsLinkClicked(); |
| 32 } |
| 33 |
| 34 void PasswordGenerationPopupViewAndroid::Dismissed(JNIEnv* env, jobject obj) { |
| 35 if (controller_) |
| 36 controller_->ViewDestroyed(); |
| 37 |
| 38 delete this; |
| 39 } |
| 40 |
| 41 void PasswordGenerationPopupViewAndroid::PasswordSelected( |
| 42 JNIEnv* env, jobject object) { |
| 43 if (controller_) |
| 44 controller_->PasswordAccepted(); |
| 45 } |
| 46 |
| 47 // static |
| 48 bool PasswordGenerationPopupViewAndroid::Register(JNIEnv* env) { |
| 49 return RegisterNativesImpl(env); |
| 50 } |
| 51 |
| 52 PasswordGenerationPopupViewAndroid::~PasswordGenerationPopupViewAndroid() {} |
| 53 |
| 54 void PasswordGenerationPopupViewAndroid::Show() { |
| 55 JNIEnv* env = base::android::AttachCurrentThread(); |
| 56 ui::ViewAndroid* view_android = controller_->container_view(); |
| 57 |
| 58 DCHECK(view_android); |
| 59 |
| 60 java_object_.Reset(Java_PasswordGenerationPopupBridge_create( |
| 61 env, |
| 62 reinterpret_cast<intptr_t>(this), |
| 63 view_android->GetWindowAndroid()->GetJavaObject().obj(), |
| 64 view_android->GetJavaObject().obj())); |
| 65 |
| 66 UpdateBoundsAndRedrawPopup(); |
| 67 } |
| 68 |
| 69 void PasswordGenerationPopupViewAndroid::Hide() { |
| 70 controller_ = NULL; |
| 71 JNIEnv* env = base::android::AttachCurrentThread(); |
| 72 Java_PasswordGenerationPopupBridge_hide(env, java_object_.obj()); |
| 73 } |
| 74 |
| 75 gfx::Size PasswordGenerationPopupViewAndroid::GetPreferredSizeOfPasswordView() { |
| 76 static const int kUnusedSize = 0; |
| 77 return gfx::Size(kUnusedSize, kUnusedSize); |
| 78 } |
| 79 |
| 80 void PasswordGenerationPopupViewAndroid::UpdateBoundsAndRedrawPopup() { |
| 81 JNIEnv* env = base::android::AttachCurrentThread(); |
| 82 Java_PasswordGenerationPopupBridge_setAnchorRect( |
| 83 env, |
| 84 java_object_.obj(), |
| 85 controller_->element_bounds().x(), |
| 86 controller_->element_bounds().y(), |
| 87 controller_->element_bounds().width(), |
| 88 controller_->element_bounds().height()); |
| 89 |
| 90 ScopedJavaLocalRef<jstring> password = |
| 91 base::android::ConvertUTF16ToJavaString(env, controller_->password()); |
| 92 ScopedJavaLocalRef<jstring> suggestion = |
| 93 base::android::ConvertUTF16ToJavaString( |
| 94 env, controller_->SuggestedText()); |
| 95 ScopedJavaLocalRef<jstring> help = |
| 96 base::android::ConvertUTF16ToJavaString(env, controller_->HelpText()); |
| 97 |
| 98 Java_PasswordGenerationPopupBridge_show( |
| 99 env, |
| 100 java_object_.obj(), |
| 101 controller_->IsRTL(), |
| 102 controller_->display_password(), |
| 103 password.obj(), |
| 104 suggestion.obj(), |
| 105 help.obj(), |
| 106 controller_->HelpTextLinkRange().start(), |
| 107 controller_->HelpTextLinkRange().end()); |
| 108 } |
| 109 |
| 110 void PasswordGenerationPopupViewAndroid::PasswordSelectionUpdated() {} |
| 111 |
| 112 bool PasswordGenerationPopupViewAndroid::IsPointInPasswordBounds( |
| 113 const gfx::Point& point) { |
| 114 NOTREACHED(); |
| 115 return false; |
| 116 } |
| 117 |
| 118 // static |
| 119 PasswordGenerationPopupView* PasswordGenerationPopupView::Create( |
| 120 PasswordGenerationPopupController* controller) { |
| 121 return new PasswordGenerationPopupViewAndroid(controller); |
| 122 } |
| 123 |
| 124 } // namespace autofill |
OLD | NEW |