This source file includes following definitions.
- JNINamespace
- setWindow
- getWindow
- setStartupUrl
- getActiveShell
- launchShell
- setOverlayVideoMode
- SuppressWarnings
- createShell
- showShell
- removeShell
- nativeInit
- nativeLaunchShell
package org.chromium.content_shell;
import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import org.chromium.base.CalledByNative;
import org.chromium.base.CommandLine;
import org.chromium.base.JNINamespace;
import org.chromium.base.ThreadUtils;
import org.chromium.content.browser.ActivityContentVideoViewClient;
import org.chromium.content.browser.ContentVideoViewClient;
import org.chromium.content.browser.ContentView;
import org.chromium.content.browser.ContentViewClient;
import org.chromium.content.browser.ContentViewRenderView;
import org.chromium.content.common.ContentSwitches;
import org.chromium.ui.base.WindowAndroid;
@JNINamespace("content")
public class ShellManager extends FrameLayout {
public static final String DEFAULT_SHELL_URL = "http://www.google.com";
private static boolean sStartup = true;
private WindowAndroid mWindow;
private Shell mActiveShell;
private String mStartupUrl = DEFAULT_SHELL_URL;
private ContentViewRenderView mContentViewRenderView;
private ContentViewClient mContentViewClient;
public ShellManager(final Context context, AttributeSet attrs) {
super(context, attrs);
nativeInit(this);
mContentViewClient = new ContentViewClient() {
@Override
public ContentVideoViewClient getContentVideoViewClient() {
return new ActivityContentVideoViewClient((Activity) context) {
@Override
public void onShowCustomView(View view) {
super.onShowCustomView(view);
if (!CommandLine.getInstance().hasSwitch(
ContentSwitches.DISABLE_OVERLAY_FULLSCREEN_VIDEO_SUBTITLE)) {
setOverlayVideoMode(true);
}
}
@Override
public void onDestroyContentVideoView() {
super.onDestroyContentVideoView();
if (!CommandLine.getInstance().hasSwitch(
ContentSwitches.DISABLE_OVERLAY_FULLSCREEN_VIDEO_SUBTITLE)) {
setOverlayVideoMode(false);
}
}
};
}
};
}
public void setWindow(WindowAndroid window) {
assert window != null;
mWindow = window;
mContentViewRenderView = new ContentViewRenderView(getContext(), window) {
@Override
protected void onReadyToRender() {
if (sStartup) {
mActiveShell.loadUrl(mStartupUrl);
sStartup = false;
}
}
};
}
public WindowAndroid getWindow() {
return mWindow;
}
public void setStartupUrl(String url) {
mStartupUrl = url;
}
public Shell getActiveShell() {
return mActiveShell;
}
public void launchShell(String url) {
ThreadUtils.assertOnUiThread();
Shell previousShell = mActiveShell;
nativeLaunchShell(url);
if (previousShell != null) previousShell.close();
}
public void setOverlayVideoMode(boolean enabled) {
if (mContentViewRenderView == null) return;
mContentViewRenderView.setOverlayVideoMode(enabled);
}
@SuppressWarnings("unused")
@CalledByNative
private Object createShell(long nativeShellPtr) {
assert mContentViewRenderView != null;
LayoutInflater inflater =
(LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
Shell shellView = (Shell) inflater.inflate(R.layout.shell_view, null);
shellView.initialize(nativeShellPtr, mWindow, mContentViewClient);
if (mActiveShell != null) removeShell(mActiveShell);
showShell(shellView);
return shellView;
}
private void showShell(Shell shellView) {
shellView.setContentViewRenderView(mContentViewRenderView);
addView(shellView, new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
mActiveShell = shellView;
ContentView contentView = mActiveShell.getContentView();
if (contentView != null) {
mContentViewRenderView.setCurrentContentView(contentView);
contentView.onShow();
}
}
@CalledByNative
private void removeShell(Shell shellView) {
if (shellView == mActiveShell) mActiveShell = null;
if (shellView.getParent() == null) return;
ContentView contentView = shellView.getContentView();
if (contentView != null) contentView.onHide();
shellView.setContentViewRenderView(null);
removeView(shellView);
}
private static native void nativeInit(Object shellManagerInstance);
private static native void nativeLaunchShell(String url);
}