diff options
author | tedchoc@chromium.org <tedchoc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-10 00:03:59 +0000 |
---|---|---|
committer | tedchoc@chromium.org <tedchoc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-10 00:03:59 +0000 |
commit | d4f8cd3b6b75ae4292b6eb028c51fd6082af2ee4 (patch) | |
tree | 8a2a7c47eea4fc98fd315bf4ab21023aadbec128 /content/shell/android/java/src | |
parent | df1e4fc94bda9ee5576b566aade733ccc53a9d3f (diff) | |
download | chromium_src-d4f8cd3b6b75ae4292b6eb028c51fd6082af2ee4.zip chromium_src-d4f8cd3b6b75ae4292b6eb028c51fd6082af2ee4.tar.gz chromium_src-d4f8cd3b6b75ae4292b6eb028c51fd6082af2ee4.tar.bz2 |
Add support for closing Android Shell instances from Java.
This also fixes an issue where the java side would be deleted when
calling launchShell, but the native counter part was not being cleaned
up.
BUG=330902
TBR=avi@chromium.org
Review URL: https://codereview.chromium.org/117403003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@244022 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/shell/android/java/src')
-rw-r--r-- | content/shell/android/java/src/org/chromium/content_shell/Shell.java | 35 | ||||
-rw-r--r-- | content/shell/android/java/src/org/chromium/content_shell/ShellManager.java | 11 |
2 files changed, 40 insertions, 6 deletions
diff --git a/content/shell/android/java/src/org/chromium/content_shell/Shell.java b/content/shell/android/java/src/org/chromium/content_shell/Shell.java index 1ec5919..1010c80 100644 --- a/content/shell/android/java/src/org/chromium/content_shell/Shell.java +++ b/content/shell/android/java/src/org/chromium/content_shell/Shell.java @@ -49,6 +49,7 @@ public class Shell extends LinearLayout { private ClipDrawable mProgressDrawable; + private long mNativeShell; private ContentViewRenderView mContentViewRenderView; private WindowAndroid mWindow; @@ -80,13 +81,43 @@ public class Shell extends LinearLayout { } /** + * Initializes the Shell for use. + * + * @param nativeShell The pointer to the native Shell object. * @param window The owning window for this shell. */ - public void setWindow(WindowAndroid window) { + public void initialize(long nativeShell, WindowAndroid window) { + mNativeShell = nativeShell; mWindow = window; } /** + * Closes the shell and cleans up the native instance, which will handle destroying all + * dependencies. + */ + public void close() { + if (mNativeShell == 0) return; + nativeCloseShell(mNativeShell); + } + + @CalledByNative + private void onNativeDestroyed() { + mWindow = null; + mNativeShell = 0; + assert !mContentView.isAttachedToWindow() + : "Attempting to destroy the content view while attached to the view hierarchy."; + mContentView.destroy(); + } + + /** + * @return Whether the Shell has been destroyed. + * @see #onNativeDestroyed() + */ + public boolean isDestroyed() { + return mNativeShell == 0; + } + + /** * @return Whether or not the Shell is loading content. */ public boolean isLoading() { @@ -242,4 +273,6 @@ public class Shell extends LinearLayout { imm.hideSoftInputFromWindow(mUrlTextView.getWindowToken(), 0); } } + + private static native void nativeCloseShell(long shellPtr); } diff --git a/content/shell/android/java/src/org/chromium/content_shell/ShellManager.java b/content/shell/android/java/src/org/chromium/content_shell/ShellManager.java index c1f1e3d..6663f31 100644 --- a/content/shell/android/java/src/org/chromium/content_shell/ShellManager.java +++ b/content/shell/android/java/src/org/chromium/content_shell/ShellManager.java @@ -11,6 +11,7 @@ import android.widget.FrameLayout; import org.chromium.base.CalledByNative; import org.chromium.base.JNINamespace; +import org.chromium.base.ThreadUtils; import org.chromium.content.browser.ContentView; import org.chromium.content.browser.ContentViewRenderView; import org.chromium.ui.base.WindowAndroid; @@ -82,6 +83,7 @@ public class ShellManager extends FrameLayout { * @param url The URL the shell should load upon creation. */ public void launchShell(String url) { + ThreadUtils.assertOnUiThread(); nativeLaunchShell(url); } @@ -96,14 +98,14 @@ public class ShellManager extends FrameLayout { @SuppressWarnings("unused") @CalledByNative - private Object createShell() { + 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.setWindow(mWindow); + shellView.initialize(nativeShellPtr, mWindow); - if (mActiveShell != null) closeShell(mActiveShell); + if (mActiveShell != null) mActiveShell.close(); shellView.setContentViewRenderView(mContentViewRenderView); addView(shellView, new FrameLayout.LayoutParams( @@ -120,12 +122,11 @@ public class ShellManager extends FrameLayout { @SuppressWarnings("unused") @CalledByNative - private void closeShell(Shell shellView) { + private void removeShell(Shell shellView) { if (shellView == mActiveShell) mActiveShell = null; ContentView contentView = shellView.getContentView(); if (contentView != null) contentView.onHide(); shellView.setContentViewRenderView(null); - shellView.setWindow(null); removeView(shellView); } |