Commit c54e521e authored by Rahul Singh's avatar Rahul Singh Committed by Commit Bot

desktop-pwas: Create mechanism for OS shortcuts menu to add params into

the app's launch url

This CL fixes an issue where clicking an item in a PWA's shortcuts menu
always navigates to the PWA's start_url.

To fix this, it adds a new command line switch. When registering the
shortcuts menu with the OS, it uses this switch to pass the shortcut url
as a command line argument.

In WebAppLaunchManager, when kDesktopPWAsAppIconShortcutsMenu is
enabled, it sets AppLaunchParams' override_url member to the switch's
value i.e. the shortcut url.

Note: The shortcut url that the switch is set to in the shortcuts menu
registration code has the same origin as the app's start_url. This is
validated as part of web app manifest parsing.

I verified that this fix works with Extensions based as well as WebApp
based PWAs.

Bug: 955497
Change-Id: Ib6360b16fe976e7e498bd783cf44911fe8c75b7f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2213344
Commit-Queue: Rahul Singh <rahsin@microsoft.com>
Reviewed-by: default avatarDavid Bienvenu <davidbienvenu@chromium.org>
Reviewed-by: default avatarAlexey Baskakov <loyso@chromium.org>
Reviewed-by: default avatarAlan Cutter <alancutter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#772441}
parent ad0719c9
......@@ -4,6 +4,9 @@
#include "chrome/browser/ui/web_applications/web_app_launch_manager.h"
#include <string>
#include <utility>
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/metrics/histogram_macros.h"
......@@ -32,6 +35,8 @@
#include "chrome/browser/web_applications/web_app_registrar.h"
#include "chrome/browser/web_applications/web_app_tab_helper.h"
#include "chrome/browser/web_launch/web_launch_files_helper.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_switches.h"
#include "content/public/browser/page_navigator.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
......@@ -242,6 +247,11 @@ void WebAppLaunchManager::LaunchApplication(
params.command_line = command_line;
params.current_directory = current_directory;
params.launch_files = apps::GetLaunchFilesFromCommandLine(command_line);
if (base::FeatureList::IsEnabled(
features::kDesktopPWAsAppIconShortcutsMenu)) {
params.override_url = GURL(command_line.GetSwitchValueASCII(
switches::kAppLaunchUrlForShortcutsMenuItem));
}
// Wait for the web applications database to load.
// If the profile and WebAppLaunchManager are destroyed,
......
......@@ -169,12 +169,13 @@ void RegisterShortcutsMenuWithOsTask(
// Set switches to launch shortcut items in the specified app.
shortcut_link->GetCommandLine()->AppendSwitchASCII(switches::kAppId,
app_id);
shortcut_link->GetCommandLine()->AppendArgNative(
base::UTF8ToUTF16(shortcuts[i].url.spec()));
shortcut_link->GetCommandLine()->AppendSwitchASCII(
switches::kAppLaunchUrlForShortcutsMenuItem, shortcuts[i].url.spec());
// Set JumpList Item title and icon. The icon needs to be a .ico file.
// We downloaded these in a shortcuts folder alongside the app's top level
// Icons folder.
// We downloaded these in a shortcut icons folder in the OS integration
// resources directory for this app.
shortcut_link->set_title(shortcuts[i].name);
base::FilePath shortcut_icon_path =
GetShortcutIconPath(shortcut_data_dir, i);
......
......@@ -55,6 +55,12 @@ const char kApp[] = "app";
// according to its configuration.
const char kAppId[] = "app-id";
// Overrides the launch url of an app with the specified url. This is used
// along with kAppId to launch a given app with the url corresponding to an item
// in the app's shortcuts menu.
const char kAppLaunchUrlForShortcutsMenuItem[] =
"app-launch-url-for-shortcuts-menu-item";
// Value of GAIA auth code for --force-app-mode.
const char kAppModeAuthCode[] = "app-mode-auth-code";
......
......@@ -37,6 +37,7 @@ extern const char kAllowRunningInsecureContent[];
extern const char kAllowSilentPush[];
extern const char kApp[];
extern const char kAppId[];
extern const char kAppLaunchUrlForShortcutsMenuItem[];
extern const char kAppModeAuthCode[];
extern const char kAppModeOAuth2Token[];
extern const char kAppsGalleryDownloadURL[];
......
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