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

Set the restore id for browser windows.

Add the restore_id to AppLaunchParams and browser::CreateParams, to
set the id from the restore data as the window's property:
kRestoreWindowIdKey, for the full restore to restore browser windows.

Modify the web app interface CreateWebApplicationWindow to pass the
restore id to the browser class.

BUG=1146900

Change-Id: Ia9c88a7f3eddcd0d984d555c6cd15a9351fa5248
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2599650
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841310}
parent cf817e13
......@@ -62,6 +62,9 @@ struct AppLaunchParams {
// If non-empty, use override_app_name in place of generating one normally.
std::string override_app_name;
// The id from the restore data to restore the browser window.
int32_t restore_id = 0;
// If non-empty, information from the command line may be passed on to the
// application.
base::CommandLine command_line;
......
......@@ -179,6 +179,7 @@ void AppLaunchHandler::LaunchWebAppOrExtension(
it.second->file_paths.has_value() ? it.second->file_paths.value()
: std::vector<base::FilePath>{},
it.second->intent.has_value() ? it.second->intent.value() : intent);
params.restore_id = it.first;
launcher->LaunchAppWithParams(std::move(params));
}
}
......
......@@ -246,6 +246,11 @@ class Browser : public TabStripModelObserver,
bool is_session_restore = false;
#if BUILDFLAG(IS_CHROMEOS_ASH)
// The id from the restore data to restore the browser window.
int32_t restore_id = 0;
#endif
bool is_focus_mode = false;
// Whether this browser was created by a user gesture. We track this
......
......@@ -85,6 +85,9 @@ void BrowserFrame::InitBrowserFrame() {
#if BUILDFLAG(IS_CHROMEOS_ASH)
params.init_properties_container.SetProperty(
full_restore::kWindowIdKey, browser_view_->browser()->session_id().id());
params.init_properties_container.SetProperty(
full_restore::kRestoreWindowIdKey,
browser_view_->browser()->create_params().restore_id);
#endif
if (browser_view_->browser()->is_type_normal() ||
browser_view_->browser()->is_type_devtools() ||
......
......@@ -241,8 +241,9 @@ Browser* LaunchSystemWebApp(Profile* profile,
content::WebContents* web_contents = nullptr;
if (!browser) {
browser = CreateWebApplicationWindow(profile_for_launch, params->app_id,
params->disposition);
browser =
CreateWebApplicationWindow(profile_for_launch, params->app_id,
params->disposition, params->restore_id);
}
// Navigate application window to application's |url| if necessary.
......
......@@ -1212,7 +1212,7 @@ IN_PROC_BROWSER_TEST_F(WebAppBrowserTest, PopupLocationBar) {
const AppId app_id = InstallPWA(app_url);
Browser* const popup_browser = web_app::CreateWebApplicationWindow(
profile(), app_id, WindowOpenDisposition::NEW_POPUP);
profile(), app_id, WindowOpenDisposition::NEW_POPUP, /*restore_id=*/0);
EXPECT_TRUE(
popup_browser->CanSupportWindowFeature(Browser::FEATURE_LOCATIONBAR));
......
......@@ -104,7 +104,8 @@ GURL GetLaunchUrl(WebAppProvider& provider,
Browser* CreateWebApplicationWindow(Profile* profile,
const std::string& app_id,
WindowOpenDisposition disposition) {
WindowOpenDisposition disposition,
int32_t restore_id) {
std::string app_name = GenerateApplicationNameFromAppId(app_id);
gfx::Rect initial_bounds;
Browser::CreateParams browser_params =
......@@ -116,6 +117,9 @@ Browser* CreateWebApplicationWindow(Profile* profile,
app_name, /*trusted_source=*/true, initial_bounds, profile,
/*user_gesture=*/true);
browser_params.initial_show_state = DetermineWindowShowState();
#if BUILDFLAG(IS_CHROMEOS_ASH)
browser_params.restore_id = restore_id;
#endif
return Browser::Create(browser_params);
}
......@@ -192,8 +196,8 @@ content::WebContents* WebAppLaunchManager::OpenApplication(
}
}
if (!browser) {
browser = CreateWebApplicationWindow(profile_, params.app_id,
params.disposition);
browser = CreateWebApplicationWindow(
profile_, params.app_id, params.disposition, params.restore_id);
}
}
......
......@@ -74,7 +74,8 @@ class WebAppLaunchManager {
Browser* CreateWebApplicationWindow(Profile* profile,
const std::string& app_id,
WindowOpenDisposition disposition);
WindowOpenDisposition disposition,
int32_t restore_id);
content::WebContents* NavigateWebApplicationWindow(
Browser* browser,
......
......@@ -15,6 +15,7 @@
namespace full_restore {
DEFINE_UI_CLASS_PROPERTY_KEY(int32_t, kWindowIdKey, 0)
DEFINE_UI_CLASS_PROPERTY_KEY(int32_t, kRestoreWindowIdKey, 0)
void SaveAppLaunchInfo(const base::FilePath& profile_dir,
std::unique_ptr<AppLaunchInfo> app_launch_info) {
......
......@@ -29,6 +29,10 @@ struct WindowInfo;
COMPONENT_EXPORT(FULL_RESTORE)
extern const ui::ClassProperty<int32_t>* const kWindowIdKey;
// A property key to indicate the restore id for the window from RestoreData.
COMPONENT_EXPORT(FULL_RESTORE)
extern const ui::ClassProperty<int32_t>* const kRestoreWindowIdKey;
// Saves the app launch parameters to the full restore file.
COMPONENT_EXPORT(FULL_RESTORE)
void SaveAppLaunchInfo(const base::FilePath& profile_dir,
......
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