Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / android / autofill / password_generation_popup_view_android.cc
blobf5ec945fd106201ce358ccf3cc6e5e7b97f33394
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.
5 #include "chrome/browser/ui/android/autofill/password_generation_popup_view_android.h"
7 #include <jni.h>
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/android/view_android.h"
18 #include "ui/android/window_android.h"
19 #include "ui/gfx/geometry/rect_f.h"
20 #include "ui/gfx/range/range.h"
22 namespace autofill {
24 PasswordGenerationPopupViewAndroid::PasswordGenerationPopupViewAndroid(
25 PasswordGenerationPopupController* controller)
26 : controller_(controller) {}
28 void PasswordGenerationPopupViewAndroid::SavedPasswordsLinkClicked(
29 JNIEnv* env, jobject obj) {
30 if (controller_)
31 controller_->OnSavedPasswordsLinkClicked();
34 void PasswordGenerationPopupViewAndroid::Dismissed(JNIEnv* env, jobject obj) {
35 if (controller_)
36 controller_->ViewDestroyed();
38 delete this;
41 void PasswordGenerationPopupViewAndroid::PasswordSelected(
42 JNIEnv* env, jobject object) {
43 if (controller_)
44 controller_->PasswordAccepted();
47 // static
48 bool PasswordGenerationPopupViewAndroid::Register(JNIEnv* env) {
49 return RegisterNativesImpl(env);
52 PasswordGenerationPopupViewAndroid::~PasswordGenerationPopupViewAndroid() {}
54 void PasswordGenerationPopupViewAndroid::Show() {
55 JNIEnv* env = base::android::AttachCurrentThread();
56 ui::ViewAndroid* view_android = controller_->container_view();
58 DCHECK(view_android);
60 java_object_.Reset(Java_PasswordGenerationPopupBridge_create(
61 env, reinterpret_cast<intptr_t>(this),
62 view_android->GetWindowAndroid()->GetJavaObject().obj(),
63 view_android->GetViewAndroidDelegate().obj()));
65 UpdateBoundsAndRedrawPopup();
68 void PasswordGenerationPopupViewAndroid::Hide() {
69 controller_ = NULL;
70 JNIEnv* env = base::android::AttachCurrentThread();
71 Java_PasswordGenerationPopupBridge_hide(env, java_object_.obj());
74 gfx::Size PasswordGenerationPopupViewAndroid::GetPreferredSizeOfPasswordView() {
75 static const int kUnusedSize = 0;
76 return gfx::Size(kUnusedSize, kUnusedSize);
79 void PasswordGenerationPopupViewAndroid::UpdateBoundsAndRedrawPopup() {
80 JNIEnv* env = base::android::AttachCurrentThread();
81 Java_PasswordGenerationPopupBridge_setAnchorRect(
82 env,
83 java_object_.obj(),
84 controller_->element_bounds().x(),
85 controller_->element_bounds().y(),
86 controller_->element_bounds().width(),
87 controller_->element_bounds().height());
89 ScopedJavaLocalRef<jstring> password =
90 base::android::ConvertUTF16ToJavaString(env, controller_->password());
91 ScopedJavaLocalRef<jstring> suggestion =
92 base::android::ConvertUTF16ToJavaString(
93 env, controller_->SuggestedText());
94 ScopedJavaLocalRef<jstring> help =
95 base::android::ConvertUTF16ToJavaString(env, controller_->HelpText());
97 Java_PasswordGenerationPopupBridge_show(
98 env,
99 java_object_.obj(),
100 controller_->IsRTL(),
101 controller_->display_password(),
102 password.obj(),
103 suggestion.obj(),
104 help.obj(),
105 controller_->HelpTextLinkRange().start(),
106 controller_->HelpTextLinkRange().end());
109 void PasswordGenerationPopupViewAndroid::PasswordSelectionUpdated() {}
111 bool PasswordGenerationPopupViewAndroid::IsPointInPasswordBounds(
112 const gfx::Point& point) {
113 NOTREACHED();
114 return false;
117 // static
118 PasswordGenerationPopupView* PasswordGenerationPopupView::Create(
119 PasswordGenerationPopupController* controller) {
120 return new PasswordGenerationPopupViewAndroid(controller);
123 } // namespace autofill