Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1914)

Unified Diff: apps/app_shim/extension_app_shim_handler_mac.cc

Issue 14579006: Start app shim when app launched. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comment Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..c3f65f176950e98ec510796ca145c3a5e1027445 100644
--- a/apps/app_shim/extension_app_shim_handler_mac.cc
+++ b/apps/app_shim/extension_app_shim_handler_mac.cc
@@ -13,11 +13,16 @@
#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/ui/web_applications/web_app_ui.h"
+#include "chrome/browser/web_applications/web_app_mac.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 +32,7 @@ ExtensionAppShimHandler::~ExtensionAppShimHandler() {
}
}
-bool ExtensionAppShimHandler::OnShimLaunch(Host* host) {
+bool ExtensionAppShimHandler::OnShimLaunch(Host* host, bool launch_now) {
Profile* profile = host->GetProfile();
DCHECK(profile);
@@ -37,13 +42,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 +88,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 +101,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 +119,34 @@ 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(
+ web_app::ShortcutInfoForExtensionAndProfile(extension, profile));
+}
+
void ExtensionAppShimHandler::CloseShim(Profile* profile,
const std::string& app_id) {
HostMap::const_iterator it = hosts_.find(make_pair(profile, app_id));

Powered by Google App Engine
This is Rietveld 408576698