Commit d1a667aa authored by Jay Harris's avatar Jay Harris Committed by Commit Bot

Makes it possible to open web apps with files from the command line.

This is a prerequisite for adding file handling on Windows, MacOS and
Linux.

Example:
./chrome --profile-directory=my-profile --app-id=.. -- -- file1 file2 file3

Note: In future, the FileHandlerManager will infer the correct FileHandler for
an app based on the files it is given. For now, it just opens the app's launch
url.

Bug: 938103
Change-Id: Ieaa136d109fc906c9c48a95cdbd194fb0622d3cc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1819286Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarEric Willigers <ericwilligers@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Commit-Queue: Jay Harris <harrisjay@chromium.org>
Cr-Commit-Position: refs/heads/master@{#702740}
parent bd28b6f5
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/apps/launch_service/launch_manager.h" #include "chrome/browser/apps/launch_service/launch_manager.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "chrome/common/chrome_switches.h"
namespace apps { namespace apps {
...@@ -10,4 +13,24 @@ LaunchManager::LaunchManager(Profile* profile) : profile_(profile) {} ...@@ -10,4 +13,24 @@ LaunchManager::LaunchManager(Profile* profile) : profile_(profile) {}
LaunchManager::~LaunchManager() = default; LaunchManager::~LaunchManager() = default;
// static
std::vector<base::FilePath> LaunchManager::GetLaunchFilesFromCommandLine(
const base::CommandLine& command_line) {
std::vector<base::FilePath> launch_files;
if (!command_line.HasSwitch(switches::kAppId))
return launch_files;
// Assume all args passed were intended as files to pass to the app.
launch_files.reserve(command_line.GetArgs().size());
for (const auto& arg : command_line.GetArgs()) {
base::FilePath path(arg);
if (path.empty())
continue;
launch_files.push_back(path);
}
return launch_files;
}
} // namespace apps } // namespace apps
...@@ -42,6 +42,10 @@ class LaunchManager { ...@@ -42,6 +42,10 @@ class LaunchManager {
// Attempt to open |app_id| in a new tab. // Attempt to open |app_id| in a new tab.
virtual bool OpenApplicationTab(const std::string& app_id) = 0; virtual bool OpenApplicationTab(const std::string& app_id) = 0;
// Converts file arguments to an app on |command_line| into base::FilePaths.
static std::vector<base::FilePath> GetLaunchFilesFromCommandLine(
const base::CommandLine& command_line);
protected: protected:
explicit LaunchManager(Profile*); explicit LaunchManager(Profile*);
Profile* profile() { return profile_; } Profile* profile() { return profile_; }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chrome/browser/apps/platform_apps/platform_app_launch.h" #include "chrome/browser/apps/platform_apps/platform_app_launch.h"
#include "chrome/browser/apps/app_service/app_launch_params.h" #include "chrome/browser/apps/app_service/app_launch_params.h"
#include "chrome/browser/apps/launch_service/launch_manager.h"
#include "chrome/browser/extensions/launch_util.h" #include "chrome/browser/extensions/launch_util.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/extensions/application_launch.h" #include "chrome/browser/ui/extensions/application_launch.h"
...@@ -82,6 +83,10 @@ bool OpenExtensionApplicationWindow(Profile* profile, ...@@ -82,6 +83,10 @@ bool OpenExtensionApplicationWindow(Profile* profile,
extensions::AppLaunchSource::kSourceCommandLine); extensions::AppLaunchSource::kSourceCommandLine);
params.command_line = command_line; params.command_line = command_line;
params.current_directory = current_directory; params.current_directory = current_directory;
if (app->from_bookmark()) {
params.launch_files =
LaunchManager::GetLaunchFilesFromCommandLine(command_line);
}
content::WebContents* tab_in_app_window = ::OpenApplication(profile, params); content::WebContents* tab_in_app_window = ::OpenApplication(profile, params);
// Platform apps fire off a launch event which may or may not open a window. // Platform apps fire off a launch event which may or may not open a window.
......
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
#include "extensions/common/features/feature.h" #include "extensions/common/features/feature.h"
#include "extensions/common/features/feature_provider.h" #include "extensions/common/features/feature_provider.h"
#include "extensions/common/manifest_handlers/options_page_info.h" #include "extensions/common/manifest_handlers/options_page_info.h"
#include "third_party/blink/public/common/features.h"
#include "ui/base/window_open_disposition.h" #include "ui/base/window_open_disposition.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
...@@ -417,8 +418,10 @@ WebContents* ShowApplicationWindow(Profile* profile, ...@@ -417,8 +418,10 @@ WebContents* ShowApplicationWindow(Profile* profile,
// focus explicitly. // focus explicitly.
web_contents->SetInitialFocus(); web_contents->SetInitialFocus();
web_launch::WebLaunchFilesHelper::SetLaunchPaths(web_contents, url, if (base::FeatureList::IsEnabled(blink::features::kFileHandlingAPI)) {
params.launch_files); web_launch::WebLaunchFilesHelper::SetLaunchPaths(web_contents, url,
params.launch_files);
}
return web_contents; return web_contents;
} }
......
...@@ -117,6 +117,8 @@ bool WebAppLaunchManager::OpenApplicationWindow( ...@@ -117,6 +117,8 @@ bool WebAppLaunchManager::OpenApplicationWindow(
apps::mojom::AppLaunchSource::kSourceCommandLine); apps::mojom::AppLaunchSource::kSourceCommandLine);
params.command_line = command_line; params.command_line = command_line;
params.current_directory = current_directory; params.current_directory = current_directory;
params.launch_files =
apps::LaunchManager::GetLaunchFilesFromCommandLine(command_line);
provider_->on_registry_ready().Post( provider_->on_registry_ready().Post(
FROM_HERE, base::BindOnce(&WebAppLaunchManager::OpenWebApplication, FROM_HERE, base::BindOnce(&WebAppLaunchManager::OpenWebApplication,
......
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