| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 return nil; // We couldn't find the node. | 124 return nil; // We couldn't find the node. |
| 125 } | 125 } |
| 126 | 126 |
| 127 #pragma mark Window Controller | 127 #pragma mark Window Controller |
| 128 | 128 |
| 129 @implementation CookiesWindowController | 129 @implementation CookiesWindowController |
| 130 | 130 |
| 131 @synthesize removeButtonEnabled = removeButtonEnabled_; | 131 @synthesize removeButtonEnabled = removeButtonEnabled_; |
| 132 @synthesize treeController = treeController_; | 132 @synthesize treeController = treeController_; |
| 133 | 133 |
| 134 - (id)initWithProfile:(Profile*)profile { | 134 - (id)initWithProfile:(Profile*)profile |
| 135 storageHelper:(BrowsingDataLocalStorageHelper*)storageHelper { |
| 135 DCHECK(profile); | 136 DCHECK(profile); |
| 136 NSString* nibpath = [mac_util::MainAppBundle() pathForResource:@"Cookies" | 137 NSString* nibpath = [mac_util::MainAppBundle() pathForResource:@"Cookies" |
| 137 ofType:@"nib"]; | 138 ofType:@"nib"]; |
| 138 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { | 139 if ((self = [super initWithWindowNibPath:nibpath owner:self])) { |
| 139 profile_ = profile; | 140 profile_ = profile; |
| 141 storageHelper_ = storageHelper; |
| 140 | 142 |
| 141 [self loadTreeModelFromProfile]; | 143 [self loadTreeModelFromProfile]; |
| 142 | 144 |
| 143 // Register for Clear Browsing Data controller so we update appropriately. | 145 // Register for Clear Browsing Data controller so we update appropriately. |
| 144 ClearBrowsingDataController* clearingController = | 146 ClearBrowsingDataController* clearingController = |
| 145 [ClearBrowsingDataController controllerForProfile:profile_]; | 147 [ClearBrowsingDataController controllerForProfile:profile_]; |
| 146 if (clearingController) { | 148 if (clearingController) { |
| 147 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | 149 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
| 148 [center addObserver:self | 150 [center addObserver:self |
| 149 selector:@selector(clearBrowsingDataNotification:) | 151 selector:@selector(clearBrowsingDataNotification:) |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 | 300 |
| 299 - (NSArray*)icons { | 301 - (NSArray*)icons { |
| 300 return icons_.get(); | 302 return icons_.get(); |
| 301 } | 303 } |
| 302 | 304 |
| 303 // Re-initializes the |treeModel_|, creates a new observer for it, and re- | 305 // Re-initializes the |treeModel_|, creates a new observer for it, and re- |
| 304 // builds the |cocoaTreeModel_|. We use this to initialize the controller and | 306 // builds the |cocoaTreeModel_|. We use this to initialize the controller and |
| 305 // to rebuild after the user clears browsing data. Because the models get | 307 // to rebuild after the user clears browsing data. Because the models get |
| 306 // clobbered, we rebuild the icon cache for safety (though they do not change). | 308 // clobbered, we rebuild the icon cache for safety (though they do not change). |
| 307 - (void)loadTreeModelFromProfile { | 309 - (void)loadTreeModelFromProfile { |
| 308 treeModel_.reset(new CookiesTreeModel(profile_)); | 310 treeModel_.reset(new CookiesTreeModel(profile_, storageHelper_)); |
| 309 modelObserver_.reset(new CookiesTreeModelObserverBridge(self)); | 311 modelObserver_.reset(new CookiesTreeModelObserverBridge(self)); |
| 310 treeModel_->SetObserver(modelObserver_.get()); | 312 treeModel_->SetObserver(modelObserver_.get()); |
| 311 | 313 |
| 312 // Convert the model's icons from Skia to Cocoa. | 314 // Convert the model's icons from Skia to Cocoa. |
| 313 std::vector<SkBitmap> skiaIcons; | 315 std::vector<SkBitmap> skiaIcons; |
| 314 treeModel_->GetIcons(&skiaIcons); | 316 treeModel_->GetIcons(&skiaIcons); |
| 315 icons_.reset([[NSMutableArray alloc] init]); | 317 icons_.reset([[NSMutableArray alloc] init]); |
| 316 for (std::vector<SkBitmap>::iterator it = skiaIcons.begin(); | 318 for (std::vector<SkBitmap>::iterator it = skiaIcons.begin(); |
| 317 it != skiaIcons.end(); ++it) { | 319 it != skiaIcons.end(); ++it) { |
| 318 [icons_ addObject:gfx::SkBitmapToNSImage(*it)]; | 320 [icons_ addObject:gfx::SkBitmapToNSImage(*it)]; |
| 319 } | 321 } |
| 320 | 322 |
| 321 // Default icon will be the last item in the array. | 323 // Default icon will be the last item in the array. |
| 322 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 324 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 323 // TODO(rsesek): Rename this resource now that it's in multiple places. | 325 // TODO(rsesek): Rename this resource now that it's in multiple places. |
| 324 [icons_ addObject:rb.GetNSImageNamed(IDR_BOOKMARK_BAR_FOLDER)]; | 326 [icons_ addObject:rb.GetNSImageNamed(IDR_BOOKMARK_BAR_FOLDER)]; |
| 325 | 327 |
| 326 // Create the Cocoa model. | 328 // Create the Cocoa model. |
| 327 CookieTreeNode* root = static_cast<CookieTreeNode*>(treeModel_->GetRoot()); | 329 CookieTreeNode* root = static_cast<CookieTreeNode*>(treeModel_->GetRoot()); |
| 328 scoped_nsobject<CocoaCookieTreeNode> model( | 330 scoped_nsobject<CocoaCookieTreeNode> model( |
| 329 [[CocoaCookieTreeNode alloc] initWithNode:root]); | 331 [[CocoaCookieTreeNode alloc] initWithNode:root]); |
| 330 [self setCocoaTreeModel:model.get()]; // Takes ownership. | 332 [self setCocoaTreeModel:model.get()]; // Takes ownership. |
| 331 } | 333 } |
| 332 | 334 |
| 333 @end | 335 @end |
| OLD | NEW |