]> khamidou — GitHub mirrors - electron.git/commitdiff
mac: InspectableWebContents should be destroyed before release NSWindow.
authorCheng Zhao <zcbenz@gmail.com>
Fri, 11 Apr 2014 04:32:42 +0000 (12:32 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 11 Apr 2014 04:32:42 +0000 (12:32 +0800)
Fixes atom/atom#1841.

atom/browser/native_window.cc
atom/browser/native_window.h
atom/browser/native_window_mac.mm

index ad0977199b2cb66494abb394b2ba3fa72fe2aedd..95fa029bf20b0ada72144b465534bf6d64224dd0 100644 (file)
@@ -57,12 +57,12 @@ NativeWindow::NativeWindow(content::WebContents* web_contents,
                            base::DictionaryValue* options)
     : content::WebContentsObserver(web_contents),
       has_frame_(true),
+      inspectable_web_contents_(
+          brightray::InspectableWebContents::Create(web_contents)),
       is_closed_(false),
       node_integration_("except-iframe"),
       has_dialog_attached_(false),
-      weak_factory_(this),
-      inspectable_web_contents_(
-          brightray::InspectableWebContents::Create(web_contents)) {
+      weak_factory_(this) {
   options->GetBoolean(switches::kFrame, &has_frame_);
 
 #if defined(OS_MACOSX)
index 27349b192e4545e8980e8272a06d81e4c66155e8..17b06b45d67c3cd900422d0d8821026173fef021 100644 (file)
@@ -251,6 +251,8 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
   // Window icon.
   gfx::Image icon_;
 
+  scoped_ptr<brightray::InspectableWebContents> inspectable_web_contents_;
+
  private:
   // Schedule a notification unresponsive event.
   void ScheduleUnresponsiveEvent(int ms);
@@ -304,7 +306,6 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
   scoped_ptr<DevToolsWebContentsObserver> devtools_web_contents_observer_;
 
   scoped_ptr<AtomJavaScriptDialogManager> dialog_manager_;
-  scoped_ptr<brightray::InspectableWebContents> inspectable_web_contents_;
 
   // Maps url to file path, used by the file requests sent from devtools.
   typedef std::map<std::string, base::FilePath> PathsMap;
index 2a779dd76905abb717f677e37bd9db257e6a6d55..2fbcb1127ce510844aee0db27f4894783f9ae30e 100644 (file)
@@ -66,7 +66,6 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
 }
 
 - (void)windowWillClose:(NSNotification*)notification {
-  shell_->window() = nil;
   [self autorelease];
 }
 
@@ -177,6 +176,9 @@ NativeWindowMac::NativeWindowMac(content::WebContents* web_contents,
       [[AtomNSWindowDelegate alloc] initWithShell:this];
   [window() setDelegate:delegate];
 
+  // We will manage window's lifetime ourselves.
+  [window() setReleasedWhenClosed:NO];
+
   // Enable the NSView to accept first mouse event.
   bool acceptsFirstMouse = false;
   options->GetBoolean(switches::kAcceptFirstMouse, &acceptsFirstMouse);
@@ -198,9 +200,12 @@ NativeWindowMac::NativeWindowMac(content::WebContents* web_contents,
 }
 
 NativeWindowMac::~NativeWindowMac() {
+  // Force InspectableWebContents to be destroyed before we destroy window,
+  // because it may still be observing the window at this time.
+  inspectable_web_contents_.reset();
+
   if (window())
-    // Use autorelease since we may have delegates or observers at this time.
-    [window() autorelease];
+    [window_ release];
 }
 
 void NativeWindowMac::Close() {