electron/atom/app/atom_main_delegate.cc

152 lines
4.6 KiB
C++
Raw Normal View History

// Copyright (c) 2013 GitHub, Inc.
2014-04-25 09:49:37 +00:00
// Use of this source code is governed by the MIT license that can be
2013-04-12 01:46:58 +00:00
// found in the LICENSE file.
2014-03-16 00:30:26 +00:00
#include "atom/app/atom_main_delegate.h"
2013-04-12 01:46:58 +00:00
#include <string>
#include <iostream>
#include "atom/app/atom_content_client.h"
#include "atom/browser/atom_browser_client.h"
2014-10-08 10:27:39 +00:00
#include "atom/common/google_api_key.h"
#include "atom/renderer/atom_renderer_client.h"
2015-05-04 12:58:48 +00:00
#include "atom/utility/atom_content_utility_client.h"
2013-04-20 03:19:25 +00:00
#include "base/command_line.h"
2014-02-19 11:07:52 +00:00
#include "base/debug/stack_trace.h"
2014-10-08 10:27:39 +00:00
#include "base/environment.h"
#include "base/logging.h"
2013-04-20 03:19:25 +00:00
#include "content/public/common/content_switches.h"
2014-07-16 07:05:02 +00:00
#include "ui/base/resource/resource_bundle.h"
2013-04-12 01:46:58 +00:00
namespace atom {
namespace {
bool IsBrowserProcess(base::CommandLine* cmd) {
std::string process_type = cmd->GetSwitchValueASCII(switches::kProcessType);
return process_type.empty();
}
} // namespace
2013-04-12 01:46:58 +00:00
AtomMainDelegate::AtomMainDelegate() {
}
AtomMainDelegate::~AtomMainDelegate() {
}
bool AtomMainDelegate::BasicStartupComplete(int* exit_code) {
auto command_line = base::CommandLine::ForCurrentProcess();
logging::LoggingSettings settings;
2015-03-25 12:21:56 +00:00
#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;
2015-03-26 03:27:06 +00:00
#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.
if (!command_line->HasSwitch(switches::kEnableLogging)) {
settings.logging_dest = logging::LOG_NONE;
logging::SetMinLogLevel(logging::LOG_NUM_SEVERITIES);
}
2015-03-25 12:21:56 +00:00
logging::InitLogging(settings);
2013-12-23 14:04:49 +00:00
// Logging with pid and timestamp.
logging::SetLogItems(true, false, true, false);
#if defined(DEBUG) && defined(OS_LINUX)
2015-03-26 03:27:06 +00:00
// Enable convient stack printing.
2014-02-19 11:07:52 +00:00
base::debug::EnableInProcessStackDumping();
#endif
2014-07-09 09:15:28 +00:00
return brightray::MainDelegate::BasicStartupComplete(exit_code);
}
2013-04-20 03:19:25 +00:00
void AtomMainDelegate::PreSandboxStartup() {
2014-07-09 09:15:28 +00:00
brightray::MainDelegate::PreSandboxStartup();
2014-10-08 10:27:39 +00: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 22:27:27 +00:00
auto command_line = base::CommandLine::ForCurrentProcess();
std::string process_type = command_line->GetSwitchValueASCII(
switches::kProcessType);
if (process_type == switches::kUtilityProcess) {
AtomContentUtilityClient::PreSandboxStartup();
}
// Only append arguments for browser process.
if (!IsBrowserProcess(command_line))
return;
#if defined(OS_WIN)
// Disable the LegacyRenderWidgetHostHWND, it made frameless windows unable
// to move and resize. We may consider enabling it again after upgraded to
// Chrome 38, which should have fixed the problem.
command_line->AppendSwitch(switches::kDisableLegacyIntermediateWindow);
#endif
// Disable renderer sandbox for most of node's functions.
2013-04-20 03:19:25 +00:00
command_line->AppendSwitch(switches::kNoSandbox);
// Allow file:// URIs to read other file:// URIs by default.
command_line->AppendSwitch(switches::kAllowFileAccessFromFiles);
2014-10-08 10:17:27 +00:00
#if defined(OS_MACOSX)
// Enable AVFoundation.
command_line->AppendSwitch("enable-avfoundation");
#endif
2013-04-20 03:19:25 +00:00
}
2013-04-12 01:46:58 +00: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 03:31:17 +00:00
content::ContentUtilityClient* AtomMainDelegate::CreateContentUtilityClient() {
utility_client_.reset(new AtomContentUtilityClient);
return utility_client_.get();
}
scoped_ptr<brightray::ContentClient> AtomMainDelegate::CreateContentClient() {
return scoped_ptr<brightray::ContentClient>(new AtomContentClient).Pass();
}
void AtomMainDelegate::AddDataPackFromPath(
ui::ResourceBundle* bundle, const base::FilePath& pak_dir) {
#if defined(OS_WIN)
bundle->AddDataPackFromPath(
pak_dir.Append(FILE_PATH_LITERAL("ui_resources_200_percent.pak")),
ui::SCALE_FACTOR_200P);
bundle->AddDataPackFromPath(
2014-12-10 22:17:07 +00:00
pak_dir.Append(FILE_PATH_LITERAL("content_resources_200_percent.pak")),
ui::SCALE_FACTOR_200P);
#endif
}
2013-04-12 01:46:58 +00:00
} // namespace atom