2011-11-30 37 views
0

我嘗試創建一個將URL傳遞到Safari的簡單NPAPI。如何使用NPAPI for Mac中的參數調用應用程序

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不能傳遞。

如何將示例URL傳遞給NPAPI中的Safari?我讀LSOpenFromURLSpec可能會工作,但我無法創建代碼。

回答

1

閱讀documentation for Launch Services,尤其是LSOpenURLsWithRole。

僅供參考,與您的問題無關的是NPAPI特有的,它只是從另一個進程啓動Mac應用程序。一般來說,如果您不將一般問題作爲NPAPI問題發佈,您將得到更多答案,因爲方式更多人知道一般Mac問題的答案,而不是NPAPI特定問題。

相關問題