Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / android / autofill / credit_card_scanner_view_android.cc
blobbd2914d35e0fe1ff71a85dced608ec5fd7dd9ae9
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/credit_card_scanner_view_android.h"
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/ui/android/window_android_helper.h"
11 #include "chrome/browser/ui/autofill/credit_card_scanner_view_delegate.h"
12 #include "content/public/browser/android/content_view_core.h"
13 #include "jni/CreditCardScanner_jni.h"
14 #include "ui/android/view_android.h"
15 #include "ui/android/window_android.h"
17 namespace autofill {
19 // static
20 bool CreditCardScannerView::CanShow() {
21 JNIEnv* env = base::android::AttachCurrentThread();
22 base::android::ScopedJavaGlobalRef<jobject> java_object(
23 Java_CreditCardScanner_create(
24 env, 0, base::android::GetApplicationContext(), 0));
25 return Java_CreditCardScanner_canScan(env, java_object.obj());
28 // static
29 scoped_ptr<CreditCardScannerView> CreditCardScannerView::Create(
30 const base::WeakPtr<CreditCardScannerViewDelegate>& delegate,
31 content::WebContents* web_contents) {
32 return make_scoped_ptr(
33 new CreditCardScannerViewAndroid(delegate, web_contents));
36 // static
37 bool CreditCardScannerViewAndroid::Register(JNIEnv* env) {
38 return RegisterNativesImpl(env);
41 CreditCardScannerViewAndroid::CreditCardScannerViewAndroid(
42 const base::WeakPtr<CreditCardScannerViewDelegate>& delegate,
43 content::WebContents* web_contents)
44 : delegate_(delegate),
45 java_object_(Java_CreditCardScanner_create(
46 base::android::AttachCurrentThread(),
47 reinterpret_cast<intptr_t>(this),
48 base::android::GetApplicationContext(),
49 WindowAndroidHelper::FromWebContents(web_contents)
50 ->GetWindowAndroid()->GetJavaObject().obj())) {}
52 CreditCardScannerViewAndroid::~CreditCardScannerViewAndroid() {}
54 void CreditCardScannerViewAndroid::ScanCancelled(JNIEnv* env, jobject object) {
55 delegate_->ScanCancelled();
58 void CreditCardScannerViewAndroid::ScanCompleted(JNIEnv* env,
59 jobject object,
60 jstring card_number,
61 jint expiration_month,
62 jint expiration_year) {
63 delegate_->ScanCompleted(
64 base::android::ConvertJavaStringToUTF16(env, card_number),
65 static_cast<int>(expiration_month), static_cast<int>(expiration_year));
68 void CreditCardScannerViewAndroid::Show() {
69 JNIEnv* env = base::android::AttachCurrentThread();
70 Java_CreditCardScanner_scan(env, java_object_.obj());
73 } // namespace autofill