Commit 57687533 authored by Nancy Wang's avatar Nancy Wang Committed by Chromium LUCI CQ

Save the launch parameters for restored system web apps.

The full restore calls BrowserAppLauncher::LaunchAppWithParams to
restore the system web apps:
https://source.chromium.org/chromium/chromium/src/+/master:chrome/browser/chromeos/full_restore/app_launch_handler.cc;l=210

So modify BrowserAppLauncher::LaunchAppWithParams to save the launch
parameters to prepare the full restore for the next reboot.

Modify ExtensionAppsChromeOs to save the launch parameters for platform
apps only. Modify WebAppsChromeOs to save the launch parameters for the
system web apps only. Because if the apps opened in tab or with browser,
the full restore component can get the info from the window property
kWindowIdKey, and Chrome session restore can restore browsers, so we
don't need to save the launch parameter.

BUG=1146900

Change-Id: I1231bcbc1d665918f5f6d7efbf19751387bf8ebb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2639346Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845536}
parent 842ceac0
......@@ -13,6 +13,13 @@
#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/apps/app_service/launch_utils.h"
#include "components/full_restore/app_launch_info.h"
#include "components/full_restore/full_restore_utils.h"
#include "components/sessions/core/session_id.h"
#endif
namespace apps {
BrowserAppLauncher::BrowserAppLauncher(Profile* profile)
......@@ -26,7 +33,38 @@ content::WebContents* BrowserAppLauncher::LaunchAppWithParams(
extensions::ExtensionRegistry::Get(profile_)->GetInstalledExtension(
params.app_id);
if (!extension || extension->from_bookmark()) {
#if BUILDFLAG(IS_CHROMEOS_ASH)
AppLaunchParams params_for_restore(
params.app_id, params.container, params.disposition, params.source,
params.display_id, params.launch_files, params.intent);
int restore_id = params.restore_id;
auto* web_contents =
web_app_launch_manager_.OpenApplication(std::move(params));
if (!SessionID::IsValidValue(restore_id)) {
return web_contents;
}
int session_id = GetSessionIdForRestoreFromWebContents(web_contents);
if (!SessionID::IsValidValue(session_id)) {
return web_contents;
}
// If the restore id is available, save the launch parameters to the full
// restore file for the system web apps.
auto launch_info = std::make_unique<full_restore::AppLaunchInfo>(
params_for_restore.app_id, session_id, params_for_restore.container,
params_for_restore.disposition, params_for_restore.display_id,
std::move(params_for_restore.launch_files),
std::move(params_for_restore.intent));
full_restore::SaveAppLaunchInfo(profile_->GetPath(),
std::move(launch_info));
return web_contents;
#else
return web_app_launch_manager_.OpenApplication(std::move(params));
#endif
}
if (params.container ==
......
......@@ -701,19 +701,8 @@ content::WebContents* ExtensionAppsChromeOs::LaunchImpl(
auto* web_contents = ExtensionAppsBase::LaunchImpl(std::move(params));
std::unique_ptr<full_restore::AppLaunchInfo> launch_info;
int session_id = GetSessionIdForRestoreFromWebContents(
params_for_restore.container, web_contents);
if (SessionID::IsValidValue(session_id)) {
// If the app is launched via browser, the browser session restore can
// restore the app after reboot, so we don't need to save the launch
// parameters to launch the app after reboot. Only the browser session id is
// saved as the window id, to restore the window stack, snap, etc. The app
// id is modified as the Chrome browser id, so that it won't be launched
// after reboot. Also for apps opened with tabs in one browser window, we
// don't need to save multiple records in the full restore data.
launch_info = std::make_unique<full_restore::AppLaunchInfo>(
extension_misc::kChromeAppId, session_id);
} else {
int session_id = GetSessionIdForRestoreFromWebContents(web_contents);
if (!SessionID::IsValidValue(session_id)) {
// Save all launch information for platform apps, which can launch via
// event, e.g. file app.
launch_info = std::make_unique<full_restore::AppLaunchInfo>(
......@@ -721,9 +710,10 @@ content::WebContents* ExtensionAppsChromeOs::LaunchImpl(
params_for_restore.disposition, params_for_restore.display_id,
std::move(params_for_restore.launch_files),
std::move(params_for_restore.intent));
full_restore::SaveAppLaunchInfo(profile()->GetPath(),
std::move(launch_info));
}
full_restore::SaveAppLaunchInfo(profile()->GetPath(), std::move(launch_info));
return web_contents;
}
......
......@@ -227,7 +227,6 @@ int GetEventFlags(apps::mojom::LaunchContainer container,
}
int GetSessionIdForRestoreFromWebContents(
apps::mojom::LaunchContainer container,
const content::WebContents* web_contents) {
if (!web_contents) {
return SessionID::InvalidValue().id();
......
......@@ -74,7 +74,6 @@ int GetEventFlags(apps::mojom::LaunchContainer container,
// for a system web app, or for a web app not opened in tab. Otherwise, returns
// an invalid session id.
int GetSessionIdForRestoreFromWebContents(
apps::mojom::LaunchContainer container,
const content::WebContents* web_contents);
} // namespace apps
......
......@@ -613,8 +613,7 @@ content::WebContents* WebAppsChromeOs::LaunchAppWithParams(
auto* web_contents = WebAppsBase::LaunchAppWithParams(std::move(params));
int session_id = GetSessionIdForRestoreFromWebContents(
params_for_restore.container, web_contents);
int session_id = GetSessionIdForRestoreFromWebContents(web_contents);
if (!SessionID::IsValidValue(session_id)) {
return web_contents;
}
......@@ -629,19 +628,10 @@ content::WebContents* WebAppsChromeOs::LaunchAppWithParams(
params_for_restore.disposition, params_for_restore.display_id,
std::move(params_for_restore.launch_files),
std::move(params_for_restore.intent));
} else {
// If the app is not a system web app, the browser session restore can
// restore the app after reboot, so we don't need to save the launch
// parameters to launch the app after reboot. Only the browser session id is
// saved as the window id, to restore the window stack, snap, etc. The app
// id is modified as the Chrome browser id, so that it won't be launched
// after reboot. Also for web apps opened with tabs in one browser window,
// we don't need to save multiple records in the full restore data.
launch_info = std::make_unique<full_restore::AppLaunchInfo>(
extension_misc::kChromeAppId, session_id);
full_restore::SaveAppLaunchInfo(profile()->GetPath(),
std::move(launch_info));
}
full_restore::SaveAppLaunchInfo(profile()->GetPath(), std::move(launch_info));
return web_contents;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment