mirror of
https://github.com/electron/electron.git
synced 2026-05-02 03:00:22 -04:00
refactor: eliminate brightray::MainDelegate (#15333)
This commit is contained in:
committed by
Alexey Kuzmin
parent
fbbb704146
commit
809bd3757b
@@ -1,99 +0,0 @@
|
||||
// Copyright (c) 2012 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-CHROMIUM file.
|
||||
|
||||
#include "brightray/common/main_delegate.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/mac/bundle_locations.h"
|
||||
#include "base/path_service.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "electron/buildflags/buildflags.h"
|
||||
#include "services/service_manager/embedder/switches.h"
|
||||
#include "ui/base/resource/resource_bundle.h"
|
||||
#include "ui/base/ui_base_switches.h"
|
||||
|
||||
namespace brightray {
|
||||
|
||||
namespace {
|
||||
|
||||
// Returns true if this subprocess type needs the ResourceBundle initialized
|
||||
// and resources loaded.
|
||||
bool SubprocessNeedsResourceBundle(const std::string& process_type) {
|
||||
return
|
||||
#if defined(OS_POSIX) && !defined(OS_MACOSX)
|
||||
// The zygote process opens the resources for the renderers.
|
||||
process_type == service_manager::switches::kZygoteProcess ||
|
||||
#endif
|
||||
#if defined(OS_MACOSX)
|
||||
// Mac needs them too for scrollbar related images and for sandbox
|
||||
// profiles.
|
||||
process_type == switches::kPpapiPluginProcess ||
|
||||
process_type == switches::kPpapiBrokerProcess ||
|
||||
process_type == switches::kGpuProcess ||
|
||||
#endif
|
||||
process_type == switches::kRendererProcess ||
|
||||
process_type == switches::kUtilityProcess;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void LoadResourceBundle(const std::string& locale) {
|
||||
const bool initialized = ui::ResourceBundle::HasSharedInstance();
|
||||
if (initialized)
|
||||
ui::ResourceBundle::CleanupSharedInstance();
|
||||
|
||||
// Load other resource files.
|
||||
base::FilePath pak_dir;
|
||||
#if defined(OS_MACOSX)
|
||||
pak_dir =
|
||||
base::mac::FrameworkBundlePath().Append(FILE_PATH_LITERAL("Resources"));
|
||||
#else
|
||||
base::PathService::Get(base::DIR_MODULE, &pak_dir);
|
||||
#endif
|
||||
|
||||
ui::ResourceBundle::InitSharedInstanceWithLocale(
|
||||
locale, nullptr, ui::ResourceBundle::LOAD_COMMON_RESOURCES);
|
||||
ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
|
||||
bundle.ReloadLocaleResources(locale);
|
||||
bundle.AddDataPackFromPath(pak_dir.Append(FILE_PATH_LITERAL("resources.pak")),
|
||||
ui::SCALE_FACTOR_NONE);
|
||||
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
||||
NOTIMPLEMENTED()
|
||||
<< "Hi, whoever's fixing PDF support! Thanks! The pdf "
|
||||
"viewer resources haven't been ported over to the GN build yet, so "
|
||||
"you'll probably need to change this bit of code.";
|
||||
bundle.AddDataPackFromPath(
|
||||
pak_dir.Append(FILE_PATH_LITERAL("pdf_viewer_resources.pak")),
|
||||
ui::GetSupportedScaleFactors()[0]);
|
||||
#endif // BUILDFLAG(ENABLE_PDF_VIEWER)
|
||||
}
|
||||
|
||||
MainDelegate::MainDelegate() {}
|
||||
|
||||
MainDelegate::~MainDelegate() {}
|
||||
|
||||
bool MainDelegate::BasicStartupComplete(int* exit_code) {
|
||||
#if defined(OS_MACOSX)
|
||||
OverrideChildProcessPath();
|
||||
OverrideFrameworkBundlePath();
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
void MainDelegate::PreSandboxStartup() {
|
||||
auto cmd = *base::CommandLine::ForCurrentProcess();
|
||||
std::string process_type = cmd.GetSwitchValueASCII(switches::kProcessType);
|
||||
|
||||
// Initialize ResourceBundle which handles files loaded from external
|
||||
// sources. The language should have been passed in to us from the
|
||||
// browser process as a command line flag.
|
||||
if (SubprocessNeedsResourceBundle(process_type)) {
|
||||
std::string locale = cmd.GetSwitchValueASCII(switches::kLang);
|
||||
LoadResourceBundle(locale);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace brightray
|
||||
@@ -1,49 +0,0 @@
|
||||
// Copyright (c) 2012 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-CHROMIUM file.
|
||||
|
||||
#ifndef BRIGHTRAY_COMMON_MAIN_DELEGATE_H_
|
||||
#define BRIGHTRAY_COMMON_MAIN_DELEGATE_H_
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "content/public/app/content_main_delegate.h"
|
||||
|
||||
namespace base {
|
||||
class FilePath;
|
||||
}
|
||||
|
||||
namespace ui {
|
||||
class ResourceBundle;
|
||||
}
|
||||
|
||||
namespace brightray {
|
||||
|
||||
void LoadResourceBundle(const std::string& locale);
|
||||
void LoadCommonResources();
|
||||
|
||||
class MainDelegate : public content::ContentMainDelegate {
|
||||
public:
|
||||
MainDelegate();
|
||||
~MainDelegate() override;
|
||||
|
||||
protected:
|
||||
#if defined(OS_MACOSX)
|
||||
// Subclasses can override this to custom the paths of child process and
|
||||
// framework bundle.
|
||||
virtual void OverrideChildProcessPath();
|
||||
virtual void OverrideFrameworkBundlePath();
|
||||
#endif
|
||||
|
||||
bool BasicStartupComplete(int* exit_code) override;
|
||||
void PreSandboxStartup() override;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(MainDelegate);
|
||||
};
|
||||
|
||||
} // namespace brightray
|
||||
|
||||
#endif // BRIGHTRAY_COMMON_MAIN_DELEGATE_H_
|
||||
@@ -1,47 +0,0 @@
|
||||
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
||||
// Copyright (c) 2013 Adam Roben <adam@roben.org>. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE-CHROMIUM file.
|
||||
|
||||
#import "brightray/common/main_delegate.h"
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/mac/bundle_locations.h"
|
||||
#include "base/mac/foundation_util.h"
|
||||
#include "base/path_service.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
#include "brightray/common/application_info.h"
|
||||
#include "brightray/common/mac/main_application_bundle.h"
|
||||
#include "content/public/common/content_paths.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "ui/base/resource/resource_bundle.h"
|
||||
|
||||
namespace brightray {
|
||||
|
||||
namespace {
|
||||
|
||||
base::FilePath GetFrameworksPath() {
|
||||
return MainApplicationBundlePath().Append("Contents").Append("Frameworks");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void MainDelegate::OverrideFrameworkBundlePath() {
|
||||
base::FilePath helper_path =
|
||||
GetFrameworksPath().Append(GetApplicationName() + " Framework.framework");
|
||||
|
||||
base::mac::SetOverrideFrameworkBundlePath(helper_path);
|
||||
}
|
||||
|
||||
void MainDelegate::OverrideChildProcessPath() {
|
||||
base::FilePath helper_path = GetFrameworksPath()
|
||||
.Append(GetApplicationName() + " Helper.app")
|
||||
.Append("Contents")
|
||||
.Append("MacOS")
|
||||
.Append(GetApplicationName() + " Helper");
|
||||
|
||||
base::PathService::Override(content::CHILD_PROCESS_EXE, helper_path);
|
||||
}
|
||||
|
||||
} // namespace brightray
|
||||
Reference in New Issue
Block a user