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/instrument_unmask_prompt_view_andro
id.h" |
| 6 |
| 7 #include "content/public/browser/web_contents.h" |
| 8 #include "jni/InstrumentUnmaskBridge_jni.h" |
| 9 #include "ui/base/android/view_android.h" |
| 10 #include "ui/base/android/window_android.h" |
| 11 |
| 12 namespace autofill { |
| 13 |
| 14 InstrumentUnmaskPromptView* |
| 15 InstrumentUnmaskPromptView::CreateAndShow(content::WebContents* web_contents, |
| 16 const UnmaskCallback& finished) { |
| 17 InstrumentUnmaskPromptViewAndroid* view = |
| 18 new InstrumentUnmaskPromptViewAndroid(web_contents, finished); |
| 19 view->Show(); |
| 20 return view; |
| 21 } |
| 22 |
| 23 InstrumentUnmaskPromptViewAndroid::InstrumentUnmaskPromptViewAndroid( |
| 24 content::WebContents* web_contents, |
| 25 const UnmaskCallback& finished) |
| 26 : web_contents_(web_contents), finished_(finished) { |
| 27 } |
| 28 |
| 29 InstrumentUnmaskPromptViewAndroid::~InstrumentUnmaskPromptViewAndroid() { |
| 30 finished_.Run(response_); |
| 31 } |
| 32 |
| 33 void InstrumentUnmaskPromptViewAndroid::Show() { |
| 34 JNIEnv* env = base::android::AttachCurrentThread(); |
| 35 ui::ViewAndroid* view_android = web_contents_->GetNativeView(); |
| 36 |
| 37 java_object_.Reset(Java_InstrumentUnmaskBridge_create( |
| 38 env, reinterpret_cast<intptr_t>(this), |
| 39 view_android->GetWindowAndroid()->GetJavaObject().obj())); |
| 40 |
| 41 Java_InstrumentUnmaskBridge_show(env, java_object_.obj()); |
| 42 } |
| 43 |
| 44 void InstrumentUnmaskPromptViewAndroid::PromptDismissed(JNIEnv* env, |
| 45 jobject obj, |
| 46 jstring response) { |
| 47 response_ = base::android::ConvertJavaStringToUTF16(env, response); |
| 48 delete this; |
| 49 } |
| 50 |
| 51 // static |
| 52 bool InstrumentUnmaskPromptViewAndroid::Register(JNIEnv* env) { |
| 53 return RegisterNativesImpl(env); |
| 54 } |
| 55 |
| 56 } // namespace autofill |
OLD | NEW |