Mrkebubun / o3d

Automatically exported from code.google.com/p/o3d
0 stars 0 forks source link

SafariBrowserWindowForWindowRef destroys non-Safari windows #197

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
This code is supposed to (according to the comments) look for Safari window, 
"harmlessly" to 
other browsers.

NSWindow* cocoaWindow = [[NSWindow alloc] initWithWindowRef:theWindow];
if (cocoaWindow) {
  if (strcmp(object_getClassName(cocoaWindow), "BrowserWindow") == 0) {
    return cocoaWindow;
  } else {
    [cocoaWindow release];
  }
}

The problem is that it actually destroys any non-Safari window it operates on. 
The docs for initWithWindowRef: say that it does *not* retain windowRef, but 
*does* release it on de-alloc, so 
the NSWindow takes ownership of one retain on the window ref. If the window ref 
given to this 
method isn't a BrowserWindow, the net effect is to immediately decrement the 
release count of 
the window.

It should CFRetain the windowRef if cocoaWindow is non-nil, to balance the 
release. (I'm not sure 
if the it-is-a-BrowserWindow path should CFRelease or not; it seems unlikely if 
the windowRef 
originally comes in through NPAPI)

Original issue reported on code.google.com by stuartmorgan@chromium.org on 10 Dec 2009 at 8:19

GoogleCodeExporter commented 9 years ago
Fix in progress.

Original comment by m...@google.com on 10 Dec 2009 at 10:56

GoogleCodeExporter commented 9 years ago
Fix checked in: http://codereview.chromium.org/486021/show

Original comment by m...@google.com on 10 Dec 2009 at 11:32