summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjackhou@chromium.org <jackhou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-03 03:45:00 +0000
committerjackhou@chromium.org <jackhou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-03 03:45:00 +0000
commit22e0e8a30359118e29f96544da7c1bd21dd48e33 (patch)
treebcfb9061a3e9c35350a6f28f961220bc0f06b77c
parentfce50255402b235a8f9fe4b1122915d22c58e834 (diff)
downloadchromium_src-22e0e8a30359118e29f96544da7c1bd21dd48e33.zip
chromium_src-22e0e8a30359118e29f96544da7c1bd21dd48e33.tar.gz
chromium_src-22e0e8a30359118e29f96544da7c1bd21dd48e33.tar.bz2
Hide and show app windows when the shim is hidden/shown.
This adds a new IPC message for hiding/showing the app. It currently only works while Chrome is shown. Hiding Chrome hides all windows and any time a Chrome window gains focus, Chrome becomes unhidden. To make it work as desired, we'd have to override the built-in NSApp hide/unhide behaviour and manage it ourselves. BUG=168080 TEST=Start an app. Right click its shim -> Hide. The apps windows should disappear with Chrome still visible. Click the shim (or right click -> Show). Th apps windows should reappear in the order they were previously. Review URL: https://chromiumcodereview.appspot.com/17999002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@209869 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--apps/app_shim/app_shim_handler_mac.h3
-rw-r--r--apps/app_shim/app_shim_host_mac.cc8
-rw-r--r--apps/app_shim/app_shim_host_mac.h2
-rw-r--r--apps/app_shim/app_shim_host_mac_unittest.cc4
-rw-r--r--apps/app_shim/app_shim_messages.h4
-rw-r--r--apps/app_shim/extension_app_shim_handler_mac.cc15
-rw-r--r--apps/app_shim/extension_app_shim_handler_mac.h1
-rw-r--r--chrome/app/chrome_main_app_mode_mac.mm26
-rw-r--r--chrome/browser/ui/app_list/app_list_service_mac.mm5
9 files changed, 61 insertions, 7 deletions
diff --git a/apps/app_shim/app_shim_handler_mac.h b/apps/app_shim/app_shim_handler_mac.h
index 9a6d73c..7b3fea3 100644
--- a/apps/app_shim/app_shim_handler_mac.h
+++ b/apps/app_shim/app_shim_handler_mac.h
@@ -59,6 +59,9 @@ class AppShimHandler {
// Invoked by the shim host when the shim process receives a focus event.
virtual void OnShimFocus(Host* host, AppShimFocusType focus_type) = 0;
+ // Invoked by the shim host when the shim process is hidden or shown.
+ virtual void OnShimSetHidden(Host* host, bool hidden) = 0;
+
// Invoked by the shim host when the shim process receives a quit event.
virtual void OnShimQuit(Host* host) = 0;
diff --git a/apps/app_shim/app_shim_host_mac.cc b/apps/app_shim/app_shim_host_mac.cc
index 8c4c89d..8f45c6d 100644
--- a/apps/app_shim/app_shim_host_mac.cc
+++ b/apps/app_shim/app_shim_host_mac.cc
@@ -46,6 +46,7 @@ bool AppShimHost::OnMessageReceived(const IPC::Message& message) {
IPC_BEGIN_MESSAGE_MAP(AppShimHost, message)
IPC_MESSAGE_HANDLER(AppShimHostMsg_LaunchApp, OnLaunchApp)
IPC_MESSAGE_HANDLER(AppShimHostMsg_FocusApp, OnFocus)
+ IPC_MESSAGE_HANDLER(AppShimHostMsg_SetAppHidden, OnSetHidden)
IPC_MESSAGE_HANDLER(AppShimHostMsg_QuitApp, OnQuit)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
@@ -88,6 +89,13 @@ void AppShimHost::OnFocus(apps::AppShimFocusType focus_type) {
handler->OnShimFocus(this, focus_type);
}
+void AppShimHost::OnSetHidden(bool hidden) {
+ DCHECK(CalledOnValidThread());
+ apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_);
+ if (handler)
+ handler->OnShimSetHidden(this, hidden);
+}
+
void AppShimHost::OnQuit() {
DCHECK(CalledOnValidThread());
apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_);
diff --git a/apps/app_shim/app_shim_host_mac.h b/apps/app_shim/app_shim_host_mac.h
index 9bb2438..f654396 100644
--- a/apps/app_shim/app_shim_host_mac.h
+++ b/apps/app_shim/app_shim_host_mac.h
@@ -57,6 +57,8 @@ class AppShimHost : public IPC::Listener,
// Called when the app shim process notifies that the app was focused.
void OnFocus(apps::AppShimFocusType focus_type);
+ void OnSetHidden(bool hidden);
+
// Called when the app shim process notifies that the app should quit.
void OnQuit();
diff --git a/apps/app_shim/app_shim_host_mac_unittest.cc b/apps/app_shim/app_shim_host_mac_unittest.cc
index ccc9a50..bb8d2d7 100644
--- a/apps/app_shim/app_shim_host_mac_unittest.cc
+++ b/apps/app_shim/app_shim_host_mac_unittest.cc
@@ -88,10 +88,14 @@ class AppShimHostTest : public testing::Test,
}
virtual void OnShimClose(Host* host) OVERRIDE { ++close_count_; }
+
virtual void OnShimFocus(Host* host,
apps::AppShimFocusType focus_type) OVERRIDE {
++focus_count_;
}
+
+ virtual void OnShimSetHidden(Host* host, bool hidden) OVERRIDE {}
+
virtual void OnShimQuit(Host* host) OVERRIDE { ++quit_count_; }
bool fail_launch_;
diff --git a/apps/app_shim/app_shim_messages.h b/apps/app_shim/app_shim_messages.h
index c6958e5..457e940 100644
--- a/apps/app_shim/app_shim_messages.h
+++ b/apps/app_shim/app_shim_messages.h
@@ -38,6 +38,10 @@ IPC_MESSAGE_CONTROL3(AppShimHostMsg_LaunchApp,
IPC_MESSAGE_CONTROL1(AppShimHostMsg_FocusApp,
apps::AppShimFocusType /* focus type */)
+// Sent when the app shim is hidden or unhidden.
+IPC_MESSAGE_CONTROL1(AppShimHostMsg_SetAppHidden,
+ bool /* hidden */)
+
// Sent when the shim process receives a request to terminate. Once all of the
// app's windows have closed, and the extension is unloaded, the AppShimHost
// closes the channel. The shim process then completes the terminate request
diff --git a/apps/app_shim/extension_app_shim_handler_mac.cc b/apps/app_shim/extension_app_shim_handler_mac.cc
index 4694650..13114e5 100644
--- a/apps/app_shim/extension_app_shim_handler_mac.cc
+++ b/apps/app_shim/extension_app_shim_handler_mac.cc
@@ -205,6 +205,21 @@ void ExtensionAppShimHandler::OnShimFocus(Host* host,
}
}
+void ExtensionAppShimHandler::OnShimSetHidden(Host* host, bool hidden) {
+ DCHECK(delegate_->ProfileExistsForPath(host->GetProfilePath()));
+ Profile* profile = delegate_->ProfileForPath(host->GetProfilePath());
+
+ const ShellWindowList windows =
+ delegate_->GetWindows(profile, host->GetAppId());
+ for (ShellWindowList::const_reverse_iterator it = windows.rbegin();
+ it != windows.rend(); ++it) {
+ if (hidden)
+ (*it)->GetBaseWindow()->Hide();
+ else
+ (*it)->GetBaseWindow()->ShowInactive();
+ }
+}
+
void ExtensionAppShimHandler::OnShimQuit(Host* host) {
DCHECK(delegate_->ProfileExistsForPath(host->GetProfilePath()));
Profile* profile = delegate_->ProfileForPath(host->GetProfilePath());
diff --git a/apps/app_shim/extension_app_shim_handler_mac.h b/apps/app_shim/extension_app_shim_handler_mac.h
index 257fb39..c2b6e3c 100644
--- a/apps/app_shim/extension_app_shim_handler_mac.h
+++ b/apps/app_shim/extension_app_shim_handler_mac.h
@@ -64,6 +64,7 @@ class ExtensionAppShimHandler : public AppShimHandler,
virtual bool OnShimLaunch(Host* host, AppShimLaunchType launch_type) OVERRIDE;
virtual void OnShimClose(Host* host) OVERRIDE;
virtual void OnShimFocus(Host* host, AppShimFocusType focus_type) OVERRIDE;
+ virtual void OnShimSetHidden(Host* host, bool hidden) OVERRIDE;
virtual void OnShimQuit(Host* host) OVERRIDE;
// AppLifetimeMonitor::Observer overrides:
diff --git a/chrome/app/chrome_main_app_mode_mac.mm b/chrome/app/chrome_main_app_mode_mac.mm
index 812e985..ab970419 100644
--- a/chrome/app/chrome_main_app_mode_mac.mm
+++ b/chrome/app/chrome_main_app_mode_mac.mm
@@ -47,11 +47,10 @@ class AppShimController;
}
- (id)initWithController:(AppShimController*)controller;
-
- (BOOL)applicationOpenUntitledFile:(NSApplication *)app;
-
- (void)applicationWillBecomeActive:(NSNotification*)notification;
-
+- (void)applicationWillHide:(NSNotification*)notification;
+- (void)applicationWillUnhide:(NSNotification*)notification;
- (void)terminateNow;
@end
@@ -65,8 +64,9 @@ class AppShimController : public IPC::Listener {
// Connects to Chrome and sends a LaunchApp message.
void Init();
- // Sends a QuitApp message to Chrome.
- void QuitApp();
+ void SendSetAppHidden(bool hidden);
+
+ void SendQuitApp();
// Called when the app is activated, either by the user clicking on it in the
// dock or by Cmd+Tabbing to it.
@@ -123,7 +123,7 @@ void AppShimController::Init() {
[NSApp setDelegate:nsapp_delegate_];
}
-void AppShimController::QuitApp() {
+void AppShimController::SendQuitApp() {
channel_->Send(new AppShimHostMsg_QuitApp);
}
@@ -161,6 +161,10 @@ void AppShimController::ActivateApp(bool is_reopen) {
}
}
+void AppShimController::SendSetAppHidden(bool hidden) {
+ channel_->Send(new AppShimHostMsg_SetAppHidden(hidden));
+}
+
@implementation AppShimDelegate
- (id)initWithController:(AppShimController*)controller {
@@ -184,12 +188,20 @@ void AppShimController::ActivateApp(bool is_reopen) {
if (terminateNow_)
return NSTerminateNow;
- appShimController_->QuitApp();
+ appShimController_->SendQuitApp();
// Wait for the channel to close before terminating.
terminateRequested_ = YES;
return NSTerminateLater;
}
+- (void)applicationWillHide:(NSNotification*)notification {
+ appShimController_->SendSetAppHidden(true);
+}
+
+- (void)applicationWillUnhide:(NSNotification*)notification {
+ appShimController_->SendSetAppHidden(false);
+}
+
- (void)terminateNow {
if (terminateRequested_) {
[NSApp replyToApplicationShouldTerminate:NSTerminateNow];
diff --git a/chrome/browser/ui/app_list/app_list_service_mac.mm b/chrome/browser/ui/app_list/app_list_service_mac.mm
index b28d88a..f6435e5 100644
--- a/chrome/browser/ui/app_list/app_list_service_mac.mm
+++ b/chrome/browser/ui/app_list/app_list_service_mac.mm
@@ -72,6 +72,8 @@ class AppListServiceMac : public AppListServiceImpl,
virtual void OnShimClose(apps::AppShimHandler::Host* host) OVERRIDE;
virtual void OnShimFocus(apps::AppShimHandler::Host* host,
apps::AppShimFocusType focus_type) OVERRIDE;
+ virtual void OnShimSetHidden(apps::AppShimHandler::Host* host,
+ bool hidden) OVERRIDE;
virtual void OnShimQuit(apps::AppShimHandler::Host* host) OVERRIDE;
private:
@@ -338,6 +340,9 @@ void AppListServiceMac::OnShimFocus(apps::AppShimHandler::Host* host,
DismissAppList();
}
+void AppListServiceMac::OnShimSetHidden(apps::AppShimHandler::Host* host,
+ bool hidden) {}
+
void AppListServiceMac::OnShimQuit(apps::AppShimHandler::Host* host) {
DismissAppList();
}