Reviewed by Darin.
authorthatcher <thatcher@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Apr 2007 08:47:07 +0000 (08:47 +0000)
committerthatcher <thatcher@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Apr 2007 08:47:07 +0000 (08:47 +0000)
        Bug 6658: World leak when closing inspected window
        http://bugs.webkit.org/show_bug.cgi?id=6658 and <rdar://problem/4411863>

        Removes over-retains of the inspector WebView, WebInspector and WebInspectorPanel.

        * WebInspector/WebInspector.m:
        (+[WebInspector sharedWebInspector]): Return the global sharedWebInspector variable.
        (-[WebInspector window]): Release the window after calling setWindow:.
        (-[WebInspector windowWillClose:]): Set the JavaScript Inspector variable to null and expire the current highlight.
          Also clear the global sharedWebInspector variable and release it if self equals sharedWebInspector.
        (-[WebInspector showWindow:]): Set the JavaScript Inspector variable back to self.
        * WebInspector/WebInspectorInternal.h: Remove the isSharedInspector member variable.
        * WebView/WebView.mm:
        (-[WebView windowScriptObject]): Return nil if core([self mainFrame]) is NULL.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@21028 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKit/ChangeLog
WebKit/WebInspector/WebInspector.m
WebKit/WebInspector/WebInspectorInternal.h
WebKit/WebKit.xcodeproj/project.pbxproj
WebKit/WebView/WebView.mm

index 3b42503..c20b070 100644 (file)
@@ -1,3 +1,22 @@
+2007-04-23  Timothy Hatcher  <timothy@apple.com>
+
+        Reviewed by Darin.
+
+        Bug 6658: World leak when closing inspected window
+        http://bugs.webkit.org/show_bug.cgi?id=6658 and <rdar://problem/4411863>
+
+        Removes over-retains of the inspector WebView, WebInspector and WebInspectorPanel.
+
+        * WebInspector/WebInspector.m:
+        (+[WebInspector sharedWebInspector]): Return the global sharedWebInspector variable.
+        (-[WebInspector window]): Release the window after calling setWindow:.
+        (-[WebInspector windowWillClose:]): Set the JavaScript Inspector variable to null and expire the current highlight.
+          Also clear the global sharedWebInspector variable and release it if self equals sharedWebInspector.
+        (-[WebInspector showWindow:]): Set the JavaScript Inspector variable back to self.
+        * WebInspector/WebInspectorInternal.h: Remove the isSharedInspector member variable.
+        * WebView/WebView.mm:
+        (-[WebView windowScriptObject]): Return nil if core([self mainFrame]) is NULL.
+
 2007-04-23  Darin Adler  <darin@apple.com>
 
         Reviewed by Hyatt.
index 8040d3e..63cadc4 100644 (file)
 
 #pragma mark -
 
-@implementation WebInspector
+static WebInspector *sharedWebInspector = nil;
 
+@implementation WebInspector
 + (WebInspector *)sharedWebInspector
 {
-    static WebInspector *_sharedWebInspector = nil;
-    if (!_sharedWebInspector) {
-        _sharedWebInspector = [[self alloc] init];
-        _sharedWebInspector->_private->isSharedInspector = YES;
-    }
-
-    return _sharedWebInspector;
+    if (!sharedWebInspector)
+        sharedWebInspector = [[self alloc] init];
+    return sharedWebInspector;
 }
 
 #pragma mark -
         [window setContentView:_private->webView];
 
         [self setWindow:window];
+        [window release];
+
         return window;
     }
 
 
 - (void)windowWillClose:(NSNotification *)notification
 {
+    [_private->currentHighlight expire];
+
     [[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationWillResignActiveNotification object:nil];
     [[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationDidBecomeActiveNotification object:nil];
+    [[NSNotificationCenter defaultCenter] removeObserver:self name:NSApplicationWillTerminateNotification object:nil];
     [[NSNotificationCenter defaultCenter] removeObserver:self name:WebNodeHighlightExpiredNotification object:nil];
     [[NSNotificationCenter defaultCenter] removeObserver:self name:NSViewFrameDidChangeNotification object:nil];
     [[NSNotificationCenter defaultCenter] removeObserver:self name:NSSystemColorsDidChangeNotification object:nil];
     [self setFocusedDOMNode:nil];
     [self setWebFrame:nil];
 
-    if (!_private->isSharedInspector)
+    [[_private->webView windowScriptObject] setValue:[NSNull null] forKey:@"Inspector"];
+
+    if (self == sharedWebInspector) {
         [self release];
+        sharedWebInspector = nil;
+    }
 }
 
 - (IBAction)showWindow:(id)sender
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_updateSystemColors) name:NSSystemColorsDidChangeNotification object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_applicationWillResignActive) name:NSApplicationWillResignActiveNotification object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_applicationDidBecomeActive) name:NSApplicationDidBecomeActiveNotification object:nil];
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_applicationWillTerminate) name:NSApplicationWillTerminateNotification object:nil];
+
+    [[_private->webView windowScriptObject] setValue:self forKey:@"Inspector"];
 
     [super showWindow:sender];
 }
     [(NSPanel *)[self window] setFloatingPanel:YES];
 }
 
+- (void)_applicationWillTerminate
+{
+    [_private->webView close];
+}
+
 - (void)_webFrameDetached:(WebFrame *)frame
 {
     [self setRootDOMNode:nil];
index 643aef5..5479bdd 100644 (file)
@@ -48,7 +48,6 @@
 #endif
     BOOL webViewLoaded;
     BOOL preventHighlight;
-    BOOL isSharedInspector;
 }
 @end
 
index 1e5c370..465b926 100644 (file)
                0867D690FE84028FC02AAC07 /* Project object */ = {
                        isa = PBXProject;
                        buildConfigurationList = 149C283208902B0F008A9EFC /* Build configuration list for PBXProject "WebKit" */;
+                       compatibilityVersion = "Xcode 2.4";
                        hasScannedForEncodings = 1;
                        knownRegions = (
                                English,
                        productRefGroup = 034768DFFF38A50411DB9C8B /* Products */;
                        projectDirPath = "";
                        projectRoot = "";
+                       shouldCheckCompatibility = 1;
                        targets = (
                                9398100A0824BF01008DF038 /* WebKit */,
                        );
index 7308fda..eb8b3ef 100644 (file)
@@ -2123,7 +2123,10 @@ NS_ENDHANDLER
 
 - (WebScriptObject *)windowScriptObject
 {
-    return core([self mainFrame])->windowScriptObject();
+    Frame* coreFrame = core([self mainFrame]);
+    if (!coreFrame)
+        return nil;
+    return coreFrame->windowScriptObject();
 }
 
 // Get the appropriate user-agent string for a particular URL.