summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authortapted@chromium.org <tapted@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-25 00:23:34 +0000
committertapted@chromium.org <tapted@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-25 00:23:34 +0000
commitc1dbcb178ba806f1c7b7e26e4e14deb85cb9b720 (patch)
tree0b1ceb20c77cfd9b02a364e3cbc02ed41f017504 /apps
parent0700471c72bca247109af0165d09173ce9c107c8 (diff)
downloadchromium_src-c1dbcb178ba806f1c7b7e26e4e14deb85cb9b720.zip
chromium_src-c1dbcb178ba806f1c7b7e26e4e14deb85cb9b720.tar.gz
chromium_src-c1dbcb178ba806f1c7b7e26e4e14deb85cb9b720.tar.bz2
Show an InfoBar when trying to start Packaged Apps from Metro mode.
Platform Apps do not function properly while in Metro mode. This change intercepts platform app launch requests done while the browser is in metro mode, redirecting them to an infobar. If "yes" is chosen, a local pref is stored with the extension id and Profile that tried to launch it, and a relaunch of Chrome in Desktop mode is triggered. Upon restart, apps::AppLaunchOnRestartService is responsible for launching the selected app, and clearing the pref. BUG=153426 TEST=With Chrome configured for Windows 8 mode, try to start a packaged app. This can be done from NTP (if launcher not enabled), or from a taskbar shortcut, a desktop shortcut, or a pinned start page tile. InfoBar should display offering to switch to Desktop mode. If switching, selected packaged app should launch after a brief delay. Review URL: https://chromiumcodereview.appspot.com/12450014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@190306 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'apps')
-rw-r--r--apps/DEPS1
-rw-r--r--apps/app_launch_for_metro_restart_win.cc95
-rw-r--r--apps/app_launch_for_metro_restart_win.h26
-rw-r--r--apps/apps.gypi12
-rw-r--r--apps/pref_names.cc9
-rw-r--r--apps/pref_names.h2
-rw-r--r--apps/prefs.cc5
7 files changed, 145 insertions, 5 deletions
diff --git a/apps/DEPS b/apps/DEPS
index df03f2b..fb10d13 100644
--- a/apps/DEPS
+++ b/apps/DEPS
@@ -2,6 +2,7 @@ include_rules = [
"+base",
"+content",
"+ui",
+ "+win8",
# Temporary allowed includes.
# TODO(benwells): remove these (http://crbug.com/159366)
"+chrome/browser/browser_process.h",
diff --git a/apps/app_launch_for_metro_restart_win.cc b/apps/app_launch_for_metro_restart_win.cc
new file mode 100644
index 0000000..1fa0cc9
--- /dev/null
+++ b/apps/app_launch_for_metro_restart_win.cc
@@ -0,0 +1,95 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "apps/app_launch_for_metro_restart_win.h"
+
+#include "apps/pref_names.h"
+#include "base/bind.h"
+#include "base/files/file_path.h"
+#include "base/message_loop.h"
+#include "base/prefs/pref_service.h"
+#include "base/time.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/extensions/api/app_runtime/app_runtime_api.h"
+#include "chrome/browser/extensions/extension_service.h"
+#include "chrome/browser/extensions/extension_system.h"
+#include "chrome/browser/extensions/platform_app_launcher.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/profiles/profile_manager.h"
+#include "win8/util/win8_util.h"
+
+using extensions::Extension;
+using extensions::ExtensionSystem;
+
+namespace apps {
+
+namespace {
+
+void LaunchAppWithId(Profile* profile,
+ const std::string& extension_id) {
+ ExtensionService* extension_service =
+ ExtensionSystem::Get(profile)->extension_service();
+ if (!extension_service)
+ return;
+
+ const Extension* extension =
+ extension_service->GetExtensionById(extension_id, false);
+ if (!extension)
+ return;
+
+ extensions::AppEventRouter::DispatchOnLaunchedEvent(profile, extension);
+}
+
+} // namespace
+
+void HandleAppLaunchForMetroRestart(Profile* profile) {
+ PrefService* prefs = g_browser_process->local_state();
+ if (!prefs->HasPrefPath(prefs::kAppLaunchForMetroRestartProfile))
+ return;
+
+ // This will be called for each profile that had a browser window open before
+ // relaunch. After checking that the preference is set, check that the
+ // profile that is starting up matches the profile that initially wanted to
+ // launch the app.
+ base::FilePath profile_dir = base::FilePath::FromUTF8Unsafe(
+ prefs->GetString(prefs::kAppLaunchForMetroRestartProfile));
+ if (profile_dir.empty() || profile->GetPath().BaseName() != profile_dir)
+ return;
+
+ prefs->ClearPref(prefs::kAppLaunchForMetroRestartProfile);
+
+ if (!prefs->HasPrefPath(prefs::kAppLaunchForMetroRestart))
+ return;
+
+ std::string extension_id = prefs->GetString(prefs::kAppLaunchForMetroRestart);
+ if (extension_id.empty())
+ return;
+
+ prefs->ClearPref(prefs::kAppLaunchForMetroRestart);
+
+ if (win8::IsSingleWindowMetroMode()) {
+ // In this case we have relaunched with the correct profile, but we are not
+ // in Desktop mode, so can not launch apps. Leave the preferences cleared so
+ // there are no surprises later.
+ return;
+ }
+
+ const int kRestartAppLaunchDelayMs = 1000;
+ MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ base::Bind(&LaunchAppWithId,
+ profile,
+ extension_id),
+ base::TimeDelta::FromMilliseconds(kRestartAppLaunchDelayMs));
+}
+
+void SetAppLaunchForMetroRestart(Profile* profile,
+ const std::string& extension_id) {
+ PrefService* prefs = g_browser_process->local_state();
+ prefs->SetString(prefs::kAppLaunchForMetroRestartProfile,
+ profile->GetPath().BaseName().MaybeAsASCII());
+ prefs->SetString(prefs::kAppLaunchForMetroRestart, extension_id);
+}
+
+} // namespace apps
diff --git a/apps/app_launch_for_metro_restart_win.h b/apps/app_launch_for_metro_restart_win.h
new file mode 100644
index 0000000..dfbd13e
--- /dev/null
+++ b/apps/app_launch_for_metro_restart_win.h
@@ -0,0 +1,26 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef APPS_APP_LAUNCH_FOR_METRO_RESTART_WIN_H
+#define APPS_APP_LAUNCH_FOR_METRO_RESTART_WIN_H
+
+#include <string>
+
+#include "base/basictypes.h"
+
+class Profile;
+
+namespace apps {
+
+// Handles launching apps on browser startup due to an attempt to launch an app
+// in Windows 8 Metro mode.
+void HandleAppLaunchForMetroRestart(Profile* profile);
+
+// Set a local pref to launch an app before relaunching chrome in desktop mode.
+void SetAppLaunchForMetroRestart(Profile* profile,
+ const std::string& extension_id);
+
+} // namespace apps
+
+#endif // APPS_APP_LAUNCH_FOR_METRO_RESTART_WIN_H
diff --git a/apps/apps.gypi b/apps/apps.gypi
index aa2330b..8760e17 100644
--- a/apps/apps.gypi
+++ b/apps/apps.gypi
@@ -1,4 +1,4 @@
-# Copyright (c) 2013 The Chromium Authors. All rights reserved.
+# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -22,16 +22,18 @@
'<(INTERMEDIATE_DIR)',
],
'sources': [
- 'app_shim/app_shim_host_mac.cc',
- 'app_shim/app_shim_host_mac.h',
- 'app_shim/app_shim_host_manager_mac.h',
- 'app_shim/app_shim_host_manager_mac.mm',
+ 'app_launch_for_metro_restart_win.cc',
+ 'app_launch_for_metro_restart_win.h',
'app_launcher.cc',
'app_launcher.h',
'app_restore_service.cc',
'app_restore_service.h',
'app_restore_service_factory.cc',
'app_restore_service_factory.h',
+ 'app_shim/app_shim_host_mac.cc',
+ 'app_shim/app_shim_host_mac.h',
+ 'app_shim/app_shim_host_manager_mac.h',
+ 'app_shim/app_shim_host_manager_mac.mm',
'pref_names.cc',
'pref_names.h',
'prefs.cc',
diff --git a/apps/pref_names.cc b/apps/pref_names.cc
index 15a33f9..d4ac6fa 100644
--- a/apps/pref_names.cc
+++ b/apps/pref_names.cc
@@ -12,6 +12,15 @@ namespace prefs {
const char kAppLauncherIsEnabled[] =
"apps.app_launcher.should_show_apps_page";
+// If set, the user requested to launch the app with this extension id while
+// in Metro mode, and then relaunched to Desktop mode to start it.
+const char kAppLaunchForMetroRestart[] = "apps.app_launch_for_metro_restart";
+
+// Set with |kAppLaunchForMetroRestart|, the profile whose loading triggers
+// launch of the specified app when restarting Chrome in desktop mode.
+const char kAppLaunchForMetroRestartProfile[] =
+ "apps.app_launch_for_metro_restart_profile";
+
} // namespace prefs
} // namespace apps
diff --git a/apps/pref_names.h b/apps/pref_names.h
index 90fc5d6..db6ad7c 100644
--- a/apps/pref_names.h
+++ b/apps/pref_names.h
@@ -11,6 +11,8 @@ namespace prefs {
// Alphabetical list of preference names specific to Apps component.
// Keep alphabetized and document each one in the source file.
extern const char kAppLauncherIsEnabled[];
+extern const char kAppLaunchForMetroRestart[];
+extern const char kAppLaunchForMetroRestartProfile[];
} // namespace prefs
} // namespace apps
diff --git a/apps/prefs.cc b/apps/prefs.cc
index b883fbb..edaf119 100644
--- a/apps/prefs.cc
+++ b/apps/prefs.cc
@@ -20,6 +20,11 @@ void RegisterPrefs(PrefRegistrySimple* registry) {
// GetIsAppLauncherEnabled().
registry->RegisterBooleanPref(prefs::kAppLauncherIsEnabled,
MaybeIsAppLauncherEnabled());
+
+#if defined(OS_WIN)
+ registry->RegisterStringPref(prefs::kAppLaunchForMetroRestart, "");
+ registry->RegisterStringPref(prefs::kAppLaunchForMetroRestartProfile, "");
+#endif
}
} // namespace apps