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

Side by Side Diff: chrome/browser/ui/cocoa/toolbar/toolbar_controller.mm

Issue 1221173003: [Mac] Inform reference counted objects that hold a weak Browser* when the Browser is being destroye… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Keep -[BookmarBarController dealloc] instead of changing all the tests. Created 5 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/cocoa/toolbar/toolbar_controller.h" 5 #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/mac/bundle_locations.h" 9 #include "base/mac/bundle_locations.h"
10 #include "base/mac/foundation_util.h" 10 #include "base/mac/foundation_util.h"
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 199
200 } // namespace ToolbarControllerInternal 200 } // namespace ToolbarControllerInternal
201 201
202 @implementation ToolbarController 202 @implementation ToolbarController
203 203
204 @synthesize browser = browser_; 204 @synthesize browser = browser_;
205 205
206 - (id)initWithCommands:(CommandUpdater*)commands 206 - (id)initWithCommands:(CommandUpdater*)commands
207 profile:(Profile*)profile 207 profile:(Profile*)profile
208 browser:(Browser*)browser 208 browser:(Browser*)browser
209 resizeDelegate:(id<ViewResizer>)resizeDelegate
210 nibFileNamed:(NSString*)nibName { 209 nibFileNamed:(NSString*)nibName {
211 DCHECK(commands && profile && [nibName length]); 210 DCHECK(commands && profile && [nibName length]);
212 if ((self = [super initWithNibName:nibName 211 if ((self = [super initWithNibName:nibName
213 bundle:base::mac::FrameworkBundle()])) { 212 bundle:base::mac::FrameworkBundle()])) {
214 commands_ = commands; 213 commands_ = commands;
215 profile_ = profile; 214 profile_ = profile;
216 browser_ = browser; 215 browser_ = browser;
217 resizeDelegate_ = resizeDelegate;
218 hasToolbar_ = YES; 216 hasToolbar_ = YES;
219 hasLocationBar_ = YES; 217 hasLocationBar_ = YES;
220 218
221 // Register for notifications about state changes for the toolbar buttons 219 // Register for notifications about state changes for the toolbar buttons
222 commandObserver_.reset( 220 commandObserver_.reset(
223 new ToolbarControllerInternal::CommandObserverBridge(self)); 221 new ToolbarControllerInternal::CommandObserverBridge(self));
224 222
225 commands->AddCommandObserver(IDC_BACK, commandObserver_.get()); 223 commands->AddCommandObserver(IDC_BACK, commandObserver_.get());
226 commands->AddCommandObserver(IDC_FORWARD, commandObserver_.get()); 224 commands->AddCommandObserver(IDC_FORWARD, commandObserver_.get());
227 commands->AddCommandObserver(IDC_RELOAD, commandObserver_.get()); 225 commands->AddCommandObserver(IDC_RELOAD, commandObserver_.get());
228 commands->AddCommandObserver(IDC_HOME, commandObserver_.get()); 226 commands->AddCommandObserver(IDC_HOME, commandObserver_.get());
229 commands->AddCommandObserver(IDC_BOOKMARK_PAGE, commandObserver_.get()); 227 commands->AddCommandObserver(IDC_BOOKMARK_PAGE, commandObserver_.get());
230 // NOTE: Don't remove the command observers. ToolbarController is 228 // NOTE: Don't remove the command observers. ToolbarController is
231 // autoreleased at about the same time as the CommandUpdater (owned by the 229 // autoreleased at about the same time as the CommandUpdater (owned by the
232 // Browser), so |commands_| may not be valid any more. 230 // Browser), so |commands_| may not be valid any more.
233 } 231 }
234 return self; 232 return self;
235 } 233 }
236 234
237 - (id)initWithCommands:(CommandUpdater*)commands 235 - (id)initWithCommands:(CommandUpdater*)commands
238 profile:(Profile*)profile 236 profile:(Profile*)profile
239 browser:(Browser*)browser 237 browser:(Browser*)browser {
240 resizeDelegate:(id<ViewResizer>)resizeDelegate {
241 if ((self = [self initWithCommands:commands 238 if ((self = [self initWithCommands:commands
242 profile:profile 239 profile:profile
243 browser:browser 240 browser:browser
244 resizeDelegate:resizeDelegate
245 nibFileNamed:@"Toolbar"])) { 241 nibFileNamed:@"Toolbar"])) {
246 } 242 }
247 return self; 243 return self;
248 } 244 }
249 245
250
251 - (void)dealloc {
252 browserActionsContainerDelegate_.reset();
253
254 // Unset ViewIDs of toolbar elements.
255 // ViewIDs of |toolbarView|, |reloadButton_|, |locationBar_| and
256 // |browserActionsContainerView_| are handled by themselves.
257 view_id_util::UnsetID(backButton_);
258 view_id_util::UnsetID(forwardButton_);
259 view_id_util::UnsetID(homeButton_);
260 view_id_util::UnsetID(wrenchButton_);
261
262 // Make sure any code in the base class which assumes [self view] is
263 // the "parent" view continues to work.
264 hasToolbar_ = YES;
265 hasLocationBar_ = YES;
266
267 [[NSNotificationCenter defaultCenter] removeObserver:self];
268
269 if (trackingArea_.get())
270 [[self view] removeTrackingArea:trackingArea_.get()];
271 [super dealloc];
272 }
273
274 // Called after the view is done loading and the outlets have been hooked up. 246 // Called after the view is done loading and the outlets have been hooked up.
275 // Now we can hook up bridges that rely on UI objects such as the location 247 // Now we can hook up bridges that rely on UI objects such as the location
276 // bar and button state. 248 // bar and button state.
277 - (void)awakeFromNib { 249 - (void)awakeFromNib {
278 [[backButton_ cell] setImageID:IDR_BACK 250 [[backButton_ cell] setImageID:IDR_BACK
279 forButtonState:image_button_cell::kDefaultState]; 251 forButtonState:image_button_cell::kDefaultState];
280 [[backButton_ cell] setImageID:IDR_BACK_H 252 [[backButton_ cell] setImageID:IDR_BACK_H
281 forButtonState:image_button_cell::kHoverState]; 253 forButtonState:image_button_cell::kHoverState];
282 [[backButton_ cell] setImageID:IDR_BACK_P 254 [[backButton_ cell] setImageID:IDR_BACK_P
283 forButtonState:image_button_cell::kPressedState]; 255 forButtonState:image_button_cell::kPressedState];
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 // ViewIDs of |toolbarView|, |reloadButton_|, |locationBar_| and 363 // ViewIDs of |toolbarView|, |reloadButton_|, |locationBar_| and
392 // |browserActionsContainerView_| are handled by themselves. 364 // |browserActionsContainerView_| are handled by themselves.
393 view_id_util::SetID(backButton_, VIEW_ID_BACK_BUTTON); 365 view_id_util::SetID(backButton_, VIEW_ID_BACK_BUTTON);
394 view_id_util::SetID(forwardButton_, VIEW_ID_FORWARD_BUTTON); 366 view_id_util::SetID(forwardButton_, VIEW_ID_FORWARD_BUTTON);
395 view_id_util::SetID(homeButton_, VIEW_ID_HOME_BUTTON); 367 view_id_util::SetID(homeButton_, VIEW_ID_HOME_BUTTON);
396 view_id_util::SetID(wrenchButton_, VIEW_ID_APP_MENU); 368 view_id_util::SetID(wrenchButton_, VIEW_ID_APP_MENU);
397 369
398 [self addAccessibilityDescriptions]; 370 [self addAccessibilityDescriptions];
399 } 371 }
400 372
373 - (void)browserWillBeDestroyed {
erikchen 2015/07/08 01:18:03 This method makes the assumption that this is guar
jackhou1 2015/07/08 07:02:12 Yeah good point. For most of these it's fine to ju
374 // This method indicates imminent destruction. Destroy owned objects that hold
375 // a weak Browser*, or pass this call onto reference counted objects.
376 locationBarView_.reset();
377 [backMenuController_ browserWillBeDestroyed];
378 [forwardMenuController_ browserWillBeDestroyed];
379 [browserActionsController_ browserWillBeDestroyed];
380 [wrenchMenuController_ browserWillBeDestroyed];
381 browserActionsContainerDelegate_.reset();
382
383 // Unset ViewIDs of toolbar elements.
384 // ViewIDs of |toolbarView|, |reloadButton_|, |locationBar_| and
385 // |browserActionsContainerView_| are handled by themselves.
386 view_id_util::UnsetID(backButton_);
387 view_id_util::UnsetID(forwardButton_);
388 view_id_util::UnsetID(homeButton_);
389 view_id_util::UnsetID(wrenchButton_);
390
391 // Make sure any code in the base class which assumes [self view] is
392 // the "parent" view continues to work.
393 hasToolbar_ = YES;
394 hasLocationBar_ = YES;
395
396 [[NSNotificationCenter defaultCenter] removeObserver:self];
397
398 if (trackingArea_.get())
399 [[self view] removeTrackingArea:trackingArea_.get()];
400
401 browser_ = nullptr;
402 }
403
401 - (void)addAccessibilityDescriptions { 404 - (void)addAccessibilityDescriptions {
402 // Set accessibility descriptions. http://openradar.appspot.com/7496255 405 // Set accessibility descriptions. http://openradar.appspot.com/7496255
403 NSString* description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_BACK); 406 NSString* description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_BACK);
404 [[backButton_ cell] 407 [[backButton_ cell]
405 accessibilitySetOverrideValue:description 408 accessibilitySetOverrideValue:description
406 forAttribute:NSAccessibilityDescriptionAttribute]; 409 forAttribute:NSAccessibilityDescriptionAttribute];
407 description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_FORWARD); 410 description = l10n_util::GetNSStringWithFixup(IDS_ACCNAME_FORWARD);
408 [[forwardButton_ cell] 411 [[forwardButton_ cell]
409 accessibilitySetOverrideValue:description 412 accessibilitySetOverrideValue:description
410 forAttribute:NSAccessibilityDescriptionAttribute]; 413 forAttribute:NSAccessibilityDescriptionAttribute];
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 - (void)hideDropURLsIndicatorInView:(NSView*)view { 915 - (void)hideDropURLsIndicatorInView:(NSView*)view {
913 // Do nothing. 916 // Do nothing.
914 } 917 }
915 918
916 // (URLDropTargetController protocol) 919 // (URLDropTargetController protocol)
917 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info { 920 - (BOOL)isUnsupportedDropData:(id<NSDraggingInfo>)info {
918 return drag_util::IsUnsupportedDropData(profile_, info); 921 return drag_util::IsUnsupportedDropData(profile_, info);
919 } 922 }
920 923
921 @end 924 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698