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

Unified Diff: chrome/browser/app_controller_mac.mm

Issue 159780: Add support for constrained windows on os x, based on Avi's GTMWindowSheetController. (Closed)
Patch Set: Merge with ToT Created 11 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/app_controller_mac.mm
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm
index d7f4a9797645bf6d345f052254272b400bed8b0e..40ccaad5067b473b791cbcacd3644f3a093ba177 100644
--- a/chrome/browser/app_controller_mac.mm
+++ b/chrome/browser/app_controller_mac.mm
@@ -18,6 +18,8 @@
#include "chrome/browser/browser_window.h"
#import "chrome/browser/cocoa/about_window_controller.h"
#import "chrome/browser/cocoa/bookmark_menu_bridge.h"
+#import "chrome/browser/cocoa/browser_window_cocoa.h"
+#import "chrome/browser/cocoa/browser_window_controller.h"
#import "chrome/browser/cocoa/history_menu_bridge.h"
#import "chrome/browser/cocoa/clear_browsing_data_controller.h"
#import "chrome/browser/cocoa/encoding_menu_controller_delegate_mac.h"
@@ -27,6 +29,7 @@
#import "chrome/browser/cocoa/ui_localizer.h"
#include "chrome/browser/command_updater.h"
#include "chrome/browser/download/download_manager.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/sessions/tab_restore_service.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
@@ -108,6 +111,45 @@
[self initMenuState];
}
+// Checks if there are any tabs with sheets open, and if so, raises one of
+// the tabs with a sheet and returns NO.
+- (BOOL)shouldQuitWithOpenPerTabSheets {
+ BrowserList::const_iterator it = BrowserList::begin();
+ for (; it != BrowserList::end(); ++it) {
+ Browser* browser = *it;
+ BrowserWindowCocoa* window =
+ static_cast<BrowserWindowCocoa*>(browser->window());
+
+ // Could do this more nicely with a method e.g. on BWC. If I decide for
+ // keeping it this way, at least add a DCHECK().
+ BrowserWindowController* controller =
+ (BrowserWindowController*)[window->GetNativeHandle() windowController];
+
+ if (![controller shouldCloseWithOpenPerTabSheets])
+ return NO;
+ }
+
+ return YES;
+}
+
+// We do not use the normal application teardown process -- this function is
+// not called by the system but by us in |quit:|. |NSTerminateLater| is not a
+// return value that is supported by |quit:|.
+- (NSApplicationTerminateReply)applicationShouldTerminate:
+ (NSApplication *)sender {
+ // Do not quit if any per-tab sheets are open, as required by
+ // GTMWindowSheetController.
+ if (![self shouldQuitWithOpenPerTabSheets])
+ return NSTerminateCancel;
+
+ // Check for in-progress downloads, and prompt the user if they really want to
+ // quit (and thus cancel the downloads).
+ if (![self shouldQuitWithInProgressDownloads])
+ return NSTerminateCancel;
+
+ return NSTerminateNow;
+}
+
// Called when the app is shutting down. Clean-up as appropriate.
- (void)applicationWillTerminate:(NSNotification *)aNotification {
DCHECK(!BrowserList::HasBrowserWithProfile([self defaultProfile]));
@@ -338,6 +380,9 @@
// the app and leave things on the stack in an unfinalized state. We need to
// post a quit message to our run loop so the stack can gracefully unwind.
- (IBAction)quit:(id)sender {
+ if ([self applicationShouldTerminate:NSApp] == NSTerminateCancel)
+ return;
+
// TODO(pinkerton):
// since we have to roll it ourselves, ask the delegate (ourselves, really)
// if we should terminate. For example, we might not want to if the user
@@ -346,11 +391,6 @@
// handle it. If it says to continue, post the quit message, otherwise
// go back to normal.
- // Check for in-progress downloads, and prompt the user if they really want to
- // quit (and thus cancel the downloads).
- if (![self shouldQuitWithInProgressDownloads])
- return;
-
NSAppleEventManager* em = [NSAppleEventManager sharedAppleEventManager];
[em removeEventHandlerForEventClass:kInternetEventClass
andEventID:kAEGetURL];

Powered by Google App Engine
This is Rietveld 408576698