summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authordimich@chromium.org <dimich@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-27 17:55:54 +0000
committerdimich@chromium.org <dimich@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-27 17:55:54 +0000
commit91484afdf575b8dd68ba92238338085f8758dbcd (patch)
tree6e1b831f09cf9a910211eb515c91ce320589aae6 /chrome/browser
parentd852274be5cd2157e9519c9dc587e29a091032fa (diff)
downloadchromium_src-91484afdf575b8dd68ba92238338085f8758dbcd.zip
chromium_src-91484afdf575b8dd68ba92238338085f8758dbcd.tar.gz
chromium_src-91484afdf575b8dd68ba92238338085f8758dbcd.tar.bz2
Re-land. Fixed previous errors.
Implement OSX version for "Start on Login" for background-enabled extensions. When user installs first background-enabled extension we set Chrome to be a hidden "Login Item", and when user uninstalls the last one, we remove Chrome from the "Login Items List". Login Items are the apps that are listed in Systempreferences->Accounts->Login Items, or which have a "Open on Login" check for their Dock icon. Since we manipulate the user-faced UI item here, we try to do it in a way that will likely not interfere with user settings. Most typically, users do not use 'hidden' property, so if we ever encounter setting w/o this property, we won't override. Also there is a hidden preference used to remember the fact that Chrome changed the settings earlier - to avoid override on uninstall of the last persistent app in opposite case. Using the same bit that user can manipulate separately and perhaps even knows about is beneficial since it provides for unified place to "start Chrome on Login" and reduces confusion. Implementation for Login Items List access uses LSSharedFileList API that is available starting 10.5, which I think is our minimal supported version of OSX. BUG=43382 TEST=none Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=57569 Reverted Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=57614 Reverted Review URL: http://codereview.chromium.org/3163029 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57699 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/background_mode_manager.cc51
-rw-r--r--chrome/browser/background_mode_manager.h6
-rw-r--r--chrome/browser/browser_main_mac.mm9
3 files changed, 65 insertions, 1 deletions
diff --git a/chrome/browser/background_mode_manager.cc b/chrome/browser/background_mode_manager.cc
index 871e243..b619177 100644
--- a/chrome/browser/background_mode_manager.cc
+++ b/chrome/browser/background_mode_manager.cc
@@ -23,6 +23,10 @@
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
+#if defined(OS_MACOSX)
+#include "base/mac_util.h"
+#endif
+
#if defined(TOOLKIT_GTK)
#include "chrome/browser/gtk/gtk_util.h"
#endif
@@ -82,13 +86,27 @@ bool BackgroundModeManager::IsBackgroundModeEnabled() {
return profile_->GetPrefs()->GetBoolean(prefs::kBackgroundModeEnabled);
}
+bool BackgroundModeManager::IsLaunchOnStartupResetAllowed() {
+ return profile_->GetPrefs()->GetBoolean(prefs::kLaunchOnStartupResetAllowed);
+}
+
+void BackgroundModeManager::SetLaunchOnStartupResetAllowed(bool allowed) {
+ profile_->GetPrefs()->SetBoolean(prefs::kLaunchOnStartupResetAllowed,
+ allowed);
+}
+
void BackgroundModeManager::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
switch (type.value) {
case NotificationType::EXTENSIONS_READY:
+ // On a Mac, we use 'login items' mechanism which has user-facing UI so we
+ // don't want to stomp on user choice every time we start and load
+ // registered extensions.
+#if !defined(OS_MACOSX)
EnableLaunchOnStartup(IsBackgroundModeEnabled() &&
background_app_count_ > 0);
+#endif
break;
case NotificationType::EXTENSION_LOADED:
if (IsBackgroundApp(Details<Extension>(details).ptr()))
@@ -171,8 +189,38 @@ void BackgroundModeManager::OnBackgroundAppUninstalled() {
}
void BackgroundModeManager::EnableLaunchOnStartup(bool should_launch) {
- // TODO(atwilson): Add platform-specific code to enable/disable launch on
+ // TODO(BUG43382): Add code for other platforms to enable/disable launch on
// startup.
+
+ // This functionality is only defined for default profile, currently.
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUserDataDir))
+ return;
+
+#if defined(OS_MACOSX)
+ if (should_launch) {
+ // Return if Chrome is already a Login Item (avoid overriding user choice).
+ if (mac_util::CheckLoginItemStatus(NULL))
+ return;
+
+ mac_util::AddToLoginItems(true); // Hide on startup.
+
+ // Remember we set Login Item, not the user - so we can reset it later.
+ SetLaunchOnStartupResetAllowed(true);
+ } else {
+ // If we didn't set Login Item, don't mess with it.
+ if (!IsLaunchOnStartupResetAllowed())
+ return;
+ SetLaunchOnStartupResetAllowed(false);
+
+ // Check if Chrome is not a login Item, or is a Login Item but w/o 'hidden'
+ // flag - most likely user has modified the setting, don't override it.
+ bool is_hidden = false;
+ if (!mac_util::CheckLoginItemStatus(&is_hidden) || !is_hidden)
+ return;
+
+ mac_util::RemoveFromLoginItems();
+ }
+#endif
}
void BackgroundModeManager::CreateStatusTrayIcon() {
@@ -269,4 +317,5 @@ Browser* BackgroundModeManager::GetBrowserWindow() {
// static
void BackgroundModeManager::RegisterUserPrefs(PrefService* prefs) {
prefs->RegisterBooleanPref(prefs::kBackgroundModeEnabled, true);
+ prefs->RegisterBooleanPref(prefs::kLaunchOnStartupResetAllowed, false);
}
diff --git a/chrome/browser/background_mode_manager.h b/chrome/browser/background_mode_manager.h
index 3a82399..38b010c 100644
--- a/chrome/browser/background_mode_manager.h
+++ b/chrome/browser/background_mode_manager.h
@@ -82,6 +82,12 @@ class BackgroundModeManager
// Returns true if the background mode preference is enabled
bool IsBackgroundModeEnabled();
+ // Returns true if chrome has set "launch on startup" property for itself
+ // earlier and is allowed to reset it later, reducing likelihood of
+ // overriding user choices.
+ bool IsLaunchOnStartupResetAllowed();
+ void SetLaunchOnStartupResetAllowed(bool allowed);
+
// Called to make sure that our launch-on-startup mode is properly set.
// (virtual so we can override for tests).
virtual void EnableLaunchOnStartup(bool should_launch);
diff --git a/chrome/browser/browser_main_mac.mm b/chrome/browser/browser_main_mac.mm
index 5aa5999..a00c47b 100644
--- a/chrome/browser/browser_main_mac.mm
+++ b/chrome/browser/browser_main_mac.mm
@@ -68,6 +68,15 @@ class BrowserMainPartsMac : public BrowserMainPartsPosix {
: BrowserMainPartsPosix(parameters) {}
protected:
+ virtual void PreEarlyInitialization() {
+ BrowserMainPartsPosix::PreEarlyInitialization();
+
+ if (mac_util::WasLaunchedAsHiddenLoginItem()) {
+ CommandLine* singleton_command_line = CommandLine::ForCurrentProcess();
+ singleton_command_line->AppendSwitch(switches::kNoStartupWindow);
+ }
+ }
+
virtual void PreMainMessageLoopStart() {
BrowserMainPartsPosix::PreMainMessageLoopStart();