Audio plugin host https://kx.studio/carla
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.

151 lines
5.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. namespace juce
  14. {
  15. #if JUCE_WEB_BROWSER || DOXYGEN
  16. //==============================================================================
  17. /**
  18. A component that displays an embedded web browser.
  19. The browser itself will be platform-dependent. On Mac and iOS it will be
  20. WebKit, if you have enabled JUCE_USE_WINRT_WEBVIEW on Windows 10 it will be
  21. EdgeHTML otherwise IE, on Android it will be Chrome, and on Linux it will be
  22. WebKit.
  23. @tags{GUI}
  24. */
  25. class JUCE_API WebBrowserComponent : public Component
  26. {
  27. public:
  28. //==============================================================================
  29. /** Creates a WebBrowserComponent.
  30. Once it's created and visible, send the browser to a URL using goToURL().
  31. @param unloadPageWhenBrowserIsHidden if this is true, then when the browser
  32. component is taken offscreen, it'll clear the current page
  33. and replace it with a blank page - this can be handy to stop
  34. the browser using resources in the background when it's not
  35. actually being used.
  36. */
  37. explicit WebBrowserComponent (bool unloadPageWhenBrowserIsHidden = true);
  38. /** Destructor. */
  39. ~WebBrowserComponent() override;
  40. //==============================================================================
  41. /** Sends the browser to a particular URL.
  42. @param url the URL to go to.
  43. @param headers an optional set of parameters to put in the HTTP header. If
  44. you supply this, it should be a set of string in the form
  45. "HeaderKey: HeaderValue"
  46. @param postData an optional block of data that will be attached to the HTTP
  47. POST request
  48. */
  49. void goToURL (const String& url,
  50. const StringArray* headers = nullptr,
  51. const MemoryBlock* postData = nullptr);
  52. /** Stops the current page loading. */
  53. void stop();
  54. /** Sends the browser back one page. */
  55. void goBack();
  56. /** Sends the browser forward one page. */
  57. void goForward();
  58. /** Refreshes the browser. */
  59. void refresh();
  60. /** Clear cookies that the OS has stored for the WebComponents of this application */
  61. static void clearCookies();
  62. //==============================================================================
  63. /** This callback is called when the browser is about to navigate
  64. to a new location.
  65. You can override this method to perform some action when the user
  66. tries to go to a particular URL. To allow the operation to carry on,
  67. return true, or return false to stop the navigation happening.
  68. */
  69. virtual bool pageAboutToLoad (const String& newURL) { ignoreUnused (newURL); return true; }
  70. /** This callback happens when the browser has finished loading a page. */
  71. virtual void pageFinishedLoading (const String& url) { ignoreUnused (url); }
  72. /** This callback happens when a network error was encountered while
  73. trying to load a page.
  74. You can override this method to show some other error page by calling
  75. goToURL. Return true to allow the browser to carry on to the internal
  76. browser error page.
  77. The errorInfo contains some platform dependent string describing the
  78. error.
  79. */
  80. virtual bool pageLoadHadNetworkError (const String& errorInfo) { ignoreUnused (errorInfo); return true; }
  81. /** This callback occurs when a script or other activity in the browser asks for
  82. the window to be closed.
  83. */
  84. virtual void windowCloseRequest() {}
  85. /** This callback occurs when the browser attempts to load a URL in a new window.
  86. This won't actually load the window but gives you a chance to either launch a
  87. new window yourself or just load the URL into the current window with goToURL().
  88. */
  89. virtual void newWindowAttemptingToLoad (const String& newURL) { ignoreUnused (newURL); }
  90. //==============================================================================
  91. /** @internal */
  92. void paint (Graphics&) override;
  93. /** @internal */
  94. void resized() override;
  95. /** @internal */
  96. void parentHierarchyChanged() override;
  97. /** @internal */
  98. void visibilityChanged() override;
  99. /** @internal */
  100. void focusGained (FocusChangeType) override;
  101. /** @internal */
  102. class Pimpl;
  103. private:
  104. //==============================================================================
  105. std::unique_ptr<Pimpl> browser;
  106. bool blankPageShown = false, unloadPageWhenBrowserIsHidden;
  107. String lastURL;
  108. StringArray lastHeaders;
  109. MemoryBlock lastPostData;
  110. void reloadLastURL();
  111. void checkWindowAssociation();
  112. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WebBrowserComponent)
  113. };
  114. #endif
  115. } // namespace juce