Upstream version 8.36.156.0
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / android / core_internal / src / org / xwalk / core / internal / extension / XWalkExtensionBridge.java
1 // Copyright (c) 2013 Intel Corporation. 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.extension;
6
7 import android.content.Intent;
8
9 /**
10  * Interface for bridging XWalkExtension functionalities to its backend implementation.
11  */
12 interface XWalkExtensionBridge {
13     /**
14      * Post a message from native to a specific receiver on JavaScript side.
15      *
16      * A receiver on JavaScript side is considered as an extension instance created
17      * for a JavaScript context. If a web page has multiple JavaScript contexts,
18      * e.g. iframes, multiple extension instances will be created for each JavaScript
19      * context, and an integer is assigned to each extension instance as the unique
20      * identifier.
21      *
22      * @param instanceId The internal unique id on native side to identify the message
23      *                   receiver. Always got from handleMessage interface.
24      * @param message The message content to be posted.
25      */
26     public void postMessage(int instanceId, String message);
27
28     /**
29      * Broadcast a message frome native side to all receivers on JavaScript side.
30      *
31      * @param message The message content to be posted.
32      */
33     public void broadcastMessage(String message);
34
35     /**
36      * Handle the message from JavaScript side to native side.
37      *
38      * @param instanceId The extension instance id.
39      * @param message The message content received on native side.
40      */
41     public void handleMessage(int instanceId, String message);
42
43     /**
44      * Handle the message from JavaScript side to native side in a synchronous way.
45      *
46      * Note that it will block the current thread until the method is finished and
47      * returns the result as string.
48      *
49      * @param instanceId The extension instance id.
50      * @param message The message content received on native side.
51      *
52      * @return The result to be posted to JavaScript side
53      */
54     public String handleSyncMessage(int instanceId, String message);
55
56     /**
57      * Called when the extension is required to be resumed.
58      */
59     public void onResume();
60
61     /**
62      * Called when the extension is required to be paused.
63      */
64     public void onPause();
65
66     /**
67      * Called when the extension is required to be destroyed.
68      *
69      * It gives a chance to cleanup the resource allocated for the extension.
70      * Any attempt to call a method on XWalkExtension after onDestroy is called
71      * will cause undefined program behavior.
72      */
73     public void onDestroy();
74
75     /**
76      * Called when the extension exists if activity launched exists.
77      * TODO(hmin): Figure out if it is necessary and how to use it.
78      */
79     public void onActivityResult(int requestCode, int resultCode, Intent data);
80 }