Commit 751d4107 authored by dhollowa@chromium.org's avatar dhollowa@chromium.org

Mac Lion: Chrome opens new window on restart when no windows were previously open

Changes startup / restore behavior to better match Lion resume expectations.  Chrome can get launched by the |loginwindow| process due to the resume feature on Lion.  In this case, if there were no windows open in Chrome when restarting, Chrome re-opens with no windows upon login.  This is also the expectation under previous OSs when Chrome is a login item, so that's been changed here too.

BUG=90249
TEST=Manual.  On Lion.  Turn Chrome session restore on, close all windows (but don't quit), restart computer.  Expect Chrome launches on startup with no open windows.

Review URL: http://codereview.chromium.org/7497056

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96198 0039d316-1c4b-4281-b951-d872f2087c98
parent 118d3122
......@@ -114,6 +114,10 @@ BASE_EXPORT void AddToLoginItems(bool hide_on_startup);
// Removes the current application from the list Of Login Items.
BASE_EXPORT void RemoveFromLoginItems();
// Returns true if the current process was automatically launched as a
// 'Login Item' or via Lion's Resume. Used to suppress opening windows.
BASE_EXPORT bool WasLaunchedAsLoginOrResumeItem();
// Returns true if the current process was automatically launched as a
// 'Login Item' with 'hide on startup' flag. Used to suppress opening windows.
BASE_EXPORT bool WasLaunchedAsHiddenLoginItem();
......
......@@ -56,28 +56,6 @@ void SetUIMode() {
SetSystemUIMode(desired_mode, desired_options);
}
bool WasLaunchedAsLoginItem() {
ProcessSerialNumber psn = { 0, kCurrentProcess };
scoped_nsobject<NSDictionary> process_info(
CFToNSCast(ProcessInformationCopyDictionary(&psn,
kProcessDictionaryIncludeAllInformationMask)));
long long temp = [[process_info objectForKey:@"ParentPSN"] longLongValue];
ProcessSerialNumber parent_psn =
{ (temp >> 32) & 0x00000000FFFFFFFFLL, temp & 0x00000000FFFFFFFFLL };
scoped_nsobject<NSDictionary> parent_info(
CFToNSCast(ProcessInformationCopyDictionary(&parent_psn,
kProcessDictionaryIncludeAllInformationMask)));
// Check that creator process code is that of loginwindow.
BOOL result =
[[parent_info objectForKey:@"FileCreator"] isEqualToString:@"lgnw"];
return result == YES;
}
// Looks into Shared File Lists corresponding to Login Items for the item
// representing the current application. If such an item is found, returns a
// retained reference to it. Caller is responsible for releasing the reference.
......@@ -472,13 +450,40 @@ void RemoveFromLoginItems() {
LSSharedFileListItemRemove(login_items, item);
}
bool WasLaunchedAsLoginOrResumeItem() {
ProcessSerialNumber psn = { 0, kCurrentProcess };
scoped_nsobject<NSDictionary> process_info(
CFToNSCast(ProcessInformationCopyDictionary(&psn,
kProcessDictionaryIncludeAllInformationMask)));
long long temp = [[process_info objectForKey:@"ParentPSN"] longLongValue];
ProcessSerialNumber parent_psn =
{ (temp >> 32) & 0x00000000FFFFFFFFLL, temp & 0x00000000FFFFFFFFLL };
scoped_nsobject<NSDictionary> parent_info(
CFToNSCast(ProcessInformationCopyDictionary(&parent_psn,
kProcessDictionaryIncludeAllInformationMask)));
// Check that creator process code is that of loginwindow.
BOOL result =
[[parent_info objectForKey:@"FileCreator"] isEqualToString:@"lgnw"];
return result == YES;
}
bool WasLaunchedAsHiddenLoginItem() {
if (!WasLaunchedAsLoginItem())
if (!WasLaunchedAsLoginOrResumeItem())
return false;
ScopedCFTypeRef<LSSharedFileListItemRef> item(GetLoginItemForApp());
if (!item.get()) {
LOG(ERROR) << "Process launched at Login but can't access Login Item List.";
// Lion can launch items for the resume feature. So log an error only for
// Snow Leopard or earlier.
if (IsOSSnowLeopardOrEarlier())
LOG(ERROR) <<
"Process launched at Login but can't access Login Item List.";
return false;
}
return IsHiddenLoginItem(item);
......
......@@ -78,6 +78,7 @@
#include "webkit/glue/webkit_glue.h"
#if defined(OS_MACOSX)
#include "base/mac/mac_util.h"
#include "chrome/browser/ui/cocoa/keystone_infobar.h"
#endif
......@@ -912,10 +913,23 @@ bool BrowserInit::LaunchWithProfile::ProcessStartupURLs(
// infobar.
return false;
}
Browser* browser = SessionRestore::RestoreSession(
profile_, NULL,
(SessionRestore::SYNCHRONOUS |
SessionRestore::ALWAYS_CREATE_TABBED_BROWSER), urls_to_open);
uint32 restore_behavior = SessionRestore::SYNCHRONOUS |
SessionRestore::ALWAYS_CREATE_TABBED_BROWSER;
#if defined(OS_MACOSX)
// On Mac, when restoring a session with no windows, suppress the creation
// of a new window in the case where the system is launching Chrome via a
// login item or Lion's resume feature.
if (base::mac::WasLaunchedAsLoginOrResumeItem()) {
restore_behavior = restore_behavior &
~SessionRestore::ALWAYS_CREATE_TABBED_BROWSER;
}
#endif
Browser* browser = SessionRestore::RestoreSession(profile_,
NULL,
restore_behavior,
urls_to_open);
AddInfoBarsIfNecessary(browser);
return true;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment