1 // Copyright (c) 2012 The Chromium Authors. 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.chromium.content_shell;
7 import android.content.Context;
8 import android.util.AttributeSet;
9 import android.view.LayoutInflater;
10 import android.widget.FrameLayout;
12 import org.chromium.base.CalledByNative;
13 import org.chromium.base.JNINamespace;
14 import org.chromium.content.browser.ContentView;
15 import org.chromium.content.browser.ContentViewRenderView;
16 import org.chromium.ui.WindowAndroid;
19 * Container and generator of ShellViews.
21 @JNINamespace("content")
22 public class ShellManager extends FrameLayout {
24 public static final String DEFAULT_SHELL_URL = "http://www.google.com";
25 private static boolean sStartup = true;
26 private WindowAndroid mWindow;
27 private Shell mActiveShell;
29 private String mStartupUrl = DEFAULT_SHELL_URL;
31 // The target for all content rendering.
32 private ContentViewRenderView mContentViewRenderView;
35 * Constructor for inflating via XML.
37 public ShellManager(Context context, AttributeSet attrs) {
38 super(context, attrs);
40 mContentViewRenderView = new ContentViewRenderView(context) {
42 protected void onReadyToRender() {
44 mActiveShell.loadUrl(mStartupUrl);
52 * @param window The window used to generate all shells.
54 public void setWindow(WindowAndroid window) {
59 * @return The window used to generate all shells.
61 public WindowAndroid getWindow() {
66 * Sets the startup URL for new shell windows.
68 public void setStartupUrl(String url) {
73 * @return The currently visible shell view or null if one is not showing.
75 public Shell getActiveShell() {
80 * Creates a new shell pointing to the specified URL.
81 * @param url The URL the shell should load upon creation.
83 public void launchShell(String url) {
84 nativeLaunchShell(url);
87 @SuppressWarnings("unused")
89 private Object createShell() {
90 LayoutInflater inflater =
91 (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
92 Shell shellView = (Shell) inflater.inflate(R.layout.shell_view, null);
93 shellView.setWindow(mWindow);
95 if (mActiveShell != null) closeShell(mActiveShell);
97 shellView.setContentViewRenderView(mContentViewRenderView);
98 addView(shellView, new FrameLayout.LayoutParams(
99 FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
100 mActiveShell = shellView;
101 ContentView contentView = mActiveShell.getContentView();
102 if (contentView != null) {
103 mContentViewRenderView.setCurrentContentView(contentView);
104 contentView.onShow();
110 @SuppressWarnings("unused")
112 private void closeShell(Shell shellView) {
113 if (shellView == mActiveShell) mActiveShell = null;
114 ContentView contentView = shellView.getContentView();
115 if (contentView != null) contentView.onHide();
116 shellView.setContentViewRenderView(null);
117 shellView.setWindow(null);
118 removeView(shellView);
121 private static native void nativeInit(Object shellManagerInstance);
122 private static native void nativeLaunchShell(String url);