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

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

Issue 11016023: Quickly close tabs/window with long-running unload handlers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Keep original TabsNeedBeforeUnloadFired implementation. Created 8 years, 1 month 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 | Annotate | Revision Log
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 #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 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 // The Browser object is in control of whether or not we're allowed to close. It 543 // The Browser object is in control of whether or not we're allowed to close. It
544 // may defer closing due to several states, such as onUnload handlers needing to 544 // may defer closing due to several states, such as onUnload handlers needing to
545 // be fired. If closing is deferred, the Browser will handle the processing 545 // be fired. If closing is deferred, the Browser will handle the processing
546 // required to get us to the closing state and (by watching for all the tabs 546 // required to get us to the closing state and (by watching for all the tabs
547 // going away) will again call to close the window when it's finally ready. 547 // going away) will again call to close the window when it's finally ready.
548 - (BOOL)windowShouldClose:(id)sender { 548 - (BOOL)windowShouldClose:(id)sender {
549 // Disable updates while closing all tabs to avoid flickering. 549 // Disable updates while closing all tabs to avoid flickering.
550 gfx::ScopedNSDisableScreenUpdates disabler; 550 gfx::ScopedNSDisableScreenUpdates disabler;
551 // Give beforeunload handlers the chance to cancel the close before we hide 551 // Give beforeunload handlers the chance to cancel the close before we hide
552 // the window below. 552 // the window below.
553 if (!browser_->ShouldCloseWindow()) 553 if (!browser_->ShouldCloseWindow()) {
554 if (browser_->tab_strip_model()->empty()) {
555 // saveWindowPositionIfNeeded: only works if we are the last active
556 // window, but orderOut: ends up activating another window, so we
557 // have to save the window position before we call orderOut:.
558 [self saveWindowPositionIfNeeded];
559
560 // The browser needs to finish running unload handlers.
561 // Hide the window (so it appears to have closed immediately), and
562 // the browser will call us back again when it is ready to close.
563 [[self window] orderOut:self];
564 }
554 return NO; 565 return NO;
566 }
555 567
556 // saveWindowPositionIfNeeded: only works if we are the last active 568 // saveWindowPositionIfNeeded: only works if we are the last active
557 // window, but orderOut: ends up activating another window, so we 569 // window, but orderOut: ends up activating another window, so we
558 // have to save the window position before we call orderOut:. 570 // have to save the window position before we call orderOut:.
559 [self saveWindowPositionIfNeeded]; 571 [self saveWindowPositionIfNeeded];
560 572
561 if (!browser_->tab_strip_model()->empty()) {
562 // Tab strip isn't empty. Hide the frame (so it appears to have closed
563 // immediately) and close all the tabs, allowing the renderers to shut
564 // down. When the tab strip is empty we'll be called back again.
565 [[self window] orderOut:self];
566 browser_->OnWindowClosing();
567 return NO;
568 }
569
570 // the tab strip is empty, it's ok to close the window 573 // the tab strip is empty, it's ok to close the window
571 return YES; 574 return YES;
572 } 575 }
573 576
574 // Called right after our window became the main window. 577 // Called right after our window became the main window.
575 - (void)windowDidBecomeMain:(NSNotification*)notification { 578 - (void)windowDidBecomeMain:(NSNotification*)notification {
576 BrowserList::SetLastActive(browser_.get()); 579 BrowserList::SetLastActive(browser_.get());
577 [self saveWindowPositionIfNeeded]; 580 [self saveWindowPositionIfNeeded];
578 581
579 // TODO(dmaclach): Instead of redrawing the whole window, views that care 582 // TODO(dmaclach): Instead of redrawing the whole window, views that care
(...skipping 1594 matching lines...) Expand 10 before | Expand all | Expand 10 after
2174 2177
2175 - (BOOL)supportsBookmarkBar { 2178 - (BOOL)supportsBookmarkBar {
2176 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR]; 2179 return [self supportsWindowFeature:Browser::FEATURE_BOOKMARKBAR];
2177 } 2180 }
2178 2181
2179 - (BOOL)isTabbedWindow { 2182 - (BOOL)isTabbedWindow {
2180 return browser_->is_type_tabbed(); 2183 return browser_->is_type_tabbed();
2181 } 2184 }
2182 2185
2183 @end // @implementation BrowserWindowController(WindowType) 2186 @end // @implementation BrowserWindowController(WindowType)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698