diff --git a/extras/Demo/Source/Demos/WebBrowserDemo.cpp b/extras/Demo/Source/Demos/WebBrowserDemo.cpp index b0b5ee4ce7..08022c9cad 100644 --- a/extras/Demo/Source/Demos/WebBrowserDemo.cpp +++ b/extras/Demo/Source/Demos/WebBrowserDemo.cpp @@ -37,13 +37,12 @@ class DemoBrowserComponent : public WebBrowserComponent { public: //============================================================================== - DemoBrowserComponent (TextEditor& addressTextBox_) - : addressTextBox (addressTextBox_) + DemoBrowserComponent (TextEditor& addressBox) : addressTextBox (addressBox) { } // This method gets called when the browser is about to go to a new URL.. - bool pageAboutToLoad (const String& newURL) + bool pageAboutToLoad (const String& newURL) override { // We'll just update our address box to reflect the new location.. addressTextBox.setText (newURL, false); @@ -53,6 +52,13 @@ public: return true; } + // This method gets called when the browser is requested to launch a new window + void newWindowAttemptingToLoad (const String& newURL) override + { + // We'll just load the URL into the main window + goToURL (newURL); + } + private: TextEditor& addressTextBox; @@ -93,7 +99,7 @@ public: webView->goToURL ("http://www.juce.com"); } - void paint (Graphics& g) + void paint (Graphics& g) override { g.fillAll (Colours::grey); } diff --git a/modules/juce_gui_basics/drawables/juce_DrawableImage.cpp b/modules/juce_gui_basics/drawables/juce_DrawableImage.cpp index 7c29dee045..d609011a19 100644 --- a/modules/juce_gui_basics/drawables/juce_DrawableImage.cpp +++ b/modules/juce_gui_basics/drawables/juce_DrawableImage.cpp @@ -37,6 +37,7 @@ DrawableImage::DrawableImage (const DrawableImage& other) overlayColour (other.overlayColour), bounds (other.bounds) { + setBounds (other.getBounds()); } DrawableImage::~DrawableImage() diff --git a/modules/juce_gui_extra/juce_gui_extra.cpp b/modules/juce_gui_extra/juce_gui_extra.cpp index d26dd912b4..bff407c15e 100644 --- a/modules/juce_gui_extra/juce_gui_extra.cpp +++ b/modules/juce_gui_extra/juce_gui_extra.cpp @@ -147,5 +147,6 @@ namespace juce bool WebBrowserComponent::pageAboutToLoad (const String&) { return true; } void WebBrowserComponent::pageFinishedLoading (const String&) {} void WebBrowserComponent::windowCloseRequest() {} + void WebBrowserComponent::newWindowAttemptingToLoad (const String&) {} #endif } diff --git a/modules/juce_gui_extra/misc/juce_WebBrowserComponent.h b/modules/juce_gui_extra/misc/juce_WebBrowserComponent.h index 6afad60a4e..fb32cc728a 100644 --- a/modules/juce_gui_extra/misc/juce_WebBrowserComponent.h +++ b/modules/juce_gui_extra/misc/juce_WebBrowserComponent.h @@ -98,6 +98,12 @@ public: */ virtual void windowCloseRequest(); + /** This callback occurs when the browser attempts to load a URL in a new window. + This won't actually load the window but gives you a chance to either launch a + new window yourself or just load the URL into the current window with goToURL(). + */ + virtual void newWindowAttemptingToLoad (const String& newURL); + //============================================================================== /** @internal */ void paint (Graphics&) override; diff --git a/modules/juce_gui_extra/native/juce_mac_WebBrowserComponent.mm b/modules/juce_gui_extra/native/juce_mac_WebBrowserComponent.mm index a522809e5c..732665cf09 100644 --- a/modules/juce_gui_extra/native/juce_mac_WebBrowserComponent.mm +++ b/modules/juce_gui_extra/native/juce_mac_WebBrowserComponent.mm @@ -32,6 +32,8 @@ struct DownloadClickDetectorClass : public ObjCClass addMethod (@selector (webView:decidePolicyForNavigationAction:request:frame:decisionListener:), decidePolicyForNavigationAction, "v@:@@@@@"); + addMethod (@selector (webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener:), + decidePolicyForNewWindowAction, "v@:@@@@@"); addMethod (@selector (webView:didFinishLoadForFrame:), didFinishLoadForFrame, "v@:@@"); addMethod (@selector (webView:willCloseFrame:), willCloseFrame, "v@:@@"); addMethod (@selector (webView:runOpenPanelForFileButtonWithResultListener:allowMultipleFiles:), runOpenPanel, "v@:@@", @encode (BOOL)); @@ -43,17 +45,30 @@ struct DownloadClickDetectorClass : public ObjCClass static WebBrowserComponent* getOwner (id self) { return getIvar (self, "owner"); } private: + static String getOriginalURL (NSDictionary* actionInformation) + { + if (NSURL* url = [actionInformation valueForKey: nsStringLiteral ("WebActionOriginalURLKey")]) + return nsStringToJuce ([url absoluteString]); + + return String(); + } + static void decidePolicyForNavigationAction (id self, SEL, WebView*, NSDictionary* actionInformation, NSURLRequest*, WebFrame*, id listener) { - NSURL* url = [actionInformation valueForKey: nsStringLiteral ("WebActionOriginalURLKey")]; - - if (getOwner (self)->pageAboutToLoad (nsStringToJuce ([url absoluteString]))) + if (getOwner (self)->pageAboutToLoad (getOriginalURL (actionInformation))) [listener use]; else [listener ignore]; } + static void decidePolicyForNewWindowAction (id self, SEL, WebView*, NSDictionary* actionInformation, + NSURLRequest*, NSString*, id listener) + { + getOwner (self)->newWindowAttemptingToLoad (getOriginalURL (actionInformation)); + [listener ignore]; + } + static void didFinishLoadForFrame (id self, SEL, WebView* sender, WebFrame* frame) { if ([frame isEqual: [sender mainFrame]]) diff --git a/modules/juce_gui_extra/native/juce_win32_WebBrowserComponent.cpp b/modules/juce_gui_extra/native/juce_win32_WebBrowserComponent.cpp index 273d790d04..2e1979810b 100644 --- a/modules/juce_gui_extra/native/juce_win32_WebBrowserComponent.cpp +++ b/modules/juce_gui_extra/native/juce_win32_WebBrowserComponent.cpp @@ -153,6 +153,13 @@ private: : VARIANT_TRUE; return S_OK; } + else if (dispIdMember == DISPID_NEWWINDOW3) + { + owner.newWindowAttemptingToLoad (pDispParams->rgvarg[0].bstrVal); + *pDispParams->rgvarg[3].pboolVal = VARIANT_TRUE; + + return S_OK; + } else if (dispIdMember == DISPID_DOCUMENTCOMPLETE) { owner.pageFinishedLoading (getStringFromVariant (pDispParams->rgvarg[0].pvarVal));