OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "chrome/browser/cocoa/cookies_window_controller.h" | 5 #import "chrome/browser/cocoa/cookies_window_controller.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "app/l10n_util_mac.h" | 9 #include "app/l10n_util_mac.h" |
10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 [[folderChild childNodes] objectAtIndex:0]; | 313 [[folderChild childNodes] objectAtIndex:0]; |
314 [treeController_ setSelectionIndexPath:[firstCookieChild indexPath]]; | 314 [treeController_ setSelectionIndexPath:[firstCookieChild indexPath]]; |
315 } | 315 } |
316 } | 316 } |
317 } | 317 } |
318 } | 318 } |
319 | 319 |
320 - (void)outlineViewSelectionDidChange:(NSNotification*)notif { | 320 - (void)outlineViewSelectionDidChange:(NSNotification*)notif { |
321 // Multi-selection should be disabled in the UI, but for sanity, double-check | 321 // Multi-selection should be disabled in the UI, but for sanity, double-check |
322 // that they can't do it here. | 322 // that they can't do it here. |
323 NSUInteger count = [[treeController_ selectedObjects] count]; | 323 NSArray* selectedObjects = [treeController_ selectedObjects]; |
| 324 NSUInteger count = [selectedObjects count]; |
324 if (count != 1U) { | 325 if (count != 1U) { |
325 DCHECK_LT(count, 1U) << "User was able to select more than 1 cookie node!"; | 326 DCHECK_LT(count, 1U) << "User was able to select more than 1 cookie node!"; |
326 [self setRemoveButtonEnabled:NO]; | 327 [self setRemoveButtonEnabled:NO]; |
327 return; | 328 return; |
328 } | 329 } |
329 | 330 |
330 // Go through the selection's indexPath and make sure that the node that is | 331 // Go through the selection's indexPath and make sure that the node that is |
331 // being referenced actually exists in the Cocoa model. | 332 // being referenced actually exists in the Cocoa model. |
332 NSIndexPath* selection = [treeController_ selectionIndexPath]; | 333 NSIndexPath* selection = [treeController_ selectionIndexPath]; |
333 NSUInteger length = [selection length]; | 334 NSUInteger length = [selection length]; |
334 CocoaCookieTreeNode* node = [self cocoaTreeModel]; | 335 CocoaCookieTreeNode* node = [self cocoaTreeModel]; |
335 for (NSUInteger i = 0; i < length; ++i) { | 336 for (NSUInteger i = 0; i < length; ++i) { |
336 NSUInteger childIndex = [selection indexAtPosition:i]; | 337 NSUInteger childIndex = [selection indexAtPosition:i]; |
337 if (childIndex >= [[node children] count]) { | 338 if (childIndex >= [[node children] count]) { |
338 [self setRemoveButtonEnabled:NO]; | 339 [self setRemoveButtonEnabled:NO]; |
339 return; | 340 return; |
340 } | 341 } |
341 node = [[node children] objectAtIndex:childIndex]; | 342 node = [[node children] objectAtIndex:childIndex]; |
342 } | 343 } |
343 | 344 |
344 [self setRemoveButtonEnabled:YES]; | 345 [self setRemoveButtonEnabled:YES]; |
| 346 CocoaCookieTreeNodeType nodeType = [[selectedObjects lastObject] nodeType]; |
| 347 if (nodeType == kCocoaCookieTreeNodeTypeLocalStorage) { |
| 348 [cookieInfo_ setHidden:YES]; |
| 349 [localStorageInfo_ setHidden:NO]; |
| 350 } else { |
| 351 [cookieInfo_ setHidden:NO]; |
| 352 [localStorageInfo_ setHidden:YES]; |
| 353 } |
345 } | 354 } |
346 | 355 |
347 #pragma mark Unit Testing | 356 #pragma mark Unit Testing |
348 | 357 |
349 - (CookiesTreeModelObserverBridge*)modelObserver { | 358 - (CookiesTreeModelObserverBridge*)modelObserver { |
350 return modelObserver_.get(); | 359 return modelObserver_.get(); |
351 } | 360 } |
352 | 361 |
353 - (NSArray*)icons { | 362 - (NSArray*)icons { |
354 return icons_.get(); | 363 return icons_.get(); |
355 } | 364 } |
356 | 365 |
| 366 - (NSView*)cookieInfoView { |
| 367 return cookieInfo_; |
| 368 } |
| 369 |
| 370 - (NSView*)localStorageInfoView { |
| 371 return localStorageInfo_; |
| 372 } |
| 373 |
357 // Re-initializes the |treeModel_|, creates a new observer for it, and re- | 374 // Re-initializes the |treeModel_|, creates a new observer for it, and re- |
358 // builds the |cocoaTreeModel_|. We use this to initialize the controller and | 375 // builds the |cocoaTreeModel_|. We use this to initialize the controller and |
359 // to rebuild after the user clears browsing data. Because the models get | 376 // to rebuild after the user clears browsing data. Because the models get |
360 // clobbered, we rebuild the icon cache for safety (though they do not change). | 377 // clobbered, we rebuild the icon cache for safety (though they do not change). |
361 - (void)loadTreeModelFromProfile { | 378 - (void)loadTreeModelFromProfile { |
362 treeModel_.reset(new CookiesTreeModel(profile_, storageHelper_)); | 379 treeModel_.reset(new CookiesTreeModel(profile_, storageHelper_)); |
363 modelObserver_.reset(new CookiesTreeModelObserverBridge(self)); | 380 modelObserver_.reset(new CookiesTreeModelObserverBridge(self)); |
364 treeModel_->SetObserver(modelObserver_.get()); | 381 treeModel_->SetObserver(modelObserver_.get()); |
365 | 382 |
366 // Convert the model's icons from Skia to Cocoa. | 383 // Convert the model's icons from Skia to Cocoa. |
(...skipping 11 matching lines...) Expand all Loading... |
378 [icons_ addObject:rb.GetNSImageNamed(IDR_BOOKMARK_BAR_FOLDER)]; | 395 [icons_ addObject:rb.GetNSImageNamed(IDR_BOOKMARK_BAR_FOLDER)]; |
379 | 396 |
380 // Create the Cocoa model. | 397 // Create the Cocoa model. |
381 CookieTreeNode* root = static_cast<CookieTreeNode*>(treeModel_->GetRoot()); | 398 CookieTreeNode* root = static_cast<CookieTreeNode*>(treeModel_->GetRoot()); |
382 scoped_nsobject<CocoaCookieTreeNode> model( | 399 scoped_nsobject<CocoaCookieTreeNode> model( |
383 [[CocoaCookieTreeNode alloc] initWithNode:root]); | 400 [[CocoaCookieTreeNode alloc] initWithNode:root]); |
384 [self setCocoaTreeModel:model.get()]; // Takes ownership. | 401 [self setCocoaTreeModel:model.get()]; // Takes ownership. |
385 } | 402 } |
386 | 403 |
387 @end | 404 @end |
OLD | NEW |