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 | |
Ignacio Solla | 451e338 | 2014-11-10 10:35:54 +0000 | [diff] [blame] | 19 | import android.annotation.SystemApi; |
Mathew Inwood | 42afea2 | 2018-08-16 19:18:28 +0100 | [diff] [blame] | 20 | import android.annotation.UnsupportedAppUsage; |
Ignacio Solla | 451e338 | 2014-11-10 10:35:54 +0000 | [diff] [blame] | 21 | |
Jonathan Dixon | 2377b99 | 2012-04-12 18:17:08 +0100 | [diff] [blame] | 22 | /** |
| 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | public class JsResult { |
Grace Kloba | 2df9a91 | 2010-02-01 12:25:11 -0800 | [diff] [blame] | 28 | /** |
Jonathan Dixon | 2377b99 | 2012-04-12 18:17:08 +0100 | [diff] [blame] | 29 | * 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 Kloba | 2df9a91 | 2010-02-01 12:25:11 -0800 | [diff] [blame] | 32 | */ |
Ignacio Solla | 451e338 | 2014-11-10 10:35:54 +0000 | [diff] [blame] | 33 | @SystemApi |
Jonathan Dixon | 2377b99 | 2012-04-12 18:17:08 +0100 | [diff] [blame] | 34 | public interface ResultReceiver { |
| 35 | public void onJsResultComplete(JsResult result); |
| 36 | } |
Jonathan Dixon | 939e504 | 2012-04-12 21:21:07 +0100 | [diff] [blame] | 37 | // This is the caller of the prompt and is the object that is waiting. |
Mathew Inwood | 42afea2 | 2018-08-16 19:18:28 +0100 | [diff] [blame] | 38 | @UnsupportedAppUsage |
Jonathan Dixon | 939e504 | 2012-04-12 21:21:07 +0100 | [diff] [blame] | 39 | private final ResultReceiver mReceiver; |
| 40 | // This is a basic result of a confirm or prompt dialog. |
| 41 | private boolean mResult; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | |
| 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 Dixon | 2377b99 | 2012-04-12 18:17:08 +0100 | [diff] [blame] | 59 | /** |
| 60 | * @hide Only for use by WebViewProvider implementations |
| 61 | */ |
Ignacio Solla | 451e338 | 2014-11-10 10:35:54 +0000 | [diff] [blame] | 62 | @SystemApi |
Jonathan Dixon | 2377b99 | 2012-04-12 18:17:08 +0100 | [diff] [blame] | 63 | public JsResult(ResultReceiver receiver) { |
| 64 | mReceiver = receiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | } |
| 66 | |
Jonathan Dixon | 2377b99 | 2012-04-12 18:17:08 +0100 | [diff] [blame] | 67 | /** |
| 68 | * @hide Only for use by WebViewProvider implementations |
| 69 | */ |
Ignacio Solla | 451e338 | 2014-11-10 10:35:54 +0000 | [diff] [blame] | 70 | @SystemApi |
Jonathan Dixon | 2377b99 | 2012-04-12 18:17:08 +0100 | [diff] [blame] | 71 | public final boolean getResult() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | return mResult; |
| 73 | } |
| 74 | |
Jonathan Dixon | 2377b99 | 2012-04-12 18:17:08 +0100 | [diff] [blame] | 75 | /* Notify the caller that the JsResult has completed */ |
Jonathan Dixon | 939e504 | 2012-04-12 21:21:07 +0100 | [diff] [blame] | 76 | private final void wakeUp() { |
Jonathan Dixon | 2377b99 | 2012-04-12 18:17:08 +0100 | [diff] [blame] | 77 | mReceiver.onJsResultComplete(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | } |
| 79 | } |