Closed Bug 567357 Opened 14 years ago Closed 14 years ago

Fire a DOMWindowCreated DOM event to match the observer notification in bug 549539

Categories

(Core :: DOM: Core & HTML, defect)

x86
Windows 7
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla2.0b6
Tracking Status
status1.9.2 --- .7-fixed

People

(Reporter: benjamin, Assigned: benjamin)

References

Details

(Keywords: dev-doc-needed)

Attachments

(1 file, 1 obsolete file)

Bug 549539 added a (chrome|content)-document-global-created observer-service notification. People using the message manager, however, don't have easy access to the observer service and really want to be scoped to the current tab and its descendent frames anyway. This patch adds a chrome-listener-only DOMWindowCreated event which has the same effect (fires before any content script is run).

There is one issue I'm not sure about here: this patch ends up issuing a WARNING: fix the caller! file c:/builds/mozilla-central/ff-debug/content/events/src/../../../../src/content/events/src/nsEventDispatcher.cpp, line 512

because DocumentViewerImpl::InitInternal holds an nsAutoScriptBlocker. This means at least that any observers of (chrome|content)-document-global-created, as well as any event listeners of this new DOM event, need to be careful not to cause re-entrancy into DocumentViewerImpl::InitPresentationStuff. The script-blocker was added in bug 528493. Is there some way to silence this warning by refactoring InitInternal so that it actually is safe to run any scripts during that time, suppressing InitPresentationStuff?
Attached patch DOMWindowCreated, rev. 1 (obsolete) — Splinter Review
Attachment #446714 - Flags: superreview?(roc)
Attachment #446714 - Flags: review?(jonas)
Don't we need something similar for the window-destroyed case, then?  Except there's no obvious place to dispatch the event for that one....
None of my current candidate-consumers do: they typically just add something to the global object like window.Mochitest = mychromething, or window.InstallTrigger, or add an event listener to the document for things like form autofill, etc.  None of those clients really care about when the document goes away.
Ah, ok.

Will chrome consumers in e10s receive observer service notifications at all?  Or do we need a different setup for the consumers who do care about window destruction?  Note that the destruction message is async, so can be remoted easily as needed.
Not sure what "chome consumers" you mean. The observer service will function normally in both the chrome and content processes. It's just that my current plan is that the content process will only run builtin XPCOM components (libxul, plus maybe platform JS components), and extensions/apps won't have the opportunity to register contractids/category entries in the content process.
> Not sure what "chome consumers" you mean.

Firebug, for one.  It wants to know when it can forget all the script info it cached for a window.
I don't think we know how Firebug is going to work yet in content-land.
Comment on attachment 446714 [details] [diff] [review]
DOMWindowCreated, rev. 1

+  if (domEventDoc)
+    domEventDoc->CreateEvent(NS_LITERAL_STRING("event"), getter_AddRefs(event));

{}
Attachment #446714 - Flags: superreview?(roc) → superreview+
Please don't add DOM events which fire at unsafe time.

But is the script blocker still needed in DocumentViewer?
nsSubDocumentFrame::ShowViewer is called async nowadays.
Are we talking the blocker in InitInternal?  I don't see how async would help with the flushing problem that blocker tries to address...
I was just looking at the stack trace for which the blocker was added, but
perhaps I misinterpreted that.
Blocks: 550936
I agree with comment 9. Could you add a scriptrunner (nsContentUtils::AddScriptRunner) which fires the event?
Will that still guarantee that the event fires before content script can run?
I guess it should, more or less by definition....
Scriptrunner FTW
Attachment #446714 - Attachment is obsolete: true
Attachment #447911 - Flags: review?(jonas)
would this patch solve this assertion:
###!!! ASSERTION: Want to fire mutation events, but it's not safe: '(aNode->IsNodeOfType(nsINode::eCONTENT) && static_cast<nsIContent*>(aNode)-> IsInNativeAnonymousSubtree()) || sScriptBlockerCount == sRemovableScriptBlockerCount', file /home/joel/mozilla/src/content/base/src/nsContentUtils.cpp, line 3419
That depends on the stack at the time.
Comment on attachment 447911 [details] [diff] [review]
DOMWindowCreated, rev. 2

Use nsContentUtils::DispatchChromeEvent instead, that'll save you much of this code.

r=me with that
Attachment #447911 - Flags: review?(jonas) → review+
http://hg.mozilla.org/mozilla-central/rev/be68a65eb4c7
Status: NEW → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
Blocks: 571339
could this have caused the 100ms startup regression in bug 574457?
(In reply to comment #20)
> could this have caused the 100ms startup regression in bug 574457?

That seems very unlikely. Simply firing the notification when no one is listening should be a very low cost operation. Especially in the context of creating a new global object.
Blocks: 578150
No longer blocks: 578150
Depends on: 578150
Keywords: dev-doc-needed
Target Milestone: --- → mozilla2.0b6
Version: unspecified → Trunk
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: