diff --git a/browser/BUILD.gn b/browser/BUILD.gn index 545b7b0e35f5..d20822b189fd 100644 --- a/browser/BUILD.gn +++ b/browser/BUILD.gn @@ -235,6 +235,12 @@ source_set("browser_process") { "//google_update", ] } + + if (is_mac) { + deps += [ + "//brave/browser/apps/app_shim", + ] + } } buildflag_header("sparkle_buildflags") { diff --git a/browser/apps/app_shim/BUILD.gn b/browser/apps/app_shim/BUILD.gn new file mode 100644 index 000000000000..dee2ad009408 --- /dev/null +++ b/browser/apps/app_shim/BUILD.gn @@ -0,0 +1,9 @@ +source_set("app_shim") { + sources = [ + "brave_extension_app_shim_handler_mac.cc", + "brave_extension_app_shim_handler_mac.h", + ] + deps = [ + "//content/public/browser", + ] +} diff --git a/browser/apps/app_shim/brave_extension_app_shim_handler_mac.cc b/browser/apps/app_shim/brave_extension_app_shim_handler_mac.cc new file mode 100644 index 000000000000..8f2e04819b6b --- /dev/null +++ b/browser/apps/app_shim/brave_extension_app_shim_handler_mac.cc @@ -0,0 +1,43 @@ +/* Copyright (c) 2019 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. */ + +#include "brave/browser/apps/app_shim/brave_extension_app_shim_handler_mac.h" + +#include "brave/browser/profiles/profile_util.h" +#include "chrome/browser/chrome_notification_types.h" +#include "content/public/browser/notification_source.h" + +namespace apps { + +// Same as off-the-record profiles, we return early for Tor profile for +// NOTIFICATION_PROFILE_CREATED and NOTIFICATION_PROFILE_DESTROYED cases +// since ExtensionAppShimHandler is observing AppLifetimeMonitorFactory through +// parent profiles. +void BraveExtensionAppShimHandler::Observe( + int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) { + switch (type) { + case chrome::NOTIFICATION_PROFILE_CREATED: { + Profile* profile = content::Source(source).ptr(); + if (brave::IsTorProfile(profile)) + return; + break; + } + case chrome::NOTIFICATION_PROFILE_DESTROYED: { + Profile* profile = content::Source(source).ptr(); + if (brave::IsTorProfile(profile)) + return; + break; + } + default: { + break; + } + } + + return ExtensionAppShimHandler::Observe(type, source, details); +} + +} // namespace apps diff --git a/browser/apps/app_shim/brave_extension_app_shim_handler_mac.h b/browser/apps/app_shim/brave_extension_app_shim_handler_mac.h new file mode 100644 index 000000000000..474174aa25d7 --- /dev/null +++ b/browser/apps/app_shim/brave_extension_app_shim_handler_mac.h @@ -0,0 +1,30 @@ +/* Copyright (c) 2019 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. */ + +#ifndef BRAVE_BROWSER_APPS_APP_SHIM_BRAVE_EXTENSION_APP_SHIM_HANDLER_MAC_H_ +#define BRAVE_BROWSER_APPS_APP_SHIM_BRAVE_EXTENSION_APP_SHIM_HANDLER_MAC_H_ + +#include "chrome/browser/apps/app_shim/extension_app_shim_handler_mac.h" + +#include "content/public/browser/notification_observer.h" + +namespace apps { + +class BraveExtensionAppShimHandler : public ExtensionAppShimHandler { + public: + BraveExtensionAppShimHandler() = default; + ~BraveExtensionAppShimHandler() override = default; + + // content::NotificationObserver overrides: + void Observe(int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) override; + + DISALLOW_COPY_AND_ASSIGN(BraveExtensionAppShimHandler); +}; + +} // namespace apps + +#endif // BRAVE_BROWSER_APPS_APP_SHIM_BRAVE_EXTENSION_APP_SHIM_HANDLER_MAC_H_ diff --git a/chromium_src/chrome/browser/apps/app_shim/app_shim_host_manager_mac.mm b/chromium_src/chrome/browser/apps/app_shim/app_shim_host_manager_mac.mm new file mode 100644 index 000000000000..063f7e17872c --- /dev/null +++ b/chromium_src/chrome/browser/apps/app_shim/app_shim_host_manager_mac.mm @@ -0,0 +1,10 @@ +/* Copyright (c) 2019 The Brave Authors. All rights reserved. + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at https://mozilla.org/MPL/2.0/. */ + +#include "brave/browser/apps/app_shim/brave_extension_app_shim_handler_mac.h" + +#define ExtensionAppShimHandler BraveExtensionAppShimHandler +#include "../../../../../../chrome/browser/apps/app_shim/app_shim_host_manager_mac.mm" +#undef ExtensionAppShimHandler