WebAppBrowser.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. // media stream support
  33. command_line->AppendSwitch("--enable-media-stream");
  34. command_line->AppendSwitch("--enable-usermedia-screen-capturing");
  35. // transparency support
  36. command_line->AppendSwitch("--off-screen-rendering-enabled");
  37. command_line->AppendSwitch("--transparent-painting-enabled");
  38. #ifdef ATOMIC_PLATFORM_LINUX
  39. // Issues with GPU acceleration (and possibly offscreen rendering)
  40. // https://github.com/AtomicGameEngine/AtomicGameEngine/issues/924
  41. command_line->AppendSwitch("--disable-gpu");
  42. #endif
  43. CefApp::OnBeforeCommandLineProcessing(process_type, command_line);
  44. }
  45. // CefBrowserProcessHandler methods.
  46. void WebAppBrowser::OnContextInitialized()
  47. {
  48. CefBrowserProcessHandler::OnContextInitialized();
  49. }
  50. bool WebAppBrowser::CreateGlobalProperties(CefRefPtr<CefDictionaryValue>& globalProps)
  51. {
  52. // Get a copy global properties
  53. GlobalPropertyMap props = WebBrowserHost::GetGlobalProperties();
  54. if (props.Empty())
  55. return false;
  56. GlobalPropertyMap::ConstIterator itr = props.Begin();
  57. // populate with globals args
  58. globalProps = CefDictionaryValue::Create();
  59. while (itr != props.End())
  60. {
  61. HashMap<String, Variant>::ConstIterator pitr = itr->second_.Begin();
  62. const String& globalVar = itr->first_;
  63. CefRefPtr<CefDictionaryValue> kprops = CefDictionaryValue::Create();
  64. while (pitr != itr->second_.End())
  65. {
  66. const String& propertyName = pitr->first_;
  67. const Variant& value = pitr->second_;
  68. if (value.GetType() == VAR_INT || value.GetType() == VAR_FLOAT || value.GetType() == VAR_DOUBLE)
  69. {
  70. kprops->SetDouble(propertyName.CString(), value.GetDouble());
  71. }
  72. else if (value.GetType() == VAR_BOOL)
  73. {
  74. kprops->SetBool(propertyName.CString(), value.GetBool());
  75. }
  76. else if (value.GetType() == VAR_STRING)
  77. {
  78. kprops->SetString(propertyName.CString(), value.GetString().CString());
  79. }
  80. pitr++;
  81. }
  82. globalProps->SetDictionary(globalVar.CString(), kprops);
  83. itr++;
  84. }
  85. return true;
  86. }
  87. void WebAppBrowser::OnRenderProcessThreadCreated(CefRefPtr<CefListValue> extra_info)
  88. {
  89. // We're not on main thread here, we're on IO thread
  90. CefRefPtr<CefDictionaryValue> globalProps;
  91. if (CreateGlobalProperties(globalProps))
  92. {
  93. extra_info->SetDictionary(0, globalProps);
  94. }
  95. else
  96. {
  97. extra_info->SetNull(0);
  98. }
  99. extra_info->SetString(1, WebBrowserHost::GetJSMessageQueryFunctionName().CString());
  100. extra_info->SetString(2, WebBrowserHost::GetJSMessageQueryCancelFunctionName().CString());
  101. }
  102. }