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

Sets the value of a property.

Parameters
propertyNameName of the property.
valueThe value.

Implements FB::JSAPI.

Definition at line 304 of file IDispatchAPI.cpp.

References FB::utf8_to_wstring().

305 {
306  if (m_browser.expired() || m_obj.expired())
307  return;
308 
309  ActiveXBrowserHostPtr browser(getHost());
310  if (!browser->isMainThread()) {
311  browser->CallOnMainThread(boost::bind((FB::SetPropertyType)&IDispatchAPI::SetProperty, this, propertyName, value));
312  return;
313  }
314 
315  if (is_JSAPI) {
316  FB::JSAPIPtr tmp = inner.lock();
317  if (tmp)
318  tmp->SetProperty(propertyName, value);
319  return;
320  }
321 
322  DISPID dispId = getIDForName(FB::utf8_to_wstring(propertyName));
323  if (dispId == DISPID_UNKNOWN) {
324  throw FB::script_error("Could not set property");
325  }
326 
327  CComVariant arg[1];
328  VARIANTARG rawArg[1];
329  DISPID namedArg[1];
330  DISPPARAMS params;
331  params.cArgs = 1;
332  params.cNamedArgs = 1;
333  params.rgdispidNamedArgs = namedArg;
334  params.rgvarg = rawArg;
335 
336  browser->getComVariant(&arg[0], value);
337  rawArg[0] = arg[0];
338  namedArg[0] = DISPID_PROPERTYPUT;
339 
340  HRESULT hr;
341  CComVariant result;
342  CComExcepInfo exceptionInfo;
343  CComQIPtr<IDispatchEx> dispatchEx(getIDispatch());
344  if (dispatchEx) {
345  hr = dispatchEx->InvokeEx(dispId, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUTREF, &params,
346  &result, &exceptionInfo, NULL);
347  if (hr == DISP_E_MEMBERNOTFOUND) {
348  hr = dispatchEx->InvokeEx(dispId, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUT, &params,
349  NULL, &exceptionInfo, NULL);
350  }
351  } else {
352  hr = getIDispatch()->Invoke(dispId, IID_NULL, LOCALE_USER_DEFAULT,
353  DISPATCH_PROPERTYPUT, &params, &result, &exceptionInfo, NULL);
354  }
355 
356  if (FAILED(hr)) {
357  throw FB::script_error("Could not set property");
358  }
359 }
void SetProperty(const std::string &propertyName, const FB::variant &value)
Sets the value of a 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
Exception type; when thrown in a JSAPI method, a javascript exception will be thrown.
Definition: JSExceptions.h:28
void(JSAPI::* SetPropertyType)(const std::string &, const variant &)
Defines an alias representing a function pointer to JSAPI::SetProperty.
Definition: APITypes.h:176
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: