FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
void FB::JSAPIImpl::FireEvent ( const std::string &  eventName,
const std::vector< variant > &  args 
)
protectedvirtual

Fires an event into javascript asynchronously.

This fires an event to all handlers attached to the given event in javascript.

IE:

document.getElementByID("plugin").attachEvent("onload", function() { alert("loaded!"); });

Firefox/Safari/Chrome/Opera:

// Note that the convention used by these browsers is that "on" is implied
document.getElementByID("plugin").addEventListener("load", function() { alert("loaded!"); }, false);;/.

You can then fire the event – from any thread – from the JSAPI object like so:

FireEvent("onload", FB::variant_list_of("param1")(2)(3.0));

Also note that registerEvent must be called from the constructor to register the event.

registerEvent("onload");
Parameters
eventNameName of the event. This event must start with "on"
argsThe arguments that should be sent to each attached event handler
See Also
registerEvent

Definition at line 151 of file JSAPIImpl.cpp.

152 {
153  if (!m_valid) // When invalidated, do nothing more
154  return;
155 
156  {
157  JSAPIImplPtr self(shared_from_this());
158  boost::recursive_mutex::scoped_lock _l(m_proxyMutex);
159  ProxyList::iterator proxyIt = m_proxies.begin();
160  while (proxyIt != m_proxies.end()) {
161  JSAPIImplPtr proxy(proxyIt->lock());
162  if (!proxy) {
163  // Since you can't use a shared_ptr in a destructor, there
164  // is no way for the proxy object to let us know when it goes
165  // away; thus when we find them, we remove them for efficiency
166  proxyIt = m_proxies.erase(proxyIt);
167  continue;
168  }
169 
170  VariantList newArgs = proxyProcessList(args, self, proxy);
171 
172  proxy->FireEvent(eventName, newArgs);
173  ++proxyIt;
174  }
175  }
176 
177  try {
178  fireAsyncEvent(eventName, args);
179  } catch (const FB::script_error&) {
180  // a script_error can be fired during shutdown when this is called
181  // from another thread; this should not be an error
182  }
183 }
std::vector< variant > VariantList
Defines an alias representing list of variants.
Definition: APITypes.h:64
Exception type; when thrown in a JSAPI method, a javascript exception will be thrown.
Definition: JSExceptions.h:28