Fix bug 269084: allow users to select one or more cookies and say "block these sites" to add the sites to the "deny" list. Also tidy up the UI in the Cookies and Exceptions sheets to use action buttons, and save table and window state.

This commit is contained in:
smfr%smfr.org 2005-11-18 05:20:41 +00:00
Родитель 4bf26fb54d
Коммит 1745dfbcf0
8 изменённых файлов: 217 добавлений и 18 удалений

Двоичный файл не отображается.

Просмотреть файл

@ -16,6 +16,7 @@
{CLASS = NSTableView; LANGUAGE = ObjC; SUPERCLASS = NSControl; },
{
ACTIONS = {
blockCookiesFromSites = id;
clickAskAboutCookies = id;
clickAutoFillPasswords = id;
clickCookieBehavior = id;
@ -29,6 +30,7 @@
removeAllCookies = id;
removeCookiePermissions = id;
removeCookies = id;
removeCookiesAndBlockSites = id;
};
CLASS = OrgMozillaChimeraPreferencePrivacy;
LANGUAGE = ObjC;
@ -43,13 +45,11 @@
mPermissionFilterField = SearchTextField;
mPermissionsPanel = id;
mPermissionsTable = ExtendedTableView;
mRemoveAllCookiesButton = NSButton;
mRemoveAllPermissionsButton = NSButton;
mRemoveCookiesButton = NSButton;
mStorePasswords = NSButton;
};
SUPERCLASS = PreferencePaneBase;
},
{CLASS = PopupMenuButton; LANGUAGE = ObjC; SUPERCLASS = NSButton; },
{CLASS = PreferencePaneBase; LANGUAGE = ObjC; SUPERCLASS = NSPreferencePane; },
{
ACTIONS = {selectText = id; };

Просмотреть файл

@ -3,7 +3,14 @@
<plist version="1.0">
<dict>
<key>IBDocumentLocation</key>
<string>34 75 356 240 0 0 1600 1002 </string>
<string>67 25 406 307 0 0 1600 1002 </string>
<key>IBEditorPositions</key>
<dict>
<key>622</key>
<string>235 288 252 130 0 0 1600 1002 </string>
<key>635</key>
<string>813 503 126 68 0 0 1600 1002 </string>
</dict>
<key>IBFramework Version</key>
<string>437.0</string>
<key>IBSystem Version</key>

Двоичные данные
camino/PreferencePanes/Privacy/English.lproj/Privacy.nib/keyedobjects.nib сгенерированный Normal file

Двоичный файл не отображается.

Просмотреть файл

Просмотреть файл

@ -71,13 +71,10 @@ class nsICookie;
IBOutlet SearchTextField* mPermissionFilterField;
nsIPermissionManager* mPermissionManager; // STRONG (should be nsCOMPtr)
nsCOMArray<nsIPermission>* mCachedPermissions; // parallel list for speed, STRONG
IBOutlet NSButton* mRemoveAllPermissionsButton;
// cookie sheet
IBOutlet id mCookiesPanel;
IBOutlet ExtendedTableView* mCookiesTable;
IBOutlet NSButton* mRemoveCookiesButton;
IBOutlet NSButton* mRemoveAllCookiesButton;
IBOutlet SearchTextField* mCookiesFilterField;
nsICookieManager* mCookieManager;
nsCOMArray<nsICookie>* mCachedCookies;
@ -96,6 +93,8 @@ class nsICookie;
-(IBAction) editCookiesDone:(id)aSender;
-(IBAction) removeCookies:(id)aSender;
-(IBAction) removeAllCookies:(id)aSender;
-(IBAction) blockCookiesFromSites:(id)aSender;
-(IBAction) removeCookiesAndBlockSites:(id)aSender;
// permission editing functions
-(void) populatePermissionCache;

Просмотреть файл

@ -36,7 +36,9 @@
* ***** END LICENSE BLOCK ***** */
#import "PrivacyPane.h"
#import "NSString+Utils.h"
#import "NSArray+Utils.h"
#include "nsCOMPtr.h"
#include "nsServiceManagerUtils.h"
@ -123,6 +125,22 @@ const int kSortReverse = 1;
#pragma mark -
@interface OrgMozillaChimeraPreferencePrivacy(Private)
- (void)addPermission:(int)inPermission forHost:(NSString*)inHost;
- (int)numCookiesSelectedInCookiePanel;
- (int)numPermissionsSelectedInPermissionsPanel;
// get the number of unique cookie sites that are selected,
// and if it's just one, return the site name (with leading period removed, if necessary)
- (int)numUniqueCookieSitesSelected:(NSString**)outSiteName;
- (NSString*)permissionsBlockingNameForCookieHostname:(NSString*)inHostname;
- (NSArray*)selectedCookieSites;
@end
#pragma mark -
// callbacks for sorting the permission list
PR_STATIC_CALLBACK(int) comparePermHosts(nsIPermission* aPerm1, nsIPermission* aPerm2, void* aData)
{
@ -369,14 +387,14 @@ PR_STATIC_CALLBACK(int) compareValues(nsICookie* aCookie1, nsICookie* aCookie2,
//clear the filter field
[mCookiesFilterField setStringValue: @""];
// make sure the "remove all" button is enabled
[mRemoveAllCookiesButton setEnabled:YES];
// we shouldn't need to do this, but the scrollbar won't enable unless we
// force the table to reload its data. Oddly it gets the number of rows correct,
// it just forgets to tell the scrollbar. *shrug*
[mCookiesTable reloadData];
[mCookiesPanel setFrameAutosaveName:@"cookies_sheet"];
// bring up sheet
[NSApp beginSheet:mCookiesPanel
modalForWindow:[mAskAboutCookies window] // any old window accessor
@ -417,7 +435,7 @@ PR_STATIC_CALLBACK(int) compareValues(nsICookie* aCookie1, nsICookie* aCookie2,
if (rowToSelect >=0 && rowToSelect < [mCookiesTable numberOfRows])
[mCookiesTable selectRow:rowToSelect byExtendingSelection:NO];
else
[mCookiesTable deselectAll: self];
[mCookiesTable deselectAll:self];
}
-(IBAction) removeAllCookies: (id)aSender
@ -439,6 +457,67 @@ PR_STATIC_CALLBACK(int) compareValues(nsICookie* aCookie1, nsICookie* aCookie2,
}
}
-(IBAction) blockCookiesFromSites:(id)aSender
{
if (mCachedCookies && mPermissionManager) {
NSArray *rows = [[mCookiesTable selectedRowEnumerator] allObjects];
NSEnumerator *e = [rows reverseObjectEnumerator];
NSNumber *index;
while ((index = [e nextObject]))
{
int row = [index intValue];
nsCAutoString host, name, path;
mCachedCookies->ObjectAt(row)->GetHost(host);
[self addPermission:nsIPermissionManager::DENY_ACTION forHost:[NSString stringWith_nsACString:host]];
}
}
}
-(IBAction) removeCookiesAndBlockSites:(id)aSender
{
if (mCachedCookies && mPermissionManager)
{
// first fetch the list of sites
NSArray* selectedSites = [self selectedCookieSites];
int rowToSelect = -1;
// remove the cookies
for (int row = 0; row < mCachedCookies->Count(); row++)
{
nsCAutoString host, name, path;
// only search on the host
mCachedCookies->ObjectAt(row)->GetHost(host);
NSString* cookieHost = [NSString stringWith_nsACString:host];
if ([selectedSites containsObject:cookieHost])
{
if (rowToSelect == -1)
rowToSelect = row;
mCachedCookies->ObjectAt(row)->GetName(name);
mCachedCookies->ObjectAt(row)->GetPath(path);
mCookieManager->Remove(host, name, path, PR_FALSE); // don't block permanently
mCachedCookies->RemoveObjectAt(row);
--row; // to account for removal
}
}
// and block the sites
NSEnumerator* sitesEnum = [selectedSites objectEnumerator];
NSString* curSite;
while ((curSite = [sitesEnum nextObject]))
[self addPermission:nsIPermissionManager::DENY_ACTION forHost:curSite];
// and reload data
[mCookiesTable reloadData];
if (rowToSelect >=0 && rowToSelect < [mCookiesTable numberOfRows])
[mCookiesTable selectRow:rowToSelect byExtendingSelection:NO];
else
[mCookiesTable deselectAll:self];
}
}
-(IBAction) editCookiesDone:(id)aSender
{
// save stuff
@ -504,14 +583,14 @@ PR_STATIC_CALLBACK(int) compareValues(nsICookie* aCookie1, nsICookie* aCookie2,
//clear the filter field
[mPermissionFilterField setStringValue: @""];
// and make sure the button is enabled
[mRemoveAllPermissionsButton setEnabled:YES];
// we shouldn't need to do this, but the scrollbar won't enable unless we
// force the table to reload its data. Oddly it gets the number of rows correct,
// it just forgets to tell the scrollbar. *shrug*
[mPermissionsTable reloadData];
[mPermissionsPanel setFrameAutosaveName:@"permissions_sheet"];
// bring up sheet
[NSApp beginSheet:mPermissionsPanel
modalForWindow:[mAskAboutCookies window] // any old window accessor
@ -617,7 +696,8 @@ PR_STATIC_CALLBACK(int) compareValues(nsICookie* aCookie1, nsICookie* aCookie2,
mCachedPermissions = nsnull;
}
-(int) getRowForPermissionWithHost:(NSString *)aHost {
-(int) getRowForPermissionWithHost:(NSString *)aHost
{
nsCAutoString host;
if (mCachedPermissions) {
int numRows = mCachedPermissions->Count();
@ -726,7 +806,7 @@ PR_STATIC_CALLBACK(int) compareValues(nsICookie* aCookie1, nsICookie* aCookie2,
// nsIPermissions are immutable, and there's no API to change the action,
// so instead we have to delete the old pref and insert a new one.
// remove the old entry
mPermissionManager->Remove(host, "cookie");
mPermissionManager->Remove(host, "cookie"); // XXX necessary?
// add a new entry with the new permission
if ([anObject intValue] == kAllowIndex)
mPermissionManager->Add(newURI, "cookie", nsIPermissionManager::ALLOW_ACTION);
@ -862,8 +942,7 @@ PR_STATIC_CALLBACK(int) compareValues(nsICookie* aCookie1, nsICookie* aCookie2,
{
if ([aNotification object] == mCookiesTable)
{
int selRow =[mCookiesTable selectedRow];
[mRemoveCookiesButton setEnabled:(selRow != -1)];
// nothing to do
}
}
@ -929,7 +1008,6 @@ PR_STATIC_CALLBACK(int) compareValues(nsICookie* aCookie1, nsICookie* aCookie2,
if (([aNotification object] == mPermissionFilterField) && mCachedPermissions && mPermissionManager) {
// the user wants to filter down the list of cookies. Reinitialize the list of permission in case
// they deleted or replaced a letter.
[mRemoveAllPermissionsButton setEnabled:([filterString length] == 0)];
[self filterCookiesPermissionsWithString:filterString];
// re-sort
[self sortPermissionsByColumn:[mPermissionsTable highlightedTableColumn] inAscendingOrder:mSortedAscending];
@ -939,7 +1017,6 @@ PR_STATIC_CALLBACK(int) compareValues(nsICookie* aCookie1, nsICookie* aCookie2,
}
else if (([aNotification object] == mCookiesFilterField) && mCachedCookies && mCookieManager) {
// reinitialize the list of cookies in case user deleted a letter or replaced a letter
[mRemoveAllCookiesButton setEnabled:([filterString length] == 0)];
[self filterCookiesWithString:filterString];
// re-sort
[self sortCookiesByColumn:[mCookiesTable highlightedTableColumn] inAscendingOrder:mSortedAscending];
@ -998,4 +1075,120 @@ PR_STATIC_CALLBACK(int) compareValues(nsICookie* aCookie1, nsICookie* aCookie2,
mCachedCookies->RemoveObjectAt([currentItem intValue]);
}
}
- (void)addPermission:(int)inPermission forHost:(NSString*)inHost
{
nsCOMPtr<nsIURI> hostURI;
NS_NewURI(getter_AddRefs(hostURI), "http://");
nsCAutoString host([[self permissionsBlockingNameForCookieHostname:inHost] UTF8String]);
hostURI->SetHost(host);
mPermissionManager->Add(hostURI, "cookie", inPermission);
}
- (int)numCookiesSelectedInCookiePanel
{
int numSelected = 0;
if ([mCookiesPanel isVisible])
numSelected = [mCookiesTable numberOfSelectedRows];
return numSelected;
}
- (int)numPermissionsSelectedInPermissionsPanel
{
int numSelected = 0;
if ([mPermissionsPanel isVisible])
numSelected = [mPermissionsTable numberOfSelectedRows];
return numSelected;
}
- (int)numUniqueCookieSitesSelected:(NSString**)outSiteName
{
if (outSiteName)
*outSiteName = nil;
NSArray* selectedSites = [self selectedCookieSites];
unsigned int numHosts = [selectedSites count];
if (numHosts == 1 && outSiteName)
*outSiteName = [self permissionsBlockingNameForCookieHostname:[selectedSites firstObject]];
return numHosts;
}
- (NSString*)permissionsBlockingNameForCookieHostname:(NSString*)inHostname
{
// if the host string starts with a '.', remove it (because this is
// how the permissions manager looks up hosts)
if ([inHostname hasPrefix:@"."])
inHostname = [inHostname substringFromIndex:1];
return inHostname;
}
- (NSArray*)selectedCookieSites
{
// the set does the uniquifying for us
NSMutableSet* selectedHostsSet = [[[NSMutableSet alloc] init] autorelease];
NSEnumerator* e = [mCookiesTable selectedRowEnumerator];
NSNumber* index;
while ((index = [e nextObject]))
{
int row = [index intValue];
nsCAutoString host;
mCachedCookies->ObjectAt(row)->GetHost(host);
NSString* hostString = [NSString stringWith_nsACString:host];
[selectedHostsSet addObject:hostString];
}
return [selectedHostsSet allObjects];
}
- (BOOL)validateMenuItem:(NSMenuItem*)inMenuItem
{
SEL action = [inMenuItem action];
// cookies context menu
if (action == @selector(removeCookies:))
return ([self numCookiesSelectedInCookiePanel] > 0);
// only allow "remove all" if we're not filtering
if (action == @selector(removeAllCookies:))
return ([[mCookiesFilterField stringValue] length] == 0);
if (action == @selector(blockCookiesFromSites:))
{
NSString* siteName = nil;
int numCookieSites = [self numUniqueCookieSitesSelected:&siteName];
NSString* menuTitle = (numCookieSites == 1) ?
[NSString stringWithFormat:[self getLocalizedString:@"BlockCookieFromSite"], siteName] :
[self getLocalizedString:@"BlockCookiesFromSites"];
[inMenuItem setTitle:menuTitle];
return (numCookieSites > 0);
}
if (action == @selector(removeCookiesAndBlockSites:))
{
NSString* siteName = nil;
int numCookieSites = [self numUniqueCookieSitesSelected:&siteName];
NSString* menuTitle = (numCookieSites == 1) ?
[NSString stringWithFormat:[self getLocalizedString:@"RemoveAndBlockCookieFromSite"], siteName] :
[self getLocalizedString:@"RemoveAndBlockCookiesFromSites"];
[inMenuItem setTitle:menuTitle];
return (numCookieSites > 0);
}
// permissions context menu
if (action == @selector(removeCookiePermissions:))
return ([self numPermissionsSelectedInPermissionsPanel] > 0);
// only allow "remove all" if we're not filtering
if (action == @selector(removeAllCookiePermissions:))
return ([[mPermissionFilterField stringValue] length] == 0);
return YES;
}
@end

Двоичные данные
camino/PreferencePanes/Privacy/images/action_button.tiff Normal file

Двоичный файл не отображается.