JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_WebBrowserComponent.h
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
29#if JUCE_WEB_BROWSER || DOXYGEN
30
31//==============================================================================
45class JUCE_API WebBrowserComponent : public Component
46{
47public:
48 //==============================================================================
52 class JUCE_API Options
53 {
54 public:
55 //==============================================================================
56 enum class Backend
57 {
62 defaultBackend,
63
76 ie,
77
81 webview2
82 };
83
90 [[nodiscard]] Options withBackend (Backend backend) const { return withMember (*this, &Options::browserBackend, backend); }
91
92 //==============================================================================
99 [[nodiscard]] Options withKeepPageLoadedWhenBrowserIsHidden() const { return withMember (*this, &Options::keepPageLoadedWhenBrowserIsHidden, true); }
100
104 [[nodiscard]] Options withUserAgent (String ua) const { return withMember (*this, &Options::userAgent, std::move (ua)); }
105
106 //==============================================================================
111 {
112 public:
113 //==============================================================================
117 [[nodiscard]] WinWebView2 withDLLLocation (const File& location) const { return withMember (*this, &WinWebView2::dllLocation, location); }
118
120 [[nodiscard]] WinWebView2 withUserDataFolder (const File& folder) const { return withMember (*this, &WinWebView2::userDataFolder, folder); }
121
125 [[nodiscard]] WinWebView2 withStatusBarDisabled() const { return withMember (*this, &WinWebView2::disableStatusBar, true); }
126
130 [[nodiscard]] WinWebView2 withBuiltInErrorPageDisabled() const { return withMember (*this, &WinWebView2::disableBuiltInErrorPage, true); }
131
137 [[nodiscard]] WinWebView2 withBackgroundColour (const Colour& colour) const
138 {
139 // the background colour must be either fully opaque or transparent!
140 jassert (colour.isOpaque() || colour.isTransparent());
141
142 return withMember (*this, &WinWebView2::backgroundColour, colour);
143 }
144
145 //==============================================================================
146 File getDLLLocation() const { return dllLocation; }
147 File getUserDataFolder() const { return userDataFolder; }
148 bool getIsStatusBarDisabled() const noexcept { return disableStatusBar; }
149 bool getIsBuiltInErrorPageDisabled() const noexcept { return disableBuiltInErrorPage; }
150 Colour getBackgroundColour() const { return backgroundColour; }
151
152 private:
153 //==============================================================================
154 File dllLocation, userDataFolder;
155 bool disableStatusBar = false, disableBuiltInErrorPage = false;
156 Colour backgroundColour;
157 };
158
159 [[nodiscard]] Options withWinWebView2Options (const WinWebView2& winWebView2Options) const
160 {
161 return withMember (*this, &Options::winWebView2, winWebView2Options);
162 }
163
164 //==============================================================================
165 Backend getBackend() const noexcept { return browserBackend; }
166 bool keepsPageLoadedWhenBrowserIsHidden() const noexcept { return keepPageLoadedWhenBrowserIsHidden; }
167 String getUserAgent() const { return userAgent; }
168 WinWebView2 getWinWebView2BackendOptions() const { return winWebView2; }
169
170 private:
171 //==============================================================================
172 Backend browserBackend = Backend::defaultBackend;
173 bool keepPageLoadedWhenBrowserIsHidden = false;
174 String userAgent;
175 WinWebView2 winWebView2;
176 };
177
178 //==============================================================================
181
186 explicit WebBrowserComponent (const Options& options);
187
190
191 //==============================================================================
193 static bool areOptionsSupported (const Options& options);
194
195 //==============================================================================
205 void goToURL (const String& url,
206 const StringArray* headers = nullptr,
207 const MemoryBlock* postData = nullptr);
208
210 void stop();
211
213 void goBack();
214
216 void goForward();
217
219 void refresh();
220
222 static void clearCookies();
223
224 //==============================================================================
232 virtual bool pageAboutToLoad (const String& newURL);
233
235 virtual void pageFinishedLoading (const String& url);
236
247 virtual bool pageLoadHadNetworkError (const String& errorInfo);
248
252 virtual void windowCloseRequest();
253
258 virtual void newWindowAttemptingToLoad (const String& newURL);
259
260 //==============================================================================
262 void paint (Graphics&) override;
264 void resized() override;
266 void parentHierarchyChanged() override;
268 void visibilityChanged() override;
271
273 class Pimpl;
274
275private:
276 std::unique_ptr<AccessibilityHandler> createAccessibilityHandler() override
277 {
278 return std::make_unique<AccessibilityHandler> (*this, AccessibilityRole::group);
279 }
280
281 //==============================================================================
283 bool blankPageShown = false, unloadPageWhenHidden;
284 String lastURL;
285 StringArray lastHeaders;
286 MemoryBlock lastPostData;
287
288 void reloadLastURL();
289 void checkWindowAssociation();
290
292};
293
294#endif
295
296} // namespace juce
Represents a colour, also including a transparency value.
Definition juce_Colour.h:38
bool isOpaque() const noexcept
Returns true if this colour is completely opaque.
bool isTransparent() const noexcept
Returns true if this colour is completely transparent.
The base class for all JUCE user-interface objects.
FocusChangeType
Enumeration used by the focusGained() and focusLost() methods.
FocusChangeDirection
Enumeration used by the focusGainedWithDirection() method.
Represents a local file or directory.
Definition juce_File.h:45
A graphics context, used for drawing a component or image.
A class to hold a resizable block of raw data.
A special array for holding a list of strings.
The JUCE String class!
Definition juce_String.h:53
Options specific to the WebView2 backend.
WinWebView2 withBackgroundColour(const Colour &colour) const
Sets the background colour that WebView2 renders underneath all web content.
WinWebView2 withStatusBarDisabled() const
If this is set, the status bar usually displayed in the lower-left of the webview will be disabled.
WinWebView2 withUserDataFolder(const File &folder) const
Sets a non-default location for storing user data for the browser instance.
WinWebView2 withBuiltInErrorPageDisabled() const
If this is set, a blank page will be displayed on error instead of the default built-in error page.
WinWebView2 withDLLLocation(const File &location) const
Sets a custom location for the WebView2Loader.dll that is not a part of the standard system DLL searc...
Options to configure WebBrowserComponent.
Options withKeepPageLoadedWhenBrowserIsHidden() const
Tell JUCE to keep the web page alive when the WebBrowserComponent is not visible.
Options withBackend(Backend backend) const
Use a particular backend to create the WebViewBrowserComponent.
Options withUserAgent(String ua) const
Use a specific user agent string when requesting web pages.
A component that displays an embedded web browser.
static void clearCookies()
Clear cookies that the OS has stored for the WebComponents of this application.
void goBack()
Sends the browser back one page.
void goForward()
Sends the browser forward one page.
void parentHierarchyChanged() override
Called to indicate that the component's parents have changed.
void refresh()
Refreshes the browser.
void paint(Graphics &) override
Components can override this method to draw their content.
void resized() override
Called when this component's size has been changed.
WebBrowserComponent()
Creates a WebBrowserComponent with default options.
static bool areOptionsSupported(const Options &options)
Check if the specified options are supported on this platform.
void focusGainedWithDirection(FocusChangeType, FocusChangeDirection) override
Called to indicate that this component has just acquired the keyboard focus.
void visibilityChanged() override
Called when this component's visibility changes.
void stop()
Stops the current page loading.
WebBrowserComponent(const Options &options)
Creates a WebBrowserComponent.
void goToURL(const String &url, const StringArray *headers=nullptr, const MemoryBlock *postData=nullptr)
Sends the browser to a particular URL.
~WebBrowserComponent() override
Destructor.
#define jassert(expression)
Platform-independent assertion macro.
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
This is a shorthand way of writing both a JUCE_DECLARE_NON_COPYABLE and JUCE_LEAK_DETECTOR macro for ...
JUCE Namespace.
Object withMember(Object copy, Member OtherObject::*member, Other &&value)
Copies an object, sets one of the copy's members to the specified value, and then returns the copy.