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

Add new AppLaunchInfo constructors to save chrome apps launch info.

Modify GetSessionIdForRestoreFromWebContents to return session id for
all browsers, because we need to save the window stack (z-order) for
all browser windows.

Modify web apps, and extension apps publishers to save app launch
information for system web apps, and platform apps, because the browser
session restore can't restore them.

For all other apps, no matter opened in tab, or window, the browser
session restore can restore them, so we don't need to save the app
launch information, we only save the browser session id as the window
id, to restore the browser windows, including window stack (z-order),
snap, etc.

The app ids for apps opened with browsers are saved as the chrome
browser's app id, because there could be multiple apps opened as tabs
in one browser, and we only need to save one browser window for them.
There will be separate CL to handle the chrome browser saving and
restoration.

BUG=1146900

Change-Id: I9f6d6675a7f7a39bd361f911d1c5cd22e898817e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2602038
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#840108}
parent c5868cd1
......@@ -318,6 +318,10 @@ content::WebContents* ExtensionAppsBase::LaunchAppWithIntentImpl(
return LaunchImpl(std::move(params));
}
content::WebContents* ExtensionAppsBase::LaunchImpl(AppLaunchParams&& params) {
return ::OpenApplication(profile_, std::move(params));
}
const extensions::Extension* ExtensionAppsBase::MaybeGetExtension(
const std::string& app_id) {
DCHECK(profile_);
......@@ -646,10 +650,6 @@ bool ExtensionAppsBase::RunExtensionEnableFlow(const std::string& app_id,
return true;
}
content::WebContents* ExtensionAppsBase::LaunchImpl(AppLaunchParams&& params) {
return ::OpenApplication(profile_, std::move(params));
}
// static
bool ExtensionAppsBase::ShouldShow(const extensions::Extension* extension,
Profile* profile) {
......
......@@ -84,6 +84,8 @@ class ExtensionAppsBase : public apps::PublisherBase,
apps::mojom::LaunchSource launch_source,
int64_t display_id);
virtual content::WebContents* LaunchImpl(AppLaunchParams&& params);
// Returns extensions::Extension* for the valid |app_id|. Otherwise, returns
// nullptr.
const extensions::Extension* MaybeGetExtension(const std::string& app_id);
......@@ -161,8 +163,6 @@ class ExtensionAppsBase : public apps::PublisherBase,
bool RunExtensionEnableFlow(const std::string& app_id,
base::OnceClosure callback);
content::WebContents* LaunchImpl(AppLaunchParams&& params);
virtual bool ShouldShownInLauncher(
const extensions::Extension* extension) = 0;
static bool ShouldShow(const extensions::Extension* extension,
......
......@@ -23,6 +23,7 @@
#include "base/values.h"
#include "chrome/browser/apps/app_service/app_icon_factory.h"
#include "chrome/browser/apps/app_service/app_service_metrics.h"
#include "chrome/browser/apps/app_service/launch_utils.h"
#include "chrome/browser/apps/app_service/menu_util.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/arc/arc_util.h"
......@@ -50,6 +51,8 @@
#include "chrome/common/pref_names.h"
#include "chrome/grit/generated_resources.h"
#include "components/arc/arc_service_manager.h"
#include "components/full_restore/app_launch_info.h"
#include "components/full_restore/full_restore_utils.h"
#include "components/policy/core/common/policy_pref_names.h"
#include "components/services/app_service/public/cpp/instance.h"
#include "components/services/app_service/public/cpp/intent_filter_util.h"
......@@ -692,4 +695,39 @@ void ExtensionAppsChromeOs::GetMenuModelForChromeBrowserApp(
std::move(callback).Run(std::move(menu_items));
}
content::WebContents* ExtensionAppsChromeOs::LaunchImpl(
AppLaunchParams&& params) {
AppLaunchParams params_for_restore(params.app_id, params.container,
params.disposition, params.display_id,
params.launch_files, params.intent);
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 {
// Save all launch information for platform apps, which can launch via
// event, e.g. file app.
launch_info = std::make_unique<full_restore::AppLaunchInfo>(
params_for_restore.app_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;
}
} // namespace apps
......@@ -148,6 +148,8 @@ class ExtensionAppsChromeOs : public ExtensionAppsBase,
void GetMenuModelForChromeBrowserApp(apps::mojom::MenuType menu_type,
GetMenuModelCallback callback);
content::WebContents* LaunchImpl(AppLaunchParams&& params) override;
apps::InstanceRegistry* instance_registry_;
ScopedObserver<extensions::AppWindowRegistry,
extensions::AppWindowRegistry::Observer>
......
......@@ -229,22 +229,16 @@ int GetEventFlags(apps::mojom::LaunchContainer container,
int GetSessionIdForRestoreFromWebContents(
apps::mojom::LaunchContainer container,
const content::WebContents* web_contents) {
if (web_contents == nullptr) {
if (!web_contents) {
return SessionID::InvalidValue().id();
}
Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
if (browser == nullptr) {
if (!browser) {
return SessionID::InvalidValue().id();
}
if ((browser->app_controller() &&
browser->app_controller()->is_for_system_web_app()) ||
container != apps::mojom::LaunchContainer::kLaunchContainerTab) {
return browser->session_id().id();
}
return SessionID::InvalidValue().id();
return browser->session_id().id();
}
} // namespace apps
......@@ -58,6 +58,7 @@
#include "components/sessions/core/session_id.h"
#include "content/public/browser/clear_site_data_utils.h"
#include "content/public/browser/web_contents.h"
#include "extensions/common/constants.h"
#include "ui/message_center/public/cpp/notification.h"
#include "url/origin.h"
......@@ -510,13 +511,29 @@ content::WebContents* WebAppsChromeOs::LaunchAppWithParams(
return web_contents;
}
full_restore::SaveAppLaunchInfo(
profile()->GetPath(),
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)));
const web_app::WebApp* web_app = GetWebApp(params_for_restore.app_id);
std::unique_ptr<full_restore::AppLaunchInfo> launch_info;
if (web_app && web_app->IsSystemApp()) {
// Save all launch information for system web apps, because the browser
// session restore can't restore system web apps.
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));
} 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));
return web_contents;
}
......
......@@ -23,6 +23,22 @@ AppLaunchInfo::AppLaunchInfo(const std::string& app_id,
file_paths(std::move(launch_files)),
intent(std::move(intent)) {}
AppLaunchInfo::AppLaunchInfo(const std::string& app_id, int32_t session_id)
: app_id(app_id), id(session_id) {}
AppLaunchInfo::AppLaunchInfo(const std::string& app_id,
apps::mojom::LaunchContainer container,
WindowOpenDisposition disposition,
int64_t display_id,
std::vector<base::FilePath> launch_files,
apps::mojom::IntentPtr intent)
: app_id(app_id),
container(static_cast<int32_t>(container)),
disposition(static_cast<int32_t>(disposition)),
display_id(display_id),
file_paths(std::move(launch_files)),
intent(std::move(intent)) {}
AppLaunchInfo::AppLaunchInfo(const std::string& app_id,
int32_t event_flags,
int64_t display_id)
......
......@@ -27,6 +27,15 @@ struct COMPONENT_EXPORT(FULL_RESTORE) AppLaunchInfo {
std::vector<base::FilePath> launch_files,
apps::mojom::IntentPtr intent);
AppLaunchInfo(const std::string& app_id, int32_t session_id);
AppLaunchInfo(const std::string& app_id,
apps::mojom::LaunchContainer container,
WindowOpenDisposition disposition,
int64_t display_id,
std::vector<base::FilePath> launch_files,
apps::mojom::IntentPtr intent);
AppLaunchInfo(const std::string& app_id,
int32_t event_flags,
int64_t display_id);
......
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