JD_METHOD JavaPluginFactory5::Create(ISupports* sm,   
				     const JDIID& aIID,    
				     void* *aInstancePtr) {

    JDresult rv = JD_ERROR_FAILURE;
    if (aInstancePtr == NULL) {
        plugin_error("Received a null pointer to pointer in Create!\n");
    } else {
        JavaPluginFactory5 *res;

        if (!g_plugin_factory) {
	    IPluginServiceProvider* spService;
	    if (JD_FAILED(sm->QueryInterface(jIPluginServiceProviderIID, (void**)&spService)))
	        return rv;
	    
            res = new JavaPluginFactory5(spService); // g_plugin_factory set in here
            // The peice of shit browser does not seem to call Initialize
            // on this code path!!!
            spService->Release();
	    res->Initialize(); 
            init_utils();
        } else {
            res = g_plugin_factory;
        }
        rv = res->QueryInterface(aIID,aInstancePtr);
    }
    return rv;
}
//=--------------------------------------------------------------------------=
// CNSAdapter_PluginManager::GetURL
//=--------------------------------------------------------------------------=
// params:  
//
// notes:
//
JD_METHOD
CNSAdapter_PluginManager::GetURL(ISupports* pluginInst,
			         const char* url,
				 const char* target,
				 IPluginStreamListener* sl,
			         const char* altHost,
			         const char* referrer,
			         JDBool forceJSEnabled)
{
    TRACE("CNSAdapter_PluginManager::GetURL\n");

    if (m_pPluginManager == NULL || pluginInst == NULL)
	return JD_ERROR_NULL_POINTER;

    // the streamListener is not null only for Netscape 4.x browser
    if (sl != NULL)
	return JD_ERROR_FAILURE;

    JDSmartPtr<IPluginInstance> inst;
    
    if (JD_FAILED(pluginInst->QueryInterface(jIPluginInstanceIID, (void**)&inst)) )
        return JD_ERROR_FAILURE;

    CNSAdapter_JavaPlugin* pluginAdapterInst = (CNSAdapter_JavaPlugin*)pluginMap.FindElement(inst);
        
    if (pluginAdapterInst == NULL)
	return JD_ERROR_FAILURE;

    return m_pPluginManager->GetURL((nsIJVMPluginInstance*)pluginAdapterInst, url, target, NULL, altHost, referrer, forceJSEnabled);
}
/* The interface to CookieSupport to get the Cookie 
   Service from browser
*/
ICookieStorage* 
JavaPluginFactory5::GetCookieStorage(void) {
        if (cookieStorage == NULL) {
            if (JD_FAILED(service_provider->QueryService(jCPluginManagerCID,
    						 jICookieStorageIID,
    						 (ISupports **) &cookieStorage)))
                plugin_error("Could not get the CookieStorage");
        }
	return cookieStorage;
}
/* Returns JVMManager */
IJVMManager* 
JavaPluginFactory5::GetJVMManager(void) {
        if (jvm_manager == NULL) {
            if (JD_FAILED(service_provider->QueryService(jCJVMManagerCID, 
						         jIJVMManagerIID, 
						         (ISupports **) &jvm_manager)))
                plugin_error("Could not get the JVM manager");

        }
	return jvm_manager;
}
JD_IMETHODIMP
JavaPluginFactory5::Initialize() {
  // With the new API, the service manager
  // made available in the GetFactory method and is 
  // then passed into the constructor of the factory,
  // where the CPluginServiceProvider is created.
  // No args to initialize
  
    static JDresult error = JD_ERROR_FAILURE;
    if (isInitialized) 
        return error;
    else 
        isInitialized = true;
    trace("JavaPluginFactory5::Initialize\n");

    /* Set the plugin and jvm managers */
    //XXXFIX consider the lifetime of these objects and when
    // the refs should be released. They should probably
    // be freed when this object is destroyed, but there might
    // be circular references from the plugin manager to the
    // plugin factory and back.
    if (JD_FAILED(service_provider->QueryService(jCPluginManagerCID, 
						 jIPluginManagerIID, 
						 (ISupports **)&plugin_manager)))
      plugin_error("Could not get the plugin manager");
    
    if (plugin_manager != NULL) {
	/* Dump the environment variables for debugging */
	if (tracing) {
	    char *cp = getenv("CLASSPATH");
	    char *jtrace = getenv("JAVA_PLUGIN_TRACE");
	    char *vmwait  = getenv("JAVA_VM_WAIT");
	    char *ldpath = getenv("LD_LIBRARY_PATH");
	    if (cp) trace("CLASSPATH = %s\n", cp);
	    if (jtrace) trace("JAVA_PLUGIN_TRACE = %s\n", jtrace);
	    if (vmwait) trace("JAVA_VM_WAIT = %s\n", vmwait);
	    if (ldpath) trace("LD_LIBRARY_PATH = %s\n", ldpath);
	}
	return error;
    } else {
	plugin_error("No manager for initializing factory?\n");
	error = JD_ERROR_ILLEGAL_VALUE;
	return error;
    }

}
Exemplo n.º 6
0
//=--------------------------------------------------------------------------=
// CNS4Adapter::NPP_NewStream
//=--------------------------------------------------------------------------=
// Notifies an instance of a new data stream and returns an error value. 
//
// Create a stream peer and stream.  If succesful, save
// the stream peer in NPStream's pdata.
//
NPError 
CNS4Adapter::NPP_NewStream(NPP instance,
			   NPMIMEType type,
			   NPStream *stream, 
			   NPBool seekable,
			   JDUint16 *stype)
{
    TRACE("CNS4Adapter::NPP_NewStream\n");

    if (instance == NULL)
        return NPERR_INVALID_INSTANCE_ERROR;

    if (stream == NULL)
	return NPERR_INVALID_PLUGIN_ERROR;
				
    JDSmartPtr<IPluginStreamListener> spStreamListener = (IPluginStreamListener*)stream->notifyData;
    stream->pdata = NULL;

    if (spStreamListener != NULL)
    {
	IPluginStreamInfo* 
	pInfo = new CNS4Adapter_PluginStreamInfo(m_pINS4AdapterPeer, instance, stream, 
						 type, seekable);
	stream->pdata = (void*) pInfo;
        JDresult err = spStreamListener->OnStartBinding(pInfo);
        if (JD_FAILED(err)) 
            return err;

        // Obtain stream type
        err = spStreamListener->GetStreamType((JDPluginStreamType*)stype);
        assert(err == JD_OK);
    }
    else
    {
        *stype = JDPluginStreamType_Normal;
    }

    return NPERR_NO_ERROR;
}
Exemplo n.º 7
0
/* Handle the next message from Java to JS */
void
JSHandler(RemoteJNIEnv* env) {
	/* 2 cases 
	   - if this is recursive then we have sole ownership of the
	   pipe. 
	   - If this is spontaneous, we should also have sole ownership of
	   the pipe since it is locked at the other end 
	   - Hence, there should be no need for locking here
	*/
	/* Get the plugin index */
	int pluginIndex;
	get_msg(env, (char*)&pluginIndex, 4);
	JavaPluginFactory5* plugin_factory = get_global_factory();
	JavaPluginInstance5* inst = plugin_factory->GetInstance(pluginIndex);
	int code;
	get_msg(env, (char*)&code, 4);
  
	/*
	 * when  JSObject is GCed after plugin is destroyed, inst is NULL 
	 * and code is JAVA_PLUGIN_JNIJS_FINALIZE. In this case, we still
	 * need consume message from spontaneous pipe and ask browser to 
	 * release native JSObject,  or spontaneous pipe will be corrupted
	 * and resource leak
	 */
	if (code != JAVA_PLUGIN_JNIJS_FINALIZE) {

		if (inst == NULL || inst->IsDestroyPending()) {

			// Consume the message
			int raw_msg_len;
			char* raw_msg;
			get_msg(env, &raw_msg_len, 4);
			raw_msg = (char *) checked_malloc(raw_msg_len);
			/* Swallow the whole message */
			get_msg(env, raw_msg, raw_msg_len);
			int replyID = 0;
			memcpy(&replyID, raw_msg, 4);
			free(raw_msg);
			jobject nullret = NULL;
			send_jnijsOK_res(env, replyID, &nullret, sizeof(jobject));
			return;
		}
	}
  
	JSMessage msg;
	trace("JSObject:Entering JSHandler()\n");

	UnpackJSMessage(env, &msg);

	// Create ProxyJNIEnv
	JNIEnv* pProxyJNIEnv = NULL;
	IJVMManager* jvm_manager;
	jvm_manager = plugin_factory->GetJVMManager();
    
	ILiveconnect* pLiveConnect = NULL;
	ISecurityContext* pContext = NULL;
    
	if (JD_SUCCEEDED(jvm_manager->CreateProxyJNI(NULL, &pProxyJNIEnv)) ) {
		trace("JSHandler(): JS command: %X %s\n", code, jscode_to_str(code));
	
		if (inst == NULL) {
			IPluginServiceProvider* pProvider = plugin_factory->GetServiceProvider();

			if (pProvider == NULL) {
				trace("JSHandler(): cannot get pProvider when inst is NULL\n");
				return;
			}

			if (JD_FAILED(pProvider->QueryService(jCLiveconnectCID,
					jILiveconnectIID, (ISupports**)&pLiveConnect))) {
				trace("JSHandler(): cannot get liveconnect when inst is NULL\n");
				return;
			}

		} else {
	
			if (JD_FAILED(inst->GetJSDispatcher(&pLiveConnect))) {
				return;
			}
		}

		if (msg.utfstr != NULL)
			CreateSecurityContext(msg.utfstr, (int) msg.ctx, &pContext);

		int replyID = msg.requestID;

		switch(code){
		case JAVA_PLUGIN_JNIJS_GET_NATIVE:
			{
				// CLiveconnect	  
				jsobject ret = 0;

				/* Get the JS object, which represents a window associated
				   with the given plugin instance */

				JDresult nr = pLiveConnect->GetWindow(pProxyJNIEnv, 
													  (IPluginInstance*) inst, 
													  (void **)NULL, 
													  0, 
													  (ISecurityContext*) pContext, 
													  &ret);
				if(JD_FAILED(nr) || ret == 0) {
					trace("JSObject::ILiveConnect::GetWindow FAILED\n");
				}
  
				send_jnijsOK_res(env, replyID, &ret, sizeof(jsobject));
				break;
			}
		case JAVA_PLUGIN_JNIJS_TOSTRING:
			{
				jstring ret = NULL;
	  
				JDresult nr = pLiveConnect->ToString(pProxyJNIEnv,
													 (jsobject) msg.nativeJSObject,
													 &ret);
				if(!JD_SUCCEEDED(nr)) {
					trace("JSObject::ILiveConnect::ToString FAILED\n");
				}
	  	  	
				send_jnijsOK_res(env, replyID, &ret, sizeof(jstring));
				break;
			}
		case JAVA_PLUGIN_JNIJS_FINALIZE:
			{		 
				jobject dummy = NULL;
				JDresult nr = pLiveConnect->FinalizeJSObject(pProxyJNIEnv, 
															 (jsobject) msg.nativeJSObject);
				if(!JD_SUCCEEDED(nr)) {
					trace("JSObject::ILiveConnect::FinalizeJSObject() FAILED\n");
				}
		
				send_jnijsOK_res(env, replyID, &dummy, sizeof(jobject));
				break;
			}
		case JAVA_PLUGIN_GET_BROWSER_AUTHINFO: 
			{
				IBrowserAuthenticator* pBrowserAuthenticator;
				jobject ret = NULL;
				if (inst != NULL) {
					IPluginServiceProvider* service_provider =  plugin_factory->GetServiceProvider();

					trace("Handle native call: GetBrowserAuthenticat()");
					if(service_provider != NULL && 
					   JD_SUCCEEDED(service_provider->QueryService(jBrowserAuthenticatorCID, 
																   jBrowserAuthenticatorIID,
																   (ISupports**)&pBrowserAuthenticator))) {                       
						trace("Interface IBrowserAuthenticator found");
						ret = GetBrowserAuthInfo(env, msg.jarr, pBrowserAuthenticator);
						service_provider->ReleaseService(jBrowserAuthenticatorCID, pBrowserAuthenticator);
					} else {
						trace("Interface IBrowserAuthenticator not found");
					}
				}

				send_jnijsOK_res(env, replyID, &ret, sizeof(jobject));
				break;
			}
		case JAVA_PLUGIN_JNIJS_CALL:
			{
				jobject ret = NULL;
				JDresult nr = pLiveConnect->Call(pProxyJNIEnv, 
												 (jsobject)msg.nativeJSObject, 
												 msg.charstr, msg.charstr_len, 
												 msg.jarr,
												 (void**)NULL, 0, 
												 (ISecurityContext*)pContext, &ret);
				if(!JD_SUCCEEDED(nr)) {
					trace("JSObject::ILiveConnect::Call() FAILED\n");
				}
			
				send_jnijsOK_res(env, replyID, &ret, sizeof(jobject));
				break;
			}
		case JAVA_PLUGIN_JNIJS_EVAL:
			{
				jobject ret = NULL;
				JDresult nr = pLiveConnect->Eval(pProxyJNIEnv, 
												 (jsobject)msg.nativeJSObject,
												 msg.charstr, msg.charstr_len,
												 (void**)NULL, 0,
												 (ISecurityContext*)pContext, &ret);
				if(!JD_SUCCEEDED(nr)) {
					trace("JSObject::ILiveConnect::Eval() FAILED\n");
				}
		
				send_jnijsOK_res(env, replyID, &ret, sizeof(jobject));
				break;
			}
		case JAVA_PLUGIN_JNIJS_GETMEMBER:
			{
				jobject ret = NULL;
		 
				JDresult nr = pLiveConnect->GetMember(pProxyJNIEnv,
													  (jsobject)msg.nativeJSObject,
													  msg.charstr, msg.charstr_len,
													  (void**)NULL, 0,
													  (ISecurityContext*)pContext, &ret);
				if(!JD_SUCCEEDED(nr)) {
					trace("JSObject::ILiveConnect::GetMember() FAILED\n");
				}
		
				send_jnijsOK_res(env, replyID, &ret, sizeof(jobject));
				break;
			}
		case JAVA_PLUGIN_JNIJS_SETMEMBER:
			{
				jobject dummy = NULL;
	 
				JDresult nr = pLiveConnect->SetMember(pProxyJNIEnv,
													  (jsobject)msg.nativeJSObject,
													  msg.charstr, msg.charstr_len, 
													  msg.value,
													  (void**)NULL, 0,
													  (ISecurityContext*)pContext);
				if(!JD_SUCCEEDED(nr)) {
					trace("JSObject::ILiveConnect::SetMember() FAILED\n");
				}
	  
				send_jnijsOK_res(env, replyID, &dummy, sizeof(jobject));
				break;
			}
		case JAVA_PLUGIN_JNIJS_REMOVEMEMBER:
			{
				jobject dummy = NULL;
		 
				JDresult nr = pLiveConnect->RemoveMember(pProxyJNIEnv, 
														 (jsobject)msg.nativeJSObject, 
														 msg.charstr, msg.charstr_len, 
														 (void**)NULL, 0, 
														 (ISecurityContext*)pContext);
				if(!JD_SUCCEEDED(nr)) {
					trace("JSObject::ILiveConnect::RemoveMember() FAILED\n");
				}
		  
				send_jnijsOK_res(env, replyID, &dummy, sizeof(jobject));
				break;
			}
		case JAVA_PLUGIN_JNIJS_GETSLOT:
			{
				jobject ret = NULL;
	 
				JDresult nr = pLiveConnect->GetSlot(pProxyJNIEnv, 
													(jsobject)msg.nativeJSObject, 
													msg.slotindex,
													(void**)NULL, 0, 
													(ISecurityContext*)pContext, &ret);
				if(!JD_SUCCEEDED(nr)) {
					trace("JSObject::ILiveConnect::GetSlot() FAILED");
				}
				send_jnijsOK_res(env, replyID, &ret, sizeof(jobject));
				break;
			}
		case JAVA_PLUGIN_JNIJS_SETSLOT:
			{
				jobject dummy = NULL;
	  
				JDresult nr = pLiveConnect->SetSlot(pProxyJNIEnv, 
													(jsobject)msg.nativeJSObject, 
													msg.slotindex, 
													msg.value,
													(void**)NULL, 0, 
													(ISecurityContext*)pContext);
				if(!JD_SUCCEEDED(nr)) {
					trace("JSObject::ILiveConnect::SetSlot() FAILED\n");
				}
				send_jnijsOK_res(env, replyID, &dummy, sizeof(jobject));
				break;
			}
		default:
			plugin_error("Error in handler for JS calls!\n");
	
			if (pContext != NULL)
				pContext->Release();
			/* End of the handler for JS method calls */
		}
	}
	else {
		trace("Can not get ProxyJNI\n");
	}
	if(pLiveConnect != NULL)
		pLiveConnect->Release();

	if (pContext)
		pContext->Release();

	FreeJSMessage(&msg);
}