diff --git a/modules/juce_gui_extra/juce_gui_extra.cpp b/modules/juce_gui_extra/juce_gui_extra.cpp index 3b2eb9453a..764c33c107 100644 --- a/modules/juce_gui_extra/juce_gui_extra.cpp +++ b/modules/juce_gui_extra/juce_gui_extra.cpp @@ -144,4 +144,9 @@ namespace juce #endif #endif +#if JUCE_WEB_BROWSER + bool WebBrowserComponent::pageAboutToLoad (const String&) { return true; } + void WebBrowserComponent::pageFinishedLoading (const String&) {} + void WebBrowserComponent::windowCloseRequest() {} +#endif } diff --git a/modules/juce_gui_extra/misc/juce_WebBrowserComponent.h b/modules/juce_gui_extra/misc/juce_WebBrowserComponent.h index c6f5925866..a50f167805 100644 --- a/modules/juce_gui_extra/misc/juce_WebBrowserComponent.h +++ b/modules/juce_gui_extra/misc/juce_WebBrowserComponent.h @@ -93,6 +93,11 @@ public: /** This callback happens when the browser has finished loading a page. */ virtual void pageFinishedLoading (const String& url); + /** This callback occurs when a script or other activity in the browser asks for + the window to be closed. + */ + virtual void windowCloseRequest(); + //============================================================================== /** @internal */ void paint (Graphics&) override; @@ -120,4 +125,4 @@ private: #endif -#endif // JUCE_WEBBROWSERCOMPONENT_H_INCLUDED +#endif // JUCE_WEBBROWSERCOMPONENT_H_INCLUDED \ No newline at end of file diff --git a/modules/juce_gui_extra/native/juce_android_WebBrowserComponent.cpp b/modules/juce_gui_extra/native/juce_android_WebBrowserComponent.cpp index 3cc6aacf7d..dcf786d732 100644 --- a/modules/juce_gui_extra/native/juce_android_WebBrowserComponent.cpp +++ b/modules/juce_gui_extra/native/juce_android_WebBrowserComponent.cpp @@ -107,6 +107,3 @@ void WebBrowserComponent::visibilityChanged() { checkWindowAssociation(); } - -bool WebBrowserComponent::pageAboutToLoad (const String&) { return true; } -void WebBrowserComponent::pageFinishedLoading (const String&) {} diff --git a/modules/juce_gui_extra/native/juce_linux_WebBrowserComponent.cpp b/modules/juce_gui_extra/native/juce_linux_WebBrowserComponent.cpp index f7c8228bcd..1a36b7407b 100644 --- a/modules/juce_gui_extra/native/juce_linux_WebBrowserComponent.cpp +++ b/modules/juce_gui_extra/native/juce_linux_WebBrowserComponent.cpp @@ -112,6 +112,3 @@ void WebBrowserComponent::visibilityChanged() { checkWindowAssociation(); } - -bool WebBrowserComponent::pageAboutToLoad (const String&) { return true; } -void WebBrowserComponent::pageFinishedLoading (const String&) {} diff --git a/modules/juce_gui_extra/native/juce_mac_WebBrowserComponent.mm b/modules/juce_gui_extra/native/juce_mac_WebBrowserComponent.mm index 4ed27ed61f..286ff804b3 100644 --- a/modules/juce_gui_extra/native/juce_mac_WebBrowserComponent.mm +++ b/modules/juce_gui_extra/native/juce_mac_WebBrowserComponent.mm @@ -33,6 +33,7 @@ struct DownloadClickDetectorClass : public ObjCClass addMethod (@selector (webView:decidePolicyForNavigationAction:request:frame:decisionListener:), decidePolicyForNavigationAction, "v@:@@@@@"); addMethod (@selector (webView:didFinishLoadForFrame:), didFinishLoadForFrame, "v@:@@"); + addMethod (@selector (webView:willCloseFrame:), willCloseFrame, "v@:@@"); registerClass(); } @@ -60,6 +61,11 @@ private: getOwner (self)->pageFinishedLoading (nsStringToJuce ([url absoluteString])); } } + + static void willCloseFrame (id self, SEL, WebView*, WebFrame*) + { + getOwner (self)->windowCloseRequest(); + } }; #else @@ -346,6 +352,3 @@ void WebBrowserComponent::visibilityChanged() { checkWindowAssociation(); } - -bool WebBrowserComponent::pageAboutToLoad (const String&) { return true; } -void WebBrowserComponent::pageFinishedLoading (const String&) {} diff --git a/modules/juce_gui_extra/native/juce_win32_WebBrowserComponent.cpp b/modules/juce_gui_extra/native/juce_win32_WebBrowserComponent.cpp index cb4ef12356..76f4c1d4a7 100644 --- a/modules/juce_gui_extra/native/juce_win32_WebBrowserComponent.cpp +++ b/modules/juce_gui_extra/native/juce_win32_WebBrowserComponent.cpp @@ -158,6 +158,16 @@ private: owner.pageFinishedLoading (getStringFromVariant (pDispParams->rgvarg[0].pvarVal)); return S_OK; } + else if (dispIdMember == DISPID_WINDOWCLOSING) + { + owner.windowCloseRequest(); + + // setting this bool tells the browser to ignore the event - we'll handle it. + if (pDispParams->cArgs > 0 && pDispParams->rgvarg[0].vt == (VT_BYREF | VT_BOOL)) + *pDispParams->rgvarg[0].pboolVal = VARIANT_TRUE; + + return S_OK; + } return E_NOTIMPL; } @@ -305,6 +315,3 @@ void WebBrowserComponent::visibilityChanged() { checkWindowAssociation(); } - -bool WebBrowserComponent::pageAboutToLoad (const String&) { return true; } -void WebBrowserComponent::pageFinishedLoading (const String&) {}