blob: e4e6851d1a415e3a0d9a10a6feaf2b6e50e64d1c [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
Jonathan Dixon2377b992012-04-12 18:17:08 +010019/**
20 * An instance of this class is passed as a parameter in various {@link WebChromeClient} action
21 * notifications. The object is used as a handle onto the underlying JavaScript-originated request,
22 * and provides a means for the client to indicate whether this action should proceed.
23 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024public class JsResult {
Grace Kloba2df9a912010-02-01 12:25:11 -080025 /**
Jonathan Dixon2377b992012-04-12 18:17:08 +010026 * Callback interface, implemented by the WebViewProvider implementation to receive
27 * notifications when the JavaScript result represented by a JsResult instance has
28 * @hide Only for use by WebViewProvider implementations
Grace Kloba2df9a912010-02-01 12:25:11 -080029 */
Jonathan Dixon2377b992012-04-12 18:17:08 +010030 public interface ResultReceiver {
31 public void onJsResultComplete(JsResult result);
32 }
Jonathan Dixon939e5042012-04-12 21:21:07 +010033 // This is the caller of the prompt and is the object that is waiting.
34 private final ResultReceiver mReceiver;
35 // This is a basic result of a confirm or prompt dialog.
36 private boolean mResult;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037
38 /**
39 * Handle the result if the user cancelled the dialog.
40 */
41 public final void cancel() {
42 mResult = false;
43 wakeUp();
44 }
45
46 /**
47 * Handle a confirmation response from the user.
48 */
49 public final void confirm() {
50 mResult = true;
51 wakeUp();
52 }
53
Jonathan Dixon2377b992012-04-12 18:17:08 +010054 /**
55 * @hide Only for use by WebViewProvider implementations
56 */
57 public JsResult(ResultReceiver receiver) {
58 mReceiver = receiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059 }
60
Jonathan Dixon2377b992012-04-12 18:17:08 +010061 /**
62 * @hide Only for use by WebViewProvider implementations
63 */
64 public final boolean getResult() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065 return mResult;
66 }
67
Jonathan Dixon2377b992012-04-12 18:17:08 +010068 /* Notify the caller that the JsResult has completed */
Jonathan Dixon939e5042012-04-12 21:21:07 +010069 private final void wakeUp() {
Jonathan Dixon2377b992012-04-12 18:17:08 +010070 mReceiver.onJsResultComplete(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071 }
72}