1/*
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
19/**
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 */
24public class JsResult {
25    /**
26     * 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
29     */
30    public interface ResultReceiver {
31        public void onJsResultComplete(JsResult result);
32    }
33    // 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;
37
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
54    /**
55     * @hide Only for use by WebViewProvider implementations
56     */
57    public JsResult(ResultReceiver receiver) {
58        mReceiver = receiver;
59    }
60
61    /**
62     * @hide Only for use by WebViewProvider implementations
63     */
64    public final boolean getResult() {
65        return mResult;
66    }
67
68    /* Notify the caller that the JsResult has completed */
69    private final void wakeUp() {
70        mReceiver.onJsResultComplete(this);
71    }
72}
73