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

Unified Diff: android_webview/java/src/org/chromium/android_webview/AwContents.java

Issue 11348075: [Android WebView] AwContentsClient.shouldCreate window callback part 2. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix spurious includes. Created 8 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: android_webview/java/src/org/chromium/android_webview/AwContents.java
diff --git a/android_webview/java/src/org/chromium/android_webview/AwContents.java b/android_webview/java/src/org/chromium/android_webview/AwContents.java
index 2d831718261da54f7530e452f1de5ef537ddff18..2ee4724a4f258fe53c9f40f2a366a25c79225f1c 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwContents.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java
@@ -25,6 +25,7 @@ import android.webkit.ValueCallback;
import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace;
import org.chromium.base.ThreadUtils;
+import org.chromium.content.browser.ContentSettings;
import org.chromium.content.browser.ContentViewCore;
import org.chromium.content.browser.LoadUrlParams;
import org.chromium.content.browser.NavigationHistory;
@@ -78,6 +79,7 @@ public class AwContents {
private AwContentsClient mContentsClient;
private AwContentsIoThreadClient mIoThreadClient;
private InterceptNavigationDelegateImpl mInterceptNavigationDelegate;
+ private ContentViewCore.InternalAccessDelegate mInternalAccessAdapter;
// This can be accessed on any thread after construction. See AwContentsIoThreadClient.
private final AwSettings mSettings;
private final ClientCallbackHandler mClientCallbackHandler;
@@ -216,6 +218,7 @@ public class AwContents {
* @param contentsClient will receive API callbacks from this WebView Contents
* @param privateBrowsing whether this is a private browsing instance of WebView.
* @param isAccessFromFileURLsGrantedByDefault passed to ContentViewCore.initialize.
+ * TODO(benm): Remove the nativeWindow parameter.
*/
public AwContents(ViewGroup containerView,
ContentViewCore.InternalAccessDelegate internalAccessAdapter,
@@ -223,6 +226,7 @@ public class AwContents {
NativeWindow nativeWindow, boolean privateBrowsing,
boolean isAccessFromFileURLsGrantedByDefault) {
mContainerView = containerView;
+ mInternalAccessAdapter = internalAccessAdapter;
// Note that ContentViewCore must be set up before AwContents, as ContentViewCore
// setup performs process initialisation work needed by AwContents.
mContentViewCore = new ContentViewCore(containerView.getContext(),
@@ -233,9 +237,10 @@ public class AwContents {
mClientCallbackHandler = new ClientCallbackHandler();
mContentViewCore.initialize(containerView, internalAccessAdapter,
- nativeGetWebContents(mNativeAwContents), nativeWindow,
+ nativeGetWebContents(mNativeAwContents),
+ new AwNativeWindow(mContainerView.getContext()),
isAccessFromFileURLsGrantedByDefault);
- mContentViewCore.setContentViewClient(contentsClient);
+ mContentViewCore.setContentViewClient(mContentsClient);
mContentsClient.installWebContentsObserver(mContentViewCore);
mSettings = new AwSettings(mContentViewCore.getContext());
@@ -356,6 +361,56 @@ public class AwContents {
}
}
+ /**
+ * Called on the "source" AwContents that is opening the popup window to
+ * provide the AwContents to host the pop up content.
+ */
+ public void supplyContentsForPopup(AwContents newContents) {
+ int popupWebContents = nativeReleasePopupWebContents(mNativeAwContents);
+ assert popupWebContents != 0;
+ newContents.setNewWebContents(popupWebContents);
+ }
+
+ private void setNewWebContents(int newWebContentsPtr) {
+ // When setting a new WebContents, we new up a ContentViewCore that will
+ // wrap it and then swap it.
+ ContentViewCore newCore = new ContentViewCore(mContainerView.getContext(),
+ ContentViewCore.PERSONALITY_VIEW);
+ // Note we pass false for isAccessFromFileURLsGrantedByDefault as we'll
+ // set it correctly when when we copy the settings from the old ContentViewCore
+ // into the new one.
+ newCore.initialize(mContainerView, mInternalAccessAdapter,
+ newWebContentsPtr, new AwNativeWindow(mContainerView.getContext()),
+ false);
+ newCore.setContentViewClient(mContentsClient);
+ mContentsClient.installWebContentsObserver(newCore);
+
+ ContentSettings oldSettings = mContentViewCore.getContentSettings();
+ newCore.getContentSettings().initFrom(oldSettings);
+
+ // Now swap the Java side reference.
+ mContentViewCore.destroy();
+ mContentViewCore = newCore;
+
+ // Now rewire native side to use the new WebContents.
+ nativeSetWebContents(mNativeAwContents, newWebContentsPtr);
+ nativeSetIoThreadClient(mNativeAwContents, mIoThreadClient);
+ nativeSetInterceptNavigationDelegate(mNativeAwContents, mInterceptNavigationDelegate);
+
+ // Finally poke the new ContentViewCore with the size of the container view and show it.
+ if (mContainerView.getWidth() != 0 || mContainerView.getHeight() != 0) {
+ mContentViewCore.onSizeChanged(
+ mContainerView.getWidth(), mContainerView.getHeight(), 0, 0);
+ }
+ nativeDidInitializeContentViewCore(mNativeAwContents,
+ mContentViewCore.getNativeContentViewCore());
+ if (mContainerView.getVisibility() == View.VISIBLE) {
+ // The popup window was hidden when we prompted the embedder to display
+ // it, so show it again now we have a container.
+ mContentViewCore.onShow();
+ }
+ }
+
//--------------------------------------------------------------------------------------------
// WebView[Provider] method implementations (where not provided by ContentViewCore)
//--------------------------------------------------------------------------------------------
@@ -623,9 +678,15 @@ public class AwContents {
private void updateVisiblityState() {
if (mNativeAwContents == 0 || mIsPaused) return;
- nativeSetWindowViewVisibility(mNativeAwContents,
- mContainerView.getWindowVisibility() == View.VISIBLE,
- mContainerView.getVisibility() == View.VISIBLE);
+ boolean windowVisible = mContainerView.getWindowVisibility() == View.VISIBLE;
+ boolean viewVisible = mContainerView.getVisibility() == View.VISIBLE;
+ nativeSetWindowViewVisibility(mNativeAwContents, windowVisible, viewVisible);
+
+ if (viewVisible) {
+ mContentViewCore.onShow();
+ } else {
+ mContentViewCore.onHide();
+ }
}
@@ -820,4 +881,7 @@ public class AwContents {
// Returns false if restore state fails.
private native boolean nativeRestoreFromOpaqueState(int nativeAwContents, byte[] state);
+
+ private native int nativeReleasePopupWebContents(int nativeAwContents);
+ private native void nativeSetWebContents(int nativeAwContents, int nativeNewWebContents);
}

Powered by Google App Engine
This is Rietveld 408576698