Title: [125113] trunk/Tools
Revision
125113
Author
[email protected]
Date
2012-08-08 16:47:42 -0700 (Wed, 08 Aug 2012)

Log Message

        [WK2] MiniBrowser crashes on quit if any windows were previously closed
        https://bugs.webkit.org/show_bug.cgi?id=93529

        Reviewed by John Sullivan.

        * MiniBrowser/mac/AppDelegate.h:
        * MiniBrowser/mac/AppDelegate.m:
        (-[BrowserAppDelegate init]):
        (-[BrowserAppDelegate newWindow:]):
        (-[BrowserAppDelegate browserWindowWillClose:]):
        (-[BrowserAppDelegate applicationWillTerminate:]):
        (-[BrowserAppDelegate frontmostBrowserWindowController]):
        Track browser windows explicitly, not relying on [NSApp windows]. Closed windows
        are not automatically removed from the list until deallocated, so a refcounting
        error can result in working on a closed window.

        * MiniBrowser/mac/BrowserWindowController.m:
        (-[BrowserWindowController dealloc]): Moved code from -windowWillClose: here.
        Releasing data members is -dealloc's job.
        (-[BrowserWindowController windowWillClose:]): Notify BrowserAppDelegate that
        the window is no longer open. Autorelease self, making sure that WKView and
        then WebPageProxy get released.
        (-[BrowserWindowController applicationTerminating]): Don't release _webView.pageRef.
        WKView is responsible for its lifetime.
        (closePage): Ditto.

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (125112 => 125113)


--- trunk/Tools/ChangeLog	2012-08-08 23:42:15 UTC (rev 125112)
+++ trunk/Tools/ChangeLog	2012-08-08 23:47:42 UTC (rev 125113)
@@ -1,3 +1,31 @@
+2012-08-08  Alexey Proskuryakov  <[email protected]>
+
+        [WK2] MiniBrowser crashes on quit if any windows were previously closed
+        https://bugs.webkit.org/show_bug.cgi?id=93529
+
+        Reviewed by John Sullivan.
+
+        * MiniBrowser/mac/AppDelegate.h:
+        * MiniBrowser/mac/AppDelegate.m:
+        (-[BrowserAppDelegate init]):
+        (-[BrowserAppDelegate newWindow:]):
+        (-[BrowserAppDelegate browserWindowWillClose:]):
+        (-[BrowserAppDelegate applicationWillTerminate:]):
+        (-[BrowserAppDelegate frontmostBrowserWindowController]):
+        Track browser windows explicitly, not relying on [NSApp windows]. Closed windows
+        are not automatically removed from the list until deallocated, so a refcounting
+        error can result in working on a closed window.
+
+        * MiniBrowser/mac/BrowserWindowController.m:
+        (-[BrowserWindowController dealloc]): Moved code from -windowWillClose: here.
+        Releasing data members is -dealloc's job.
+        (-[BrowserWindowController windowWillClose:]): Notify BrowserAppDelegate that
+        the window is no longer open. Autorelease self, making sure that WKView and
+        then WebPageProxy get released.
+        (-[BrowserWindowController applicationTerminating]): Don't release _webView.pageRef.
+        WKView is responsible for its lifetime.
+        (closePage): Ditto.
+
 2012-08-08  Xianzhu Wang  <[email protected]>
 
         [Chromium-Android] Apply all Linux layout test expectations

Modified: trunk/Tools/MiniBrowser/mac/AppDelegate.h (125112 => 125113)


--- trunk/Tools/MiniBrowser/mac/AppDelegate.h	2012-08-08 23:42:15 UTC (rev 125112)
+++ trunk/Tools/MiniBrowser/mac/AppDelegate.h	2012-08-08 23:47:42 UTC (rev 125113)
@@ -34,10 +34,13 @@
     WKContextRef _threadContext;
     WKContextRef _processContext;
     WKPageGroupRef _pageGroup;
+    NSMutableSet *_browserWindows;
 }
 
 - (WKContextRef)getCurrentContext;
 
+- (void)browserWindowWillClose:(NSWindow *)window;
+
 - (IBAction)setSharedProcessProcessModel:(id)sender;
 - (IBAction)setSharedThreadProcessModel:(id)sender;
 - (IBAction)showStatisticsWindow:(id)sender;

Modified: trunk/Tools/MiniBrowser/mac/AppDelegate.m (125112 => 125113)


