Пример #1
0
// 清空IECtrl::Navigate的参数
void CPlugin::RemoveNavigateParams()
{
  NPObject* pWindow = NULL;
  NPVariant vCOBAContainer;
  VOID_TO_NPVARIANT(vCOBAContainer);
  NPVariant vResult;
  VOID_TO_NPVARIANT(vResult);

  try
  {
    if ((NPN_GetValue( m_pNPInstance, NPNVWindowNPObject, &pWindow) != NPERR_NO_ERROR ) || !pWindow )
    {
      throw(CString(_T("Cannot get window")));
    }

    if ((!NPN_GetProperty( m_pNPInstance, pWindow, NPN_GetStringIdentifier ("COBAContainer"), &vCOBAContainer)) || !NPVARIANT_IS_OBJECT (vCOBAContainer))
    {
      throw(CString(_T("Cannot get window.COBAContainer")));
    }

    if (!NPN_Invoke(m_pNPInstance, NPVARIANT_TO_OBJECT(vCOBAContainer), NPN_GetStringIdentifier("removeNavigateParams"), NULL, 0, &vResult))
    {
      throw(CString(_T("Cannot execute window.COBAContainer.removeNavigateParams()")));
    }
  }
  catch (CString strMessage)
  {
    TRACE(_T("[CPlugin::RemoveNavigateParams Exception] %s"), strMessage);
  }

  if (!NPVARIANT_IS_VOID(vResult))	NPN_ReleaseVariantValue(&vResult);
  if (!NPVARIANT_IS_VOID(vCOBAContainer))	NPN_ReleaseVariantValue(&vCOBAContainer);
  if (pWindow != NULL) NPN_ReleaseObject(pWindow);
}
Пример #2
0
// 获取Plugin所在页面的URL
CString CPlugin::GetHostURL() const
{
  CString url;

  BOOL bOK = FALSE;
  NPObject* pWindow = NULL;
  NPVariant vLocation;
  VOID_TO_NPVARIANT(vLocation);
  NPVariant vHref;
  VOID_TO_NPVARIANT(vHref);

  try 
  {

    if (( NPN_GetValue( m_pNPInstance, NPNVWindowNPObject, &pWindow) != NPERR_NO_ERROR ) || !pWindow )
    {
      throw(CString(_T("Cannot get window")));
    }

    if ((!NPN_GetProperty( m_pNPInstance, pWindow, NPN_GetStringIdentifier ("location"), &vLocation)) || !NPVARIANT_IS_OBJECT (vLocation))
    {
      throw(CString(_T("Cannot get window.location")));
    }

    if ((!NPN_GetProperty( m_pNPInstance, NPVARIANT_TO_OBJECT(vLocation), NPN_GetStringIdentifier ("href"), &vHref)) || !NPVARIANT_IS_STRING(vHref))
    {
      throw(CString(_T("Cannot get window.location.href")));
    }

    // 转换window.location.href的编码
    int buffer_size = vHref.value.stringValue.UTF8Length + 1;
    char* szUnescaped = new char[buffer_size];
    DWORD dwSize = buffer_size;
    if (SUCCEEDED(UrlUnescapeA(const_cast<LPSTR>(vHref.value.stringValue.UTF8Characters), szUnescaped, &dwSize, 0)))
    {
      WCHAR* szURL = new WCHAR[dwSize + 1];
      if (MultiByteToWideChar(CP_UTF8, 0, szUnescaped, -1, szURL, dwSize + 1) > 0)
      {
        url = CW2T(szURL);
      }
      delete[] szURL;
    }
    delete[] szUnescaped;

  }
  catch (CString strMessage)
  {
    TRACE(_T("[CPlugin::GetHostURL Exception] %s"), strMessage);
  }

  if (!NPVARIANT_IS_VOID(vHref))	NPN_ReleaseVariantValue(&vHref);
  if (!NPVARIANT_IS_VOID(vLocation))	NPN_ReleaseVariantValue(&vLocation);
  if (pWindow != NULL) NPN_ReleaseObject(pWindow);

  return url;
}
Пример #3
0
	double CPlugin::GetZoomLevel()
	{
		double level = 1;

		NPVariant vLevel;
		VOID_TO_NPVARIANT(vLevel);

		try
		{
			NPObject* pContainer = GetContainer();

			if (!NPN_Invoke(m_pNPInstance, pContainer, GetIdentifier("getZoomLevel"), NULL, 0, &vLevel))
			{
				throw CString(_T("Cannot invoke window.Container.getZoomLevel()"));
			}
			if (NPVARIANT_IS_DOUBLE(vLevel)) 
				level = NPVARIANT_TO_DOUBLE(vLevel);
			else if ( NPVARIANT_IS_INT32(vLevel) ) 
				level = NPVARIANT_TO_INT32(vLevel);
		}
		catch (const CString& strMessage)
		{
			level = 1;
			UNUSED(strMessage);
			TRACE(_T("[CPlugin::GetZoomLevel Exception] %s\n"), strMessage);
		}

		if (!NPVARIANT_IS_VOID(vLevel))	NPN_ReleaseVariantValue(&vLevel);

		return level;
	}
