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

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: Add HasWeakBrowserPointer protocol. Allow -dealloc without preceding -browserWillBeDestroyed. 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];
316 316
317 // Create a controller for the toolbar, giving it the toolbar model object 317 // Create a controller for the toolbar, giving it the toolbar model object
318 // and the toolbar view from the nib. The controller will handle 318 // and the toolbar view from the nib. The controller will handle
319 // registering for the appropriate command state changes from the back-end. 319 // registering for the appropriate command state changes from the back-end.
320 // Adds the toolbar to the content area. 320 // Adds the toolbar to the content area.
321 toolbarController_.reset([[ToolbarController alloc] 321 toolbarController_.reset([[ToolbarController alloc]
322 initWithCommands:browser->command_controller()->command_updater() 322 initWithCommands:browser->command_controller()->command_updater()
323 profile:browser->profile() 323 profile:browser->profile()
324 browser:browser 324 browser:browser]);
325 resizeDelegate:self]);
326 [toolbarController_ setHasToolbar:[self hasToolbar] 325 [toolbarController_ setHasToolbar:[self hasToolbar]
327 hasLocationBar:[self hasLocationBar]]; 326 hasLocationBar:[self hasLocationBar]];
328 327
329 // Create a sub-controller for the bookmark bar. 328 // Create a sub-controller for the bookmark bar.
330 bookmarkBarController_.reset( 329 bookmarkBarController_.reset(
331 [[BookmarkBarController alloc] 330 [[BookmarkBarController alloc]
332 initWithBrowser:browser_.get() 331 initWithBrowser:browser_.get()
333 initialWidth:NSWidth([[[self window] contentView] frame]) 332 initialWidth:NSWidth([[[self window] contentView] frame])
334 delegate:self 333 delegate:self
335 resizeDelegate:self]); 334 resizeDelegate:self]);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 windowShim_.get())); 417 windowShim_.get()));
419 418
420 // We are done initializing now. 419 // We are done initializing now.
421 initializing_ = NO; 420 initializing_ = NO;
422 } 421 }
423 return self; 422 return self;
424 } 423 }
425 424
426 - (void)dealloc { 425 - (void)dealloc {
427 browser_->tab_strip_model()->CloseAllTabs(); 426 browser_->tab_strip_model()->CloseAllTabs();
428 [downloadShelfController_ exiting];
429 427
430 // Explicitly release |presentationModeController_| here, as it may call back 428 // Explicitly release |presentationModeController_| here, as it may call back
431 // to this BWC in |-dealloc|. We are required to call |-exitPresentationMode| 429 // to this BWC in |-dealloc|. We are required to call |-exitPresentationMode|
432 // before releasing the controller. 430 // before releasing the controller.
433 [presentationModeController_ exitPresentationMode]; 431 [presentationModeController_ exitPresentationMode];
434 presentationModeController_.reset(); 432 presentationModeController_.reset();
435 433
436 // Under certain testing configurations we may not actually own the browser. 434 // Under certain testing configurations we may not actually own the browser.
437 if (ownsBrowser_ == NO) 435 if (ownsBrowser_ == NO)
438 ignore_result(browser_.release()); 436 ignore_result(browser_.release());
439 437
440 [[NSNotificationCenter defaultCenter] removeObserver:self]; 438 [[NSNotificationCenter defaultCenter] removeObserver:self];
441 439
440 // Inform reference counted objects that the Browser will be destroyed. This
441 // ensures they invalidate their weak Browser* to prevent use-after-free.
442 // These may outlive the Browser if they are retained by something else. For
443 // example, since 10.10, the Nib loader internally creates an NSDictionary
444 // that retains NSViewControllers and is autoreleased, so there is no way to
445 // guarantee that the [super dealloc] call below will also call dealloc on the
446 // controllers.
447 [toolbarController_ browserWillBeDestroyed];
448 [tabStripController_ browserWillBeDestroyed];
449 [findBarCocoaController_ browserWillBeDestroyed];
450 [downloadShelfController_ browserWillBeDestroyed];
451 [bookmarkBarController_ browserWillBeDestroyed];
452 [avatarButtonController_ browserWillBeDestroyed];
453
442 [super dealloc]; 454 [super dealloc];
443 } 455 }
444 456
445 - (gfx::Rect)enforceMinWindowSize:(gfx::Rect)bounds { 457 - (gfx::Rect)enforceMinWindowSize:(gfx::Rect)bounds {
446 gfx::Rect checkedBounds = bounds; 458 gfx::Rect checkedBounds = bounds;
447 459
448 NSSize minSize = [[self window] minSize]; 460 NSSize minSize = [[self window] minSize];
449 if (bounds.width() < minSize.width) 461 if (bounds.width() < minSize.width)
450 checkedBounds.set_width(minSize.width); 462 checkedBounds.set_width(minSize.width);
451 if (bounds.height() < minSize.height) 463 if (bounds.height() < minSize.height)
(...skipping 1793 matching lines...) Expand 10 before | Expand all | Expand 10 after
2245 2257
2246 - (BOOL)supportsBookmarkBar { 2258 - (BOOL)supportsBookmarkBar {
2247 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; 2259 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR];
2248 } 2260 }
2249 2261
2250 - (BOOL)isTabbedWindow { 2262 - (BOOL)isTabbedWindow {
2251 return browser_->is_type_tabbed(); 2263 return browser_->is_type_tabbed();
2252 } 2264 }
2253 2265
2254 @end // @implementation BrowserWindowController(WindowType) 2266 @end // @implementation BrowserWindowController(WindowType)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698