Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(186)

Unified Diff: chrome/browser/cocoa/cookies_window_controller.mm

Issue 546102: [Mac] Fix a crash in the cookies manager that was caused by an invalid selection. (Closed)
Patch Set: do'h Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/cocoa/cookies_window_controller.mm
diff --git a/chrome/browser/cocoa/cookies_window_controller.mm b/chrome/browser/cocoa/cookies_window_controller.mm
index 8325f3a6102688412ec9d9aa5737e9cfd6b0e0f9..75e5060f356fc4fb8e6434697773ef4625e5aa28 100644
--- a/chrome/browser/cocoa/cookies_window_controller.mm
+++ b/chrome/browser/cocoa/cookies_window_controller.mm
@@ -128,6 +128,7 @@ CocoaCookieTreeNode* CookiesTreeModelObserverBridge::FindCocoaNode(
@implementation CookiesWindowController
+@synthesize removeButtonEnabled = removeButtonEnabled_;
@synthesize treeController = treeController_;
- (id)initWithProfile:(Profile*)profile {
@@ -262,6 +263,33 @@ CocoaCookieTreeNode* CookiesTreeModelObserverBridge::FindCocoaNode(
}
}
+- (void)outlineViewSelectionDidChange:(NSNotification*)notif {
+ // Multi-selection should be disabled in the UI, but for sanity, double-check
+ // that they can't do it here.
+ NSUInteger count = [[treeController_ selectedObjects] count];
+ if (count != 1U) {
+ DCHECK_LT(count, 1U) << "User was able to select more than one cookie node!";
+ [self setRemoveButtonEnabled:NO];
+ return;
+ }
+
+ // Go through the selection's indexPath and make sure that the node that is
+ // being referenced actually exists in the Cocoa model.
+ NSIndexPath* selection = [treeController_ selectionIndexPath];
+ NSUInteger length = [selection length];
+ CocoaCookieTreeNode* node = [self cocoaTreeModel];
+ for (NSUInteger i = 0; i < length; ++i) {
+ NSUInteger childIndex = [selection indexAtPosition:i];
+ if (childIndex >= [[node children] count]) {
+ [self setRemoveButtonEnabled:NO];
+ return;
+ }
+ node = [[node children] objectAtIndex:childIndex];
+ }
+
+ [self setRemoveButtonEnabled:YES];
+}
+
#pragma mark Unit Testing
- (CookiesTreeModelObserverBridge*)modelObserver {
« no previous file with comments | « chrome/browser/cocoa/cookies_window_controller.h ('k') | chrome/browser/cocoa/cookies_window_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698