summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormitchelljones <mitchelljones@chromium.org>2014-12-18 21:01:37 -0800
committerCommit bot <commit-bot@chromium.org>2014-12-19 05:02:28 +0000
commit3bc6ced32ae6e4ae294cb23fd179cb1084e9a0bb (patch)
tree4c296391bfed24e17fafbc8eff3a909d9f134126
parent73c209621e823e68ef57a00bd15f5599bbf1ddd2 (diff)
downloadchromium_src-3bc6ced32ae6e4ae294cb23fd179cb1084e9a0bb.zip
chromium_src-3bc6ced32ae6e4ae294cb23fd179cb1084e9a0bb.tar.gz
chromium_src-3bc6ced32ae6e4ae294cb23fd179cb1084e9a0bb.tar.bz2
Added flag --enable-hosted-app-quit-notification.
Displays a notification for quitting Chrome with hosted apps running in the background on Mac. Currently, quitting Chrome will close all associated hosted app windows. BUG=442176 Review URL: https://codereview.chromium.org/801233002 Cr-Commit-Position: refs/heads/master@{#309150}
-rw-r--r--chrome/app/generated_resources.grd6
-rw-r--r--chrome/browser/about_flags.cc7
-rw-r--r--chrome/browser/app_controller_mac.mm5
-rw-r--r--chrome/browser/ui/cocoa/apps/quit_with_apps_controller_mac.cc69
-rw-r--r--chrome/browser/ui/cocoa/apps/quit_with_apps_controller_mac.h3
-rw-r--r--chrome/common/chrome_switches.cc4
-rw-r--r--chrome/common/chrome_switches.h1
-rw-r--r--tools/metrics/histograms/histograms.xml1
8 files changed, 86 insertions, 10 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index 67450a9..cc2b7c0 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -6596,6 +6596,12 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_FLAGS_ENABLE_HOSTED_APP_SHIM_CREATION_DESCRIPTION" desc="Description for the flag to enable creation of app shims for hosted apps on Mac.">
Enables the creation of app shims on Mac when creating a hosted app.
</message>
+ <message name="IDS_FLAGS_ENABLE_HOSTED_APP_QUIT_NOTIFICATION_NAME" desc="Name of the flag to enable a notification when quitting with hosted apps.">
+ Enable quit notification for hosted apps.
+ </message>
+ <message name="IDS_FLAGS_ENABLE_HOSTED_APP_QUIT_NOTIFICATION_DESCRIPTION" desc="Description for the flag to enable a notification when quitting with hosted apps.">
+ Display a notification when quitting Chrome if hosted apps are currently running.
+ </message>
<message name="IDS_FLAGS_ENABLE_EPHEMERAL_APPS_IN_WEBSTORE_NAME" desc="Name of the flag to enable ephemeral apps in the webstore.">
Enable experimental ephemeral apps from the webstore.
</message>
diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
index f8f43d4..8e458b7 100644
--- a/chrome/browser/about_flags.cc
+++ b/chrome/browser/about_flags.cc
@@ -1518,6 +1518,13 @@ const Experiment kExperiments[] = {
kOsMac,
SINGLE_VALUE_TYPE(switches::kEnableHostedAppShimCreation)
},
+ {
+ "enable-hosted-app-quit-notification",
+ IDS_FLAGS_ENABLE_HOSTED_APP_QUIT_NOTIFICATION_NAME,
+ IDS_FLAGS_ENABLE_HOSTED_APP_QUIT_NOTIFICATION_DESCRIPTION,
+ kOsMac,
+ SINGLE_VALUE_TYPE(switches::kHostedAppQuitNotification)
+ },
#endif
{
"enable-ephemeral-apps-in-webstore",
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm
index e86c79c..32e82339 100644
--- a/chrome/browser/app_controller_mac.mm
+++ b/chrome/browser/app_controller_mac.mm
@@ -430,6 +430,11 @@ class AppControllerProfileObserver : public ProfileInfoCacheObserver {
// sessions.
if (!browser_shutdown::IsTryingToQuit() && quitWithAppsController_.get() &&
!quitWithAppsController_->ShouldQuit()) {
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kHostedAppQuitNotification)) {
+ return NO;
+ }
+
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST,
content::NotificationService::AllSources(),
diff --git a/chrome/browser/ui/cocoa/apps/quit_with_apps_controller_mac.cc b/chrome/browser/ui/cocoa/apps/quit_with_apps_controller_mac.cc
index 8c4278c..f48afaa 100644
--- a/chrome/browser/ui/cocoa/apps/quit_with_apps_controller_mac.cc
+++ b/chrome/browser/ui/cocoa/apps/quit_with_apps_controller_mac.cc
@@ -12,23 +12,31 @@
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/apps/app_window_registry_util.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chrome_notification_types.h"
+#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser_iterator.h"
+#include "chrome/browser/ui/browser_window.h"
+#include "chrome/browser/web_applications/web_app.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/grit/google_chrome_strings.h"
+#include "content/public/browser/notification_service.h"
#include "extensions/browser/app_window/app_window.h"
#include "extensions/browser/app_window/native_app_window.h"
+#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension.h"
#include "grit/chrome_unscaled_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/l10n_util_mac.h"
#include "ui/base/resource/resource_bundle.h"
+using extensions::ExtensionRegistry;
+
const char kQuitWithAppsOriginUrl[] = "chrome://quit-with-apps";
const int kQuitAllAppsButtonIndex = 0;
const int kDontShowAgainButtonIndex = 1;
@@ -40,17 +48,22 @@ QuitWithAppsController::QuitWithAppsController()
: notification_profile_(NULL), suppress_for_session_(false) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ hosted_app_quit_notification_ = CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kHostedAppQuitNotification);
+
// There is only ever one notification to replace, so use the same replace_id
// each time.
base::string16 replace_id = base::UTF8ToUTF16(id());
message_center::ButtonInfo quit_apps_button_info(
l10n_util::GetStringUTF16(IDS_QUIT_WITH_APPS_QUIT_LABEL));
- message_center::ButtonInfo suppression_button_info(
- l10n_util::GetStringUTF16(IDS_QUIT_WITH_APPS_SUPPRESSION_LABEL));
message_center::RichNotificationData rich_notification_data;
rich_notification_data.buttons.push_back(quit_apps_button_info);
- rich_notification_data.buttons.push_back(suppression_button_info);
+ if (!hosted_app_quit_notification_) {
+ message_center::ButtonInfo suppression_button_info(
+ l10n_util::GetStringUTF16(IDS_QUIT_WITH_APPS_SUPPRESSION_LABEL));
+ rich_notification_data.buttons.push_back(suppression_button_info);
+ }
notification_.reset(new Notification(
message_center::NOTIFICATION_TYPE_SIMPLE,
@@ -73,8 +86,9 @@ QuitWithAppsController::~QuitWithAppsController() {}
void QuitWithAppsController::Display() {}
void QuitWithAppsController::Close(bool by_user) {
- if (by_user)
- suppress_for_session_ = true;
+ if (by_user) {
+ suppress_for_session_ = hosted_app_quit_notification_ ? false : true;
+ }
}
void QuitWithAppsController::Click() {
@@ -85,9 +99,18 @@ void QuitWithAppsController::Click() {
void QuitWithAppsController::ButtonClick(int button_index) {
g_browser_process->notification_ui_manager()->CancelById(
id(), NotificationUIManager::GetProfileID(notification_profile_));
+
if (button_index == kQuitAllAppsButtonIndex) {
+ if (hosted_app_quit_notification_) {
+ content::NotificationService::current()->Notify(
+ chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST,
+ content::NotificationService::AllSources(),
+ content::NotificationService::NoDetails());
+ chrome::CloseAllBrowsers();
+ }
AppWindowRegistryUtil::CloseAllAppWindows();
- } else if (button_index == kDontShowAgainButtonIndex) {
+ } else if (button_index == kDontShowAgainButtonIndex &&
+ !hosted_app_quit_notification_) {
g_browser_process->local_state()->SetBoolean(
prefs::kNotifyWhenAppsKeepChromeAlive, false);
}
@@ -107,10 +130,36 @@ bool QuitWithAppsController::ShouldQuit() {
return true;
}
- // Quit immediately if there are no windows or the confirmation has been
- // suppressed.
- if (!AppWindowRegistryUtil::IsAppWindowRegisteredInAnyProfile(0))
- return true;
+ if (hosted_app_quit_notification_) {
+ bool hosted_apps_open = false;
+ const BrowserList* browser_list =
+ BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_NATIVE);
+ for (Browser* browser : *browser_list) {
+ if (!browser->is_app())
+ continue;
+
+ ExtensionRegistry* registry = ExtensionRegistry::Get(browser->profile());
+ const extensions::Extension* extension = registry->GetExtensionById(
+ web_app::GetExtensionIdFromApplicationName(browser->app_name()),
+ ExtensionRegistry::ENABLED);
+ if (extension->is_hosted_app()) {
+ hosted_apps_open = true;
+ break;
+ }
+ }
+
+ // Quit immediately if there are no windows/hosted apps open or
+ // the confirmation has been suppressed.
+ if (!AppWindowRegistryUtil::IsAppWindowRegisteredInAnyProfile(0) &&
+ !hosted_apps_open) {
+ return true;
+ }
+ } else {
+ // Quit immediately if there are no windows or the confirmation has been
+ // suppressed.
+ if (!AppWindowRegistryUtil::IsAppWindowRegisteredInAnyProfile(0))
+ return true;
+ }
// If there are browser windows, and this notification has been suppressed for
// this session or permanently, then just return false to prevent Chrome from
diff --git a/chrome/browser/ui/cocoa/apps/quit_with_apps_controller_mac.h b/chrome/browser/ui/cocoa/apps/quit_with_apps_controller_mac.h
index 3cc67d9..9ac3982 100644
--- a/chrome/browser/ui/cocoa/apps/quit_with_apps_controller_mac.h
+++ b/chrome/browser/ui/cocoa/apps/quit_with_apps_controller_mac.h
@@ -47,6 +47,9 @@ class QuitWithAppsController : public NotificationDelegate {
// Whether to suppress showing the notification for the rest of the session.
bool suppress_for_session_;
+ // Display a notification when quitting Chrome with hosted apps running?
+ bool hosted_app_quit_notification_;
+
DISALLOW_COPY_AND_ASSIGN(QuitWithAppsController);
};
diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc
index bebeb20..5bc2188 100644
--- a/chrome/common/chrome_switches.cc
+++ b/chrome/common/chrome_switches.cc
@@ -1306,6 +1306,10 @@ const char kMigrateDataDirForSxS[] = "migrate-data-dir-for-sxs";
// Prevents Chrome from quitting when Chrome Apps are open.
const char kAppsKeepChromeAliveInTests[] = "apps-keep-chrome-alive-in-tests";
+// Shows a notification when quitting Chrome with hosted apps running. Default
+// behavior is to also quit all hosted apps.
+const char kHostedAppQuitNotification[] = "enable-hosted-app-quit-notification";
+
// Forcibly disables Lion-style on newer OSes, to allow developers to test the
// older, SnowLeopard-style fullscreen.
const char kDisableSystemFullscreenForTesting[] =
diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h
index 7b8abf2..02a4030 100644
--- a/chrome/common/chrome_switches.h
+++ b/chrome/common/chrome_switches.h
@@ -369,6 +369,7 @@ extern const char kMigrateDataDirForSxS[];
#if defined(OS_MACOSX)
extern const char kAppsKeepChromeAliveInTests[];
+extern const char kHostedAppQuitNotification[];
extern const char kDisableSystemFullscreenForTesting[];
extern const char kEnableHostedAppShimCreation[];
extern const char kRelauncherProcess[];
diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml
index a877022..181ee13 100644
--- a/tools/metrics/histograms/histograms.xml
+++ b/tools/metrics/histograms/histograms.xml
@@ -49722,6 +49722,7 @@ To add a new entry, add it with any value and run test to compute valid value.
<int value="-1218608640" label="disable-offline-load-stale-cache"/>
<int value="-1212273428" label="enable-experimental-app-list"/>
<int value="-1201183153" label="enable-centered-app-list"/>
+ <int value="-1177802205" label="enable-hosted-app-quit-notification"/>
<int value="-1172204005" label="enable-offline-auto-reload-visible-only"/>
<int value="-1159563774" label="enable-accessibility-script-injection"/>
<int value="-1136627751" label="ignore-autocomplete-off-autofill"/>