720398cdcbf566f82faf05422205dac65cd30f3b
[platform/framework/web/crosswalk.git] / src / xwalk / app / android / runtime_client / src / org / xwalk / app / runtime / extension / XWalkExtensionContextClient.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.app.runtime.extension;
6
7 import android.app.Activity;
8 import android.content.Context;
9 import android.content.Intent;
10 import android.util.AttributeSet;
11 import android.widget.FrameLayout;
12
13 import java.lang.reflect.Method;
14 import java.util.StringTokenizer;
15 import java.util.regex.Matcher;
16 import java.util.regex.Pattern;
17
18 import org.xwalk.app.runtime.CrossPackageWrapper;
19
20 /**
21  * This is the extension context used by external extensions. It'll be created
22  * by runtime side.
23  */
24 public final class XWalkExtensionContextClient extends CrossPackageWrapper {
25     private final static String EXTENSION_CLASS_NAME =
26             "org.xwalk.core.internal.extension.XWalkExtensionContextWrapper";
27     private Object mInstance;
28     private Method mGetContext;
29     private Method mGetActivity;
30
31     /**
32      * It's called by runtime side.
33      */
34     public XWalkExtensionContextClient(Activity activity, Object instance) {
35         super(activity, EXTENSION_CLASS_NAME, null, String.class, String.class,
36                 instance.getClass());
37
38         mInstance = instance;
39         mGetActivity = lookupMethod("getActivity");
40         mGetContext = lookupMethod("getContext");
41     }
42
43     /**
44      * Get the current Android Activity. Used by XWalkExtensionClient.
45      * @return the current Android Activity.
46      */
47     public Activity getActivity() {
48         return (Activity) invokeMethod(mGetActivity, mInstance);
49     }
50
51     /**
52      * Get the current Android Context. Used by XWalkExtensionClient.
53      * @return the current Android Context.
54      */
55     public Context getContext() {
56         return (Context) invokeMethod(mGetContext, mInstance);
57     }
58
59     /**
60      * Get the object of the runtime side.
61      * @return the object of the runtime side.
62      */
63     public Object getInstance() {
64         return mInstance;
65     }
66 }