summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorjackhou@chromium.org <jackhou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-29 10:01:51 +0000
committerjackhou@chromium.org <jackhou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-29 10:01:51 +0000
commita39dcb42c9cc46fa6598744d043f3461c542d967 (patch)
treee4319f455404b21c725e4d1f50b05775a19f3236 /apps
parent21b91ac7a95a94d77d8e0c91ce51387e4218bee0 (diff)
downloadchromium_src-a39dcb42c9cc46fa6598744d043f3461c542d967.zip
chromium_src-a39dcb42c9cc46fa6598744d043f3461c542d967.tar.gz
chromium_src-a39dcb42c9cc46fa6598744d043f3461c542d967.tar.bz2
Differentiate windows hidden by AppWindow.hide API and Mac-style Hide/Show.
Windows hidden by AppWindow.hide will not be shown when the app is unhidden. Similarly, when AppWindow.show is called in a hidden app, the app is unhidden. BUG=257537 TEST=Open a packaged app that hides windows using AppWindow.hide. Right click the dock icon and select Hide, then Show. Only the windows that were visible should be shown. Windows hidden with AppWindow.hide should stay hidden. Review URL: https://chromiumcodereview.appspot.com/18758002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@220253 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'apps')
-rw-r--r--apps/app_shim/app_shim_handler_mac.h2
-rw-r--r--apps/app_shim/app_shim_host_mac.cc4
-rw-r--r--apps/app_shim/app_shim_host_mac.h1
-rw-r--r--apps/app_shim/app_shim_messages.h3
-rw-r--r--apps/app_shim/app_shim_quit_interactive_uitest_mac.mm1
-rw-r--r--apps/app_shim/chrome_main_app_mode_mac.mm8
-rw-r--r--apps/app_shim/extension_app_shim_handler_mac.cc46
-rw-r--r--apps/app_shim/extension_app_shim_handler_mac.h6
-rw-r--r--apps/app_shim/extension_app_shim_handler_mac_unittest.cc1
-rw-r--r--apps/native_app_window.h6
10 files changed, 67 insertions, 11 deletions
diff --git a/apps/app_shim/app_shim_handler_mac.h b/apps/app_shim/app_shim_handler_mac.h
index aba7a1c..bb908f9 100644
--- a/apps/app_shim/app_shim_handler_mac.h
+++ b/apps/app_shim/app_shim_handler_mac.h
@@ -24,6 +24,8 @@ class AppShimHandler {
virtual void OnAppLaunchComplete(AppShimLaunchResult result) = 0;
// Invoked when the app is closed in the browser process.
virtual void OnAppClosed() = 0;
+ // Invoked when the app is requesting user attention.
+ virtual void OnAppRequestUserAttention() = 0;
// Allows the handler to determine which app this host corresponds to.
virtual base::FilePath GetProfilePath() const = 0;
diff --git a/apps/app_shim/app_shim_host_mac.cc b/apps/app_shim/app_shim_host_mac.cc
index 72840c7..aba1a58 100644
--- a/apps/app_shim/app_shim_host_mac.cc
+++ b/apps/app_shim/app_shim_host_mac.cc
@@ -114,6 +114,10 @@ void AppShimHost::OnAppClosed() {
Close();
}
+void AppShimHost::OnAppRequestUserAttention() {
+ Send(new AppShimMsg_RequestUserAttention);
+}
+
void AppShimHost::Close() {
DCHECK(CalledOnValidThread());
delete this;
diff --git a/apps/app_shim/app_shim_host_mac.h b/apps/app_shim/app_shim_host_mac.h
index 2bed7f1..9c3c948 100644
--- a/apps/app_shim/app_shim_host_mac.h
+++ b/apps/app_shim/app_shim_host_mac.h
@@ -65,6 +65,7 @@ class AppShimHost : public IPC::Listener,
// apps::AppShimHandler::Host overrides:
virtual void OnAppLaunchComplete(apps::AppShimLaunchResult result) OVERRIDE;
virtual void OnAppClosed() OVERRIDE;
+ virtual void OnAppRequestUserAttention() OVERRIDE;
virtual base::FilePath GetProfilePath() const OVERRIDE;
virtual std::string GetAppId() const OVERRIDE;
diff --git a/apps/app_shim/app_shim_messages.h b/apps/app_shim/app_shim_messages.h
index 85a1df3..e0fd299 100644
--- a/apps/app_shim/app_shim_messages.h
+++ b/apps/app_shim/app_shim_messages.h
@@ -25,6 +25,9 @@ IPC_ENUM_TRAITS_MAX_VALUE(apps::AppShimFocusType,
IPC_MESSAGE_CONTROL1(AppShimMsg_LaunchApp_Done,
apps::AppShimLaunchResult /* launch result */)
+// Instructs the shim to request user attention.
+IPC_MESSAGE_CONTROL0(AppShimMsg_RequestUserAttention)
+
// Signals to the main Chrome process that a shim has started indicating the
// profile and app_id that the shim should be associated with and whether to
// launch the app immediately.
diff --git a/apps/app_shim/app_shim_quit_interactive_uitest_mac.mm b/apps/app_shim/app_shim_quit_interactive_uitest_mac.mm
index 5b5dad6..4a74457 100644
--- a/apps/app_shim/app_shim_quit_interactive_uitest_mac.mm
+++ b/apps/app_shim/app_shim_quit_interactive_uitest_mac.mm
@@ -39,6 +39,7 @@ class FakeHost : public apps::AppShimHandler::Host {
virtual void OnAppClosed() OVERRIDE {
handler_->OnShimClose(this);
}
+ virtual void OnAppRequestUserAttention() OVERRIDE {}
virtual base::FilePath GetProfilePath() const OVERRIDE {
return profile_path_;
}
diff --git a/apps/app_shim/chrome_main_app_mode_mac.mm b/apps/app_shim/chrome_main_app_mode_mac.mm
index 773bd8d..96b947d 100644
--- a/apps/app_shim/chrome_main_app_mode_mac.mm
+++ b/apps/app_shim/chrome_main_app_mode_mac.mm
@@ -89,6 +89,9 @@ class AppShimController : public IPC::Listener {
// shim process should die.
void OnLaunchAppDone(apps::AppShimLaunchResult result);
+ // Requests user attention.
+ void OnRequestUserAttention();
+
// Terminates the app shim process.
void Close();
@@ -174,6 +177,7 @@ bool AppShimController::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(AppShimController, message)
IPC_MESSAGE_HANDLER(AppShimMsg_LaunchApp_Done, OnLaunchAppDone)
+ IPC_MESSAGE_HANDLER(AppShimMsg_RequestUserAttention, OnRequestUserAttention)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
@@ -193,6 +197,10 @@ void AppShimController::OnLaunchAppDone(apps::AppShimLaunchResult result) {
launch_app_done_ = true;
}
+void AppShimController::OnRequestUserAttention() {
+ [NSApp requestUserAttention:NSInformationalRequest];
+}
+
void AppShimController::Close() {
[nsapp_delegate_ terminateNow];
}
diff --git a/apps/app_shim/extension_app_shim_handler_mac.cc b/apps/app_shim/extension_app_shim_handler_mac.cc
index f794230..a45eccb 100644
--- a/apps/app_shim/extension_app_shim_handler_mac.cc
+++ b/apps/app_shim/extension_app_shim_handler_mac.cc
@@ -32,6 +32,8 @@
namespace {
+typedef apps::ShellWindowRegistry::ShellWindowList ShellWindowList;
+
void ProfileLoadedCallback(base::Callback<void(Profile*)> callback,
Profile* profile,
Profile::CreateStatus status) {
@@ -51,12 +53,22 @@ void TerminateIfNoShellWindows() {
chrome::AttemptExit();
}
+void SetAppHidden(Profile* profile, const std::string& app_id, bool hidden) {
+ ShellWindowList windows =
+ apps::ShellWindowRegistry::Get(profile)->GetShellWindowsForApp(app_id);
+ for (ShellWindowList::const_reverse_iterator it = windows.rbegin();
+ it != windows.rend(); ++it) {
+ if (hidden)
+ (*it)->GetBaseWindow()->HideWithApp();
+ else
+ (*it)->GetBaseWindow()->ShowWithApp();
+ }
+}
+
} // namespace
namespace apps {
-typedef ShellWindowRegistry::ShellWindowList ShellWindowList;
-
bool ExtensionAppShimHandler::Delegate::ProfileExistsForPath(
const base::FilePath& path) {
ProfileManager* profile_manager = g_browser_process->profile_manager();
@@ -171,6 +183,26 @@ void ExtensionAppShimHandler::QuitAppForWindow(ShellWindow* shell_window) {
}
}
+// static
+bool ExtensionAppShimHandler::RequestUserAttentionForWindow(
+ ShellWindow* shell_window) {
+ ExtensionAppShimHandler* handler =
+ g_browser_process->platform_part()->app_shim_host_manager()->
+ extension_app_shim_handler();
+ Profile* profile = shell_window->profile();
+ Host* host = handler->FindHost(profile, shell_window->extension_id());
+ if (host) {
+ // Bring the window to the front without showing it.
+ ShellWindowRegistry::Get(profile)->ShellWindowActivated(shell_window);
+ host->OnAppRequestUserAttention();
+ return true;
+ } else {
+ // Just show the app.
+ SetAppHidden(profile, shell_window->extension_id(), false);
+ return false;
+ }
+}
+
void ExtensionAppShimHandler::OnShimLaunch(Host* host,
AppShimLaunchType launch_type) {
const std::string& app_id = host->GetAppId();
@@ -286,15 +318,7 @@ 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();
- }
+ SetAppHidden(profile, host->GetAppId(), hidden);
}
void ExtensionAppShimHandler::OnShimQuit(Host* host) {
diff --git a/apps/app_shim/extension_app_shim_handler_mac.h b/apps/app_shim/extension_app_shim_handler_mac.h
index 8a9f64e..f707232 100644
--- a/apps/app_shim/extension_app_shim_handler_mac.h
+++ b/apps/app_shim/extension_app_shim_handler_mac.h
@@ -32,6 +32,8 @@ class Extension;
namespace apps {
+class ShellWindow;
+
// This app shim handler that handles events for app shims that correspond to an
// extension.
class ExtensionAppShimHandler : public AppShimHandler,
@@ -67,6 +69,10 @@ class ExtensionAppShimHandler : public AppShimHandler,
static void QuitAppForWindow(ShellWindow* shell_window);
+ // Brings the window to the front without showing it and instructs the shim to
+ // request user attention. Returns false if there is no shim for this window.
+ static bool RequestUserAttentionForWindow(ShellWindow* shell_window);
+
// AppShimHandler overrides:
virtual void OnShimLaunch(Host* host, AppShimLaunchType launch_type) OVERRIDE;
virtual void OnShimClose(Host* host) OVERRIDE;
diff --git a/apps/app_shim/extension_app_shim_handler_mac_unittest.cc b/apps/app_shim/extension_app_shim_handler_mac_unittest.cc
index 08fbc47..c51a017a 100644
--- a/apps/app_shim/extension_app_shim_handler_mac_unittest.cc
+++ b/apps/app_shim/extension_app_shim_handler_mac_unittest.cc
@@ -102,6 +102,7 @@ class FakeHost : public apps::AppShimHandler::Host {
handler_->OnShimClose(this);
++close_count_;
}
+ virtual void OnAppRequestUserAttention() OVERRIDE {}
virtual base::FilePath GetProfilePath() const OVERRIDE {
return profile_path_;
}
diff --git a/apps/native_app_window.h b/apps/native_app_window.h
index fcad3ce..9a1e05b 100644
--- a/apps/native_app_window.h
+++ b/apps/native_app_window.h
@@ -51,6 +51,12 @@ class NativeAppWindow : public ui::BaseWindow,
// borders) and the content bounds, if any.
virtual gfx::Insets GetFrameInsets() const = 0;
+ // Hide or show this window as part of hiding or showing the app.
+ // This may have different logic to Hide, Show, and ShowInactive as those are
+ // called via the AppWindow javascript API.
+ virtual void ShowWithApp() = 0;
+ virtual void HideWithApp() = 0;
+
virtual ~NativeAppWindow() {}
};