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

Reland "WebApps: Implement unregistering file handlers on Linux."

This reverts commit 6cf710fa.

Reason for revert: This CL didn't cause the linked bug. That bug was a duplicate of crbug.com/1044520 which is now fixed.

Original change's description:
> Revert "WebApps: Implement unregistering file handlers on Linux."
> 
> This reverts commit 32a1f8bf.
> 
> Reason for revert: LocalNTPJavascriptTest failing on 7 builder(s)
> Fixed: 1044497
> 
> Original change's description:
> > WebApps: Implement unregistering file handlers on Linux.
> > 
> > This will allow us to disable the file handlers for an app on Linux
> > without uninstalling it. This is necessary preparation for the origin
> > trial, as we need to be able to disable/enable the file handlers as
> > the validity of the app's origin trial changes.
> > 
> > Bug: 1028448
> > Change-Id: I63eb6582852ff75d3d88181ede07f0cbd010df2d
> > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2010234
> > Commit-Queue: Jay Harris <harrisjay@chromium.org>
> > Reviewed-by: Alexey Baskakov <loyso@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#733859}
> 
> TBR=loyso@chromium.org,harrisjay@chromium.org
> 
> Change-Id: I67239e88d48df1d70ff1a432863b3be26d5d7bd4
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: 1028448
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2014352
> Reviewed-by: Yoichi Osato <yoichio@chromium.org>
> Commit-Queue: Yoichi Osato <yoichio@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#733902}

TBR=yoichio@chromium.org,loyso@chromium.org,harrisjay@chromium.org

Change-Id: I5052bf84dc417f11325c51e9a584e13a585c46a0
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 1028448
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2015901Reviewed-by: default avatarJay Harris <harrisjay@chromium.org>
Commit-Queue: Jay Harris <harrisjay@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734225}
parent 10734365
......@@ -6,6 +6,7 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "chrome/browser/web_applications/components/app_registrar.h"
#include "chrome/browser/web_applications/components/app_shortcut_manager.h"
#include "chrome/browser/web_applications/components/web_app_provider_base.h"
#include "chrome/browser/web_applications/components/web_app_shortcut.h"
......@@ -26,6 +27,16 @@ void OnShortcutInfoReceived(std::unique_ptr<ShortcutInfo> info) {
base::DoNothing());
}
void UpdateFileHandlerRegistrationInOs(const AppId& app_id, Profile* profile) {
// On Linux, file associations are managed through shortcuts in the app menu,
// so after enabling or disabling file handling for an app its shortcuts
// need to be recreated.
AppShortcutManager& shortcut_manager =
WebAppProviderBase::GetProviderBase(profile)->shortcut_manager();
shortcut_manager.GetShortcutInfoForApp(
app_id, base::BindOnce(&OnShortcutInfoReceived));
}
} // namespace
bool ShouldRegisterFileHandlersWithOs() {
......@@ -37,14 +48,18 @@ void RegisterFileHandlersWithOs(const AppId& app_id,
Profile* profile,
const std::set<std::string>& file_extensions,
const std::set<std::string>& mime_types) {
AppShortcutManager& shortcut_manager =
WebAppProviderBase::GetProviderBase(profile)->shortcut_manager();
shortcut_manager.GetShortcutInfoForApp(
app_id, base::BindOnce(OnShortcutInfoReceived));
UpdateFileHandlerRegistrationInOs(app_id, profile);
}
void UnregisterFileHandlersWithOs(const AppId& app_id, Profile* profile) {
// TODO(harrisjay): Add support for unregistering file handlers.
// If this was triggered as part of the uninstallation process, nothing more
// is needed. Uninstalling already cleans up shortcuts (and thus, file
// handlers).
auto* provider = WebAppProviderBase::GetProviderBase(profile);
if (!provider->registrar().IsInstalled(app_id))
return;
UpdateFileHandlerRegistrationInOs(app_id, profile);
}
} // namespace web_app
......@@ -20,6 +20,7 @@
#include "chrome/browser/profiles/profile_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/components/web_app_provider_base.h"
#include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h"
......@@ -178,11 +179,18 @@ std::unique_ptr<ShortcutInfo> ShortcutInfoForExtensionAndProfile(
shortcut_info->profile_name =
profile->GetPrefs()->GetString(prefs::kProfileName);
shortcut_info->version_for_display = app->GetVersionForDisplay();
if (const auto* info = extensions::FileHandlers::GetFileHandlers(app)) {
shortcut_info->file_handler_extensions =
web_app::GetFileExtensionsFromFileHandlers(*info);
shortcut_info->file_handler_mime_types =
web_app::GetMimeTypesFromFileHandlers(*info);
// File Handlers should only be included in bookmark apps.
if (app->from_bookmark()) {
FileHandlerManager& file_handler_manager =
WebAppProviderBase::GetProviderBase(profile)->file_handler_manager();
if (const auto* file_handlers =
file_handler_manager.GetEnabledFileHandlers(app->id())) {
shortcut_info->file_handler_extensions =
web_app::GetFileExtensionsFromFileHandlers(*file_handlers);
shortcut_info->file_handler_mime_types =
web_app::GetMimeTypesFromFileHandlers(*file_handlers);
}
}
return shortcut_info;
......
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