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 starting. This can make runtime
103 * be aware of application life cycle.
105 public void onStart() {
110 * Tell runtime that the application is on resuming. This can make runtime
111 * be aware of application life cycle.
113 public void onResume() {
114 mProvider.onResume();
118 * Tell runtime that the application is on pausing. This can make runtime
119 * be aware of application life cycle.
121 public void onPause() {
126 * Tell runtime that the application is on stoping. This can make runtime
127 * be aware of application life cycle.
129 public void onStop() {
134 * Tell runtime that the application is on destroying. This can make runtime
135 * be aware of application life cycle.
137 public void onDestroy() {
138 mProvider.onDestroy();
142 * Tell runtime that one activity exists so that it can know the result code
145 * @param requestCode the request code to identify where the result is from
146 * @param resultCode the result code of the activity
147 * @param data the data to contain the result data
149 public void onActivityResult(int requestCode, int resultCode, Intent data) {
150 mProvider.onActivityResult(requestCode, resultCode, data);
154 * Tell runtime that the activity receive a new Intent to start it. It may contains
155 * data that runtime want to deal with.
156 * @param intent the new coming Intent.
157 * @return boolean whether runtime consumed it.
159 public boolean onNewIntent(Intent intent) {
160 return mProvider.onNewIntent(intent);
164 * Enable remote debugging for the loaded web application. The caller
165 * can set the url of debugging url. Besides, the socket name for remote
166 * debugging has to be unique so typically the string can be appended
167 * with the package name of the application.
169 * @param frontEndUrl the url of debugging url. If it's empty, then a
170 * default url will be used.
171 * @param socketName the unique socket name for setting up socket for
172 * remote debugging. If it's empty, then a default
174 * @return the url of web socket for remote debugging
176 public void enableRemoteDebugging(String frontEndUrl, String socketName) {
177 // TODO(yongsheng): Figure out which parameters are needed once we
178 // have a conclusion.
179 mProvider.enableRemoteDebugging(frontEndUrl,socketName);
183 * Disable remote debugging so runtime can close related stuff for
186 public void disableRemoteDebugging() {
187 mProvider.disableRemoteDebugging();
190 // For instrumentation test.
191 public String getTitleForTest() {
192 return mProvider.getTitleForTest();
195 public void setCallbackForTest(Object callback) {
196 mProvider.setCallbackForTest(callback);
199 public void loadDataForTest(String data, String mimeType, boolean isBase64Encoded) {
200 mProvider.loadDataForTest(data, mimeType, isBase64Encoded);