Commit 2b7ecf24 authored by Jay Harris's avatar Jay Harris Committed by Commit Bot

WebApps: Add method for determining if file handling is available.

This is in preparation for the file handling origin trial, where file
handling will be available on a per app basis. This CL makes no
functional changes but instead changes the API used to check if file
handling is enabled.

Old Check:
if (base::FeatureList::IsEnable(blink::features::kFileHandlingAPI))

New Check:
if (file_handler_manager().IsFileHandlingAPIAvailable(app_id))

Currently, the implementation of |IsFileHandlingAPIAvailable| is
simply the old check. In https://crrev.com/c/1940001, this will
be changed to also be true if |app_id| has a valid FileHandling API
origin trial token.

Note: This also restricts file handling in extensions to extensions
where from_bookmark() is true (this should have always been the case).

Bug: 1028448
Change-Id: I525bb7bf03f052b79721fdc13fb154b34fa411a8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2016688Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Commit-Queue: Jay Harris <harrisjay@chromium.org>
Cr-Commit-Position: refs/heads/master@{#735753}
parent 4d5bf209
......@@ -29,21 +29,9 @@
namespace file_manager {
namespace file_tasks {
namespace {
bool WebAppFileHandlingDisabled() {
return !base::FeatureList::IsEnabled(blink::features::kNativeFileSystemAPI) ||
!base::FeatureList::IsEnabled(blink::features::kFileHandlingAPI);
}
} // namespace
void FindWebTasks(Profile* profile,
const std::vector<extensions::EntryInfo>& entries,
std::vector<FullTaskDescriptor>* result_list) {
if (WebAppFileHandlingDisabled())
return;
DCHECK(!entries.empty());
DCHECK(result_list);
......@@ -55,6 +43,9 @@ void FindWebTasks(Profile* profile,
auto app_ids = registrar.GetAppIds();
for (const auto& app_id : app_ids) {
if (!file_handler_manager.IsFileHandlingAPIAvailable(app_id))
continue;
const auto* file_handlers =
file_handler_manager.GetEnabledFileHandlers(app_id);
......@@ -97,13 +88,6 @@ void ExecuteWebTask(Profile* profile,
const TaskDescriptor& task,
const std::vector<storage::FileSystemURL>& file_system_urls,
FileTaskFinishedCallback done) {
if (WebAppFileHandlingDisabled()) {
std::move(done).Run(
extensions::api::file_manager_private::TASK_RESULT_FAILED,
"Web app file handling is disabled.");
return;
}
web_app::WebAppProviderBase* provider =
web_app::WebAppProviderBase::GetProviderBase(profile);
web_app::AppRegistrar& registrar = provider->registrar();
......@@ -115,6 +99,14 @@ void ExecuteWebTask(Profile* profile,
return;
}
if (!provider->file_handler_manager().IsFileHandlingAPIAvailable(
task.app_id)) {
std::move(done).Run(
extensions::api::file_manager_private::TASK_RESULT_FAILED,
"Web app file handling disabled");
return;
}
apps::mojom::LaunchContainer launch_container =
apps::mojom::LaunchContainer::kLaunchContainerWindow;
......
......@@ -345,12 +345,14 @@ WebContents* OpenEnabledApplication(Profile* profile,
break;
}
if (base::FeatureList::IsEnabled(blink::features::kFileHandlingAPI)) {
web_launch::WebLaunchFilesHelper::SetLaunchPaths(tab, url,
params.launch_files);
}
if (extension->from_bookmark()) {
if (web_app::WebAppProviderBase::GetProviderBase(profile)
->file_handler_manager()
.IsFileHandlingAPIAvailable(extension->id())) {
web_launch::WebLaunchFilesHelper::SetLaunchPaths(tab, url,
params.launch_files);
}
UMA_HISTOGRAM_ENUMERATION("Extensions.BookmarkAppLaunchSource",
params.source);
UMA_HISTOGRAM_ENUMERATION("Extensions.BookmarkAppLaunchContainer",
......
......@@ -27,6 +27,7 @@
#include "chrome/browser/ui/extensions/application_launch.h"
#include "chrome/browser/ui/web_applications/app_browser_controller.h"
#include "chrome/browser/ui/web_applications/web_app_launch_manager.h"
#include "chrome/browser/web_applications/components/file_handler_manager.h"
#include "chrome/browser/web_applications/components/web_app_helpers.h"
#include "chrome/browser/web_applications/system_web_app_manager.h"
#include "chrome/browser/web_applications/web_app_provider.h"
......@@ -159,7 +160,8 @@ Browser* LaunchSystemWebApp(Profile* profile,
}
// Send launch files.
if (base::FeatureList::IsEnabled(blink::features::kFileHandlingAPI)) {
if (provider->file_handler_manager().IsFileHandlingAPIAvailable(
params.app_id)) {
if (provider->system_web_app_manager().AppShouldReceiveLaunchDirectory(
app_type)) {
web_launch::WebLaunchFilesHelper::SetLaunchDirectoryAndLaunchPaths(
......
......@@ -110,7 +110,7 @@ content::WebContents* WebAppLaunchManager::OpenApplication(
content::WebContents* web_contents = NavigateWebApplicationWindow(
browser, params.app_id, url, WindowOpenDisposition::NEW_FOREGROUND_TAB);
if (base::FeatureList::IsEnabled(blink::features::kFileHandlingAPI)) {
if (file_handler_manager.IsFileHandlingAPIAvailable(params.app_id)) {
web_launch::WebLaunchFilesHelper::SetLaunchPaths(web_contents, url,
params.launch_files);
}
......
......@@ -32,7 +32,7 @@ void FileHandlerManager::DisableOsIntegrationForTesting() {
}
void FileHandlerManager::EnableAndRegisterOsFileHandlers(const AppId& app_id) {
if (!base::FeatureList::IsEnabled(blink::features::kFileHandlingAPI))
if (!IsFileHandlingAPIAvailable(app_id))
return;
UpdateBoolWebAppPref(profile()->GetPrefs(), app_id, kFileHandlersEnabled,
......@@ -61,8 +61,7 @@ void FileHandlerManager::DisableAndUnregisterOsFileHandlers(
UpdateBoolWebAppPref(profile()->GetPrefs(), app_id, kFileHandlersEnabled,
/*value=*/false);
if (!base::FeatureList::IsEnabled(blink::features::kFileHandlingAPI) ||
!ShouldRegisterFileHandlersWithOs() ||
if (!ShouldRegisterFileHandlersWithOs() ||
disable_os_integration_for_testing_) {
return;
}
......@@ -72,12 +71,16 @@ void FileHandlerManager::DisableAndUnregisterOsFileHandlers(
const std::vector<apps::FileHandlerInfo>*
FileHandlerManager::GetEnabledFileHandlers(const AppId& app_id) {
if (AreFileHandlersEnabled(app_id))
if (AreFileHandlersEnabled(app_id) && IsFileHandlingAPIAvailable(app_id))
return GetAllFileHandlers(app_id);
return nullptr;
}
bool FileHandlerManager::IsFileHandlingAPIAvailable(const AppId& app_id) {
return base::FeatureList::IsEnabled(blink::features::kFileHandlingAPI);
}
bool FileHandlerManager::AreFileHandlersEnabled(const AppId& app_id) const {
return GetBoolWebAppPref(profile()->GetPrefs(), app_id, kFileHandlersEnabled);
}
......@@ -97,7 +100,7 @@ void FileHandlerManager::OnAppRegistrarDestroyed() {
const base::Optional<GURL> FileHandlerManager::GetMatchingFileHandlerURL(
const AppId& app_id,
const std::vector<base::FilePath>& launch_files) {
if (!base::FeatureList::IsEnabled(blink::features::kFileHandlingAPI))
if (!IsFileHandlingAPIAvailable(app_id))
return base::nullopt;
const std::vector<apps::FileHandlerInfo>* file_handlers =
......
......@@ -59,6 +59,12 @@ class FileHandlerManager : public AppRegistrarObserver {
const std::vector<apps::FileHandlerInfo>* GetEnabledFileHandlers(
const AppId& app_id);
// Determines whether file handling is allowed for |app_id|. This is true if
// the FileHandlingAPI flag is enabled.
// TODO(crbug.com/1028448): Also return true if there is a valid file handling
// origin trial token for |app_id|.
bool IsFileHandlingAPIAvailable(const AppId& app_id);
protected:
Profile* profile() const { return profile_; }
AppRegistrar* registrar() { return registrar_; }
......
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