Web scripting key does not work

Christiaan Hofman <[email protected]> Wed, 20 Oct 2010 15:18:17 +0200
Newsgroups gmane.comp.macosx.devel
Message-ID <[email protected]>
I am trying to make a key for an object available to javascript in a webview. I have been able to successfully do this for calling methods on the object, but exposing the key does not work. I have followed all the prescriptions in the documentation:

- Implemented -webView:didClearWindowObject:forFrame: in the WebFrameLoadDelegate

- (void)webView:(WebView *)sender didClearWindowObject:(WebScriptObject *)windowObject forFrame:(WebFrame *)frame {
    [windowObject setValue:[FOO sharedInstance] forKey:@"foo"];
}

- Implemented +isKeyExcludedFromWebScript: on the class (Foo) for the exposed object, returning NO for the (KVC compliant) key I want to expose.

+ (BOOL)isKeyExcludedFromWebScript:(const char *)name {
	return strcmp(name, "bar") != 0;
}

Now when I try to set the key of the object in a JavaScript function on a page loaded in my webview (window.foo.bar = true), the KVC compliant setter is never called, and nothing happens. As I said, calling a function for an exposed selector from JavaScript does work, the method is properly called.

Is this a bug, or has webkit stopped supporting this, or is there something else I forgot?

thanks,
Christiaan