From ecbd24f47289e8d3665bcd95886f4b0b88df05b9 Mon Sep 17 00:00:00 2001 From: "hwaara%gmail.com" Date: Thu, 6 Jul 2006 08:13:25 +0000 Subject: [PATCH] Fix bug 331194, implement ability to show (and whitelist) blocked popups. r/sr=pinkerton --- camino/src/browser/BrowserContentViews.h | 5 ---- camino/src/browser/BrowserContentViews.mm | 21 ------------- camino/src/browser/BrowserWindowController.h | 2 +- camino/src/browser/BrowserWrapper.h | 12 ++++---- camino/src/browser/BrowserWrapper.mm | 31 ++++++++------------ camino/src/browser/KeychainService.mm | 2 +- camino/src/embedding/CHBrowserListener.mm | 11 +++---- camino/src/embedding/CHBrowserView.h | 6 +++- camino/src/embedding/CHBrowserView.mm | 12 ++++++++ 9 files changed, 42 insertions(+), 60 deletions(-) diff --git a/camino/src/browser/BrowserContentViews.h b/camino/src/browser/BrowserContentViews.h index d14118d6cfff..2650e7775f51 100644 --- a/camino/src/browser/BrowserContentViews.h +++ b/camino/src/browser/BrowserContentViews.h @@ -58,8 +58,3 @@ } @end - -@interface BookmarkManagerView : NSView -{ -} -@end diff --git a/camino/src/browser/BrowserContentViews.mm b/camino/src/browser/BrowserContentViews.mm index b4d26f4eb495..8d1ab69d62e1 100644 --- a/camino/src/browser/BrowserContentViews.mm +++ b/camino/src/browser/BrowserContentViews.mm @@ -186,24 +186,3 @@ } @end - -#pragma mark - - -@implementation BookmarkManagerView - -- (BOOL) isOpaque -{ - return YES; -} - -- (void)drawRect:(NSRect)aRect -{ - [[NSColor windowBackgroundColor] set]; - NSRectFill(aRect); - [[NSColor lightGrayColor] set]; - NSFrameRect([self bounds]); -} - -@end - - diff --git a/camino/src/browser/BrowserWindowController.h b/camino/src/browser/BrowserWindowController.h index a2a4e1b7e5ab..fd35cb51ab13 100644 --- a/camino/src/browser/BrowserWindowController.h +++ b/camino/src/browser/BrowserWindowController.h @@ -187,7 +187,7 @@ typedef enum - (void)focusURLBar; -- (void)unblockAllPopupSites:(nsISupportsArray*)inSites; +- (void)unblockAllPopupSites:(nsIArray*)inSites; - (void)performAppropriateLocationAction; - (IBAction)goToLocationFromToolbarURLField:(id)sender; diff --git a/camino/src/browser/BrowserWrapper.h b/camino/src/browser/BrowserWrapper.h index 081f0395ac6b..894916038ca7 100644 --- a/camino/src/browser/BrowserWrapper.h +++ b/camino/src/browser/BrowserWrapper.h @@ -42,7 +42,8 @@ @class ToolTip; @class AutoCompleteTextField; -class nsISupportsArray; +class nsIMutableArray; +class nsIArray; // // The BrowserWrapper communicates with the UI via this delegate. @@ -65,7 +66,7 @@ class nsISupportsArray; - (void)showPopupBlocked:(BOOL)blocked; - (void)configurePopupBlocking; -- (void)unblockAllPopupSites:(nsISupportsArray*)inSites; +- (void)unblockAllPopupSites:(nsIArray*)inSites; - (void)showSecurityState:(unsigned long)state; - (BOOL)userChangedLocationField; @@ -138,9 +139,9 @@ class nsISupportsArray; NSString* mTitle; // the title we use for the tab. This differs for mTitle when the tab is loading NSString* mTabTitle; - // array of sites that have blocked popups. If nil, no sites are blocked. Cleared - // after each new page. - nsISupportsArray* mBlockedSites; // STRONG + // array of popupevents that have been blocked. We can use them to reconstruct the popups + // later. If nil, no sites are blocked. Cleared after each new page. + nsIMutableArray* mBlockedSites; CHBrowserView* mBrowserView; // retained NSString* mDefaultStatusString; @@ -194,7 +195,6 @@ class nsISupportsArray; - (NSString*)getCurrentURI; -- (void)getBlockedSites:(nsISupportsArray**)outSites; - (IBAction)configurePopupBlocking:(id)sender; - (IBAction)unblockPopupSites:(id)sender; - (IBAction)hideBlockedPopupView:(id)sender; diff --git a/camino/src/browser/BrowserWrapper.mm b/camino/src/browser/BrowserWrapper.mm index 76585885ddac..62b8f976f5b2 100644 --- a/camino/src/browser/BrowserWrapper.mm +++ b/camino/src/browser/BrowserWrapper.mm @@ -55,7 +55,8 @@ #include "nsCOMPtr.h" #include "nsIServiceManager.h" -#include "nsISupportsArray.h" +#include "nsIMutableArray.h" +#include "nsIArray.h" #include "nsIURI.h" #include "nsIIOService.h" #include "nsIDocument.h" @@ -71,6 +72,7 @@ #include "nsIWebProgressListener.h" #include "nsIBrowserDOMWindow.h" +class nsIDOMPopupBlockedEvent; static NSString* const kOfflineNotificationName = @"offlineModeChanged"; @@ -134,7 +136,6 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged"; mListenersAttached = NO; mSecureState = nsIWebProgressListener::STATE_IS_INSECURE; mProgress = 0.0; - mBlockedSites = nsnull; BOOL gotPref; BOOL pluginsEnabled = [[PreferenceManager sharedInstance] getBooleanPref:"camino.enable_plugins" withSuccess:&gotPref]; @@ -317,7 +318,7 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged"; if (!mBlockedSites) return NO; PRUint32 numBlocked = 0; - mBlockedSites->Count(&numBlocked); + mBlockedSites->GetLength(&numBlocked); return (numBlocked > 0); } @@ -526,7 +527,8 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged"; { // defer hiding of blocked popup view until we've loaded the new page [self removeBlockedPopupViewAndDisplay]; - NS_IF_RELEASE(mBlockedSites); + if(mBlockedSites) + mBlockedSites->Clear(); [mDelegate showPopupBlocked:NO]; NSString* faviconURI = [SiteIconProvider defaultFaviconLocationStringFromURI:urlSpec]; @@ -708,18 +710,18 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged"; // // - onPopupBlocked:fromSite: // -// Called when gecko blocks a popup, telling us who it came from. Keep track -// of the blocked URI so we can allow the user to unblock the site later. This +// Called when gecko blocks a popup, telling us who it came from, the modifiers of the popup +// and more data that we'll need if the user wants to unblock the popup later. This // doesn't show the blocked popup view, we wait until the page finishes loading // to do that. // -- (void)onPopupBlocked:(nsIURI*)inURIBlocked fromSite:(nsIURI*)inSite +- (void)onPopupBlocked:(nsIDOMPopupBlockedEvent*)eventData; { // lazily instantiate. if (!mBlockedSites) - NS_NewISupportsArray(&mBlockedSites); + CallCreateInstance(NS_ARRAY_CONTRACTID, &mBlockedSites); if (mBlockedSites) { - mBlockedSites->AppendElement(inSite); + mBlockedSites->AppendElement((nsISupports*)eventData, PR_FALSE); [mDelegate showPopupBlocked:YES]; } } @@ -1046,14 +1048,6 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged"; return [[self getBrowserView] currentCharset]; } -- (void)getBlockedSites:(nsISupportsArray**)outSites -{ - if ( !outSites ) - return; - *outSites = mBlockedSites; - NS_IF_ADDREF(*outSites); -} - // // -configurePopupBlocking: // @@ -1077,7 +1071,8 @@ static NSString* const kOfflineNotificationName = @"offlineModeChanged"; { NS_ASSERTION([self popupsBlocked], "no popups to unblock!"); if ([self popupsBlocked]) { - [mDelegate unblockAllPopupSites:mBlockedSites]; + nsCOMPtr blockedSites = do_QueryInterface(mBlockedSites); + [mDelegate unblockAllPopupSites:blockedSites]; [self removeBlockedPopupViewAndDisplay]; } } diff --git a/camino/src/browser/KeychainService.mm b/camino/src/browser/KeychainService.mm index 9e90b01ffcc6..fb29b1dc0d09 100644 --- a/camino/src/browser/KeychainService.mm +++ b/camino/src/browser/KeychainService.mm @@ -1111,7 +1111,7 @@ KeychainFormSubmitObserver::CheckChangeDataYN(nsIDOMWindowInternal* window) { } -- (void)onPopupBlocked:(nsIURI*)inURIBlocked fromSite:(nsIURI*)inSite +- (void)onPopupBlocked:(nsIDOMPopupBlockedEvent*)data; { } diff --git a/camino/src/embedding/CHBrowserListener.mm b/camino/src/embedding/CHBrowserListener.mm index 1bb27eaef11e..8ee887042a97 100644 --- a/camino/src/embedding/CHBrowserListener.mm +++ b/camino/src/embedding/CHBrowserListener.mm @@ -769,13 +769,10 @@ CHBrowserListener::HandleEvent(nsIDOMEvent* inEvent) nsresult CHBrowserListener::HandleBlockedPopupEvent(nsIDOMEvent* inEvent) { - nsCOMPtr blockEvent = do_QueryInterface(inEvent); - if (blockEvent) { - nsCOMPtr blockedURI, blockedSite; - blockEvent->GetPopupWindowURI(getter_AddRefs(blockedURI)); - blockEvent->GetRequestingWindowURI(getter_AddRefs(blockedSite)); - [mContainer onPopupBlocked:blockedURI fromSite:blockedSite]; - } + nsCOMPtr blockedPopupEvent = do_QueryInterface(inEvent); + if (blockedPopupEvent) + [mContainer onPopupBlocked:blockedPopupEvent]; + return NS_OK; } diff --git a/camino/src/embedding/CHBrowserView.h b/camino/src/embedding/CHBrowserView.h index 188eea7da676..e8bd344f1de1 100644 --- a/camino/src/embedding/CHBrowserView.h +++ b/camino/src/embedding/CHBrowserView.h @@ -50,7 +50,9 @@ class CHBrowserListener; class nsIDOMWindow; class nsIWebBrowser; +class nsIDocShell; class nsIDOMNode; +class nsIDOMPopupBlockedEvent; class nsIDOMEvent; class nsIEventSink; class nsIDragHelperService; @@ -82,7 +84,7 @@ class nsISecureBrowserUI; - (void)onShowTooltip:(NSPoint)where withText:(NSString*)text; - (void)onHideTooltip; // Called when a popup is blocked -- (void)onPopupBlocked:(nsIURI*)inURIBlocked fromSite:(nsIURI*)inSite; +- (void)onPopupBlocked:(nsIDOMPopupBlockedEvent*)data; // Called when a "shortcut icon" link element is noticed - (void)onFoundShortcutIcon:(NSString*)inIconURI; @@ -282,6 +284,8 @@ typedef enum { - (already_AddRefed)getPageDescriptor; - (void)setPageDescriptor:(nsISupports*)aDesc displayType:(PRUint32)aDisplayType; +- (already_AddRefed)findDocShellForURI:(nsIURI*)aURI; + @end #endif // __nsCocoaBrowserView_h__ diff --git a/camino/src/embedding/CHBrowserView.mm b/camino/src/embedding/CHBrowserView.mm index 33f623830169..17470a26cbef 100644 --- a/camino/src/embedding/CHBrowserView.mm +++ b/camino/src/embedding/CHBrowserView.mm @@ -117,6 +117,8 @@ typedef unsigned int DragReference; #include "nsICommandManager.h" #include "nsICommandParams.h" +#include "GeckoUtils.h" + const char kPersistContractID[] = "@mozilla.org/embedding/browser/nsWebBrowserPersist;1"; const char kDirServiceContractID[] = "@mozilla.org/file/directory_service;1"; @@ -1219,6 +1221,16 @@ const long NSFindPanelActionSetFindString = 7; return privWin->GetDocShell(); } +// used for finding a blocked popup's docshell +// addrefs the result! +- (already_AddRefed)findDocShellForURI:(nsIURI*)aURI +{ + nsIDocShell *match; + GeckoUtils::FindDocShellForURI(aURI, [self getDocShell], &match); + return match; +} + + - (id)getBrowserContainer { // i'm not sure why this doesn't return whatever -setContainer: was called with