WebBrowserHost.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 ATOMIC_API WebBrowserHost : public Object
  31. {
  32. OBJECT(WebBrowserHost);
  33. public:
  34. /// Construct.
  35. WebBrowserHost(Context* context);
  36. /// Destruct.
  37. virtual ~WebBrowserHost();
  38. /// Set global property object values, available as read only on page
  39. static void SetGlobalBoolProperty(const String& globalVar, const String& property, bool value);
  40. static void SetGlobalStringProperty(const String& globalVar, const String& property, const String& value);
  41. static void SetGlobalNumberProperty(const String& globalVar, const String& property, double value);
  42. static const GlobalPropertyMap& GetGlobalProperties() { return globalProperties_; }
  43. // Configuration settings that must be set before creating WebBrowserHost subsystem
  44. /// Set value that will be returned as the User-Agent HTTP header.
  45. static void SetUserAgent(const String& userAgent) { userAgent_ = userAgent; }
  46. /// Set value that will be inserted as the product portion of the default User-Agent string
  47. static void SetProductVersion(const String& productVersion) { productVersion_ = productVersion; }
  48. /// Set to a value between 1024 and 65535 to enable remote debugging on the specified port
  49. static void SetDebugPort(int debugPort) { debugPort_ = debugPort; }
  50. /// Get User-Agent of the HTTP header. If empty the default User-Agent string will be used
  51. static const String& GetUserAgent() { return userAgent_; }
  52. /// 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
  53. static const String& GetProductVersion() { return productVersion_; }
  54. private:
  55. void HandleUpdate(StringHash eventType, VariantMap& eventData);
  56. static void SetGlobalProperty(const String& globalVar, const String& property, Variant& value);
  57. WebBrowserHostPrivate* d_;
  58. static WeakPtr<WebBrowserHost> instance_;
  59. static GlobalPropertyMap globalProperties_;
  60. // configuration settings that must be set before WebBrowserHost subsystem is created
  61. static String userAgent_;
  62. static String productVersion_;
  63. static int debugPort_;
  64. };
  65. }