import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.ref.WeakReference;
+import java.net.MalformedURLException;
+import java.net.URL;
import org.chromium.base.ActivityState;
import org.chromium.base.ApplicationStatus;
import org.chromium.base.ApplicationStatus.ActivityStateListener;
import org.chromium.base.CommandLine;
-
-import org.xwalk.core.internal.extension.XWalkExtensionManager;
-import org.xwalk.core.internal.extension.XWalkPathHelper;
+import org.xwalk.core.internal.extension.BuiltinXWalkExtensions;
/**
* <p>XWalkViewInternal represents an Android view for web apps/pages. Thus most of attributes
* }
* </pre>
*/
+@XWalkAPI(extendClass = FrameLayout.class, createExternally = true)
public class XWalkViewInternal extends android.widget.FrameLayout {
private class XWalkActivityStateListener implements ActivityStateListener {
private XWalkContent mContent;
private Activity mActivity;
private Context mContext;
- private XWalkExtensionManager mExtensionManager;
private boolean mIsHidden;
private XWalkActivityStateListener mActivityStateListener;
* Normal reload mode as default.
* @since 1.0
*/
+ @XWalkAPI
public static final int RELOAD_NORMAL = 0;
/**
* Reload mode with bypassing the cache.
* @since 1.0
*/
+ @XWalkAPI
public static final int RELOAD_IGNORE_CACHE = 1;
/**
* @param attrs an AttributeSet passed to our parent.
* @since 1.0
*/
+ @XWalkAPI(preWrapperLines = {
+ " super(${param1}, ${param2});"},
+ postWrapperLines = {
+ " if (bridge == null) return;",
+ " addView((FrameLayout)bridge, new FrameLayout.LayoutParams(",
+ " FrameLayout.LayoutParams.MATCH_PARENT,",
+ " FrameLayout.LayoutParams.MATCH_PARENT));"})
public XWalkViewInternal(Context context, AttributeSet attrs) {
- super(context, attrs);
+ super(convertContext(context), attrs);
checkThreadSafety();
- mContext = context;
- init(context, attrs);
+ mActivity = (Activity) context;
+ mContext = getContext();
+ init(mContext, attrs);
}
/**
* @param activity the activity for this XWalkViewInternal.
* @since 1.0
*/
+ @XWalkAPI(preWrapperLines = {
+ " super(${param1}, null);"},
+ postWrapperLines = {
+ " if (bridge == null) return;",
+ " addView((FrameLayout)bridge, new FrameLayout.LayoutParams(",
+ " FrameLayout.LayoutParams.MATCH_PARENT,",
+ " FrameLayout.LayoutParams.MATCH_PARENT));"})
public XWalkViewInternal(Context context, Activity activity) {
- super(context, null);
- checkThreadSafety();
+ super(convertContext(context), null);
+ checkThreadSafety();
// Make sure mActivity is initialized before calling 'init' method.
mActivity = activity;
- mContext = context;
- init(context, null);
+ mContext = getContext();
+ init(mContext, null);
+ }
+
+ private static Context convertContext(Context context) {
+ Context ret = context;
+ Context bridgeContext = ReflectionHelper.getBridgeContext();
+ if (bridgeContext == null || context == null ||
+ bridgeContext.getPackageName().equals(context.getPackageName())) {
+ // Not acrossing package
+ ret = context;
+ } else {
+ ret = new MixedContext(bridgeContext, context);
+ }
+ return ret;
}
/**
return mContext;
}
+ public void completeWindowCreation(XWalkViewInternal newXWalkView) {
+ mContent.supplyContentsForPopup(newXWalkView == null ? null : newXWalkView.mContent);
+ }
+
private void init(Context context, AttributeSet attrs) {
// Initialize chromium resources. Assign them the correct ids in
// xwalk core.
setNotificationService(new XWalkNotificationServiceImpl(context, this));
if (!CommandLine.getInstance().hasSwitch("disable-xwalk-extensions")) {
- // Enable xwalk extension mechanism and start load extensions here.
- // Note that it has to be after above initialization.
- mExtensionManager = new XWalkExtensionManager(context, getActivity());
- mExtensionManager.loadExtensions();
+ BuiltinXWalkExtensions.load(context, getActivity());
+ } else {
+ XWalkPreferencesInternal.setValue(XWalkPreferencesInternal.ENABLE_EXTENSIONS, false);
}
XWalkPathHelper.initialize();
* @param content the content for the web page/app. Could be empty.
* @since 1.0
*/
+ @XWalkAPI
public void load(String url, String content) {
if (mContent == null) return;
checkThreadSafety();
* @param content the content for manifest.json.
* @since 1.0
*/
+ @XWalkAPI
public void loadAppFromManifest(String url, String content) {
if (mContent == null) return;
checkThreadSafety();
* @param mode the reload mode.
* @since 1.0
*/
+ @XWalkAPI
public void reload(int mode) {
if (mContent == null) return;
checkThreadSafety();
* Stop current loading progress.
* @since 1.0
*/
+ @XWalkAPI
public void stopLoading() {
if (mContent == null) return;
checkThreadSafety();
* @return the url for current web page/app.
* @since 1.0
*/
+ @XWalkAPI
public String getUrl() {
if (mContent == null) return null;
checkThreadSafety();
* @return the title for current web page/app.
* @since 1.0
*/
+ @XWalkAPI
public String getTitle() {
if (mContent == null) return null;
checkThreadSafety();
* @return the original url.
* @since 1.0
*/
+ @XWalkAPI
public String getOriginalUrl() {
if (mContent == null) return null;
checkThreadSafety();
* @return the navigation history.
* @since 1.0
*/
+ @XWalkAPI
public XWalkNavigationHistoryInternal getNavigationHistory() {
if (mContent == null) return null;
checkThreadSafety();
* @param name the name injected in JavaScript.
* @since 1.0
*/
+ @XWalkAPI
public void addJavascriptInterface(Object object, String name) {
if (mContent == null) return;
checkThreadSafety();
* @param callback the callback to handle the evaluated result.
* @since 1.0
*/
+ @XWalkAPI
public void evaluateJavascript(String script, ValueCallback<String> callback) {
if (mContent == null) return;
checkThreadSafety();
* @param includeDiskFiles indicate whether to clear disk files for cache.
* @since 1.0
*/
+ @XWalkAPI
public void clearCache(boolean includeDiskFiles) {
if (mContent == null) return;
checkThreadSafety();
* @return true if any HTML element is occupying the whole screen.
* @since 1.0
*/
+ @XWalkAPI
public boolean hasEnteredFullscreen() {
if (mContent == null) return false;
checkThreadSafety();
* in fullscreen.
* @since 1.0
*/
+ @XWalkAPI
public void leaveFullscreen() {
if (mContent == null) return;
checkThreadSafety();
*
* @since 1.0
*/
+ @XWalkAPI
public void pauseTimers() {
if (mContent == null) return;
checkThreadSafety();
*
* @since 1.0
*/
+ @XWalkAPI
public void resumeTimers() {
if (mContent == null) return;
checkThreadSafety();
* called to pause above things.
* @since 1.0
*/
+ @XWalkAPI
public void onHide() {
if (mContent == null || mIsHidden) return;
- if (null != mExtensionManager) mExtensionManager.onPause();
mContent.onPause();
mIsHidden = true;
}
* called to resume above things.
* @since 1.0
*/
+ @XWalkAPI
public void onShow() {
if (mContent == null || !mIsHidden ) return;
- if (null != mExtensionManager) mExtensionManager.onResume();
mContent.onResume();
mIsHidden = false;
}
* called to release resources.
* @since 1.0
*/
+ @XWalkAPI
public void onDestroy() {
destroy();
}
* @param data passed from android.app.Activity.onActivityResult().
* @since 1.0
*/
+ @XWalkAPI
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (mContent == null) return;
- if (null != mExtensionManager)
- mExtensionManager.onActivityResult(requestCode, resultCode, data);
mContent.onActivityResult(requestCode, resultCode, data);
}
* @param intent passed from android.app.Activity.onNewIntent().
* @since 1.0
*/
+ @XWalkAPI
public boolean onNewIntent(Intent intent) {
if (mContent == null) return false;
return mContent.onNewIntent(intent);
* @param outState the saved state for restoring.
* @since 1.0
*/
+ @XWalkAPI
public boolean saveState(Bundle outState) {
if (mContent == null) return false;
mContent.saveState(outState);
* @return true if it can restore the state.
* @since 1.0
*/
+ @XWalkAPI
public boolean restoreState(Bundle inState) {
if (mContent == null) return false;
if (mContent.restoreState(inState) != null) return true;
* @since 1.0
*/
// TODO(yongsheng): make it static?
+ @XWalkAPI
public String getAPIVersion() {
- return "2.1";
+ return "3.0";
}
/**
* @since 1.0
*/
// TODO(yongsheng): make it static?
+ @XWalkAPI
public String getXWalkVersion() {
if (mContent == null) return null;
return mContent.getXWalkVersion();
* @param client the XWalkUIClientInternal defined by callers.
* @since 1.0
*/
+ @XWalkAPI
public void setUIClient(XWalkUIClientInternal client) {
if (mContent == null) return;
checkThreadSafety();
* @param client the XWalkResourceClientInternal defined by callers.
* @since 1.0
*/
+ @XWalkAPI
public void setResourceClient(XWalkResourceClientInternal client) {
if (mContent == null) return;
checkThreadSafety();
*
* @hide
*/
+ @XWalkAPI
public void setNetworkAvailable(boolean networkUp) {
if (mContent == null) return;
checkThreadSafety();
}
/**
- * Enables remote debugging and returns the URL at which the dev tools server is listening
- * for commands. The allowedUid argument can be used to specify the uid of the process that is
- * permitted to connect.
- * TODO(yongsheng): how to enable this in XWalkPreferencesInternal?
- *
- * @hide
+ * Enables remote debugging and returns the URL at which the dev tools
+ * server is listening for commands.
+ * The allowedUid argument can be used to specify the uid of the process
+ * that is permitted to connect.
*/
- public String enableRemoteDebugging(int allowedUid) {
+ public void enableRemoteDebugging(int allowedUid) {
+ if (mContent == null) return;
+ checkThreadSafety();
+ mContent.enableRemoteDebugging(allowedUid);
+ }
+
+ /**
+ * Get the websocket url for remote debugging.
+ * @return the web socket url to remote debug this xwalk view.
+ * null will be returned if remote debugging is not enabled.
+ * @since 4.0
+ */
+ @XWalkAPI
+ public URL getRemoteDebuggingUrl() {
if (mContent == null) return null;
checkThreadSafety();
- return mContent.enableRemoteDebugging(allowedUid);
+ String wsUrl = mContent.getRemoteDebuggingUrl();
+ if (wsUrl == null || wsUrl.isEmpty()) return null;
+
+ try {
+ return new URL(wsUrl);
+ } catch (MalformedURLException e) {
+ return null;
+ }
}
/**
if (mContent == null) return;
ApplicationStatus.unregisterActivityStateListener(mActivityStateListener);
mActivityStateListener = null;
- if (null != mExtensionManager) mExtensionManager.onDestroy();
mContent.destroy();
disableRemoteDebugging();
}
// Enables remote debugging and returns the URL at which the dev tools server is listening
// for commands. Only the current process is allowed to connect to the server.
- String enableRemoteDebugging() {
- return enableRemoteDebugging(mContext.getApplicationInfo().uid);
+ void enableRemoteDebugging() {
+ enableRemoteDebugging(mContext.getApplicationInfo().uid);
}
void disableRemoteDebugging() {
private void onActivityStateChange(Activity activity, int newState) {
assert(getActivity() == activity);
switch (newState) {
- case ActivityState.STARTED:
+ case ActivityState.STARTED:
onShow();
break;
case ActivityState.PAUSED:
case ActivityState.DESTROYED:
onDestroy();
break;
- case ActivityState.STOPPED:
+ case ActivityState.STOPPED:
onHide();
break;
default: