summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authoratwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-06 17:49:02 +0000
committeratwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-06 17:49:02 +0000
commit6f9eac9b410e41052a238eaa4da863572f1e86a4 (patch)
tree358b80e8d9b11b3b017bc2f1a5be606ede5a7071 /chrome
parentd9d7c7368bc7f3190791466b2db63baca1063f34 (diff)
downloadchromium_src-6f9eac9b410e41052a238eaa4da863572f1e86a4.zip
chromium_src-6f9eac9b410e41052a238eaa4da863572f1e86a4.tar.gz
chromium_src-6f9eac9b410e41052a238eaa4da863572f1e86a4.tar.bz2
Display balloon notification when background app is installed.
BUG=74970 TEST=install background app on windows, see balloon near status tray icon. Review URL: http://codereview.chromium.org/6624044 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77078 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/app/generated_resources.grd6
-rw-r--r--chrome/browser/background_mode_manager.cc26
-rw-r--r--chrome/browser/background_mode_manager.h11
-rw-r--r--chrome/browser/background_mode_manager_chromeos.cc8
-rw-r--r--chrome/browser/background_mode_manager_linux.cc6
-rw-r--r--chrome/browser/background_mode_manager_mac.mm8
-rw-r--r--chrome/browser/background_mode_manager_unittest.cc4
-rw-r--r--chrome/browser/background_mode_manager_win.cc19
-rw-r--r--chrome/browser/status_icons/status_icon.h6
-rw-r--r--chrome/browser/status_icons/status_icon_unittest.cc4
-rw-r--r--chrome/browser/status_icons/status_tray_unittest.cc4
-rw-r--r--chrome/browser/ui/cocoa/status_icons/status_icon_mac.h3
-rw-r--r--chrome/browser/ui/cocoa/status_icons/status_icon_mac.mm9
-rw-r--r--chrome/browser/ui/gtk/status_icons/status_icon_gtk.cc6
-rw-r--r--chrome/browser/ui/gtk/status_icons/status_icon_gtk.h1
-rw-r--r--chrome/browser/ui/views/status_icons/status_icon_win.cc22
-rw-r--r--chrome/browser/ui/views/status_icons/status_icon_win.h3
17 files changed, 117 insertions, 29 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index 2991709..144042c 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -210,6 +210,12 @@ Other platform defines such as use_titlecase are declared in build/common.gypi.
change nontranslateable parts of the messages into placeholders (using the
<ph> element). You can also use the 'grit add' tool to help you identify
nontranslateable parts and create placeholders for them. -->
+ <message name="IDS_BACKGROUND_APP_INSTALLED_BALLOON_TITLE" desc="The title of the balloon that is displayed when a background app is installed">
+ New background app installed
+ </message>
+ <message name="IDS_BACKGROUND_APP_INSTALLED_BALLOON_BODY" desc="The contents of the balloon that is displayed when a background app is installed">
+ <ph name="APP_NAME">$1<ex>Background App</ex></ph> will launch at system startup and continue to run in the background even once you've closed all other <ph name="PRODUCT_NAME">$2<ex>Google Chrome</ex></ph> windows.
+ </message>
<message name="IDS_SHOWFULLHISTORY_LINK" desc="The label of the Show Full History link at the bottom of the back/forward menu.">
Show Full History
diff --git a/chrome/browser/background_mode_manager.cc b/chrome/browser/background_mode_manager.cc
index fc0e07f..025eba7 100644
--- a/chrome/browser/background_mode_manager.cc
+++ b/chrome/browser/background_mode_manager.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -119,14 +119,15 @@ void BackgroundModeManager::Observe(NotificationType type,
EnableLaunchOnStartup(background_app_count_ > 0);
#endif
break;
- case NotificationType::EXTENSION_LOADED:
- if (BackgroundApplicationListModel::IsBackgroundApp(
- *Details<Extension>(details).ptr())) {
- // Extensions loaded after the ExtensionsService is ready should be
- // treated as new installs.
- if (profile_->GetExtensionService()->is_ready())
- OnBackgroundAppInstalled();
- OnBackgroundAppLoaded();
+ case NotificationType::EXTENSION_LOADED: {
+ Extension* extension = Details<Extension>(details).ptr();
+ if (BackgroundApplicationListModel::IsBackgroundApp(*extension)) {
+ // Extensions loaded after the ExtensionsService is ready should be
+ // treated as new installs.
+ if (profile_->GetExtensionService()->is_ready())
+ OnBackgroundAppInstalled(extension);
+ OnBackgroundAppLoaded();
+ }
}
break;
case NotificationType::EXTENSION_UNLOADED:
@@ -214,11 +215,16 @@ void BackgroundModeManager::EndBackgroundMode() {
RemoveStatusTrayIcon();
}
-void BackgroundModeManager::OnBackgroundAppInstalled() {
+void BackgroundModeManager::OnBackgroundAppInstalled(
+ const Extension* extension) {
// We're installing a background app. If this is the first background app
// being installed, make sure we are set to launch on startup.
if (background_app_count_ == 0)
EnableLaunchOnStartup(true);
+
+ // Notify the user that a background app has been installed.
+ if (extension) // NULL when called by unit tests.
+ DisplayAppInstalledNotification(extension);
}
void BackgroundModeManager::OnBackgroundAppUninstalled() {
diff --git a/chrome/browser/background_mode_manager.h b/chrome/browser/background_mode_manager.h
index b874fd6..e8f5e23 100644
--- a/chrome/browser/background_mode_manager.h
+++ b/chrome/browser/background_mode_manager.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -86,8 +86,9 @@ class BackgroundModeManager
void OnBackgroundAppUnloaded();
// Invoked when an extension is installed so we can ensure that
- // launch-on-startup is enabled if appropriate.
- void OnBackgroundAppInstalled();
+ // launch-on-startup is enabled if appropriate. |extension| can be NULL when
+ // called from unit tests.
+ void OnBackgroundAppInstalled(const Extension* extension);
// Invoked when an extension is uninstalled so we can ensure that
// launch-on-startup is disabled if appropriate.
@@ -97,6 +98,10 @@ class BackgroundModeManager
// (virtual so we can override for tests).
virtual void EnableLaunchOnStartup(bool should_launch);
+ // Invoked when a background app is installed so we can display a
+ // platform-specific notification to the user.
+ void DisplayAppInstalledNotification(const Extension* extension);
+
// Invoked to put Chrome in KeepAlive mode - chrome runs in the background
// and has a status bar icon.
void StartBackgroundMode();
diff --git a/chrome/browser/background_mode_manager_chromeos.cc b/chrome/browser/background_mode_manager_chromeos.cc
index d01c70d..86138b0 100644
--- a/chrome/browser/background_mode_manager_chromeos.cc
+++ b/chrome/browser/background_mode_manager_chromeos.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -11,6 +11,12 @@ void BackgroundModeManager::EnableLaunchOnStartup(bool should_launch) {
NOTREACHED();
}
+void BackgroundModeManager::DisplayAppInstalledNotification(
+ const Extension* extension) {
+ // No need to display anything on ChromeOS because all extensions run all
+ // the time anyway.
+}
+
string16 BackgroundModeManager::GetPreferencesMenuLabel() {
return l10n_util::GetStringUTF16(IDS_SETTINGS);
}
diff --git a/chrome/browser/background_mode_manager_linux.cc b/chrome/browser/background_mode_manager_linux.cc
index bdae35a..be4d969 100644
--- a/chrome/browser/background_mode_manager_linux.cc
+++ b/chrome/browser/background_mode_manager_linux.cc
@@ -78,6 +78,12 @@ void EnableLaunchOnStartupTask::Run() {
}
}
+void BackgroundModeManager::DisplayAppInstalledNotification(
+ const Extension* extension) {
+ // TODO(atwilson): Display a platform-appropriate notification here.
+ // http://crbug.com/74970
+}
+
string16 BackgroundModeManager::GetPreferencesMenuLabel() {
string16 result = gtk_util::GetStockPreferencesMenuLabel();
if (!result.empty())
diff --git a/chrome/browser/background_mode_manager_mac.mm b/chrome/browser/background_mode_manager_mac.mm
index dfd102e..d7a7142 100644
--- a/chrome/browser/background_mode_manager_mac.mm
+++ b/chrome/browser/background_mode_manager_mac.mm
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -73,6 +73,12 @@ void BackgroundModeManager::EnableLaunchOnStartup(bool should_launch) {
}
}
+void BackgroundModeManager::DisplayAppInstalledNotification(
+ const Extension* extension) {
+ // TODO(atwilson): Display a platform-appropriate notification here.
+ // http://crbug.com/74970
+}
+
string16 BackgroundModeManager::GetPreferencesMenuLabel() {
return l10n_util::GetStringUTF16(IDS_OPTIONS);
}
diff --git a/chrome/browser/background_mode_manager_unittest.cc b/chrome/browser/background_mode_manager_unittest.cc
index 0005afd..142c12e 100644
--- a/chrome/browser/background_mode_manager_unittest.cc
+++ b/chrome/browser/background_mode_manager_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -60,7 +60,7 @@ TEST_F(BackgroundModeManagerTest, BackgroundAppInstallUninstall) {
EXPECT_CALL(manager, CreateStatusTrayIcon());
EXPECT_CALL(manager, RemoveStatusTrayIcon());
EXPECT_CALL(manager, EnableLaunchOnStartup(false));
- manager.OnBackgroundAppInstalled();
+ manager.OnBackgroundAppInstalled(NULL);
manager.OnBackgroundAppLoaded();
manager.OnBackgroundAppUnloaded();
manager.OnBackgroundAppUninstalled();
diff --git a/chrome/browser/background_mode_manager_win.cc b/chrome/browser/background_mode_manager_win.cc
index 4c9a59f..7eafe73 100644
--- a/chrome/browser/background_mode_manager_win.cc
+++ b/chrome/browser/background_mode_manager_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -8,11 +8,13 @@
#include "base/logging.h"
#include "base/path_service.h"
#include "base/task.h"
+#include "base/utf_string_conversions.h"
#include "base/win/registry.h"
#include "chrome/browser/background_mode_manager.h"
#include "chrome/common/chrome_switches.h"
#include "content/browser/browser_thread.h"
-#include "grit/generated_resources.h"
+#include "grit/chromium_strings.h"
+#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
namespace {
@@ -84,6 +86,19 @@ void BackgroundModeManager::EnableLaunchOnStartup(bool should_launch) {
}
}
+void BackgroundModeManager::DisplayAppInstalledNotification(
+ const Extension* extension) {
+ // Create a status tray notification balloon explaining to the user that
+ // a background app has been installed.
+ CreateStatusTrayIcon();
+ status_icon_->DisplayBalloon(
+ l10n_util::GetStringUTF16(IDS_BACKGROUND_APP_INSTALLED_BALLOON_TITLE),
+ l10n_util::GetStringFUTF16(
+ IDS_BACKGROUND_APP_INSTALLED_BALLOON_BODY,
+ UTF8ToUTF16(extension->name()),
+ l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)));
+}
+
string16 BackgroundModeManager::GetPreferencesMenuLabel() {
return l10n_util::GetStringUTF16(IDS_OPTIONS);
}
diff --git a/chrome/browser/status_icons/status_icon.h b/chrome/browser/status_icons/status_icon.h
index 3b53dc5..654230b 100644
--- a/chrome/browser/status_icons/status_icon.h
+++ b/chrome/browser/status_icons/status_icon.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -30,6 +30,10 @@ class StatusIcon {
// Sets the hover text for this status icon.
virtual void SetToolTip(const string16& tool_tip) = 0;
+ // Displays a notification balloon with the specified contents.
+ virtual void DisplayBalloon(const string16& title,
+ const string16& contents) = 0;
+
// Set the context menu for this icon. The icon takes ownership of the passed
// context menu. Passing NULL results in no menu at all.
void SetContextMenu(ui::MenuModel* menu);
diff --git a/chrome/browser/status_icons/status_icon_unittest.cc b/chrome/browser/status_icons/status_icon_unittest.cc
index a3a2596..ec41e7e 100644
--- a/chrome/browser/status_icons/status_icon_unittest.cc
+++ b/chrome/browser/status_icons/status_icon_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -19,6 +19,8 @@ class TestStatusIcon : public StatusIcon {
virtual void SetPressedImage(const SkBitmap& image) {}
virtual void SetToolTip(const string16& tool_tip) {}
virtual void UpdatePlatformContextMenu(ui::MenuModel* menu) {}
+ virtual void DisplayBalloon(const string16& title,
+ const string16& contents) {}
};
TEST(StatusIconTest, ObserverAdd) {
diff --git a/chrome/browser/status_icons/status_tray_unittest.cc b/chrome/browser/status_icons/status_tray_unittest.cc
index 61555f9..926aa38 100644
--- a/chrome/browser/status_icons/status_tray_unittest.cc
+++ b/chrome/browser/status_icons/status_tray_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -15,6 +15,8 @@ class MockStatusIcon : public StatusIcon {
virtual void SetImage(const SkBitmap& image) {}
virtual void SetPressedImage(const SkBitmap& image) {}
virtual void SetToolTip(const string16& tool_tip) {}
+ virtual void DisplayBalloon(const string16& title,
+ const string16& contents) {}
virtual void UpdatePlatformContextMenu(ui::MenuModel* menu) {}
virtual void AddObserver(StatusIcon::Observer* observer) {}
virtual void RemoveObserver(StatusIcon::Observer* observer) {}
diff --git a/chrome/browser/ui/cocoa/status_icons/status_icon_mac.h b/chrome/browser/ui/cocoa/status_icons/status_icon_mac.h
index 7c2c84e..122aab7 100644
--- a/chrome/browser/ui/cocoa/status_icons/status_icon_mac.h
+++ b/chrome/browser/ui/cocoa/status_icons/status_icon_mac.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -25,6 +25,7 @@ class StatusIconMac : public StatusIcon {
virtual void SetImage(const SkBitmap& image);
virtual void SetPressedImage(const SkBitmap& image);
virtual void SetToolTip(const string16& tool_tip);
+ virtual void DisplayBalloon(const string16& title, const string16& contents);
protected:
// Overridden from StatusIcon.
diff --git a/chrome/browser/ui/cocoa/status_icons/status_icon_mac.mm b/chrome/browser/ui/cocoa/status_icons/status_icon_mac.mm
index 9ac39bf..a10b148 100644
--- a/chrome/browser/ui/cocoa/status_icons/status_icon_mac.mm
+++ b/chrome/browser/ui/cocoa/status_icons/status_icon_mac.mm
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -76,6 +76,13 @@ void StatusIconMac::SetToolTip(const string16& tool_tip) {
[item() setToolTip:base::SysUTF16ToNSString(tool_tip)];
}
+void StatusIconMac::DisplayBalloon(const string16& title,
+ const string16& contents) {
+ // TODO(atwilson): Figure out the right UI to display here when actually
+ // needed (not yet called).
+ // http://crbug.com/74970
+}
+
void StatusIconMac::UpdatePlatformContextMenu(ui::MenuModel* menu) {
// TODO(atwilson): Add support for context menus for Mac when actually needed
// (not yet used by anything) - http://crbug.com/37375.
diff --git a/chrome/browser/ui/gtk/status_icons/status_icon_gtk.cc b/chrome/browser/ui/gtk/status_icons/status_icon_gtk.cc
index 1d66b6b..c9456e8 100644
--- a/chrome/browser/ui/gtk/status_icons/status_icon_gtk.cc
+++ b/chrome/browser/ui/gtk/status_icons/status_icon_gtk.cc
@@ -43,6 +43,12 @@ void StatusIconGtk::SetToolTip(const string16& tool_tip) {
gtk_status_icon_set_tooltip(icon_, UTF16ToUTF8(tool_tip).c_str());
}
+void StatusIconGtk::DisplayBalloon(const string16& title,
+ const string16& contents) {
+ // TODO(atwilson): Figure out the right thing to do here.
+ // http://crbug.com/74970
+}
+
void StatusIconGtk::OnClick(GtkWidget* widget) {
DispatchClickEvent();
}
diff --git a/chrome/browser/ui/gtk/status_icons/status_icon_gtk.h b/chrome/browser/ui/gtk/status_icons/status_icon_gtk.h
index 3acf454..217e693 100644
--- a/chrome/browser/ui/gtk/status_icons/status_icon_gtk.h
+++ b/chrome/browser/ui/gtk/status_icons/status_icon_gtk.h
@@ -23,6 +23,7 @@ class StatusIconGtk : public StatusIcon {
virtual void SetImage(const SkBitmap& image);
virtual void SetPressedImage(const SkBitmap& image);
virtual void SetToolTip(const string16& tool_tip);
+ virtual void DisplayBalloon(const string16& title, const string16& contents);
// Exposed for testing.
CHROMEGTK_CALLBACK_0(StatusIconGtk, void, OnClick);
diff --git a/chrome/browser/ui/views/status_icons/status_icon_win.cc b/chrome/browser/ui/views/status_icons/status_icon_win.cc
index 19d182a..ba937c6 100644
--- a/chrome/browser/ui/views/status_icons/status_icon_win.cc
+++ b/chrome/browser/ui/views/status_icons/status_icon_win.cc
@@ -79,10 +79,18 @@ void StatusIconWin::SetToolTip(const string16& tool_tip) {
LOG(WARNING) << "Unable to set tooltip for status tray icon";
}
-void StatusIconWin::InitIconData(NOTIFYICONDATA* icon_data) {
- icon_data->cbSize = sizeof(icon_data);
- icon_data->hWnd = window_;
- icon_data->uID = icon_id_;
+void StatusIconWin::DisplayBalloon(const string16& title,
+ const string16& contents) {
+ NOTIFYICONDATA icon_data;
+ InitIconData(&icon_data);
+ icon_data.uFlags = NIF_INFO;
+ icon_data.dwInfoFlags = NIIF_INFO;
+ wcscpy_s(icon_data.szInfoTitle, title.c_str());
+ wcscpy_s(icon_data.szInfo, contents.c_str());
+ icon_data.uTimeout = 0;
+ BOOL result = Shell_NotifyIcon(NIM_MODIFY, &icon_data);
+ if (!result)
+ LOG(WARNING) << "Unable to create status tray balloon.";
}
void StatusIconWin::UpdatePlatformContextMenu(ui::MenuModel* menu) {
@@ -111,3 +119,9 @@ void StatusIconWin::HandleClickEvent(int x, int y, bool left_mouse_click) {
context_menu_->RunContextMenuAt(gfx::Point(x, y));
}
}
+
+void StatusIconWin::InitIconData(NOTIFYICONDATA* icon_data) {
+ icon_data->cbSize = sizeof(NOTIFYICONDATA);
+ icon_data->hWnd = window_;
+ icon_data->uID = icon_id_;
+}
diff --git a/chrome/browser/ui/views/status_icons/status_icon_win.h b/chrome/browser/ui/views/status_icons/status_icon_win.h
index a4582ba..38eda3f 100644
--- a/chrome/browser/ui/views/status_icons/status_icon_win.h
+++ b/chrome/browser/ui/views/status_icons/status_icon_win.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -27,6 +27,7 @@ class StatusIconWin : public StatusIcon {
virtual void SetImage(const SkBitmap& image);
virtual void SetPressedImage(const SkBitmap& image);
virtual void SetToolTip(const string16& tool_tip);
+ virtual void DisplayBalloon(const string16& title, const string16& contents);
UINT icon_id() const { return icon_id_; }