blob: 5bf6aab3225dd9e150f1a18c4f26dadbe92b84ee [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.webkit;
18
Ignacio Solla451e3382014-11-10 10:35:54 +000019import android.annotation.SystemApi;
Mathew Inwood42afea22018-08-16 19:18:28 +010020import android.annotation.UnsupportedAppUsage;
Ignacio Solla451e3382014-11-10 10:35:54 +000021
Jonathan Dixon2377b992012-04-12 18:17:08 +010022/**
23 * An instance of this class is passed as a parameter in various {@link WebChromeClient} action
24 * notifications. The object is used as a handle onto the underlying JavaScript-originated request,
25 * and provides a means for the client to indicate whether this action should proceed.
26 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027public class JsResult {
Grace Kloba2df9a912010-02-01 12:25:11 -080028 /**
Jonathan Dixon2377b992012-04-12 18:17:08 +010029 * Callback interface, implemented by the WebViewProvider implementation to receive
30 * notifications when the JavaScript result represented by a JsResult instance has
31 * @hide Only for use by WebViewProvider implementations
Grace Kloba2df9a912010-02-01 12:25:11 -080032 */
Ignacio Solla451e3382014-11-10 10:35:54 +000033 @SystemApi
Jonathan Dixon2377b992012-04-12 18:17:08 +010034 public interface ResultReceiver {
35 public void onJsResultComplete(JsResult result);
36 }
Jonathan Dixon939e5042012-04-12 21:21:07 +010037 // This is the caller of the prompt and is the object that is waiting.
Mathew Inwood42afea22018-08-16 19:18:28 +010038 @UnsupportedAppUsage
Jonathan Dixon939e5042012-04-12 21:21:07 +010039 private final ResultReceiver mReceiver;
40 // This is a basic result of a confirm or prompt dialog.
41 private boolean mResult;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042
43 /**
44 * Handle the result if the user cancelled the dialog.
45 */
46 public final void cancel() {
47 mResult = false;
48 wakeUp();
49 }
50
51 /**
52 * Handle a confirmation response from the user.
53 */
54 public final void confirm() {
55 mResult = true;
56 wakeUp();
57 }
58
Jonathan Dixon2377b992012-04-12 18:17:08 +010059 /**
60 * @hide Only for use by WebViewProvider implementations
61 */
Ignacio Solla451e3382014-11-10 10:35:54 +000062 @SystemApi
Jonathan Dixon2377b992012-04-12 18:17:08 +010063 public JsResult(ResultReceiver receiver) {
64 mReceiver = receiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065 }
66
Jonathan Dixon2377b992012-04-12 18:17:08 +010067 /**
68 * @hide Only for use by WebViewProvider implementations
69 */
Ignacio Solla451e3382014-11-10 10:35:54 +000070 @SystemApi
Jonathan Dixon2377b992012-04-12 18:17:08 +010071 public final boolean getResult() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072 return mResult;
73 }
74
Jonathan Dixon2377b992012-04-12 18:17:08 +010075 /* Notify the caller that the JsResult has completed */
Jonathan Dixon939e5042012-04-12 21:21:07 +010076 private final void wakeUp() {
Jonathan Dixon2377b992012-04-12 18:17:08 +010077 mReceiver.onJsResultComplete(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078 }
79}