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.
5 package org.xwalk.core.internal.extension;
7 import android.content.Intent;
10 * Interface for bridging XWalkExtension functionalities to its backend implementation.
12 interface XWalkExtensionBridge {
14 * Post a message from native to a specific receiver on JavaScript side.
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
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.
26 public void postMessage(int instanceId, String message);
29 * Broadcast a message frome native side to all receivers on JavaScript side.
31 * @param message The message content to be posted.
33 public void broadcastMessage(String message);
36 * Handle the message from JavaScript side to native side.
38 * @param instanceId The extension instance id.
39 * @param message The message content received on native side.
41 public void handleMessage(int instanceId, String message);
44 * Handle the message from JavaScript side to native side in a synchronous way.
46 * Note that it will block the current thread until the method is finished and
47 * returns the result as string.
49 * @param instanceId The extension instance id.
50 * @param message The message content received on native side.
52 * @return The result to be posted to JavaScript side
54 public String handleSyncMessage(int instanceId, String message);
57 * Called when the extension is required to be resumed.
59 public void onResume();
62 * Called when the extension is required to be paused.
64 public void onPause();
67 * Called when the extension is required to be destroyed.
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.
73 public void onDestroy();
76 * Called when the extension exists if activity launched exists.
77 * TODO(hmin): Figure out if it is necessary and how to use it.
79 public void onActivityResult(int requestCode, int resultCode, Intent data);