diff options
author | dhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-10 17:18:45 +0000 |
---|---|---|
committer | dhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-10 17:18:45 +0000 |
commit | 751d410765c3b6e34c84f6f29ad4e2e10186baa8 (patch) | |
tree | 62d751b25619f76c9fcd3a87505717434bb07b4d /base/mac | |
parent | 118d3122e60a648db2b054da8d83af1109915ed3 (diff) | |
download | chromium_src-751d410765c3b6e34c84f6f29ad4e2e10186baa8.zip chromium_src-751d410765c3b6e34c84f6f29ad4e2e10186baa8.tar.gz chromium_src-751d410765c3b6e34c84f6f29ad4e2e10186baa8.tar.bz2 |
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
Diffstat (limited to 'base/mac')
-rw-r--r-- | base/mac/mac_util.h | 4 | ||||
-rw-r--r-- | base/mac/mac_util.mm | 53 |
2 files changed, 33 insertions, 24 deletions
diff --git a/base/mac/mac_util.h b/base/mac/mac_util.h index e3ee0db..dcb7780 100644 --- a/base/mac/mac_util.h +++ b/base/mac/mac_util.h @@ -115,6 +115,10 @@ BASE_EXPORT void AddToLoginItems(bool hide_on_startup); 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(); diff --git a/base/mac/mac_util.mm b/base/mac/mac_util.mm index 0f34180..60f544f 100644 --- a/base/mac/mac_util.mm +++ b/base/mac/mac_util.mm @@ -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); |