--- trunk/Tools/MiniBrowser/mac/AppDelegate.m	2012-08-08 23:42:15 UTC (rev 125112)
+++ trunk/Tools/MiniBrowser/mac/AppDelegate.m	2012-08-08 23:47:42 UTC (rev 125113)
@@ -153,6 +153,8 @@
         WKStringRef pageGroupIdentifier = WKStringCreateWithCFString(CFSTR("MiniBrowser"));
         _pageGroup = WKPageGroupCreateWithIdentifier(pageGroupIdentifier);
         WKRelease(pageGroupIdentifier);
+
+        _browserWindows = [[NSMutableSet alloc] init];
     }
 
     return self;
@@ -162,10 +164,16 @@
 {
     BrowserWindowController *controller = [[BrowserWindowController alloc] initWithContext:[self getCurrentContext] pageGroup:_pageGroup];
     [[controller window] makeKeyAndOrderFront:sender];
+    [_browserWindows addObject:[controller window]];
     
     [controller loadURLString:defaultURL];
 }
 
+- (void)browserWindowWillClose:(NSWindow *)window
+{
+    [_browserWindows removeObject:window];
+}
+
 - (WKContextRef)getCurrentContext
 {
     return (_currentProcessModel == kProcessModelSharedSecondaryThread) ? _threadContext : _processContext;
@@ -215,13 +223,11 @@
 
 - (void)applicationWillTerminate:(NSNotification *)notification
 {
-    NSArray* windows = [NSApp windows];
-    for (NSWindow* window in windows) {
+    for (NSWindow* window in _browserWindows) {
         id delegate = [window delegate];
-        if ([delegate isKindOfClass:[BrowserWindowController class]]) {
-            BrowserWindowController *controller = (BrowserWindowController *)delegate;
-            [controller applicationTerminating];
-        }
+        assert([delegate isKindOfClass:[BrowserWindowController class]]);
+        BrowserWindowController *controller = (BrowserWindowController *)delegate;
+        [controller applicationTerminating];
     }
 
     WKRelease(_processContext);
@@ -233,8 +239,10 @@
     NSArray* windows = [NSApp windows];
     for (NSWindow* window in windows) {
         id delegate = [window delegate];
-        if ([delegate isKindOfClass:[BrowserWindowController class]])
-            return (BrowserWindowController *)delegate;
+        assert([delegate isKindOfClass:[BrowserWindowController class]]);
+        BrowserWindowController *controller = (BrowserWindowController *)delegate;
+        assert([_browserWindows containsObject:[controller window]]);
+        return controller;
     }
 
     return 0;

Modified: trunk/Tools/MiniBrowser/mac/BrowserWindowController.m (125112 => 125113)


--- trunk/Tools/MiniBrowser/mac/BrowserWindowController.m	2012-08-08 23:42:15 UTC (rev 125112)
+++ trunk/Tools/MiniBrowser/mac/BrowserWindowController.m	2012-08-08 23:47:42 UTC (rev 125113)
@@ -25,6 +25,7 @@
 
 #import "BrowserWindowController.h"
 
+#import "AppDelegate.h"
 #import <WebKit2/WKPagePrivate.h>
 #import <WebKit2/WKStringCF.h>
 #import <WebKit2/WKURLCF.h>
@@ -58,7 +59,10 @@
 
 - (void)dealloc
 {
-    assert(!_context);
+    WKRelease(_context);
+    WKRelease(_pageGroup);
+    [_webView release];
+
     [super dealloc];
 }
 
@@ -163,16 +167,14 @@
 
 - (void)windowWillClose:(NSNotification *)notification
 {
-    WKRelease(_context);
-    _context = 0;
-    WKRelease(_pageGroup);
-    _pageGroup = 0;
+    [(BrowserAppDelegate *)[NSApp delegate] browserWindowWillClose:[self window]];
+    [self autorelease];
 }
 
 - (void)applicationTerminating
 {
+    // FIXME: Why are we bothering to close the page? This doesn't even prevent LEAK output.
     WKPageClose(_webView.pageRef);
-    WKRelease(_webView.pageRef);
 }
 
 #define DefaultMinimumZoomFactor (.5)
@@ -426,7 +428,6 @@
     LOG(@"closePage");
     WKPageClose(page);
     [[(BrowserWindowController *)clientInfo window] close];
-    WKRelease(page);
 }
 
 static void runJavaScriptAlert(WKPageRef page, WKStringRef message, WKFrameRef frame, const void* clientInfo)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to