Beispiel #1
0
void IGUIObject::ScriptEvent(const CStr& Action)
{
	auto it = m_ScriptHandlers.find(Action);
	if (it == m_ScriptHandlers.end())
		return;

	JSContext* cx = m_pGUI->GetScriptInterface()->GetContext();
	JSAutoRequest rq(cx);

	// Set up the 'mouse' parameter
	JS::RootedValue mouse(cx);
	m_pGUI->GetScriptInterface()->Eval("({})", &mouse);
	m_pGUI->GetScriptInterface()->SetProperty(mouse, "x", m_pGUI->m_MousePos.x, false);
	m_pGUI->GetScriptInterface()->SetProperty(mouse, "y", m_pGUI->m_MousePos.y, false);
	m_pGUI->GetScriptInterface()->SetProperty(mouse, "buttons", m_pGUI->m_MouseButtons, false);

	JS::AutoValueVector paramData(cx);
	paramData.append(mouse);
	JS::RootedObject obj(cx, GetJSObject());
	JS::RootedValue handlerVal(cx, JS::ObjectValue(*it->second));
	JS::RootedValue result(cx);
	bool ok = JS_CallFunctionValue(cx, obj, handlerVal, paramData, &result);
	if (!ok)
	{
		// We have no way to propagate the script exception, so just ignore it
		// and hope the caller checks JS_IsExceptionPending
	}
}
Beispiel #2
0
void IGUIObject::ScriptEvent(const CStr& Action, JS::HandleValue Argument)
{
	auto it = m_ScriptHandlers.find(Action);
	if (it == m_ScriptHandlers.end())
		return;

	JSContext* cx = m_pGUI->GetScriptInterface()->GetContext();
	JSAutoRequest rq(cx);
	JS::AutoValueVector paramData(cx);
	paramData.append(Argument.get());
	JS::RootedObject obj(cx, GetJSObject());
	JS::RootedValue handlerVal(cx, JS::ObjectValue(*it->second));
	JS::RootedValue result(cx);
	bool ok = JS_CallFunctionValue(cx, obj, handlerVal, paramData, &result);
	if (!ok)
	{
		JS_ReportError(cx, "Errors executing script action \"%s\"", Action.c_str());
	}
}
void CUPnPHeaderReader::DecodeManL(RHeaderField& aHeader) const
	{
	TPtrC8 rawData;
	aHeader.RawDataL(rawData);
	TInt remaining = rawData.Length();
	TPtrC8 token;
	TInt tokensFound = 0;
	while (remaining > 0)
		{
		remaining -= InetProtTextUtils::ExtractNextTokenFromList(rawData, token, KCommaChar);

		TInt pos = token.Locate(KSemiColonChar);
		if (pos < 0)
			{
			// No parameters. Just store the field value
			InetProtTextUtils::RemoveWhiteSpace(token, InetProtTextUtils::ERemoveBoth);
			SetNewFStringPartL(aHeader, tokensFound, token);
			}
		else if (pos==0)
			{
			// No valid ns-value. Just store the parameter.
			User::Leave(KErrUPnPDecodeMAN);
			}
		else
			{
			// parameter value(s) exist.

			if (pos==token.Length())
				// if no field value exists. i.e. an invalid header
				User::Leave(KErrUPnPDecodeMAN);

			// store the field
			TPtrC8 fieldValue(token.Left(pos));
			TPtrC8 parameters(token.Mid(pos+1));
			InetProtTextUtils::RemoveWhiteSpace(fieldValue, InetProtTextUtils::ERemoveBoth);

			CHeaderFieldPart* part = SetNewFStringPartL(aHeader, tokensFound, fieldValue);

			TPtrC8 thisParam;
			do {
				// check if there is another parameter
				pos = parameters.Locate(KSemiColonChar);
				if (pos > 0)
					{
					if (pos==token.Length())
						// if no field value exists. i.e. an invalid header
						User::Leave(KErrUPnPDecodeMAN);

					thisParam.Set(parameters.Left(pos));
					parameters.Set(parameters.Mid(pos+1));
					}
				else
					thisParam.Set(parameters);

				
				TInt pPos = thisParam.Locate(KEqualsChar);
				if (pPos <= 0 || pPos==thisParam.Length())
					// Invalid parameter, missing '=' char, or missing field value.
					User::Leave(KErrUPnPDecodeMAN);

				TPtrC8 paramField(thisParam.Left(pPos));
 				TPtrC8 paramData(thisParam.Mid(pPos + 1));

				SetNewFStringParamL(*part, paramField, paramData);

				} while (pos > 0);
			}
		++tokensFound;
		}
	}