Пример #4
0
bool GenericNPObject::Enumerate(NPIdentifier **identifiers, uint32_t *identifierCount) {

	if (invalid) return false;

	try {
		*identifiers = (NPIdentifier *)NPNFuncs.memalloc(sizeof(NPIdentifier) * numeric_mapper.size());
		if (NULL == *identifiers) {

			return false;
		}
		*identifierCount = 0;

		std::vector<NPVariant>::iterator it;
		unsigned int i = 0;
		char str[10] = "";
		for (it = numeric_mapper.begin(); it < numeric_mapper.end(); ++it, ++i) {

			// skip empty (padding) elements
			if (NPVARIANT_IS_VOID(*it)) continue;
			_snprintf(str, sizeof(str), "%u", i);
			(*identifiers)[(*identifierCount)++] = NPNFuncs.getstringidentifier(str);
		}
	}
	catch (...) {
	}

	return true;
}
Пример #5
0
	CString CPlugin::GetNavigateParam(const NPUTF8* name) const
	{
		CString strParam;

		NPVariant vParam;
		VOID_TO_NPVARIANT(vParam);

		try
		{
			NPObject* pContainer = GetContainer();

			if (!NPN_Invoke(m_pNPInstance, pContainer, GetIdentifier(name), NULL, 0, &vParam))
			{
				throw(CString(_T("Cannot invoke window.Container.getXXX()")));
			}
			if (!NPVARIANT_IS_STRING(vParam)) 
			{
				throw(CString(_T("Invalid return value.")));
			}
			strParam = NPStringToCString(vParam.value.stringValue);
		}
		catch (const CString& strMessage)
		{
			UNUSED(strMessage);
			TRACE(_T("[CPlugin::GetNavigateHeaders Exception] %s\n"), strMessage);
		}

		if (!NPVARIANT_IS_VOID(vParam))	NPN_ReleaseVariantValue(&vParam);

		return strParam;
	}
Пример #6
0
	NPObject* CPlugin::GetWindowPropertyObject(const NPUTF8* szPropertyName) const
	{
		NPObject* pWindow = GetWindow();
		NPVariant vObject;
		VOID_TO_NPVARIANT(vObject);

		if ((!NPN_GetProperty(m_pNPInstance, pWindow, GetIdentifier(szPropertyName), &vObject)) || !NPVARIANT_IS_OBJECT(vObject))
		{
			if (!NPVARIANT_IS_VOID(vObject))
				NPN_ReleaseVariantValue(&vObject);
			throw CString(_T("Cannot get window.")) + NPStringCharactersToCString(szPropertyName);
		}

		NPObject* pObject = NPVARIANT_TO_OBJECT(vObject);
		if (!pObject)
		{
			NPN_ReleaseVariantValue(&vObject);
			throw CString(_T("window.")) + NPStringCharactersToCString(szPropertyName) + _T(" is null");
		}

		NPN_RetainObject(pObject);
		NPN_ReleaseVariantValue(&vObject);

		return pObject;
	}
