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

WebApps: Makes it possible to register/unregister file handlers on OSX.

Previously, file handlers were registered once, when the app was
installed. This makes it possible to update registrations, which is a
requirement for the origin trial.

Bug: 1028448
Change-Id: Id1e05f6efdc69da601573349de6ab6932a7901c4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2032700
Auto-Submit: Jay Harris <harrisjay@chromium.org>
Reviewed-by: default avatarAlexey Baskakov <loyso@chromium.org>
Commit-Queue: Jay Harris <harrisjay@chromium.org>
Cr-Commit-Position: refs/heads/master@{#739249}
parent 7b7dcd3d
...@@ -89,6 +89,7 @@ source_set("components") { ...@@ -89,6 +89,7 @@ source_set("components") {
if (is_mac) { if (is_mac) {
sources += [ sources += [
"web_app_file_handler_registration_mac.cc",
"web_app_shortcut_mac.h", "web_app_shortcut_mac.h",
"web_app_shortcut_mac.mm", "web_app_shortcut_mac.mm",
] ]
......
...@@ -10,12 +10,9 @@ ...@@ -10,12 +10,9 @@
namespace web_app { namespace web_app {
// This block defines stub implementations of OS specific methods for // This block defines stub implementations of OS specific methods for
// FileHandling. Currently, Windows and Desktop Linux (but not Chrome OS) have // FileHandling. Currently, Windows, MacOSX and Desktop Linux (but not Chrome
// their own implementations. // OS) have their own implementations.
// #if defined(OS_CHROMEOS)
// Note: Because OS_LINUX includes OS_CHROMEOS be sure to use the stub on
// OS_CHROMEOS.
#if !defined(OS_WIN) && !(defined(OS_LINUX) && !defined(OS_CHROMEOS))
bool ShouldRegisterFileHandlersWithOs() { bool ShouldRegisterFileHandlersWithOs() {
return false; return false;
} }
......
// Copyright 2019 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/web_applications/components/web_app_file_handler_registration.h"
#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"
namespace web_app {
namespace {
void UpdateFileHandlerRegistrationInOs(const AppId& app_id, Profile* profile) {
// On OSX, file associations are managed through app shims in the Applications
// directory, so after enabling or disabling file handling for an app its shim
// needs to be updated.
AppShortcutManager& shortcut_manager =
WebAppProviderBase::GetProviderBase(profile)->shortcut_manager();
shortcut_manager.CreateShortcuts(app_id, /*add_to_desktop=*/false,
base::DoNothing());
}
} // namespace
bool ShouldRegisterFileHandlersWithOs() {
return true;
}
void RegisterFileHandlersWithOs(const AppId& app_id,
const std::string& app_name,
Profile* profile,
const std::set<std::string>& file_extensions,
const std::set<std::string>& mime_types) {
UpdateFileHandlerRegistrationInOs(app_id, profile);
}
void UnregisterFileHandlersWithOs(const AppId& app_id, Profile* profile) {
// If this was triggered as part of the uninstallation process, nothing more
// is needed. Uninstalling already cleans up app shims (and thus, file
// handlers).
auto* provider = WebAppProviderBase::GetProviderBase(profile);
if (!provider->registrar().IsInstalled(app_id))
return;
UpdateFileHandlerRegistrationInOs(app_id, profile);
}
} // namespace web_app
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