Camino only - Bug 343937: Give access to all popup options in the notification bar. r=smurph r=kreeger sr=mento

This commit is contained in:
stuart.morgan%alumni.case.edu 2007-02-17 01:32:00 +00:00
parent 289604f585
commit 388f119bfe
7 changed files with 117 additions and 76 deletions

View File

@ -2,15 +2,17 @@
IBClasses = (
{
ACTIONS = {
configurePopupBlocking = id;
blacklistPopups = id;
hideBlockedPopupView = id;
reloadWithNewCharset = id;
unblockPopupSites = id;
showPopups = id;
unblockPopups = id;
};
CLASS = BrowserWrapper;
LANGUAGE = ObjC;
OUTLETS = {
mBlockedPopupCloseButton = RolloverImageButton;
mBlockedPopupLabel = NSTextField;
mBlockedPopupView = NSView;
mCreateDelegate = id;
mDelegate = id;

View File

@ -3,11 +3,11 @@
<plist version="1.0">
<dict>
<key>IBDocumentLocation</key>
<string>62 9 356 240 0 0 1680 1028 </string>
<string>51 7 356 240 0 0 1440 878 </string>
<key>IBEditorPositions</key>
<dict>
<key>5</key>
<string>542 649 645 72 0 0 1680 1028 </string>
<string>382 549 720 72 0 0 1440 878 </string>
</dict>
<key>IBFramework Version</key>
<string>446.1</string>
@ -16,6 +16,6 @@
<integer>5</integer>
</array>
<key>IBSystem Version</key>
<string>8L2127</string>
<string>8J2135a</string>
</dict>
</plist>

View File

@ -190,7 +190,8 @@ typedef enum
- (void)focusURLBar;
- (void)unblockAllPopupSites:(nsIArray*)inSites;
- (void)showBlockedPopups:(nsIArray*)blockedSites whitelistingSource:(BOOL)shouldWhitelist;
- (void)blacklistPopupsFromURL:(NSString*)inURL;
// call to update feed detection in a page
- (void)showFeedDetected:(BOOL)inDetected;

View File

@ -551,8 +551,8 @@ enum BWCOpenDest {
- (void)sessionHistoryItemAtRelativeOffset:(int)indexOffset forWrapper:(BrowserWrapper*)inWrapper title:(NSString**)outTitle URL:(NSString**)outURLString;
- (NSString *)locationToolTipWithFormat:(NSString *)format title:(NSString *)backTitle URL:(NSString *)backURL;
- (void)whitelistURL:(nsIURI*)URL;
- (void)whitelistAndShowPopup:(nsIDOMPopupBlockedEvent*)aBlockedPopup;
- (void)whitelistPopupsFromURL:(NSString*)inURL;
- (void)showPopup:(nsIDOMPopupBlockedEvent*)aBlockedPopup;
- (void)clearContextMenuTarget;
- (void)updateLock:(unsigned int)securityState;
@ -1896,18 +1896,6 @@ enum BWCOpenDest {
// do nothing, everything is now handled by the BrowserWindow.
}
//
// -configurePopupBlocking
//
// Called to display our popup blocking configuration ui, which is in prefs.
// Show the prefs window focused on the "web features" panel.
//
- (void)configurePopupBlocking
{
[[MVPreferencesController sharedInstance] showPreferences:nil];
[[MVPreferencesController sharedInstance] selectPreferencePaneByIdentifier:@"org.mozilla.camino.preference.webfeatures"];
}
//
// -openFeedPrefPane
//
@ -1920,15 +1908,14 @@ enum BWCOpenDest {
}
//
// -unblockAllPopupSites:
// showBlockedPopups:whitelistingSource:
//
// Called in response to the menu item from the unblock popup. Puts all the
// blocked popups in the array on the whitelist, and shows them.
// UI delegate method to show the given blocked popups, optionally whitelisting the source.
//
- (void)unblockAllPopupSites:(nsIArray*)inSites
- (void)showBlockedPopups:(nsIArray*)blockedSites whitelistingSource:(BOOL)shouldWhitelist
{
nsCOMPtr<nsISimpleEnumerator> enumerator;
inSites->Enumerate(getter_AddRefs(enumerator));
blockedSites->Enumerate(getter_AddRefs(enumerator));
PRBool hasMore = PR_FALSE;
// iterate over the array of blocked popup events, and unblock & show
@ -1942,11 +1929,15 @@ enum BWCOpenDest {
nsCOMPtr<nsIDOMPopupBlockedEvent> evt;
evt = do_QueryInterface(curSupports);
if (evt)
[self whitelistAndShowPopup:evt];
[self showPopup:evt];
}
// Because of the way our UI is set up, we white/blacklist based on the top-level window URI,
// rather than the requesting URI (which can be different on framed sites).
if (shouldWhitelist)
[self whitelistPopupsFromURL:[mBrowserView currentURI]];
}
- (void)whitelistAndShowPopup:(nsIDOMPopupBlockedEvent*)aPopupBlockedEvent
- (void)showPopup:(nsIDOMPopupBlockedEvent*)aPopupBlockedEvent
{
nsCOMPtr<nsIDOMWindow> requestingWindow;
aPopupBlockedEvent->GetRequestingWindow(getter_AddRefs(requestingWindow));
@ -1980,17 +1971,6 @@ enum BWCOpenDest {
nsCAutoString uriStr;
popupWindowURI->GetSpec(uriStr);
// whitelist the URL
nsCOMPtr<nsIURI> requestingWindowURI;
nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(requestingWindow);
if (webNav)
webNav->GetCurrentURI(getter_AddRefs(requestingWindowURI));
if (requestingWindowURI)
[self whitelistURL:requestingWindowURI];
else
NSLog(@"Couldn't whitelist the URI");
// show the blocked popup
nsCOMPtr<nsIDOMWindow> openedWindow;
nsresult rv = piDomWin->Open(NS_ConvertUTF8toUTF16(uriStr), windowName, features, getter_AddRefs(openedWindow));
@ -1998,10 +1978,22 @@ enum BWCOpenDest {
NSLog(@"Couldn't show the blocked popup window for %@", [NSString stringWith_nsACString:uriStr]);
}
- (void)whitelistURL:(nsIURI*)URL
- (void)whitelistPopupsFromURL:(NSString*)inURL
{
nsCOMPtr<nsIPermissionManager> pm (do_GetService(NS_PERMISSIONMANAGER_CONTRACTID));
pm->Add(URL, "popup", nsIPermissionManager::ALLOW_ACTION);
nsCOMPtr<nsIURI> uri;
NS_NewURI(getter_AddRefs(uri), [inURL UTF8String]);
nsCOMPtr<nsIPermissionManager> pm(do_GetService(NS_PERMISSIONMANAGER_CONTRACTID));
if (pm && uri)
pm->Add(uri, "popup", nsIPermissionManager::ALLOW_ACTION);
}
- (void)blacklistPopupsFromURL:(NSString*)inURL
{
nsCOMPtr<nsIURI> uri;
NS_NewURI(getter_AddRefs(uri), [inURL UTF8String]);
nsCOMPtr<nsIPermissionManager> pm(do_GetService(NS_PERMISSIONMANAGER_CONTRACTID));
if (pm && uri)
pm->Add(uri, "popup", nsIPermissionManager::DENY_ACTION);
}
//

View File

@ -66,10 +66,10 @@ class nsIArray;
- (void)updateSiteIcons:(NSImage*)icon ignoreTyping:(BOOL)ignoreTyping;
- (void)showPopupBlocked:(BOOL)blocked;
- (void)configurePopupBlocking;
- (void)unblockAllPopupSites:(nsIArray*)inSites;
- (void)showSecurityState:(unsigned long)state;
- (void)showFeedDetected:(BOOL)inDetected;
- (void)showBlockedPopups:(nsIArray*)blockedSites whitelistingSource:(BOOL)shouldWhitelist;
- (void)blacklistPopupsFromURL:(NSString*)inURL;
- (BOOL)userChangedLocationField;
@ -140,7 +140,7 @@ class nsIArray;
NSString* mDisplayTitle;
// 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;
nsIMutableArray* mBlockedPopups;
NSMutableArray* mFeedList; // list of feeds found on page
CHBrowserView* mBrowserView; // retained
@ -148,7 +148,8 @@ class nsIArray;
NSMutableArray* mStatusStrings; // current status bar messages, STRONG
IBOutlet NSView* mBlockedPopupView; // loaded on demand, can be nil, STRONG
IBOutlet RolloverImageButton* mBlockedPopupCloseButton;
IBOutlet RolloverImageButton* mBlockedPopupCloseButton;
IBOutlet NSTextField* mBlockedPopupLabel;
double mProgress;
@ -197,8 +198,9 @@ class nsIArray;
- (unsigned long)securityState;
- (NSArray*)feedList;
- (IBAction)configurePopupBlocking:(id)sender;
- (IBAction)unblockPopupSites:(id)sender;
- (IBAction)showPopups:(id)sender;
- (IBAction)unblockPopups:(id)sender;
- (IBAction)blacklistPopups:(id)sender;
- (IBAction)hideBlockedPopupView:(id)sender;
- (void)loadURI:(NSString *)urlSpec referrer:(NSString*)referrer flags:(unsigned int)flags focusContent:(BOOL)focusContent allowPopups:(BOOL)inAllowPopups;

View File

@ -66,6 +66,7 @@
#include "nsIArray.h"
#include "nsIURI.h"
#include "nsNetUtil.h"
#include "nsIIOService.h"
#include "nsIDocument.h"
#include "nsIDOMWindow.h"
@ -79,6 +80,7 @@
#include "nsIDOMEventReceiver.h"
#include "nsIWebProgressListener.h"
#include "nsIBrowserDOMWindow.h"
#include "nsIPermissionManager.h"
class nsIDOMPopupBlockedEvent;
@ -113,6 +115,8 @@ enum {
- (void)checkForCustomViewOnLoad:(NSString*)inURL;
- (BOOL)popupsAreBlacklistedForURL:(NSString*)inURL;
- (void)showPopupsWhitelistingSource:(BOOL)shouldWhitelist;
- (void)addBlockedPopupViewAndDisplay;
- (void)removeBlockedPopupViewAndDisplay;
@ -190,7 +194,7 @@ enum {
[mToolTip release];
[mDisplayTitle release];
NS_IF_RELEASE(mBlockedSites);
NS_IF_RELEASE(mBlockedPopups);
[mFeedList release];
@ -343,10 +347,10 @@ enum {
- (BOOL)popupsBlocked
{
if (!mBlockedSites) return NO;
if (!mBlockedPopups) return NO;
PRUint32 numBlocked = 0;
mBlockedSites->GetLength(&numBlocked);
mBlockedPopups->GetLength(&numBlocked);
return (numBlocked > 0);
}
@ -540,8 +544,8 @@ enum {
{
// defer hiding of blocked popup view until we've loaded the new page
[self removeBlockedPopupViewAndDisplay];
if(mBlockedSites)
mBlockedSites->Clear();
if(mBlockedPopups)
mBlockedPopups->Clear();
[mDelegate showPopupBlocked:NO];
NSString* faviconURI = [SiteIconProvider defaultFaviconLocationStringFromURI:urlSpec];
@ -704,20 +708,21 @@ enum {
}
//
// - onPopupBlocked:fromSite:
// - onPopupBlocked:
//
// 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.
// and more data that we'll need if the user wants to unblock the popup later.
//
- (void)onPopupBlocked:(nsIDOMPopupBlockedEvent*)eventData;
{
// If popups from this site have been blacklisted, silently discard the event.
if ([self popupsAreBlacklistedForURL:[self currentURI]])
return;
// lazily instantiate.
if (!mBlockedSites)
CallCreateInstance(NS_ARRAY_CONTRACTID, &mBlockedSites);
if (mBlockedSites) {
mBlockedSites->AppendElement((nsISupports*)eventData, PR_FALSE);
if (!mBlockedPopups)
CallCreateInstance(NS_ARRAY_CONTRACTID, &mBlockedPopups);
if (mBlockedPopups) {
mBlockedPopups->AppendElement((nsISupports*)eventData, PR_FALSE);
[self addBlockedPopupViewAndDisplay];
[mDelegate showPopupBlocked:YES];
}
@ -1047,31 +1052,66 @@ enum {
#pragma mark -
//
// -configurePopupBlocking:
//
// Called when the user clicks on the "configure" button in the blocked popup view.
// Sends the msg along to our UI delegate so they can handle it
//
- (IBAction)configurePopupBlocking:(id)sender
- (BOOL)popupsAreBlacklistedForURL:(NSString*)inURL
{
[mDelegate configurePopupBlocking];
nsCOMPtr<nsIURI> uri;
NS_NewURI(getter_AddRefs(uri), [inURL UTF8String]);
nsCOMPtr<nsIPermissionManager> pm(do_GetService(NS_PERMISSIONMANAGER_CONTRACTID));
if (pm && uri) {
PRUint32 permission;
pm->TestPermission(uri, "popup", &permission);
return (permission == nsIPermissionManager::DENY_ACTION);
}
return NO;
}
//
// -unblockPopupSites:
// -showPopups:
//
// Called when the user clicks on the "unblock" button in the blocked popup view.
// Sends the msg along with the list of sites whose popups we just blocked to our UI
// delegate so they can handle it. This also removes the blocked popup UI from
// the current window.
// Called when the user clicks on the "Allow Once" button in the blocked popup view.
// Shows the blocked popups without whitelisting the source page.
//
- (IBAction)unblockPopupSites:(id)sender
- (IBAction)showPopups:(id)sender
{
[self showPopupsWhitelistingSource:NO];
}
//
// -unblockPopups:
//
// Called when the user clicks on the "Always Allow" button in the blocked popup view.
// Shows the blocked popups and whitelists the source page.
//
- (IBAction)unblockPopups:(id)sender
{
[self showPopupsWhitelistingSource:YES];
}
//
// -blacklistPopups:
//
// Called when the user clicks on the "Never Allow" button in the blocked popup view.
// Adds the current site to the blacklist, and dismisses the blocked popup UI.
//
- (IBAction)blacklistPopups:(id)sender
{
[mDelegate blacklistPopupsFromURL:[self currentURI]];
[self removeBlockedPopupViewAndDisplay];
}
//
// -showPopupsWhitelistingSource:
//
// Private helper method to handle showing blocked popups.
// Sends the the list of popups we just blocked to our UI delegate so it can
// handle them. This also removes the blocked popup UI from the current window.
//
- (void)showPopupsWhitelistingSource:(BOOL)shouldWhitelist
{
NS_ASSERTION([self popupsBlocked], "no popups to unblock!");
if ([self popupsBlocked]) {
nsCOMPtr<nsIArray> blockedSites = do_QueryInterface(mBlockedSites);
[mDelegate unblockAllPopupSites:blockedSites];
nsCOMPtr<nsIArray> blockedSites = do_QueryInterface(mBlockedPopups);
[mDelegate showBlockedPopups:blockedSites whitelistingSource:shouldWhitelist];
[self removeBlockedPopupViewAndDisplay];
}
}
@ -1087,6 +1127,10 @@ enum {
if ([self popupsBlocked] && !mBlockedPopupView) {
[NSBundle loadNibNamed:@"PopupBlockView" owner:self];
NSString* currentHost = [[NSURL URLWithString:[self currentURI]] host];
if (!currentHost)
currentHost = NSLocalizedString(@"GenericHostString", nil);
[mBlockedPopupLabel setStringValue:[NSString stringWithFormat:NSLocalizedString(@"PopupDisplayRequest", nil), currentHost]];
[mBlockedPopupCloseButton setImage:[NSImage imageNamed:@"popup_close"]];
[mBlockedPopupCloseButton setAlternateImage:[NSImage imageNamed:@"popup_close_pressed"]];
[mBlockedPopupCloseButton setHoverImage:[NSImage imageNamed:@"popup_close_hover"]];