Пример #7
0
CString CPlugin::GetNavigateParam(const NPUTF8* name) const
{
  CString strParam;

  NPObject* pWindow = NULL;
  NPVariant vCOBAContainer;
  VOID_TO_NPVARIANT(vCOBAContainer);
  NPVariant vParam;
  VOID_TO_NPVARIANT(vParam);

  try
  {
    if ((NPN_GetValue( m_pNPInstance, NPNVWindowNPObject, &pWindow) != NPERR_NO_ERROR ) || !pWindow )
    {
      throw(CString(_T("Cannot get window")));
    }

    if ((!NPN_GetProperty( m_pNPInstance, pWindow, NPN_GetStringIdentifier ("COBAContainer"), &vCOBAContainer)) || !NPVARIANT_IS_OBJECT (vCOBAContainer))
    {
      throw(CString(_T("Cannot get window.COBAContainer")));
    }

    if (!NPN_Invoke(m_pNPInstance, NPVARIANT_TO_OBJECT(vCOBAContainer), NPN_GetStringIdentifier(name), NULL, 0, &vParam))
    {
      throw(CString(_T("Cannot execute window.COBAContainer.getXXX()")));
    }
    if (!NPVARIANT_IS_STRING(vParam)) 
    {
      throw(CString(_T("Invalid return value.")));
    }
    strParam = NPStringToCString(vParam.value.stringValue);
  }
  catch (CString strMessage)
  {
    TRACE(_T("[CPlugin::GetNavigateHeaders Exception] %s"), strMessage);
  }

  if (!NPVARIANT_IS_VOID(vParam))	NPN_ReleaseVariantValue(&vParam);
  if (!NPVARIANT_IS_VOID(vCOBAContainer))	NPN_ReleaseVariantValue(&vCOBAContainer);
  if (pWindow != NULL) NPN_ReleaseObject(pWindow);

  return strParam;
}
Пример #8
0
double CPlugin::GetZoomLevel()
{
  double level = 1;

  NPObject* pWindow = NULL;
  NPVariant vCOBA;
  VOID_TO_NPVARIANT(vCOBA);
  NPVariant vLevel;
  VOID_TO_NPVARIANT(vLevel);

  try
  {
    if ((NPN_GetValue( m_pNPInstance, NPNVWindowNPObject, &pWindow) != NPERR_NO_ERROR ) || !pWindow )
    {
      throw(CString(_T("Cannot get window")));
    }

    if ((!NPN_GetProperty( m_pNPInstance, pWindow, NPN_GetStringIdentifier ("COBA"), &vCOBA)) || !NPVARIANT_IS_OBJECT (vCOBA))
    {
      throw(CString(_T("Cannot get window.COBA")));
    }

    if (!NPN_Invoke(m_pNPInstance, NPVARIANT_TO_OBJECT(vCOBA), NPN_GetStringIdentifier("getZoomLevel"), NULL, 0, &vLevel))
    {
      throw(CString(_T("Cannot execute window.COBA.getZoomLevel()")));
    }
    if (NPVARIANT_IS_DOUBLE(vLevel)) 
      level = NPVARIANT_TO_DOUBLE(vLevel);
    else if ( NPVARIANT_IS_INT32(vLevel) ) 
      level = NPVARIANT_TO_INT32(vLevel);
  }
  catch (CString strMessage)
  {
    level = 1;
    TRACE(_T("[CPlugin::FireEvent Exception] %s"), strMessage);
  }

  if (!NPVARIANT_IS_VOID(vLevel))	NPN_ReleaseVariantValue(&vLevel);
  if (!NPVARIANT_IS_VOID(vCOBA))	NPN_ReleaseVariantValue(&vCOBA);
  if (pWindow != NULL) NPN_ReleaseObject(pWindow);

  return level;
}
Пример #9
0
bool
xplayerNPObject::GetObjectFromArguments (const NPVariant* argv,
                                        uint32_t argc,
                                        uint32_t argNum,
                                        NPObject*& _result)
{
  if (!CheckArg (argv, argc, argNum, NPVariantType_Object))
    return false;

  NPVariant arg = argv[argNum];
  if (NPVARIANT_IS_STRING (arg)) {
    _result = NPVARIANT_TO_OBJECT (arg);
  } else if (NPVARIANT_IS_NULL (arg) ||
             NPVARIANT_IS_VOID (arg)) {
    _result = NULL;
  }

  return true;
}
Пример #10
0
bool
xplayerNPObject::GetNPStringFromArguments (const NPVariant* argv,
                                         uint32_t argc,
                                         uint32_t argNum,
                                         NPString& _result)
{
  if (!CheckArg (argv, argc, argNum, NPVariantType_String))
    return false;

  NPVariant arg = argv[argNum];
  if (NPVARIANT_IS_STRING (arg)) {
    _result = NPVARIANT_TO_STRING (arg);
  } else if (NPVARIANT_IS_NULL (arg) ||
             NPVARIANT_IS_VOID (arg)) {
    _result.UTF8Characters = NULL;
    _result.UTF8Length = 0;
  }

  return true;
}
Пример #11
0
void m_strFromVar(char **dst, NPVariant var) {
	if (!dst)
		return;
	if (!((NPVARIANT_IS_STRING(var)) || (NPVARIANT_IS_VOID(var))))
		return;
	if (*dst) {
		NPN_MemFree(*dst);
		*dst = NULL;
	}
	if (NPVARIANT_IS_STRING(var)) {
		NPString src = NPVARIANT_TO_STRING(var);
		int len = src.UTF8Length;
		*dst = (char*) NPN_MemAlloc(len+1);
		memcpy(*dst, src.UTF8Characters, len);
		(*dst)[len] = '\0';
	}
	else {
		*dst = NULL;
	}
}
Пример #12
0
	// Clear all the paramters for IECtrl::Navigate
	void CPlugin::RemoveNavigateParams()
	{
		NPVariant vResult;
		VOID_TO_NPVARIANT(vResult);

		try
		{
			NPObject* pContainer = GetContainer();

			if (!NPN_Invoke(m_pNPInstance, pContainer, GetIdentifier("removeNavigateParams"), NULL, 0, &vResult))
			{
				throw(CString(_T("Cannot execute window.Container.removeNavigateParams()")));
			}
		}
		catch (const CString& strMessage)
		{
			UNUSED(strMessage);
			TRACE(_T("[CPlugin::RemoveNavigateParams Exception] %s\n"), strMessage);
		}

		if (!NPVARIANT_IS_VOID(vResult))	NPN_ReleaseVariantValue(&vResult);
	}
