cc6bb413e5a73369d25cb05dcdd95229bb1dde68
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / android / core_internal / src / org / xwalk / core / internal / XWalkJavascriptResultHandlerInternal.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.xwalk.core.internal;
6
7 import org.chromium.base.ThreadUtils;
8
9 public class XWalkJavascriptResultHandlerInternal implements XWalkJavascriptResultInternal {
10     private XWalkContentsClientBridge mBridge;
11     private final int mId;
12
13     XWalkJavascriptResultHandlerInternal(XWalkContentsClientBridge bridge, int id) {
14         mBridge = bridge;
15         mId = id;
16     }
17
18     @Override
19     public void confirm() {
20         confirmWithResult(null);
21     }
22
23     @Override
24     public void confirmWithResult(final String promptResult) {
25         ThreadUtils.runOnUiThread(new Runnable() {
26             @Override
27             public void run() {
28                 if (mBridge != null) {
29                     mBridge.confirmJsResult(mId, promptResult);
30                 }
31                 mBridge = null;
32             }
33         });
34     }
35
36     @Override
37     public void cancel() {
38         ThreadUtils.runOnUiThread(new Runnable() {
39             @Override
40             public void run() {
41                 if (mBridge != null) {
42                     mBridge.cancelJsResult(mId);
43                 }
44                 mBridge = null;
45             }
46         });
47     }
48 }