2014-10-31 11:17:05 -07:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 17:49:37 +08:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-04-12 09:46:58 +08:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2014-03-16 08:30:26 +08:00
|
|
|
#include "atom/app/atom_main_delegate.h"
|
2013-04-12 09:46:58 +08:00
|
|
|
|
2014-03-16 09:13:06 +08:00
|
|
|
#include <string>
|
2015-10-10 06:39:02 +03:00
|
|
|
#include <iostream>
|
2014-03-16 09:13:06 +08:00
|
|
|
|
2014-08-27 20:48:49 +08:00
|
|
|
#include "atom/app/atom_content_client.h"
|
2014-06-30 12:15:59 +08:00
|
|
|
#include "atom/browser/atom_browser_client.h"
|
2014-10-08 18:27:39 +08:00
|
|
|
#include "atom/common/google_api_key.h"
|
2014-06-30 12:15:59 +08:00
|
|
|
#include "atom/renderer/atom_renderer_client.h"
|
2015-05-04 20:58:48 +08:00
|
|
|
#include "atom/utility/atom_content_utility_client.h"
|
2013-04-20 11:19:25 +08:00
|
|
|
#include "base/command_line.h"
|
2014-02-19 19:07:52 +08:00
|
|
|
#include "base/debug/stack_trace.h"
|
2014-10-08 18:27:39 +08:00
|
|
|
#include "base/environment.h"
|
2013-07-08 11:09:53 +08:00
|
|
|
#include "base/logging.h"
|
2015-11-13 13:05:16 +08:00
|
|
|
#include "chrome/common/chrome_paths.h"
|
2013-04-20 11:19:25 +08:00
|
|
|
#include "content/public/common/content_switches.h"
|
2016-01-08 12:06:06 +08:00
|
|
|
#include "ui/base/l10n/l10n_util.h"
|
2014-07-16 15:05:02 +08:00
|
|
|
#include "ui/base/resource/resource_bundle.h"
|
2013-09-12 15:42:36 +08:00
|
|
|
|
2013-04-12 09:46:58 +08:00
|
|
|
namespace atom {
|
|
|
|
|
2015-10-15 12:44:55 +08:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
bool IsBrowserProcess(base::CommandLine* cmd) {
|
|
|
|
std::string process_type = cmd->GetSwitchValueASCII(switches::kProcessType);
|
|
|
|
return process_type.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2013-04-12 09:46:58 +08:00
|
|
|
AtomMainDelegate::AtomMainDelegate() {
|
|
|
|
}
|
|
|
|
|
|
|
|
AtomMainDelegate::~AtomMainDelegate() {
|
|
|
|
}
|
|
|
|
|
2013-07-08 11:09:53 +08:00
|
|
|
bool AtomMainDelegate::BasicStartupComplete(int* exit_code) {
|
2015-10-15 12:44:55 +08:00
|
|
|
auto command_line = base::CommandLine::ForCurrentProcess();
|
|
|
|
|
2013-12-17 14:01:40 +08:00
|
|
|
logging::LoggingSettings settings;
|
2015-03-25 17:51:56 +05:30
|
|
|
#if defined(OS_WIN)
|
2015-10-10 06:39:02 +03:00
|
|
|
// On Windows the terminal returns immediately, so we add a new line to
|
|
|
|
// prevent output in the same line as the prompt.
|
2015-10-15 12:44:55 +08:00
|
|
|
if (IsBrowserProcess(command_line))
|
|
|
|
std::wcout << std::endl;
|
2013-07-23 16:37:00 +08:00
|
|
|
#if defined(DEBUG)
|
2015-10-03 15:33:55 +08:00
|
|
|
// Print logging to debug.log on Windows
|
2013-12-17 14:01:40 +08:00
|
|
|
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;
|
2013-07-23 16:37:00 +08:00
|
|
|
#else
|
2013-12-17 14:01:40 +08:00
|
|
|
settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
|
2015-03-26 11:27:06 +08:00
|
|
|
#endif // defined(DEBUG)
|
2015-09-07 21:44:03 +08:00
|
|
|
#else // defined(OS_WIN)
|
|
|
|
settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
|
|
|
|
#endif // !defined(OS_WIN)
|
2015-10-03 15:33:55 +08:00
|
|
|
|
|
|
|
// Only enable logging when --enable-logging is specified.
|
2015-10-20 13:00:28 +08:00
|
|
|
scoped_ptr<base::Environment> env(base::Environment::Create());
|
|
|
|
if (!command_line->HasSwitch(switches::kEnableLogging) &&
|
|
|
|
!env->HasVar("ELECTRON_ENABLE_LOGGING")) {
|
2015-10-03 15:33:55 +08:00
|
|
|
settings.logging_dest = logging::LOG_NONE;
|
2015-10-10 20:44:22 +03:00
|
|
|
logging::SetMinLogLevel(logging::LOG_NUM_SEVERITIES);
|
|
|
|
}
|
2015-10-03 15:33:55 +08:00
|
|
|
|
2015-03-25 17:51:56 +05:30
|
|
|
logging::InitLogging(settings);
|
|
|
|
|
2013-12-23 22:04:49 +08:00
|
|
|
// Logging with pid and timestamp.
|
|
|
|
logging::SetLogItems(true, false, true, false);
|
|
|
|
|
2015-03-26 11:27:06 +08:00
|
|
|
// Enable convient stack printing.
|
2015-10-20 13:02:48 +08:00
|
|
|
bool enable_stack_dumping = env->HasVar("ELECTRON_ENABLE_STACK_DUMPING");
|
|
|
|
#if defined(DEBUG) && defined(OS_LINUX)
|
|
|
|
enable_stack_dumping = true;
|
2014-02-19 19:07:52 +08:00
|
|
|
#endif
|
2015-10-20 13:02:48 +08:00
|
|
|
if (enable_stack_dumping)
|
|
|
|
base::debug::EnableInProcessStackDumping();
|
2014-02-19 19:07:52 +08:00
|
|
|
|
2015-11-13 13:05:16 +08:00
|
|
|
chrome::RegisterPathProvider();
|
|
|
|
|
2014-07-09 17:15:28 +08:00
|
|
|
return brightray::MainDelegate::BasicStartupComplete(exit_code);
|
2013-07-08 11:09:53 +08:00
|
|
|
}
|
|
|
|
|
2013-04-20 11:19:25 +08:00
|
|
|
void AtomMainDelegate::PreSandboxStartup() {
|
2014-07-09 17:15:28 +08:00
|
|
|
brightray::MainDelegate::PreSandboxStartup();
|
2013-09-12 15:42:36 +08:00
|
|
|
|
2014-10-08 18:27:39 +08:00
|
|
|
// Set google API key.
|
|
|
|
scoped_ptr<base::Environment> env(base::Environment::Create());
|
|
|
|
if (!env->HasVar("GOOGLE_API_KEY"))
|
|
|
|
env->SetVar("GOOGLE_API_KEY", GOOGLEAPIS_API_KEY);
|
|
|
|
|
2015-03-10 15:27:27 -07:00
|
|
|
auto command_line = base::CommandLine::ForCurrentProcess();
|
2014-01-30 21:06:56 +08:00
|
|
|
std::string process_type = command_line->GetSwitchValueASCII(
|
|
|
|
switches::kProcessType);
|
|
|
|
|
2015-05-11 20:14:07 +08:00
|
|
|
if (process_type == switches::kUtilityProcess) {
|
|
|
|
AtomContentUtilityClient::PreSandboxStartup();
|
|
|
|
}
|
|
|
|
|
2014-02-21 01:04:27 +08:00
|
|
|
// Only append arguments for browser process.
|
2015-10-15 12:44:55 +08:00
|
|
|
if (!IsBrowserProcess(command_line))
|
2014-01-30 21:06:56 +08:00
|
|
|
return;
|
2013-12-13 00:57:08 +08:00
|
|
|
|
|
|
|
// Disable renderer sandbox for most of node's functions.
|
2013-04-20 11:19:25 +08:00
|
|
|
command_line->AppendSwitch(switches::kNoSandbox);
|
2013-12-13 00:57:08 +08:00
|
|
|
|
2015-05-12 18:21:48 +05:30
|
|
|
// Allow file:// URIs to read other file:// URIs by default.
|
|
|
|
command_line->AppendSwitch(switches::kAllowFileAccessFromFiles);
|
|
|
|
|
2014-10-08 18:17:27 +08:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
// Enable AVFoundation.
|
|
|
|
command_line->AppendSwitch("enable-avfoundation");
|
|
|
|
#endif
|
2013-04-20 11:19:25 +08:00
|
|
|
}
|
|
|
|
|
2013-04-12 09:46:58 +08:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2015-04-30 11:31:17 +08:00
|
|
|
content::ContentUtilityClient* AtomMainDelegate::CreateContentUtilityClient() {
|
|
|
|
utility_client_.reset(new AtomContentUtilityClient);
|
|
|
|
return utility_client_.get();
|
|
|
|
}
|
|
|
|
|
2014-08-27 20:48:49 +08:00
|
|
|
scoped_ptr<brightray::ContentClient> AtomMainDelegate::CreateContentClient() {
|
2016-03-08 23:28:53 +09:00
|
|
|
return scoped_ptr<brightray::ContentClient>(new AtomContentClient);
|
2014-08-27 20:48:49 +08:00
|
|
|
}
|
|
|
|
|
2013-04-12 09:46:58 +08:00
|
|
|
} // namespace atom
|