1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Added new callback method WebBrowserComponent:: newWindowAttemptingToLoad()

This commit is contained in:
jules 2014-11-04 17:55:58 +00:00
parent 6aebccfeb6
commit 2792bd2761
5 changed files with 42 additions and 7 deletions

View file

@ -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);
}

View file

@ -146,5 +146,6 @@ namespace juce
bool WebBrowserComponent::pageAboutToLoad (const String&) { return true; }
void WebBrowserComponent::pageFinishedLoading (const String&) {}
void WebBrowserComponent::windowCloseRequest() {}
void WebBrowserComponent::newWindowAttemptingToLoad (const String&) {}
#endif
}

View file

@ -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 gotToURL.
*/
virtual void newWindowAttemptingToLoad (const String& newURL);
//==============================================================================
/** @internal */
void paint (Graphics&) override;

View file

@ -32,6 +32,8 @@ struct DownloadClickDetectorClass : public ObjCClass <NSObject>
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 <NSObject>
static WebBrowserComponent* getOwner (id self) { return getIvar<WebBrowserComponent*> (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 <WebPolicyDecisionListener> 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 <WebPolicyDecisionListener> listener)
{
getOwner (self)->newWindowAttemptingToLoad (getOriginalURL (actionInformation));
[listener ignore];
}
static void didFinishLoadForFrame (id self, SEL, WebView* sender, WebFrame* frame)
{
if ([frame isEqual: [sender mainFrame]])

View file

@ -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));