You cannot implement protocol at runtime (either in Objective-C or in .NET).
If you want to use the WebScripting protocol through the IWebScripting
interface, you have to find out which class implements it, and how to obtain

I have found some samples on calling JavaScript from Cocoa, but not the
other way. Maybe you can take a look at the bridges (JS <-> Cocoa) from the
Apple website ?

Regards, Laurent Etiemble.

2010/5/25 Eric Slosser <eric.slos...@v-fx.com>

> I've found Monobjc.WebKit.IWebScripting, a sub-class of IManagedWrapper.
> It's marked as [ObjectiveCProtocol("WebScripting")].  I'm now looking for
> clues on how to use this class (or should I call it an 'interface'?)
> On May 24, 2010, at 2:43 PM, Eric Slosser wrote:
> > I'm porting a .NET app that uses the WebBrowser control, and has
> Javascript that calls back into the C#.
> >
> > It does this by stating "[ComVisible(true)]  public class Foo { }", by
> having an member variable 'browser' of type System.Windows.Forms.WebBrowser"
> in Foo, and by calling "browser.ObjectForScripting = this" in Foo's
> constructor.  After those steps, the JavaScript can call back into
> Foo.Callback by calling "window.external.Callback()".
> >
> > On Cocoa/WebKit, that would be done by implementing the WebScripting
> protocol in an object (the 4 methods that define how the selectors in Foo
> are exposed to JavaScript) , then calling [someWebScriptObject
> setValue:someFoo forKey:@"external"], then the JavaScript would be able to
> call window.external.Callback_().
> >
> > I'm trying (and failing) to figure out how to implement the 4 methods of
> the WebScripting protocol so that they'll get called by Webkit.  Two of them
> return NSString*, and the "no op" case of returning nil is allowed.
> >
> > Will I be able to define these 4 in C#, or will I need to create a pure
> ObjectiveC object for this?
> >
> > Thanks in advance.

Reply via email to