WebAppBrowser.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. #include <Atomic/IO/Log.h>
  23. #include "WebAppBrowser.h"
  24. #include "../WebBrowserHost.h"
  25. namespace Atomic
  26. {
  27. WebAppBrowser::WebAppBrowser()
  28. {
  29. }
  30. void WebAppBrowser::OnBeforeCommandLineProcessing(const CefString& process_type, CefRefPtr<CefCommandLine> command_line)
  31. {
  32. CefApp::OnBeforeCommandLineProcessing(process_type, command_line);
  33. }
  34. // CefBrowserProcessHandler methods.
  35. void WebAppBrowser::OnContextInitialized()
  36. {
  37. CefBrowserProcessHandler::OnContextInitialized();
  38. }
  39. bool WebAppBrowser::CreateGlobalProperties(CefRefPtr<CefDictionaryValue>& globalProps)
  40. {
  41. // Get a copy global properties
  42. GlobalPropertyMap props = WebBrowserHost::GetGlobalProperties();
  43. if (props.Empty())
  44. return false;
  45. GlobalPropertyMap::ConstIterator itr = props.Begin();
  46. // populate with globals args
  47. globalProps = CefDictionaryValue::Create();
  48. while (itr != props.End())
  49. {
  50. HashMap<String, Variant>::ConstIterator pitr = itr->second_.Begin();
  51. const String& globalVar = itr->first_;
  52. CefRefPtr<CefDictionaryValue> kprops = CefDictionaryValue::Create();
  53. while (pitr != itr->second_.End())
  54. {
  55. const String& propertyName = pitr->first_;
  56. const Variant& value = pitr->second_;
  57. if (value.GetType() == VAR_INT || value.GetType() == VAR_FLOAT || value.GetType() == VAR_DOUBLE)
  58. {
  59. kprops->SetDouble(propertyName.CString(), value.GetDouble());
  60. }
  61. else if (value.GetType() == VAR_BOOL)
  62. {
  63. kprops->SetBool(propertyName.CString(), value.GetBool());
  64. }
  65. else if (value.GetType() == VAR_STRING)
  66. {
  67. kprops->SetString(propertyName.CString(), value.GetString().CString());
  68. }
  69. pitr++;
  70. }
  71. globalProps->SetDictionary(globalVar.CString(), kprops);
  72. itr++;
  73. }
  74. return true;
  75. }
  76. void WebAppBrowser::OnRenderProcessThreadCreated(CefRefPtr<CefListValue> extra_info)
  77. {
  78. // We're not on main thread here, we're on IO thread
  79. CefRefPtr<CefDictionaryValue> globalProps;
  80. if (CreateGlobalProperties(globalProps))
  81. {
  82. extra_info->SetDictionary(0, globalProps);
  83. }
  84. }
  85. }