forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
tapted@chromium.org
committed
Mar 25, 2013
1 parent
0700471
commit c1dbcb1
Showing
14 changed files
with
237 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.