Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / xwalk / app / android / runtime_client / src / org / xwalk / app / 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.app.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.SharedXWalkExceptionHandler;
14 import org.xwalk.core.SharedXWalkView;
15 import org.xwalk.core.XWalkView;
16 import org.xwalk.core.XWalkPreferences;
17
18 /**
19  * The implementation class for runtime core. It calls the methods provided
20  * by runtime core and customizes the behaviors for runtime.
21  */
22 class XWalkCoreProviderImpl implements XWalkRuntimeViewProvider {
23     private Context mContext;
24     private Activity mActivity;
25     private XWalkView mXWalkView;
26
27     public XWalkCoreProviderImpl(Context context, Activity activity) {
28         mContext = context;
29         mActivity = activity;
30         init(context, activity);
31     }
32
33     private void init(Context context, Activity activity) {
34         // TODO(yongsheng): do customizations for XWalkView. There will
35         // be many callback classes which are needed to be implemented.
36         mXWalkView = new SharedXWalkView(context, activity, new SharedXWalkExceptionHandler() {
37             @Override
38             public void onSharedLibraryNotFound() {
39                 throw new RuntimeException(new XWalkRuntimeLibraryException(
40                         XWalkRuntimeLibraryException.XWALK_RUNTIME_LIBRARY_NOT_INSTALLED));
41             }
42         });
43     }
44
45     @Override
46     public void loadAppFromUrl(String url) {
47         mXWalkView.load(url, null);
48     }
49
50     @Override
51     public void loadAppFromManifest(String manifestUrl) {
52         mXWalkView.loadAppFromManifest(manifestUrl, null);
53     }
54
55     @Override
56     public void onCreate() {
57     }
58
59     @Override
60     public void onResume() {
61     }
62
63     @Override
64     public void onPause() {
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 }