FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
bool IDispatchAPI::HasProperty ( const std::string &  propertyName) const
virtual

Query if 'propertyName' is a valid property.

Parameters
propertyNameName of the property.
Returns
true if property exists, false if not.

Implements FB::JSAPI.

Definition at line 200 of file IDispatchAPI.cpp.

References FB::utf8_to_wstring().

201 {
202  if (m_browser.expired() || m_obj.expired())
203  return false;
204 
205  ActiveXBrowserHostPtr browser(getHost());
206  if (!browser->isMainThread()) {
207  typedef bool (IDispatchAPI::*HasPropertyType)(const std::string&) const;
208  return browser->CallOnMainThread(boost::bind((HasPropertyType)&IDispatchAPI::HasProperty, this, propertyName));
209  }
210 
211  if (is_JSAPI) {
212  FB::JSAPIPtr tmp = inner.lock();
213  if (!tmp) {
214  return false;
215  }
216  return tmp->HasProperty(propertyName);
217  }
218 
219  DISPID dispId = getIDForName(FB::utf8_to_wstring(propertyName));
220  if (dispId == DISPID_UNKNOWN && propertyName != "toString") {
221  return false;
222  }
223 
224  DISPPARAMS params;
225  params.cArgs = 0;
226  params.cNamedArgs = 0;
227 
228  // the only way to find out if the property actually exists or not is to try to get it
229  HRESULT hr;
230  CComVariant result;
231  CComExcepInfo exceptionInfo;
232  try {
233  CComQIPtr<IDispatchEx> dispatchEx(getIDispatch());
234  if (dispatchEx) {
235  hr = dispatchEx->InvokeEx(dispId, LOCALE_USER_DEFAULT,
236  DISPATCH_PROPERTYGET, &params, &result, &exceptionInfo, NULL);
237  } else {
238  hr = getIDispatch()->Invoke(dispId, IID_NULL, LOCALE_USER_DEFAULT,
239  DISPATCH_PROPERTYGET, &params, &result, &exceptionInfo, NULL);
240  }
241  return SUCCEEDED(hr);
242  } catch (...) { return false; }
243 }
Provide a JSObject implementation to wrap a IDispatch ActiveX object.
Definition: IDispatchAPI.h:33
bool HasProperty(const std::string &propertyName) const
Query if 'propertyName' is a valid property.
boost::shared_ptr< FB::JSAPI > JSAPIPtr
Defines an alias for a JSAPI shared_ptr (you should never use a JSAPI* directly)
Definition: APITypes.h:94
std::wstring utf8_to_wstring(const std::string &src)
Accepts a UTF8-encoded std::string and returns a std::wstring.
Definition: utf8_tools.cpp:50

Here is the call graph for this function: