| 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.CalledByNative; | 12 import org.chromium.base.CalledByNative; |
| 13 import org.chromium.base.JNINamespace; | 13 import org.chromium.base.JNINamespace; |
| 14 import org.chromium.base.ThreadUtils; |
| 14 import org.chromium.content.browser.ContentView; | 15 import org.chromium.content.browser.ContentView; |
| 15 import org.chromium.content.browser.ContentViewRenderView; | 16 import org.chromium.content.browser.ContentViewRenderView; |
| 16 import org.chromium.ui.base.WindowAndroid; | 17 import org.chromium.ui.base.WindowAndroid; |
| 17 | 18 |
| 18 /** | 19 /** |
| 19 * Container and generator of ShellViews. | 20 * Container and generator of ShellViews. |
| 20 */ | 21 */ |
| 21 @JNINamespace("content") | 22 @JNINamespace("content") |
| 22 public class ShellManager extends FrameLayout { | 23 public class ShellManager extends FrameLayout { |
| 23 | 24 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 */ | 76 */ |
| 76 public Shell getActiveShell() { | 77 public Shell getActiveShell() { |
| 77 return mActiveShell; | 78 return mActiveShell; |
| 78 } | 79 } |
| 79 | 80 |
| 80 /** | 81 /** |
| 81 * Creates a new shell pointing to the specified URL. | 82 * Creates a new shell pointing to the specified URL. |
| 82 * @param url The URL the shell should load upon creation. | 83 * @param url The URL the shell should load upon creation. |
| 83 */ | 84 */ |
| 84 public void launchShell(String url) { | 85 public void launchShell(String url) { |
| 86 ThreadUtils.assertOnUiThread(); |
| 85 nativeLaunchShell(url); | 87 nativeLaunchShell(url); |
| 86 } | 88 } |
| 87 | 89 |
| 88 @SuppressWarnings("unused") | 90 @SuppressWarnings("unused") |
| 89 @CalledByNative | 91 @CalledByNative |
| 90 private Object createShell() { | 92 private Object createShell(long nativeShellPtr) { |
| 91 assert mContentViewRenderView != null; | 93 assert mContentViewRenderView != null; |
| 92 LayoutInflater inflater = | 94 LayoutInflater inflater = |
| 93 (LayoutInflater) getContext().getSystemService(Context.LAYOUT_IN
FLATER_SERVICE); | 95 (LayoutInflater) getContext().getSystemService(Context.LAYOUT_IN
FLATER_SERVICE); |
| 94 Shell shellView = (Shell) inflater.inflate(R.layout.shell_view, null); | 96 Shell shellView = (Shell) inflater.inflate(R.layout.shell_view, null); |
| 95 shellView.setWindow(mWindow); | 97 shellView.initialize(nativeShellPtr, mWindow); |
| 96 | 98 |
| 97 if (mActiveShell != null) closeShell(mActiveShell); | 99 if (mActiveShell != null) mActiveShell.close(); |
| 98 | 100 |
| 99 shellView.setContentViewRenderView(mContentViewRenderView); | 101 shellView.setContentViewRenderView(mContentViewRenderView); |
| 100 addView(shellView, new FrameLayout.LayoutParams( | 102 addView(shellView, new FrameLayout.LayoutParams( |
| 101 FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.
MATCH_PARENT)); | 103 FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.
MATCH_PARENT)); |
| 102 mActiveShell = shellView; | 104 mActiveShell = shellView; |
| 103 ContentView contentView = mActiveShell.getContentView(); | 105 ContentView contentView = mActiveShell.getContentView(); |
| 104 if (contentView != null) { | 106 if (contentView != null) { |
| 105 mContentViewRenderView.setCurrentContentView(contentView); | 107 mContentViewRenderView.setCurrentContentView(contentView); |
| 106 contentView.onShow(); | 108 contentView.onShow(); |
| 107 } | 109 } |
| 108 | 110 |
| 109 return shellView; | 111 return shellView; |
| 110 } | 112 } |
| 111 | 113 |
| 112 @SuppressWarnings("unused") | 114 @SuppressWarnings("unused") |
| 113 @CalledByNative | 115 @CalledByNative |
| 114 private void closeShell(Shell shellView) { | 116 private void removeShell(Shell shellView) { |
| 115 if (shellView == mActiveShell) mActiveShell = null; | 117 if (shellView == mActiveShell) mActiveShell = null; |
| 116 ContentView contentView = shellView.getContentView(); | 118 ContentView contentView = shellView.getContentView(); |
| 117 if (contentView != null) contentView.onHide(); | 119 if (contentView != null) contentView.onHide(); |
| 118 shellView.setContentViewRenderView(null); | 120 shellView.setContentViewRenderView(null); |
| 119 shellView.setWindow(null); | |
| 120 removeView(shellView); | 121 removeView(shellView); |
| 121 } | 122 } |
| 122 | 123 |
| 123 private static native void nativeInit(Object shellManagerInstance); | 124 private static native void nativeInit(Object shellManagerInstance); |
| 124 private static native void nativeLaunchShell(String url); | 125 private static native void nativeLaunchShell(String url); |
| 125 } | 126 } |
| OLD | NEW |