- Page restrictions apply
- Added by Automation System, last edited by Automation System on Oct 11, 2012 (view change)
JSAPIAuto.h
00001 /**********************************************************\ 00002 Original Author: Georg Fritzsche 00003 00004 Created: November 7, 2009 00005 License: Dual license model; choose one of two: 00006 New BSD License 00007 http://www.opensource.org/licenses/bsd-license.php 00008 - or - 00009 GNU Lesser General Public License, version 2.1 00010 http://www.gnu.org/licenses/lgpl-2.1.html 00011 00012 Copyright 2009 Georg Fritzsche, Firebreath development team 00013 \**********************************************************/ 00014 00015 #pragma once 00016 #ifndef JSAPIAUTO_H 00017 #define JSAPIAUTO_H 00018 00019 #include <deque> 00020 #include <vector> 00021 #include <string> 00022 #include <boost/thread/recursive_mutex.hpp> 00023 #include <boost/tuple/tuple.hpp> 00024 #include <boost/tuple/tuple_comparison.hpp> 00025 #include "JSAPIImpl.h" 00026 #include "MethodConverter.h" 00027 #include "PropertyConverter.h" 00028 #include "Util/typesafe_event.h" 00029 00030 namespace FB { 00031 FB_FORWARD_PTR(JSFunction); 00032 00047 00094 class JSAPIAuto : public JSAPIImpl 00095 { 00096 protected: 00097 struct Attribute { 00098 bool operator<(const Attribute& rh) const 00099 { 00100 return value < rh.value; 00101 } 00102 FB::variant value; 00103 bool readonly; 00104 }; 00105 typedef std::map<boost::tuple<std::string, FB::SecurityZone>, FB::JSFunctionPtr> MethodObjectMap; 00106 typedef std::map<std::string, FB::SecurityZone> ZoneMap; 00107 typedef std::map<std::string, Attribute> AttributeMap; 00108 00109 public: 00111 JSAPIAuto(const std::string& description = "<JSAPI-Auto Javascript Object>"); 00112 JSAPIAuto(const SecurityZone& securityLevel, const std::string& description = "<JSAPI-Auto Secure Javascript Object>"); 00113 typedef std::deque<SecurityZone> ZoneStack; 00114 00115 void init(); 00116 00117 virtual ~JSAPIAuto(); 00118 00132 virtual void registerAttribute(const std::string &name, const FB::variant& value, bool readonly = false); 00133 00150 virtual void setReserved(const std::string &name) 00151 { 00152 m_reservedMembers.insert(name); 00153 } 00154 00168 bool isReserved( const std::string& propertyName ) const 00169 { 00170 return m_reservedMembers.find(propertyName) != m_reservedMembers.end(); 00171 } 00172 00173 virtual void getMemberNames(std::vector<std::string> &nameVector) const; 00174 virtual size_t getMemberCount() const; 00175 00176 virtual variant Invoke(const std::string& methodName, const std::vector<variant>& args); 00177 virtual variant Construct(const std::vector<variant>& args); 00178 virtual JSAPIPtr GetMethodObject(const std::string& methodObjName); 00179 00180 virtual void unregisterMethod(const std::wstring& name) 00181 { 00182 unregisterMethod(FB::wstring_to_utf8(name)); 00183 } 00195 virtual void unregisterMethod(const std::string& name); 00196 00197 virtual void registerMethod(const std::wstring& name, const CallMethodFunctor& func) 00198 { 00199 registerMethod(FB::wstring_to_utf8(name), func); 00200 } 00226 virtual void registerMethod(const std::string& name, const CallMethodFunctor& func); 00227 00228 virtual bool HasMethod(const std::string& methodName) const; 00229 virtual bool HasMethodObject(const std::string& methodObjName) const; 00230 virtual bool HasProperty(const std::string& propertyName) const; 00231 virtual bool HasProperty(int idx) const; 00232 00233 virtual void registerProperty(const std::wstring& name, const PropertyFunctors& propFuncs); 00234 00258 virtual void registerProperty(const std::string& name, const PropertyFunctors& propFuncs); 00259 00260 virtual void unregisterProperty(const std::wstring& name); 00272 virtual void unregisterProperty(const std::string& name); 00273 00274 virtual variant GetProperty(const std::string& propertyName); 00275 virtual void SetProperty(const std::string& propertyName, const variant& value); 00276 virtual void RemoveProperty(const std::string& propertyName); 00277 virtual variant GetProperty(int idx); 00278 virtual void SetProperty(int idx, const variant& value); 00279 virtual void RemoveProperty(int idx); 00280 00281 virtual void FireJSEvent(const std::string& eventName, const FB::VariantMap &members, const FB::VariantList &arguments); 00282 virtual void fireAsyncEvent( const std::string& eventName, const std::vector<variant>& args ); 00283 00293 virtual std::string ToString() 00294 { 00295 return m_description; 00296 } 00297 00306 virtual bool get_valid() 00307 { 00308 return true; 00309 } 00310 00325 virtual FB::variant getAttribute(const std::string& name); 00339 virtual void setAttribute(const std::string& name, const FB::variant& value); 00352 virtual void unregisterAttribute(const std::string& name); 00353 00354 protected: 00355 bool memberAccessible( ZoneMap::const_iterator it ) const 00356 { 00357 return (it != m_zoneMap.end()) && getZone() >= it->second; 00358 } 00359 00360 protected: 00361 // Stores Method Objects -- JSAPI proxy objects for calling a method on this object 00362 MethodObjectMap m_methodObjectMap; 00363 // Stores the methods exposed to JS 00364 MethodFunctorMap m_methodFunctorMap; 00365 // Stores the properties exposed to JS 00366 PropertyFunctorsMap m_propertyFunctorsMap; 00367 // Keeps track of the security zone of each member 00368 ZoneMap m_zoneMap; 00369 00370 const std::string m_description; 00371 00372 AttributeMap m_attributes; 00373 FB::StringSet m_reservedMembers; 00374 bool m_allowDynamicAttributes; 00375 bool m_allowRemoveProperties; 00376 bool m_allowMethodObjects; 00377 public: 00378 static bool s_allowDynamicAttributes; 00379 static bool s_allowRemoveProperties; 00380 static bool s_allowMethodObjects; 00381 }; 00382 00383 }; 00384 00385 #endif // JSAPIAUTO_H 00386
Generated on 24 May 2013 for FireBreath by
1.6.1
Labels
