Exemple #1
0
bool NPObjectAPI::HasProperty(int idx) const
{
    if (m_browser.expired())
        return false;

    NpapiBrowserHostPtr browser(getHost());
    if (is_JSAPI) {
        FB::JSAPIPtr tmp = inner.lock();
        if (tmp)
            return tmp->HasProperty(idx);
        else 
            return false;
    }
    return browser->HasProperty(obj, browser->GetIntIdentifier(idx));
}
bool IDispatchAPI::HasProperty(const std::string& propertyName) const
{
    if (m_browser.expired() || m_obj.expired())
        return false;

    ActiveXBrowserHostPtr browser(getHost());
    if (!browser->isMainThread()) {
        typedef bool (IDispatchAPI::*HasPropertyType)(const std::string&) const;
        return browser->CallOnMainThread(boost::bind((HasPropertyType)&IDispatchAPI::HasProperty, this, propertyName));
    }

    if (is_JSAPI) {
        FB::JSAPIPtr tmp = inner.lock();
        if (!tmp) {
            return false;
        }
        return tmp->HasProperty(propertyName);
    }

    DISPID dispId = getIDForName(FB::utf8_to_wstring(propertyName));
    if (dispId == DISPID_UNKNOWN && propertyName != "toString") {
        return false;
    }

    DISPPARAMS params;
    params.cArgs = 0;
    params.cNamedArgs = 0;

    // the only way to find out if the property actually exists or not is to try to get it
    HRESULT hr;
    CComVariant result;
    CComExcepInfo exceptionInfo;
    try {
        CComQIPtr<IDispatchEx> dispatchEx(getIDispatch());
        if (dispatchEx) {
            hr = dispatchEx->InvokeEx(dispId, LOCALE_USER_DEFAULT, 
                DISPATCH_PROPERTYGET, &params, &result, &exceptionInfo, NULL);
        } else {
            hr = getIDispatch()->Invoke(dispId, IID_NULL, LOCALE_USER_DEFAULT,
                DISPATCH_PROPERTYGET, &params, &result, &exceptionInfo, NULL);
        }
        return SUCCEEDED(hr);
    } catch (...) { return false; }
}
Exemple #3
0
bool NPObjectAPI::HasProperty(const std::string& propertyName) const
{
    if (m_browser.expired())
        return false;

    NpapiBrowserHostPtr browser(getHost());
    if (!browser->isMainThread()) {
        typedef bool (NPObjectAPI::*curtype)(const std::string&) const;
        return browser->CallOnMainThread(boost::bind((curtype)&NPObjectAPI::HasProperty, this, propertyName));
    }
    if (is_JSAPI) {
        FB::JSAPIPtr tmp = inner.lock();
        if (tmp)
            return tmp->HasProperty(propertyName);
        else 
            return false;
    }
    return browser->HasProperty(obj, browser->GetStringIdentifier(propertyName.c_str()));
}
Exemple #4
0
bool IDispatchAPI::HasProperty(const std::string& propertyName) const
{
    if (!host->isMainThread()) {
        typedef bool (IDispatchAPI::*HasPropertyType)(const std::string&) const;
        return host->CallOnMainThread(boost::bind((HasPropertyType)&IDispatchAPI::HasProperty, this, propertyName));
    }
    if (is_JSAPI) {
        FB::JSAPIPtr tmp = inner.lock();
        if (tmp)
            return tmp->HasProperty(propertyName);
        else 
            return false;
    }

    DISPID id = getIDForName(FB::utf8_to_wstring(propertyName));
    if (id == -1 && propertyName != "toString")
        return false;

	DISPPARAMS params;
    params.cArgs = 0;
    params.cNamedArgs = 0;

	// The only way to find out if the property actually exists or not is to try to get it; 
    VARIANT res;
    EXCEPINFO eInfo;
    HRESULT hr = E_NOTIMPL;
    CComQIPtr<IDispatchEx> dispex(m_obj);
    if (dispex) {
        hr = dispex->InvokeEx(id, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET, &params,
            &res, &eInfo, NULL);
    } else {
        hr = m_obj->Invoke(getIDForName(FB::utf8_to_wstring(propertyName)), IID_NULL, LOCALE_USER_DEFAULT,
            DISPATCH_PROPERTYGET, &params, &res, NULL, NULL);
    }
    if (SUCCEEDED(hr)) {
        return true;
    } else {
        return false;
    }
}