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

WebApps: Exposes functions for enabling and disabling file handlers.

This is in preparation for the origin trial, where we will need to be
able to disable and re-enable file handlers as the validity of the
origin trial token changes.

Bug: 1028448
Change-Id: Ifd78328ce8dd2ddb71113e84f001ac809135903b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1936440
Commit-Queue: Jay Harris <harrisjay@chromium.org>
Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720113}
parent b7cfa22a
...@@ -29,41 +29,49 @@ void FileHandlerManager::Start() { ...@@ -29,41 +29,49 @@ void FileHandlerManager::Start() {
shortcut_observer_.Add(shortcut_manager_); shortcut_observer_.Add(shortcut_manager_);
} }
void FileHandlerManager::OnWebAppUninstalled(const AppId& installed_app_id) { void FileHandlerManager::EnableAndRegisterOsFileHandlers(const AppId& app_id) {
if (base::FeatureList::IsEnabled(blink::features::kFileHandlingAPI) &&
ShouldRegisterFileHandlersWithOs()) {
UnregisterFileHandlersWithOs(installed_app_id, profile_);
}
}
void FileHandlerManager::OnWebAppProfileWillBeDeleted(const AppId& app_id) {
if (base::FeatureList::IsEnabled(blink::features::kFileHandlingAPI) &&
ShouldRegisterFileHandlersWithOs()) {
UnregisterFileHandlersWithOs(app_id, profile_);
}
}
void FileHandlerManager::OnAppRegistrarDestroyed() {
registrar_observer_.RemoveAll();
}
void FileHandlerManager::OnShortcutsCreated(const AppId& installed_app_id) {
if (!base::FeatureList::IsEnabled(blink::features::kFileHandlingAPI) || if (!base::FeatureList::IsEnabled(blink::features::kFileHandlingAPI) ||
!ShouldRegisterFileHandlersWithOs()) { !ShouldRegisterFileHandlersWithOs()) {
return; return;
} }
std::string app_name = registrar_->GetAppShortName(installed_app_id); std::string app_name = registrar_->GetAppShortName(app_id);
const std::vector<apps::FileHandlerInfo>* file_handlers = const std::vector<apps::FileHandlerInfo>* file_handlers =
GetFileHandlers(installed_app_id); GetFileHandlers(app_id);
if (!file_handlers) if (!file_handlers)
return; return;
std::set<std::string> file_extensions = std::set<std::string> file_extensions =
GetFileExtensionsFromFileHandlers(*file_handlers); GetFileExtensionsFromFileHandlers(*file_handlers);
std::set<std::string> mime_types = std::set<std::string> mime_types =
GetMimeTypesFromFileHandlers(*file_handlers); GetMimeTypesFromFileHandlers(*file_handlers);
RegisterFileHandlersWithOs(installed_app_id, app_name, profile_, RegisterFileHandlersWithOs(app_id, app_name, profile(), file_extensions,
file_extensions, mime_types); mime_types);
}
void FileHandlerManager::DisableAndUnregisterOsFileHandlers(
const AppId& app_id) {
if (!base::FeatureList::IsEnabled(blink::features::kFileHandlingAPI) ||
!ShouldRegisterFileHandlersWithOs()) {
return;
}
UnregisterFileHandlersWithOs(app_id, profile());
}
void FileHandlerManager::OnWebAppUninstalled(const AppId& app_id) {
DisableAndUnregisterOsFileHandlers(app_id);
}
void FileHandlerManager::OnWebAppProfileWillBeDeleted(const AppId& app_id) {
DisableAndUnregisterOsFileHandlers(app_id);
}
void FileHandlerManager::OnAppRegistrarDestroyed() {
registrar_observer_.RemoveAll();
}
void FileHandlerManager::OnShortcutsCreated(const AppId& app_id) {
EnableAndRegisterOsFileHandlers(app_id);
} }
void FileHandlerManager::OnShortcutManagerDestroyed() { void FileHandlerManager::OnShortcutManagerDestroyed() {
......
...@@ -33,6 +33,16 @@ class FileHandlerManager : public AppRegistrarObserver, ...@@ -33,6 +33,16 @@ class FileHandlerManager : public AppRegistrarObserver,
AppShortcutManager* shortcut_manager); AppShortcutManager* shortcut_manager);
void Start(); void Start();
// Enables and registers OS specific file handlers for OSs that need them.
// Currently on Chrome OS, file handlers are enabled and registered as long as
// the app is installed.
void EnableAndRegisterOsFileHandlers(const AppId& app_id);
// Disables file handlers for all OSs and unregisters OS specific file
// handlers for OSs that need them. Currently on Chrome OS, file handlers are
// enabled and registered as long as the app is installed.
void DisableAndUnregisterOsFileHandlers(const AppId& app_id);
// Gets all file handlers for |app_id|. |nullptr| if the app has no file // Gets all file handlers for |app_id|. |nullptr| if the app has no file
// handlers. // handlers.
// Note: The lifetime of the file handlers are tied to the app they belong to. // Note: The lifetime of the file handlers are tied to the app they belong to.
......
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