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
private XWalkContent mContent;
private Activity mActivity;
private Context mContext;
- private XWalkExtensionManager mExtensionManager;
private boolean mIsHidden;
private XWalkActivityStateListener mActivityStateListener;
@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);
}
/**
@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;
}
/**
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();
@XWalkAPI
public void onHide() {
if (mContent == null || mIsHidden) return;
- if (null != mExtensionManager) mExtensionManager.onPause();
mContent.onPause();
mIsHidden = true;
}
@XWalkAPI
public void onShow() {
if (mContent == null || !mIsHidden ) return;
- if (null != mExtensionManager) mExtensionManager.onResume();
mContent.onResume();
mIsHidden = false;
}
@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);
}
// TODO(yongsheng): make it static?
@XWalkAPI
public String getAPIVersion() {
- return "2.1";
+ return "3.0";
}
/**
*
* @hide
*/
+ @XWalkAPI
public void setNetworkAvailable(boolean networkUp) {
if (mContent == null) return;
checkThreadSafety();
if (mContent == null) return;
ApplicationStatus.unregisterActivityStateListener(mActivityStateListener);
mActivityStateListener = null;
- if (null != mExtensionManager) mExtensionManager.onDestroy();
mContent.destroy();
disableRemoteDebugging();
}