Commit d282a5ad authored by nancylingwang's avatar nancylingwang Committed by Commit Bot

Add the LaunchPlatformAppWithFilePaths interface.

For extensions, add the LaunchPlatformAppWithFilePaths interface to
launch the app by issuing an onLaunched event with the contents of
file_paths.

BUG=1090211

Change-Id: I92db10bac0d64e3c108d4aa67770a9b5f35d30f3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2264080Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Reviewed-by: default avatarLuciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#805637}
parent 30a5da05
......@@ -428,8 +428,17 @@ void LaunchPlatformAppWithCommandLineAndLaunchId(
void LaunchPlatformAppWithPath(content::BrowserContext* context,
const Extension* app,
const base::FilePath& file_path) {
scoped_refptr<PlatformAppPathLauncher> launcher =
new PlatformAppPathLauncher(context, app, file_path);
auto launcher =
base::MakeRefCounted<PlatformAppPathLauncher>(context, app, file_path);
launcher->Launch();
}
void LaunchPlatformAppWithFilePaths(
content::BrowserContext* context,
const extensions::Extension* app,
const std::vector<base::FilePath>& file_paths) {
auto launcher =
base::MakeRefCounted<PlatformAppPathLauncher>(context, app, file_paths);
launcher->Launch();
}
......
......@@ -61,6 +61,13 @@ void LaunchPlatformAppWithPath(content::BrowserContext* context,
const extensions::Extension* app,
const base::FilePath& file_path);
// Launches the platform app |app| by issuing an onLaunched event with the
// contents of |file_paths| available through the launch data.
void LaunchPlatformAppWithFilePaths(
content::BrowserContext* context,
const extensions::Extension* app,
const std::vector<base::FilePath>& file_paths);
// Launches the platform app |app| with the specific |action_data|. |file_path|
// is an optional argument and if present contains the file that the app should
// open w.r.t. the given action.
......
......@@ -228,6 +228,31 @@ class PlatformAppWithFileBrowserTest : public PlatformAppBrowserTest {
extension_name, *base::CommandLine::ForCurrentProcess());
}
void RunPlatformAppTestWithFiles(const std::string& extension_name,
const std::string& test_file) {
extensions::ResultCatcher catcher;
base::FilePath test_doc(test_data_dir_.AppendASCII(test_file));
base::FilePath file_path = test_doc.NormalizePathSeparators();
base::FilePath extension_path = test_data_dir_.AppendASCII(extension_name);
const extensions::Extension* extension =
LoadExtensionWithFlags(extension_path, kFlagNone);
ASSERT_TRUE(extension);
apps::mojom::FilePathsPtr launch_files = apps::mojom::FilePaths::New();
launch_files->file_paths.push_back(file_path);
apps::AppServiceProxyFactory::GetForProfile(browser()->profile())
->LaunchAppWithFiles(
extension->id(), apps::mojom::LaunchContainer::kLaunchContainerNone,
apps::GetEventFlags(
apps::mojom::LaunchContainer::kLaunchContainerNone,
WindowOpenDisposition::NEW_FOREGROUND_TAB,
true /* preferred_container */),
apps::mojom::LaunchSource::kFromTest, std::move(launch_files));
ASSERT_TRUE(catcher.GetNextResult());
}
private:
bool RunPlatformAppTestWithCommandLine(
const std::string& extension_name,
......@@ -567,6 +592,13 @@ IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, MAYBE_ExtensionWindowingApis) {
// ChromeOS does not support passing arguments on the command line, so the tests
// that rely on this functionality are disabled.
#if !defined(OS_CHROMEOS)
// Tests that launch data is sent through if the file extension matches.
IN_PROC_BROWSER_TEST_F(PlatformAppWithFileBrowserTest,
LaunchFilesWithFileExtension) {
RunPlatformAppTestWithFiles("platform_apps/launch_file_by_extension",
kTestFilePath);
}
// Tests that command line parameters get passed through to platform apps
// via launchData correctly when launching with a file.
// TODO(benwells/jeremya): tests need a way to specify a handler ID.
......
......@@ -310,6 +310,18 @@ WebContents* OpenEnabledApplication(Profile* profile,
prefs->SetActiveBit(extension->id(), true);
if (CanLaunchViaEvent(extension)) {
// When launching an app with a command line, there might be a file path to
// work with that command line, so
// LaunchPlatformAppWithCommandLineAndLaunchId should be called to handle
// the command line. If |launch_files| is set without |command_line|, that
// means launching the app with files, so call
// LaunchPlatformAppWithFilePaths to forward |launch_files| to the app.
if (params.command_line.GetArgs().empty() && !params.launch_files.empty()) {
apps::LaunchPlatformAppWithFilePaths(profile, extension,
params.launch_files);
return nullptr;
}
apps::LaunchPlatformAppWithCommandLineAndLaunchId(
profile, extension, params.launch_id, params.command_line,
params.current_directory, params.source);
......
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