// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-package org.xwalk.core;
+package org.xwalk.core.internal;
import android.app.Activity;
import android.content.Context;
import org.chromium.content.browser.ContentViewStatics;
import org.chromium.content.browser.LoadUrlParams;
import org.chromium.content.browser.NavigationHistory;
+import org.chromium.content.common.CleanupReference;
import org.chromium.media.MediaPlayerBridge;
import org.chromium.ui.base.ActivityWindowAndroid;
+import org.xwalk.core.JavascriptInterface;
+
@JNINamespace("xwalk")
/**
- * This class is the implementation class for XWalkView by calling internal
+ * This class is the implementation class for XWalkViewInternal by calling internal
* various classes.
*/
-class XWalkContent extends FrameLayout implements XWalkPreferences.KeyValueChangeListener {
+class XWalkContent extends FrameLayout implements XWalkPreferencesInternal.KeyValueChangeListener {
private static String TAG = "XWalkContent";
private ContentViewCore mContentViewCore;
private ContentView mContentView;
private ContentViewRenderView mContentViewRenderView;
private ActivityWindowAndroid mWindow;
private XWalkDevToolsServer mDevToolsServer;
- private XWalkView mXWalkView;
+ private XWalkViewInternal mXWalkView;
private XWalkContentsClientBridge mContentsClientBridge;
private XWalkContentsIoThreadClient mIoThreadClient;
private XWalkWebContentsDelegateAdapter mXWalkContentsDelegateAdapter;
long mXWalkContent;
long mWebContents;
- public XWalkContent(Context context, AttributeSet attrs, XWalkView xwView) {
+ private static final class DestroyRunnable implements Runnable {
+ private final long mXWalkContent;
+ private DestroyRunnable(long nativeXWalkContent) {
+ mXWalkContent = nativeXWalkContent;
+ }
+
+ @Override
+ public void run() {
+ nativeDestroy(mXWalkContent);
+ }
+ }
+
+ // Reference to the active mXWalkContent pointer while it is active use
+ // (ie before it is destroyed).
+ private CleanupReference mCleanupReference;
+
+ public XWalkContent(Context context, AttributeSet attrs, XWalkViewInternal xwView) {
super(context, attrs);
// Initialize the WebContensDelegate.
mWindow = new ActivityWindowAndroid(xwView.getActivity());
// Initialize ContentViewRenderView
- boolean animated = XWalkPreferences.getValue(XWalkPreferences.ANIMATABLE_XWALK_VIEW);
+ boolean animated = XWalkPreferencesInternal.getValue(XWalkPreferencesInternal.ANIMATABLE_XWALK_VIEW);
CompositingSurfaceType surfaceType =
animated ? CompositingSurfaceType.TEXTURE_VIEW : CompositingSurfaceType.SURFACE_VIEW;
mContentViewRenderView = new ContentViewRenderView(context, mWindow, surfaceType) {
FrameLayout.LayoutParams.MATCH_PARENT));
mXWalkContent = nativeInit(mXWalkContentsDelegateAdapter, mContentsClientBridge);
+
+ // The native side object has been bound to this java instance, so now is the time to
+ // bind all the native->java relationships.
+ mCleanupReference = new CleanupReference(this, new DestroyRunnable(mXWalkContent));
+
mWebContents = nativeGetWebContents(mXWalkContent, mIoThreadClient,
mContentsClientBridge.getInterceptNavigationDelegate());
MediaPlayerBridge.setResourceLoadingFilter(
new XWalkMediaPlayerResourceLoadingFilter());
- XWalkPreferences.load(this);
+ XWalkPreferencesInternal.load(this);
}
void doLoadUrl(String url, String content) {
public void reload(int mode) {
switch (mode) {
- case XWalkView.RELOAD_IGNORE_CACHE:
+ case XWalkViewInternal.RELOAD_IGNORE_CACHE:
mContentViewCore.reloadIgnoringCache(true);
break;
- case XWalkView.RELOAD_NORMAL:
+ case XWalkViewInternal.RELOAD_NORMAL:
default:
mContentViewCore.reload(true);
}
mContentViewCore.evaluateJavaScript(script, coreCallback);
}
- public void setUIClient(XWalkUIClient client) {
+ public void setUIClient(XWalkUIClientInternal client) {
mContentsClientBridge.setUIClient(client);
}
- public void setResourceClient(XWalkResourceClient client) {
+ public void setResourceClient(XWalkResourceClientInternal client) {
mContentsClientBridge.setResourceClient(client);
}
}
}
- public XWalkNavigationHistory getNavigationHistory() {
- return new XWalkNavigationHistory(mXWalkView, mContentViewCore.getNavigationHistory());
+ public XWalkNavigationHistoryInternal getNavigationHistory() {
+ return new XWalkNavigationHistoryInternal(mXWalkView, mContentViewCore.getNavigationHistory());
}
public static final String SAVE_RESTORE_STATE_KEY = "XWALKVIEW_STATE";
- public XWalkNavigationHistory saveState(Bundle outState) {
+ public XWalkNavigationHistoryInternal saveState(Bundle outState) {
if (outState == null) return null;
byte[] state = nativeGetState(mXWalkContent);
return getNavigationHistory();
}
- public XWalkNavigationHistory restoreState(Bundle inState) {
+ public XWalkNavigationHistoryInternal restoreState(Bundle inState) {
if (inState == null) return null;
byte[] state = inState.getByteArray(SAVE_RESTORE_STATE_KEY);
public void destroy() {
if (mXWalkContent == 0) return;
- XWalkPreferences.unload(this);
+ XWalkPreferencesInternal.unload(this);
// Reset existing notification service in order to destruct it.
setNotificationService(null);
// Remove its children used for page rendering from view hierarchy.
mContentViewRenderView.destroy();
mContentViewCore.destroy();
- nativeDestroy(mXWalkContent);
+ mCleanupReference.cleanupNow();
+ mCleanupReference = null;
mXWalkContent = 0;
}
} else {
if (isMainFrame && webResourceResponse.getData() == null) {
mContentsClientBridge.getCallbackHelper().postOnReceivedError(
- XWalkResourceClient.ERROR_UNKNOWN, null, url);
+ XWalkResourceClientInternal.ERROR_UNKNOWN, null, url);
}
interceptedRequestData = new InterceptedRequestData(webResourceResponse.getMimeType(),
webResourceResponse.getEncoding(),
@Override
public void onKeyValueChanged(String key, boolean value) {
- if (key == XWalkPreferences.REMOTE_DEBUGGING) {
+ if (key == XWalkPreferencesInternal.REMOTE_DEBUGGING) {
if (value) enableRemoteDebugging();
else disableRemoteDebugging();
}