Commit e525a289 authored by garzonou's avatar garzonou Committed by Commit Bot

Fix the crash of window.open() in ChromeWebView.

When window.open() is called, we need to use the exact WKWebViewConfiguration provided by WebKit's delegate method in crw_wk_ui_handler to initialize the WKWebView inside CWVWebView.

This CL makes the WKWebView inside CWVWebView to be initialized lazily.

Bug: 1054276
Change-Id: I5e26c393bbaa667b43b43ba5f78a24b2cacaaede
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2061984
Commit-Queue: Jiajun Ou <garzonou@google.com>
Reviewed-by: default avatarHiroshi Ichikawa <ichikawa@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744924}
parent 95ba7404
......@@ -743,12 +743,21 @@ BOOL gChromeLongPressAndForceTouchHandlingEnabled = YES;
// |web::EnsureWebViewCreatedWithConfiguration()|, as this is the requirement
// of |web::EnsureWebViewCreatedWithConfiguration()|
// Creates a WKWebView immediately to assure the class property
// |chromeLongPressAndForceTouchHandlingEnabled| is consumed when a
// CWVWebView is initializing instead of some time later. Then
// "longPressActionsEnabled" will be set in WKWebViewConfigurationProvider.
WKWebView* webView = web::EnsureWebViewCreatedWithConfiguration(
_webState.get(), wkConfiguration);
WKWebView* webView = nil;
if (wkConfiguration) {
// When |wkConfiguration| is nil, |self| could be a newly opened web view
// e.g., triggered by JavaScript "window.open()" function. In that case, if
// |self| is not created by the WKWebViewConfiguration provided by WebKit's
// delegate method
// (https://cs.chromium.org/chromium/src/ios/web/web_state/ui/crw_wk_ui_handler.mm?q=crw_wk_ui_handler&sq=package:chromium&dr=C&l=61)
// then calling |web::EnsureWebViewCreatedWithConfiguration()| here would
// result in a crash (https://crbug.com/1054276). Now, we lazily create the
// WKWebView inside |_webState| when |wkConfiguration| is not nil, and the
// correct WKWebViewConfiguration will be passed inside //ios/web.
webView = web::EnsureWebViewCreatedWithConfiguration(_webState.get(),
wkConfiguration);
}
if (createdWebView) {
// If the created webView is needed, returns it by the out variable way.
*createdWebView = webView;
......
......@@ -121,8 +121,9 @@ CWV_EXPORT
@property(nonatomic, readonly, nonnull) CWVBackForwardList* backForwardList;
// Enables Chrome's custom logic to handle long press and force touch. Defaults
// to YES. This CLASS PROPERTY setting will only be applied to all CWVWebView
// instances INITIALIZED AFTERWARD.
// to YES. To use the system context menu this must be set to NO.
// This class property setting should only be changed BEFORE any
// CWVWebViewConfiguration instance is initialized.
@property(nonatomic, class) BOOL chromeLongPressAndForceTouchHandlingEnabled;
// The User Agent product string used to build the full User Agent.
......
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