- Page restrictions apply
- Added by Automation System, last edited by Automation System on Oct 11, 2012 (view change)
APITypes.h
00001 /**********************************************************\ 00002 Original Author: Richard Bateman (taxilian) 00003 00004 Created: Sept 24, 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 Richard Bateman, Firebreath development team 00013 \**********************************************************/ 00014 00015 #pragma once 00016 #ifndef H_FB_APITYPES 00017 #define H_FB_APITYPES 00018 00019 #include <string> 00020 #include <vector> 00021 #include <map> 00022 #include <set> 00023 #include <boost/function.hpp> 00024 #include <boost/shared_ptr.hpp> 00025 #include <boost/variant/variant_fwd.hpp> 00026 #include "fb_stdint.h" 00027 #include "FBPointers.h" 00028 00041 namespace FB 00042 { 00043 FB_FORWARD_PTR(BrowserHost); 00044 FB_FORWARD_PTR(JSAPI); 00045 FB_FORWARD_PTR(JSObject); 00046 class variant; 00047 namespace variant_detail { 00048 // Note that null translates to returning NULL 00049 struct null; 00050 // Note that empty translates into return VOID (undefined) 00051 struct empty; 00052 } 00053 00054 // Variant list 00055 00064 typedef std::vector<variant> VariantList; 00065 00072 typedef std::map<std::string, variant> VariantMap; 00073 00079 typedef std::set<std::string> StringSet; 00080 00081 // FB pointer types 00082 00088 typedef boost::weak_ptr<FB::JSAPI> JSAPIWeakPtr; 00094 typedef boost::shared_ptr<FB::JSAPI> JSAPIPtr; 00095 00102 typedef boost::weak_ptr<FB::JSObject> JSObjectWeakPtr; 00109 typedef boost::shared_ptr<FB::JSObject> JSObjectPtr; 00110 00117 typedef boost::shared_ptr<FB::BrowserHost> BrowserHostPtr; 00118 00119 // backwards compability typedefs 00120 00127 typedef BrowserHost BrowserHostWrapper; 00128 00135 typedef JSObject BrowserObjectAPI; 00136 00143 typedef JSAPIPtr JSOutObject; 00144 00145 // deprecation warnings 00146 00147 #if defined(_MSC_VER) 00148 # pragma deprecated(BrowserHostWrapper, BrowserObjectAPI, JSOutObject) 00149 #elif defined(__GNUC__) 00150 typedef BrowserHost BrowserHostWrapper __attribute__((deprecated)); 00151 typedef JSObject BrowserObjectAPI __attribute__((deprecated)); 00152 typedef JSAPIPtr JSOutObject __attribute__((deprecated)); 00153 #endif 00154 00155 // dynamically cast a FB pointer 00156 00168 template<class T, class U> 00169 boost::shared_ptr<T> ptr_cast(boost::shared_ptr<U> const & r); 00170 00172 typedef variant (JSAPI::*InvokeType)(const std::string&, const std::vector<variant>&); 00174 typedef variant (JSAPI::*ConstructType)(const std::vector<variant>&); 00176 typedef void (JSAPI::*SetPropertyType)(const std::string&, const variant&); 00178 typedef variant (JSAPI::*GetPropertyType)(const std::string&); 00180 typedef void (JSAPI::*RemovePropertyType)(const std::string&); 00181 00208 struct CatchAll { 00209 typedef FB::VariantList value_type; 00210 FB::VariantList value; 00211 }; 00212 00213 // Special Variant types 00214 typedef FB::variant_detail::empty FBVoid; 00215 typedef FB::variant_detail::null FBNull; 00216 struct FBDateString { 00217 public: 00218 FBDateString() { } 00219 FBDateString(const FBDateString& rhs) : date(rhs.date) { } 00220 FBDateString(const std::string &dstr) : date(dstr) { } 00221 00222 FBDateString& operator=(const std::string& dstr) { date = dstr; return *this; } 00223 std::string getValue() { return date; } 00224 void setValue(std::string value) { date = value; } 00225 bool operator<(const std::string& rh) const 00226 { 00227 return date < rh; 00228 } 00229 bool operator<(const FBDateString& rh) const 00230 { 00231 return date < rh.date; 00232 } 00233 00234 protected: 00235 std::string date; 00236 }; 00237 00238 // JSAPI methods 00239 00240 class JSAPI; 00242 typedef variant (JSAPI::*CallMethodPtr)(const std::vector<variant>&); 00244 struct MethodInfo { 00245 MethodInfo() : callFunc(NULL) { } 00246 MethodInfo(CallMethodPtr callFunc) : callFunc(callFunc) { } 00247 MethodInfo(const MethodInfo &rh) : callFunc(rh.callFunc) { } 00248 CallMethodPtr callFunc; 00249 }; 00250 00252 typedef std::map<std::string, MethodInfo> MethodMap; 00253 00254 // JSAPI properties 00255 00256 00258 typedef variant (JSAPI::*GetPropPtr)(); 00260 typedef void (JSAPI::*SetPropPtr)(const variant& value); 00262 struct PropertyInfo { 00263 PropertyInfo() : getFunc(NULL), setFunc(NULL) { } 00264 PropertyInfo(GetPropPtr getFunc, SetPropPtr setFunc) : getFunc(getFunc), setFunc(setFunc) { } 00265 PropertyInfo(const PropertyInfo &rh) : getFunc(rh.getFunc), setFunc(rh.setFunc) { } 00266 GetPropPtr getFunc; 00267 SetPropPtr setFunc; 00268 }; 00269 00271 typedef std::map<std::string, PropertyInfo> PropertyMap; 00272 00273 // new style JSAPI methods 00275 typedef int SecurityZone; 00276 00278 enum SecurityLevel { 00279 SecurityScope_Public = 0, 00280 SecurityScope_Protected = 2, 00281 SecurityScope_Private = 4, 00282 SecurityScope_Local = 6 00283 }; 00284 00286 typedef boost::function<variant (const std::vector<variant>&)> CallMethodFunctor; 00287 struct MethodFunctors 00288 { 00289 CallMethodFunctor call; 00290 SecurityZone zone; 00291 MethodFunctors() : call() {} 00292 MethodFunctors(const CallMethodFunctor& call) : call(call) {} 00293 MethodFunctors(const SecurityZone& zone, const CallMethodFunctor& call) : call(call), zone(zone) {} 00294 MethodFunctors(const MethodFunctors& m) : call(m.call) {} 00295 MethodFunctors& operator=(const MethodFunctors& rhs) { 00296 call = rhs.call; 00297 zone = rhs.zone; 00298 return *this; 00299 } 00300 }; 00302 typedef std::map<std::string, MethodFunctors> MethodFunctorMap; 00303 00304 // new style JSAPI properties 00305 00307 typedef boost::function<FB::variant ()> GetPropFunctor; 00309 typedef boost::function<void (const FB::variant&)> SetPropFunctor; 00311 struct PropertyFunctors 00312 { 00313 GetPropFunctor get; 00314 SetPropFunctor set; 00315 PropertyFunctors() : get(), set() {} 00316 PropertyFunctors(const GetPropFunctor& get, const SetPropFunctor& set) 00317 : get(get), set(set) {} 00318 PropertyFunctors(const PropertyFunctors& p) 00319 : get(p.get), set(p.set) {} 00320 PropertyFunctors& operator=(const PropertyFunctors& rhs) { 00321 get = rhs.get; 00322 set = rhs.set; 00323 return *this; 00324 } 00325 }; 00327 typedef std::map<std::string, PropertyFunctors> PropertyFunctorsMap; 00328 00329 // JSAPI event handlers 00330 00331 typedef std::pair<std::string, FB::JSObjectPtr> EventPair; 00332 typedef std::multimap<std::string, FB::JSObjectPtr> EventMultiMap; 00333 typedef std::map<void*, FB::JSObjectPtr> EventIFaceMap; 00334 typedef std::map<std::string, FB::JSObjectPtr> EventSingleMap; 00335 00336 // implementation details 00337 00338 template<class T, class U> 00339 boost::shared_ptr<T> ptr_cast(boost::shared_ptr<U> const & r) 00340 { 00341 return boost::dynamic_pointer_cast<T>(r); 00342 } 00343 00344 namespace boost_variant { 00345 typedef boost::variant<long, int, double, std::string, FB::JSAPIPtr, FB::JSObjectPtr, FB::FBNull, FB::FBVoid> fb_compat; 00346 typedef boost::variant<long, int, double, float, std::string, FB::FBNull, FB::FBVoid> primitives; 00347 typedef boost::variant<std::string, FB::StringSet> strings; 00348 } 00349 00350 struct Rect { 00351 int32_t top; 00352 int32_t left; 00353 int32_t bottom; 00354 int32_t right; 00355 }; 00356 } 00357 00358 // This needs to be included after all our classes are defined because it relies on types defined in this file 00359 // TODO: can this be done better? 00360 #include "variant.h" 00361 00362 #endif 00363
Generated on 25 May 2013 for FireBreath by
1.6.1
Labels
