OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.content_shell; | 5 package org.chromium.content_shell; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.util.AttributeSet; | 8 import android.util.AttributeSet; |
9 import android.view.LayoutInflater; | 9 import android.view.LayoutInflater; |
10 import android.widget.FrameLayout; | 10 import android.widget.FrameLayout; |
11 | 11 |
12 import org.chromium.base.ThreadUtils; | 12 import org.chromium.base.ThreadUtils; |
13 import org.chromium.base.annotations.CalledByNative; | 13 import org.chromium.base.annotations.CalledByNative; |
14 import org.chromium.base.annotations.JNINamespace; | 14 import org.chromium.base.annotations.JNINamespace; |
15 import org.chromium.content.browser.ContentViewClient; | 15 import org.chromium.content.browser.ContentViewClient; |
16 import org.chromium.content.browser.ContentViewCore; | 16 import org.chromium.content.browser.ContentViewCore; |
17 import org.chromium.content.browser.ContentViewRenderView; | 17 import org.chromium.content.browser.ContentViewRenderView; |
| 18 import org.chromium.ui.base.ViewRoot; |
18 import org.chromium.ui.base.WindowAndroid; | 19 import org.chromium.ui.base.WindowAndroid; |
19 | 20 |
20 /** | 21 /** |
21 * Container and generator of ShellViews. | 22 * Container and generator of ShellViews. |
22 */ | 23 */ |
23 @JNINamespace("content") | 24 @JNINamespace("content") |
24 public class ShellManager extends FrameLayout { | 25 public class ShellManager extends FrameLayout { |
25 | 26 |
26 public static final String DEFAULT_SHELL_URL = "http://www.google.com"; | 27 public static final String DEFAULT_SHELL_URL = "http://www.google.com"; |
27 private WindowAndroid mWindow; | 28 private WindowAndroid mWindow; |
| 29 private ViewRoot mViewRoot; |
28 private Shell mActiveShell; | 30 private Shell mActiveShell; |
29 | 31 |
30 private String mStartupUrl = DEFAULT_SHELL_URL; | 32 private String mStartupUrl = DEFAULT_SHELL_URL; |
31 | 33 |
32 // The target for all content rendering. | 34 // The target for all content rendering. |
33 private ContentViewRenderView mContentViewRenderView; | 35 private ContentViewRenderView mContentViewRenderView; |
34 private final ContentViewClient mContentViewClient = new ContentViewClient()
; | 36 private final ContentViewClient mContentViewClient = new ContentViewClient()
; |
35 | 37 |
36 /** | 38 /** |
37 * Constructor for inflating via XML. | 39 * Constructor for inflating via XML. |
38 */ | 40 */ |
39 public ShellManager(final Context context, AttributeSet attrs) { | 41 public ShellManager(final Context context, AttributeSet attrs) { |
40 super(context, attrs); | 42 super(context, attrs); |
41 nativeInit(this); | 43 nativeInit(this); |
42 } | 44 } |
43 | 45 |
44 /** | 46 /** |
45 * @param window The window used to generate all shells. | 47 * @param viewRoot The {@link ViewRoot} used to forward events to native. |
46 */ | 48 */ |
47 public void setWindow(WindowAndroid window) { | 49 public void setViewRoot(ViewRoot viewRoot) { |
48 assert window != null; | 50 assert viewRoot != null && viewRoot.getWindowAndroid() != null; |
49 mWindow = window; | 51 mViewRoot = viewRoot; |
| 52 mWindow = viewRoot.getWindowAndroid(); |
50 mContentViewRenderView = new ContentViewRenderView(getContext()); | 53 mContentViewRenderView = new ContentViewRenderView(getContext()); |
51 mContentViewRenderView.onNativeLibraryLoaded(window); | 54 mContentViewRenderView.onNativeLibraryLoaded(viewRoot); |
52 } | 55 } |
53 | 56 |
54 /** | 57 /** |
55 * @return The window used to generate all shells. | |
56 */ | |
57 public WindowAndroid getWindow() { | |
58 return mWindow; | |
59 } | |
60 | |
61 /** | |
62 * Get the ContentViewRenderView. | 58 * Get the ContentViewRenderView. |
63 */ | 59 */ |
64 public ContentViewRenderView getContentViewRenderView() { | 60 public ContentViewRenderView getContentViewRenderView() { |
65 return mContentViewRenderView; | 61 return mContentViewRenderView; |
66 } | 62 } |
67 | 63 |
68 /** | 64 /** |
69 * Sets the startup URL for new shell windows. | 65 * Sets the startup URL for new shell windows. |
70 */ | 66 */ |
71 public void setStartupUrl(String url) { | 67 public void setStartupUrl(String url) { |
(...skipping 27 matching lines...) Expand all Loading... |
99 mContentViewRenderView.setOverlayVideoMode(enabled); | 95 mContentViewRenderView.setOverlayVideoMode(enabled); |
100 } | 96 } |
101 | 97 |
102 @SuppressWarnings("unused") | 98 @SuppressWarnings("unused") |
103 @CalledByNative | 99 @CalledByNative |
104 private Object createShell(long nativeShellPtr) { | 100 private Object createShell(long nativeShellPtr) { |
105 assert mContentViewRenderView != null; | 101 assert mContentViewRenderView != null; |
106 LayoutInflater inflater = | 102 LayoutInflater inflater = |
107 (LayoutInflater) getContext().getSystemService(Context.LAYOUT_IN
FLATER_SERVICE); | 103 (LayoutInflater) getContext().getSystemService(Context.LAYOUT_IN
FLATER_SERVICE); |
108 Shell shellView = (Shell) inflater.inflate(R.layout.shell_view, null); | 104 Shell shellView = (Shell) inflater.inflate(R.layout.shell_view, null); |
109 shellView.initialize(nativeShellPtr, mWindow, mContentViewClient); | 105 shellView.initialize(nativeShellPtr, mViewRoot, mContentViewClient); |
110 | 106 |
111 // TODO(tedchoc): Allow switching back to these inactive shells. | 107 // TODO(tedchoc): Allow switching back to these inactive shells. |
112 if (mActiveShell != null) removeShell(mActiveShell); | 108 if (mActiveShell != null) removeShell(mActiveShell); |
113 | 109 |
114 showShell(shellView); | 110 showShell(shellView); |
115 return shellView; | 111 return shellView; |
116 } | 112 } |
117 | 113 |
118 private void showShell(Shell shellView) { | 114 private void showShell(Shell shellView) { |
119 shellView.setContentViewRenderView(mContentViewRenderView); | 115 shellView.setContentViewRenderView(mContentViewRenderView); |
(...skipping 23 matching lines...) Expand all Loading... |
143 public void destroy() { | 139 public void destroy() { |
144 // Remove active shell (Currently single shell support only available). | 140 // Remove active shell (Currently single shell support only available). |
145 removeShell(mActiveShell); | 141 removeShell(mActiveShell); |
146 mContentViewRenderView.destroy(); | 142 mContentViewRenderView.destroy(); |
147 mContentViewRenderView = null; | 143 mContentViewRenderView = null; |
148 } | 144 } |
149 | 145 |
150 private static native void nativeInit(Object shellManagerInstance); | 146 private static native void nativeInit(Object shellManagerInstance); |
151 private static native void nativeLaunchShell(String url); | 147 private static native void nativeLaunchShell(String url); |
152 } | 148 } |
OLD | NEW |