From a6780d4bddfd49cd37462b38eac7a9f3bb701087 Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Thu, 18 Oct 2018 02:36:15 +0200 Subject: [PATCH] refactor: eliminate brightray --- .gitignore | 7 - BUILD.gn | 7 +- atom/app/atom_content_client.cc | 18 ++ atom/app/atom_content_client.h | 8 +- atom/app/atom_library_main.mm | 4 +- atom/app/atom_main_delegate.cc | 79 ++++- atom/app/atom_main_delegate.h | 19 +- atom/app/atom_main_delegate_mac.mm | 13 +- atom/browser/api/atom_api_app.cc | 14 +- atom/browser/api/atom_api_web_contents.h | 4 +- atom/browser/atom_browser_client.cc | 59 +++- atom/browser/atom_browser_client.h | 16 +- atom/browser/atom_browser_context.cc | 13 +- atom/browser/atom_browser_main_parts.cc | 302 ++++++++++++++++-- atom/browser/atom_browser_main_parts.h | 26 +- atom/browser/atom_browser_main_parts_mac.mm | 32 +- .../browser/atom_paths.h | 10 +- atom/browser/browser.cc | 14 +- atom/browser/browser_linux.cc | 6 +- atom/browser/browser_mac.mm | 6 +- atom/browser/browser_win.cc | 8 +- atom/browser/common_web_contents_delegate.h | 4 +- atom/browser/media/media_device_id_salt.cc | 2 +- .../browser/net/url_request_context_getter.cc | 2 +- .../linux/libnotify_notification.cc | 4 +- .../win/windows_toast_notification.cc | 8 +- .../win/windows_toast_notification.h | 4 +- .../atom_inspectable_web_contents_view.mm | 2 +- atom/browser/ui/devtools_manager_delegate.cc | 1 - .../ui/inspectable_web_contents_impl.cc | 6 +- atom/browser/ui/tray_icon_gtk.cc | 4 +- .../browser/win/scoped_hstring.cc | 6 +- .../browser/win/scoped_hstring.h | 10 +- atom/common/api/atom_bindings.cc | 4 +- .../common/application_info.cc | 10 +- {brightray => atom}/common/application_info.h | 16 +- ...tion_info.cc => application_info_linux.cc} | 6 +- .../common/application_info_mac.mm | 12 +- .../common/application_info_win.cc | 12 +- atom/common/mac/main_application_bundle.h | 26 ++ .../common/mac/main_application_bundle.mm | 6 +- .../atom_sandboxed_renderer_client.cc | 4 +- brightray/CPPLINT.cfg | 1 - brightray/LICENSE | 19 -- brightray/LICENSE-CHROMIUM | 27 -- brightray/browser/browser_main_parts.h | 62 ---- brightray/browser/browser_main_parts_mac.mm | 37 --- brightray/common/content_client.cc | 61 ---- brightray/common/content_client.h | 36 --- .../common/mac/main_application_bundle.h | 21 -- brightray/common/main_delegate.cc | 116 ------- brightray/common/main_delegate.h | 65 ---- brightray/common/main_delegate_mac.mm | 47 --- docs/development/build-system-overview.md | 3 +- .../development/debug-instructions-windows.md | 3 +- .../debugging-instructions-macos.md | 3 +- docs/development/pull-requests.md | 2 +- .../source-code-directory-structure.md | 1 - docs/glossary.md | 8 +- filenames.gni | 11 +- package.json | 6 +- patches/common/chromium/.patches.yaml | 2 +- patches/common/chromium/gtk_visibility.patch | 9 +- script/lint.js | 2 +- 64 files changed, 678 insertions(+), 678 deletions(-) rename brightray/browser/brightray_paths.h => atom/browser/atom_paths.h (82%) rename {brightray => atom}/browser/win/scoped_hstring.cc (90%) rename {brightray => atom}/browser/win/scoped_hstring.h (82%) rename {brightray => atom}/common/application_info.cc (73%) rename {brightray => atom}/common/application_info.h (61%) rename atom/common/{linux/application_info.cc => application_info_linux.cc} (94%) rename {brightray => atom}/common/application_info_mac.mm (70%) rename {brightray => atom}/common/application_info_win.cc (92%) create mode 100644 atom/common/mac/main_application_bundle.h rename {brightray => atom}/common/mac/main_application_bundle.mm (94%) delete mode 100644 brightray/CPPLINT.cfg delete mode 100644 brightray/LICENSE delete mode 100644 brightray/LICENSE-CHROMIUM delete mode 100644 brightray/browser/browser_main_parts.h delete mode 100644 brightray/browser/browser_main_parts_mac.mm delete mode 100644 brightray/common/content_client.cc delete mode 100644 brightray/common/content_client.h delete mode 100644 brightray/common/mac/main_application_bundle.h delete mode 100644 brightray/common/main_delegate.cc delete mode 100644 brightray/common/main_delegate.h delete mode 100644 brightray/common/main_delegate_mac.mm diff --git a/.gitignore b/.gitignore index 63272ea1e3fb0..fab8743120908 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ diff --git a/BUILD.gn b/BUILD.gn index 16479b4ed6d1d..92db789eccfb9 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -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") @@ -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", @@ -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", diff --git a/atom/app/atom_content_client.cc b/atom/app/atom_content_client.cc index 4107656c52afe..f7fb4bb3cf687 100644 --- a/atom/app/atom_content_client.cc +++ b/atom/app/atom_content_client.cc @@ -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) @@ -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"); diff --git a/atom/app/atom_content_client.h b/atom/app/atom_content_client.h index b6ecc3407d0e9..bf07825c474cd 100644 --- a/atom/app/atom_content_client.h +++ b/atom/app/atom_content_client.h @@ -9,11 +9,11 @@ #include #include -#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; @@ -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* plugins) override; diff --git a/atom/app/atom_library_main.mm b/atom/app/atom_library_main.mm index f1bf7bb97a8c8..bd241ca2f74f1 100644 --- a/atom/app/atom_library_main.mm +++ b/atom/app/atom_library_main.mm @@ -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[]) { @@ -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")); diff --git a/atom/app/atom_main_delegate.cc b/atom/app/atom_main_delegate.cc index 668501a7c49bb..cd9f79f92bb68 100644 --- a/atom/app/atom_main_delegate.cc +++ b/atom/app/atom_main_delegate.cc @@ -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 @@ -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*, @@ -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() {} @@ -118,6 +173,8 @@ bool AtomMainDelegate::BasicStartupComplete(int* exit_code) { chrome::RegisterPathProvider(); #if defined(OS_MACOSX) + OverrideChildProcessPath(); + OverrideFrameworkBundlePath(); SetUpBundleOverrides(); #endif @@ -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(); + 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)) @@ -212,9 +280,4 @@ bool AtomMainDelegate::DelaySandboxInitialization( } #endif -std::unique_ptr -AtomMainDelegate::CreateContentClient() { - return std::make_unique(); -} - } // namespace atom diff --git a/atom/app/atom_main_delegate.h b/atom/app/atom_main_delegate.h index 83d2c6e2ae52a..21cd63d82db72 100644 --- a/atom/app/atom_main_delegate.h +++ b/atom/app/atom_main_delegate.h @@ -8,12 +8,15 @@ #include #include -#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; @@ -34,19 +37,15 @@ class AtomMainDelegate : public brightray::MainDelegate { bool DelaySandboxInitialization(const std::string& process_type) override; #endif - // brightray::MainDelegate: - std::unique_ptr 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 browser_client_; + std::unique_ptr content_client_; std::unique_ptr renderer_client_; std::unique_ptr utility_client_; diff --git a/atom/app/atom_main_delegate_mac.mm b/atom/app/atom_main_delegate_mac.mm index 21104ae23e741..5b60ea44639ad 100644 --- a/atom/app/atom_main_delegate_mac.mm +++ b/atom/app/atom_main_delegate_mac.mm @@ -5,6 +5,8 @@ #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" @@ -12,8 +14,6 @@ #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 { @@ -21,9 +21,7 @@ namespace { base::FilePath GetFrameworksPath() { - return brightray::MainApplicationBundlePath() - .Append("Contents") - .Append("Frameworks"); + return MainApplicationBundlePath().Append("Contents").Append("Frameworks"); } base::FilePath GetHelperAppPath(const base::FilePath& frameworks_path, @@ -46,8 +44,7 @@ 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); @@ -55,7 +52,7 @@ 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"]; diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index dafde725c47d8..c9d3660a1633f 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -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" @@ -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" @@ -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") @@ -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)); diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 5586321326ff6..f2ce2c0865140 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -400,10 +400,10 @@ class WebContents : public mate::TrackableObject, content::WebContentsObserver::MediaStoppedReason reason) override; void DidChangeThemeColor(SkColor theme_color) override; - // brightray::InspectableWebContentsDelegate: + // content::InspectableWebContentsDelegate: void DevToolsReloadPage() override; - // brightray::InspectableWebContentsViewDelegate: + // content::InspectableWebContentsViewDelegate: void DevToolsFocused() override; void DevToolsOpened() override; void DevToolsClosed() override; diff --git a/atom/browser/atom_browser_client.cc b/atom/browser/atom_browser_client.cc index 8c4553ccc449e..cde178baa5a2b 100644 --- a/atom/browser/atom_browser_client.cc +++ b/atom/browser/atom_browser_client.cc @@ -17,6 +17,7 @@ #include "atom/browser/atom_browser_context.h" #include "atom/browser/atom_browser_main_parts.h" #include "atom/browser/atom_navigation_throttle.h" +#include "atom/browser/atom_paths.h" #include "atom/browser/atom_quota_permission_context.h" #include "atom/browser/atom_resource_dispatcher_host_delegate.h" #include "atom/browser/atom_speech_recognition_manager_delegate.h" @@ -38,7 +39,9 @@ #include "base/environment.h" #include "base/files/file_util.h" #include "base/json/json_reader.h" +#include "base/lazy_instance.h" #include "base/no_destructor.h" +#include "base/path_service.h" #include "base/stl_util.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_util.h" @@ -121,6 +124,18 @@ bool IsSameWebSite(content::BrowserContext* browser_context, src_url; } +AtomBrowserClient* g_browser_client = nullptr; + +base::LazyInstance::DestructorAtExit + g_io_thread_application_locale = LAZY_INSTANCE_INITIALIZER; + +base::NoDestructor g_application_locale; + +void SetApplicationLocaleOnIOThread(const std::string& locale) { + DCHECK_CURRENTLY_ON(BrowserThread::IO); + g_io_thread_application_locale.Get() = locale; +} + } // namespace // static @@ -133,9 +148,32 @@ void AtomBrowserClient::SetCustomServiceWorkerSchemes( *g_custom_service_worker_schemes = base::JoinString(schemes, ","); } -AtomBrowserClient::AtomBrowserClient() {} +AtomBrowserClient* AtomBrowserClient::Get() { + return g_browser_client; +} + +// static +void AtomBrowserClient::SetApplicationLocale(const std::string& locale) { + DCHECK_CURRENTLY_ON(BrowserThread::UI); + + if (!BrowserThread::IsThreadInitialized(BrowserThread::IO) || + !BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + base::BindOnce(&SetApplicationLocaleOnIOThread, locale))) { + g_io_thread_application_locale.Get() = locale; + } + *g_application_locale = locale; +} + +AtomBrowserClient::AtomBrowserClient() { + DCHECK(!g_browser_client); + g_browser_client = this; +} -AtomBrowserClient::~AtomBrowserClient() {} +AtomBrowserClient::~AtomBrowserClient() { + DCHECK(g_browser_client); + g_browser_client = nullptr; +} content::WebContents* AtomBrowserClient::GetWebContentsFromProcessID( int process_id) { @@ -579,7 +617,7 @@ net::NetLog* AtomBrowserClient::GetNetLog() { return AtomBrowserMainParts::Get()->net_log(); } -brightray::BrowserMainParts* AtomBrowserClient::OverrideCreateBrowserMainParts( +content::BrowserMainParts* AtomBrowserClient::CreateBrowserMainParts( const content::MainFunctionParams& params) { return new AtomBrowserMainParts(params); } @@ -708,4 +746,19 @@ AtomBrowserClient::GetPlatformNotificationService() { return notification_service_.get(); } +base::FilePath AtomBrowserClient::GetDefaultDownloadDirectory() { + // ~/Downloads + base::FilePath path; + if (base::PathService::Get(base::DIR_HOME, &path)) + path = path.Append(FILE_PATH_LITERAL("Downloads")); + + return path; +} + +std::string AtomBrowserClient::GetApplicationLocale() { + if (BrowserThread::CurrentlyOn(BrowserThread::IO)) + return g_io_thread_application_locale.Get(); + return *g_application_locale; +} + } // namespace atom diff --git a/atom/browser/atom_browser_client.h b/atom/browser/atom_browser_client.h index 520b9e032e5fd..7a36efea72f51 100644 --- a/atom/browser/atom_browser_client.h +++ b/atom/browser/atom_browser_client.h @@ -11,7 +11,7 @@ #include #include -#include "brightray/browser/browser_client.h" +#include "content/public/browser/content_browser_client.h" #include "content/public/browser/render_process_host_observer.h" #include "net/ssl/client_cert_identity.h" @@ -30,9 +30,12 @@ class AtomResourceDispatcherHostDelegate; class NotificationPresenter; class PlatformNotificationService; -class AtomBrowserClient : public brightray::BrowserClient, +class AtomBrowserClient : public content::ContentBrowserClient, public content::RenderProcessHostObserver { public: + static AtomBrowserClient* Get(); + static void SetApplicationLocale(const std::string& locale); + AtomBrowserClient(); ~AtomBrowserClient() override; @@ -58,8 +61,10 @@ class AtomBrowserClient : public brightray::BrowserClient, std::vector> CreateThrottlesForNavigation(content::NavigationHandle* handle) override; - protected: // content::ContentBrowserClient: + std::string GetApplicationLocale() override; + + protected: void RenderProcessWillLaunch( content::RenderProcessHost* host, service_manager::mojom::ServiceRequest* service_request) override; @@ -131,10 +136,9 @@ class AtomBrowserClient : public brightray::BrowserClient, content::DevToolsManagerDelegate* GetDevToolsManagerDelegate() override; content::PlatformNotificationService* GetPlatformNotificationService() override; - - // brightray::BrowserClient: - brightray::BrowserMainParts* OverrideCreateBrowserMainParts( + content::BrowserMainParts* CreateBrowserMainParts( const content::MainFunctionParams&) override; + base::FilePath GetDefaultDownloadDirectory() override; // content::RenderProcessHostObserver: void RenderProcessHostDestroyed(content::RenderProcessHost* host) override; diff --git a/atom/browser/atom_browser_context.cc b/atom/browser/atom_browser_context.cc index af30a5c6861dc..1b6fff16919d6 100644 --- a/atom/browser/atom_browser_context.cc +++ b/atom/browser/atom_browser_context.cc @@ -9,6 +9,7 @@ #include "atom/browser/atom_blob_reader.h" #include "atom/browser/atom_browser_main_parts.h" #include "atom/browser/atom_download_manager_delegate.h" +#include "atom/browser/atom_paths.h" #include "atom/browser/atom_permission_manager.h" #include "atom/browser/browser.h" #include "atom/browser/cookie_change_notifier.h" @@ -18,6 +19,7 @@ #include "atom/browser/ui/inspectable_web_contents_impl.h" #include "atom/browser/web_view_manager.h" #include "atom/browser/zoom_level_delegate.h" +#include "atom/common/application_info.h" #include "atom/common/atom_version.h" #include "atom/common/chrome_version.h" #include "atom/common/options_switches.h" @@ -28,8 +30,6 @@ #include "base/strings/stringprintf.h" #include "base/threading/sequenced_task_runner_handle.h" #include "base/threading/thread_restrictions.h" -#include "brightray/browser/brightray_paths.h" -#include "brightray/common/application_info.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/pref_names.h" #include "components/keyed_service/content/browser_context_dependency_manager.h" @@ -100,11 +100,10 @@ AtomBrowserContext::AtomBrowserContext(const std::string& partition, base::StringToInt(command_line->GetSwitchValueASCII(switches::kDiskCacheSize), &max_cache_size_); - if (!base::PathService::Get(brightray::DIR_USER_DATA, &path_)) { - base::PathService::Get(brightray::DIR_APP_DATA, &path_); - path_ = path_.Append( - base::FilePath::FromUTF8Unsafe(brightray::GetApplicationName())); - base::PathService::Override(brightray::DIR_USER_DATA, path_); + if (!base::PathService::Get(DIR_USER_DATA, &path_)) { + base::PathService::Get(DIR_APP_DATA, &path_); + path_ = path_.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName())); + base::PathService::Override(DIR_USER_DATA, path_); } if (!in_memory && !partition.empty()) diff --git a/atom/browser/atom_browser_main_parts.cc b/atom/browser/atom_browser_main_parts.cc index 2f17c9992d137..efccde0abc104 100644 --- a/atom/browser/atom_browser_main_parts.cc +++ b/atom/browser/atom_browser_main_parts.cc @@ -6,10 +6,16 @@ #include +#if defined(OS_LINUX) +#include // for g_setenv() +#endif + +#include "atom/app/atom_main_delegate.h" #include "atom/browser/api/atom_api_app.h" #include "atom/browser/api/trackable_object.h" #include "atom/browser/atom_browser_client.h" #include "atom/browser/atom_browser_context.h" +#include "atom/browser/atom_paths.h" #include "atom/browser/atom_web_ui_controller_factory.h" #include "atom/browser/browser.h" #include "atom/browser/io_thread.h" @@ -18,30 +24,62 @@ #include "atom/browser/node_debugger.h" #include "atom/browser/ui/devtools_manager_delegate.h" #include "atom/common/api/atom_bindings.h" +#include "atom/common/application_info.h" #include "atom/common/asar/asar_util.h" #include "atom/common/node_bindings.h" +#include "base/base_switches.h" #include "base/command_line.h" -#include "base/threading/thread_task_runner_handle.h" +#include "base/feature_list.h" +#include "base/message_loop/message_loop.h" +#include "base/path_service.h" +#include "base/strings/string_number_conversions.h" +#include "base/strings/utf_string_conversions.h" #include "chrome/browser/browser_process_impl.h" #include "chrome/browser/icon_manager.h" #include "chrome/browser/net/chrome_net_log_helper.h" #include "components/net_log/chrome_net_log.h" #include "components/net_log/net_export_file_writer.h" +#include "content/public/browser/browser_thread.h" #include "content/public/browser/child_process_security_policy.h" #include "content/public/browser/web_ui_controller_factory.h" +#include "content/public/common/content_features.h" #include "content/public/common/content_switches.h" #include "content/public/common/result_codes.h" #include "content/public/common/service_manager_connection.h" #include "electron/buildflags/buildflags.h" +#include "media/base/localized_strings.h" #include "services/device/public/mojom/constants.mojom.h" #include "services/network/public/cpp/network_switches.h" #include "services/service_manager/public/cpp/connector.h" #include "ui/base/idle/idle.h" #include "ui/base/l10n/l10n_util.h" +#include "ui/base/material_design/material_design_controller.h" +#include "ui/base/resource/resource_bundle.h" +#include "ui/base/ui_base_switches.h" + +#if defined(USE_AURA) +#include "ui/display/display.h" +#include "ui/display/screen.h" +#include "ui/views/widget/desktop_aura/desktop_screen.h" +#include "ui/wm/core/wm_state.h" +#endif #if defined(USE_X11) +#include "base/environment.h" +#include "base/nix/xdg_util.h" +#include "base/threading/thread_task_runner_handle.h" +#include "chrome/browser/ui/libgtkui/gtk_ui.h" #include "chrome/browser/ui/libgtkui/gtk_util.h" +#include "ui/base/x/x11_util.h" +#include "ui/base/x/x11_util_internal.h" #include "ui/events/devices/x11/touch_factory_x11.h" +#include "ui/views/linux_ui/linux_ui.h" +#endif + +#if defined(OS_WIN) +#include "ui/base/cursor/cursor_loader_win.h" +#include "ui/base/l10n/l10n_util_win.h" +#include "ui/gfx/platform_font_win.h" #endif #if defined(OS_MACOSX) @@ -50,6 +88,11 @@ #include "atom/browser/ui/views/atom_views_delegate.h" #endif +#if defined(OS_LINUX) +#include "device/bluetooth/bluetooth_adapter_factory.h" +#include "device/bluetooth/dbus/dbus_bluez_manager_wrapper_linux.h" +#endif + // Must be included after all other headers. #include "atom/common/node_includes.h" @@ -62,8 +105,133 @@ void Erase(T* container, typename T::iterator iter) { container->erase(iter); } +#if defined(OS_WIN) +// gfx::Font callbacks +void AdjustUIFont(LOGFONT* logfont) { + l10n_util::AdjustUIFont(logfont); +} + +int GetMinimumFontSize() { + return 10; +} +#endif + +base::string16 MediaStringProvider(media::MessageId id) { + switch (id) { + case media::DEFAULT_AUDIO_DEVICE_NAME: + return base::ASCIIToUTF16("Default"); +#if defined(OS_WIN) + case media::COMMUNICATIONS_AUDIO_DEVICE_NAME: + return base::ASCIIToUTF16("Communications"); +#endif + default: + return base::string16(); + } +} + +#if defined(USE_X11) +// Indicates that we're currently responding to an IO error (by shutting down). +bool g_in_x11_io_error_handler = false; + +// Number of seconds to wait for UI thread to get an IO error if we get it on +// the background thread. +const int kWaitForUIThreadSeconds = 10; + +void OverrideLinuxAppDataPath() { + base::FilePath path; + if (base::PathService::Get(DIR_APP_DATA, &path)) + return; + std::unique_ptr env(base::Environment::Create()); + path = base::nix::GetXDGDirectory(env.get(), base::nix::kXdgConfigHomeEnvVar, + base::nix::kDotConfigDir); + base::PathService::Override(DIR_APP_DATA, path); +} + +int BrowserX11ErrorHandler(Display* d, XErrorEvent* error) { + if (!g_in_x11_io_error_handler && base::ThreadTaskRunnerHandle::IsSet()) { + base::ThreadTaskRunnerHandle::Get()->PostTask( + FROM_HERE, base::Bind(&ui::LogErrorEventDescription, d, *error)); + } + return 0; +} + +// This function is used to help us diagnose crash dumps that happen +// during the shutdown process. +NOINLINE void WaitingForUIThreadToHandleIOError() { + // Ensure function isn't optimized away. + asm(""); + sleep(kWaitForUIThreadSeconds); +} + +int BrowserX11IOErrorHandler(Display* d) { + if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { + // Wait for the UI thread (which has a different connection to the X server) + // to get the error. We can't call shutdown from this thread without + // tripping an error. Doing it through a function so that we'll be able + // to see it in any crash dumps. + WaitingForUIThreadToHandleIOError(); + return 0; + } + + // If there's an IO error it likely means the X server has gone away. + // If this DCHECK fails, then that means SessionEnding() below triggered some + // code that tried to talk to the X server, resulting in yet another error. + DCHECK(!g_in_x11_io_error_handler); + + g_in_x11_io_error_handler = true; + LOG(ERROR) << "X IO error received (X server probably went away)"; + base::ThreadTaskRunnerHandle::Get()->PostTask( + FROM_HERE, base::RunLoop::QuitCurrentWhenIdleClosureDeprecated()); + + return 0; +} + +int X11EmptyErrorHandler(Display* d, XErrorEvent* error) { + return 0; +} + +int X11EmptyIOErrorHandler(Display* d) { + return 0; +} +#endif + } // namespace +void AtomBrowserMainParts::InitializeFeatureList() { + auto* cmd_line = base::CommandLine::ForCurrentProcess(); + auto enable_features = + cmd_line->GetSwitchValueASCII(::switches::kEnableFeatures); + // Node depends on SharedArrayBuffer support, which was temporarily disabled + // by https://chromium-review.googlesource.com/c/chromium/src/+/849429 (in + // M64) and reenabled by + // https://chromium-review.googlesource.com/c/chromium/src/+/1159358 (in + // M70). Once Electron upgrades to M70, we can remove this. + enable_features += std::string(",") + features::kSharedArrayBuffer.name; + auto disable_features = + cmd_line->GetSwitchValueASCII(::switches::kDisableFeatures); +#if defined(OS_MACOSX) + // Disable the V2 sandbox on macOS. + // Chromium is going to use the system sandbox API of macOS for the sandbox + // implmentation, we may have to deprecate --mixed-sandbox for macOS once + // Chromium drops support for the old sandbox implmentation. + disable_features += std::string(",") + features::kMacV2Sandbox.name; +#endif + auto feature_list = std::make_unique(); + feature_list->InitializeFromCommandLine(enable_features, disable_features); + base::FeatureList::SetInstance(std::move(feature_list)); +} + +#if !defined(OS_MACOSX) +void AtomBrowserMainParts::OverrideAppLogsPath() { + base::FilePath path; + if (base::PathService::Get(DIR_APP_DATA, &path)) { + path = path.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName())); + path = path.Append(base::FilePath::FromUTF8Unsafe("logs")); + base::PathService::Override(DIR_APP_LOGS, path); + } +} +#endif + // static AtomBrowserMainParts* AtomBrowserMainParts::self_ = nullptr; @@ -120,10 +288,22 @@ void AtomBrowserMainParts::RegisterDestructionCallback( destructors_.insert(destructors_.begin(), std::move(callback)); } +bool AtomBrowserMainParts::ShouldContentCreateFeatureList() { + return false; +} + int AtomBrowserMainParts::PreEarlyInitialization() { - const int result = brightray::BrowserMainParts::PreEarlyInitialization(); - if (result != service_manager::RESULT_CODE_NORMAL_EXIT) - return result; + InitializeFeatureList(); + OverrideAppLogsPath(); +#if defined(USE_X11) + views::LinuxUI::SetInstance(BuildGtkUi()); + OverrideLinuxAppDataPath(); + + // Installs the X11 error handlers for the browser process used during + // startup. They simply print error messages and exit because + // we can't shutdown properly while creating and initializing services. + ui::SetX11ErrorHandlers(nullptr, nullptr); +#endif #if defined(OS_POSIX) HandleSIGCHLD(); @@ -133,8 +313,6 @@ int AtomBrowserMainParts::PreEarlyInitialization() { } void AtomBrowserMainParts::PostEarlyInitialization() { - brightray::BrowserMainParts::PostEarlyInitialization(); - // A workaround was previously needed because there was no ThreadTaskRunner // set. If this check is failing we may need to re-add that workaround DCHECK(base::ThreadTaskRunnerHandle::IsSet()); @@ -162,21 +340,35 @@ void AtomBrowserMainParts::PostEarlyInitialization() { // Wrap the uv loop with global env. node_bindings_->set_uv_env(env); - // We already initialized the feature list in - // brightray::BrowserMainParts::PreEarlyInitialization(), but + // We already initialized the feature list in PreEarlyInitialization(), but // the user JS script would not have had a chance to alter the command-line // switches at that point. Lets reinitialize it here to pick up the // command-line changes. base::FeatureList::ClearInstanceForTesting(); - brightray::BrowserMainParts::InitializeFeatureList(); + InitializeFeatureList(); } int AtomBrowserMainParts::PreCreateThreads() { - const int result = brightray::BrowserMainParts::PreCreateThreads(); - if (!result) { - fake_browser_process_->SetApplicationLocale( - brightray::BrowserClient::Get()->GetApplicationLocale()); - } +#if defined(USE_AURA) + display::Screen* screen = views::CreateDesktopScreen(); + display::Screen::SetScreenInstance(screen); +#if defined(USE_X11) + views::LinuxUI::instance()->UpdateDeviceScaleFactor(); +#endif +#endif + + if (!views::LayoutProvider::Get()) + layout_provider_.reset(new views::LayoutProvider()); + + // Initialize the app locale. + atom::AtomBrowserClient::SetApplicationLocale( + l10n_util::GetApplicationLocale(custom_locale_)); + + fake_browser_process_->SetApplicationLocale( + AtomBrowserClient::Get()->GetApplicationLocale()); + + // Force MediaCaptureDevicesDispatcher to be created on UI thread. + MediaCaptureDevicesDispatcher::GetInstance(); // Force MediaCaptureDevicesDispatcher to be created on UI thread. MediaCaptureDevicesDispatcher::GetInstance(); @@ -203,16 +395,37 @@ int AtomBrowserMainParts::PreCreateThreads() { // Manage global state of net and other IO thread related. io_thread_ = std::make_unique(net_log_.get()); - return result; + return 0; } void AtomBrowserMainParts::PostDestroyThreads() { - brightray::BrowserMainParts::PostDestroyThreads(); +#if defined(OS_LINUX) + device::BluetoothAdapterFactory::Shutdown(); + bluez::DBusBluezManagerWrapperLinux::Shutdown(); +#endif io_thread_.reset(); } void AtomBrowserMainParts::ToolkitInitialized() { - brightray::BrowserMainParts::ToolkitInitialized(); + ui::MaterialDesignController::Initialize(); + +#if defined(USE_AURA) && defined(USE_X11) + views::LinuxUI::instance()->Initialize(); +#endif + +#if defined(USE_AURA) + wm_state_.reset(new wm::WMState); +#endif + +#if defined(OS_WIN) + gfx::PlatformFontWin::adjust_font_callback = &AdjustUIFont; + gfx::PlatformFontWin::get_minimum_font_size_callback = &GetMinimumFontSize; + + wchar_t module_name[MAX_PATH] = {0}; + if (GetModuleFileName(NULL, module_name, MAX_PATH)) + ui::CursorLoaderWin::SetCursorResourceModule(module_name); +#endif + #if defined(OS_MACOSX) views_delegate_.reset(new ViewsDelegateMac); #else @@ -260,7 +473,7 @@ void AtomBrowserMainParts::PreMainMessageLoopRun() { bool AtomBrowserMainParts::MainMessageLoopRun(int* result_code) { js_env_->OnMessageLoopCreated(); exit_code_ = result_code; - return brightray::BrowserMainParts::MainMessageLoopRun(result_code); + return content::BrowserMainParts::MainMessageLoopRun(result_code); } void AtomBrowserMainParts::PreDefaultMainMessageLoopRun( @@ -269,14 +482,27 @@ void AtomBrowserMainParts::PreDefaultMainMessageLoopRun( } void AtomBrowserMainParts::PostMainMessageLoopStart() { - brightray::BrowserMainParts::PostMainMessageLoopStart(); +#if defined(USE_X11) + // Installs the X11 error handlers for the browser process after the + // main message loop has started. This will allow us to exit cleanly + // if X exits before us. + ui::SetX11ErrorHandlers(BrowserX11ErrorHandler, BrowserX11IOErrorHandler); +#endif +#if defined(OS_LINUX) + bluez::DBusBluezManagerWrapperLinux::Initialize(); +#endif #if defined(OS_POSIX) HandleShutdownSignals(); #endif } void AtomBrowserMainParts::PostMainMessageLoopRun() { - brightray::BrowserMainParts::PostMainMessageLoopRun(); +#if defined(USE_X11) + // Unset the X11 error handlers. The X11 error handlers log the errors using a + // |PostTask()| on the message-loop. But since the message-loop is in the + // process of terminating, this can cause errors. + ui::SetX11ErrorHandlers(X11EmptyErrorHandler, X11EmptyIOErrorHandler); +#endif js_env_->OnMessageLoopDestroying(); @@ -297,6 +523,42 @@ void AtomBrowserMainParts::PostMainMessageLoopRun() { } } +#if !defined(OS_MACOSX) +void AtomBrowserMainParts::PreMainMessageLoopStart() { + PreMainMessageLoopStartCommon(); +} +#endif + +void AtomBrowserMainParts::PreMainMessageLoopStartCommon() { + // Initialize ui::ResourceBundle. + ui::ResourceBundle::InitSharedInstanceWithLocale( + "", nullptr, ui::ResourceBundle::DO_NOT_LOAD_COMMON_RESOURCES); + auto* cmd_line = base::CommandLine::ForCurrentProcess(); + if (cmd_line->HasSwitch(switches::kLang)) { + const std::string locale = cmd_line->GetSwitchValueASCII(switches::kLang); + const base::FilePath locale_file_path = + ui::ResourceBundle::GetSharedInstance().GetLocaleFilePath(locale, true); + if (!locale_file_path.empty()) { + custom_locale_ = locale; +#if defined(OS_LINUX) + /* When built with USE_GLIB, libcc's GetApplicationLocaleInternal() uses + * glib's g_get_language_names(), which keys off of getenv("LC_ALL") */ + g_setenv("LC_ALL", custom_locale_.c_str(), TRUE); +#endif + } + } + +#if defined(OS_MACOSX) + if (custom_locale_.empty()) + l10n_util::OverrideLocaleWithCocoaLocale(); +#endif + LoadResourceBundle(custom_locale_); +#if defined(OS_MACOSX) + InitializeMainNib(); +#endif + media::SetLocalizedStringProvider(MediaStringProvider); +} + device::mojom::GeolocationControl* AtomBrowserMainParts::GetGeolocationControl() { if (geolocation_control_) diff --git a/atom/browser/atom_browser_main_parts.h b/atom/browser/atom_browser_main_parts.h index 28b31661f60a9..1653227c708e9 100644 --- a/atom/browser/atom_browser_main_parts.h +++ b/atom/browser/atom_browser_main_parts.h @@ -11,10 +11,11 @@ #include "base/callback.h" #include "base/timer/timer.h" -#include "brightray/browser/browser_main_parts.h" #include "content/public/browser/browser_context.h" +#include "content/public/browser/browser_main_parts.h" #include "content/public/common/main_function_params.h" #include "services/device/public/mojom/geolocation_control.mojom.h" +#include "ui/views/layout/layout_provider.h" class BrowserProcess; class IconManager; @@ -23,6 +24,12 @@ namespace net_log { class ChromeNetLog; } +#if defined(USE_AURA) +namespace wm { +class WMState; +} +#endif + namespace atom { class AtomBindings; @@ -42,7 +49,7 @@ class ViewsDelegate; class ViewsDelegateMac; #endif -class AtomBrowserMainParts : public brightray::BrowserMainParts { +class AtomBrowserMainParts : public content::BrowserMainParts { public: explicit AtomBrowserMainParts(const content::MainFunctionParams& params); ~AtomBrowserMainParts() override; @@ -73,6 +80,7 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts { protected: // content::BrowserMainParts: + bool ShouldContentCreateFeatureList() override; int PreEarlyInitialization() override; void PostEarlyInitialization() override; int PreCreateThreads() override; @@ -82,12 +90,14 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts { void PreDefaultMainMessageLoopRun(base::OnceClosure quit_closure) override; void PostMainMessageLoopStart() override; void PostMainMessageLoopRun() override; -#if defined(OS_MACOSX) void PreMainMessageLoopStart() override; -#endif void PostDestroyThreads() override; private: + void InitializeFeatureList(); + void OverrideAppLogsPath(); + void PreMainMessageLoopStartCommon(); + #if defined(OS_POSIX) // Set signal handlers. void HandleSIGCHLD(); @@ -96,6 +106,7 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts { #if defined(OS_MACOSX) void FreeAppDelegate(); + void InitializeMainNib(); #endif #if defined(OS_MACOSX) @@ -104,6 +115,13 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts { std::unique_ptr views_delegate_; #endif +#if defined(USE_AURA) + std::unique_ptr wm_state_; +#endif + + std::unique_ptr layout_provider_; + std::string custom_locale_; + // A fake BrowserProcess object that used to feed the source code from chrome. std::unique_ptr fake_browser_process_; diff --git a/atom/browser/atom_browser_main_parts_mac.mm b/atom/browser/atom_browser_main_parts_mac.mm index 92af70cf3830a..073945fbecafc 100644 --- a/atom/browser/atom_browser_main_parts_mac.mm +++ b/atom/browser/atom_browser_main_parts_mac.mm @@ -4,9 +4,11 @@ #include "atom/browser/atom_browser_main_parts.h" +#include "atom/browser/atom_paths.h" #include "atom/browser/mac/atom_application_delegate.h" #include "base/mac/bundle_locations.h" #include "base/mac/foundation_util.h" +#include "base/path_service.h" #include "ui/base/l10n/l10n_util_mac.h" namespace atom { @@ -16,7 +18,7 @@ AtomApplicationDelegate* delegate = [[AtomApplicationDelegate alloc] init]; [NSApp setDelegate:delegate]; - brightray::BrowserMainParts::PreMainMessageLoopStart(); + PreMainMessageLoopStartCommon(); // Prevent Cocoa from turning command-line arguments into // |-application:openFiles:|, since we already handle them directly. @@ -30,4 +32,32 @@ [NSApp setDelegate:nil]; } +void AtomBrowserMainParts::OverrideAppLogsPath() { + base::FilePath path; + NSString* bundleName = + [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]; + NSString* logsPath = + [NSString stringWithFormat:@"Library/Logs/%@", bundleName]; + NSString* libraryPath = + [NSHomeDirectory() stringByAppendingPathComponent:logsPath]; + + base::PathService::Override(DIR_APP_LOGS, + base::FilePath([libraryPath UTF8String])); +} + +// Replicates NSApplicationMain, but doesn't start a run loop. +void AtomBrowserMainParts::InitializeMainNib() { + auto infoDictionary = base::mac::OuterBundle().infoDictionary; + + auto principalClass = + NSClassFromString([infoDictionary objectForKey:@"NSPrincipalClass"]); + auto application = [principalClass sharedApplication]; + + NSString* mainNibName = [infoDictionary objectForKey:@"NSMainNibFile"]; + auto mainNib = [[NSNib alloc] initWithNibNamed:mainNibName + bundle:base::mac::FrameworkBundle()]; + [mainNib instantiateWithOwner:application topLevelObjects:nil]; + [mainNib release]; +} + } // namespace atom diff --git a/brightray/browser/brightray_paths.h b/atom/browser/atom_paths.h similarity index 82% rename from brightray/browser/brightray_paths.h rename to atom/browser/atom_paths.h index 5c6c6d9e7adb9..bf018839e7ef0 100644 --- a/brightray/browser/brightray_paths.h +++ b/atom/browser/atom_paths.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef BRIGHTRAY_BROWSER_BRIGHTRAY_PATHS_H_ -#define BRIGHTRAY_BROWSER_BRIGHTRAY_PATHS_H_ +#ifndef ATOM_BROWSER_ATOM_PATHS_H_ +#define ATOM_BROWSER_ATOM_PATHS_H_ #if defined(OS_WIN) #include "base/base_paths_win.h" @@ -15,7 +15,7 @@ #include "base/base_paths_posix.h" #endif -namespace brightray { +namespace atom { enum { PATH_START = 11000, @@ -39,6 +39,6 @@ enum { PATH_END }; -} // namespace brightray +} // namespace atom -#endif // BRIGHTRAY_BROWSER_BRIGHTRAY_PATHS_H_ +#endif // ATOM_BROWSER_ATOM_PATHS_H_ diff --git a/atom/browser/browser.cc b/atom/browser/browser.cc index f172a77e72bcb..e37de81042881 100644 --- a/atom/browser/browser.cc +++ b/atom/browser/browser.cc @@ -9,10 +9,12 @@ #include #include "atom/browser/atom_browser_main_parts.h" +#include "atom/browser/atom_paths.h" #include "atom/browser/browser_observer.h" #include "atom/browser/login_handler.h" #include "atom/browser/native_window.h" #include "atom/browser/window_list.h" +#include "atom/common/application_info.h" #include "base/files/file_util.h" #include "base/message_loop/message_loop.h" #include "base/no_destructor.h" @@ -20,8 +22,6 @@ #include "base/run_loop.h" #include "base/threading/thread_restrictions.h" #include "base/threading/thread_task_runner_handle.h" -#include "brightray/browser/brightray_paths.h" -#include "brightray/common/application_info.h" namespace atom { @@ -104,25 +104,25 @@ void Browser::Shutdown() { } std::string Browser::GetVersion() const { - std::string ret = brightray::GetOverriddenApplicationVersion(); + std::string ret = GetOverriddenApplicationVersion(); if (ret.empty()) ret = GetExecutableFileVersion(); return ret; } void Browser::SetVersion(const std::string& version) { - brightray::OverrideApplicationVersion(version); + OverrideApplicationVersion(version); } std::string Browser::GetName() const { - std::string ret = brightray::GetOverriddenApplicationName(); + std::string ret = GetOverriddenApplicationName(); if (ret.empty()) ret = GetExecutableFileProductName(); return ret; } void Browser::SetName(const std::string& name) { - brightray::OverrideApplicationName(name); + OverrideApplicationName(name); } int Browser::GetBadgeCount() { @@ -156,7 +156,7 @@ void Browser::DidFinishLaunching(const base::DictionaryValue& launch_info) { // Make sure the userData directory is created. base::ThreadRestrictions::ScopedAllowIO allow_io; base::FilePath user_data; - if (base::PathService::Get(brightray::DIR_USER_DATA, &user_data)) + if (base::PathService::Get(DIR_USER_DATA, &user_data)) base::CreateDirectoryAndGetError(user_data, nullptr); is_ready_ = true; diff --git a/atom/browser/browser_linux.cc b/atom/browser/browser_linux.cc index 0b4868f711ec2..06f8ee47105e6 100644 --- a/atom/browser/browser_linux.cc +++ b/atom/browser/browser_linux.cc @@ -9,11 +9,11 @@ #include "atom/browser/native_window.h" #include "atom/browser/window_list.h" +#include "atom/common/application_info.h" #include "atom/common/atom_version.h" #include "base/command_line.h" #include "base/environment.h" #include "base/process/launch.h" -#include "brightray/common/application_info.h" #if defined(USE_X11) #include "chrome/browser/ui/libgtkui/gtk_util.h" @@ -131,11 +131,11 @@ Browser::LoginItemSettings Browser::GetLoginItemSettings( } std::string Browser::GetExecutableFileVersion() const { - return brightray::GetApplicationVersion(); + return GetApplicationVersion(); } std::string Browser::GetExecutableFileProductName() const { - return brightray::GetApplicationName(); + return GetApplicationName(); } bool Browser::IsUnityRunning() { diff --git a/atom/browser/browser_mac.mm b/atom/browser/browser_mac.mm index 735e07b2f3be5..d4edb3f577ef8 100644 --- a/atom/browser/browser_mac.mm +++ b/atom/browser/browser_mac.mm @@ -9,13 +9,13 @@ #include "atom/browser/mac/dict_util.h" #include "atom/browser/native_window.h" #include "atom/browser/window_list.h" +#include "atom/common/application_info.h" #include "atom/common/platform_util.h" #include "base/mac/bundle_locations.h" #include "base/mac/foundation_util.h" #include "base/mac/mac_util.h" #include "base/strings/string_number_conversions.h" #include "base/strings/sys_string_conversions.h" -#include "brightray/common/application_info.h" #include "net/base/mac/url_conversions.h" #include "ui/gfx/image/image.h" #include "url/gurl.h" @@ -289,11 +289,11 @@ void RemoveFromLoginItems() { } std::string Browser::GetExecutableFileVersion() const { - return brightray::GetApplicationVersion(); + return GetApplicationVersion(); } std::string Browser::GetExecutableFileProductName() const { - return brightray::GetApplicationName(); + return GetApplicationName(); } int Browser::DockBounce(BounceType type) { diff --git a/atom/browser/browser_win.cc b/atom/browser/browser_win.cc index f5f7465e03661..18cc45741bec3 100644 --- a/atom/browser/browser_win.cc +++ b/atom/browser/browser_win.cc @@ -11,6 +11,7 @@ #include #include "atom/browser/ui/win/jump_list.h" +#include "atom/common/application_info.h" #include "atom/common/atom_version.h" #include "atom/common/native_mate_converters/string16_converter.h" #include "base/base_paths.h" @@ -24,7 +25,6 @@ #include "base/win/registry.h" #include "base/win/win_util.h" #include "base/win/windows_version.h" -#include "brightray/common/application_info.h" namespace atom { @@ -120,7 +120,7 @@ void Browser::ClearRecentDocuments() { } void Browser::SetAppUserModelID(const base::string16& name) { - brightray::SetAppUserModelID(name); + atom::SetAppUserModelID(name); } bool Browser::SetUserTasks(const std::vector& tasks) { @@ -324,7 +324,7 @@ Browser::LoginItemSettings Browser::GetLoginItemSettings( } PCWSTR Browser::GetAppUserModelID() { - return brightray::GetRawAppUserModelID(); + return GetRawAppUserModelID(); } std::string Browser::GetExecutableFileVersion() const { @@ -340,7 +340,7 @@ std::string Browser::GetExecutableFileVersion() const { } std::string Browser::GetExecutableFileProductName() const { - return brightray::GetApplicationName(); + return GetApplicationName(); } } // namespace atom diff --git a/atom/browser/common_web_contents_delegate.h b/atom/browser/common_web_contents_delegate.h index 9481eddbac767..f8d9c7e9aa7fa 100644 --- a/atom/browser/common_web_contents_delegate.h +++ b/atom/browser/common_web_contents_delegate.h @@ -114,7 +114,7 @@ class CommonWebContentsDelegate : public content::WebContentsDelegate, void HideAutofillPopup(); #endif - // brightray::InspectableWebContentsDelegate: + // content::InspectableWebContentsDelegate: void DevToolsSaveToFile(const std::string& url, const std::string& content, bool save_as) override; @@ -133,7 +133,7 @@ class CommonWebContentsDelegate : public content::WebContentsDelegate, const std::string& file_system_path, const std::string& query) override; - // brightray::InspectableWebContentsViewDelegate: + // content::InspectableWebContentsViewDelegate: #if defined(TOOLKIT_VIEWS) && !defined(OS_MACOSX) gfx::ImageSkia GetDevToolsWindowIcon() override; #endif diff --git a/atom/browser/media/media_device_id_salt.cc b/atom/browser/media/media_device_id_salt.cc index 466c631364b69..f7fb66d1584fd 100644 --- a/atom/browser/media/media_device_id_salt.cc +++ b/atom/browser/media/media_device_id_salt.cc @@ -15,7 +15,7 @@ namespace atom { namespace { -const char kMediaDeviceIdSalt[] = "brightray.media.device_id_salt"; +const char kMediaDeviceIdSalt[] = "electron.media.device_id_salt"; } // namespace diff --git a/atom/browser/net/url_request_context_getter.cc b/atom/browser/net/url_request_context_getter.cc index 056fe8416640d..ec719e73b3c84 100644 --- a/atom/browser/net/url_request_context_getter.cc +++ b/atom/browser/net/url_request_context_getter.cc @@ -81,7 +81,7 @@ network::mojom::NetworkContextParamsPtr CreateDefaultNetworkContextParams( network_context_params->http_cache_enabled = use_cache; network_context_params->accept_language = net::HttpUtil::GenerateAcceptLanguageHeader( - brightray::BrowserClient::Get()->GetApplicationLocale()); + AtomBrowserClient::Get()->GetApplicationLocale()); network_context_params->enable_data_url_support = false; network_context_params->proxy_resolver_factory = ChromeMojoProxyResolverFactory::CreateWithStrongBinding().PassInterface(); diff --git a/atom/browser/notifications/linux/libnotify_notification.cc b/atom/browser/notifications/linux/libnotify_notification.cc index 26b65f13310e6..553057f03941e 100644 --- a/atom/browser/notifications/linux/libnotify_notification.cc +++ b/atom/browser/notifications/linux/libnotify_notification.cc @@ -9,12 +9,12 @@ #include #include "atom/browser/notifications/notification_delegate.h" +#include "atom/common/application_info.h" #include "atom/common/platform_util.h" #include "base/files/file_enumerator.h" #include "base/logging.h" #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" -#include "brightray/common/application_info.h" #include "chrome/browser/ui/libgtkui/gtk_util.h" #include "chrome/browser/ui/libgtkui/skia_utils_gtk.h" #include "third_party/skia/include/core/SkBitmap.h" @@ -66,7 +66,7 @@ bool LibnotifyNotification::Initialize() { return false; } if (!libnotify_loader_.notify_is_initted() && - !libnotify_loader_.notify_init(brightray::GetApplicationName().c_str())) { + !libnotify_loader_.notify_init(GetApplicationName().c_str())) { LOG(WARNING) << "Unable to initialize libnotify; notifications disabled"; return false; } diff --git a/atom/browser/notifications/win/windows_toast_notification.cc b/atom/browser/notifications/win/windows_toast_notification.cc index f1e210019bee9..c74326d752596 100644 --- a/atom/browser/notifications/win/windows_toast_notification.cc +++ b/atom/browser/notifications/win/windows_toast_notification.cc @@ -13,10 +13,10 @@ #include "atom/browser/notifications/notification_delegate.h" #include "atom/browser/notifications/win/notification_presenter_win.h" +#include "atom/browser/win/scoped_hstring.h" +#include "atom/common/application_info.h" #include "base/environment.h" #include "base/strings/utf_string_conversions.h" -#include "brightray/browser/win/scoped_hstring.h" -#include "brightray/common/application_info.h" #include "content/public/browser/browser_thread.h" using ABI::Windows::Data::Xml::Dom::IXmlAttribute; @@ -58,13 +58,13 @@ bool WindowsToastNotification::Initialize() { &toast_manager_))) return false; - if (brightray::IsRunningInDesktopBridge()) { + if (IsRunningInDesktopBridge()) { // Ironically, the Desktop Bridge / UWP environment // requires us to not give Windows an appUserModelId. return SUCCEEDED(toast_manager_->CreateToastNotifier(&toast_notifier_)); } else { ScopedHString app_id; - if (!brightray::GetAppUserModelID(&app_id)) + if (!GetAppUserModelID(&app_id)) return false; return SUCCEEDED( diff --git a/atom/browser/notifications/win/windows_toast_notification.h b/atom/browser/notifications/win/windows_toast_notification.h index 3d415a885abe5..7c15a60a5838b 100644 --- a/atom/browser/notifications/win/windows_toast_notification.h +++ b/atom/browser/notifications/win/windows_toast_notification.h @@ -23,10 +23,10 @@ using Microsoft::WRL::Make; using Microsoft::WRL::RuntimeClass; using Microsoft::WRL::RuntimeClassFlags; -class ScopedHString; - namespace atom { +class ScopedHString; + using DesktopToastActivatedEventHandler = ABI::Windows::Foundation::ITypedEventHandler< ABI::Windows::UI::Notifications::ToastNotification*, diff --git a/atom/browser/ui/cocoa/atom_inspectable_web_contents_view.mm b/atom/browser/ui/cocoa/atom_inspectable_web_contents_view.mm index 6d1fc8f250602..49e42fcc6e63b 100644 --- a/atom/browser/ui/cocoa/atom_inspectable_web_contents_view.mm +++ b/atom/browser/ui/cocoa/atom_inspectable_web_contents_view.mm @@ -150,7 +150,7 @@ - (void)setIsDocked:(BOOL)docked { backing:NSBackingStoreBuffered defer:YES]); [devtools_window_ setDelegate:self]; - [devtools_window_ setFrameAutosaveName:@"brightray.devtools"]; + [devtools_window_ setFrameAutosaveName:@"electron.devtools"]; [devtools_window_ setTitle:@"Developer Tools"]; [devtools_window_ setReleasedWhenClosed:NO]; [devtools_window_ setAutorecalculatesContentBorderThickness:NO diff --git a/atom/browser/ui/devtools_manager_delegate.cc b/atom/browser/ui/devtools_manager_delegate.cc index e5dd5d7e5d530..2361dfa83c13d 100644 --- a/atom/browser/ui/devtools_manager_delegate.cc +++ b/atom/browser/ui/devtools_manager_delegate.cc @@ -13,7 +13,6 @@ #include "base/strings/string_number_conversions.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" -#include "brightray/common/content_client.h" #include "content/public/browser/devtools_agent_host.h" #include "content/public/browser/devtools_frontend_host.h" #include "content/public/browser/devtools_socket_factory.h" diff --git a/atom/browser/ui/inspectable_web_contents_impl.cc b/atom/browser/ui/inspectable_web_contents_impl.cc index 9fc86a0b337a4..aa3e0d9cb498c 100644 --- a/atom/browser/ui/inspectable_web_contents_impl.cc +++ b/atom/browser/ui/inspectable_web_contents_impl.cc @@ -59,9 +59,9 @@ const char kChromeUIDevToolsRemoteFrontendBase[] = "https://chrome-devtools-frontend.appspot.com/"; const char kChromeUIDevToolsRemoteFrontendPath[] = "serve_file"; -const char kDevToolsBoundsPref[] = "brightray.devtools.bounds"; -const char kDevToolsZoomPref[] = "brightray.devtools.zoom"; -const char kDevToolsPreferences[] = "brightray.devtools.preferences"; +const char kDevToolsBoundsPref[] = "electron.devtools.bounds"; +const char kDevToolsZoomPref[] = "electron.devtools.zoom"; +const char kDevToolsPreferences[] = "electron.devtools.preferences"; const char kFrontendHostId[] = "id"; const char kFrontendHostMethod[] = "method"; diff --git a/atom/browser/ui/tray_icon_gtk.cc b/atom/browser/ui/tray_icon_gtk.cc index 4c780285c80a1..a1eb3b32b11cc 100644 --- a/atom/browser/ui/tray_icon_gtk.cc +++ b/atom/browser/ui/tray_icon_gtk.cc @@ -5,9 +5,9 @@ #include "atom/browser/ui/tray_icon_gtk.h" #include "atom/browser/browser.h" +#include "atom/common/application_info.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" -#include "brightray/common/application_info.h" #include "chrome/browser/ui/libgtkui/app_indicator_icon.h" #include "chrome/browser/ui/libgtkui/gtk_status_icon.h" #include "ui/gfx/image/image.h" @@ -31,7 +31,7 @@ void TrayIconGtk::SetImage(const gfx::Image& image) { return; } - const auto toolTip = base::UTF8ToUTF16(brightray::GetApplicationName()); + const auto toolTip = base::UTF8ToUTF16(GetApplicationName()); if (libgtkui::AppIndicatorIcon::CouldOpen()) { ++indicators_count; diff --git a/brightray/browser/win/scoped_hstring.cc b/atom/browser/win/scoped_hstring.cc similarity index 90% rename from brightray/browser/win/scoped_hstring.cc rename to atom/browser/win/scoped_hstring.cc index 6c9e0a3ec787c..437e45f5123f5 100644 --- a/brightray/browser/win/scoped_hstring.cc +++ b/atom/browser/win/scoped_hstring.cc @@ -2,10 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-CHROMIUM file. -#include "brightray/browser/win/scoped_hstring.h" +#include "atom/browser/win/scoped_hstring.h" #include +namespace atom { + ScopedHString::ScopedHString(const wchar_t* source) : str_(nullptr) { Reset(source); } @@ -36,3 +38,5 @@ void ScopedHString::Reset(const std::wstring& source) { Reset(); WindowsCreateString(source.c_str(), source.length(), &str_); } + +} // namespace atom diff --git a/brightray/browser/win/scoped_hstring.h b/atom/browser/win/scoped_hstring.h similarity index 82% rename from brightray/browser/win/scoped_hstring.h rename to atom/browser/win/scoped_hstring.h index 879e62cd39b89..2b4b8658ce43b 100644 --- a/brightray/browser/win/scoped_hstring.h +++ b/atom/browser/win/scoped_hstring.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-CHROMIUM file. -#ifndef BRIGHTRAY_BROWSER_WIN_SCOPED_HSTRING_H_ -#define BRIGHTRAY_BROWSER_WIN_SCOPED_HSTRING_H_ +#ifndef ATOM_BROWSER_WIN_SCOPED_HSTRING_H_ +#define ATOM_BROWSER_WIN_SCOPED_HSTRING_H_ #include #include @@ -12,6 +12,8 @@ #include "base/macros.h" +namespace atom { + class ScopedHString { public: // Copy from |source|. @@ -38,4 +40,6 @@ class ScopedHString { DISALLOW_COPY_AND_ASSIGN(ScopedHString); }; -#endif // BRIGHTRAY_BROWSER_WIN_SCOPED_HSTRING_H_ +} // namespace atom + +#endif // ATOM_BROWSER_WIN_SCOPED_HSTRING_H_ diff --git a/atom/common/api/atom_bindings.cc b/atom/common/api/atom_bindings.cc index 51a85c1297ba6..5590797d4ea34 100644 --- a/atom/common/api/atom_bindings.cc +++ b/atom/common/api/atom_bindings.cc @@ -9,6 +9,7 @@ #include #include "atom/common/api/locker.h" +#include "atom/common/application_info.h" #include "atom/common/atom_version.h" #include "atom/common/chrome_version.h" #include "atom/common/heap_snapshot.h" @@ -20,7 +21,6 @@ #include "base/process/process_metrics_iocounters.h" #include "base/sys_info.h" #include "base/threading/thread_restrictions.h" -#include "brightray/common/application_info.h" #include "native_mate/dictionary.h" namespace atom { @@ -76,7 +76,7 @@ void AtomBindings::BindTo(v8::Isolate* isolate, v8::Local process) { #endif #if defined(OS_WIN) - if (brightray::IsRunningInDesktopBridge()) + if (IsRunningInDesktopBridge()) dict.Set("windowsStore", true); #endif diff --git a/brightray/common/application_info.cc b/atom/common/application_info.cc similarity index 73% rename from brightray/common/application_info.cc rename to atom/common/application_info.cc index 728c8dcdf6d52..53a1b0a52dcfb 100644 --- a/brightray/common/application_info.cc +++ b/atom/common/application_info.cc @@ -1,8 +1,12 @@ -#include "brightray/common/application_info.h" +// Copyright (c) 2013 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#include "atom/common/application_info.h" #include "base/no_destructor.h" -namespace brightray { +namespace atom { namespace { @@ -27,4 +31,4 @@ std::string GetOverriddenApplicationVersion() { return *g_overridden_application_version; } -} // namespace brightray +} // namespace atom diff --git a/brightray/common/application_info.h b/atom/common/application_info.h similarity index 61% rename from brightray/common/application_info.h rename to atom/common/application_info.h index b11893f51ccf2..6243f288682cc 100644 --- a/brightray/common/application_info.h +++ b/atom/common/application_info.h @@ -1,14 +1,18 @@ -#ifndef BRIGHTRAY_COMMON_APPLICATION_INFO_H_ -#define BRIGHTRAY_COMMON_APPLICATION_INFO_H_ +// Copyright (c) 2013 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#ifndef ATOM_COMMON_APPLICATION_INFO_H_ +#define ATOM_COMMON_APPLICATION_INFO_H_ #if defined(OS_WIN) +#include "atom/browser/win/scoped_hstring.h" #include "base/strings/string16.h" -#include "brightray/browser/win/scoped_hstring.h" #endif #include -namespace brightray { +namespace atom { void OverrideApplicationName(const std::string& name); std::string GetOverriddenApplicationName(); @@ -26,6 +30,6 @@ void SetAppUserModelID(const base::string16& name); bool IsRunningInDesktopBridge(); #endif -} // namespace brightray +} // namespace atom -#endif // BRIGHTRAY_COMMON_APPLICATION_INFO_H_ +#endif // ATOM_COMMON_APPLICATION_INFO_H_ diff --git a/atom/common/linux/application_info.cc b/atom/common/application_info_linux.cc similarity index 94% rename from atom/common/linux/application_info.cc rename to atom/common/application_info_linux.cc index 89a3185de46f6..ea69acad12887 100644 --- a/atom/common/linux/application_info.cc +++ b/atom/common/application_info_linux.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by the MIT license that can be // found in the LICENSE file. -#include "brightray/common/application_info.h" +#include "atom/common/application_info.h" #include #include @@ -30,7 +30,7 @@ GDesktopAppInfo* get_desktop_app_info() { } // namespace -namespace brightray { +namespace atom { std::string GetApplicationName() { // attempt #1: the string set in app.setName() @@ -76,4 +76,4 @@ std::string GetApplicationVersion() { return ret; } -} // namespace brightray +} // namespace atom diff --git a/brightray/common/application_info_mac.mm b/atom/common/application_info_mac.mm similarity index 70% rename from brightray/common/application_info_mac.mm rename to atom/common/application_info_mac.mm index 63db8c9b4c7df..163d0e22c75e9 100644 --- a/brightray/common/application_info_mac.mm +++ b/atom/common/application_info_mac.mm @@ -1,10 +1,14 @@ -#import "brightray/common/application_info.h" +// Copyright (c) 2013 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. +#import "atom/common/application_info.h" + +#import "atom/common/mac/main_application_bundle.h" #import "base/mac/foundation_util.h" #import "base/strings/sys_string_conversions.h" -#import "brightray/common/mac/main_application_bundle.h" -namespace brightray { +namespace atom { namespace { @@ -27,4 +31,4 @@ return ApplicationInfoDictionaryValue(@"CFBundleShortVersionString"); } -} // namespace brightray +} // namespace atom diff --git a/brightray/common/application_info_win.cc b/atom/common/application_info_win.cc similarity index 92% rename from brightray/common/application_info_win.cc rename to atom/common/application_info_win.cc index abd28eee4fd57..a6f4e939f49a3 100644 --- a/brightray/common/application_info_win.cc +++ b/atom/common/application_info_win.cc @@ -1,4 +1,8 @@ -#include "brightray/common/application_info.h" +// Copyright (c) 2013 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#include "atom/common/application_info.h" #include // windows.h must be included first @@ -8,13 +12,13 @@ #include +#include "atom/browser/win/scoped_hstring.h" #include "base/file_version_info.h" #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" -#include "brightray/browser/win/scoped_hstring.h" -namespace brightray { +namespace atom { namespace { @@ -106,4 +110,4 @@ bool IsRunningInDesktopBridge() { return result; } -} // namespace brightray +} // namespace atom diff --git a/atom/common/mac/main_application_bundle.h b/atom/common/mac/main_application_bundle.h new file mode 100644 index 0000000000000..ab1ea6d614daf --- /dev/null +++ b/atom/common/mac/main_application_bundle.h @@ -0,0 +1,26 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright (c) 2013 Adam Roben . 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 ATOM_COMMON_MAC_MAIN_APPLICATION_BUNDLE_H_ +#define ATOM_COMMON_MAC_MAIN_APPLICATION_BUNDLE_H_ + +@class NSBundle; + +namespace base { +class FilePath; +} + +namespace atom { + +// The "main" application bundle is the outermost bundle for this logical +// application. E.g., if you have MyApp.app and +// MyApp.app/Contents/Frameworks/MyApp Helper.app, the main application bundle +// is MyApp.app, no matter which executable is currently running. +NSBundle* MainApplicationBundle(); +base::FilePath MainApplicationBundlePath(); + +} // namespace atom + +#endif // ATOM_COMMON_MAC_MAIN_APPLICATION_BUNDLE_H_ diff --git a/brightray/common/mac/main_application_bundle.mm b/atom/common/mac/main_application_bundle.mm similarity index 94% rename from brightray/common/mac/main_application_bundle.mm rename to atom/common/mac/main_application_bundle.mm index 9a26b079f59ef..6971424e9cd8a 100644 --- a/brightray/common/mac/main_application_bundle.mm +++ b/atom/common/mac/main_application_bundle.mm @@ -3,7 +3,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE-CHROMIUM file. -#import "brightray/common/mac/main_application_bundle.h" +#import "atom/common/mac/main_application_bundle.h" #include "base/files/file_path.h" #include "base/mac/bundle_locations.h" @@ -11,7 +11,7 @@ #include "base/path_service.h" #include "base/strings/string_util.h" -namespace brightray { +namespace atom { namespace { @@ -53,4 +53,4 @@ bool HasMainProcessKey() { MainApplicationBundlePath())]; } -} // namespace brightray +} // namespace atom diff --git a/atom/renderer/atom_sandboxed_renderer_client.cc b/atom/renderer/atom_sandboxed_renderer_client.cc index 688f33bc165b0..db05f967188c5 100644 --- a/atom/renderer/atom_sandboxed_renderer_client.cc +++ b/atom/renderer/atom_sandboxed_renderer_client.cc @@ -6,6 +6,7 @@ #include "atom/common/api/api_messages.h" #include "atom/common/api/atom_bindings.h" +#include "atom/common/application_info.h" #include "atom/common/native_mate_converters/string16_converter.h" #include "atom/common/native_mate_converters/value_converter.h" #include "atom/common/node_bindings.h" @@ -17,7 +18,6 @@ #include "base/files/file_path.h" #include "base/path_service.h" #include "base/process/process_handle.h" -#include "brightray/common/application_info.h" #include "content/public/renderer/render_frame.h" #include "native_mate/dictionary.h" #include "third_party/blink/public/web/blink.h" @@ -168,7 +168,7 @@ void AtomSandboxedRendererClient::InitializeBindings( #endif #if defined(OS_WIN) - if (brightray::IsRunningInDesktopBridge()) + if (IsRunningInDesktopBridge()) process.Set("windowsStore", true); #endif diff --git a/brightray/CPPLINT.cfg b/brightray/CPPLINT.cfg deleted file mode 100644 index 88c6f99113d51..0000000000000 --- a/brightray/CPPLINT.cfg +++ /dev/null @@ -1 +0,0 @@ -filter=-legal/copyright diff --git a/brightray/LICENSE b/brightray/LICENSE deleted file mode 100644 index fe24a3c65fbd7..0000000000000 --- a/brightray/LICENSE +++ /dev/null @@ -1,19 +0,0 @@ -Copyright (c) 2013-2014 Adam Roben - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the "Software"), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/brightray/LICENSE-CHROMIUM b/brightray/LICENSE-CHROMIUM deleted file mode 100644 index 3d0f7d3edfd81..0000000000000 --- a/brightray/LICENSE-CHROMIUM +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2013 The Chromium Authors. All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/brightray/browser/browser_main_parts.h b/brightray/browser/browser_main_parts.h deleted file mode 100644 index 505689e6704c8..0000000000000 --- a/brightray/browser/browser_main_parts.h +++ /dev/null @@ -1,62 +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_BROWSER_BROWSER_MAIN_PARTS_H_ -#define BRIGHTRAY_BROWSER_BROWSER_MAIN_PARTS_H_ - -#include -#include - -#include "base/compiler_specific.h" -#include "base/macros.h" -#include "base/path_service.h" -#include "brightray/browser/brightray_paths.h" -#include "content/public/browser/browser_main_parts.h" -#include "ui/views/layout/layout_provider.h" - -#if defined(USE_AURA) -namespace wm { -class WMState; -} -#endif - -namespace brightray { - -class BrowserMainParts : public content::BrowserMainParts { - public: - BrowserMainParts(); - ~BrowserMainParts() override; - - protected: - // content::BrowserMainParts: - bool ShouldContentCreateFeatureList() override; - int PreEarlyInitialization() override; - void ToolkitInitialized() override; - void PreMainMessageLoopStart() override; - void PostMainMessageLoopStart() override; - void PostMainMessageLoopRun() override; - int PreCreateThreads() override; - void PostDestroyThreads() override; - - void InitializeFeatureList(); - - private: -#if defined(OS_MACOSX) - void InitializeMainNib(); - void OverrideAppLogsPath(); -#endif - -#if defined(USE_AURA) - std::unique_ptr wm_state_; -#endif - - std::unique_ptr layout_provider_; - std::string custom_locale_; - - DISALLOW_COPY_AND_ASSIGN(BrowserMainParts); -}; - -} // namespace brightray - -#endif // BRIGHTRAY_BROWSER_BROWSER_MAIN_PARTS_H_ diff --git a/brightray/browser/browser_main_parts_mac.mm b/brightray/browser/browser_main_parts_mac.mm deleted file mode 100644 index b0deae60828c9..0000000000000 --- a/brightray/browser/browser_main_parts_mac.mm +++ /dev/null @@ -1,37 +0,0 @@ -#import "brightray/browser/browser_main_parts.h" - -#import -#import "base/logging.h" -#import "base/mac/bundle_locations.h" - -namespace brightray { - -void BrowserMainParts::OverrideAppLogsPath() { - base::FilePath path; - NSString* bundleName = - [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]; - NSString* logsPath = - [NSString stringWithFormat:@"Library/Logs/%@", bundleName]; - NSString* libraryPath = - [NSHomeDirectory() stringByAppendingPathComponent:logsPath]; - - base::PathService::Override(DIR_APP_LOGS, - base::FilePath([libraryPath UTF8String])); -} - -// Replicates NSApplicationMain, but doesn't start a run loop. -void BrowserMainParts::InitializeMainNib() { - auto infoDictionary = base::mac::OuterBundle().infoDictionary; - - auto principalClass = - NSClassFromString([infoDictionary objectForKey:@"NSPrincipalClass"]); - auto application = [principalClass sharedApplication]; - - NSString* mainNibName = [infoDictionary objectForKey:@"NSMainNibFile"]; - auto mainNib = [[NSNib alloc] initWithNibNamed:mainNibName - bundle:base::mac::FrameworkBundle()]; - [mainNib instantiateWithOwner:application topLevelObjects:nil]; - [mainNib release]; -} - -} // namespace brightray diff --git a/brightray/common/content_client.cc b/brightray/common/content_client.cc deleted file mode 100644 index 2a8331c53cec4..0000000000000 --- a/brightray/common/content_client.cc +++ /dev/null @@ -1,61 +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/content_client.h" - -#include "base/strings/string_util.h" -#include "base/strings/stringprintf.h" -#include "brightray/common/application_info.h" -#include "content/public/common/user_agent.h" -#include "ui/base/l10n/l10n_util.h" -#include "ui/base/resource/resource_bundle.h" - -namespace brightray { - -std::string GetProductInternal() { - auto name = GetApplicationName(); - base::RemoveChars(name, base::kWhitespaceASCII, &name); - return base::StringPrintf("%s/%s", name.c_str(), - GetApplicationVersion().c_str()); -} - -std::string GetBrightrayUserAgent() { - return content::BuildUserAgentFromProduct(GetProductInternal()); -} - -ContentClient::ContentClient() {} - -ContentClient::~ContentClient() {} - -std::string ContentClient::GetProduct() const { - return GetProductInternal(); -} - -std::string ContentClient::GetUserAgent() const { - return GetBrightrayUserAgent(); -} - -base::string16 ContentClient::GetLocalizedString(int message_id) const { - return l10n_util::GetStringUTF16(message_id); -} - -base::StringPiece ContentClient::GetDataResource( - int resource_id, - ui::ScaleFactor scale_factor) const { - return ui::ResourceBundle::GetSharedInstance().GetRawDataResourceForScale( - resource_id, scale_factor); -} - -gfx::Image& ContentClient::GetNativeImageNamed(int resource_id) const { - return ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( - resource_id); -} - -base::RefCountedMemory* ContentClient::GetDataResourceBytes( - int resource_id) const { - return ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytes( - resource_id); -} - -} // namespace brightray diff --git a/brightray/common/content_client.h b/brightray/common/content_client.h deleted file mode 100644 index 0089ebc9d8106..0000000000000 --- a/brightray/common/content_client.h +++ /dev/null @@ -1,36 +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_CONTENT_CLIENT_H_ -#define BRIGHTRAY_COMMON_CONTENT_CLIENT_H_ - -#include - -#include "base/compiler_specific.h" -#include "content/public/common/content_client.h" - -namespace brightray { - -std::string GetBrightrayUserAgent(); - -class ContentClient : public content::ContentClient { - public: - ContentClient(); - ~ContentClient() override; - - private: - 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; - - DISALLOW_COPY_AND_ASSIGN(ContentClient); -}; - -} // namespace brightray - -#endif // BRIGHTRAY_COMMON_CONTENT_CLIENT_H_ diff --git a/brightray/common/mac/main_application_bundle.h b/brightray/common/mac/main_application_bundle.h deleted file mode 100644 index 555738023cfd6..0000000000000 --- a/brightray/common/mac/main_application_bundle.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef BRIGHTRAY_COMMON_MAC_MAIN_APPLICATION_BUNDLE_H_ -#define BRIGHTRAY_COMMON_MAC_MAIN_APPLICATION_BUNDLE_H_ - -@class NSBundle; - -namespace base { -class FilePath; -} - -namespace brightray { - -// The "main" application bundle is the outermost bundle for this logical -// application. E.g., if you have MyApp.app and -// MyApp.app/Contents/Frameworks/MyApp Helper.app, the main application bundle -// is MyApp.app, no matter which executable is currently running. -NSBundle* MainApplicationBundle(); -base::FilePath MainApplicationBundlePath(); - -} // namespace brightray - -#endif // BRIGHTRAY_COMMON_MAC_MAIN_APPLICATION_BUNDLE_H_ diff --git a/brightray/common/main_delegate.cc b/brightray/common/main_delegate.cc deleted file mode 100644 index 942e8b3504dd4..0000000000000 --- a/brightray/common/main_delegate.cc +++ /dev/null @@ -1,116 +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 - -#include "base/command_line.h" -#include "base/mac/bundle_locations.h" -#include "base/path_service.h" -#include "brightray/browser/browser_client.h" -#include "brightray/common/content_client.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() {} - -std::unique_ptr MainDelegate::CreateContentClient() { - return std::unique_ptr(new ContentClient); -} - -bool MainDelegate::BasicStartupComplete(int* exit_code) { - content_client_ = CreateContentClient(); - SetContentClient(content_client_.get()); -#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); - } -} - -content::ContentBrowserClient* MainDelegate::CreateContentBrowserClient() { - browser_client_ = CreateBrowserClient(); - return browser_client_.get(); -} - -std::unique_ptr MainDelegate::CreateBrowserClient() { - return std::unique_ptr(new BrowserClient); -} - -} // namespace brightray diff --git a/brightray/common/main_delegate.h b/brightray/common/main_delegate.h deleted file mode 100644 index 3160f9b252cf4..0000000000000 --- a/brightray/common/main_delegate.h +++ /dev/null @@ -1,65 +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 -#include - -#include "base/macros.h" -#include "content/public/app/content_main_delegate.h" - -namespace base { -class FilePath; -} - -namespace ui { -class ResourceBundle; -} - -namespace brightray { - -class BrowserClient; -class ContentClient; - -void LoadResourceBundle(const std::string& locale); -void LoadCommonResources(); - -class MainDelegate : public content::ContentMainDelegate { - public: - MainDelegate(); - ~MainDelegate() override; - - protected: - // Subclasses can override this to provide their own ContentClient - // implementation. - virtual std::unique_ptr CreateContentClient(); - - // Subclasses can override this to provide their own BrowserClient - // implementation. - virtual std::unique_ptr CreateBrowserClient(); - -#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: - content::ContentBrowserClient* CreateContentBrowserClient() override; - - std::unique_ptr content_client_; - std::unique_ptr browser_client_; - - DISALLOW_COPY_AND_ASSIGN(MainDelegate); -}; - -} // namespace brightray - -#endif // BRIGHTRAY_COMMON_MAIN_DELEGATE_H_ diff --git a/brightray/common/main_delegate_mac.mm b/brightray/common/main_delegate_mac.mm deleted file mode 100644 index e91a65ba4ce90..0000000000000 --- a/brightray/common/main_delegate_mac.mm +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Copyright (c) 2013 Adam Roben . 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 diff --git a/docs/development/build-system-overview.md b/docs/development/build-system-overview.md index 1983de07ec1c9..881e4cc653fd4 100644 --- a/docs/development/build-system-overview.md +++ b/docs/development/build-system-overview.md @@ -8,8 +8,7 @@ be found in the `.gn` and `.gni` files. The following `gn` files contain the main rules for building Electron: -* `BUILD.gn` defines how Electron itself is built. -* `brightray/BUILD.gn` defines how `brightray` is built and +* `BUILD.gn` defines how Electron itself is built and includes the default configurations for linking with Chromium. * `build/args/{debug,release,all}.gn` contain the default build arguments for building Electron. diff --git a/docs/development/debug-instructions-windows.md b/docs/development/debug-instructions-windows.md index 93f0ec7e2ea32..c2d79003cec78 100644 --- a/docs/development/debug-instructions-windows.md +++ b/docs/development/debug-instructions-windows.md @@ -48,8 +48,7 @@ still set breakpoints - Visual Studio will automatically figure out that the source code matches the code running in the attached process and break accordingly. -Relevant code files can be found in `./atom/` as well as in Brightray, found in -`./brightray/browser` and `./brightray/common`. +Relevant code files can be found in `./atom/`. ### Attaching diff --git a/docs/development/debugging-instructions-macos.md b/docs/development/debugging-instructions-macos.md index cf31b7184933d..630ab12113871 100644 --- a/docs/development/debugging-instructions-macos.md +++ b/docs/development/debugging-instructions-macos.md @@ -41,8 +41,7 @@ this basic introduction, let's assume that you're calling a command from JavaScr that isn't behaving correctly - so you'd like to break on that command's C++ counterpart inside the Electron source. -Relevant code files can be found in `./atom/` as well as in Brightray, found in -`./brightray/browser` and `./brightray/common`. +Relevant code files can be found in `./atom/`. Let's assume that you want to debug `app.setName()`, which is defined in `browser.cc` as `Browser::SetName()`. Set the breakpoint using the `breakpoint` command, specifying diff --git a/docs/development/pull-requests.md b/docs/development/pull-requests.md index 4af63ababded4..19960889ff956 100644 --- a/docs/development/pull-requests.md +++ b/docs/development/pull-requests.md @@ -55,7 +55,7 @@ $ git checkout -b my-branch -t upstream/master ### Step 4: Code Most pull requests opened against the `electron/electron` repository include -changes to either the C/C++ code in the `atom/` or `brightray/` folders, +changes to either the C/C++ code in the `atom/` folder, the JavaScript code in the `lib/` folder, the documentation in `docs/api/` or tests in the `spec/` folder. diff --git a/docs/development/source-code-directory-structure.md b/docs/development/source-code-directory-structure.md index c009c53465cff..5a0369c4a32e4 100644 --- a/docs/development/source-code-directory-structure.md +++ b/docs/development/source-code-directory-structure.md @@ -31,7 +31,6 @@ Electron | | message loop into Chromium's message loop. | └── api/ - The implementation of common APIs, and foundations of | Electron's built-in modules. -├── brightray/ - Thin shim over libcc that makes it easier to use. ├── chromium_src/ - Source code copied from Chromium. See below. ├── default_app/ - The default page to show when Electron is started without | providing an app. diff --git a/docs/glossary.md b/docs/glossary.md index da1ddd28f1def..dab5b97b3fc2f 100644 --- a/docs/glossary.md +++ b/docs/glossary.md @@ -10,12 +10,6 @@ arbitrary files from it without unpacking the whole file. The ASAR format was created primarily to improve performance on Windows... TODO -### Brightray - -Brightray [was](https://github.com/electron-archive/brightray) a static library -that made [libchromiumcontent] easier to use in applications. It is now -deprecated and has been merged into Electron's codebase. - ### CRT The C Run-time Library (CRT) is the part of the C++ Standard Library that @@ -74,7 +68,7 @@ MAS, see the [Mac App Store Submission Guide]. ### Mojo -An IPC system for communicating intra- or inter-process, and that's important because Chrome is keen on being able to split its work into separate processes or not, depending on memory pressures etc. +An IPC system for communicating intra- or inter-process, and that's important because Chrome is keen on being able to split its work into separate processes or not, depending on memory pressures etc. See https://chromium.googlesource.com/chromium/src/+/master/mojo/README.md diff --git a/filenames.gni b/filenames.gni index 1a6d2e65c8a5e..e47ef084c4b29 100644 --- a/filenames.gni +++ b/filenames.gni @@ -222,6 +222,7 @@ filenames = { "atom/browser/atom_javascript_dialog_manager.h", "atom/browser/atom_navigation_throttle.h", "atom/browser/atom_navigation_throttle.cc", + "atom/browser/atom_paths.h", "atom/browser/atom_permission_manager.cc", "atom/browser/atom_permission_manager.h", "atom/browser/atom_quota_permission_context.cc", @@ -495,6 +496,8 @@ filenames = { "atom/browser/ui/x/x_window_utils.h", "atom/browser/unresponsive_suppressor.cc", "atom/browser/unresponsive_suppressor.h", + "atom/browser/win/scoped_hstring.cc", + "atom/browser/win/scoped_hstring.h", "atom/browser/web_contents_permission_helper.cc", "atom/browser/web_contents_permission_helper.h", "atom/browser/web_contents_preferences.cc", @@ -544,6 +547,11 @@ filenames = { "atom/common/asar/asar_util.h", "atom/common/asar/scoped_temporary_file.cc", "atom/common/asar/scoped_temporary_file.h", + "atom/common/application_info_linux.cc", + "atom/common/application_info_mac.mm", + "atom/common/application_info_win.cc", + "atom/common/application_info.cc", + "atom/common/application_info.h", "atom/common/atom_command_line.cc", "atom/common/atom_command_line.h", "atom/common/atom_constants.cc", @@ -576,7 +584,8 @@ filenames = { "atom/common/keyboard_util.h", "atom/common/mouse_util.cc", "atom/common/mouse_util.h", - "atom/common/linux/application_info.cc", + "atom/common/mac/main_application_bundle.h", + "atom/common/mac/main_application_bundle.mm", "atom/common/native_mate_converters/accelerator_converter.cc", "atom/common/native_mate_converters/accelerator_converter.h", "atom/common/native_mate_converters/blink_converter.cc", diff --git a/package.json b/package.json index 65b0768bda7f5..cff865db05dfd 100644 --- a/package.json +++ b/package.json @@ -43,10 +43,10 @@ "browserify": "browserify", "bump-version": "./script/bump-version.py", "check-tls": "python ./script/tls.py", - "clang-format": "find atom/ brightray/ chromium_src/ -iname *.h -o -iname *.cc -o -iname *.mm | xargs clang-format -i", + "clang-format": "find atom/ chromium_src/ -iname *.h -o -iname *.cc -o -iname *.mm | xargs clang-format -i", "lint": "node ./script/lint.js && npm run lint:clang-format && npm run lint:docs", "lint:js": "node ./script/lint.js --js", - "lint:clang-format": "python script/run-clang-format.py -r -c atom/ chromium_src/ brightray/ || (echo \"\\nCode not formatted correctly.\" && exit 1)", + "lint:clang-format": "python script/run-clang-format.py -r -c atom/ chromium_src/ || (echo \"\\nCode not formatted correctly.\" && exit 1)", "lint:cpp": "node ./script/lint.js --cc", "lint:py": "node ./script/lint.js --py", "lint:gn": "node ./script/lint.js --gn", @@ -56,7 +56,7 @@ "create-api-json": "electron-docs-linter docs --outfile=electron-api.json", "create-typescript-definitions": "npm run create-api-json && electron-typescript-definitions --in=electron-api.json --out=electron.d.ts", "preinstall": "node -e 'process.exit(0)'", - "precommit": "python script/run-clang-format.py -r -c atom/ chromium_src/ brightray/ && node ./script/lint.js -c && remark docs -qf || (echo \"Code not formatted correctly.\" && exit 1)", + "precommit": "python script/run-clang-format.py -r -c atom/ chromium_src/ && node ./script/lint.js -c && remark docs -qf || (echo \"Code not formatted correctly.\" && exit 1)", "prepack": "check-for-leaks", "prepush": "check-for-leaks", "repl": "node ./script/start.js --interactive", diff --git a/patches/common/chromium/.patches.yaml b/patches/common/chromium/.patches.yaml index f4a0a020260f9..bc7e0eb65a6f7 100644 --- a/patches/common/chromium/.patches.yaml +++ b/patches/common/chromium/.patches.yaml @@ -261,7 +261,7 @@ patches: author: Jeremy Apthorp file: gtk_visibility.patch description: | - Allow electron and brightray to depend on GTK in the GN build. + Allow electron to depend on GTK in the GN build. - author: Jeremy Apthorp file: sysroot.patch diff --git a/patches/common/chromium/gtk_visibility.patch b/patches/common/chromium/gtk_visibility.patch index e9a0028887166..80cb06f871ffe 100644 --- a/patches/common/chromium/gtk_visibility.patch +++ b/patches/common/chromium/gtk_visibility.patch @@ -3,21 +3,20 @@ From: Jeremy Apthorp Date: Thu, 20 Sep 2018 17:48:38 -0700 Subject: gtk_visibility.patch -Allow electron and brightray to depend on GTK in the GN build. +Allow electron to depend on GTK in the GN build. diff --git a/build/config/linux/gtk/BUILD.gn b/build/config/linux/gtk/BUILD.gn -index deae4d3455a8..fd5d906b98b0 100644 +index deae4d3455a8..5f5db2fd6e5e 100644 --- a/build/config/linux/gtk/BUILD.gn +++ b/build/config/linux/gtk/BUILD.gn -@@ -18,6 +18,8 @@ group("gtk") { +@@ -18,6 +18,7 @@ group("gtk") { visibility = [ "//chrome/test:interactive_ui_tests", "//chrome/test:unit_tests", + "//electron:*", -+ "//electron/brightray:*", "//examples:peerconnection_client", "//gpu/gles2_conform_support:gles2_conform_test_windowless", "//remoting/host", --- +-- 2.17.0 diff --git a/script/lint.js b/script/lint.js index c8a79811bc234..a95134de115b7 100755 --- a/script/lint.js +++ b/script/lint.js @@ -40,7 +40,7 @@ function spawnAndCheckExitCode (cmd, args, opts) { const LINTERS = [ { key: 'c++', - roots: ['atom', 'brightray'], + roots: ['atom'], test: filename => filename.endsWith('.cc') || filename.endsWith('.h'), run: (opts, filenames) => { if (opts.fix) {