Commit 26b2bfbf authored by Jason Lin's avatar Jason Lin Committed by Commit Bot

[System Web Apps] Add util function CreateSystemWebAppLaunchParams()

This function is splited from LaunchSystemWebApp. It makes it easier for
power users (e.g. terminal settings) to customize launch behavior.

Bug: 1048451
Change-Id: I855faea6f264204953f7fbcaf1cee0e117d76845
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2050048
Commit-Queue: Jason Lin <lxj@google.com>
Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Reviewed-by: default avatarJoel Hockey <joelhockey@chromium.org>
Reviewed-by: default avatarcalamity <calamity@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742047}
parent 78e2bc9c
......@@ -4,6 +4,7 @@
#include "chrome/browser/chromeos/crostini/crostini_terminal.h"
#include "chrome/browser/apps/app_service/app_launch_params.h"
#include "chrome/browser/chromeos/crostini/crostini_util.h"
#include "chrome/browser/extensions/api/terminal/terminal_extension_helper.h"
#include "chrome/browser/ui/ash/window_properties.h"
......@@ -17,6 +18,7 @@
#include "chrome/common/webui_url_constants.h"
#include "chrome/grit/chrome_unscaled_resources.h"
#include "net/base/escape.h"
#include "ui/base/window_open_disposition.h"
namespace crostini {
......@@ -104,10 +106,14 @@ void LaunchContainerTerminal(Profile* profile,
void LaunchTerminalSettings(Profile* profile) {
DCHECK(base::FeatureList::IsEnabled(features::kTerminalSystemApp));
auto params = web_app::CreateSystemWebAppLaunchParams(
profile, web_app::SystemAppType::TERMINAL);
// Use an app pop window to host the settings page.
params->disposition = WindowOpenDisposition::NEW_POPUP;
web_app::LaunchSystemWebApp(profile, web_app::SystemAppType::TERMINAL,
GURL(std::string(chrome::kChromeUITerminalURL) +
"html/terminal_settings.html"),
/*is_popup=*/true);
*params);
}
} // namespace crostini
......@@ -70,7 +70,7 @@ void SettingsWindowManager::ShowChromePageForProfile(Profile* profile,
if (web_app::SystemWebAppManager::IsEnabled()) {
bool did_create;
Browser* browser = web_app::LaunchSystemWebApp(
profile, web_app::SystemAppType::SETTINGS, gurl, false, &did_create);
profile, web_app::SystemAppType::SETTINGS, gurl, &did_create);
ShowSettingsOnCurrentDesktop(browser);
// Only notify if we created a new browser.
if (!did_create || !browser)
......
......@@ -12,6 +12,7 @@
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/memory/ref_counted_memory.h"
#include "base/optional.h"
#include "base/strings/string16.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
......@@ -61,18 +62,13 @@ base::Optional<AppId> GetAppIdForSystemWebApp(Profile* profile,
: base::Optional<AppId>();
}
Browser* LaunchSystemWebApp(Profile* profile,
SystemAppType app_type,
const GURL& url,
bool is_popup,
bool* did_create) {
if (did_create)
*did_create = false;
base::Optional<apps::AppLaunchParams> CreateSystemWebAppLaunchParams(
Profile* profile,
SystemAppType app_type) {
base::Optional<AppId> app_id = GetAppIdForSystemWebApp(profile, app_type);
// TODO(calamity): Queue a task to launch app after it is installed.
// TODO(calamity): Decide whether to report app launch failure or CHECK fail.
if (!app_id)
return nullptr;
return base::nullopt;
auto* provider = WebAppProvider::Get(profile);
DCHECK(provider);
......@@ -86,11 +82,24 @@ Browser* LaunchSystemWebApp(Profile* profile,
apps::mojom::AppLaunchSource::kSourceChromeInternal,
display::kInvalidDisplayId, /*fallback_container=*/
ConvertDisplayModeToAppLaunchContainer(display_mode));
if (is_popup)
params.disposition = WindowOpenDisposition::NEW_POPUP;
params.override_url = url;
return LaunchSystemWebApp(profile, app_type, url, params, did_create);
return params;
}
Browser* LaunchSystemWebApp(Profile* profile,
SystemAppType app_type,
const GURL& url,
bool* did_create) {
if (did_create)
*did_create = false;
base::Optional<apps::AppLaunchParams> params =
CreateSystemWebAppLaunchParams(profile, app_type);
if (!params)
return nullptr;
params->override_url = url;
return LaunchSystemWebApp(profile, app_type, url, *params, did_create);
}
namespace {
......
......@@ -30,6 +30,10 @@ base::Optional<SystemAppType> GetSystemWebAppTypeForAppId(Profile* profile,
base::Optional<AppId> GetAppIdForSystemWebApp(Profile* profile,
SystemAppType app_type);
base::Optional<apps::AppLaunchParams> CreateSystemWebAppLaunchParams(
Profile* profile,
SystemAppType app_type);
// Launches a System App to the given URL, reusing any existing window for the
// app. Returns the browser for the System App, or nullptr if launch/focus
// failed. |did_create| will reflect whether a new window was created if passed.
......@@ -39,7 +43,6 @@ base::Optional<AppId> GetAppIdForSystemWebApp(Profile* profile,
Browser* LaunchSystemWebApp(Profile* profile,
SystemAppType app_type,
const GURL& url = GURL(),
bool is_popup = false,
bool* did_create = nullptr);
Browser* LaunchSystemWebApp(Profile* profile,
SystemAppType app_type,
......
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