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 19 import android.annotation.SystemApi; 20 21 /** 22 * An instance of this class is passed as a parameter in various {@link WebChromeClient} action 23 * notifications. The object is used as a handle onto the underlying JavaScript-originated request, 24 * and provides a means for the client to indicate whether this action should proceed. 25 */ 26 public class JsResult { 27 /** 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 31 */ 32 @SystemApi 33 public interface ResultReceiver { 34 public void onJsResultComplete(JsResult result); 35 } 36 // This is the caller of the prompt and is the object that is waiting. 37 private final ResultReceiver mReceiver; 38 // This is a basic result of a confirm or prompt dialog. 39 private boolean mResult; 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 57 /** 58 * @hide Only for use by WebViewProvider implementations 59 */ 60 @SystemApi 61 public JsResult(ResultReceiver receiver) { 62 mReceiver = receiver; 63 } 64 65 /** 66 * @hide Only for use by WebViewProvider implementations 67 */ 68 @SystemApi 69 public final boolean getResult() { 70 return mResult; 71 } 72 73 /* Notify the caller that the JsResult has completed */ 74 private final void wakeUp() { 75 mReceiver.onJsResultComplete(this); 76 } 77 } 78