Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / xwalk / runtime / android / runtime / src / org / xwalk / runtime / XWalkCoreProviderImpl.java
1 // Copyright (c) 2013-2014 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;
6
7 import android.app.Activity;
8 import android.content.Context;
9 import android.content.Intent;
10 import android.view.View;
11 import android.widget.FrameLayout;
12
13 import org.xwalk.core.XWalkView;
14 import org.xwalk.core.XWalkPreferences;
15
16 /**
17  * The implementation class for runtime core. It calls the methods provided
18  * by runtime core and customizes the behaviors for runtime.
19  */
20 class XWalkCoreProviderImpl implements XWalkRuntimeViewProvider {
21     private Context mContext;
22     private Activity mActivity;
23     private XWalkView mXWalkView;
24
25     public XWalkCoreProviderImpl(Context context, Activity activity) {
26         mContext = context;
27         mActivity = activity;
28         init(context, activity);
29     }
30
31     private void init(Context context, Activity activity) {
32         // TODO(yongsheng): do customizations for XWalkView. There will
33         // be many callback classes which are needed to be implemented.
34         mXWalkView = new XWalkView(context, activity);
35     }
36
37     @Override
38     public void loadAppFromUrl(String url) {
39         mXWalkView.load(url, null);
40     }
41
42     @Override
43     public void loadAppFromManifest(String manifestUrl) {
44         mXWalkView.loadAppFromManifest(manifestUrl, null);
45     }
46
47     @Override
48     public void onCreate() {
49     }
50
51     @Override
52     public void onStart() {
53     }
54
55     @Override
56     public void onResume() {
57     }
58
59     @Override
60     public void onPause() {
61     }
62
63     @Override
64     public void onStop() {
65     }
66
67     @Override
68     public void onDestroy() {
69     }
70
71     @Override
72     public void onActivityResult(int requestCode, int resultCode, Intent data) {
73         mXWalkView.onActivityResult(requestCode, resultCode, data);
74     }
75
76     @Override
77     public boolean onNewIntent(Intent intent) {
78         return mXWalkView.onNewIntent(intent);
79     }
80
81     @Override
82     public void enableRemoteDebugging(String frontEndUrl, String socketName) {
83         // TODO(yongsheng): Enable two parameters once they're supported in XWalkView.
84         XWalkPreferences.setValue(XWalkPreferences.REMOTE_DEBUGGING, true);
85     }
86
87     @Override
88     public void disableRemoteDebugging() {
89         XWalkPreferences.setValue(XWalkPreferences.REMOTE_DEBUGGING, false);
90     }
91
92     @Override
93     public String getVersion() {
94         return mXWalkView.getXWalkVersion();
95     }
96
97     @Override
98     public View getView() {
99         return mXWalkView;
100     }
101
102     // For instrumentation test.
103     @Override
104     public String getTitleForTest() {
105         return mXWalkView.getTitle();
106     }
107
108     @Override
109     public void setCallbackForTest(Object callback) {
110         XWalkRuntimeTestHelper testHelper = new XWalkRuntimeTestHelper(mContext, mXWalkView);
111         testHelper.setCallbackForTest(callback);
112         mXWalkView.setUIClient(testHelper.getUIClient());
113         mXWalkView.setResourceClient(testHelper.getResourceClient());
114     }
115
116     @Override
117     public void loadDataForTest(String data, String mimeType, boolean isBase64Encoded) {
118         mXWalkView.load("", data);
119     }
120 }