- add sources.
[platform/framework/web/crosswalk.git] / src / android_webview / java / src / org / chromium / android_webview / JsResultHandler.java
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.android_webview;
6
7 import org.chromium.base.ThreadUtils;
8
9 class JsResultHandler implements JsResultReceiver, JsPromptResultReceiver {
10     private AwContentsClientBridge mBridge;
11     private final int mId;
12
13     JsResultHandler(AwContentsClientBridge bridge, int id) {
14         mBridge = bridge;
15         mId = id;
16     }
17
18     @Override
19     public void confirm() {
20         confirm(null);
21     }
22
23     @Override
24     public void confirm(final String promptResult) {
25         ThreadUtils.runOnUiThread(new Runnable() {
26             @Override
27             public void run() {
28                 if (mBridge != null)
29                     mBridge.confirmJsResult(mId, promptResult);
30                 mBridge = null;
31             }
32         });
33     }
34
35     @Override
36     public void cancel() {
37         ThreadUtils.runOnUiThread(new Runnable() {
38             @Override
39             public void run() {
40                 if (mBridge != null)
41                     mBridge.cancelJsResult(mId);
42                 mBridge = null;
43             }
44         });
45     }
46 }