Collection of DPF-based plugins for packaging
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
3.5KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2025 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. * or without fee is hereby granted, provided that the above copyright notice and this
  7. * permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  10. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  11. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  12. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  13. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #if !defined(DISTRHO_WEB_VIEW_HPP_INCLUDED) && !defined(DGL_WEB_VIEW_HPP_INCLUDED)
  17. # define DISTRHO_WEB_VIEW_INCLUDE_IMPLEMENTATION
  18. # include "WebView.hpp"
  19. #endif
  20. // --------------------------------------------------------------------------------------------------------------------
  21. // Web View stuff
  22. START_NAMESPACE_DISTRHO
  23. class WebView;
  24. END_NAMESPACE_DISTRHO
  25. #ifdef WEB_VIEW_DGL_NAMESPACE
  26. START_NAMESPACE_DGL
  27. using DISTRHO_NAMESPACE::WebView;
  28. #else
  29. START_NAMESPACE_DISTRHO
  30. #endif
  31. WebView* webview_choc_create(const WEB_VIEW_NAMESPACE::WebViewOptions& opts);
  32. void webview_choc_destroy(WebView*);
  33. void* webview_choc_handle(WebView*);
  34. void webview_choc_eval(WebView*, const char* js);
  35. void webview_choc_navigate(WebView*, const char* url);
  36. #ifdef WEB_VIEW_DGL_NAMESPACE
  37. END_NAMESPACE_DGL
  38. #else
  39. END_NAMESPACE_DISTRHO
  40. #endif
  41. // --------------------------------------------------------------------------------------------------------------------
  42. #ifdef DISTRHO_WEB_VIEW_INCLUDE_IMPLEMENTATION
  43. # define WC_ERR_INVALID_CHARS 0
  44. # include "choc/choc_WebView.h"
  45. #ifdef WEB_VIEW_DGL_NAMESPACE
  46. START_NAMESPACE_DGL
  47. #else
  48. START_NAMESPACE_DISTRHO
  49. #endif
  50. WebView* webview_choc_create(const WEB_VIEW_NAMESPACE::WebViewOptions& opts)
  51. {
  52. WebView::Options wopts;
  53. wopts.acceptsFirstMouseClick = true;
  54. wopts.enableDebugMode = true;
  55. std::unique_ptr<WebView> webview = std::make_unique<WebView>(wopts);
  56. DISTRHO_SAFE_ASSERT_RETURN(webview->loadedOK(), nullptr);
  57. if (const WEB_VIEW_NAMESPACE::WebViewMessageCallback callback = opts.callback)
  58. {
  59. webview->addInitScript("function postMessage(m){window.chrome.webview.postMessage(m);}");
  60. void* const callbackPtr = opts.callbackPtr;
  61. webview->bind([callback, callbackPtr](const std::string& value) {
  62. char* const data = strdup(value.data());
  63. callback(callbackPtr, data);
  64. std::free(data);
  65. });
  66. }
  67. else
  68. {
  69. webview->addInitScript("function postMessage(m){}");
  70. }
  71. if (opts.initialJS != nullptr)
  72. webview->addInitScript(opts.initialJS);
  73. return webview.release();
  74. }
  75. void webview_choc_destroy(WebView* const webview)
  76. {
  77. delete webview;
  78. }
  79. void* webview_choc_handle(WebView* const webview)
  80. {
  81. return webview->getViewHandle();
  82. }
  83. void webview_choc_eval(WebView* const webview, const char* const js)
  84. {
  85. webview->evaluateJavascript(js);
  86. }
  87. void webview_choc_navigate(WebView* const webview, const char* const url)
  88. {
  89. webview->navigate(url);
  90. }
  91. #ifdef WEB_VIEW_DGL_NAMESPACE
  92. END_NAMESPACE_DGL
  93. #else
  94. END_NAMESPACE_DISTRHO
  95. #endif
  96. #endif // DISTRHO_WEB_VIEW_INCLUDE_IMPLEMENTATION
  97. // --------------------------------------------------------------------------------------------------------------------