Commit 0b391961 authored by Maggie Cai's avatar Maggie Cai Committed by Commit Bot

[IntentHandling] Provide API for create intent from file path.

This CL adds the API to create intent from file path. When the intent
coming from a client with physical file path, it is easier for the
client to directly pass the file path in.

There is one issue where doing this will make the file manager involve
in the intent handling even when the file is not directly shared from
the file manager. Luciano will look into the file system context and see
if there is a way to get the file system context without involving the
file manager. There is another option that is possible is to add another
field in the intent with file path, and the receiving end will have to
resolve both fields to get the whole list of file. At the moment I will
prefer to keep it simple for the receiving end.

BUG=1092784

Change-Id: I02001085546d00434e0a47ef71e7a066b80f1d82
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2435125
Commit-Queue: Maggie Cai <mxcai@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811558}
parent 9a958c27
......@@ -4026,6 +4026,8 @@ static_library("browser") {
"apps/app_service/extension_apps_chromeos.h",
"apps/app_service/file_utils.cc",
"apps/app_service/file_utils.h",
"apps/app_service/intent_util.cc",
"apps/app_service/intent_util.h",
"apps/app_service/lacros_apps.cc",
"apps/app_service/lacros_apps.h",
"apps/app_service/menu_util.cc",
......
......@@ -4,6 +4,7 @@
#include "chrome/browser/apps/app_service/file_utils.h"
#include "base/files/file_path.h"
#include "chrome/browser/chromeos/file_manager/app_id.h"
#include "chrome/browser/chromeos/file_manager/fileapi_util.h"
#include "storage/browser/file_system/file_system_context.h"
......@@ -26,4 +27,17 @@ std::vector<storage::FileSystemURL> GetFileSystemURL(
return file_system_urls;
}
std::vector<GURL> GetFileUrls(Profile* profile,
const std::vector<base::FilePath>& file_paths) {
std::vector<GURL> file_urls;
for (auto& file_path : file_paths) {
GURL file_url;
if (file_manager::util::ConvertAbsoluteFilePathToFileSystemUrl(
profile, file_path, file_manager::kFileManagerAppId, &file_url)) {
file_urls.push_back(file_url);
}
}
return file_urls;
}
} // namespace apps
......@@ -10,6 +10,10 @@
class Profile;
class GURL;
namespace base {
class FilePath;
}
namespace storage {
class FileSystemURL;
}
......@@ -18,6 +22,10 @@ namespace apps {
std::vector<storage::FileSystemURL> GetFileSystemURL(
Profile* profile,
const std::vector<GURL>& file_urls);
// Convert absolute file path to filesystem: scheme url.
std::vector<GURL> GetFileUrls(Profile* profile,
const std::vector<base::FilePath>& file_paths);
} // namespace apps
#endif // CHROME_BROWSER_APPS_APP_SERVICE_FILE_UTILS_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/apps/app_service/intent_util.h"
#include "chrome/browser/apps/app_service/file_utils.h"
#include "components/services/app_service/public/cpp/intent_util.h"
namespace apps_util {
// TODO(crbug.com/853604): Make this not link to file manager extension if
// possible.
apps::mojom::IntentPtr CreateShareIntentFromFiles(
Profile* profile,
const std::vector<base::FilePath>& file_paths,
const std::vector<std::string>& mime_types) {
auto file_urls = apps::GetFileUrls(profile, file_paths);
return CreateShareIntentFromFiles(file_urls, mime_types);
}
} // namespace apps_util
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_APPS_APP_SERVICE_INTENT_UTIL_H_
#define CHROME_BROWSER_APPS_APP_SERVICE_INTENT_UTIL_H_
#include <vector>
#include "components/services/app_service/public/mojom/types.mojom.h"
class Profile;
namespace base {
class FilePath;
}
namespace apps_util {
// Create an intent struct from the file paths and mime types
// of a list of files.
// This util has to live under chrome/ because it uses fileapis
// and cannot be inlucded in components/.
apps::mojom::IntentPtr CreateShareIntentFromFiles(
Profile* profile,
const std::vector<base::FilePath>& file_paths,
const std::vector<std::string>& mime_types);
} // namespace apps_util
#endif // CHROME_BROWSER_APPS_APP_SERVICE_INTENT_UTIL_H_
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