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.

155 lines
5.5KB

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