LMMS
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 //==============================================================================
59 explicit WebBrowserComponent (bool unloadPageWhenBrowserIsHidden = true);
60
62 ~WebBrowserComponent() override;
63
64 //==============================================================================
74 void goToURL (const String& url,
75 const StringArray* headers = nullptr,
76 const MemoryBlock* postData = nullptr);
77
79 void stop();
80
82 void goBack();
83
85 void goForward();
86
88 void refresh();
89
91 static void clearCookies();
92
93 //==============================================================================
101 virtual bool pageAboutToLoad (const String& newURL) { ignoreUnused (newURL); return true; }
102
104 virtual void pageFinishedLoading (const String& url) { ignoreUnused (url); }
105
116 virtual bool pageLoadHadNetworkError (const String& errorInfo) { ignoreUnused (errorInfo); return true; }
117
121 virtual void windowCloseRequest() {}
122
127 virtual void newWindowAttemptingToLoad (const String& newURL) { ignoreUnused (newURL); }
128
129 //==============================================================================
131 void paint (Graphics&) override;
133 void resized() override;
135 void parentHierarchyChanged() override;
137 void visibilityChanged() override;
139 void focusGained (FocusChangeType) override;
140
142 class Pimpl;
143
144protected:
145 friend class WindowsWebView2WebBrowserComponent;
146
148 struct ConstructWithoutPimpl
149 {
150 explicit ConstructWithoutPimpl (bool unloadOnHide) : unloadWhenHidden (unloadOnHide) {}
151 const bool unloadWhenHidden;
152 };
153 explicit WebBrowserComponent (ConstructWithoutPimpl);
154
155private:
156 //==============================================================================
157 std::unique_ptr<Pimpl> browser;
158 bool blankPageShown = false, unloadPageWhenHidden;
159 String lastURL;
160 StringArray lastHeaders;
161 MemoryBlock lastPostData;
162
163 void reloadLastURL();
164 void checkWindowAssociation();
165
167};
168
169//==============================================================================
178class JUCE_API WebView2Preferences
179{
180public:
181 //==============================================================================
185 JUCE_NODISCARD WebView2Preferences withDLLLocation (const File& location) const { return with (&WebView2Preferences::dllLocation, location); }
186
188 WebView2Preferences withUserDataFolder (const File& folder) const { return with (&WebView2Preferences::userDataFolder, folder); }
189
193 JUCE_NODISCARD WebView2Preferences withStatusBarDisabled() const { return with (&WebView2Preferences::disableStatusBar, true); }
194
198 JUCE_NODISCARD WebView2Preferences withBuiltInErrorPageDisabled() const { return with (&WebView2Preferences::disableBuiltInErrorPage, true); }
199
205 JUCE_NODISCARD WebView2Preferences withBackgroundColour (const Colour& colour) const
206 {
207 // the background colour must be either fully opaque or transparent!
208 jassert (colour.isOpaque() || colour.isTransparent());
209
210 return with (&WebView2Preferences::backgroundColour, colour);
211 }
212
213 //==============================================================================
214 File getDLLLocation() const { return dllLocation; }
215 File getUserDataFolder() const { return userDataFolder; }
216 bool getIsStatusBarDisabled() const noexcept { return disableStatusBar; }
217 bool getIsBuiltInErrorPageDisabled() const noexcept { return disableBuiltInErrorPage; }
218 Colour getBackgroundColour() const { return backgroundColour; }
219
220private:
221 //==============================================================================
222 template <typename Member, typename Item>
223 WebView2Preferences with (Member&& member, Item&& item) const
224 {
225 auto options = *this;
226 options.*member = std::forward<Item> (item);
227
228 return options;
229 }
230
231 File dllLocation, userDataFolder;
232 bool disableStatusBar = false, disableBuiltInErrorPage = false;
233 Colour backgroundColour = Colours::white;
234};
235
253class WindowsWebView2WebBrowserComponent : public WebBrowserComponent
254{
255public:
256 //==============================================================================
270 WindowsWebView2WebBrowserComponent (bool unloadPageWhenBrowserIsHidden = true,
271 const WebView2Preferences& preferences = {});
272
273 // This constructor has been deprecated. Use the new constructor that takes a
274 // WebView2Preferences instead.
275 explicit WindowsWebView2WebBrowserComponent (bool unloadPageWhenBrowserIsHidden = true,
276 const File& dllLocation = {},
277 const File& userDataFolder = {})
278 : WindowsWebView2WebBrowserComponent (unloadPageWhenBrowserIsHidden,
279 WebView2Preferences().withDLLLocation (dllLocation)
280 .withUserDataFolder (userDataFolder))
281 {
282 }
283};
284
285#endif
286
287} // namespace juce
#define noexcept
Definition DistrhoDefines.h:72
virtual ASIOError stop()=0
#define JUCE_NODISCARD
Definition juce_CompilerSupport.h:108
#define jassert(expression)
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
#define JUCE_API
Definition juce_StandardHeader.h:152
Definition carla_juce.cpp:31
void ignoreUnused(Types &&...) noexcept
Definition juce_MathsFunctions.h:333
#define const
Definition zconf.h:137