views:

20

answers:

2

I have a protocol handler associated with my Cocoa application.

[[NSAppleEventManager sharedAppleEventManager] 
    setEventHandler:self
    andSelector:@selector(getUrl:withReplyEvent:)
    forEventClass:kInternetEventClass andEventID:kAEGetURL];    

...

- (void)getUrl:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
#ifdef DEBUG
    NSLog(@"%s: %@",__PRETTY_FUNCTION__,event);
#endif
    NSURL *url = [NSURL URLWithString:[[event paramDescriptorForKeyword:keyDirectObject] stringValue]];
...
}

Who is referrer? (if it called from local machine I think it can be undefined, but if I call this protocol from a Web site... I would like to know domain from which the request is received.

Is it possible at all?

Is there solution to solve this task by another way?

A: 

Try inspecting the target of the reply event. That event will be sent back to whatever application sent you the original event, wherever it may be.

If you mean the user is clicking on a link that your application handles, and you want to know the URL of the page that contained the link: There's no way to do that.

Peter Hosey
thanks for the answer.yes, ideally I wanted caller page URL. but I even can't separate local from remote request.unfortunately replyEvent is always null.there is additional 'qtnd' key with value ($3C3F786D6...however it looks identical also while all calls.<NSAppleEventDescriptor: 'null'()>so maybe the answer is 'no way at all' :-(
UncleMiF
A: 

From: http://www.cocoabuilder.com/archive/cocoa/125741-finding-the-sender-of-an-appleevent-in-cocoa-app-on-10-2-8-or-greater.html

NSAppleEventDescriptor *addrDesc = [event
attributeDescriptorForKeyword:keyAddressAttr];
NSData *psnData = [[addrDesc
coerceToDescriptorType:typeProcessSerialNumber] data];

if (psnData)
{
 ProcessSerialNumber psn = *(ProcessSerialNumber *) [psnData bytes];
 ...
}
UncleMiF
as a semi-solution - we can get process name from psn, and apply our own policy then...
UncleMiF