Пример #13
0
void
printNPVariant(const NPVariant *value)
{
    if (NPVARIANT_IS_DOUBLE(*value)) {
        double num = NPVARIANT_TO_DOUBLE(*value);
        log_debug("is double, value %g", num);
    } else if (NPVARIANT_IS_STRING(*value)) {
        std::string str = NPStringToString(NPVARIANT_TO_STRING(*value));
        log_debug("is string, value %s", str);
    } else if (NPVARIANT_IS_BOOLEAN(*value)) {
        bool flag = NPVARIANT_TO_BOOLEAN(*value);
        log_debug("is boolean, value %d", flag);
    } else if (NPVARIANT_IS_INT32(*value)) {
        int num = NPVARIANT_TO_INT32(*value);
        log_debug("is int, value %d", num);
    } else if (NPVARIANT_IS_NULL(*value)) {
        log_debug("value is null");
    } else if (NPVARIANT_IS_VOID(*value)) {
        log_debug("value is void");
    } else if (NPVARIANT_IS_OBJECT(*value)) {
        log_debug("value is object");
    }    
}
Пример #14
0
NPError 
StatementObject::AddParam(const NPVariant *value)
{
  nsODBCParam* pRec = NULL;

  if (NPVARIANT_IS_VOID(*value) || NPVARIANT_IS_NULL(*value)) {
    pRec = new nsODBCParam();

  } else if (NPVARIANT_IS_BOOLEAN(*value)) {
    pRec = new nsODBCParam(NPVARIANT_TO_BOOLEAN(*value));

  } else if (NPVARIANT_IS_INT32(*value)) {
    pRec = new nsODBCParam(NPVARIANT_TO_INT32(*value));

  } else if (NPVARIANT_IS_DOUBLE(*value)) {
    double data = NPVARIANT_TO_DOUBLE(*value);
    double delta = ceil(data);

    if (data-0.000000001 <delta  && data+0.000000001 > delta)
        pRec = new nsODBCParam((int)data);
    else
        pRec = new nsODBCParam(data);
    //--pRec = new nsODBCParam(NPVARIANT_TO_DOUBLE(*value));

  } else if (NPVARIANT_IS_STRING(*value)) {
    pRec = new nsODBCParam((NPString*)&NPVARIANT_TO_STRING(*value));

  } else {
    NPN_SetException(this, "Unsupported parameter type");
    return NPERR_GENERIC_ERROR;
  }

  if (pRec)
    m_params.push_back(pRec);
  return NPERR_NO_ERROR;
}
Пример #15
0
bool Any::IsNull() const
{
	return NPVARIANT_IS_VOID(variant) || NPVARIANT_IS_NULL(variant);
}
Пример #16
0
bool toString(void *object, const NPVariant *args, uint32_t argCount, NPVariant *result) {

	GenericNPObject *map = (GenericNPObject *)object;

	if (!map || map->invalid) return false;

	// no args expected or cared for...

	std::string out;
	std::vector<NPVariant>::iterator it;
	for (it = map->numeric_mapper.begin(); it < map->numeric_mapper.end(); ++it) {

		if (NPVARIANT_IS_VOID(*it)) {

			out += ",";
		}
		else if (NPVARIANT_IS_NULL(*it)) {

			out += ",";
		}
		else if (NPVARIANT_IS_BOOLEAN(*it)) {

			if ((*it).value.boolValue) {

				out += "true,";
			}
			else {

				out += "false,";
			}
		}
		else if (NPVARIANT_IS_INT32(*it)) {

			char tmp[50];
			memset(tmp, 0, sizeof(tmp));
			_snprintf(tmp, 49, "%d,", (*it).value.intValue);
			out += tmp;
		}
		else if (NPVARIANT_IS_DOUBLE(*it)) {

			char tmp[50];
			memset(tmp, 0, sizeof(tmp));
			_snprintf(tmp, 49, "%f,", (*it).value.doubleValue);
			out += tmp;
		}
		else if (NPVARIANT_IS_STRING(*it)) {

			out += (*it).value.stringValue.UTF8Characters;
			out += ",";
		}
		else if (NPVARIANT_IS_OBJECT(*it)) {

			out += "[object],";
		}
	}

	// calculate how much space we need
	std::string::size_type size = out.length();

	char *s = (char *)NPNFuncs.memalloc(size * sizeof(char));
	if (NULL == s) {

		return false;
	}

	memcpy(s, out.c_str(), size);
	s[size - 1] = 0; // overwrite the last ","
	STRINGZ_TO_NPVARIANT(s, (*result));
	return true;
}
Пример #17
0
// This function is equivalent to the following JavaScript function:
// function FireEvent(strEventType, strDetail) {
//   var event = document.createEvent("CustomEvent");
//   event.initCustomEvent(strEventType, true, true, strDetail);
//   pluginObject.dispatchEvent(event);
// }
// 
// Uses following JavaScript code to listen to the event fired:
// pluginObject.addEventListener(strEventType, function(event) {
//    alert(event.detail);
// }
BOOL CPlugin::FireEvent(const CString &strEventType, const CString &strDetail)
{
  BOOL bOK = FALSE;
  NPObject* pWindow = NULL;
  NPVariant vDocument;
  VOID_TO_NPVARIANT(vDocument);
  NPVariant vEvent;
  NPObject* pDocument = NULL;
  VOID_TO_NPVARIANT(vEvent);
  NPObject *pEvent = NULL;
  NPObject* pPlugin = NULL;

  try
  {
    // get window object
    if (NPN_GetValue(m_pNPInstance, NPNVWindowNPObject, &pWindow) != NPERR_NO_ERROR || pWindow == NULL)
    {
      throw CString(_T("Cannot get window"));
    }

    // get window.document
    bOK = NPN_GetProperty(m_pNPInstance, pWindow, NPN_GetStringIdentifier("document"), &vDocument);
    if (!NPVARIANT_IS_OBJECT(vDocument) || !bOK)
    {
      throw CString(_T("Cannot get window.document"));
    }
    pDocument = NPVARIANT_TO_OBJECT(vDocument);

    // var event = document.createEvent("CustomEvent");
    if (pDocument) 
    {
      NPVariant arg;
      STRINGZ_TO_NPVARIANT(CStringToNPStringCharacters(_T("CustomEvent")), arg);
      bOK = NPN_Invoke(m_pNPInstance, pDocument, NPN_GetStringIdentifier("createEvent"), &arg, 1, &vEvent);
      NPN_ReleaseVariantValue(&arg);
      if (!NPVARIANT_IS_OBJECT(vEvent) || !bOK)
      {
        throw CString(_T("Cannot document.createEvent"));
      }
    }
    else 
    {
      throw CString(_T("window.document is null"));
    }
    pEvent = NPVARIANT_TO_OBJECT(vEvent);;

    // event.initCustomEvent(strEventType, true, true, strDetail);
    if (pEvent)
    {
      NPVariant args[4];
      STRINGZ_TO_NPVARIANT(CStringToNPStringCharacters(strEventType), args[0]);
      BOOLEAN_TO_NPVARIANT(true, args[1]);
      BOOLEAN_TO_NPVARIANT(true, args[2]);
      STRINGZ_TO_NPVARIANT(CStringToNPStringCharacters(strDetail), args[3]);
      NPVariant vResult;
      bOK = NPN_Invoke(m_pNPInstance, pEvent, NPN_GetStringIdentifier("initCustomEvent"), args, 4, &vResult);
      for (int i=0; i<4; i++)
      {
        NPN_ReleaseVariantValue(&args[i]);
      }
      NPN_ReleaseVariantValue(&vResult);
      if (!bOK)
      {
        throw CString(_T("Cannot event.initCustomEvent"));
      }
    }
    else
    {
      throw CString(_T("event is null"));
    }

    // get plugin object
    if (NPN_GetValue(m_pNPInstance, NPNVPluginElementNPObject, &pPlugin) != NPERR_NO_ERROR || pPlugin == NULL)
    {
      throw CString(_T("Cannot get window"));
    }


    // pluginObject.dispatchEvent(event);
    NPVariant vNotCanceled; 
    bOK = NPN_Invoke(m_pNPInstance, pPlugin, NPN_GetStringIdentifier("dispatchEvent"), &vEvent, 1, &vNotCanceled);
    NPN_ReleaseVariantValue(&vEvent);
    if (!bOK || !NPVARIANT_IS_BOOLEAN(vNotCanceled)) 
    {
      throw CString(_T("Cannot dispatchEvent"));
    }
    if (NPVARIANT_TO_BOOLEAN(vNotCanceled) != true)
    {
      throw CString(_T("Event is canceled"));
    }
  }
  catch (CString strMessage)
  {
    TRACE(_T("[CPlugin::FireEvent Exception] %s"), strMessage);
    bOK = FALSE;
  }
  if (pPlugin != NULL) NPN_ReleaseObject(pPlugin);
  if (!NPVARIANT_IS_VOID(vEvent))	NPN_ReleaseVariantValue(&vEvent);
  if (!NPVARIANT_IS_VOID(vDocument))	NPN_ReleaseVariantValue(&vDocument);
  if (pWindow != NULL) NPN_ReleaseObject(pWindow);
  return bOK;
}