Skip to content

Commit 2313ceb

Browse files
authored
browser(webkit): fix leaking popup windows (#1908)
1 parent c474c54 commit 2313ceb

File tree

2 files changed

+16
-53
lines changed

2 files changed

+16
-53
lines changed

browser_patches/webkit/BUILD_NUMBER

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1203
1+
1204

browser_patches/webkit/patches/bootstrap.diff

Lines changed: 15 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -14390,10 +14390,10 @@ index 0000000000000000000000000000000000000000..00fb6b0006c743091a8bbf8edb18b211
1439014390
+</Scheme>
1439114391
diff --git a/Tools/Playwright/mac/AppDelegate.h b/Tools/Playwright/mac/AppDelegate.h
1439214392
new file mode 100644
14393-
index 0000000000000000000000000000000000000000..ff88daf2035365d0f1d19c5adc47b467c7d4e980
14393+
index 0000000000000000000000000000000000000000..ccc73af47f7bdb4813a9a1e6fb8d55d5d837c8d7
1439414394
--- /dev/null
1439514395
+++ b/Tools/Playwright/mac/AppDelegate.h
14396-
@@ -0,0 +1,54 @@
14396+
@@ -0,0 +1,51 @@
1439714397
+/*
1439814398
+ * Copyright (C) 2010 Apple Inc. All rights reserved.
1439914399
+ *
@@ -14428,7 +14428,6 @@ index 0000000000000000000000000000000000000000..ff88daf2035365d0f1d19c5adc47b467
1442814428
+@end
1442914429
+
1443014430
+@interface BrowserAppDelegate : NSObject <NSApplicationDelegate, WKNavigationDelegate, WKUIDelegate, _WKBrowserInspectorDelegate, _WKDownloadDelegate> {
14431-
+ NSMutableSet *_browserWindowControllers;
1443214431
+ NSMutableSet *_headlessWindows;
1443314432
+ NSMutableSet *_browserContexts;
1443414433
+ bool _headless;
@@ -14439,8 +14438,6 @@ index 0000000000000000000000000000000000000000..ff88daf2035365d0f1d19c5adc47b467
1443914438
+ IBOutlet NSMenuItem *_newWebKit2WindowItem;
1444014439
+}
1444114440
+
14442-
+- (void)browserWindowWillClose:(NSWindow *)window;
14443-
+
1444414441
+@end
1444514442
+
1444614443
+@interface NSApplication (PlaywrightApplicationExtensions)
@@ -14450,10 +14447,10 @@ index 0000000000000000000000000000000000000000..ff88daf2035365d0f1d19c5adc47b467
1445014447
+@end
1445114448
diff --git a/Tools/Playwright/mac/AppDelegate.m b/Tools/Playwright/mac/AppDelegate.m
1445214449
new file mode 100644
14453-
index 0000000000000000000000000000000000000000..6eb18b8f492fe3937d2c38b36b4daebbe2199586
14450+
index 0000000000000000000000000000000000000000..d46e0dbe9677760b63de22b837a08404a8042dd2
1445414451
--- /dev/null
1445514452
+++ b/Tools/Playwright/mac/AppDelegate.m
14456-
@@ -0,0 +1,440 @@
14453+
@@ -0,0 +1,405 @@
1445714454
+/*
1445814455
+ * Copyright (C) 2010-2016 Apple Inc. All rights reserved.
1445914456
+ *
@@ -14539,6 +14536,7 @@ index 0000000000000000000000000000000000000000..6eb18b8f492fe3937d2c38b36b4daebb
1453914536
+- (id)init
1454014537
+{
1454114538
+ self = [super init];
14539+
+
1454214540
+ if (!self)
1454314541
+ return nil;
1454414542
+
@@ -14569,7 +14567,6 @@ index 0000000000000000000000000000000000000000..6eb18b8f492fe3937d2c38b36b4daebb
1456914567
+ _dialogs = [[NSMutableSet alloc] init];
1457014568
+ } else {
1457114569
+ [NSApp activateIgnoringOtherApps:YES];
14572-
+ _browserWindowControllers = [[NSMutableSet alloc] init];
1457314570
+ }
1457414571
+ if ([arguments containsObject: @"--inspector-pipe"])
1457514572
+ [_WKBrowserInspector initializeRemoteInspectorPipe:self headless:_headless];
@@ -14651,23 +14648,6 @@ index 0000000000000000000000000000000000000000..6eb18b8f492fe3937d2c38b36b4daebb
1465114648
+ return configuration;
1465214649
+}
1465314650
+
14654-
+- (BrowserWindowController *)createBrowserWindowController:(id)sender
14655-
+{
14656-
+ if (_headless)
14657-
+ return nil;
14658-
+
14659-
+ BrowserWindowController *controller = [[[BrowserWindowController alloc] initWithConfiguration:[self defaultConfiguration]] autorelease];
14660-
+ if (!controller)
14661-
+ return nil;
14662-
+ [_browserWindowControllers addObject:controller];
14663-
+ return controller;
14664-
+}
14665-
+
14666-
+- (void)browserWindowWillClose:(NSWindow *)window
14667-
+{
14668-
+ [_browserWindowControllers removeObject:window.windowController];
14669-
+}
14670-
+
1467114651
+- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
1467214652
+{
1467314653
+ if (!_headless)
@@ -14680,22 +14660,6 @@ index 0000000000000000000000000000000000000000..6eb18b8f492fe3937d2c38b36b4daebb
1468014660
+ _initialURL = nil;
1468114661
+}
1468214662
+
14683-
+- (BrowserWindowController *)frontmostBrowserWindowController
14684-
+{
14685-
+ for (NSWindow* window in [NSApp windows]) {
14686-
+ id delegate = [window delegate];
14687-
+
14688-
+ if (![delegate isKindOfClass:[BrowserWindowController class]])
14689-
+ continue;
14690-
+
14691-
+ BrowserWindowController *controller = (BrowserWindowController *)delegate;
14692-
+ assert([_browserWindowControllers containsObject:controller]);
14693-
+ return controller;
14694-
+ }
14695-
+
14696-
+ return nil;
14697-
+}
14698-
+
1469914663
+- (void)_updateNewWindowKeyEquivalents
1470014664
+{
1470114665
+ NSString *normalWindowEquivalent = @"n";
@@ -14729,19 +14693,17 @@ index 0000000000000000000000000000000000000000..6eb18b8f492fe3937d2c38b36b4daebb
1472914693
+
1473014694
+- (WKWebView *)createHeadfulPage:(WKWebViewConfiguration *)configuration withURL:(NSString*)urlString
1473114695
+{
14732-
+
14733-
+ BrowserWindowController *controller = [[[BrowserWindowController alloc] initWithConfiguration:configuration] autorelease];
14696+
+ // WebView lifecycle will control the BrowserWindowController life times.
14697+
+ BrowserWindowController *controller = [[BrowserWindowController alloc] initWithConfiguration:configuration];
1473414698
+ if (!controller)
1473514699
+ return nil;
14736-
+ [[controller window] makeKeyAndOrderFront:nil];
14737-
+ [_browserWindowControllers addObject:controller];
1473814700
+ [controller loadURLString:urlString];
1473914701
+ return [controller webView];
1474014702
+}
1474114703
+
1474214704
+- (WKWebView *)createHeadlessPage:(WKWebViewConfiguration *)configuration withURL:(NSString*)urlString
1474314705
+{
14744-
+ NSRect rect = NSMakeRect(0, 0, 1024, 768);
14706+
+ NSRect rect = NSMakeRect(0, 0, 1280, 720);
1474514707
+ NSScreen *firstScreen = [[NSScreen screens] objectAtIndex:0];
1474614708
+ NSRect windowRect = NSOffsetRect(rect, -10000, [firstScreen frame].size.height - rect.size.height + 10000);
1474714709
+ NSWindow* window = [[NSWindow alloc] initWithContentRect:windowRect styleMask:NSWindowStyleMaskBorderless backing:(NSBackingStoreType)_NSBackingStoreUnbuffered defer:YES];
@@ -15107,10 +15069,10 @@ index 0000000000000000000000000000000000000000..4dbf13c8fb31a745ae8e1965a457d4fb
1510715069
+@end
1510815070
diff --git a/Tools/Playwright/mac/BrowserWindowController.m b/Tools/Playwright/mac/BrowserWindowController.m
1510915071
new file mode 100644
15110-
index 0000000000000000000000000000000000000000..8d4cf055b4e93f2990801cfbddc20182534ce594
15072+
index 0000000000000000000000000000000000000000..c48697f7cfd699e3da720be6d9e4d0db90726984
1511115073
--- /dev/null
1511215074
+++ b/Tools/Playwright/mac/BrowserWindowController.m
15113-
@@ -0,0 +1,838 @@
15075+
@@ -0,0 +1,839 @@
1511415076
+/*
1511515077
+ * Copyright (C) 2010-2016 Apple Inc. All rights reserved.
1511615078
+ *
@@ -15308,6 +15270,7 @@ index 0000000000000000000000000000000000000000..8d4cf055b4e93f2990801cfbddc20182
1530815270
+ _configuration = [configuration copy];
1530915271
+ _isPrivateBrowsingWindow = !_configuration.websiteDataStore.isPersistent;
1531015272
+ self.window.styleMask &= ~NSWindowStyleMaskFullSizeContentView;
15273+
+ [self.window makeKeyAndOrderFront:nil];
1531115274
+ return self;
1531215275
+}
1531315276
+
@@ -15495,10 +15458,11 @@ index 0000000000000000000000000000000000000000..8d4cf055b4e93f2990801cfbddc20182
1549515458
+
1549615459
+- (void)windowWillClose:(NSNotification *)notification
1549715460
+{
15498-
+ [[[NSApplication sharedApplication] browserAppDelegate] browserWindowWillClose:self.window];
1549915461
+ [_webView removeObserver:self forKeyPath:@"title"];
1550015462
+ [_webView removeObserver:self forKeyPath:@"URL"];
15501-
+ [self autorelease];
15463+
+ [_webView removeFromSuperview];
15464+
+ _textFinder.hideInterfaceCallback = nil;
15465+
+ [self release];
1550215466
+}
1550315467
+
1550415468
+- (void)webViewDidClose:(WKWebView *)webView {
@@ -15571,9 +15535,8 @@ index 0000000000000000000000000000000000000000..8d4cf055b4e93f2990801cfbddc20182
1557115535
+
1557215536
+- (nullable WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures
1557315537
+{
15538+
+ // WebView lifecycle will control the BrowserWindowController life times.
1557415539
+ BrowserWindowController *controller = [[BrowserWindowController alloc] initWithConfiguration:configuration];
15575-
+ [controller.window makeKeyAndOrderFront:self];
15576-
+
1557715540
+ return controller->_webView;
1557815541
+}
1557915542
+

0 commit comments

Comments
 (0)