我尝试创建一个简单的NPAPI,它将URL传递给Safari。
plugin_invoke方法如下:
bool plugin_invoke(NPObject *obj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result) {
// Make sure the method called is "open".
NPUTF8 *name = npnfuncs->utf8fromidentifier(methodName);
if(strcmp(name, plugin_method_name_open) == 0) {
npnfuncs->memfree(name);
BOOLEAN_TO_NPVARIANT(false, *result);
// Meke sure the arugment has at least one String parameter.
if(argCount > 0 && NPVARIANT_IS_STRING(args[0])) {
// Build CFURL object from the arugment.
NPString str = NPVARIANT_TO_STRING(args[0]);
CFURLRef url = CFURLCreateWithBytes(NULL, (const UInt8 *)str.UTF8Characters, str.UTF8Length, kCFStringEncodingUTF8, NULL);
if(url) {
// Open URL with the default application by Launch Service.
//OSStatus res = LSOpenCFURLRef(url, NULL);
//CFRelease(url);
OSStatus resultt = eventNotHandledErr;
//FSRef appRef;
FSRef appRef = {0};
Boolean isDir =true;
resultt = FSPathMakeRef((UInt8 *) "/Applications/Safari.app", &appRef,
&isDir);
LSApplicationParameters appParams = {0, kLSLaunchDefaults};
appParams.application = &appRef;
appParams.version = 0;
appParams.flags = kLSLaunchDefaults;
resultt = LSOpenApplication(&appParams, NULL);
BOOLEAN_TO_NPVARIANT(resultt == noErr, *result);
}
}
return true;
}
npnfuncs->memfree(name);
return false;
}
目前它只调用Safari但无法传递URL。
如何在NPAPI中将示例网址传递给Safari?我读过LSOpenFromURLSpec可能会有效但我无法创建代码。
答案 0 :(得分:1)
阅读documentation for Launch Services,特别是LSOpenURLsWithRole。
仅供参考,您的问题与NPAPI无关,只是从另一个进程启动Mac应用程序。一般情况下,如果您不将一般问题作为NPAPI问题发布,您将获得更多答案,因为方式更多人知道一般Mac问题的答案而不是NPAPI特定问题。