Exemplo n.º 1
0
void IDispatchAPI::SetProperty(const std::string& propertyName, const FB::variant& value)
{
    if (m_browser.expired() || m_obj.expired())
        return;

    ActiveXBrowserHostPtr browser(getHost());
    if (!browser->isMainThread()) {
        browser->CallOnMainThread(boost::bind((FB::SetPropertyType)&IDispatchAPI::SetProperty, this, propertyName, value));
        return;
    }

    if (is_JSAPI) {
        FB::JSAPIPtr tmp = inner.lock();
        if (tmp)
            tmp->SetProperty(propertyName, value);
        return;
    }

    DISPID dispId = getIDForName(FB::utf8_to_wstring(propertyName));
    if (dispId == DISPID_UNKNOWN) {
        throw FB::script_error("Could not set property");
    }

    CComVariant arg[1];
    VARIANTARG rawArg[1];
    DISPID namedArg[1];
    DISPPARAMS params;
    params.cArgs = 1;
    params.cNamedArgs = 1;
    params.rgdispidNamedArgs = namedArg;
    params.rgvarg = rawArg;

    browser->getComVariant(&arg[0], value);
    rawArg[0] = arg[0];
    namedArg[0] = DISPID_PROPERTYPUT;

    HRESULT hr;
    CComVariant result;
    CComExcepInfo exceptionInfo;
    CComQIPtr<IDispatchEx> dispatchEx(getIDispatch());
    if (dispatchEx) {
        hr = dispatchEx->InvokeEx(dispId, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUTREF, &params,
            &result, &exceptionInfo, NULL);
        if (hr == DISP_E_MEMBERNOTFOUND) {
            hr = dispatchEx->InvokeEx(dispId, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUT, &params,
                NULL, &exceptionInfo, NULL);
        }
    } else {
        hr = getIDispatch()->Invoke(dispId, IID_NULL, LOCALE_USER_DEFAULT,
            DISPATCH_PROPERTYPUT, &params, &result, &exceptionInfo, NULL);
    }

    if (FAILED(hr)) {
        throw FB::script_error("Could not set property");
    }
}
Exemplo n.º 2
0
void IDispatchAPI::SetProperty(int idx, const FB::variant& value)
{
    if (is_JSAPI) {
        FB::JSAPIPtr tmp = inner.lock();
        if (tmp)
            tmp->SetProperty(idx, value);
    }

    FB::variant sIdx(idx);
    SetProperty(sIdx.convert_cast<std::string>(), value);
}
Exemplo n.º 3
0
void NPObjectAPI::SetProperty(const std::string& propertyName, const FB::variant& value)
{
    if (m_browser.expired())
        return;

    NpapiBrowserHostPtr browser(getHost());
    if (!browser->isMainThread()) {
        browser->CallOnMainThread(boost::bind((FB::SetPropertyType)&JSAPI::SetProperty, this, propertyName, value));
        return;
    }
    if (is_JSAPI) {
        FB::JSAPIPtr tmp = inner.lock();
        if (tmp)
            tmp->SetProperty(propertyName, value);
        return;
    }
    NPVariant val;
    browser->getNPVariant(&val, value);
    bool res = browser->SetProperty(obj, browser->GetStringIdentifier(propertyName.c_str()), &val);
    browser->ReleaseVariantValue(&val);
    if (!res) {
        throw script_error(propertyName.c_str());
    }
}