-// Copyright (c) 2013 GitHub, Inc.\r
-// Use of this source code is governed by the MIT license that can be\r
-// found in the LICENSE file.\r
-\r
-#include "atom/app/atom_main_delegate.h"\r
-\r
-#include <string>\r
-#include <iostream>\r
-\r
-#include "atom/app/atom_content_client.h"\r
-#include "atom/browser/atom_browser_client.h"\r
-#include "atom/browser/relauncher.h"\r
-#include "atom/common/google_api_key.h"\r
-#include "atom/renderer/atom_renderer_client.h"\r
-#include "atom/utility/atom_content_utility_client.h"\r
-#include "base/command_line.h"\r
-#include "base/debug/stack_trace.h"\r
-#include "base/environment.h"\r
-#include "base/logging.h"\r
-#include "chrome/common/chrome_paths.h"\r
-#include "content/public/common/content_switches.h"\r
-#include "ui/base/l10n/l10n_util.h"\r
-#include "ui/base/resource/resource_bundle.h"\r
-\r
-namespace atom {\r
-\r
-namespace {\r
-\r
-const char* kRelauncherProcess = "relauncher";\r
-\r
-bool IsBrowserProcess(base::CommandLine* cmd) {\r
- std::string process_type = cmd->GetSwitchValueASCII(switches::kProcessType);\r
- return process_type.empty();\r
-}\r
-\r
-#if defined(OS_WIN)\r
-void InvalidParameterHandler(const wchar_t*, const wchar_t*, const wchar_t*,\r
- unsigned int, uintptr_t) {\r
- // noop.\r
-}\r
-#endif\r
-\r
-} // namespace\r
-\r
-AtomMainDelegate::AtomMainDelegate() {\r
-}\r
-\r
-AtomMainDelegate::~AtomMainDelegate() {\r
-}\r
-\r
-bool AtomMainDelegate::BasicStartupComplete(int* exit_code) {\r
- auto command_line = base::CommandLine::ForCurrentProcess();\r
-\r
- logging::LoggingSettings settings;\r
-#if defined(OS_WIN)\r
- // On Windows the terminal returns immediately, so we add a new line to\r
- // prevent output in the same line as the prompt.\r
- if (IsBrowserProcess(command_line))\r
- std::wcout << std::endl;\r
-#if defined(DEBUG)\r
- // Print logging to debug.log on Windows\r
- settings.logging_dest = logging::LOG_TO_ALL;\r
- settings.log_file = L"debug.log";\r
- settings.lock_log = logging::LOCK_LOG_FILE;\r
- settings.delete_old = logging::DELETE_OLD_LOG_FILE;\r
-#else\r
- settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;\r
-#endif // defined(DEBUG)\r
-#else // defined(OS_WIN)\r
- settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;\r
-#endif // !defined(OS_WIN)\r
-\r
- // Only enable logging when --enable-logging is specified.\r
- std::unique_ptr<base::Environment> env(base::Environment::Create());\r
- if (!command_line->HasSwitch(switches::kEnableLogging) &&\r
- !env->HasVar("ELECTRON_ENABLE_LOGGING")) {\r
- settings.logging_dest = logging::LOG_NONE;\r
- logging::SetMinLogLevel(logging::LOG_NUM_SEVERITIES);\r
- }\r
-\r
- logging::InitLogging(settings);\r
-\r
- // Logging with pid and timestamp.\r
- logging::SetLogItems(true, false, true, false);\r
-\r
- // Enable convient stack printing.\r
- bool enable_stack_dumping = env->HasVar("ELECTRON_ENABLE_STACK_DUMPING");\r
-#if defined(DEBUG) && defined(OS_LINUX)\r
- enable_stack_dumping = true;\r
-#endif\r
- if (enable_stack_dumping)\r
- base::debug::EnableInProcessStackDumping();\r
-\r
- chrome::RegisterPathProvider();\r
-\r
-#if defined(OS_MACOSX)\r
- SetUpBundleOverrides();\r
-#endif\r
-\r
-#if defined(OS_WIN)\r
- // Ignore invalid parameter errors.\r
- _set_invalid_parameter_handler(InvalidParameterHandler);\r
-#endif\r
-\r
- return brightray::MainDelegate::BasicStartupComplete(exit_code);\r
-}\r
-\r
-void AtomMainDelegate::PreSandboxStartup() {\r
- brightray::MainDelegate::PreSandboxStartup();\r
-\r
- // Set google API key.\r
- std::unique_ptr<base::Environment> env(base::Environment::Create());\r
- if (!env->HasVar("GOOGLE_API_KEY"))\r
- env->SetVar("GOOGLE_API_KEY", GOOGLEAPIS_API_KEY);\r
-\r
- auto command_line = base::CommandLine::ForCurrentProcess();\r
- std::string process_type = command_line->GetSwitchValueASCII(\r
- switches::kProcessType);\r
-\r
- // Only append arguments for browser process.\r
- if (!IsBrowserProcess(command_line))\r
- return;\r
-\r
- // Disable renderer sandbox for most of node's functions.\r
- command_line->AppendSwitch(switches::kNoSandbox);\r
-\r
- // Allow file:// URIs to read other file:// URIs by default.\r
- command_line->AppendSwitch(switches::kAllowFileAccessFromFiles);\r
-\r
-#if defined(OS_MACOSX)\r
- // Enable AVFoundation.\r
- command_line->AppendSwitch("enable-avfoundation");\r
-#endif\r
-}\r
-\r
-content::ContentBrowserClient* AtomMainDelegate::CreateContentBrowserClient() {\r
- browser_client_.reset(new AtomBrowserClient);\r
- return browser_client_.get();\r
-}\r
-\r
-content::ContentRendererClient*\r
- AtomMainDelegate::CreateContentRendererClient() {\r
- renderer_client_.reset(new AtomRendererClient);\r
- return renderer_client_.get();\r
-}\r
-\r
-content::ContentUtilityClient* AtomMainDelegate::CreateContentUtilityClient() {\r
- utility_client_.reset(new AtomContentUtilityClient);\r
- return utility_client_.get();\r
-}\r
-\r
-int AtomMainDelegate::RunProcess(\r
- const std::string& process_type,\r
- const content::MainFunctionParams& main_function_params) {\r
- if (process_type == kRelauncherProcess)\r
- return relauncher::RelauncherMain(main_function_params);\r
- else\r
- return -1;\r
-}\r
-\r
-#if defined(OS_MACOSX)\r
-bool AtomMainDelegate::ShouldSendMachPort(const std::string& process_type) {\r
- return process_type != kRelauncherProcess;\r
-}\r
-\r
-bool AtomMainDelegate::DelaySandboxInitialization(\r
- const std::string& process_type) {\r
- return process_type == kRelauncherProcess;\r
-}\r
-#endif\r
-\r
-std::unique_ptr<brightray::ContentClient>\r
-AtomMainDelegate::CreateContentClient() {\r
- return std::unique_ptr<brightray::ContentClient>(new AtomContentClient);\r
-}\r
-\r
-} // namespace atom\r
+// 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/app/atom_main_delegate.h"
+
+#include <string>
+#include <iostream>
+
+#include "atom/app/atom_content_client.h"
+#include "atom/browser/atom_browser_client.h"
+#include "atom/browser/relauncher.h"
+#include "atom/common/google_api_key.h"
+#include "atom/renderer/atom_renderer_client.h"
+#include "atom/utility/atom_content_utility_client.h"
+#include "base/command_line.h"
+#include "base/debug/stack_trace.h"
+#include "base/environment.h"
+#include "base/logging.h"
+#include "chrome/common/chrome_paths.h"
+#include "content/public/common/content_switches.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/resource/resource_bundle.h"
+
+namespace atom {
+
+namespace {
+
+const char* kRelauncherProcess = "relauncher";
+
+bool IsBrowserProcess(base::CommandLine* cmd) {
+ std::string process_type = cmd->GetSwitchValueASCII(switches::kProcessType);
+ return process_type.empty();
+}
+
+#if defined(OS_WIN)
+void InvalidParameterHandler(const wchar_t*, const wchar_t*, const wchar_t*,
+ unsigned int, uintptr_t) {
+ // noop.
+}
+#endif
+
+} // namespace
+
+AtomMainDelegate::AtomMainDelegate() {
+}
+
+AtomMainDelegate::~AtomMainDelegate() {
+}
+
+bool AtomMainDelegate::BasicStartupComplete(int* exit_code) {
+ auto command_line = base::CommandLine::ForCurrentProcess();
+
+ logging::LoggingSettings settings;
+#if defined(OS_WIN)
+ // On Windows the terminal returns immediately, so we add a new line to
+ // prevent output in the same line as the prompt.
+ if (IsBrowserProcess(command_line))
+ std::wcout << std::endl;
+#if defined(DEBUG)
+ // Print logging to debug.log on Windows
+ settings.logging_dest = logging::LOG_TO_ALL;
+ settings.log_file = L"debug.log";
+ settings.lock_log = logging::LOCK_LOG_FILE;
+ settings.delete_old = logging::DELETE_OLD_LOG_FILE;
+#else
+ settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
+#endif // defined(DEBUG)
+#else // defined(OS_WIN)
+ settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
+#endif // !defined(OS_WIN)
+
+ // Only enable logging when --enable-logging is specified.
+ std::unique_ptr<base::Environment> env(base::Environment::Create());
+ if (!command_line->HasSwitch(switches::kEnableLogging) &&
+ !env->HasVar("ELECTRON_ENABLE_LOGGING")) {
+ settings.logging_dest = logging::LOG_NONE;
+ logging::SetMinLogLevel(logging::LOG_NUM_SEVERITIES);
+ }
+
+ logging::InitLogging(settings);
+
+ // Logging with pid and timestamp.
+ logging::SetLogItems(true, false, true, false);
+
+ // Enable convient stack printing.
+ bool enable_stack_dumping = env->HasVar("ELECTRON_ENABLE_STACK_DUMPING");
+#if defined(DEBUG) && defined(OS_LINUX)
+ enable_stack_dumping = true;
+#endif
+ if (enable_stack_dumping)
+ base::debug::EnableInProcessStackDumping();
+
+ chrome::RegisterPathProvider();
+
+#if defined(OS_MACOSX)
+ SetUpBundleOverrides();
+#endif
+
+#if defined(OS_WIN)
+ // Ignore invalid parameter errors.
+ _set_invalid_parameter_handler(InvalidParameterHandler);
+#endif
+
+ return brightray::MainDelegate::BasicStartupComplete(exit_code);
+}
+
+void AtomMainDelegate::PreSandboxStartup() {
+ brightray::MainDelegate::PreSandboxStartup();
+
+ // Set google API key.
+ std::unique_ptr<base::Environment> env(base::Environment::Create());
+ if (!env->HasVar("GOOGLE_API_KEY"))
+ env->SetVar("GOOGLE_API_KEY", GOOGLEAPIS_API_KEY);
+
+ auto command_line = base::CommandLine::ForCurrentProcess();
+ std::string process_type = command_line->GetSwitchValueASCII(
+ switches::kProcessType);
+
+ // Only append arguments for browser process.
+ if (!IsBrowserProcess(command_line))
+ return;
+
+ // Disable renderer sandbox for most of node's functions.
+ command_line->AppendSwitch(switches::kNoSandbox);
+
+ // Allow file:// URIs to read other file:// URIs by default.
+ command_line->AppendSwitch(switches::kAllowFileAccessFromFiles);
+
+#if defined(OS_MACOSX)
+ // Enable AVFoundation.
+ command_line->AppendSwitch("enable-avfoundation");
+#endif
+}
+
+content::ContentBrowserClient* AtomMainDelegate::CreateContentBrowserClient() {
+ browser_client_.reset(new AtomBrowserClient);
+ return browser_client_.get();
+}
+
+content::ContentRendererClient*
+ AtomMainDelegate::CreateContentRendererClient() {
+ renderer_client_.reset(new AtomRendererClient);
+ return renderer_client_.get();
+}
+
+content::ContentUtilityClient* AtomMainDelegate::CreateContentUtilityClient() {
+ utility_client_.reset(new AtomContentUtilityClient);
+ return utility_client_.get();
+}
+
+int AtomMainDelegate::RunProcess(
+ const std::string& process_type,
+ const content::MainFunctionParams& main_function_params) {
+ if (process_type == kRelauncherProcess)
+ return relauncher::RelauncherMain(main_function_params);
+ else
+ return -1;
+}
+
+#if defined(OS_MACOSX)
+bool AtomMainDelegate::ShouldSendMachPort(const std::string& process_type) {
+ return process_type != kRelauncherProcess;
+}
+
+bool AtomMainDelegate::DelaySandboxInitialization(
+ const std::string& process_type) {
+ return process_type == kRelauncherProcess;
+}
+#endif
+
+std::unique_ptr<brightray::ContentClient>
+AtomMainDelegate::CreateContentClient() {
+ return std::unique_ptr<brightray::ContentClient>(new AtomContentClient);
+}
+
+} // namespace atom
-// Copyright (c) 2013 GitHub, Inc.\r
-// Use of this source code is governed by the MIT license that can be\r
-// found in the LICENSE file.\r
-\r
-#ifndef ATOM_APP_ATOM_MAIN_DELEGATE_H_\r
-#define ATOM_APP_ATOM_MAIN_DELEGATE_H_\r
-\r
-#include <string>\r
-\r
-#include "brightray/common/main_delegate.h"\r
-#include "brightray/common/content_client.h"\r
-\r
-namespace atom {\r
-\r
-class AtomMainDelegate : public brightray::MainDelegate {\r
- public:\r
- AtomMainDelegate();\r
- ~AtomMainDelegate();\r
-\r
- protected:\r
- // content::ContentMainDelegate:\r
- bool BasicStartupComplete(int* exit_code) override;\r
- void PreSandboxStartup() override;\r
- content::ContentBrowserClient* CreateContentBrowserClient() override;\r
- content::ContentRendererClient* CreateContentRendererClient() override;\r
- content::ContentUtilityClient* CreateContentUtilityClient() override;\r
- int RunProcess(\r
- const std::string& process_type,\r
- const content::MainFunctionParams& main_function_params) override;\r
-#if defined(OS_MACOSX)\r
- bool ShouldSendMachPort(const std::string& process_type) override;\r
- bool DelaySandboxInitialization(const std::string& process_type) override;\r
-#endif\r
-\r
- // brightray::MainDelegate:\r
- std::unique_ptr<brightray::ContentClient> CreateContentClient() override;\r
-#if defined(OS_MACOSX)\r
- void OverrideChildProcessPath() override;\r
- void OverrideFrameworkBundlePath() override;\r
-#endif\r
-\r
- private:\r
-#if defined(OS_MACOSX)\r
- void SetUpBundleOverrides();\r
-#endif\r
-\r
- brightray::ContentClient content_client_;\r
- std::unique_ptr<content::ContentBrowserClient> browser_client_;\r
- std::unique_ptr<content::ContentRendererClient> renderer_client_;\r
- std::unique_ptr<content::ContentUtilityClient> utility_client_;\r
-\r
- DISALLOW_COPY_AND_ASSIGN(AtomMainDelegate);\r
-};\r
-\r
-} // namespace atom\r
-\r
-#endif // ATOM_APP_ATOM_MAIN_DELEGATE_H_\r
+// 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_APP_ATOM_MAIN_DELEGATE_H_
+#define ATOM_APP_ATOM_MAIN_DELEGATE_H_
+
+#include <string>
+
+#include "brightray/common/main_delegate.h"
+#include "brightray/common/content_client.h"
+
+namespace atom {
+
+class AtomMainDelegate : public brightray::MainDelegate {
+ public:
+ AtomMainDelegate();
+ ~AtomMainDelegate();
+
+ protected:
+ // content::ContentMainDelegate:
+ bool BasicStartupComplete(int* exit_code) override;
+ void PreSandboxStartup() override;
+ content::ContentBrowserClient* CreateContentBrowserClient() override;
+ content::ContentRendererClient* CreateContentRendererClient() override;
+ content::ContentUtilityClient* CreateContentUtilityClient() override;
+ int RunProcess(
+ const std::string& process_type,
+ const content::MainFunctionParams& main_function_params) override;
+#if defined(OS_MACOSX)
+ bool ShouldSendMachPort(const std::string& process_type) override;
+ bool DelaySandboxInitialization(const std::string& process_type) override;
+#endif
+
+ // brightray::MainDelegate:
+ std::unique_ptr<brightray::ContentClient> CreateContentClient() override;
+#if defined(OS_MACOSX)
+ void OverrideChildProcessPath() override;
+ void OverrideFrameworkBundlePath() override;
+#endif
+
+ private:
+#if defined(OS_MACOSX)
+ void SetUpBundleOverrides();
+#endif
+
+ brightray::ContentClient content_client_;
+ std::unique_ptr<content::ContentBrowserClient> browser_client_;
+ std::unique_ptr<content::ContentRendererClient> renderer_client_;
+ std::unique_ptr<content::ContentUtilityClient> utility_client_;
+
+ DISALLOW_COPY_AND_ASSIGN(AtomMainDelegate);
+};
+
+} // namespace atom
+
+#endif // ATOM_APP_ATOM_MAIN_DELEGATE_H_