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

Gets a property value.

Parameters
propertyNameName of the property.
Returns
The property value

Implements FB::JSAPI.

Definition at line 252 of file IDispatchAPI.cpp.

References FB::utf8_to_wstring().

253 {
254  if (m_browser.expired() || m_obj.expired())
255  return FB::FBVoid();
256 
257  ActiveXBrowserHostPtr browser(getHost());
258  if (!browser->isMainThread()) {
259  return browser->CallOnMainThread(boost::bind((FB::GetPropertyType)&IDispatchAPI::GetProperty, this, propertyName));
260  }
261 
262  if (is_JSAPI) {
263  FB::JSAPIPtr tmp = inner.lock();
264  if (!tmp) {
265  return false;
266  }
267  return tmp->GetProperty(propertyName);
268  }
269 
270  DISPID dispId = getIDForName(FB::utf8_to_wstring(propertyName));
271  if (dispId == DISPID_UNKNOWN && propertyName != "toString") {
272  throw FB::script_error("Could not get property");
273  }
274 
275  // TODO: how can toString == DISPID_UNKNOWN work?
276 
277  DISPPARAMS params;
278  params.cArgs = 0;
279  params.cNamedArgs = 0;
280 
281  HRESULT hr;
282  CComVariant result;
283  CComExcepInfo exceptionInfo;
284  try {
285  CComQIPtr<IDispatchEx> dispatchEx(getIDispatch());
286  if (dispatchEx) {
287  hr = dispatchEx->InvokeEx(dispId, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET, &params,
288  &result, &exceptionInfo, NULL);
289  } else {
290  hr = getIDispatch()->Invoke(dispId, IID_NULL, LOCALE_USER_DEFAULT,
291  DISPATCH_PROPERTYGET, &params, &result, &exceptionInfo, NULL);
292  }
293 
294  if (FAILED(hr)) {
295  throw FB::script_error("Could not get property");
296  }
297 
298  return browser->getVariant(&result);
299  } catch (...) {
300  throw FB::script_error("Could not get property");
301  }
302 }
variant(JSAPI::* GetPropertyType)(const std::string &)
Defines an alias representing a function pointer to JSAPI::GetProperty.
Definition: APITypes.h:178
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
Exception type; when thrown in a JSAPI method, a javascript exception will be thrown.
Definition: JSExceptions.h:28
FB::variant GetProperty(const std::string &propertyName)
Gets a property value.
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: