Hello,
I have a JavaScript function like this:
function callCocoaWithString(functionName, argument) {
var theBroker = window.myMessageBroker;
var returnMsg = theBroker.cocoaFunctionWithString(functionName,argument);
}
where myMessageBroker is an NSObject attached in webView:windowScriptObjectAvailable: with a [wso setValue:msgBroker forKey:@"myMessageBroker" ].
I have the following methods in msgBroker.m:
+ (NSString *) webScriptNameForSelector:(SEL)sel
{
if (sel == @selector(cocoaFunction:withString:))
return @"cocoaFunctionWithString";
return nil;
}
+ (BOOL)isSelectorExcludedFromWebScript:(SEL)selector
{
if (selector == @selector(cocoaFunction:withString:)) {
return NO;
}
return YES;
}
- (NSString *)cocoaFunction:(NSString*)functionName withString:(NSString *)dataString
{
NSString * someString;
NSString * selName = [ functionName stringByAppendingString:@":" ];
SEL sel = NSSelectorFromString(selName);
if ( [self respondsToSelector:sel] ) {
someString = [self performSelector:sel withObject:dataString];
}
else {
NSLog(@"javascript called cocoaFunction: with unknown selector: |%@|", functionName);
return @"%UNKNOWNFUNCTION";
}
return someString;
}
- (NSString *) styleAction:(NSString *)dataString
{
NSString * returnString = [[[NSString alloc] initWithString:dataString] autorelease] ;
return returnString;
}
styleAction: doesn't really do anything yet, obviously, and I'm doing the NSSelectorFromString() thing so that we can add new functions without having to constantly be editing webScriptNameForSelector: and isSelectorExcludedFromWebScript:.
Given a JavaScript
callCocoaWithString("styleAction","a String")
am I doing the right thing with regards to autoreleasing the string returned by styleAction: ? What about the static string I return in cocoaFunction:withString: for unknown selectors?
Thanks
Jeffrey Johnson
Macintosh Development
Wavefunction, Inc.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webkitsdk-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webkitsdk-dev/email@hidden
This email sent to email@hidden