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.
5 package org.xwalk.runtime;
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;
14 * This class is to provide public APIs which are called by web application
15 * APKs. Since the runtime is shared as a library APK, web application APKs
16 * have to call them via class loader but not direct API calling.
18 * A web application APK should create its Activity and set this view as
21 // Implementation notes.
22 // Please be careful to change any public APIs for the backward compatibility
23 // is very important to us. Don't change any of them without permisson.
24 public class XWalkRuntimeView extends FrameLayout {
25 // The actual implementation to hide the internals to API users.
26 private XWalkRuntimeViewProvider mProvider;
29 * Contructs a XWalkRuntimeView with Activity and library Context. Called
30 * from runtime client.
32 * @param activity the activity from runtime client
33 * @param context a context when creating this package
34 * @param attrs the attributes of the XML tag that is inflating the view
36 public XWalkRuntimeView(Activity activity, Context libContext, AttributeSet attrs) {
37 super(libContext, attrs);
39 // MixedContext is needed for cross package because the application
40 // context is different.
41 init(new MixedContext(libContext, activity), activity);
45 * This is for inflating this view from XML. Called from test shell.
46 * @param context a context to construct View
47 * @param attrs the attributes of the XML tag that is inflating the view
49 public XWalkRuntimeView(Context context, AttributeSet attrs) {
50 super(context, attrs);
52 init(context, (Activity)context);
55 private void init(Context context, Activity activity) {
56 mProvider = XWalkRuntimeViewProviderFactory.getProvider(context, activity);
57 this.addView(mProvider.getView(),
58 new FrameLayout.LayoutParams(
59 FrameLayout.LayoutParams.MATCH_PARENT,
60 FrameLayout.LayoutParams.MATCH_PARENT));
64 * Get the version information of current runtime library.
66 * @return the string containing the version information.
68 public String getVersion() {
69 return mProvider.getVersion();
73 * Load a web application through the entry url. It may be
74 * a file from assets or a url from network.
76 * @param url the url of loaded html resource.
78 public void loadAppFromUrl(String url) {
79 mProvider.loadAppFromUrl(url);
83 * Load a web application through the url of the manifest file.
84 * The manifest file typically is placed in android assets. Now it is
85 * compliant to W3C SysApps spec.
87 * @param manifestUrl the url of the manifest file
89 public void loadAppFromManifest(String manifestUrl) {
90 mProvider.loadAppFromManifest(manifestUrl);
94 * Tell runtime that the application is on creating. This can make runtime
95 * be aware of application life cycle.
97 public void onCreate() {
102 * Tell runtime that the application is on resuming. This can make runtime
103 * be aware of application life cycle.
105 public void onResume() {
106 mProvider.onResume();
110 * Tell runtime that the application is on pausing. This can make runtime
111 * be aware of application life cycle.
113 public void onPause() {
118 * Tell runtime that the application is on destroying. This can make runtime
119 * be aware of application life cycle.
121 public void onDestroy() {
122 mProvider.onDestroy();
126 * Tell runtime that one activity exists so that it can know the result code
129 * @param requestCode the request code to identify where the result is from
130 * @param resultCode the result code of the activity
131 * @param data the data to contain the result data
133 public void onActivityResult(int requestCode, int resultCode, Intent data) {
134 mProvider.onActivityResult(requestCode, resultCode, data);
138 * Tell runtime that the activity receive a new Intent to start it. It may contains
139 * data that runtime want to deal with.
140 * @param intent the new coming Intent.
141 * @return boolean whether runtime consumed it.
143 public boolean onNewIntent(Intent intent) {
144 return mProvider.onNewIntent(intent);
148 * Enable remote debugging for the loaded web application. The caller
149 * can set the url of debugging url. Besides, the socket name for remote
150 * debugging has to be unique so typically the string can be appended
151 * with the package name of the application.
153 * @param frontEndUrl the url of debugging url. If it's empty, then a
154 * default url will be used.
155 * @param socketName the unique socket name for setting up socket for
156 * remote debugging. If it's empty, then a default
158 * @return the url of web socket for remote debugging
160 public void enableRemoteDebugging(String frontEndUrl, String socketName) {
161 // TODO(yongsheng): Figure out which parameters are needed once we
162 // have a conclusion.
163 mProvider.enableRemoteDebugging(frontEndUrl,socketName);
167 * Disable remote debugging so runtime can close related stuff for
170 public void disableRemoteDebugging() {
171 mProvider.disableRemoteDebugging();
174 // For instrumentation test.
175 public String getTitleForTest() {
176 return mProvider.getTitleForTest();
179 public void setCallbackForTest(Object callback) {
180 mProvider.setCallbackForTest(callback);
183 public void loadDataForTest(String data, String mimeType, boolean isBase64Encoded) {
184 mProvider.loadDataForTest(data, mimeType, isBase64Encoded);