summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorerg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-29 17:05:23 +0000
committererg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-29 17:05:23 +0000
commit216e904053b111d31cf5fad355f2bb57743182cc (patch)
treefb3cc29c35622a2b75b435fd61eb6d7352ed4dd0 /chrome/browser
parent5c558bc54d375335982ebcd947840a9a1f4eab40 (diff)
downloadchromium_src-216e904053b111d31cf5fad355f2bb57743182cc.zip
chromium_src-216e904053b111d31cf5fad355f2bb57743182cc.tar.gz
chromium_src-216e904053b111d31cf5fad355f2bb57743182cc.tar.bz2
Fix window restore behaviour on Mac.
On the mac, there can be no windows, but the application is sitll open. This confused "Restore the pages that were open last" so that it would restore when opening a new window. BUG=13341 TEST=Open chromium. Set On Startup to "Restore the pages that were open last". Open a few tabs. Close the window (but not chromium). Click the dock icon. The tabs shouldn't be restored. But if you quit chrome and start again, things should reopen. Review URL: http://codereview.chromium.org/340023 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30463 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/app_controller_cppsafe_mac.h19
-rw-r--r--chrome/browser/app_controller_mac.mm18
-rw-r--r--chrome/browser/sessions/session_service.cc13
3 files changed, 49 insertions, 1 deletions
diff --git a/chrome/browser/app_controller_cppsafe_mac.h b/chrome/browser/app_controller_cppsafe_mac.h
new file mode 100644
index 0000000..da2aefb
--- /dev/null
+++ b/chrome/browser/app_controller_cppsafe_mac.h
@@ -0,0 +1,19 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_APP_CONTROLLER_CPPSAFE_MAC_H_
+#define CHROME_BROWSER_APP_CONTROLLER_CPPSAFE_MAC_H_
+
+// We declare this in a separate file that is safe for including in C++ code.
+
+namespace app_controller_mac {
+
+// True if we are currently handling an IDC_NEW_{TAB,WINDOW} command. Used in
+// SessionService::Observe() to get around windows/linux and mac having
+// different models of application lifetime.
+bool IsOpeningNewWindow();
+
+} // namespace app_controller_mac
+
+#endif // CHROME_BROWSER_APP_CONTROLLER_CPPSAFE_MAC_H_
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm
index fcbdb23..faf6789 100644
--- a/chrome/browser/app_controller_mac.mm
+++ b/chrome/browser/app_controller_mac.mm
@@ -53,6 +53,12 @@
- (BOOL)shouldQuitWithInProgressDownloads;
@end
+// True while AppController is calling Browser::OpenEmptyWindow(). We need a
+// global flag here, analogue to BrowserInit::InProcessStartup() because
+// otherwise the SessionService will try to restore sessions when we make a new
+// window while there are no other active windows.
+static bool g_is_opening_new_window = false;
+
@implementation AppController
// This method is called very early in application startup (ie, before
@@ -489,7 +495,9 @@
switch (tag) {
case IDC_NEW_TAB:
case IDC_NEW_WINDOW:
+ g_is_opening_new_window = true;
Browser::OpenEmptyWindow(defaultProfile);
+ g_is_opening_new_window = false;
break;
case IDC_NEW_INCOGNITO_WINDOW:
Browser::OpenEmptyWindow(defaultProfile->GetOffTheRecordProfile());
@@ -527,7 +535,9 @@
return YES;
// Otherwise open a new window.
+ g_is_opening_new_window = true;
Browser::OpenEmptyWindow([self defaultProfile]);
+ g_is_opening_new_window = false;
// We've handled the reopen event, so return NO to tell AppKit not
// to do anything.
@@ -729,3 +739,11 @@ void ShowOptionsWindow(OptionsPage page,
Profile* profile) {
NOTIMPLEMENTED();
}
+
+namespace app_controller_mac {
+
+bool IsOpeningNewWindow() {
+ return g_is_opening_new_window;
+}
+
+} // namespace app_controller_mac
diff --git a/chrome/browser/sessions/session_service.cc b/chrome/browser/sessions/session_service.cc
index 31c2966..4682ca3 100644
--- a/chrome/browser/sessions/session_service.cc
+++ b/chrome/browser/sessions/session_service.cc
@@ -29,6 +29,10 @@
#include "chrome/common/notification_details.h"
#include "chrome/common/notification_service.h"
+#if defined(OS_MACOSX)
+#include "chrome/browser/app_controller_cppsafe_mac.h"
+#endif
+
using base::Time;
// Identifier for commands written to file.
@@ -409,7 +413,14 @@ void SessionService::Observe(NotificationType type,
return;
}
- if (!has_open_trackable_browsers_ && !BrowserInit::InProcessStartup()) {
+ if (!has_open_trackable_browsers_ && !BrowserInit::InProcessStartup()
+#if defined(OS_MACOSX)
+ // OSX has a fairly different idea of application lifetime than the
+ // other platforms. We need to check that we aren't opening a window
+ // from the dock or the menubar.
+ && !app_controller_mac::IsOpeningNewWindow()
+#endif
+ ) {
// We're going from no tabbed browsers to a tabbed browser (and not in
// process startup), restore the last session.
if (move_on_new_browser_) {