WebBrowserHost.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //
  2. // Copyright (c) 2014-2016, THUNDERBEAST GAMES LLC All rights reserved
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include <Atomic/Core/Object.h>
  24. namespace Atomic
  25. {
  26. class WebBrowserHostPrivate;
  27. class WebClient;
  28. typedef HashMap<String, HashMap<String, Variant>> GlobalPropertyMap;
  29. /// Browser host subsystem, responsible for initializing CEF
  30. class WebBrowserHost : public Object
  31. {
  32. ATOMIC_OBJECT(WebBrowserHost, Object);
  33. public:
  34. /// Construct.
  35. WebBrowserHost(Context* context);
  36. /// Destruct.
  37. virtual ~WebBrowserHost();
  38. void ClearCookies(const String& url = String::EMPTY, const String& cookieName = String::EMPTY);
  39. /// Set global property object values, available as read only on page
  40. static void SetGlobalBoolProperty(const String& globalVar, const String& property, bool value);
  41. static void SetGlobalStringProperty(const String& globalVar, const String& property, const String& value);
  42. static void SetGlobalNumberProperty(const String& globalVar, const String& property, double value);
  43. static const GlobalPropertyMap& GetGlobalProperties() { return globalProperties_; }
  44. // Configuration settings that must be set before creating WebBrowserHost subsystem
  45. /// Set the absolute root path for the cache, this is combined with the cache name to generate the full cache path
  46. static void SetRootCacheFolder(const String& rootCacheFolder) { rootCacheFolder_ = rootCacheFolder; }
  47. /// Set the cache name which is combined with the root cache folder to generate an absolute path to the browser cache
  48. static void SetCacheName(const String& cacheName) { cacheName_ = cacheName; }
  49. /// Set value that will be returned as the User-Agent HTTP header.
  50. static void SetUserAgent(const String& userAgent) { userAgent_ = userAgent; }
  51. /// Set value that will be inserted as the product portion of the default User-Agent string
  52. static void SetProductVersion(const String& productVersion) { productVersion_ = productVersion; }
  53. /// Set to a value between 1024 and 65535 to enable remote debugging on the specified port
  54. static void SetDebugPort(int debugPort) { debugPort_ = debugPort; }
  55. /// Set whether web security is enabled
  56. static void SetWebSecurity(bool enabled) { webSecurity_ = enabled; }
  57. /// Set the name of the function used for JavaScript message queries
  58. static void SetJSMessageQueryFunctionName(const String& name) { jsMessageQueryFunctionName_ = name; }
  59. /// Set the name of the function used to cancel JavaScript message queries
  60. static void SetJSMessageQueryCancelFunctionName(const String& name) { jsMessageQueryCancelFunctionName_ = name; }
  61. /// Get the absolute root path for the cache, this is combined with the cache name to generate the full cache path
  62. static const String& GetRootCacheFolder() { return rootCacheFolder_; }
  63. /// Get the cache name which is combined with the root cache folder to generate an absolute path to the browser cache
  64. static const String& GetCacheName() { return cacheName_; }
  65. /// Get User-Agent of the HTTP header. If empty the default User-Agent string will be used
  66. static const String& GetUserAgent() { return userAgent_; }
  67. /// Get value that will be inserted as the product portion of the default User-Agent string. If empty the Chromium product version will be used
  68. static const String& GetProductVersion() { return productVersion_; }
  69. /// Get whether web security is enabled
  70. static bool GetWebSecurity() { return webSecurity_; }
  71. /// Get the name of the function used for JavaScript message queries
  72. static const String& GetJSMessageQueryFunctionName() { return jsMessageQueryFunctionName_; }
  73. /// Get the name of the function used to cancel JavaScript message queries
  74. static const String& GetJSMessageQueryCancelFunctionName() { return jsMessageQueryCancelFunctionName_; }
  75. private:
  76. void HandleUpdate(StringHash eventType, VariantMap& eventData);
  77. static void SetGlobalProperty(const String& globalVar, const String& property, Variant& value);
  78. WebBrowserHostPrivate* d_;
  79. static WeakPtr<WebBrowserHost> instance_;
  80. static GlobalPropertyMap globalProperties_;
  81. // configuration settings that must be set before WebBrowserHost subsystem is created
  82. static String userAgent_;
  83. static String productVersion_;
  84. static String rootCacheFolder_;
  85. static String cacheName_;
  86. static String jsMessageQueryFunctionName_;
  87. static String jsMessageQueryCancelFunctionName_;
  88. static int debugPort_;
  89. static bool webSecurity_;
  90. };
  91. }