browser(webkit): make popups functional in mac embedder (#689)

This commit is contained in:
Dmitry Gozman 2020-01-27 15:41:01 -08:00 committed by Pavel Feldman
parent ee9c2b0c41
commit aa2ecde20f
2 changed files with 22 additions and 28 deletions

View file

@ -1 +1 @@
1116 1117

View file

@ -13089,10 +13089,10 @@ index 0000000000000000000000000000000000000000..41b5751cab626971cd12c5066218c6d1
+@end +@end
diff --git a/Tools/Playwright/mac/AppDelegate.m b/Tools/Playwright/mac/AppDelegate.m diff --git a/Tools/Playwright/mac/AppDelegate.m b/Tools/Playwright/mac/AppDelegate.m
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..84e0cd9c2d20111e936e4b16519d20bcd5aa37db index 0000000000000000000000000000000000000000..828d172381e12ea0455045fdc098dfa7726ae040
--- /dev/null --- /dev/null
+++ b/Tools/Playwright/mac/AppDelegate.m +++ b/Tools/Playwright/mac/AppDelegate.m
@@ -0,0 +1,486 @@ @@ -0,0 +1,488 @@
+/* +/*
+ * Copyright (C) 2010-2016 Apple Inc. All rights reserved. + * Copyright (C) 2010-2016 Apple Inc. All rights reserved.
+ * + *
@ -13453,7 +13453,7 @@ index 0000000000000000000000000000000000000000..84e0cd9c2d20111e936e4b16519d20bc
+ return [controller webView]; + return [controller webView];
+} +}
+ +
+- (WKWebView *)createHeadlessWebView:(WKWebViewConfiguration *)configuration +- (WKWebView *)createHeadlessWebView:(WKWebViewConfiguration *)configuration forPopup:(BOOL)popup
+{ +{
+ NSRect rect = NSMakeRect(0, 0, 1024, 768); + NSRect rect = NSMakeRect(0, 0, 1024, 768);
+ NSScreen *firstScreen = [[NSScreen screens] objectAtIndex:0]; + NSScreen *firstScreen = [[NSScreen screens] objectAtIndex:0];
@ -13467,9 +13467,11 @@ index 0000000000000000000000000000000000000000..84e0cd9c2d20111e936e4b16519d20bc
+ +
+ webView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable; + webView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
+ [window.contentView addSubview:webView]; + [window.contentView addSubview:webView];
+ NSURL *url = [NSURL _webkit_URLWithUserTypedString:_initialURL ? _initialURL : @"about:blank"]; + if (!popup) {
+ _initialURL = nil; + NSURL *url = [NSURL _webkit_URLWithUserTypedString:_initialURL ? _initialURL : @"about:blank"];
+ [webView loadRequest:[NSURLRequest requestWithURL:url]]; + _initialURL = nil;
+ [webView loadRequest:[NSURLRequest requestWithURL:url]];
+ }
+ [_headlessWindows addObject:window]; + [_headlessWindows addObject:window];
+ webView.UIDelegate = self; + webView.UIDelegate = self;
+ return [webView autorelease]; + return [webView autorelease];
@ -13478,7 +13480,7 @@ index 0000000000000000000000000000000000000000..84e0cd9c2d20111e936e4b16519d20bc
+- (WKWebView *)createHeadlessPage:(uint64_t)sessionID +- (WKWebView *)createHeadlessPage:(uint64_t)sessionID
+{ +{
+ WKWebViewConfiguration *configuration = [self sessionConfiguration:sessionID]; + WKWebViewConfiguration *configuration = [self sessionConfiguration:sessionID];
+ return [self createHeadlessWebView:configuration]; + return [self createHeadlessWebView:configuration forPopup:NO];
+} +}
+ +
+- (_WKBrowserContext *)createBrowserContext +- (_WKBrowserContext *)createBrowserContext
@ -13575,7 +13577,7 @@ index 0000000000000000000000000000000000000000..84e0cd9c2d20111e936e4b16519d20bc
+ +
+- (nullable WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures +- (nullable WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures
+{ +{
+ return [self createHeadlessWebView:configuration]; + return [self createHeadlessWebView:configuration forPopup:YES];
+} +}
+ +
+@end +@end
@ -13792,10 +13794,10 @@ index 0000000000000000000000000000000000000000..4dbf13c8fb31a745ae8e1965a457d4fb
+@end +@end
diff --git a/Tools/Playwright/mac/BrowserWindowController.m b/Tools/Playwright/mac/BrowserWindowController.m diff --git a/Tools/Playwright/mac/BrowserWindowController.m b/Tools/Playwright/mac/BrowserWindowController.m
new file mode 100644 new file mode 100644
index 0000000000000000000000000000000000000000..7a745879d076017df30afd77ded881ddbc19bb45 index 0000000000000000000000000000000000000000..033c4fcda83002cda5d069205d4f605d02f1e1f5
--- /dev/null --- /dev/null
+++ b/Tools/Playwright/mac/BrowserWindowController.m +++ b/Tools/Playwright/mac/BrowserWindowController.m
@@ -0,0 +1,834 @@ @@ -0,0 +1,826 @@
+/* +/*
+ * Copyright (C) 2010-2016 Apple Inc. All rights reserved. + * Copyright (C) 2010-2016 Apple Inc. All rights reserved.
+ * + *
@ -13946,8 +13948,6 @@ index 0000000000000000000000000000000000000000..7a745879d076017df30afd77ded881dd
+ +
+- (void)awakeFromNib +- (void)awakeFromNib
+{ +{
+ self.window.styleMask &= ~NSWindowStyleMaskFullSizeContentView;
+
+ _webView = [[WKWebView alloc] initWithFrame:[containerView bounds] configuration:_configuration]; + _webView = [[WKWebView alloc] initWithFrame:[containerView bounds] configuration:_configuration];
+ _webView._windowOcclusionDetectionEnabled = NO; + _webView._windowOcclusionDetectionEnabled = NO;
+ +
@ -13994,13 +13994,14 @@ index 0000000000000000000000000000000000000000..7a745879d076017df30afd77ded881dd
+ return nil; + return nil;
+ _configuration = [configuration copy]; + _configuration = [configuration copy];
+ _isPrivateBrowsingWindow = !_configuration.websiteDataStore.isPersistent; + _isPrivateBrowsingWindow = !_configuration.websiteDataStore.isPersistent;
+ self.window.styleMask &= ~NSWindowStyleMaskFullSizeContentView;
+ return self; + return self;
+} +}
+ +
+- (void)dealloc +- (void)dealloc
+{ +{
+ [[NSNotificationCenter defaultCenter] removeObserver:self]; + [[NSNotificationCenter defaultCenter] removeObserver:self];
+ +
+ [progressIndicator unbind:NSHiddenBinding]; + [progressIndicator unbind:NSHiddenBinding];
+ [progressIndicator unbind:NSValueBinding]; + [progressIndicator unbind:NSValueBinding];
+ +
@ -14079,7 +14080,7 @@ index 0000000000000000000000000000000000000000..7a745879d076017df30afd77ded881dd
+ return [self canZoomOut]; + return [self canZoomOut];
+ if (action == @selector(resetZoom:)) + if (action == @selector(resetZoom:))
+ return [self canResetZoom]; + return [self canResetZoom];
+ +
+ if (action == @selector(toggleZoomMode:)) + if (action == @selector(toggleZoomMode:))
+ [menuItem setState:_zoomTextOnly ? NSControlStateValueOn : NSControlStateValueOff]; + [menuItem setState:_zoomTextOnly ? NSControlStateValueOn : NSControlStateValueOff];
+ else if (action == @selector(showHideWebInspector:)) + else if (action == @selector(showHideWebInspector:))
@ -14258,7 +14259,6 @@ index 0000000000000000000000000000000000000000..7a745879d076017df30afd77ded881dd
+- (nullable WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures +- (nullable WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures
+{ +{
+ BrowserWindowController *controller = [[BrowserWindowController alloc] initWithConfiguration:configuration]; + BrowserWindowController *controller = [[BrowserWindowController alloc] initWithConfiguration:configuration];
+ [controller awakeFromNib];
+ [controller.window makeKeyAndOrderFront:self]; + [controller.window makeKeyAndOrderFront:self];
+ +
+ return controller->_webView; + return controller->_webView;
@ -14286,7 +14286,7 @@ index 0000000000000000000000000000000000000000..7a745879d076017df30afd77ded881dd
+ +
+ [alert setMessageText:[NSString stringWithFormat:@"JavaScript confirm dialog from %@.", [frame.request.URL absoluteString]]]; + [alert setMessageText:[NSString stringWithFormat:@"JavaScript confirm dialog from %@.", [frame.request.URL absoluteString]]];
+ [alert setInformativeText:message]; + [alert setInformativeText:message];
+ +
+ [alert addButtonWithTitle:@"OK"]; + [alert addButtonWithTitle:@"OK"];
+ [alert addButtonWithTitle:@"Cancel"]; + [alert addButtonWithTitle:@"Cancel"];
+ +
@ -14304,14 +14304,14 @@ index 0000000000000000000000000000000000000000..7a745879d076017df30afd77ded881dd
+ +
+ [alert setMessageText:[NSString stringWithFormat:@"JavaScript prompt dialog from %@.", [frame.request.URL absoluteString]]]; + [alert setMessageText:[NSString stringWithFormat:@"JavaScript prompt dialog from %@.", [frame.request.URL absoluteString]]];
+ [alert setInformativeText:prompt]; + [alert setInformativeText:prompt];
+ +
+ [alert addButtonWithTitle:@"OK"]; + [alert addButtonWithTitle:@"OK"];
+ [alert addButtonWithTitle:@"Cancel"]; + [alert addButtonWithTitle:@"Cancel"];
+ +
+ NSTextField* input = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 200, 24)]; + NSTextField* input = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 200, 24)];
+ [input setStringValue:defaultText]; + [input setStringValue:defaultText];
+ [alert setAccessoryView:input]; + [alert setAccessoryView:input];
+ +
+ _alert = alert; + _alert = alert;
+ [alert beginSheetModalForWindow:self.window completionHandler:^void (NSModalResponse response) { + [alert beginSheetModalForWindow:self.window completionHandler:^void (NSModalResponse response) {
+ [input validateEditing]; + [input validateEditing];
@ -14438,12 +14438,6 @@ index 0000000000000000000000000000000000000000..7a745879d076017df30afd77ded881dd
+ decisionHandler(WKNavigationActionPolicyAllow); + decisionHandler(WKNavigationActionPolicyAllow);
+ return; + return;
+ } + }
+
+ if (navigationAction._userInitiatedAction && !navigationAction._userInitiatedAction.isConsumed) {
+ [navigationAction._userInitiatedAction consume];
+ [[NSWorkspace sharedWorkspace] openURL:navigationAction.request.URL];
+ }
+
+ decisionHandler(WKNavigationActionPolicyCancel); + decisionHandler(WKNavigationActionPolicyCancel);
+} +}
+ +
@ -14487,7 +14481,7 @@ index 0000000000000000000000000000000000000000..7a745879d076017df30afd77ded881dd
+ NSView *container = [[[NSView alloc] initWithFrame:NSMakeRect(0, 0, 200, 48)] autorelease]; + NSView *container = [[[NSView alloc] initWithFrame:NSMakeRect(0, 0, 200, 48)] autorelease];
+ NSTextField *userInput = [[[NSTextField alloc] initWithFrame:NSMakeRect(0, 24, 200, 24)] autorelease]; + NSTextField *userInput = [[[NSTextField alloc] initWithFrame:NSMakeRect(0, 24, 200, 24)] autorelease];
+ NSTextField *passwordInput = [[[NSSecureTextField alloc] initWithFrame:NSMakeRect(0, 0, 200, 24)] autorelease]; + NSTextField *passwordInput = [[[NSSecureTextField alloc] initWithFrame:NSMakeRect(0, 0, 200, 24)] autorelease];
+ +
+ [alert setMessageText:[NSString stringWithFormat:@"Log in to %@:%lu.", challenge.protectionSpace.host, challenge.protectionSpace.port]]; + [alert setMessageText:[NSString stringWithFormat:@"Log in to %@:%lu.", challenge.protectionSpace.host, challenge.protectionSpace.port]];
+ [alert addButtonWithTitle:@"Log in"]; + [alert addButtonWithTitle:@"Log in"];
+ [alert addButtonWithTitle:@"Cancel"]; + [alert addButtonWithTitle:@"Cancel"];
@ -14496,7 +14490,7 @@ index 0000000000000000000000000000000000000000..7a745879d076017df30afd77ded881dd
+ [alert setAccessoryView:container]; + [alert setAccessoryView:container];
+ [userInput setNextKeyView:passwordInput]; + [userInput setNextKeyView:passwordInput];
+ [alert.window setInitialFirstResponder:userInput]; + [alert.window setInitialFirstResponder:userInput];
+ +
+ [alert beginSheetModalForWindow:self.window completionHandler:^(NSModalResponse response) { + [alert beginSheetModalForWindow:self.window completionHandler:^(NSModalResponse response) {
+ [userInput validateEditing]; + [userInput validateEditing];
+ if (response == NSAlertFirstButtonReturn) + if (response == NSAlertFirstButtonReturn)