The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
| 17 | package android.webkit; |
| 18 | |
Jonathan Dixon | 2377b99 | 2012-04-12 18:17:08 +0100 | [diff] [blame^] | 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 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | public class JsResult { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | // This is a basic result of a confirm or prompt dialog. |
| 26 | protected boolean mResult; |
Grace Kloba | 2df9a91 | 2010-02-01 12:25:11 -0800 | [diff] [blame] | 27 | /** |
Jonathan Dixon | 2377b99 | 2012-04-12 18:17:08 +0100 | [diff] [blame^] | 28 | * 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 Kloba | 2df9a91 | 2010-02-01 12:25:11 -0800 | [diff] [blame] | 31 | */ |
Jonathan Dixon | 2377b99 | 2012-04-12 18:17:08 +0100 | [diff] [blame^] | 32 | 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | |
| 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 Dixon | 2377b99 | 2012-04-12 18:17:08 +0100 | [diff] [blame^] | 57 | /** |
| 58 | * @hide Only for use by WebViewProvider implementations |
| 59 | */ |
| 60 | public JsResult(ResultReceiver receiver) { |
| 61 | mReceiver = receiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | } |
| 63 | |
Jonathan Dixon | 2377b99 | 2012-04-12 18:17:08 +0100 | [diff] [blame^] | 64 | /** |
| 65 | * @hide Only for use by WebViewProvider implementations |
| 66 | */ |
| 67 | public final boolean getResult() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | return mResult; |
| 69 | } |
| 70 | |
Jonathan Dixon | 2377b99 | 2012-04-12 18:17:08 +0100 | [diff] [blame^] | 71 | /* Notify the caller that the JsResult has completed */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | protected final void wakeUp() { |
Jonathan Dixon | 2377b99 | 2012-04-12 18:17:08 +0100 | [diff] [blame^] | 73 | mReceiver.onJsResultComplete(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | } |
| 75 | } |