| Index: apps/app_shim/extension_app_shim_handler_mac.cc
|
| diff --git a/apps/app_shim/extension_app_shim_handler_mac.cc b/apps/app_shim/extension_app_shim_handler_mac.cc
|
| index 9d31d694c01b0108da1fbd655424b845b69e8ccd..d107f2b0fb105d7611327fc7306777938e2554df 100644
|
| --- a/apps/app_shim/extension_app_shim_handler_mac.cc
|
| +++ b/apps/app_shim/extension_app_shim_handler_mac.cc
|
| @@ -13,11 +13,15 @@
|
| #include "chrome/browser/extensions/shell_window_registry.h"
|
| #include "chrome/browser/ui/extensions/application_launch.h"
|
| #include "chrome/browser/ui/extensions/shell_window.h"
|
| +#include "chrome/browser/web_applications/web_app.h"
|
| #include "ui/base/cocoa/focus_window_set.h"
|
|
|
| namespace apps {
|
|
|
| -ExtensionAppShimHandler::ExtensionAppShimHandler() {}
|
| +ExtensionAppShimHandler::ExtensionAppShimHandler() {
|
| + registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_CREATED,
|
| + content::NotificationService::AllBrowserContextsAndSources());
|
| +}
|
|
|
| ExtensionAppShimHandler::~ExtensionAppShimHandler() {
|
| for (HostMap::iterator it = hosts_.begin(); it != hosts_.end(); ) {
|
| @@ -27,7 +31,7 @@ ExtensionAppShimHandler::~ExtensionAppShimHandler() {
|
| }
|
| }
|
|
|
| -bool ExtensionAppShimHandler::OnShimLaunch(Host* host) {
|
| +bool ExtensionAppShimHandler::OnShimLaunch(Host* host, bool launch_now) {
|
| Profile* profile = host->GetProfile();
|
| DCHECK(profile);
|
|
|
| @@ -37,13 +41,15 @@ bool ExtensionAppShimHandler::OnShimLaunch(Host* host) {
|
| return false;
|
| }
|
|
|
| - if (!LaunchApp(profile, app_id))
|
| + if (!LaunchApp(profile, app_id, launch_now))
|
| return false;
|
|
|
| // The first host to claim this (profile, app_id) becomes the main host.
|
| - // For any others, we launch the app but return false.
|
| - if (!hosts_.insert(make_pair(make_pair(profile, app_id), host)).second)
|
| + // For any others, we focus the app and return false.
|
| + if (!hosts_.insert(make_pair(make_pair(profile, app_id), host)).second) {
|
| + OnShimFocus(host);
|
| return false;
|
| + }
|
|
|
| if (!registrar_.IsRegistered(
|
| this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
|
| @@ -81,7 +87,8 @@ void ExtensionAppShimHandler::OnShimFocus(Host* host) {
|
| }
|
|
|
| bool ExtensionAppShimHandler::LaunchApp(Profile* profile,
|
| - const std::string& app_id) {
|
| + const std::string& app_id,
|
| + bool launch_now) {
|
| extensions::ExtensionSystem* extension_system =
|
| extensions::ExtensionSystem::Get(profile);
|
| ExtensionServiceInterface* extension_service =
|
| @@ -93,6 +100,10 @@ bool ExtensionAppShimHandler::LaunchApp(Profile* profile,
|
| << app_id << "'.";
|
| return false;
|
| }
|
| +
|
| + if (!launch_now)
|
| + return true;
|
| +
|
| // TODO(jeremya): Handle the case that launching the app fails. Probably we
|
| // need to watch for 'app successfully launched' or at least 'background page
|
| // exists/was created' and time out with failure if we don't see that sign of
|
| @@ -107,19 +118,33 @@ void ExtensionAppShimHandler::Observe(
|
| const content::NotificationSource& source,
|
| const content::NotificationDetails& details) {
|
| Profile* profile = content::Source<Profile>(source).ptr();
|
| + extensions::ExtensionHost* extension_host =
|
| + content::Details<extensions::ExtensionHost>(details).ptr();
|
| switch (type) {
|
| - case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED: {
|
| - extensions::ExtensionHost* extension_host =
|
| - content::Details<extensions::ExtensionHost>(details).ptr();
|
| + case chrome::NOTIFICATION_EXTENSION_HOST_CREATED:
|
| + StartShim(profile, extension_host->extension());
|
| + break;
|
| + case chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED:
|
| CloseShim(profile, extension_host->extension_id());
|
| break;
|
| - }
|
| default:
|
| NOTREACHED(); // Unexpected notification.
|
| break;
|
| }
|
| }
|
|
|
| +void ExtensionAppShimHandler::StartShim(
|
| + Profile* profile,
|
| + const extensions::Extension* extension) {
|
| + if (!extension->is_platform_app())
|
| + return;
|
| +
|
| + if (hosts_.count(make_pair(profile, extension->id())))
|
| + return;
|
| +
|
| + web_app::MaybeLaunchShortcut(profile, extension);
|
| +}
|
| +
|
| void ExtensionAppShimHandler::CloseShim(Profile* profile,
|
| const std::string& app_id) {
|
| HostMap::const_iterator it = hosts_.find(make_pair(profile, app_id));
|
|
|