The default bug view has changed. See this FAQ.

nsXULWindow::GetParentNativeWindow crashes if GetParentWidget returns null

RESOLVED FIXED in mozilla1.9.3a1

Status

()

Core
XUL
--
critical
RESOLVED FIXED
8 years ago
8 years ago

People

(Reporter: Lingfeng.Guan, Assigned: mstange)

Tracking

(Depends on: 1 bug, {crash})

Trunk
mozilla1.9.3a1
crash
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [ccbr])

Attachments

(1 attachment)

(Reporter)

Description

8 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8 (.NET CLR 3.5.30729)
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8 (.NET CLR 3.5.30729)

Call nsIBaseWindow->GetParentNativeWindow() causes crash.
the crash report is here:
http://crash-stats.mozilla.com/report/index/8d49f73c-3ee9-449a-b5b7-82c9a2090418?p=1

quote Mook's analysis:
"http://mxr.mozilla.org/mozilla-central/source/xpfe/appshell/src/nsXULWindow.cpp#716 can return null, but http://mxr.mozilla.org/mozilla-central/source/xpfe/appshell/src/nsXULWindow.cpp?mark=737,739#731 assumes it won't"

Reproducible: Always

Steps to Reproduce:
1. QueryInterface to get a nsIBaseWindow from the window object.(the window is not main Window, and with attribute hidechrome="true")
2.call nsIBaseWindow->GetParentNativeWindow to get HWND 
3.
Actual Results:  
Firefox crashed. I used MSVC to debug and get these
First-chance exception at 0x103d98b6 in firefox.exe: 0xC0000005: Access violation reading location 0x00000000.
Unhandled exception at 0x103d98b6 in firefox.exe: 0xC0000005: Access violation reading location 0x00000000.
First-chance exception at 0x103d98b6 in firefox.exe: 0xC0000005: Access violation reading location 0x00000000.
Unhandled exception at 0x103d98b6 in firefox.exe: 0xC0000005: Access violation reading location 0x00000000. 
happened

Expected Results:  
should return the HWND of the window
Component: General → XUL
Keywords: crash
Product: Firefox → Core
QA Contact: general → xptoolkit.widgets
Version: unspecified → Trunk
Severity: normal → critical
Summary: nsXULWindow GetParentNativeWindow cause crash → nsXULWindow::GetParentNativeWindow crashes if GetParentWidget returns null
Whiteboard: [ccbr]
(Assignee)

Comment 1

8 years ago
Looks like GetParentNativeWindow is unused in Firefox, so maybe we could just remove it. What's mediacenter-com.dll?
(Reporter)

Comment 2

8 years ago
Please do not do that:) I'm using it right now. And Mook's minimizeToTray is using that too. Right now it is the best way to get HWND for a window.
mediacenter-com.dll is a component in my extension.
Btw: As well as GetParentNativeWindow, I suggest that GetNativeWindow is added to the interface, so that when I want the HWND of the window, I do not have to find it's child first.
(Assignee)

Comment 3

8 years ago
Would only GetNativeWindow be enough for your purposes, i.e. is there a different quick way to get the parent window?
(Reporter)

Comment 4

8 years ago
There is another way, but by that way, I have to use nsIWidget as well, and there for have to download couple of .idl and .h files of several unfrozen interfaces, which are not included in the Gecko-SDK, and could be changed anytime.
By this way, I only need nsIBaseWindow, although it's also unfrozen, but it's only one interface, which is much much better.
In fact, except for the bug, this is currently to best way to do what I want, and that's why I added it to the MDC, see below.
https://developer.mozilla.org/en/Code_snippets/Finding_Window_Handles
(Assignee)

Comment 5

8 years ago
> Btw: As well as GetParentNativeWindow, I suggest that GetNativeWindow is added
> to the interface, so that when I want the HWND of the window, I do not have to
> find it's child first.

For what reasons do you need the HWND of the child window? We'll get rid of all HWNDs except for the top level window one at some point, so I don't want to encourage using such an API now.
(Assignee)

Comment 6

8 years ago
Created attachment 404766 [details] [diff] [review]
null check

I haven't been able to figure out how to invoke GetParentNativeWindow from a js-only test. window.[...].getInterface(Ci.nsIBaseWindow).parentNativeWindow doesn't work.
Assignee: nobody → mstange
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Attachment #404766 - Flags: review?(roc)
Attachment #404766 - Flags: review?(roc) → review+
(Reporter)

Comment 7

8 years ago
I did not invoke that from js, if I recall correctly, seems like you cannot get a void * in js.
(Reporter)

Comment 8

8 years ago
(In reply to comment #5)
> > Btw: As well as GetParentNativeWindow, I suggest that GetNativeWindow is added
> > to the interface, so that when I want the HWND of the window, I do not have to
> > find it's child first.
> 
> For what reasons do you need the HWND of the child window? We'll get rid of all
> HWNDs except for the top level window one at some point, so I don't want to
> encourage using such an API now.

I don't need the HWND of the child window right now, and even if I do, I think give me the parent HWND should be enough, as long as I can tell the differences between the children.
(Assignee)

Comment 9

8 years ago
http://hg.mozilla.org/mozilla-central/rev/5bac33739a83
Status: ASSIGNED → RESOLVED
Last Resolved: 8 years ago
OS: Windows XP → All
Hardware: x86 → All
Resolution: --- → FIXED
Target Milestone: --- → mozilla1.9.3a1

Comment 10

8 years ago
Note that this will silently return garbage (more precisely, not clear aParentNativeWindow but return NS_OK) where things used to crash.

Updated

8 years ago
Depends on: 522843

Comment 11

8 years ago
Filed bug 522843 on that.
You need to log in before you can comment on or make changes to this bug.