Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / android / java / src / org / xwalk / runtime / extension / XWalkExtensionContextWrapper.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.runtime.extension;
6
7 import android.app.Activity;
8 import android.content.Context;
9
10 /**
11  * This is a public class to provide context for extensions.
12  * It'll be shared by all external extensions.
13  */
14 public class XWalkExtensionContextWrapper implements XWalkExtensionContext {
15     private XWalkExtensionContext mOriginContext;
16
17     public XWalkExtensionContextWrapper(XWalkExtensionContext context) {
18         mOriginContext = context;
19     }
20
21     public void registerExtension(XWalkExtension extension) {
22         mOriginContext.registerExtension(extension);
23     }
24
25     public void unregisterExtension(String name) {
26         mOriginContext.unregisterExtension(name);
27     }
28
29     public void postMessage(XWalkExtension extension, int instanceID, String message) {
30         mOriginContext.postMessage(extension, instanceID, message);
31     }
32
33     public void broadcastMessage(XWalkExtension extension, String message) {
34         mOriginContext.broadcastMessage(extension, message);
35     }
36
37     public Context getContext() {
38         // This is very tricky because for external extensions, we should
39         // use Activity which contains the context for runtime client side.
40         // mOriginContext.getContext() returns the context of library package,
41         // e.g., the package context of runtime side.
42         return mOriginContext.getActivity();
43     }
44
45     public Activity getActivity() {
46         return mOriginContext.getActivity();
47     }
48 }