WebAppBrowser.cpp 3.4 KB

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