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

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

Issue 2042123005: Revert of 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: 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 alert_state_(TabAlertState::NONE), 139
140 window_closed_(false) {
141 gfx::Rect bounds; 140 gfx::Rect bounds;
142 chrome::GetSavedWindowBoundsAndShowState(browser_, 141 chrome::GetSavedWindowBoundsAndShowState(browser_,
143 &bounds, 142 &bounds,
144 &initial_show_state_); 143 &initial_show_state_);
145 144
146 browser_->search_model()->AddObserver(this); 145 browser_->search_model()->AddObserver(this);
147 } 146 }
148 147
149 BrowserWindowCocoa::~BrowserWindowCocoa() { 148 BrowserWindowCocoa::~BrowserWindowCocoa() {
150 browser_->search_model()->RemoveObserver(this); 149 browser_->search_model()->RemoveObserver(this);
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 // constructor or the FindBarCocoaController init, but that makes 754 // constructor or the FindBarCocoaController init, but that makes
756 // unit testing difficult, since we would also require a 755 // unit testing difficult, since we would also require a
757 // BrowserWindow object. 756 // BrowserWindow object.
758 FindBarBridge* bridge = new FindBarBridge(browser_); 757 FindBarBridge* bridge = new FindBarBridge(browser_);
759 AddFindBar(bridge->find_bar_cocoa_controller()); 758 AddFindBar(bridge->find_bar_cocoa_controller());
760 return bridge; 759 return bridge;
761 } 760 }
762 761
763 web_modal::WebContentsModalDialogHost* 762 web_modal::WebContentsModalDialogHost*
764 BrowserWindowCocoa::GetWebContentsModalDialogHost() { 763 BrowserWindowCocoa::GetWebContentsModalDialogHost() {
765 DCHECK(window()); 764 DCHECK([controller_ window]);
766 ConstrainedWindowSheetController* sheet_controller = 765 ConstrainedWindowSheetController* sheet_controller =
767 [ConstrainedWindowSheetController controllerForParentWindow:window()]; 766 [ConstrainedWindowSheetController
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;
801 return [controller_ window]; 795 return [controller_ window];
802 } 796 }
803 797
804 void BrowserWindowCocoa::ShowAvatarBubbleFromAvatarButton( 798 void BrowserWindowCocoa::ShowAvatarBubbleFromAvatarButton(
805 AvatarBubbleMode mode, 799 AvatarBubbleMode mode,
806 const signin::ManageAccountsParams& manage_accounts_params, 800 const signin::ManageAccountsParams& manage_accounts_params,
807 signin_metrics::AccessPoint access_point) { 801 signin_metrics::AccessPoint access_point) {
808 profiles::BubbleViewMode bubble_view_mode; 802 profiles::BubbleViewMode bubble_view_mode;
809 profiles::TutorialMode tutorial_mode; 803 profiles::TutorialMode tutorial_mode;
810 profiles::BubbleViewModeFromAvatarBubbleMode(mode, &bubble_view_mode, 804 profiles::BubbleViewModeFromAvatarBubbleMode(mode, &bubble_view_mode,
(...skipping 29 matching lines...) Expand all
840 ExclusiveAccessContext* BrowserWindowCocoa::GetExclusiveAccessContext() { 834 ExclusiveAccessContext* BrowserWindowCocoa::GetExclusiveAccessContext() {
841 return [controller_ exclusiveAccessController]; 835 return [controller_ exclusiveAccessController];
842 } 836 }
843 837
844 void BrowserWindowCocoa::ShowImeWarningBubble( 838 void BrowserWindowCocoa::ShowImeWarningBubble(
845 const extensions::Extension* extension, 839 const extensions::Extension* extension,
846 const base::Callback<void(ImeWarningBubblePermissionStatus status)>& 840 const base::Callback<void(ImeWarningBubblePermissionStatus status)>&
847 callback) { 841 callback) {
848 NOTREACHED() << "The IME warning bubble is unsupported on this platform."; 842 NOTREACHED() << "The IME warning bubble is unsupported on this platform.";
849 } 843 }
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