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

Side by Side Diff: chrome/browser/ui/cocoa/browser_window_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: Fix ToolbarActionsBar 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/browser_window_controller.h" 5 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <numeric> 8 #include <numeric>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 295
296 // Create a sub-controller for the docked devTools and add its view to the 296 // Create a sub-controller for the docked devTools and add its view to the
297 // hierarchy. 297 // hierarchy.
298 devToolsController_.reset([[DevToolsController alloc] init]); 298 devToolsController_.reset([[DevToolsController alloc] init]);
299 [[devToolsController_ view] setFrame:[[self tabContentArea] bounds]]; 299 [[devToolsController_ view] setFrame:[[self tabContentArea] bounds]];
300 [[self tabContentArea] addSubview:[devToolsController_ view]]; 300 [[self tabContentArea] addSubview:[devToolsController_ view]];
301 301
302 // Create the overlayable contents controller. This provides the switch 302 // Create the overlayable contents controller. This provides the switch
303 // view that TabStripController needs. 303 // view that TabStripController needs.
304 overlayableContentsController_.reset( 304 overlayableContentsController_.reset(
305 [[OverlayableContentsController alloc] initWithBrowser:browser]); 305 [[OverlayableContentsController alloc] init]);
306 [[overlayableContentsController_ view] 306 [[overlayableContentsController_ view]
307 setFrame:[[devToolsController_ view] bounds]]; 307 setFrame:[[devToolsController_ view] bounds]];
308 [[devToolsController_ view] 308 [[devToolsController_ view]
309 addSubview:[overlayableContentsController_ view]]; 309 addSubview:[overlayableContentsController_ view]];
310 310
311 // Create a controller for the tab strip, giving it the model object for 311 // Create a controller for the tab strip, giving it the model object for
312 // this window's Browser and the tab strip view. The controller will handle 312 // this window's Browser and the tab strip view. The controller will handle
313 // registering for the appropriate tab notifications from the back-end and 313 // registering for the appropriate tab notifications from the back-end and
314 // managing the creation of new tabs. 314 // managing the creation of new tabs.
315 [self createTabStripController]; 315 [self createTabStripController];
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 windowShim_.get())); 418 windowShim_.get()));
419 419
420 // We are done initializing now. 420 // We are done initializing now.
421 initializing_ = NO; 421 initializing_ = NO;
422 } 422 }
423 return self; 423 return self;
424 } 424 }
425 425
426 - (void)dealloc { 426 - (void)dealloc {
427 browser_->tab_strip_model()->CloseAllTabs(); 427 browser_->tab_strip_model()->CloseAllTabs();
428 [downloadShelfController_ exiting]; 428 [downloadShelfController_ exiting];
tapted 2015/07/07 04:25:59 I think this is redundant now that downloadShelfCo
jackhou1 2015/07/07 08:33:05 Done.
429 429
430 // Explicitly release |presentationModeController_| here, as it may call back 430 // Explicitly release |presentationModeController_| here, as it may call back
431 // to this BWC in |-dealloc|. We are required to call |-exitPresentationMode| 431 // to this BWC in |-dealloc|. We are required to call |-exitPresentationMode|
432 // before releasing the controller. 432 // before releasing the controller.
433 [presentationModeController_ exitPresentationMode]; 433 [presentationModeController_ exitPresentationMode];
434 presentationModeController_.reset(); 434 presentationModeController_.reset();
435 435
436 // Under certain testing configurations we may not actually own the browser. 436 // Under certain testing configurations we may not actually own the browser.
437 if (ownsBrowser_ == NO) 437 if (ownsBrowser_ == NO)
438 ignore_result(browser_.release()); 438 ignore_result(browser_.release());
439 439
440 [[NSNotificationCenter defaultCenter] removeObserver:self]; 440 [[NSNotificationCenter defaultCenter] removeObserver:self];
441 441
442 // Inform reference counted objects that the Browser will be destroyed. This
443 // ensures they invalidate their weak Browser* to prevent use-after-free.
444 // These may outlive the Browser if they are retained by something else, e.g.
445 // an autorelease NSView or an NSEvent.
tapted 2015/07/07 04:25:59 You could mention here, something like, For examp
jackhou1 2015/07/07 08:33:05 Done.
446 [toolbarController_ browserWillBeDestroyed];
447 [tabStripController_ browserWillBeDestroyed];
448 [findBarCocoaController_ browserWillBeDestroyed];
449 [downloadShelfController_ browserWillBeDestroyed];
450 [bookmarkBarController_ browserWillBeDestroyed];
451 [avatarButtonController_ browserWillBeDestroyed];
452
442 [super dealloc]; 453 [super dealloc];
443 } 454 }
444 455
445 - (gfx::Rect)enforceMinWindowSize:(gfx::Rect)bounds { 456 - (gfx::Rect)enforceMinWindowSize:(gfx::Rect)bounds {
446 gfx::Rect checkedBounds = bounds; 457 gfx::Rect checkedBounds = bounds;
447 458
448 NSSize minSize = [[self window] minSize]; 459 NSSize minSize = [[self window] minSize];
449 if (bounds.width() < minSize.width) 460 if (bounds.width() < minSize.width)
450 checkedBounds.set_width(minSize.width); 461 checkedBounds.set_width(minSize.width);
451 if (bounds.height() < minSize.height) 462 if (bounds.height() < minSize.height)
(...skipping 1793 matching lines...) Expand 10 before | Expand all | Expand 10 after
2245 2256
2246 - (BOOL)supportsBookmarkBar { 2257 - (BOOL)supportsBookmarkBar {
2247 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; 2258 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR];
2248 } 2259 }
2249 2260
2250 - (BOOL)isTabbedWindow { 2261 - (BOOL)isTabbedWindow {
2251 return browser_->is_type_tabbed(); 2262 return browser_->is_type_tabbed();
2252 } 2263 }
2253 2264
2254 @end // @implementation BrowserWindowController(WindowType) 2265 @end // @implementation BrowserWindowController(WindowType)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698