blob: 07b686f7dab6a778a5de3bd22d64933f373af03d [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 {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025 // This is a basic result of a confirm or prompt dialog.
26 protected boolean mResult;
Grace Kloba2df9a912010-02-01 12:25:11 -080027 /**
Jonathan Dixon2377b992012-04-12 18:17:08 +010028 * Callback interface, implemented by the WebViewProvider implementation to receive
29 * notifications when the JavaScript result represented by a JsResult instance has
30 * @hide Only for use by WebViewProvider implementations
Grace Kloba2df9a912010-02-01 12:25:11 -080031 */
Jonathan Dixon2377b992012-04-12 18:17:08 +010032 public interface ResultReceiver {
33 public void onJsResultComplete(JsResult result);
34 }
35 /**
36 * This is the caller of the prompt and is the object that is waiting.
37 * @hide
38 */
39 protected final ResultReceiver mReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040
41 /**
42 * Handle the result if the user cancelled the dialog.
43 */
44 public final void cancel() {
45 mResult = false;
46 wakeUp();
47 }
48
49 /**
50 * Handle a confirmation response from the user.
51 */
52 public final void confirm() {
53 mResult = true;
54 wakeUp();
55 }
56
Jonathan Dixon2377b992012-04-12 18:17:08 +010057 /**
58 * @hide Only for use by WebViewProvider implementations
59 */
60 public JsResult(ResultReceiver receiver) {
61 mReceiver = receiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080062 }
63
Jonathan Dixon2377b992012-04-12 18:17:08 +010064 /**
65 * @hide Only for use by WebViewProvider implementations
66 */
67 public final boolean getResult() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068 return mResult;
69 }
70
Jonathan Dixon2377b992012-04-12 18:17:08 +010071 /* Notify the caller that the JsResult has completed */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072 protected final void wakeUp() {
Jonathan Dixon2377b992012-04-12 18:17:08 +010073 mReceiver.onJsResultComplete(this);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080074 }
75}