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

Side by Side Diff: chrome/browser/ui/cocoa/browser_window_cocoa.mm

Issue 2041213002: Address a crash under -[NSWindow close] via a WeakPtr PostTask from Browser::TabStripEmpty() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: windowWillClose Created 4 years, 6 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 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h" 5 #include "chrome/browser/ui/cocoa/browser_window_cocoa.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #import "base/mac/sdk_forward_declarations.h" 10 #import "base/mac/sdk_forward_declarations.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 [self validateText:[[notification object] stringValue]]; 125 [self validateText:[[notification object] stringValue]];
126 } 126 }
127 127
128 - (void)validateText:(NSString*)text { 128 - (void)validateText:(NSString*)text {
129 [control_ setEnabled:TrimText(text).empty() ? NO : YES]; 129 [control_ setEnabled:TrimText(text).empty() ? NO : YES];
130 } 130 }
131 @end 131 @end
132 132
133 BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser, 133 BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser,
134 BrowserWindowController* controller) 134 BrowserWindowController* controller)
135 : browser_(browser), 135 : browser_(browser),
136 controller_(controller), 136 controller_(controller),
137 initial_show_state_(ui::SHOW_STATE_DEFAULT), 137 initial_show_state_(ui::SHOW_STATE_DEFAULT),
138 attention_request_id_(0) { 138 attention_request_id_(0),
139 139 alert_state_(TabAlertState::NONE),
140 window_closed_(false) {
140 gfx::Rect bounds; 141 gfx::Rect bounds;
141 chrome::GetSavedWindowBoundsAndShowState(browser_, 142 chrome::GetSavedWindowBoundsAndShowState(browser_,
142 &bounds, 143 &bounds,
143 &initial_show_state_); 144 &initial_show_state_);
144 145
145 browser_->search_model()->AddObserver(this); 146 browser_->search_model()->AddObserver(this);
146 } 147 }
147 148
148 BrowserWindowCocoa::~BrowserWindowCocoa() { 149 BrowserWindowCocoa::~BrowserWindowCocoa() {
149 browser_->search_model()->RemoveObserver(this); 150 browser_->search_model()->RemoveObserver(this);
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 // constructor or the FindBarCocoaController init, but that makes 755 // constructor or the FindBarCocoaController init, but that makes
755 // unit testing difficult, since we would also require a 756 // unit testing difficult, since we would also require a
756 // BrowserWindow object. 757 // BrowserWindow object.
757 FindBarBridge* bridge = new FindBarBridge(browser_); 758 FindBarBridge* bridge = new FindBarBridge(browser_);
758 AddFindBar(bridge->find_bar_cocoa_controller()); 759 AddFindBar(bridge->find_bar_cocoa_controller());
759 return bridge; 760 return bridge;
760 } 761 }
761 762
762 web_modal::WebContentsModalDialogHost* 763 web_modal::WebContentsModalDialogHost*
763 BrowserWindowCocoa::GetWebContentsModalDialogHost() { 764 BrowserWindowCocoa::GetWebContentsModalDialogHost() {
764 DCHECK([controller_ window]); 765 DCHECK(window());
765 ConstrainedWindowSheetController* sheet_controller = 766 ConstrainedWindowSheetController* sheet_controller =
766 [ConstrainedWindowSheetController 767 [ConstrainedWindowSheetController controllerForParentWindow:window()];
767 controllerForParentWindow:[controller_ window]];
768 DCHECK(sheet_controller); 768 DCHECK(sheet_controller);
769 return [sheet_controller dialogHost]; 769 return [sheet_controller dialogHost];
770 } 770 }
771 771
772 extensions::ActiveTabPermissionGranter* 772 extensions::ActiveTabPermissionGranter*
773 BrowserWindowCocoa::GetActiveTabPermissionGranter() { 773 BrowserWindowCocoa::GetActiveTabPermissionGranter() {
774 WebContents* web_contents = 774 WebContents* web_contents =
775 browser_->tab_strip_model()->GetActiveWebContents(); 775 browser_->tab_strip_model()->GetActiveWebContents();
776 if (!web_contents) 776 if (!web_contents)
777 return NULL; 777 return NULL;
778 extensions::TabHelper* tab_helper = 778 extensions::TabHelper* tab_helper =
779 extensions::TabHelper::FromWebContents(web_contents); 779 extensions::TabHelper::FromWebContents(web_contents);
780 return tab_helper ? tab_helper->active_tab_permission_granter() : NULL; 780 return tab_helper ? tab_helper->active_tab_permission_granter() : NULL;
781 } 781 }
782 782
783 void BrowserWindowCocoa::ModelChanged(const SearchModel::State& old_state, 783 void BrowserWindowCocoa::ModelChanged(const SearchModel::State& old_state,
784 const SearchModel::State& new_state) { 784 const SearchModel::State& new_state) {
785 } 785 }
786 786
787 void BrowserWindowCocoa::DestroyBrowser() { 787 void BrowserWindowCocoa::DestroyBrowser() {
788 [controller_ destroyBrowser]; 788 [controller_ destroyBrowser];
789 789
790 // at this point the controller is dead (autoreleased), so 790 // at this point the controller is dead (autoreleased), so
791 // make sure we don't try to reference it any more. 791 // make sure we don't try to reference it any more.
792 } 792 }
793 793
794 NSWindow* BrowserWindowCocoa::window() const { 794 NSWindow* BrowserWindowCocoa::window() const {
795 // AppKit doesn't seem to guarantee that [controller_ window] returns nil once
796 // the NSWindow is destroyed. Since |this| is deleted only once
797 // -[NSWindowController dealloc] completes, there's a possibility of
798 // a WeakPtr to Browser* requesting the NSWindow, which may be a zombie.
799 if (window_closed_)
800 return nil;
795 return [controller_ window]; 801 return [controller_ window];
796 } 802 }
797 803
798 void BrowserWindowCocoa::ShowAvatarBubbleFromAvatarButton( 804 void BrowserWindowCocoa::ShowAvatarBubbleFromAvatarButton(
799 AvatarBubbleMode mode, 805 AvatarBubbleMode mode,
800 const signin::ManageAccountsParams& manage_accounts_params, 806 const signin::ManageAccountsParams& manage_accounts_params,
801 signin_metrics::AccessPoint access_point) { 807 signin_metrics::AccessPoint access_point) {
802 profiles::BubbleViewMode bubble_view_mode; 808 profiles::BubbleViewMode bubble_view_mode;
803 profiles::TutorialMode tutorial_mode; 809 profiles::TutorialMode tutorial_mode;
804 profiles::BubbleViewModeFromAvatarBubbleMode(mode, &bubble_view_mode, 810 profiles::BubbleViewModeFromAvatarBubbleMode(mode, &bubble_view_mode,
(...skipping 29 matching lines...) Expand all
834 ExclusiveAccessContext* BrowserWindowCocoa::GetExclusiveAccessContext() { 840 ExclusiveAccessContext* BrowserWindowCocoa::GetExclusiveAccessContext() {
835 return [controller_ exclusiveAccessController]; 841 return [controller_ exclusiveAccessController];
836 } 842 }
837 843
838 void BrowserWindowCocoa::ShowImeWarningBubble( 844 void BrowserWindowCocoa::ShowImeWarningBubble(
839 const extensions::Extension* extension, 845 const extensions::Extension* extension,
840 const base::Callback<void(ImeWarningBubblePermissionStatus status)>& 846 const base::Callback<void(ImeWarningBubblePermissionStatus status)>&
841 callback) { 847 callback) {
842 NOTREACHED() << "The IME warning bubble is unsupported on this platform."; 848 NOTREACHED() << "The IME warning bubble is unsupported on this platform.";
843 } 849 }
850
851 void BrowserWindowCocoa::OnWindowWillClose() {
852 window_closed_ = true;
853 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/browser_window_cocoa.h ('k') | chrome/browser/ui/cocoa/browser_window_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698