Bug 23708 - Would like to have a callback when an HTML element is first added to the DOM
: Would like to have a callback when an HTML element is first added to the DOM
Status: RESOLVED FIXED
: WebKit
WebKit API
: 528+ (Nightly build)
: Macintosh Mac OS X 10.5
: P2 Normal
Assigned To:
:
:
:
:
  Show dependency treegraph
 
Reported: 2009-02-03 11:34 PST by
Modified: 2009-02-05 23:41 PST (History)


Attachments
Adds htmlElementAvailable() callback to FrameLoaderClient (5.17 KB, patch)
2009-02-03 11:37 PST, Aaron Boodman
hyatt: review-
Review Patch | Details | Formatted Diff | Diff
Fixes per review feedback (12.56 KB, patch)
2009-02-03 17:03 PST, Aaron Boodman
no flags Review Patch | Details | Formatted Diff | Diff
Fix whitespace issues in previous patch (12.60 KB, patch)
2009-02-03 17:10 PST, Aaron Boodman
hyatt: review-
Review Patch | Details | Formatted Diff | Diff
More fixes (13.40 KB, patch)
2009-02-04 23:56 PST, Aaron Boodman
no flags Review Patch | Details | Formatted Diff | Diff
Add description and link to bug to ChangeLog files (14.15 KB, patch)
2009-02-05 00:10 PST, Aaron Boodman
hyatt: review+
Review Patch | Details | Formatted Diff | Diff


Note

You need to log in before you can comment on or make changes to this bug.


Description From 2009-02-03 11:34:20 PST
It would be useful to have a callback (perhaps on FrameLoaderClient) for when the HTML element is first added to the DOM. This would b fired around the same time as the existing windowObjectCleared() callback, but the difference would be that clients would be guaranteed there is a root HTML element available that they can start using.

The specific use case I have in mind in user scripts in Chromium. In Firefox, developers frequently asked for a way to run their user scripts before any HTML or script had been run on the page. A typical reason would be so that they could add CSS to the page before rendering started, or to setup event handlers.

In order to add CSS, we need a callback after there is an HTML element to append new style elements to, and windowObjectCleared() happens before this point currently.
------- Comment #1 From 2009-02-03 11:37:47 PST -------
Created an attachment (id=27282) [details]
Adds htmlElementAvailable() callback to FrameLoaderClient

This is a first cut of what I'm talking about. It works for HTML and XHTML documents, but not SVG. SVG is not critical for my use case, and it looks like parsing works much differently in SVG.

Also, please let me know what the right way is to add testing for something like this.
------- Comment #2 From 2009-02-03 11:52:19 PST -------
(From update of attachment 27282 [details])
I think this callback should just be documentElementAvailable rather than being specific to <html>.

You did not patch XHTML, but only patched the HTML parser.
------- Comment #3 From 2009-02-03 15:34:06 PST -------
You'd also need to implement the new method for all platforms rather than just Mac, otherwise the build will break.
------- Comment #4 From 2009-02-03 17:03:45 PST -------
Created an attachment (id=27300) [details]
Fixes per review feedback

Changed callback name to documentElementAvailable(), implemented for XML documents (which should cover SVG, XHTML, and WML I believe), and added empty implementations of callback for other platforms.
------- Comment #5 From 2009-02-03 17:10:06 PST -------
Created an attachment (id=27301) [details]
Fix whitespace issues in previous patch
------- Comment #6 From 2009-02-04 17:51:02 PST -------
(From update of attachment 27301 [details])
Nearly there...

Looks like your Changelog needs to be regenerated?

The change to HTMLParser.cpp could just be a single if statement.

if (localName == htmlTag && document->frame())

I don't know if Qt wants this or not but for completeness you would need to patch their XMLTokenizer as well.
------- Comment #7 From 2009-02-04 23:56:04 PST -------
Created an attachment (id=27343) [details]
More fixes

Updated ChangeLog, made changes as suggested in HTMLParser, and added an implementation to XMLTokenizerQt.cpp.
------- Comment #8 From 2009-02-05 00:04:11 PST -------
(From update of attachment 27343 [details])
>Index: WebCore/ChangeLog
...
>+2009-02-04  Aaron Boodman  <set EMAIL_ADDRESS environment variable>
>+
>+        Reviewed by NOBODY (OOPS!).
>+
>+        WARNING: NO TEST CASES ADDED OR CHANGED
>+

Usually, this is where people add a link to the bug and a description of the change.
------- Comment #9 From 2009-02-05 00:10:06 PST -------
Created an attachment (id=27344) [details]
Add description and link to bug to ChangeLog files

Whoops, you are right. Fixed now.
------- Comment #10 From 2009-02-05 14:52:54 PST -------
(From update of attachment 27344 [details])
r=me
------- Comment #11 From 2009-02-05 16:01:08 PST -------
Landed as http://trac.webkit.org/changeset/40694.
------- Comment #12 From 2009-02-05 23:41:47 PST -------
This broke the gtk build:
http://build.webkit.org/builders/trunk-qt-linux-release/builds/13432/steps/compile-release_2/logs/stdio

/home/zrusin/WebKit-BuildSlave/trunk-qt-linux-release/build/WebKitBuild/Release/lib/libQtWebKit.so: undefined reference to `non-virtual thunk to WebCore::FrameLoaderClientQt::documentElementAvailable()'
/home/zrusin/WebKit-BuildSlave/trunk-qt-linux-release/build/WebKitBuild/Release/lib/libQtWebKit.so: undefined reference to `WebCore::FrameLoaderClientQt::documentElementAvailable()'