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/card_unmask_prompt_view_android.h"
7 #include "chrome/browser/android/resource_mapper.h"
8 #include "chrome/browser/ui/autofill/create_card_unmask_prompt_view.h"
9 #include "components/autofill/core/browser/ui/card_unmask_prompt_controller.h"
10 #include "content/public/browser/web_contents.h"
11 #include "jni/CardUnmaskBridge_jni.h"
12 #include "ui/android/view_android.h"
13 #include "ui/android/window_android.h"
17 CardUnmaskPromptView
* CreateCardUnmaskPromptView(
18 CardUnmaskPromptController
* controller
,
19 content::WebContents
* web_contents
) {
20 return new CardUnmaskPromptViewAndroid(controller
, web_contents
);
23 CardUnmaskPromptViewAndroid::CardUnmaskPromptViewAndroid(
24 CardUnmaskPromptController
* controller
,
25 content::WebContents
* web_contents
)
26 : controller_(controller
), web_contents_(web_contents
) {
29 CardUnmaskPromptViewAndroid::~CardUnmaskPromptViewAndroid() {
31 controller_
->OnUnmaskDialogClosed();
34 void CardUnmaskPromptViewAndroid::Show() {
35 JNIEnv
* env
= base::android::AttachCurrentThread();
36 ui::ViewAndroid
* view_android
= web_contents_
->GetNativeView();
38 ScopedJavaLocalRef
<jstring
> dialog_title
=
39 base::android::ConvertUTF16ToJavaString(env
,
40 controller_
->GetWindowTitle());
41 ScopedJavaLocalRef
<jstring
> instructions
=
42 base::android::ConvertUTF16ToJavaString(
43 env
, controller_
->GetInstructionsMessage());
44 java_object_
.Reset(Java_CardUnmaskBridge_create(
45 env
, reinterpret_cast<intptr_t>(this), dialog_title
.obj(),
47 ResourceMapper::MapFromChromiumId(controller_
->GetCvcImageRid()),
48 controller_
->ShouldRequestExpirationDate(),
49 controller_
->CanStoreLocally(),
50 controller_
->GetStoreLocallyStartState(),
51 view_android
->GetWindowAndroid()->GetJavaObject().obj()));
53 Java_CardUnmaskBridge_show(env
, java_object_
.obj());
56 bool CardUnmaskPromptViewAndroid::CheckUserInputValidity(JNIEnv
* env
,
59 return controller_
->InputCvcIsValid(
60 base::android::ConvertJavaStringToUTF16(env
, response
));
63 void CardUnmaskPromptViewAndroid::OnUserInput(JNIEnv
* env
,
68 jboolean should_store_locally
) {
69 controller_
->OnUnmaskResponse(
70 base::android::ConvertJavaStringToUTF16(env
, cvc
),
71 base::android::ConvertJavaStringToUTF16(env
, month
),
72 base::android::ConvertJavaStringToUTF16(env
, year
),
73 should_store_locally
);
76 void CardUnmaskPromptViewAndroid::OnNewCardLinkClicked(JNIEnv
* env
,
78 controller_
->NewCardLinkClicked();
79 Java_CardUnmaskBridge_update(env
, java_object_
.obj(),
80 base::android::ConvertUTF16ToJavaString(
81 env
, controller_
->GetWindowTitle()).obj(),
82 base::android::ConvertUTF16ToJavaString(
83 env
, controller_
->GetInstructionsMessage()).obj(),
84 controller_
->ShouldRequestExpirationDate());
87 void CardUnmaskPromptViewAndroid::PromptDismissed(JNIEnv
* env
, jobject obj
) {
91 void CardUnmaskPromptViewAndroid::ControllerGone() {
92 controller_
= nullptr;
93 JNIEnv
* env
= base::android::AttachCurrentThread();
94 Java_CardUnmaskBridge_dismiss(env
, java_object_
.obj());
97 void CardUnmaskPromptViewAndroid::DisableAndWaitForVerification() {
98 JNIEnv
* env
= base::android::AttachCurrentThread();
99 Java_CardUnmaskBridge_disableAndWaitForVerification(env
, java_object_
.obj());
102 void CardUnmaskPromptViewAndroid::GotVerificationResult(
103 const base::string16
& error_message
,
105 JNIEnv
* env
= base::android::AttachCurrentThread();
106 ScopedJavaLocalRef
<jstring
> message
;
107 if (!error_message
.empty())
108 message
= base::android::ConvertUTF16ToJavaString(env
, error_message
);
110 Java_CardUnmaskBridge_verificationFinished(env
, java_object_
.obj(),
111 message
.obj(), allow_retry
);
115 bool CardUnmaskPromptViewAndroid::Register(JNIEnv
* env
) {
116 return RegisterNativesImpl(env
);
119 } // namespace autofill