[webkit-dev] Extending webkit javascript

Mark Rowe mrowe at apple.com
Sun Jan 18 23:26:36 PST 2009


On 2009-01-18, at 22:54, Erik Walter wrote:

> Then we wait until we get the didFinishDocumentLoad notification  
> (which occurs after the document is loaded, but before the OnLoad()  
> handlers are called in JavaScript).

As I mentioned in my previous message, the most appropriate time to  
register things with the context of a frame is typically immediately  
after the window object is cleared (- 
webView:didClearWindowObject:forFrame: on Mac OS X, window-object- 
cleared for Gtk, etc).  It will always be called before any scripts  
are executed in the document.  The same is not true of other  
callbacks.  For instance, didFinishDocumentLoad is called when the  
document has been parsed, which is after inline script tags have been  
executed.

> Then we register our object in the global context...
>
>
> 	Frame* coreFrame;
> 	WebFrame* targetFrame; // Make sure to set this from the loading  
> client
> 	coreFrame = core(targetFrame);
>
> 	JSContextRef scriptCtx;
>
> 	scriptCtx = toRef(coreFrame->script()->globalObject()->globalExec());
> 	
> 	JSObjectRef global = JSContextGetGlobalObject(scriptCtx);
> 	JSClassRef	fooClass = JSClassCreate(fooDef);
> 	JSObjectRef 	fooScriptObject = JSObjectMake(scriptCtx, fooClass,  
> NULL);
> 	JSObjectSetProperty(scriptCtx, global, jsStringRef("foo",  
> fooScriptObject, kJSPropertyAttributeNone, 0);

WebCore types should not be used by clients of the WebKit API.  The  
WebKit API provides methods to access the underlying context of a  
frame, and should be used instead.

- Mark

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2413 bytes
Desc: not available
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20090118/661e37f8/attachment.bin>


More information about the webkit-dev mailing list