Commit 44bdc473 authored by mariakhomenko's avatar mariakhomenko Committed by Commit bot

Fix window.open issue in Document mode on Android.

Defers unblocking renderer's requests until the asynchronous activity
and tab loading process is complete and we are ready to handle
additional requests.

Adds new android-specific API to resume the requests and web contents
delegate API to allow the deferral for resuming renderer request
handling.

BUG=432562

Review URL: https://codereview.chromium.org/1095913002

Cr-Commit-Position: refs/heads/master@{#327414}
parent ef4a526c
...@@ -19,6 +19,9 @@ public class PendingDocumentData { ...@@ -19,6 +19,9 @@ public class PendingDocumentData {
/** Pending native web contents object to initialize with. */ /** Pending native web contents object to initialize with. */
public WebContents webContents; public WebContents webContents;
/** Whether renderer events have been paused for webContents. */
public boolean webContentsPaused;
/** The url to load in the current tab. */ /** The url to load in the current tab. */
public String url; public String url;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/android/jni_android.h" #include "base/android/jni_android.h"
#include "base/android/jni_string.h" #include "base/android/jni_string.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "chrome/browser/android/feature_utilities.h"
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/file_select_helper.h" #include "chrome/browser/file_select_helper.h"
#include "chrome/browser/media/media_capture_devices_dispatcher.h" #include "chrome/browser/media/media_capture_devices_dispatcher.h"
...@@ -305,6 +306,11 @@ WebContents* ChromeWebContentsDelegateAndroid::OpenURLFromTab( ...@@ -305,6 +306,11 @@ WebContents* ChromeWebContentsDelegateAndroid::OpenURLFromTab(
return WebContentsDelegateAndroid::OpenURLFromTab(source, params); return WebContentsDelegateAndroid::OpenURLFromTab(source, params);
} }
bool ChromeWebContentsDelegateAndroid::ShouldResumeRequestsForCreatedWindow() {
return chrome::android::GetDocumentModeValue() ==
chrome::android::RUNNING_MODE_TABBED_MODE;
}
void ChromeWebContentsDelegateAndroid::AddNewContents( void ChromeWebContentsDelegateAndroid::AddNewContents(
WebContents* source, WebContents* source,
WebContents* new_contents, WebContents* new_contents,
......
...@@ -69,6 +69,7 @@ class ChromeWebContentsDelegateAndroid ...@@ -69,6 +69,7 @@ class ChromeWebContentsDelegateAndroid
content::WebContents* OpenURLFromTab( content::WebContents* OpenURLFromTab(
content::WebContents* source, content::WebContents* source,
const content::OpenURLParams& params) override; const content::OpenURLParams& params) override;
bool ShouldResumeRequestsForCreatedWindow() override;
void AddNewContents(content::WebContents* source, void AddNewContents(content::WebContents* source,
content::WebContents* new_contents, content::WebContents* new_contents,
WindowOpenDisposition disposition, WindowOpenDisposition disposition,
......
...@@ -241,6 +241,11 @@ void WebContentsAndroid::ResumeResponseDeferredAtStart(JNIEnv* env, ...@@ -241,6 +241,11 @@ void WebContentsAndroid::ResumeResponseDeferredAtStart(JNIEnv* env,
static_cast<WebContentsImpl*>(web_contents_)->ResumeResponseDeferredAtStart(); static_cast<WebContentsImpl*>(web_contents_)->ResumeResponseDeferredAtStart();
} }
void WebContentsAndroid::ResumeLoadingCreatedWebContents(JNIEnv* env,
jobject obj) {
web_contents_->ResumeLoadingCreatedWebContents();
}
void WebContentsAndroid::SetHasPendingNavigationTransitionForTesting( void WebContentsAndroid::SetHasPendingNavigationTransitionForTesting(
JNIEnv* env, JNIEnv* env,
jobject obj) { jobject obj) {
......
...@@ -55,6 +55,7 @@ class CONTENT_EXPORT WebContentsAndroid ...@@ -55,6 +55,7 @@ class CONTENT_EXPORT WebContentsAndroid
jboolean IsIncognito(JNIEnv* env, jobject obj); jboolean IsIncognito(JNIEnv* env, jobject obj);
void ResumeResponseDeferredAtStart(JNIEnv* env, jobject obj); void ResumeResponseDeferredAtStart(JNIEnv* env, jobject obj);
void ResumeLoadingCreatedWebContents(JNIEnv* env, jobject obj);
void SetHasPendingNavigationTransitionForTesting(JNIEnv* env, jobject obj); void SetHasPendingNavigationTransitionForTesting(JNIEnv* env, jobject obj);
void SetupTransitionView(JNIEnv* env, jobject jobj, jstring markup); void SetupTransitionView(JNIEnv* env, jobject jobj, jstring markup);
void BeginExitTransition(JNIEnv* env, jobject jobj, jstring css_selector, void BeginExitTransition(JNIEnv* env, jobject jobj, jstring css_selector,
......
...@@ -1702,6 +1702,9 @@ void WebContentsImpl::ShowCreatedWindow(int route_id, ...@@ -1702,6 +1702,9 @@ void WebContentsImpl::ShowCreatedWindow(int route_id,
WebContentsImpl* contents = GetCreatedWindow(route_id); WebContentsImpl* contents = GetCreatedWindow(route_id);
if (contents) { if (contents) {
WebContentsDelegate* delegate = GetDelegate(); WebContentsDelegate* delegate = GetDelegate();
if (!delegate || delegate->ShouldResumeRequestsForCreatedWindow())
contents->ResumeLoadingCreatedWebContents();
if (delegate) { if (delegate) {
delegate->AddNewContents( delegate->AddNewContents(
this, contents, disposition, initial_rect, user_gesture, NULL); this, contents, disposition, initial_rect, user_gesture, NULL);
...@@ -1789,11 +1792,6 @@ WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) { ...@@ -1789,11 +1792,6 @@ WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) {
!new_contents->GetRenderViewHost()->GetView()) !new_contents->GetRenderViewHost()->GetView())
return NULL; return NULL;
// Resume blocked requests for both the RenderViewHost and RenderFrameHost.
// TODO(brettw): It seems bogus to reach into here and initialize the host.
new_contents->GetRenderViewHost()->Init();
new_contents->GetMainFrame()->Init();
return new_contents; return new_contents;
} }
...@@ -2540,6 +2538,13 @@ void WebContentsImpl::ExitFullscreen() { ...@@ -2540,6 +2538,13 @@ void WebContentsImpl::ExitFullscreen() {
ExitFullscreenMode(); ExitFullscreenMode();
} }
void WebContentsImpl::ResumeLoadingCreatedWebContents() {
// Resume blocked requests for both the RenderViewHost and RenderFrameHost.
// TODO(brettw): It seems bogus to reach into here and initialize the host.
GetRenderViewHost()->Init();
GetMainFrame()->Init();
}
bool WebContentsImpl::FocusLocationBarByDefault() { bool WebContentsImpl::FocusLocationBarByDefault() {
NavigationEntry* entry = controller_.GetVisibleEntry(); NavigationEntry* entry = controller_.GetVisibleEntry();
if (entry && entry->GetURL() == GURL(url::kAboutBlankURL)) if (entry && entry->GetURL() == GURL(url::kAboutBlankURL))
......
...@@ -358,6 +358,7 @@ class CONTENT_EXPORT WebContentsImpl ...@@ -358,6 +358,7 @@ class CONTENT_EXPORT WebContentsImpl
bool WasRecentlyAudible() override; bool WasRecentlyAudible() override;
void GetManifest(const GetManifestCallback&) override; void GetManifest(const GetManifestCallback&) override;
void ExitFullscreen() override; void ExitFullscreen() override;
void ResumeLoadingCreatedWebContents() override;
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
base::android::ScopedJavaLocalRef<jobject> GetJavaWebContents() override; base::android::ScopedJavaLocalRef<jobject> GetJavaWebContents() override;
virtual WebContentsAndroid* GetWebContentsAndroid(); virtual WebContentsAndroid* GetWebContentsAndroid();
......
...@@ -192,6 +192,11 @@ import org.chromium.content_public.browser.WebContentsObserver; ...@@ -192,6 +192,11 @@ import org.chromium.content_public.browser.WebContentsObserver;
nativeResumeResponseDeferredAtStart(mNativeWebContentsAndroid); nativeResumeResponseDeferredAtStart(mNativeWebContentsAndroid);
} }
@Override
public void resumeLoadingCreatedWebContents() {
nativeResumeLoadingCreatedWebContents(mNativeWebContentsAndroid);
}
@Override @Override
public void setHasPendingNavigationTransitionForTesting() { public void setHasPendingNavigationTransitionForTesting() {
nativeSetHasPendingNavigationTransitionForTesting(mNativeWebContentsAndroid); nativeSetHasPendingNavigationTransitionForTesting(mNativeWebContentsAndroid);
...@@ -398,6 +403,7 @@ import org.chromium.content_public.browser.WebContentsObserver; ...@@ -398,6 +403,7 @@ import org.chromium.content_public.browser.WebContentsObserver;
private native String nativeGetLastCommittedURL(long nativeWebContentsAndroid); private native String nativeGetLastCommittedURL(long nativeWebContentsAndroid);
private native boolean nativeIsIncognito(long nativeWebContentsAndroid); private native boolean nativeIsIncognito(long nativeWebContentsAndroid);
private native void nativeResumeResponseDeferredAtStart(long nativeWebContentsAndroid); private native void nativeResumeResponseDeferredAtStart(long nativeWebContentsAndroid);
private native void nativeResumeLoadingCreatedWebContents(long nativeWebContentsAndroid);
private native void nativeSetHasPendingNavigationTransitionForTesting( private native void nativeSetHasPendingNavigationTransitionForTesting(
long nativeWebContentsAndroid); long nativeWebContentsAndroid);
private native void nativeSetupTransitionView(long nativeWebContentsAndroid, private native void nativeSetupTransitionView(long nativeWebContentsAndroid,
......
...@@ -158,6 +158,11 @@ public interface WebContents { ...@@ -158,6 +158,11 @@ public interface WebContents {
*/ */
public void resumeResponseDeferredAtStart(); public void resumeResponseDeferredAtStart();
/**
* Resumes the requests for a newly created window.
*/
public void resumeLoadingCreatedWebContents();
/** /**
* Set pending Navigation for transition testing on this WebContents. * Set pending Navigation for transition testing on this WebContents.
*/ */
......
...@@ -628,6 +628,13 @@ class WebContents : public PageNavigator, ...@@ -628,6 +628,13 @@ class WebContents : public PageNavigator,
// Requests the renderer to exit fullscreen. // Requests the renderer to exit fullscreen.
virtual void ExitFullscreen() = 0; virtual void ExitFullscreen() = 0;
// Unblocks requests from renderer for a newly created window. This is
// used in showCreatedWindow() or sometimes later in cases where
// delegate->ShouldResumeRequestsForCreatedWindow() indicated the requests
// should not yet be resumed. Then the client is responsible for calling this
// as soon as they are ready.
virtual void ResumeLoadingCreatedWebContents() = 0;
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
CONTENT_EXPORT static WebContents* FromJavaWebContents( CONTENT_EXPORT static WebContents* FromJavaWebContents(
jobject jweb_contents_android); jobject jweb_contents_android);
......
...@@ -63,6 +63,10 @@ bool WebContentsDelegate::ShouldFocusPageAfterCrash() { ...@@ -63,6 +63,10 @@ bool WebContentsDelegate::ShouldFocusPageAfterCrash() {
return true; return true;
} }
bool WebContentsDelegate::ShouldResumeRequestsForCreatedWindow() {
return true;
}
bool WebContentsDelegate::TakeFocus(WebContents* source, bool reverse) { bool WebContentsDelegate::TakeFocus(WebContents* source, bool reverse) {
return false; return false;
} }
......
...@@ -215,6 +215,11 @@ class CONTENT_EXPORT WebContentsDelegate { ...@@ -215,6 +215,11 @@ class CONTENT_EXPORT WebContentsDelegate {
// to live. Default is true. // to live. Default is true.
virtual bool ShouldFocusPageAfterCrash(); virtual bool ShouldFocusPageAfterCrash();
// Returns whether the page should resume accepting requests for the new
// window. This is used when window creation is asynchronous
// and the navigations need to be delayed. Default is true.
virtual bool ShouldResumeRequestsForCreatedWindow();
// This is called when WebKit tells us that it is done tabbing through // This is called when WebKit tells us that it is done tabbing through
// controls on the page. Provides a way for WebContentsDelegates to handle // controls on the page. Provides a way for WebContentsDelegates to handle
// this. Returns true if the delegate successfully handled it. // this. Returns true if the delegate successfully handled it.
......
...@@ -656,6 +656,10 @@ void GuestViewBase::UpdateTargetURL(content::WebContents* source, ...@@ -656,6 +656,10 @@ void GuestViewBase::UpdateTargetURL(content::WebContents* source,
embedder_web_contents(), url); embedder_web_contents(), url);
} }
bool GuestViewBase::ShouldResumeRequestsForCreatedWindow() {
return false;
}
GuestViewBase::~GuestViewBase() { GuestViewBase::~GuestViewBase() {
} }
......
...@@ -344,6 +344,7 @@ class GuestViewBase : public content::BrowserPluginGuestDelegate, ...@@ -344,6 +344,7 @@ class GuestViewBase : public content::BrowserPluginGuestDelegate,
void UpdatePreferredSize(content::WebContents* web_contents, void UpdatePreferredSize(content::WebContents* web_contents,
const gfx::Size& pref_size) final; const gfx::Size& pref_size) final;
void UpdateTargetURL(content::WebContents* source, const GURL& url) override; void UpdateTargetURL(content::WebContents* source, const GURL& url) override;
bool ShouldResumeRequestsForCreatedWindow() override;
void SetGuestZoomLevelToMatchEmbedder(); void SetGuestZoomLevelToMatchEmbedder();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment