Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(298)

Side by Side Diff: content/shell/android/java/src/org/chromium/content_shell/ShellManager.java

Issue 117403003: Add support for closing Android Shell instances from Java. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 /** 90 /**
89 * Enter or leave overlay video mode. 91 * Enter or leave overlay video mode.
90 * @param enabled Whether overlay mode is enabled. 92 * @param enabled Whether overlay mode is enabled.
91 */ 93 */
92 public void setOverlayVideoMode(boolean enabled) { 94 public void setOverlayVideoMode(boolean enabled) {
93 if (mContentViewRenderView == null) return; 95 if (mContentViewRenderView == null) return;
94 mContentViewRenderView.setOverlayVideoMode(enabled); 96 mContentViewRenderView.setOverlayVideoMode(enabled);
95 } 97 }
96 98
97 @SuppressWarnings("unused") 99 @SuppressWarnings("unused")
98 @CalledByNative 100 @CalledByNative
99 private Object createShell() { 101 private Object createShell(long nativeShellPtr) {
100 assert mContentViewRenderView != null; 102 assert mContentViewRenderView != null;
101 LayoutInflater inflater = 103 LayoutInflater inflater =
102 (LayoutInflater) getContext().getSystemService(Context.LAYOUT_IN FLATER_SERVICE); 104 (LayoutInflater) getContext().getSystemService(Context.LAYOUT_IN FLATER_SERVICE);
103 Shell shellView = (Shell) inflater.inflate(R.layout.shell_view, null); 105 Shell shellView = (Shell) inflater.inflate(R.layout.shell_view, null);
104 shellView.setWindow(mWindow); 106 shellView.initialize(nativeShellPtr, mWindow);
105 107
106 if (mActiveShell != null) closeShell(mActiveShell); 108 if (mActiveShell != null) mActiveShell.close();
107 109
108 shellView.setContentViewRenderView(mContentViewRenderView); 110 shellView.setContentViewRenderView(mContentViewRenderView);
109 addView(shellView, new FrameLayout.LayoutParams( 111 addView(shellView, new FrameLayout.LayoutParams(
110 FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams. MATCH_PARENT)); 112 FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams. MATCH_PARENT));
111 mActiveShell = shellView; 113 mActiveShell = shellView;
112 ContentView contentView = mActiveShell.getContentView(); 114 ContentView contentView = mActiveShell.getContentView();
113 if (contentView != null) { 115 if (contentView != null) {
114 mContentViewRenderView.setCurrentContentView(contentView); 116 mContentViewRenderView.setCurrentContentView(contentView);
115 contentView.onShow(); 117 contentView.onShow();
116 } 118 }
117 119
118 return shellView; 120 return shellView;
119 } 121 }
120 122
121 @SuppressWarnings("unused") 123 @SuppressWarnings("unused")
122 @CalledByNative 124 @CalledByNative
123 private void closeShell(Shell shellView) { 125 private void removeShell(Shell shellView) {
124 if (shellView == mActiveShell) mActiveShell = null; 126 if (shellView == mActiveShell) mActiveShell = null;
125 ContentView contentView = shellView.getContentView(); 127 ContentView contentView = shellView.getContentView();
126 if (contentView != null) contentView.onHide(); 128 if (contentView != null) contentView.onHide();
127 shellView.setContentViewRenderView(null); 129 shellView.setContentViewRenderView(null);
128 shellView.setWindow(null);
129 removeView(shellView); 130 removeView(shellView);
130 } 131 }
131 132
132 private static native void nativeInit(Object shellManagerInstance); 133 private static native void nativeInit(Object shellManagerInstance);
133 private static native void nativeLaunchShell(String url); 134 private static native void nativeLaunchShell(String url);
134 } 135 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698