Skip to content

Commit

Permalink
refactor: eliminate brightray
Browse files Browse the repository at this point in the history
  • Loading branch information
miniak committed Oct 18, 2018
1 parent b1fb95c commit 9e2dc66
Show file tree
Hide file tree
Showing 86 changed files with 781 additions and 1,323 deletions.
7 changes: 0 additions & 7 deletions .gitignore
Expand Up @@ -16,13 +16,6 @@
*.vcxproj.user
*.xcodeproj
/.idea/
/brightray/brightray.opensdf
/brightray/brightray.sdf
/brightray/brightray.sln
/brightray/brightray.suo
/brightray/brightray.v12.suo
/brightray/brightray.vcxproj*
/brightray/brightray.xcodeproj/
/dist/
/external_binaries/
/out/
Expand Down
7 changes: 6 additions & 1 deletion BUILD.gn
Expand Up @@ -4,6 +4,7 @@ import("buildflags/buildflags.gni")
import("electron_paks.gni")
import("filenames.gni")
import("//build/config/locales.gni")
import("//build/config/ui.gni")
import("//build/config/win/manifest.gni")
import("//pdf/features.gni")
import("//services/service_manager/public/service_manifest.gni")
Expand Down Expand Up @@ -200,11 +201,11 @@ static_library("electron_lib") {

deps = [
":atom_js2c",
"brightray",
"buildflags",
"chromium_src:chrome",
"native_mate",
"//base",
"//base:base_static",
"//base:i18n",
"//chrome/common",
"//components/certificate_transparency",
Expand All @@ -213,11 +214,15 @@ static_library("electron_lib") {
"//components/prefs",
"//components/viz/service",
"//content/public/app:both",
"//content/public/browser",
"//content/public/child",
"//content/public/common:service_names",
"//content/shell:copy_shell_resources",
"//gin",
"//media/mojo/interfaces",
"//net:extras",
"//net:net_resources",
"//net:net_with_v8",
"//ppapi/host",
"//ppapi/proxy",
"//ppapi/shared_impl",
Expand Down
18 changes: 18 additions & 0 deletions atom/app/atom_content_client.cc
Expand Up @@ -21,6 +21,7 @@
#include "electron/buildflags/buildflags.h"
#include "ppapi/shared_impl/ppapi_permissions.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "url/url_constants.h"
// In SHARED_INTERMEDIATE_DIR.
#include "widevine_cdm_version.h" // NOLINT(build/include)
Expand Down Expand Up @@ -193,6 +194,23 @@ base::string16 AtomContentClient::GetLocalizedString(int message_id) const {
return l10n_util::GetStringUTF16(message_id);
}

base::StringPiece AtomContentClient::GetDataResource(
int resource_id,
ui::ScaleFactor scale_factor) const {
return ui::ResourceBundle::GetSharedInstance().GetRawDataResourceForScale(
resource_id, scale_factor);
}

gfx::Image& AtomContentClient::GetNativeImageNamed(int resource_id) const {
return ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(
resource_id);
}

base::RefCountedMemory* AtomContentClient::GetDataResourceBytes(
int resource_id) const {
return ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes(
resource_id);
}
void AtomContentClient::AddAdditionalSchemes(Schemes* schemes) {
schemes->standard_schemes.push_back("chrome-extension");

Expand Down
8 changes: 6 additions & 2 deletions atom/app/atom_content_client.h
Expand Up @@ -9,11 +9,11 @@
#include <string>
#include <vector>

#include "brightray/common/content_client.h"
#include "content/public/common/content_client.h"

namespace atom {

class AtomContentClient : public brightray::ContentClient {
class AtomContentClient : public content::ContentClient {
public:
AtomContentClient();
~AtomContentClient() override;
Expand All @@ -23,6 +23,10 @@ class AtomContentClient : public brightray::ContentClient {
std::string GetProduct() const override;
std::string GetUserAgent() const override;
base::string16 GetLocalizedString(int message_id) const override;
base::StringPiece GetDataResource(int resource_id,
ui::ScaleFactor) const override;
gfx::Image& GetNativeImageNamed(int resource_id) const override;
base::RefCountedMemory* GetDataResourceBytes(int resource_id) const override;
void AddAdditionalSchemes(Schemes* schemes) override;
void AddPepperPlugins(
std::vector<content::PepperPluginInfo>* plugins) override;
Expand Down
4 changes: 2 additions & 2 deletions atom/app/atom_library_main.mm
Expand Up @@ -7,11 +7,11 @@
#include "atom/app/atom_main_delegate.h"
#include "atom/app/node_main.h"
#include "atom/common/atom_command_line.h"
#include "atom/common/mac/main_application_bundle.h"
#include "base/at_exit.h"
#include "base/i18n/icu_util.h"
#include "base/mac/bundle_locations.h"
#include "base/mac/scoped_nsautorelease_pool.h"
#include "brightray/common/mac/main_application_bundle.h"
#include "content/public/app/content_main.h"

int AtomMain(int argc, char* argv[]) {
Expand All @@ -28,7 +28,7 @@ int AtomInitializeICUandStartNode(int argc, char* argv[]) {
base::AtExitManager atexit_manager;
base::mac::ScopedNSAutoreleasePool pool;
base::mac::SetOverrideFrameworkBundlePath(
brightray::MainApplicationBundlePath()
atom::MainApplicationBundlePath()
.Append("Contents")
.Append("Frameworks")
.Append(ATOM_PRODUCT_NAME " Framework.framework"));
Expand Down
79 changes: 71 additions & 8 deletions atom/app/atom_main_delegate.cc
Expand Up @@ -20,12 +20,17 @@
#include "base/debug/stack_trace.h"
#include "base/environment.h"
#include "base/logging.h"
#include "base/mac/bundle_locations.h"
#include "base/path_service.h"
#include "chrome/common/chrome_paths.h"
#include "content/public/common/content_switches.h"
#include "electron/buildflags/buildflags.h"
#include "ipc/ipc_buildflags.h"
#include "services/service_manager/embedder/switches.h"
#include "services/service_manager/sandbox/switches.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_switches.h"

#if BUILDFLAG(IPC_MESSAGE_LOG_ENABLED)
#define IPC_MESSAGE_MACROS_LOG_ENABLED
Expand All @@ -50,6 +55,25 @@ bool IsBrowserProcess(base::CommandLine* cmd) {
return process_type.empty();
}

// 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;
}

#if defined(OS_WIN)
void InvalidParameterHandler(const wchar_t*,
const wchar_t*,
Expand All @@ -62,6 +86,37 @@ void InvalidParameterHandler(const wchar_t*,

} // 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)
}

AtomMainDelegate::AtomMainDelegate() {}

AtomMainDelegate::~AtomMainDelegate() {}
Expand Down Expand Up @@ -118,6 +173,8 @@ bool AtomMainDelegate::BasicStartupComplete(int* exit_code) {
chrome::RegisterPathProvider();

#if defined(OS_MACOSX)
OverrideChildProcessPath();
OverrideFrameworkBundlePath();
SetUpBundleOverrides();
#endif

Expand All @@ -129,13 +186,24 @@ bool AtomMainDelegate::BasicStartupComplete(int* exit_code) {
base::win::DisableHandleVerifier();
#endif

return brightray::MainDelegate::BasicStartupComplete(exit_code);
content_client_ = std::make_unique<AtomContentClient>();
SetContentClient(content_client_.get());

return false;
}

void AtomMainDelegate::PreSandboxStartup() {
brightray::MainDelegate::PreSandboxStartup();

auto* command_line = base::CommandLine::ForCurrentProcess();
std::string process_type =
command_line->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 = command_line->GetSwitchValueASCII(::switches::kLang);
LoadResourceBundle(locale);
}

// Only append arguments for browser process.
if (!IsBrowserProcess(command_line))
Expand Down Expand Up @@ -212,9 +280,4 @@ bool AtomMainDelegate::DelaySandboxInitialization(
}
#endif

std::unique_ptr<brightray::ContentClient>
AtomMainDelegate::CreateContentClient() {
return std::make_unique<AtomContentClient>();
}

} // namespace atom
19 changes: 9 additions & 10 deletions atom/app/atom_main_delegate.h
Expand Up @@ -8,12 +8,15 @@
#include <memory>
#include <string>

#include "brightray/common/content_client.h"
#include "brightray/common/main_delegate.h"
#include "atom/app/atom_main_delegate.h"
#include "content/public/app/content_main_delegate.h"
#include "content/public/common/content_client.h"

namespace atom {

class AtomMainDelegate : public brightray::MainDelegate {
void LoadResourceBundle(const std::string& locale);

class AtomMainDelegate : public content::ContentMainDelegate {
public:
AtomMainDelegate();
~AtomMainDelegate() override;
Expand All @@ -34,19 +37,15 @@ class AtomMainDelegate : public brightray::MainDelegate {
bool DelaySandboxInitialization(const std::string& process_type) override;
#endif

// brightray::MainDelegate:
std::unique_ptr<brightray::ContentClient> CreateContentClient() override;
#if defined(OS_MACOSX)
void OverrideChildProcessPath() override;
void OverrideFrameworkBundlePath() override;
#endif

private:
#if defined(OS_MACOSX)
void OverrideChildProcessPath();
void OverrideFrameworkBundlePath();
void SetUpBundleOverrides();
#endif

std::unique_ptr<content::ContentBrowserClient> browser_client_;
std::unique_ptr<content::ContentClient> content_client_;
std::unique_ptr<content::ContentRendererClient> renderer_client_;
std::unique_ptr<content::ContentUtilityClient> utility_client_;

Expand Down
11 changes: 5 additions & 6 deletions atom/app/atom_main_delegate_mac.mm
Expand Up @@ -5,23 +5,23 @@
#include "atom/app/atom_main_delegate.h"

#include "atom/browser/mac/atom_application.h"
#include "atom/common/application_info.h"
#include "atom/common/mac/main_application_bundle.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/mac/bundle_locations.h"
#include "base/mac/foundation_util.h"
#include "base/mac/scoped_nsautorelease_pool.h"
#include "base/path_service.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"

namespace atom {

namespace {

base::FilePath GetFrameworksPath() {
return brightray::MainApplicationBundlePath()
return atom::MainApplicationBundlePath()
.Append("Contents")
.Append("Frameworks");
}
Expand All @@ -46,16 +46,15 @@
base::FilePath helper_path =
GetHelperAppPath(frameworks_path, ATOM_PRODUCT_NAME);
if (!base::PathExists(helper_path))
helper_path =
GetHelperAppPath(frameworks_path, brightray::GetApplicationName());
helper_path = GetHelperAppPath(frameworks_path, GetApplicationName());
if (!base::PathExists(helper_path))
LOG(FATAL) << "Unable to find helper app";
base::PathService::Override(content::CHILD_PROCESS_EXE, helper_path);
}

void AtomMainDelegate::SetUpBundleOverrides() {
base::mac::ScopedNSAutoreleasePool pool;
NSBundle* bundle = brightray::MainApplicationBundle();
NSBundle* bundle = MainApplicationBundle();
std::string base_bundle_id =
base::SysNSStringToUTF8([bundle bundleIdentifier]);
NSString* team_id = [bundle objectForInfoDictionaryKey:@"ElectronTeamID"];
Expand Down
14 changes: 7 additions & 7 deletions atom/browser/api/atom_api_app.cc
Expand Up @@ -13,6 +13,7 @@
#include "atom/browser/api/gpuinfo_manager.h"
#include "atom/browser/atom_browser_context.h"
#include "atom/browser/atom_browser_main_parts.h"
#include "atom/browser/atom_paths.h"
#include "atom/browser/login_handler.h"
#include "atom/browser/relauncher.h"
#include "atom/common/atom_command_line.h"
Expand All @@ -31,7 +32,6 @@
#include "base/path_service.h"
#include "base/strings/string_util.h"
#include "base/sys_info.h"
#include "brightray/browser/brightray_paths.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/icon_manager.h"
#include "chrome/common/chrome_paths.h"
Expand Down Expand Up @@ -395,15 +395,15 @@ IconLoader::IconSize GetIconSizeByString(const std::string& size) {
// Return the path constant from string.
int GetPathConstant(const std::string& name) {
if (name == "appData")
return brightray::DIR_APP_DATA;
return DIR_APP_DATA;
else if (name == "userData")
return brightray::DIR_USER_DATA;
return DIR_USER_DATA;
else if (name == "cache")
return brightray::DIR_CACHE;
return DIR_CACHE;
else if (name == "userCache")
return brightray::DIR_USER_CACHE;
return DIR_USER_CACHE;
else if (name == "logs")
return brightray::DIR_APP_LOGS;
return DIR_APP_LOGS;
else if (name == "home")
return base::DIR_HOME;
else if (name == "temp")
Expand Down Expand Up @@ -895,7 +895,7 @@ bool App::RequestSingleInstanceLock() {
return true;

base::FilePath user_dir;
base::PathService::Get(brightray::DIR_USER_DATA, &user_dir);
base::PathService::Get(DIR_USER_DATA, &user_dir);

auto cb = base::Bind(&App::OnSecondInstance, base::Unretained(this));

Expand Down

0 comments on commit 9e2dc66

Please sign in to comment.