Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 | |
|
erikchen
2015/07/08 01:18:03
This solution seems fragile. If someone adds a new
jackhou1
2015/07/08 07:02:12
I agree it's not obvious which objects implement -
| |
| 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 // NOTE: |findBarCocoaController_| is additionally retained by FindBarBridge, | |
| 450 // but that is ultimately owned by Browser::find_bar_controller_ and will be | |
| 451 // released soon. | |
| 452 [findBarCocoaController_ browserWillBeDestroyed]; | |
| 453 [downloadShelfController_ browserWillBeDestroyed]; | |
| 454 [bookmarkBarController_ browserWillBeDestroyed]; | |
| 455 [avatarButtonController_ browserWillBeDestroyed]; | |
| 456 | |
| 442 [super dealloc]; | 457 [super dealloc]; |
| 443 } | 458 } |
| 444 | 459 |
| 445 - (gfx::Rect)enforceMinWindowSize:(gfx::Rect)bounds { | 460 - (gfx::Rect)enforceMinWindowSize:(gfx::Rect)bounds { |
| 446 gfx::Rect checkedBounds = bounds; | 461 gfx::Rect checkedBounds = bounds; |
| 447 | 462 |
| 448 NSSize minSize = [[self window] minSize]; | 463 NSSize minSize = [[self window] minSize]; |
| 449 if (bounds.width() < minSize.width) | 464 if (bounds.width() < minSize.width) |
| 450 checkedBounds.set_width(minSize.width); | 465 checkedBounds.set_width(minSize.width); |
| 451 if (bounds.height() < minSize.height) | 466 if (bounds.height() < minSize.height) |
| (...skipping 1793 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2245 | 2260 |
| 2246 - (BOOL)supportsBookmarkBar { | 2261 - (BOOL)supportsBookmarkBar { |
| 2247 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; | 2262 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; |
| 2248 } | 2263 } |
| 2249 | 2264 |
| 2250 - (BOOL)isTabbedWindow { | 2265 - (BOOL)isTabbedWindow { |
| 2251 return browser_->is_type_tabbed(); | 2266 return browser_->is_type_tabbed(); |
| 2252 } | 2267 } |
| 2253 | 2268 |
| 2254 @end // @implementation BrowserWindowController(WindowType) | 2269 @end // @implementation BrowserWindowController(WindowType) |
| OLD | NEW |