chrome: mac: Add Alerts helper app (fixes #3181)

Some Chromium code cleanup will follow in
https://chromium-review.googlesource.com/c/chromium/src/+/4456752
This commit is contained in:
Marshall Greenblatt 2023-04-21 14:39:17 -04:00
parent e0063880ac
commit 09c4142dad
6 changed files with 87 additions and 17 deletions

View File

@ -1771,7 +1771,20 @@ if (is_mac) {
}
}
foreach(helper_params, content_mac_helpers) {
# From //chrome/BUILD.gn:
# Helper app to display alert notifications. This is necessary as an app can
# only display either banner or alert style notifications and the main app
# will display banners.
alert_helper_params = [
"alerts",
".alerts",
" (Alerts)",
]
# Merge all helper apps needed by //content and //chrome.
chrome_mac_helpers = content_mac_helpers + [ alert_helper_params ]
foreach(helper_params, chrome_mac_helpers) {
_helper_target = helper_params[0]
_helper_bundle_id = helper_params[1]
_helper_suffix = helper_params[2]
@ -1802,7 +1815,7 @@ if (is_mac) {
":cef_framework",
]
foreach(helper_params, content_mac_helpers) {
foreach(helper_params, chrome_mac_helpers) {
sources += [
"$root_out_dir/${app_helper_name}${helper_params[2]}.app",
]

View File

@ -359,6 +359,7 @@ if(OS_MAC)
# Format is "<name suffix>:<target suffix>:<plist suffix>".
set(CEF_HELPER_APP_SUFFIXES
"::"
" (Alerts):_alerts:.alerts"
" (GPU):_gpu:.gpu"
" (Plugin):_plugin:.plugin"
" (Renderer):_renderer:.renderer"

View File

@ -43,6 +43,12 @@
#include "third_party/blink/public/common/web_preferences/web_preferences.h"
#include "third_party/blink/public/mojom/loader/resource_load_info.mojom-shared.h"
#if BUILDFLAG(IS_MAC)
#include "chrome/browser/child_process_host_flags.h"
#include "chrome/common/chrome_constants.h"
#include "libcef/common/util_mac.h"
#endif
namespace {
void HandleExternalProtocolHelper(
@ -482,6 +488,20 @@ void ChromeContentBrowserClientCef::RegisterBrowserInterfaceBindersForFrame(
map);
}
#if BUILDFLAG(IS_MAC)
base::FilePath ChromeContentBrowserClientCef::GetChildProcessPath(
int child_flags,
const base::FilePath& helpers_path) {
// Ignoring |helpers_path| here because it doesn't provide sufficient
// information to determine the required path for CEF.
if (child_flags == chrome::kChildProcessHelperAlerts) {
return util_mac::GetChildProcessPath(chrome::kMacHelperSuffixAlerts);
}
NOTREACHED() << "Unsupported child process flags!";
return {};
}
#endif // BUILDFLAG(IS_MAC)
CefRefPtr<CefRequestContextImpl>
ChromeContentBrowserClientCef::request_context() const {
return browser_main_parts_->request_context();

View File

@ -124,6 +124,14 @@ class ChromeContentBrowserClientCef : public ChromeContentBrowserClient {
content::RenderFrameHost* render_frame_host,
mojo::BinderMapWithContext<content::RenderFrameHost*>* map) override;
#if BUILDFLAG(IS_MAC)
// TODO: Delete after merging
// https://chromium-review.googlesource.com/c/chromium/src/+/4456752
base::FilePath GetChildProcessPath(
int child_flags,
const base::FilePath& helpers_path) override;
#endif // BUILDFLAG(IS_MAC)
CefRefPtr<CefRequestContextImpl> request_context() const;
scoped_refptr<base::SingleThreadTaskRunner> background_task_runner() const;

View File

@ -46,10 +46,13 @@ std::string GetMainBundleID();
// running in an app bundle.
base::FilePath GetMainResourcesDirectory();
// Returns the path to the child process executable (e.g. "myapp.app/
// Contents/Frameworks/myapp Helper.app/Contents/MacOS/myapp Helper"). May
// return an empty value if not running in an app bundle.
base::FilePath GetChildProcessPath();
// Returns the path to the child process executable with optional suffix (e.g.
// "myapp.app/Contents/Frameworks/myapp Helper<suffix>.app/Contents/MacOS/
// myapp Helper<suffix>"). May return an empty value if not running in an app
// bundle.
// TODO: Delete after merging
// https://chromium-review.googlesource.com/c/chromium/src/+/4456752
base::FilePath GetChildProcessPath(const std::string& suffix);
// Called from MainDelegate::PreSandboxStartup for the main process.
void PreSandboxStartup();

View File

@ -52,14 +52,27 @@ void OverrideBaseBundleID() {
base::mac::SetBaseBundleID(bundle_id.c_str());
}
base::FilePath GetNormalChildProcessPath() {
base::FilePath frameworks_path = GetFrameworksPath();
if (frameworks_path.empty()) {
return base::FilePath();
}
std::string exe_name = GetMainProcessPath().BaseName().value();
return frameworks_path.Append(FILE_PATH_LITERAL(exe_name + " Helper.app"))
.Append(FILE_PATH_LITERAL("Contents"))
.Append(FILE_PATH_LITERAL("MacOS"))
.Append(FILE_PATH_LITERAL(exe_name + " Helper"));
}
void OverrideChildProcessPath() {
base::FilePath child_process_path =
base::CommandLine::ForCurrentProcess()->GetSwitchValuePath(
switches::kBrowserSubprocessPath);
if (child_process_path.empty()) {
child_process_path = util_mac::GetChildProcessPath();
DCHECK(!child_process_path.empty());
child_process_path = GetNormalChildProcessPath();
CHECK(!child_process_path.empty());
}
// Used by ChildProcessHost::GetChildPath and PlatformCrashpadInitialization.
@ -135,17 +148,29 @@ base::FilePath GetMainResourcesDirectory() {
.Append(FILE_PATH_LITERAL("Resources"));
}
base::FilePath GetChildProcessPath() {
base::FilePath frameworks_path = GetFrameworksPath();
if (frameworks_path.empty()) {
return base::FilePath();
base::FilePath GetChildProcessPath(const std::string& suffix) {
// Match the logic in ChildProcessHost::GetChildPath().
base::FilePath child_path;
base::PathService::Get(content::CHILD_PROCESS_EXE, &child_path);
CHECK(!child_path.empty());
if (suffix.empty()) {
// Return the normal child helper path.
return child_path;
}
std::string exe_name = GetMainProcessPath().BaseName().value();
return frameworks_path.Append(FILE_PATH_LITERAL(exe_name + " Helper.app"))
.Append(FILE_PATH_LITERAL("Contents"))
.Append(FILE_PATH_LITERAL("MacOS"))
.Append(FILE_PATH_LITERAL(exe_name + " Helper"));
std::string child_base_name = child_path.BaseName().value() + suffix;
// This is a specialized helper, with the |child_path| at
// "myapp.app/Contents/Frameworks/myapp Helper.app/Contents/MacOS/
// myapp Helper" Go back up to the "Frameworks" directory to select
// a different variant.
child_path = child_path.DirName().DirName().DirName().DirName();
return child_path.Append(child_base_name + ".app")
.Append("Contents")
.Append("MacOS")
.Append(child_base_name);
}
void PreSandboxStartup() {