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.
5 package org.xwalk.runtime;
7 import android.app.Activity;
8 import android.content.Context;
9 import android.content.Intent;
10 import android.view.KeyEvent;
11 import android.view.View;
12 import android.widget.FrameLayout;
14 import org.chromium.content.browser.LoadUrlParams;
15 import org.xwalk.core.XWalkView;
16 import org.xwalk.core.XWalkPreferences;
19 * The implementation class for runtime core. It calls the methods provided
20 * by runtime core and customizes the behaviors for runtime.
22 class XWalkCoreProviderImpl implements XWalkRuntimeViewProvider {
23 private Context mContext;
24 private Activity mActivity;
25 private XWalkView mXWalkView;
27 public XWalkCoreProviderImpl(Context context, Activity activity) {
30 init(context, activity);
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 XWalkView(context, activity);
40 public void loadAppFromUrl(String url) {
41 mXWalkView.load(url, null);
45 public void loadAppFromManifest(String manifestUrl) {
46 XWalkManifestReader manifestReader = new XWalkManifestReader(mActivity);
47 String manifest = manifestReader.read(manifestUrl);
48 int position = manifestUrl.lastIndexOf("/");
50 throw new RuntimeException("The URL of manifest file is invalid.");
53 String path = manifestUrl.substring(0, position + 1);
54 mXWalkView.loadAppFromManifest(path, manifest);
58 public void onCreate() {
62 public void onResume() {
67 public void onPause() {
72 public void onDestroy() {
73 mXWalkView.onDestroy();
77 public void onActivityResult(int requestCode, int resultCode, Intent data) {
78 mXWalkView.onActivityResult(requestCode, resultCode, data);
82 public boolean onNewIntent(Intent intent) {
83 return mXWalkView.onNewIntent(intent);
87 public void enableRemoteDebugging(String frontEndUrl, String socketName) {
88 // TODO(yongsheng): Enable two parameters once they're supported in XWalkView.
89 XWalkPreferences.setValue(XWalkPreferences.REMOTE_DEBUGGING, true);
93 public void disableRemoteDebugging() {
94 XWalkPreferences.setValue(XWalkPreferences.REMOTE_DEBUGGING, false);
98 public String getVersion() {
99 return mXWalkView.getXWalkVersion();
103 public View getView() {
107 // For instrumentation test.
109 public String getTitleForTest() {
110 return mXWalkView.getTitle();
114 public void setCallbackForTest(Object callback) {
115 XWalkRuntimeTestHelper testHelper = new XWalkRuntimeTestHelper(mContext, mXWalkView);
116 testHelper.setCallbackForTest(callback);
117 mXWalkView.setXWalkClient(testHelper.getClient());
118 mXWalkView.setXWalkWebChromeClient(testHelper.getWebChromeClient());
119 mXWalkView.setResourceClient(testHelper.getResourceClient());
123 public void loadDataForTest(String data, String mimeType, boolean isBase64Encoded) {
124 mXWalkView.getXWalkViewContentForTest().getContentViewCoreForTest(
125 ).loadUrl(LoadUrlParams.createLoadDataParams(
126 data, mimeType, isBase64Encoded));
130 public boolean onKeyUp(int keyCode, KeyEvent event) {
131 return mXWalkView.onKeyUp(keyCode, event);