electron/shell/browser/api/atom_api_app.cc

1553 lines
51 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-05-02 16:05:09 +00:00
// found in the LICENSE file.
#include "shell/browser/api/atom_api_app.h"
2013-05-02 16:05:09 +00:00
#include <string>
#include <vector>
#include "base/command_line.h"
#include "base/environment.h"
#include "base/files/file_path.h"
2016-04-18 05:11:31 +00:00
#include "base/files/file_util.h"
#include "base/optional.h"
#include "base/path_service.h"
#include "base/system/sys_info.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/icon_manager.h"
2015-11-13 05:05:16 +00:00
#include "chrome/common/chrome_paths.h"
#include "content/browser/gpu/compositor_util.h" // nogncheck
#include "content/browser/gpu/gpu_data_manager_impl.h" // nogncheck
#include "content/public/browser/browser_accessibility_state.h"
2017-04-27 18:09:27 +00:00
#include "content/public/browser/browser_child_process_host.h"
2017-05-16 00:41:45 +00:00
#include "content/public/browser/child_process_data.h"
#include "content/public/browser/client_certificate_delegate.h"
2015-06-25 12:28:07 +00:00
#include "content/public/browser/gpu_data_manager.h"
2015-11-18 02:39:25 +00:00
#include "content/public/browser/render_frame_host.h"
#include "content/public/common/content_switches.h"
#include "media/audio/audio_manager.h"
2014-04-17 09:13:46 +00:00
#include "native_mate/object_template_builder.h"
#include "net/ssl/client_cert_identity.h"
#include "net/ssl/ssl_cert_request_info.h"
2018-09-15 00:07:49 +00:00
#include "services/service_manager/sandbox/switches.h"
#include "shell/browser/api/atom_api_menu.h"
#include "shell/browser/api/atom_api_session.h"
#include "shell/browser/api/atom_api_web_contents.h"
#include "shell/browser/api/gpuinfo_manager.h"
#include "shell/browser/atom_browser_context.h"
#include "shell/browser/atom_browser_main_parts.h"
#include "shell/browser/atom_paths.h"
#include "shell/browser/login_handler.h"
#include "shell/browser/relauncher.h"
#include "shell/common/application_info.h"
#include "shell/common/atom_command_line.h"
#include "shell/common/native_mate_converters/callback.h"
#include "shell/common/native_mate_converters/file_path_converter.h"
#include "shell/common/native_mate_converters/gurl_converter.h"
#include "shell/common/native_mate_converters/image_converter.h"
#include "shell/common/native_mate_converters/net_converter.h"
#include "shell/common/native_mate_converters/network_converter.h"
#include "shell/common/native_mate_converters/once_callback.h"
#include "shell/common/native_mate_converters/value_converter.h"
#include "shell/common/node_includes.h"
#include "shell/common/options_switches.h"
2015-09-16 08:16:21 +00:00
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/image/image.h"
2015-04-29 07:13:46 +00:00
#if defined(OS_WIN)
#include "base/strings/utf_string_conversions.h"
#include "shell/browser/ui/win/jump_list.h"
2015-04-29 07:13:46 +00:00
#endif
#if defined(OS_MACOSX)
#include <CoreFoundation/CoreFoundation.h>
#include "shell/browser/ui/cocoa/atom_bundle_mover.h"
#endif
using electron::Browser;
2014-04-17 09:13:46 +00:00
2014-11-17 09:19:41 +00:00
namespace mate {
2014-11-17 09:35:51 +00:00
#if defined(OS_WIN)
template <>
struct Converter<electron::ProcessIntegrityLevel> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
electron::ProcessIntegrityLevel value) {
switch (value) {
case electron::ProcessIntegrityLevel::Untrusted:
return mate::StringToV8(isolate, "untrusted");
case electron::ProcessIntegrityLevel::Low:
return mate::StringToV8(isolate, "low");
case electron::ProcessIntegrityLevel::Medium:
return mate::StringToV8(isolate, "medium");
case electron::ProcessIntegrityLevel::High:
return mate::StringToV8(isolate, "high");
default:
return mate::StringToV8(isolate, "unknown");
}
}
};
2018-04-18 01:55:30 +00:00
template <>
2014-11-17 09:19:41 +00:00
struct Converter<Browser::UserTask> {
2018-04-18 01:55:30 +00:00
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
2014-11-17 09:19:41 +00:00
Browser::UserTask* out) {
mate::Dictionary dict;
if (!ConvertFromV8(isolate, val, &dict))
return false;
if (!dict.Get("program", &(out->program)) ||
!dict.Get("title", &(out->title)))
return false;
2014-11-17 09:35:51 +00:00
if (dict.Get("iconPath", &(out->icon_path)) &&
!dict.Get("iconIndex", &(out->icon_index)))
return false;
dict.Get("arguments", &(out->arguments));
dict.Get("description", &(out->description));
dict.Get("workingDirectory", &(out->working_dir));
return true;
2014-11-17 09:19:41 +00:00
}
};
using electron::JumpListCategory;
using electron::JumpListItem;
using electron::JumpListResult;
2018-04-18 01:55:30 +00:00
template <>
struct Converter<JumpListItem::Type> {
2018-04-18 01:55:30 +00:00
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
JumpListItem::Type* out) {
std::string item_type;
if (!ConvertFromV8(isolate, val, &item_type))
return false;
if (item_type == "task")
*out = JumpListItem::Type::TASK;
else if (item_type == "separator")
*out = JumpListItem::Type::SEPARATOR;
else if (item_type == "file")
*out = JumpListItem::Type::FILE;
else
return false;
return true;
}
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
JumpListItem::Type val) {
std::string item_type;
switch (val) {
case JumpListItem::Type::TASK:
item_type = "task";
break;
case JumpListItem::Type::SEPARATOR:
item_type = "separator";
break;
case JumpListItem::Type::FILE:
item_type = "file";
break;
}
return mate::ConvertToV8(isolate, item_type);
}
};
2018-04-18 01:55:30 +00:00
template <>
struct Converter<JumpListItem> {
2018-04-18 01:55:30 +00:00
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
JumpListItem* out) {
mate::Dictionary dict;
if (!ConvertFromV8(isolate, val, &dict))
return false;
if (!dict.Get("type", &(out->type)))
return false;
switch (out->type) {
case JumpListItem::Type::TASK:
if (!dict.Get("program", &(out->path)) ||
!dict.Get("title", &(out->title)))
return false;
if (dict.Get("iconPath", &(out->icon_path)) &&
!dict.Get("iconIndex", &(out->icon_index)))
return false;
dict.Get("args", &(out->arguments));
dict.Get("description", &(out->description));
dict.Get("workingDirectory", &(out->working_dir));
return true;
case JumpListItem::Type::SEPARATOR:
return true;
case JumpListItem::Type::FILE:
return dict.Get("path", &(out->path));
}
assert(false);
return false;
}
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const JumpListItem& val) {
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
dict.Set("type", val.type);
switch (val.type) {
case JumpListItem::Type::TASK:
dict.Set("program", val.path);
dict.Set("args", val.arguments);
dict.Set("title", val.title);
dict.Set("iconPath", val.icon_path);
dict.Set("iconIndex", val.icon_index);
dict.Set("description", val.description);
dict.Set("workingDirectory", val.working_dir);
break;
case JumpListItem::Type::SEPARATOR:
break;
case JumpListItem::Type::FILE:
dict.Set("path", val.path);
break;
}
return dict.GetHandle();
}
};
2018-04-18 01:55:30 +00:00
template <>
struct Converter<JumpListCategory::Type> {
2018-04-18 01:55:30 +00:00
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
JumpListCategory::Type* out) {
std::string category_type;
if (!ConvertFromV8(isolate, val, &category_type))
return false;
if (category_type == "tasks")
*out = JumpListCategory::Type::TASKS;
else if (category_type == "frequent")
*out = JumpListCategory::Type::FREQUENT;
else if (category_type == "recent")
*out = JumpListCategory::Type::RECENT;
else if (category_type == "custom")
*out = JumpListCategory::Type::CUSTOM;
else
return false;
return true;
}
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
JumpListCategory::Type val) {
std::string category_type;
switch (val) {
case JumpListCategory::Type::TASKS:
category_type = "tasks";
break;
case JumpListCategory::Type::FREQUENT:
category_type = "frequent";
break;
case JumpListCategory::Type::RECENT:
category_type = "recent";
break;
case JumpListCategory::Type::CUSTOM:
category_type = "custom";
break;
}
return mate::ConvertToV8(isolate, category_type);
}
};
2018-04-18 01:55:30 +00:00
template <>
struct Converter<JumpListCategory> {
2018-04-18 01:55:30 +00:00
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
JumpListCategory* out) {
mate::Dictionary dict;
if (!ConvertFromV8(isolate, val, &dict))
return false;
if (dict.Get("name", &(out->name)) && out->name.empty())
return false;
if (!dict.Get("type", &(out->type))) {
if (out->name.empty())
out->type = JumpListCategory::Type::TASKS;
else
out->type = JumpListCategory::Type::CUSTOM;
}
if ((out->type == JumpListCategory::Type::TASKS) ||
(out->type == JumpListCategory::Type::CUSTOM)) {
if (!dict.Get("items", &(out->items)))
return false;
}
return true;
}
};
// static
2018-04-18 01:55:30 +00:00
template <>
struct Converter<JumpListResult> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, JumpListResult val) {
std::string result_code;
switch (val) {
case JumpListResult::SUCCESS:
result_code = "ok";
break;
case JumpListResult::ARGUMENT_ERROR:
result_code = "argumentError";
break;
case JumpListResult::GENERIC_ERROR:
result_code = "error";
break;
case JumpListResult::CUSTOM_CATEGORY_SEPARATOR_ERROR:
result_code = "invalidSeparatorError";
break;
case JumpListResult::MISSING_FILE_TYPE_REGISTRATION_ERROR:
result_code = "fileTypeRegistrationError";
break;
case JumpListResult::CUSTOM_CATEGORY_ACCESS_DENIED_ERROR:
result_code = "customCategoryAccessDeniedError";
break;
}
return ConvertToV8(isolate, result_code);
}
};
2014-11-17 09:35:51 +00:00
#endif
2014-11-17 09:19:41 +00:00
2018-04-18 01:55:30 +00:00
template <>
2016-07-07 23:29:09 +00:00
struct Converter<Browser::LoginItemSettings> {
2018-04-18 01:55:30 +00:00
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
2016-07-07 23:29:09 +00:00
Browser::LoginItemSettings* out) {
mate::Dictionary dict;
if (!ConvertFromV8(isolate, val, &dict))
return false;
dict.Get("openAtLogin", &(out->open_at_login));
dict.Get("openAsHidden", &(out->open_as_hidden));
dict.Get("path", &(out->path));
dict.Get("args", &(out->args));
2016-07-07 23:29:09 +00:00
return true;
}
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
Browser::LoginItemSettings val) {
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
dict.Set("openAtLogin", val.open_at_login);
dict.Set("openAsHidden", val.open_as_hidden);
dict.Set("restoreState", val.restore_state);
dict.Set("wasOpenedAtLogin", val.opened_at_login);
dict.Set("wasOpenedAsHidden", val.opened_as_hidden);
2016-07-07 23:29:09 +00:00
return dict.GetHandle();
}
};
2014-11-17 09:19:41 +00:00
2018-04-18 01:55:30 +00:00
template <>
2016-11-30 07:30:03 +00:00
struct Converter<content::CertificateRequestResultType> {
2018-04-18 01:55:30 +00:00
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
2016-11-30 07:30:03 +00:00
content::CertificateRequestResultType* out) {
bool b;
if (!ConvertFromV8(isolate, val, &b))
return false;
2018-04-18 01:55:30 +00:00
*out = b ? content::CERTIFICATE_REQUEST_RESULT_TYPE_CONTINUE
: content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
2016-11-30 07:30:03 +00:00
return true;
}
};
} // namespace mate
2014-11-17 09:19:41 +00:00
namespace electron {
2013-05-02 16:05:09 +00:00
namespace api {
2014-08-19 13:26:45 +00:00
namespace {
2016-11-04 06:59:18 +00:00
IconLoader::IconSize GetIconSizeByString(const std::string& size) {
2016-11-03 18:23:40 +00:00
if (size == "small") {
return IconLoader::IconSize::SMALL;
} else if (size == "large") {
return IconLoader::IconSize::LARGE;
}
return IconLoader::IconSize::NORMAL;
2016-11-03 18:43:53 +00:00
}
2016-11-03 18:23:40 +00:00
// Return the path constant from string.
int GetPathConstant(const std::string& name) {
if (name == "appData")
2018-10-24 10:49:10 +00:00
return DIR_APP_DATA;
else if (name == "userData")
2018-10-24 10:49:10 +00:00
return DIR_USER_DATA;
else if (name == "cache")
2018-10-24 10:49:10 +00:00
return DIR_CACHE;
else if (name == "userCache")
2018-10-24 10:49:10 +00:00
return DIR_USER_CACHE;
else if (name == "logs")
2018-10-24 10:49:10 +00:00
return DIR_APP_LOGS;
else if (name == "home")
return base::DIR_HOME;
2015-01-19 05:31:09 +00:00
else if (name == "temp")
return base::DIR_TEMP;
2015-11-13 05:05:16 +00:00
else if (name == "userDesktop" || name == "desktop")
2015-01-19 05:31:09 +00:00
return base::DIR_USER_DESKTOP;
else if (name == "exe")
return base::FILE_EXE;
else if (name == "module")
return base::FILE_MODULE;
2015-11-13 05:05:16 +00:00
else if (name == "documents")
return chrome::DIR_USER_DOCUMENTS;
else if (name == "downloads")
return chrome::DIR_DEFAULT_DOWNLOADS;
else if (name == "music")
return chrome::DIR_USER_MUSIC;
else if (name == "pictures")
return chrome::DIR_USER_PICTURES;
else if (name == "videos")
return chrome::DIR_USER_VIDEOS;
else if (name == "pepperFlashSystemPlugin")
return chrome::FILE_PEPPER_FLASH_SYSTEM_PLUGIN;
else
return -1;
}
bool NotificationCallbackWrapper(
const base::RepeatingCallback<
void(const base::CommandLine::StringVector& command_line,
const base::FilePath& current_directory)>& callback,
2015-10-22 11:02:21 +00:00
const base::CommandLine::StringVector& cmd,
const base::FilePath& cwd) {
// Make sure the callback is called after app gets ready.
if (Browser::Get()->is_ready()) {
callback.Run(cmd, cwd);
} else {
scoped_refptr<base::SingleThreadTaskRunner> task_runner(
base::ThreadTaskRunnerHandle::Get());
task_runner->PostTask(
FROM_HERE, base::BindOnce(base::IgnoreResult(callback), cmd, cwd));
}
// ProcessSingleton needs to know whether current process is quiting.
return !Browser::Get()->is_shutting_down();
}
void GotPrivateKey(std::shared_ptr<content::ClientCertificateDelegate> delegate,
scoped_refptr<net::X509Certificate> cert,
scoped_refptr<net::SSLPrivateKey> private_key) {
delegate->ContinueWithCertificate(cert, private_key);
}
void OnClientCertificateSelected(
v8::Isolate* isolate,
std::shared_ptr<content::ClientCertificateDelegate> delegate,
std::shared_ptr<net::ClientCertIdentityList> identities,
mate::Arguments* args) {
2016-12-07 10:03:56 +00:00
if (args->Length() == 2) {
delegate->ContinueWithCertificate(nullptr, nullptr);
2016-12-07 10:03:56 +00:00
return;
}
v8::Local<v8::Value> val;
args->GetNext(&val);
if (val->IsNull()) {
delegate->ContinueWithCertificate(nullptr, nullptr);
return;
}
2016-12-07 10:03:56 +00:00
mate::Dictionary cert_data;
if (!mate::ConvertFromV8(isolate, val, &cert_data)) {
args->ThrowError("Must pass valid certificate object.");
return;
}
2016-08-17 11:48:09 +00:00
std::string data;
if (!cert_data.Get("data", &data))
return;
auto certs = net::X509Certificate::CreateCertificateListFromBytes(
2016-08-17 11:48:09 +00:00
data.c_str(), data.length(), net::X509Certificate::FORMAT_AUTO);
if (!certs.empty()) {
scoped_refptr<net::X509Certificate> cert(certs[0].get());
for (size_t i = 0; i < identities->size(); ++i) {
if (cert->EqualsExcludingChain((*identities)[i]->certificate())) {
net::ClientCertIdentity::SelfOwningAcquirePrivateKey(
std::move((*identities)[i]),
base::BindRepeating(&GotPrivateKey, delegate, std::move(cert)));
break;
}
}
}
}
2015-10-28 11:34:01 +00:00
void PassLoginInformation(scoped_refptr<LoginHandler> login_handler,
mate::Arguments* args) {
base::string16 username, password;
if (args->GetNext(&username) && args->GetNext(&password))
login_handler->Login(username, password);
else
login_handler->CancelAuth();
}
#if defined(USE_NSS_CERTS)
2018-04-18 01:55:30 +00:00
int ImportIntoCertStore(CertificateManagerModel* model,
const base::DictionaryValue& options) {
2016-04-18 15:35:33 +00:00
std::string file_data, cert_path;
base::string16 password;
net::ScopedCERTCertificateList imported_certs;
int rv = -1;
options.GetString("certificate", &cert_path);
2016-04-18 15:35:33 +00:00
options.GetString("password", &password);
if (!cert_path.empty()) {
if (base::ReadFileToString(base::FilePath(cert_path), &file_data)) {
2017-04-17 08:17:02 +00:00
auto module = model->cert_db()->GetPrivateSlot();
2018-04-18 01:55:30 +00:00
rv = model->ImportFromPKCS12(module.get(), file_data, password, true,
2016-04-18 15:35:33 +00:00
&imported_certs);
if (imported_certs.size() > 1) {
auto it = imported_certs.begin();
2016-04-18 16:56:37 +00:00
++it; // skip first which would be the client certificate.
2016-04-18 15:35:33 +00:00
for (; it != imported_certs.end(); ++it)
2018-04-18 01:55:30 +00:00
rv &= model->SetCertTrust(it->get(), net::CA_CERT,
2016-04-18 16:56:37 +00:00
net::NSSCertDatabase::TRUSTED_SSL);
2016-04-18 15:35:33 +00:00
}
}
2016-04-18 05:11:31 +00:00
}
2016-04-18 15:35:33 +00:00
return rv;
2016-04-18 05:11:31 +00:00
}
#endif
2016-04-18 05:11:31 +00:00
void OnIconDataAvailable(util::Promise<gfx::Image> promise, gfx::Image icon) {
if (!icon.IsEmpty()) {
promise.Resolve(icon);
} else {
promise.RejectWithErrorMessage("Failed to get file icon.");
}
}
2014-08-19 13:26:45 +00:00
} // namespace
2016-04-25 01:17:54 +00:00
App::App(v8::Isolate* isolate) {
2015-11-18 02:07:03 +00:00
static_cast<AtomBrowserClient*>(AtomBrowserClient::Get())->set_delegate(this);
Browser::Get()->AddObserver(this);
2015-06-25 12:28:07 +00:00
content::GpuDataManager::GetInstance()->AddObserver(this);
2017-05-25 04:15:34 +00:00
base::ProcessId pid = base::GetCurrentProcId();
auto process_metric = std::make_unique<electron::ProcessMetric>(
content::PROCESS_TYPE_BROWSER, base::GetCurrentProcessHandle(),
base::ProcessMetrics::CreateCurrentProcessMetrics());
2017-05-16 00:41:45 +00:00
app_metrics_[pid] = std::move(process_metric);
2016-04-25 01:17:54 +00:00
Init(isolate);
}
App::~App() {
2018-04-18 01:55:30 +00:00
static_cast<AtomBrowserClient*>(AtomBrowserClient::Get())
->set_delegate(nullptr);
Browser::Get()->RemoveObserver(this);
2015-06-25 12:28:07 +00:00
content::GpuDataManager::GetInstance()->RemoveObserver(this);
2017-05-16 00:41:45 +00:00
content::BrowserChildProcessObserver::Remove(this);
}
void App::OnBeforeQuit(bool* prevent_default) {
if (Emit("before-quit")) {
*prevent_default = true;
}
}
void App::OnWillQuit(bool* prevent_default) {
if (Emit("will-quit")) {
*prevent_default = true;
}
}
void App::OnWindowAllClosed() {
Emit("window-all-closed");
}
2015-12-10 02:19:51 +00:00
void App::OnQuit() {
int exitCode = AtomBrowserMainParts::Get()->GetExitCode();
Emit("quit", exitCode);
if (process_singleton_) {
process_singleton_->Cleanup();
process_singleton_.reset();
}
2014-09-25 13:47:54 +00:00
}
void App::OnOpenFile(bool* prevent_default, const std::string& file_path) {
if (Emit("open-file", file_path)) {
*prevent_default = true;
}
}
void App::OnOpenURL(const std::string& url) {
Emit("open-url", url);
}
2015-09-15 02:05:53 +00:00
void App::OnActivate(bool has_visible_windows) {
Emit("activate", has_visible_windows);
}
void App::OnWillFinishLaunching() {
Emit("will-finish-launching");
}
void App::OnFinishLaunching(const base::DictionaryValue& launch_info) {
#if defined(OS_LINUX)
// Set the application name for audio streams shown in external
// applications. Only affects pulseaudio currently.
media::AudioManager::SetGlobalAppName(Browser::Get()->GetName());
#endif
Emit("ready", launch_info);
}
void App::OnPreMainMessageLoopRun() {
content::BrowserChildProcessObserver::Add(this);
if (process_singleton_) {
process_singleton_->OnBrowserReady();
}
}
void App::OnAccessibilitySupportChanged() {
Emit("accessibility-support-changed", IsAccessibilitySupportEnabled());
}
2016-05-05 03:26:23 +00:00
#if defined(OS_MACOSX)
2018-04-18 01:55:30 +00:00
void App::OnWillContinueUserActivity(bool* prevent_default,
const std::string& type) {
if (Emit("will-continue-activity", type)) {
*prevent_default = true;
}
}
2017-09-14 07:12:34 +00:00
2018-04-18 01:55:30 +00:00
void App::OnDidFailToContinueUserActivity(const std::string& type,
const std::string& error) {
Emit("continue-activity-error", type, error);
}
2017-09-14 07:12:34 +00:00
2018-04-18 01:55:30 +00:00
void App::OnContinueUserActivity(bool* prevent_default,
const std::string& type,
const base::DictionaryValue& user_info) {
if (Emit("continue-activity", type, user_info)) {
*prevent_default = true;
}
}
2017-09-14 07:12:34 +00:00
2018-04-18 01:55:30 +00:00
void App::OnUserActivityWasContinued(const std::string& type,
const base::DictionaryValue& user_info) {
Emit("activity-was-continued", type, user_info);
}
2017-09-14 07:12:34 +00:00
2018-04-18 01:55:30 +00:00
void App::OnUpdateUserActivityState(bool* prevent_default,
const std::string& type,
const base::DictionaryValue& user_info) {
if (Emit("update-activity-state", type, user_info)) {
*prevent_default = true;
}
}
2017-09-14 07:12:34 +00:00
void App::OnNewWindowForTab() {
Emit("new-window-for-tab");
}
2016-05-05 03:26:23 +00:00
#endif
void App::OnLogin(scoped_refptr<LoginHandler> login_handler,
const base::DictionaryValue& request_details) {
2015-10-28 13:00:39 +00:00
v8::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());
bool prevent_default = false;
content::WebContents* web_contents = login_handler->GetWebContents();
if (web_contents) {
prevent_default =
Emit("login", WebContents::FromOrCreate(isolate(), web_contents),
request_details, *login_handler->auth_info(),
base::BindOnce(&PassLoginInformation,
base::RetainedRef(login_handler)));
}
2015-10-28 11:34:01 +00:00
2015-10-28 13:00:39 +00:00
// Default behavior is to always cancel the auth.
2015-10-28 11:34:01 +00:00
if (!prevent_default)
login_handler->CancelAuth();
}
bool App::CanCreateWindow(
content::RenderFrameHost* opener,
const GURL& opener_url,
const GURL& opener_top_level_frame_url,
const url::Origin& source_origin,
content::mojom::WindowContainerType container_type,
const GURL& target_url,
const content::Referrer& referrer,
const std::string& frame_name,
WindowOpenDisposition disposition,
const blink::mojom::WindowFeatures& features,
const std::vector<std::string>& additional_features,
const scoped_refptr<network::ResourceRequestBody>& body,
bool user_gesture,
bool opener_suppressed,
bool* no_javascript_access) {
2016-03-31 14:21:18 +00:00
v8::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());
content::WebContents* web_contents =
content::WebContents::FromRenderFrameHost(opener);
2016-03-31 14:21:18 +00:00
if (web_contents) {
auto api_web_contents = WebContents::From(isolate(), web_contents);
// No need to emit any event if the WebContents is not available in JS.
if (!api_web_contents.IsEmpty()) {
api_web_contents->OnCreateWindow(target_url, referrer, frame_name,
disposition, additional_features, body);
}
2016-03-31 14:21:18 +00:00
}
return false;
2016-03-31 14:21:18 +00:00
}
2015-11-18 02:39:25 +00:00
void App::AllowCertificateError(
2016-03-08 14:28:53 +00:00
content::WebContents* web_contents,
2015-11-18 02:39:25 +00:00
int cert_error,
const net::SSLInfo& ssl_info,
const GURL& request_url,
bool is_main_frame_request,
2015-11-18 02:39:25 +00:00
bool strict_enforcement,
const base::RepeatingCallback<void(content::CertificateRequestResultType)>&
2016-11-30 07:30:03 +00:00
callback) {
2015-11-18 02:39:25 +00:00
v8::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());
2018-04-18 01:55:30 +00:00
bool prevent_default = Emit(
"certificate-error", WebContents::FromOrCreate(isolate(), web_contents),
2018-04-18 01:55:30 +00:00
request_url, net::ErrorToString(cert_error), ssl_info.cert, callback);
2015-11-18 02:39:25 +00:00
// Deny the certificate by default.
if (!prevent_default)
2016-11-30 07:30:03 +00:00
callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
2015-11-18 02:39:25 +00:00
}
chore: bump chromium to f1d9522c04ca8fa0a906f88ababe9 (master) (#18648) * chore: bump chromium in DEPS to 675d7dc9f3334b15c3ec28c27db3dc19b26bd12e * chore: update patches * chore: bump chromium in DEPS to dce3562696f165a324273fcb6893f0e1fef42ab1 * chore: const interfaces are being removed from //content Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1631749 Bug: https://bugs.chromium.org/p/chromium/issues/detail?id=908139 * chore: update patches * chore: blink::MediaStreamType is now consistent and deduplicated * chore: update patches and printing code for ref -> uniq * chore: bridge_impl() --> GetInProcessNSWindowBridge Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1642988 * fixme: TotalMarkedObjectSize has been removed * chore: fix linting * chore: bump chromium in DEPS to 9503e1a2fcbf17db08094d8caae3e1407e918af3 * chore: fix slightly broken printing patch * chore: update patches for SiteInstanceImpl changes Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1612025 * chore: update patches for SiteInstanceImpl changes * chore: bump chromium in DEPS to 6801e6c1ddd1b7b73e594e97157ddd539ca335d7 * chore: update patches * chore: bump chromium in DEPS to 27e198912d7c1767052ec785c22e2e88b2cb4d8b * chore: remove system_request_context Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1647172 * chore: creation of FtpProtocolHandler needs an auth cache Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1639683 * fixme: disable marked spec * chore: bump chromium in DEPS to 3dcd7fe453ad13a22b114b95f05590eba74c5471 * chore: bump chromium in DEPS to bdc24128b75008743d819e298557a53205706e7c * chore: bump chromium in DEPS to 7da330b58fbe0ba94b9b94abbb8085bead220228 * update patches * remove TotalMarkedObjectSize https://chromium-review.googlesource.com/c/chromium/src/+/1631708 * add libvulkan.so to dist zip manifest on linux * chore: bump chromium in DEPS to 1e85d0f45b52649efd0010cc9dab6d2804f24443 * update patches * add angle features to gpuinfo https://chromium-review.googlesource.com/c/chromium/src/+/1638658 * mark 'marked' property as deprecated * disable webview resize test * FIXME: disable vulkan on 32-bit arm * chore: bump chromium in DEPS to cd0297c6a83fdd2b1f6bc312e7d5acca736a3c56 * Revert "FIXME: disable vulkan on 32-bit arm" This reverts commit 5c1e0ef302a6db1e72231d4e823f91bb08e281af. * backport from upstream: fix swiftshader build on arm https://swiftshader-review.googlesource.com/c/SwiftShader/+/32768/ * update patches * viz: update OutputDeviceWin to new shared memory api https://chromium-review.googlesource.com/c/chromium/src/+/1649574 * base::Contains{Key,Value} => base::Contains https://chromium-review.googlesource.com/c/chromium/src/+/1649478 * fixup! viz: update OutputDeviceWin to new shared memory api * stub out StatusIconLinuxDbus-related delegate methods https://chromium-review.googlesource.com/c/chromium/src/+/1638180 * chore: bump chromium in DEPS to 964ea3fd4bdc006d62533f5755043076220181f1 * Remove the BrowserContext methods to create URLRequestContexts for main/media partitions when a partition_domain is specified https://chromium-review.googlesource.com/c/chromium/src/+/1655087 * fixup! stub out StatusIconLinuxDbus-related delegate methods * add remote_cocoa to chromium_src deps https://chromium-review.googlesource.com/c/chromium/src/+/1657068 * fixup! stub out StatusIconLinuxDbus-related delegate methods * attempt at fix linux-debug build * add swiftshader/libvulkan.so to arm manifest * chore: bump chromium in DEPS to 28688f76afef27c36631aa274691e333ddecdc22 * update patches * chore: bump chromium in DEPS to fe7450e1578a9584189f87d59d0d1a8548bf6b90 * chore: bump chromium in DEPS to f304dfd682dc86a755a6c49a16ee6876e0db45fb * chore: bump chromium in DEPS to f0fd4d6c365aad9edd83bdfff9954c47d271b75c * Update patches * Remove no longer needed WOA patch * Put back IOThread in BrowserProcess We need this until we enable the network service. * move atom.ico to inputs * Update to latest LKGR to fix no template named 'bitset' in namespace 'std' * fixup! Put back IOThread in BrowserProcess * chore: bump chromium in DEPS to dcf9662dc9a896a175d791001350324167b1cad3 * Update patches content_allow_embedder_to_prevent_locking_scheme_registry.patch is no longer necessary as it was upstreamed via https://chromium-review.googlesource.com/c/chromium/src/+/1637040 * Fix renamed enum * Use newer docker container Contains updated dependencies * Try to track down arm test failures * Fix arm tests * chore: bump chromium in DEPS to 8cbceef57b37ee14b9c4c3405a3f7663922c5b5d * Update patches * Add needed dependencies for testing 32-bit linux * Remove arm debugging. * Remove additional debugging * Fix compiler errors * Handle new macOS helper * Fix compile error on Linux * chore: bump chromium in DEPS to 66a93991ddaff6a9f1b13d110959947cb03a1860 * Add new helper files to manifests * fix BUILD.gn for macOS * Fix compile errors * Add patch to put back colors needed for autofill/datalist * chore: bump chromium in DEPS to e89617079f11e33f33cdb3924f719a579c73704b * Updated patches * Remove no longer needed patch * Remove no longer needed patch * Fix compile error with patch * Really fix the patch * chore: bump chromium in DEPS to c70f12476a45840408f1d5ff5968e7f7ceaad9d4 * chore: bump chromium in DEPS to 06d2dd7a8933b41545a7c26349c802f570563fd5 * chore: bump chromium in DEPS to b0b9ff8f727deb519ccbec7cf1c8d9ed543d88ab * Update patches * Fix compiler errors * Fix removed ChromeNetLog * Revert "Fix removed ChromeNetLog" This reverts commit 426dfd90b5ab0a9c1df415d71c88e8aed2bd5bbe. * Remove ChromeNetLog. https://chromium-review.googlesource.com/c/chromium/src/+/1663846 * chore: bump chromium in DEPS to fefcc4926d58dccd59ac95be65eab3a4ebfe2f29 * Update patches * Update v8 patches * Fix lint error * Fix compile errors * chore: bump chromium in DEPS to 4de815ef92ef2eef515506fe09bdc466526a8fd9 * Use custom protocol to test baseURLForDataURL * Use newer SDK (10.0.18362) for Windows * Update patches * Update arm manifest since swiftshader reenabled. * Don't delete dir that isn't ever there. * Fix compile errors. * Need src dir created * Update for removed InspectorFrontendAPI.addExtensions * Revert "Use newer SDK (10.0.18362) for Windows" This reverts commit 68763a0c88cdc44b971462e49662aecc167d3d99. * Revert "Need src dir created" This reverts commit 7daedc29d0844316d4097648dde7f40f1a3848fb. * Revert "Don't delete dir that isn't ever there." This reverts commit bf424bc30ffcb23b1d9a634d4df410342536640e. * chore: bump chromium in DEPS to 97dab6b0124ea53244caf123921b5d14893bcca7 * chore: bump chromium in DEPS to c87d16d49a85dc7122781f6c979d354c20f7f78b * chore: bump chromium in DEPS to 004bcee2ea336687cedfda8f8a151806ac757d15 * chore: bump chromium in DEPS to 24428b26a9d15a013b2a253e1084ec3cb54b660b * chore: bump chromium in DEPS to fd25914e875237df88035a6abf89a70bf1360b57 * Update patches * Update node to fix build error * Fix compile errors * chore: bump chromium in DEPS to 3062b7cf090f1d9522c04ca8fa0a906f88ababe9 * chore: update node ref for pushed tags * chore: update patches for new chromium * chore: fix printing patches * Use new (10.0.18362) Windows SDK * roll node to fix v8 build issues in debug build * Add support for plugin helper * fix: add patch to fix gpu info enumeration Can be removed once CL lands upstream. Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1685993 * spec: navigator.requestMIDIAccess now requires a secure origin This test requires a secure origin so we fake one. Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1657952 * FIXME: temporarily disable SharedWorker tests * use released version of node-abstractsocket * fix abstract-socket
2019-07-03 01:22:09 +00:00
base::OnceClosure App::SelectClientCertificate(
2015-11-18 02:07:03 +00:00
content::WebContents* web_contents,
net::SSLCertRequestInfo* cert_request_info,
net::ClientCertIdentityList identities,
2016-05-23 01:59:39 +00:00
std::unique_ptr<content::ClientCertificateDelegate> delegate) {
2018-04-18 01:55:30 +00:00
std::shared_ptr<content::ClientCertificateDelegate> shared_delegate(
delegate.release());
// Convert the ClientCertIdentityList to a CertificateList
// to avoid changes in the API.
auto client_certs = net::CertificateList();
for (const std::unique_ptr<net::ClientCertIdentity>& identity : identities)
client_certs.push_back(identity->certificate());
auto shared_identities =
std::make_shared<net::ClientCertIdentityList>(std::move(identities));
2015-11-18 02:07:03 +00:00
bool prevent_default =
Emit("select-client-certificate",
WebContents::FromOrCreate(isolate(), web_contents),
cert_request_info->host_and_port.ToString(), std::move(client_certs),
base::BindOnce(&OnClientCertificateSelected, isolate(),
shared_delegate, shared_identities));
2015-11-18 02:07:03 +00:00
// Default to first certificate from the platform store.
if (!prevent_default) {
scoped_refptr<net::X509Certificate> cert =
(*shared_identities)[0]->certificate();
net::ClientCertIdentity::SelfOwningAcquirePrivateKey(
std::move((*shared_identities)[0]),
base::BindRepeating(&GotPrivateKey, shared_delegate, std::move(cert)));
}
chore: bump chromium to f1d9522c04ca8fa0a906f88ababe9 (master) (#18648) * chore: bump chromium in DEPS to 675d7dc9f3334b15c3ec28c27db3dc19b26bd12e * chore: update patches * chore: bump chromium in DEPS to dce3562696f165a324273fcb6893f0e1fef42ab1 * chore: const interfaces are being removed from //content Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1631749 Bug: https://bugs.chromium.org/p/chromium/issues/detail?id=908139 * chore: update patches * chore: blink::MediaStreamType is now consistent and deduplicated * chore: update patches and printing code for ref -> uniq * chore: bridge_impl() --> GetInProcessNSWindowBridge Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1642988 * fixme: TotalMarkedObjectSize has been removed * chore: fix linting * chore: bump chromium in DEPS to 9503e1a2fcbf17db08094d8caae3e1407e918af3 * chore: fix slightly broken printing patch * chore: update patches for SiteInstanceImpl changes Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1612025 * chore: update patches for SiteInstanceImpl changes * chore: bump chromium in DEPS to 6801e6c1ddd1b7b73e594e97157ddd539ca335d7 * chore: update patches * chore: bump chromium in DEPS to 27e198912d7c1767052ec785c22e2e88b2cb4d8b * chore: remove system_request_context Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1647172 * chore: creation of FtpProtocolHandler needs an auth cache Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1639683 * fixme: disable marked spec * chore: bump chromium in DEPS to 3dcd7fe453ad13a22b114b95f05590eba74c5471 * chore: bump chromium in DEPS to bdc24128b75008743d819e298557a53205706e7c * chore: bump chromium in DEPS to 7da330b58fbe0ba94b9b94abbb8085bead220228 * update patches * remove TotalMarkedObjectSize https://chromium-review.googlesource.com/c/chromium/src/+/1631708 * add libvulkan.so to dist zip manifest on linux * chore: bump chromium in DEPS to 1e85d0f45b52649efd0010cc9dab6d2804f24443 * update patches * add angle features to gpuinfo https://chromium-review.googlesource.com/c/chromium/src/+/1638658 * mark 'marked' property as deprecated * disable webview resize test * FIXME: disable vulkan on 32-bit arm * chore: bump chromium in DEPS to cd0297c6a83fdd2b1f6bc312e7d5acca736a3c56 * Revert "FIXME: disable vulkan on 32-bit arm" This reverts commit 5c1e0ef302a6db1e72231d4e823f91bb08e281af. * backport from upstream: fix swiftshader build on arm https://swiftshader-review.googlesource.com/c/SwiftShader/+/32768/ * update patches * viz: update OutputDeviceWin to new shared memory api https://chromium-review.googlesource.com/c/chromium/src/+/1649574 * base::Contains{Key,Value} => base::Contains https://chromium-review.googlesource.com/c/chromium/src/+/1649478 * fixup! viz: update OutputDeviceWin to new shared memory api * stub out StatusIconLinuxDbus-related delegate methods https://chromium-review.googlesource.com/c/chromium/src/+/1638180 * chore: bump chromium in DEPS to 964ea3fd4bdc006d62533f5755043076220181f1 * Remove the BrowserContext methods to create URLRequestContexts for main/media partitions when a partition_domain is specified https://chromium-review.googlesource.com/c/chromium/src/+/1655087 * fixup! stub out StatusIconLinuxDbus-related delegate methods * add remote_cocoa to chromium_src deps https://chromium-review.googlesource.com/c/chromium/src/+/1657068 * fixup! stub out StatusIconLinuxDbus-related delegate methods * attempt at fix linux-debug build * add swiftshader/libvulkan.so to arm manifest * chore: bump chromium in DEPS to 28688f76afef27c36631aa274691e333ddecdc22 * update patches * chore: bump chromium in DEPS to fe7450e1578a9584189f87d59d0d1a8548bf6b90 * chore: bump chromium in DEPS to f304dfd682dc86a755a6c49a16ee6876e0db45fb * chore: bump chromium in DEPS to f0fd4d6c365aad9edd83bdfff9954c47d271b75c * Update patches * Remove no longer needed WOA patch * Put back IOThread in BrowserProcess We need this until we enable the network service. * move atom.ico to inputs * Update to latest LKGR to fix no template named 'bitset' in namespace 'std' * fixup! Put back IOThread in BrowserProcess * chore: bump chromium in DEPS to dcf9662dc9a896a175d791001350324167b1cad3 * Update patches content_allow_embedder_to_prevent_locking_scheme_registry.patch is no longer necessary as it was upstreamed via https://chromium-review.googlesource.com/c/chromium/src/+/1637040 * Fix renamed enum * Use newer docker container Contains updated dependencies * Try to track down arm test failures * Fix arm tests * chore: bump chromium in DEPS to 8cbceef57b37ee14b9c4c3405a3f7663922c5b5d * Update patches * Add needed dependencies for testing 32-bit linux * Remove arm debugging. * Remove additional debugging * Fix compiler errors * Handle new macOS helper * Fix compile error on Linux * chore: bump chromium in DEPS to 66a93991ddaff6a9f1b13d110959947cb03a1860 * Add new helper files to manifests * fix BUILD.gn for macOS * Fix compile errors * Add patch to put back colors needed for autofill/datalist * chore: bump chromium in DEPS to e89617079f11e33f33cdb3924f719a579c73704b * Updated patches * Remove no longer needed patch * Remove no longer needed patch * Fix compile error with patch * Really fix the patch * chore: bump chromium in DEPS to c70f12476a45840408f1d5ff5968e7f7ceaad9d4 * chore: bump chromium in DEPS to 06d2dd7a8933b41545a7c26349c802f570563fd5 * chore: bump chromium in DEPS to b0b9ff8f727deb519ccbec7cf1c8d9ed543d88ab * Update patches * Fix compiler errors * Fix removed ChromeNetLog * Revert "Fix removed ChromeNetLog" This reverts commit 426dfd90b5ab0a9c1df415d71c88e8aed2bd5bbe. * Remove ChromeNetLog. https://chromium-review.googlesource.com/c/chromium/src/+/1663846 * chore: bump chromium in DEPS to fefcc4926d58dccd59ac95be65eab3a4ebfe2f29 * Update patches * Update v8 patches * Fix lint error * Fix compile errors * chore: bump chromium in DEPS to 4de815ef92ef2eef515506fe09bdc466526a8fd9 * Use custom protocol to test baseURLForDataURL * Use newer SDK (10.0.18362) for Windows * Update patches * Update arm manifest since swiftshader reenabled. * Don't delete dir that isn't ever there. * Fix compile errors. * Need src dir created * Update for removed InspectorFrontendAPI.addExtensions * Revert "Use newer SDK (10.0.18362) for Windows" This reverts commit 68763a0c88cdc44b971462e49662aecc167d3d99. * Revert "Need src dir created" This reverts commit 7daedc29d0844316d4097648dde7f40f1a3848fb. * Revert "Don't delete dir that isn't ever there." This reverts commit bf424bc30ffcb23b1d9a634d4df410342536640e. * chore: bump chromium in DEPS to 97dab6b0124ea53244caf123921b5d14893bcca7 * chore: bump chromium in DEPS to c87d16d49a85dc7122781f6c979d354c20f7f78b * chore: bump chromium in DEPS to 004bcee2ea336687cedfda8f8a151806ac757d15 * chore: bump chromium in DEPS to 24428b26a9d15a013b2a253e1084ec3cb54b660b * chore: bump chromium in DEPS to fd25914e875237df88035a6abf89a70bf1360b57 * Update patches * Update node to fix build error * Fix compile errors * chore: bump chromium in DEPS to 3062b7cf090f1d9522c04ca8fa0a906f88ababe9 * chore: update node ref for pushed tags * chore: update patches for new chromium * chore: fix printing patches * Use new (10.0.18362) Windows SDK * roll node to fix v8 build issues in debug build * Add support for plugin helper * fix: add patch to fix gpu info enumeration Can be removed once CL lands upstream. Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1685993 * spec: navigator.requestMIDIAccess now requires a secure origin This test requires a secure origin so we fake one. Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1657952 * FIXME: temporarily disable SharedWorker tests * use released version of node-abstractsocket * fix abstract-socket
2019-07-03 01:22:09 +00:00
return base::OnceClosure();
2015-11-18 02:07:03 +00:00
}
void App::OnGpuInfoUpdate() {
Emit("gpu-info-update");
}
void App::OnGpuProcessCrashed(base::TerminationStatus status) {
Emit("gpu-process-crashed",
2018-04-18 01:55:30 +00:00
status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
2015-06-25 12:28:07 +00:00
}
2017-05-16 00:41:45 +00:00
void App::BrowserChildProcessLaunchedAndConnected(
const content::ChildProcessData& data) {
ChildProcessLaunched(data.process_type, data.GetProcess().Handle());
2017-05-16 00:41:45 +00:00
}
void App::BrowserChildProcessHostDisconnected(
const content::ChildProcessData& data) {
ChildProcessDisconnected(base::GetProcId(data.GetProcess().Handle()));
2017-05-16 00:41:45 +00:00
}
void App::BrowserChildProcessCrashed(
const content::ChildProcessData& data,
const content::ChildProcessTerminationInfo& info) {
ChildProcessDisconnected(base::GetProcId(data.GetProcess().Handle()));
}
void App::BrowserChildProcessKilled(
const content::ChildProcessData& data,
const content::ChildProcessTerminationInfo& info) {
ChildProcessDisconnected(base::GetProcId(data.GetProcess().Handle()));
}
2017-05-26 14:51:17 +00:00
void App::RenderProcessReady(content::RenderProcessHost* host) {
2018-09-15 00:13:02 +00:00
ChildProcessLaunched(content::PROCESS_TYPE_RENDERER,
host->GetProcess().Handle());
// TODO(jeremy): this isn't really the right place to be creating
// `WebContents` instances, but this was implicitly happening before in
// `RenderProcessPreferences`, so this is at least more explicit...
content::WebContents* web_contents =
AtomBrowserClient::Get()->GetWebContentsFromProcessID(host->GetID());
if (web_contents)
WebContents::FromOrCreate(v8::Isolate::GetCurrent(), web_contents);
2017-05-16 00:41:45 +00:00
}
void App::RenderProcessDisconnected(base::ProcessId host_pid) {
ChildProcessDisconnected(host_pid);
2017-05-16 00:41:45 +00:00
}
void App::ChildProcessLaunched(int process_type, base::ProcessHandle handle) {
auto pid = base::GetProcId(handle);
2017-05-16 00:41:45 +00:00
#if defined(OS_MACOSX)
auto metrics = base::ProcessMetrics::CreateProcessMetrics(
handle, content::BrowserChildProcessHost::GetPortProvider());
2017-05-16 00:41:45 +00:00
#else
auto metrics = base::ProcessMetrics::CreateProcessMetrics(handle);
2017-05-16 00:41:45 +00:00
#endif
app_metrics_[pid] = std::make_unique<electron::ProcessMetric>(
process_type, handle, std::move(metrics));
2017-05-16 00:41:45 +00:00
}
2017-05-26 14:51:17 +00:00
void App::ChildProcessDisconnected(base::ProcessId pid) {
2017-05-16 00:41:45 +00:00
app_metrics_.erase(pid);
}
2017-04-13 14:26:42 +00:00
base::FilePath App::GetAppPath() const {
2017-04-04 00:36:01 +00:00
return app_path_;
}
2017-04-13 01:59:12 +00:00
void App::SetAppPath(const base::FilePath& app_path) {
2017-04-04 00:36:01 +00:00
app_path_ = app_path;
}
#if !defined(OS_MACOSX)
void App::SetAppLogsPath(base::Optional<base::FilePath> custom_path,
mate::Arguments* args) {
if (custom_path.has_value()) {
if (!custom_path->IsAbsolute()) {
args->ThrowError("Path must be absolute");
return;
}
base::PathService::Override(DIR_APP_LOGS, custom_path.value());
} else {
base::FilePath path;
if (base::PathService::Get(DIR_USER_DATA, &path)) {
path = path.Append(base::FilePath::FromUTF8Unsafe(GetApplicationName()));
path = path.Append(base::FilePath::FromUTF8Unsafe("logs"));
base::PathService::Override(DIR_APP_LOGS, path);
}
}
}
#endif
base::FilePath App::GetPath(mate::Arguments* args, const std::string& name) {
bool succeed = false;
base::FilePath path;
int key = GetPathConstant(name);
if (key >= 0) {
2018-09-15 00:09:42 +00:00
succeed = base::PathService::Get(key, &path);
// If users try to get the logs path before setting a logs path,
// set the path to a sensible default and then try to get it again
if (!succeed && name == "logs") {
base::ThreadRestrictions::ScopedAllowIO allow_io;
SetAppLogsPath(base::Optional<base::FilePath>(), args);
succeed = base::PathService::Get(key, &path);
}
}
if (!succeed)
args->ThrowError("Failed to get '" + name + "' path");
2015-01-19 01:11:27 +00:00
return path;
}
void App::SetPath(mate::Arguments* args,
const std::string& name,
const base::FilePath& path) {
if (!path.IsAbsolute()) {
2016-10-06 16:14:16 +00:00
args->ThrowError("Path must be absolute");
return;
}
bool succeed = false;
int key = GetPathConstant(name);
if (key >= 0)
2018-09-15 00:09:42 +00:00
succeed =
base::PathService::OverrideAndCreateIfNeeded(key, path, true, false);
if (!succeed)
args->ThrowError("Failed to set path");
}
2014-09-18 11:12:24 +00:00
void App::SetDesktopName(const std::string& desktop_name) {
#if defined(OS_LINUX)
2016-05-23 01:59:39 +00:00
std::unique_ptr<base::Environment> env(base::Environment::Create());
2014-09-18 11:12:24 +00:00
env->SetVar("CHROME_DESKTOP", desktop_name);
#endif
}
2015-09-16 08:16:21 +00:00
std::string App::GetLocale() {
return g_browser_process->GetApplicationLocale();
2015-09-16 08:16:21 +00:00
}
std::string App::GetLocaleCountryCode() {
std::string region;
#if defined(OS_WIN)
WCHAR locale_name[LOCALE_NAME_MAX_LENGTH] = {0};
if (GetLocaleInfoEx(LOCALE_NAME_USER_DEFAULT, LOCALE_SISO3166CTRYNAME,
(LPWSTR)&locale_name,
sizeof(locale_name) / sizeof(WCHAR)) ||
GetLocaleInfoEx(LOCALE_NAME_SYSTEM_DEFAULT, LOCALE_SISO3166CTRYNAME,
(LPWSTR)&locale_name,
sizeof(locale_name) / sizeof(WCHAR))) {
base::WideToUTF8(locale_name, wcslen(locale_name), &region);
}
#elif defined(OS_MACOSX)
CFLocaleRef locale = CFLocaleCopyCurrent();
CFStringRef value = CFStringRef(
static_cast<CFTypeRef>(CFLocaleGetValue(locale, kCFLocaleCountryCode)));
const CFIndex kCStringSize = 128;
char temporaryCString[kCStringSize] = {0};
CFStringGetCString(value, temporaryCString, kCStringSize,
kCFStringEncodingUTF8);
region = temporaryCString;
#else
const char* locale_ptr = setlocale(LC_TIME, NULL);
if (!locale_ptr)
locale_ptr = setlocale(LC_NUMERIC, NULL);
if (locale_ptr) {
std::string locale = locale_ptr;
std::string::size_type rpos = locale.find('.');
if (rpos != std::string::npos)
locale = locale.substr(0, rpos);
rpos = locale.find('_');
if (rpos != std::string::npos && rpos + 1 < locale.size())
region = locale.substr(rpos + 1);
}
#endif
return region.size() == 2 ? region : std::string();
}
void App::OnSecondInstance(const base::CommandLine::StringVector& cmd,
const base::FilePath& cwd) {
Emit("second-instance", cmd, cwd);
}
bool App::HasSingleInstanceLock() const {
if (process_singleton_)
return true;
return false;
}
bool App::RequestSingleInstanceLock() {
if (HasSingleInstanceLock())
return true;
2015-10-21 20:17:56 +00:00
base::FilePath user_dir;
2018-10-24 10:49:10 +00:00
base::PathService::Get(DIR_USER_DATA, &user_dir);
auto cb = base::BindRepeating(&App::OnSecondInstance, base::Unretained(this));
process_singleton_.reset(new ProcessSingleton(
user_dir, base::BindRepeating(NotificationCallbackWrapper, cb)));
2015-10-20 01:02:54 +00:00
switch (process_singleton_->NotifyOtherProcessOrCreate()) {
2015-10-19 23:21:03 +00:00
case ProcessSingleton::NotifyResult::LOCK_ERROR:
case ProcessSingleton::NotifyResult::PROFILE_IN_USE:
case ProcessSingleton::NotifyResult::PROCESS_NOTIFIED: {
process_singleton_.reset();
return false;
}
2015-10-22 08:55:54 +00:00
case ProcessSingleton::NotifyResult::PROCESS_NONE:
default: // Shouldn't be needed, but VS warns if it is not there.
return true;
2015-10-19 23:21:03 +00:00
}
}
void App::ReleaseSingleInstanceLock() {
if (process_singleton_) {
process_singleton_->Cleanup();
process_singleton_.reset();
}
}
bool App::Relaunch(mate::Arguments* js_args) {
// Parse parameters.
bool override_argv = false;
base::FilePath exec_path;
relauncher::StringVector args;
mate::Dictionary options;
if (js_args->GetNext(&options)) {
2016-06-03 03:08:45 +00:00
if (options.Get("execPath", &exec_path) | options.Get("args", &args))
override_argv = true;
}
if (!override_argv) {
const relauncher::StringVector& argv = electron::AtomCommandLine::argv();
return relauncher::RelaunchApp(argv);
}
relauncher::StringVector argv;
argv.reserve(1 + args.size());
if (exec_path.empty()) {
base::FilePath current_exe_path;
2018-09-15 00:09:42 +00:00
base::PathService::Get(base::FILE_EXE, &current_exe_path);
argv.push_back(current_exe_path.value());
} else {
argv.push_back(exec_path.value());
}
argv.insert(argv.end(), args.begin(), args.end());
return relauncher::RelaunchApp(argv);
}
void App::DisableHardwareAcceleration(mate::Arguments* args) {
if (Browser::Get()->is_ready()) {
2018-04-18 01:55:30 +00:00
args->ThrowError(
"app.disableHardwareAcceleration() can only be called "
"before app is ready");
return;
}
content::GpuDataManager::GetInstance()->DisableHardwareAcceleration();
}
void App::DisableDomainBlockingFor3DAPIs(mate::Arguments* args) {
if (Browser::Get()->is_ready()) {
args->ThrowError(
"app.disableDomainBlockingFor3DAPIs() can only be called "
"before app is ready");
return;
}
content::GpuDataManagerImpl::GetInstance()
->DisableDomainBlockingFor3DAPIsForTesting();
}
bool App::IsAccessibilitySupportEnabled() {
auto* ax_state = content::BrowserAccessibilityState::GetInstance();
return ax_state->IsAccessibleBrowser();
}
void App::SetAccessibilitySupportEnabled(bool enabled, mate::Arguments* args) {
if (!Browser::Get()->is_ready()) {
args->ThrowError(
"app.setAccessibilitySupportEnabled() can only be called "
"after app is ready");
return;
}
auto* ax_state = content::BrowserAccessibilityState::GetInstance();
if (enabled) {
2017-08-24 14:22:28 +00:00
ax_state->OnScreenReaderDetected();
} else {
ax_state->DisableAccessibility();
}
Browser::Get()->OnAccessibilitySupportChanged();
}
Browser::LoginItemSettings App::GetLoginItemSettings(mate::Arguments* args) {
Browser::LoginItemSettings options;
args->GetNext(&options);
return Browser::Get()->GetLoginItemSettings(options);
}
#if defined(USE_NSS_CERTS)
2018-04-18 01:55:30 +00:00
void App::ImportCertificate(const base::DictionaryValue& options,
chore: bump chromium to 1e9f9a24aa12 (master) (#17880) * chore: bump chromium in DEPS to 1e9f9a24aa12bea9cf194a82a7e249bd1242ec4f * chore: update patches * Make WebContents' theme color a base::Optional<SkColor> https://chromium-review.googlesource.com/c/chromium/src/+/1540022 * update autofill patch for incorrect header includes * Move Shell messages to web_test and rename to BlinkTest. https://chromium-review.googlesource.com/c/chromium/src/+/1525181 * Make PlatformNotificationServiceImpl a KeyedService. https://chromium-review.googlesource.com/c/chromium/src/+/1336150 * Move MediaPlayerId to its own file. https://chromium-review.googlesource.com/c/chromium/src/+/1547057 * Remove net/base/completion_callback.h, which is no longer used https://chromium-review.googlesource.com/c/chromium/src/+/1552821 * AW NS: support file scheme cookies https://chromium-review.googlesource.com/c/chromium/src/+/1533486 * Remove SecurityInfo and adapt remaining consumers https://chromium-review.googlesource.com/c/chromium/src/+/1509455 * Remove deprecated type-specific number to string conversion functions https://chromium-review.googlesource.com/c/chromium/src/+/1545881 * DevTools: Adding new performance histograms for launch of top 4 tools https://chromium-review.googlesource.com/c/chromium/src/+/1506388 * Update include paths for //base/hash/hash.h https://chromium-review.googlesource.com/c/chromium/src/+/1544630 * build: Disable ensure_gn_version gclient hook for mac CI checkout * update patches * use maybe version of v8::String::NewFromTwoByte * bump appveyor image version * fix mac ci hopefully * Convert enum to enum class for MenuAnchorPosition https://chromium-review.googlesource.com/c/chromium/src/+/1530508 * use maybe version of ToObject * RenderViewHost::GetProcess is no longer const * Unrefcount AuthChallengeInfo https://chromium-review.googlesource.com/c/chromium/src/+/1550631 * MenuButtonController takes Button rather than MenuButton https://chromium-review.googlesource.com/c/chromium/src/+/1500935 * add //ui/views_bridge_mac to deps to fix link error * forward declare views::Button in atom::MenuDelegate * more v8 patches * base/{=> hash}/md5.h https://chromium-review.googlesource.com/c/chromium/src/+/1535124 * gfx::{PlatformFontWin => win}::* https://chromium-review.googlesource.com/c/chromium/src/+/1534178 * fix v8 patches * [base] Rename TaskScheduler to ThreadPool https://chromium-review.googlesource.com/c/chromium/src/+/1561552 * use internal_config_base for bytecode_builtins_list_generator avoids windows link errors * FIXME: temporarily disable v8/breakpad integration * FIXME: temporarily disable prevent-will-redirect test * FIXME: disable neon on aarch64 pending crbug.com/953815 * update to account for WebCursor refactor https://chromium-review.googlesource.com/c/chromium/src/+/1562755 * enable stack dumping on appveyor * Revert "FIXME: disable neon on aarch64 pending crbug.com/953815" This reverts commit 57f082026be3d83069f2a2814684abf4dc9e7b53. * fix: remove const qualifiers to match upstream * fix: remove const qualifiers to match upstream in cc files as well * don't throw an error when testing if an object is an object * use non-deprecated Buffer constructor * Remove net::CookieSameSite::DEFAULT_MODE enum value https://chromium-review.googlesource.com/c/chromium/src/+/1567955 * depend on modded dbus-native to work around buffer deprecation https://github.com/sidorares/dbus-native/pull/262 * revert clang roll to fix arm build on linux * fixup! depend on modded dbus-native to work around buffer deprecation need more coffee * update coffee-script * robustify verify-mksnapshot w.r.t. command-line parameters * Revert "robustify verify-mksnapshot w.r.t. command-line parameters" This reverts commit a49af01411f684f6025528d604895c3696e0bc57. * fix mksnapshot by matching args * update patches * TMP: enable rdp on appveyor * Changed ContentBrowserClient::CreateQuotaPermissionContext() to return scoped_refptr. https://chromium-review.googlesource.com/c/chromium/src/+/1569376 * Make content::ResourceType an enum class. https://chromium-review.googlesource.com/c/chromium/src/+/1569345 * fixup! Make content::ResourceType an enum class. * turn off rdp * use net::CompletionRepeatingCallback instead of base::Callback<void(int)> * remove disable_ensure_gn_version_gclient_hook.patch * copy repeating callback instead of std::move * fix lint * add completion_repeating_callback.h include
2019-04-20 17:20:37 +00:00
net::CompletionRepeatingCallback callback) {
2016-07-12 13:45:15 +00:00
auto browser_context = AtomBrowserContext::From("", false);
2016-04-18 05:11:31 +00:00
if (!certificate_manager_model_) {
auto copy = base::DictionaryValue::From(
base::Value::ToUniquePtrValue(options.Clone()));
CertificateManagerModel::Create(
browser_context.get(),
base::BindRepeating(&App::OnCertificateManagerModelCreated,
base::Unretained(this), base::Passed(&copy),
callback));
2016-04-18 05:11:31 +00:00
return;
}
2016-04-18 15:35:33 +00:00
int rv = ImportIntoCertStore(certificate_manager_model_.get(), options);
chore: bump chromium to 1e9f9a24aa12 (master) (#17880) * chore: bump chromium in DEPS to 1e9f9a24aa12bea9cf194a82a7e249bd1242ec4f * chore: update patches * Make WebContents' theme color a base::Optional<SkColor> https://chromium-review.googlesource.com/c/chromium/src/+/1540022 * update autofill patch for incorrect header includes * Move Shell messages to web_test and rename to BlinkTest. https://chromium-review.googlesource.com/c/chromium/src/+/1525181 * Make PlatformNotificationServiceImpl a KeyedService. https://chromium-review.googlesource.com/c/chromium/src/+/1336150 * Move MediaPlayerId to its own file. https://chromium-review.googlesource.com/c/chromium/src/+/1547057 * Remove net/base/completion_callback.h, which is no longer used https://chromium-review.googlesource.com/c/chromium/src/+/1552821 * AW NS: support file scheme cookies https://chromium-review.googlesource.com/c/chromium/src/+/1533486 * Remove SecurityInfo and adapt remaining consumers https://chromium-review.googlesource.com/c/chromium/src/+/1509455 * Remove deprecated type-specific number to string conversion functions https://chromium-review.googlesource.com/c/chromium/src/+/1545881 * DevTools: Adding new performance histograms for launch of top 4 tools https://chromium-review.googlesource.com/c/chromium/src/+/1506388 * Update include paths for //base/hash/hash.h https://chromium-review.googlesource.com/c/chromium/src/+/1544630 * build: Disable ensure_gn_version gclient hook for mac CI checkout * update patches * use maybe version of v8::String::NewFromTwoByte * bump appveyor image version * fix mac ci hopefully * Convert enum to enum class for MenuAnchorPosition https://chromium-review.googlesource.com/c/chromium/src/+/1530508 * use maybe version of ToObject * RenderViewHost::GetProcess is no longer const * Unrefcount AuthChallengeInfo https://chromium-review.googlesource.com/c/chromium/src/+/1550631 * MenuButtonController takes Button rather than MenuButton https://chromium-review.googlesource.com/c/chromium/src/+/1500935 * add //ui/views_bridge_mac to deps to fix link error * forward declare views::Button in atom::MenuDelegate * more v8 patches * base/{=> hash}/md5.h https://chromium-review.googlesource.com/c/chromium/src/+/1535124 * gfx::{PlatformFontWin => win}::* https://chromium-review.googlesource.com/c/chromium/src/+/1534178 * fix v8 patches * [base] Rename TaskScheduler to ThreadPool https://chromium-review.googlesource.com/c/chromium/src/+/1561552 * use internal_config_base for bytecode_builtins_list_generator avoids windows link errors * FIXME: temporarily disable v8/breakpad integration * FIXME: temporarily disable prevent-will-redirect test * FIXME: disable neon on aarch64 pending crbug.com/953815 * update to account for WebCursor refactor https://chromium-review.googlesource.com/c/chromium/src/+/1562755 * enable stack dumping on appveyor * Revert "FIXME: disable neon on aarch64 pending crbug.com/953815" This reverts commit 57f082026be3d83069f2a2814684abf4dc9e7b53. * fix: remove const qualifiers to match upstream * fix: remove const qualifiers to match upstream in cc files as well * don't throw an error when testing if an object is an object * use non-deprecated Buffer constructor * Remove net::CookieSameSite::DEFAULT_MODE enum value https://chromium-review.googlesource.com/c/chromium/src/+/1567955 * depend on modded dbus-native to work around buffer deprecation https://github.com/sidorares/dbus-native/pull/262 * revert clang roll to fix arm build on linux * fixup! depend on modded dbus-native to work around buffer deprecation need more coffee * update coffee-script * robustify verify-mksnapshot w.r.t. command-line parameters * Revert "robustify verify-mksnapshot w.r.t. command-line parameters" This reverts commit a49af01411f684f6025528d604895c3696e0bc57. * fix mksnapshot by matching args * update patches * TMP: enable rdp on appveyor * Changed ContentBrowserClient::CreateQuotaPermissionContext() to return scoped_refptr. https://chromium-review.googlesource.com/c/chromium/src/+/1569376 * Make content::ResourceType an enum class. https://chromium-review.googlesource.com/c/chromium/src/+/1569345 * fixup! Make content::ResourceType an enum class. * turn off rdp * use net::CompletionRepeatingCallback instead of base::Callback<void(int)> * remove disable_ensure_gn_version_gclient_hook.patch * copy repeating callback instead of std::move * fix lint * add completion_repeating_callback.h include
2019-04-20 17:20:37 +00:00
std::move(callback).Run(rv);
2016-04-18 05:11:31 +00:00
}
void App::OnCertificateManagerModelCreated(
2016-05-23 01:59:39 +00:00
std::unique_ptr<base::DictionaryValue> options,
chore: bump chromium to 1e9f9a24aa12 (master) (#17880) * chore: bump chromium in DEPS to 1e9f9a24aa12bea9cf194a82a7e249bd1242ec4f * chore: update patches * Make WebContents' theme color a base::Optional<SkColor> https://chromium-review.googlesource.com/c/chromium/src/+/1540022 * update autofill patch for incorrect header includes * Move Shell messages to web_test and rename to BlinkTest. https://chromium-review.googlesource.com/c/chromium/src/+/1525181 * Make PlatformNotificationServiceImpl a KeyedService. https://chromium-review.googlesource.com/c/chromium/src/+/1336150 * Move MediaPlayerId to its own file. https://chromium-review.googlesource.com/c/chromium/src/+/1547057 * Remove net/base/completion_callback.h, which is no longer used https://chromium-review.googlesource.com/c/chromium/src/+/1552821 * AW NS: support file scheme cookies https://chromium-review.googlesource.com/c/chromium/src/+/1533486 * Remove SecurityInfo and adapt remaining consumers https://chromium-review.googlesource.com/c/chromium/src/+/1509455 * Remove deprecated type-specific number to string conversion functions https://chromium-review.googlesource.com/c/chromium/src/+/1545881 * DevTools: Adding new performance histograms for launch of top 4 tools https://chromium-review.googlesource.com/c/chromium/src/+/1506388 * Update include paths for //base/hash/hash.h https://chromium-review.googlesource.com/c/chromium/src/+/1544630 * build: Disable ensure_gn_version gclient hook for mac CI checkout * update patches * use maybe version of v8::String::NewFromTwoByte * bump appveyor image version * fix mac ci hopefully * Convert enum to enum class for MenuAnchorPosition https://chromium-review.googlesource.com/c/chromium/src/+/1530508 * use maybe version of ToObject * RenderViewHost::GetProcess is no longer const * Unrefcount AuthChallengeInfo https://chromium-review.googlesource.com/c/chromium/src/+/1550631 * MenuButtonController takes Button rather than MenuButton https://chromium-review.googlesource.com/c/chromium/src/+/1500935 * add //ui/views_bridge_mac to deps to fix link error * forward declare views::Button in atom::MenuDelegate * more v8 patches * base/{=> hash}/md5.h https://chromium-review.googlesource.com/c/chromium/src/+/1535124 * gfx::{PlatformFontWin => win}::* https://chromium-review.googlesource.com/c/chromium/src/+/1534178 * fix v8 patches * [base] Rename TaskScheduler to ThreadPool https://chromium-review.googlesource.com/c/chromium/src/+/1561552 * use internal_config_base for bytecode_builtins_list_generator avoids windows link errors * FIXME: temporarily disable v8/breakpad integration * FIXME: temporarily disable prevent-will-redirect test * FIXME: disable neon on aarch64 pending crbug.com/953815 * update to account for WebCursor refactor https://chromium-review.googlesource.com/c/chromium/src/+/1562755 * enable stack dumping on appveyor * Revert "FIXME: disable neon on aarch64 pending crbug.com/953815" This reverts commit 57f082026be3d83069f2a2814684abf4dc9e7b53. * fix: remove const qualifiers to match upstream * fix: remove const qualifiers to match upstream in cc files as well * don't throw an error when testing if an object is an object * use non-deprecated Buffer constructor * Remove net::CookieSameSite::DEFAULT_MODE enum value https://chromium-review.googlesource.com/c/chromium/src/+/1567955 * depend on modded dbus-native to work around buffer deprecation https://github.com/sidorares/dbus-native/pull/262 * revert clang roll to fix arm build on linux * fixup! depend on modded dbus-native to work around buffer deprecation need more coffee * update coffee-script * robustify verify-mksnapshot w.r.t. command-line parameters * Revert "robustify verify-mksnapshot w.r.t. command-line parameters" This reverts commit a49af01411f684f6025528d604895c3696e0bc57. * fix mksnapshot by matching args * update patches * TMP: enable rdp on appveyor * Changed ContentBrowserClient::CreateQuotaPermissionContext() to return scoped_refptr. https://chromium-review.googlesource.com/c/chromium/src/+/1569376 * Make content::ResourceType an enum class. https://chromium-review.googlesource.com/c/chromium/src/+/1569345 * fixup! Make content::ResourceType an enum class. * turn off rdp * use net::CompletionRepeatingCallback instead of base::Callback<void(int)> * remove disable_ensure_gn_version_gclient_hook.patch * copy repeating callback instead of std::move * fix lint * add completion_repeating_callback.h include
2019-04-20 17:20:37 +00:00
net::CompletionOnceCallback callback,
2016-05-23 01:59:39 +00:00
std::unique_ptr<CertificateManagerModel> model) {
2016-04-18 05:11:31 +00:00
certificate_manager_model_ = std::move(model);
2018-04-18 01:55:30 +00:00
int rv =
ImportIntoCertStore(certificate_manager_model_.get(), *(options.get()));
chore: bump chromium to 1e9f9a24aa12 (master) (#17880) * chore: bump chromium in DEPS to 1e9f9a24aa12bea9cf194a82a7e249bd1242ec4f * chore: update patches * Make WebContents' theme color a base::Optional<SkColor> https://chromium-review.googlesource.com/c/chromium/src/+/1540022 * update autofill patch for incorrect header includes * Move Shell messages to web_test and rename to BlinkTest. https://chromium-review.googlesource.com/c/chromium/src/+/1525181 * Make PlatformNotificationServiceImpl a KeyedService. https://chromium-review.googlesource.com/c/chromium/src/+/1336150 * Move MediaPlayerId to its own file. https://chromium-review.googlesource.com/c/chromium/src/+/1547057 * Remove net/base/completion_callback.h, which is no longer used https://chromium-review.googlesource.com/c/chromium/src/+/1552821 * AW NS: support file scheme cookies https://chromium-review.googlesource.com/c/chromium/src/+/1533486 * Remove SecurityInfo and adapt remaining consumers https://chromium-review.googlesource.com/c/chromium/src/+/1509455 * Remove deprecated type-specific number to string conversion functions https://chromium-review.googlesource.com/c/chromium/src/+/1545881 * DevTools: Adding new performance histograms for launch of top 4 tools https://chromium-review.googlesource.com/c/chromium/src/+/1506388 * Update include paths for //base/hash/hash.h https://chromium-review.googlesource.com/c/chromium/src/+/1544630 * build: Disable ensure_gn_version gclient hook for mac CI checkout * update patches * use maybe version of v8::String::NewFromTwoByte * bump appveyor image version * fix mac ci hopefully * Convert enum to enum class for MenuAnchorPosition https://chromium-review.googlesource.com/c/chromium/src/+/1530508 * use maybe version of ToObject * RenderViewHost::GetProcess is no longer const * Unrefcount AuthChallengeInfo https://chromium-review.googlesource.com/c/chromium/src/+/1550631 * MenuButtonController takes Button rather than MenuButton https://chromium-review.googlesource.com/c/chromium/src/+/1500935 * add //ui/views_bridge_mac to deps to fix link error * forward declare views::Button in atom::MenuDelegate * more v8 patches * base/{=> hash}/md5.h https://chromium-review.googlesource.com/c/chromium/src/+/1535124 * gfx::{PlatformFontWin => win}::* https://chromium-review.googlesource.com/c/chromium/src/+/1534178 * fix v8 patches * [base] Rename TaskScheduler to ThreadPool https://chromium-review.googlesource.com/c/chromium/src/+/1561552 * use internal_config_base for bytecode_builtins_list_generator avoids windows link errors * FIXME: temporarily disable v8/breakpad integration * FIXME: temporarily disable prevent-will-redirect test * FIXME: disable neon on aarch64 pending crbug.com/953815 * update to account for WebCursor refactor https://chromium-review.googlesource.com/c/chromium/src/+/1562755 * enable stack dumping on appveyor * Revert "FIXME: disable neon on aarch64 pending crbug.com/953815" This reverts commit 57f082026be3d83069f2a2814684abf4dc9e7b53. * fix: remove const qualifiers to match upstream * fix: remove const qualifiers to match upstream in cc files as well * don't throw an error when testing if an object is an object * use non-deprecated Buffer constructor * Remove net::CookieSameSite::DEFAULT_MODE enum value https://chromium-review.googlesource.com/c/chromium/src/+/1567955 * depend on modded dbus-native to work around buffer deprecation https://github.com/sidorares/dbus-native/pull/262 * revert clang roll to fix arm build on linux * fixup! depend on modded dbus-native to work around buffer deprecation need more coffee * update coffee-script * robustify verify-mksnapshot w.r.t. command-line parameters * Revert "robustify verify-mksnapshot w.r.t. command-line parameters" This reverts commit a49af01411f684f6025528d604895c3696e0bc57. * fix mksnapshot by matching args * update patches * TMP: enable rdp on appveyor * Changed ContentBrowserClient::CreateQuotaPermissionContext() to return scoped_refptr. https://chromium-review.googlesource.com/c/chromium/src/+/1569376 * Make content::ResourceType an enum class. https://chromium-review.googlesource.com/c/chromium/src/+/1569345 * fixup! Make content::ResourceType an enum class. * turn off rdp * use net::CompletionRepeatingCallback instead of base::Callback<void(int)> * remove disable_ensure_gn_version_gclient_hook.patch * copy repeating callback instead of std::move * fix lint * add completion_repeating_callback.h include
2019-04-20 17:20:37 +00:00
std::move(callback).Run(rv);
2016-04-18 05:11:31 +00:00
}
#endif
2016-04-18 05:11:31 +00:00
#if defined(OS_WIN)
v8::Local<v8::Value> App::GetJumpListSettings() {
JumpList jump_list(Browser::Get()->GetAppUserModelID());
int min_items = 10;
std::vector<JumpListItem> removed_items;
if (jump_list.Begin(&min_items, &removed_items)) {
// We don't actually want to change anything, so abort the transaction.
jump_list.Abort();
} else {
LOG(ERROR) << "Failed to begin Jump List transaction.";
}
auto dict = mate::Dictionary::CreateEmpty(isolate());
dict.Set("minItems", min_items);
dict.Set("removedItems", mate::ConvertToV8(isolate(), removed_items));
return dict.GetHandle();
}
JumpListResult App::SetJumpList(v8::Local<v8::Value> val,
mate::Arguments* args) {
std::vector<JumpListCategory> categories;
bool delete_jump_list = val->IsNull();
if (!delete_jump_list &&
2018-04-18 01:55:30 +00:00
!mate::ConvertFromV8(args->isolate(), val, &categories)) {
args->ThrowError("Argument must be null or an array of categories");
return JumpListResult::ARGUMENT_ERROR;
}
JumpList jump_list(Browser::Get()->GetAppUserModelID());
if (delete_jump_list) {
2018-04-18 01:55:30 +00:00
return jump_list.Delete() ? JumpListResult::SUCCESS
: JumpListResult::GENERIC_ERROR;
}
// Start a transaction that updates the JumpList of this application.
if (!jump_list.Begin())
return JumpListResult::GENERIC_ERROR;
JumpListResult result = jump_list.AppendCategories(categories);
// AppendCategories may have failed to add some categories, but it's better
// to have something than nothing so try to commit the changes anyway.
if (!jump_list.Commit()) {
LOG(ERROR) << "Failed to commit changes to custom Jump List.";
// It's more useful to return the earlier error code that might give
// some indication as to why the transaction actually failed, so don't
// overwrite it with a "generic error" code here.
if (result == JumpListResult::SUCCESS)
result = JumpListResult::GENERIC_ERROR;
}
return result;
}
#endif // defined(OS_WIN)
v8::Local<v8::Promise> App::GetFileIcon(const base::FilePath& path,
mate::Arguments* args) {
util::Promise<gfx::Image> promise(isolate());
v8::Local<v8::Promise> handle = promise.GetHandle();
2016-11-05 18:55:23 +00:00
base::FilePath normalized_path = path.NormalizePathSeparators();
IconLoader::IconSize icon_size;
mate::Dictionary options;
2016-11-03 18:23:40 +00:00
if (!args->GetNext(&options)) {
2016-11-03 18:04:56 +00:00
icon_size = IconLoader::IconSize::NORMAL;
2016-11-03 18:23:40 +00:00
} else {
std::string icon_size_string;
2016-11-04 06:59:18 +00:00
options.Get("size", &icon_size_string);
2016-11-03 18:23:40 +00:00
icon_size = GetIconSizeByString(icon_size_string);
2016-11-03 18:04:56 +00:00
}
auto* icon_manager = AtomBrowserMainParts::Get()->GetIconManager();
gfx::Image* icon =
icon_manager->LookupIconFromFilepath(normalized_path, icon_size);
if (icon) {
promise.Resolve(*icon);
} else {
icon_manager->LoadIcon(
normalized_path, icon_size,
base::BindOnce(&OnIconDataAvailable, std::move(promise)),
&cancelable_task_tracker_);
}
return handle;
}
2017-05-16 00:41:45 +00:00
std::vector<mate::Dictionary> App::GetAppMetrics(v8::Isolate* isolate) {
std::vector<mate::Dictionary> result;
result.reserve(app_metrics_.size());
2017-05-16 00:41:45 +00:00
int processor_count = base::SysInfo::NumberOfProcessors();
2017-05-16 00:41:45 +00:00
for (const auto& process_metric : app_metrics_) {
2017-05-04 20:27:35 +00:00
mate::Dictionary pid_dict = mate::Dictionary::CreateEmpty(isolate);
2017-05-16 00:41:45 +00:00
mate::Dictionary cpu_dict = mate::Dictionary::CreateEmpty(isolate);
pid_dict.SetHidden("simple", true);
cpu_dict.SetHidden("simple", true);
2018-04-18 01:55:30 +00:00
cpu_dict.Set(
"percentCPUUsage",
process_metric.second->metrics->GetPlatformIndependentCPUUsage() /
processor_count);
#if !defined(OS_WIN)
2017-05-16 00:41:45 +00:00
cpu_dict.Set("idleWakeupsPerSecond",
2018-04-18 01:55:30 +00:00
process_metric.second->metrics->GetIdleWakeupsPerSecond());
#else
// Chrome's underlying process_metrics.cc will throw a non-fatal warning
// that this method isn't implemented on Windows, so set it to 0 instead
// of calling it
cpu_dict.Set("idleWakeupsPerSecond", 0);
#endif
2017-05-16 00:41:45 +00:00
pid_dict.Set("cpu", cpu_dict);
pid_dict.Set("pid", process_metric.second->process.Pid());
2018-04-18 01:55:30 +00:00
pid_dict.Set("type", content::GetProcessTypeNameInEnglish(
process_metric.second->type));
pid_dict.Set("creationTime",
process_metric.second->process.CreationTime().ToJsTime());
#if !defined(OS_LINUX)
auto memory_info = process_metric.second->GetMemoryInfo();
mate::Dictionary memory_dict = mate::Dictionary::CreateEmpty(isolate);
memory_dict.SetHidden("simple", true);
memory_dict.Set("workingSetSize",
static_cast<double>(memory_info.working_set_size >> 10));
memory_dict.Set(
"peakWorkingSetSize",
static_cast<double>(memory_info.peak_working_set_size >> 10));
#if defined(OS_WIN)
memory_dict.Set("privateBytes",
static_cast<double>(memory_info.private_bytes >> 10));
#endif
pid_dict.Set("memory", memory_dict);
#endif
#if defined(OS_MACOSX)
pid_dict.Set("sandboxed", process_metric.second->IsSandboxed());
#elif defined(OS_WIN)
auto integrity_level = process_metric.second->GetIntegrityLevel();
auto sandboxed = ProcessMetric::IsSandboxed(integrity_level);
pid_dict.Set("integrityLevel", integrity_level);
pid_dict.Set("sandboxed", sandboxed);
#endif
2017-05-04 20:27:35 +00:00
result.push_back(pid_dict);
}
return result;
}
2017-05-30 20:00:55 +00:00
v8::Local<v8::Value> App::GetGPUFeatureStatus(v8::Isolate* isolate) {
auto status = content::GetFeatureStatus();
2017-11-23 12:43:11 +00:00
base::DictionaryValue temp;
return mate::ConvertToV8(isolate, status ? *status : temp);
2017-05-30 17:06:08 +00:00
}
v8::Local<v8::Promise> App::GetGPUInfo(v8::Isolate* isolate,
const std::string& info_type) {
auto* const gpu_data_manager = content::GpuDataManagerImpl::GetInstance();
util::Promise<base::DictionaryValue> promise(isolate);
v8::Local<v8::Promise> handle = promise.GetHandle();
if (info_type != "basic" && info_type != "complete") {
promise.RejectWithErrorMessage(
"Invalid info type. Use 'basic' or 'complete'");
return handle;
}
std::string reason;
if (!gpu_data_manager->GpuAccessAllowed(&reason)) {
promise.RejectWithErrorMessage("GPU access not allowed. Reason: " + reason);
return handle;
}
auto* const info_mgr = GPUInfoManager::GetInstance();
if (info_type == "complete") {
#if defined(OS_WIN) || defined(OS_MACOSX)
info_mgr->FetchCompleteInfo(std::move(promise));
#else
info_mgr->FetchBasicInfo(std::move(promise));
#endif
} else /* (info_type == "basic") */ {
info_mgr->FetchBasicInfo(std::move(promise));
}
return handle;
}
2018-10-10 04:32:09 +00:00
static void RemoveNoSandboxSwitch(base::CommandLine* command_line) {
2018-09-15 00:07:49 +00:00
if (command_line->HasSwitch(service_manager::switches::kNoSandbox)) {
2018-10-10 04:32:09 +00:00
const base::CommandLine::CharType* noSandboxArg =
FILE_PATH_LITERAL("--no-sandbox");
2017-06-28 15:33:06 +00:00
base::CommandLine::StringVector modified_command_line;
for (auto& arg : command_line->argv()) {
if (arg.compare(noSandboxArg) != 0) {
modified_command_line.push_back(arg);
}
2017-06-26 21:13:41 +00:00
}
command_line->InitFromArgv(modified_command_line);
}
2018-10-10 04:32:09 +00:00
}
void App::EnableSandbox(mate::Arguments* args) {
if (Browser::Get()->is_ready()) {
args->ThrowError(
"app.enableSandbox() can only be called "
"before app is ready");
return;
}
auto* command_line = base::CommandLine::ForCurrentProcess();
RemoveNoSandboxSwitch(command_line);
command_line->AppendSwitch(switches::kEnableSandbox);
}
void App::SetUserAgentFallback(const std::string& user_agent) {
AtomBrowserClient::Get()->SetUserAgent(user_agent);
}
std::string App::GetUserAgentFallback() {
return AtomBrowserClient::Get()->GetUserAgent();
}
void App::SetBrowserClientCanUseCustomSiteInstance(bool should_disable) {
AtomBrowserClient::Get()->SetCanUseCustomSiteInstance(should_disable);
}
bool App::CanBrowserClientUseCustomSiteInstance() {
return AtomBrowserClient::Get()->CanUseCustomSiteInstance();
}
#if defined(OS_MACOSX)
bool App::MoveToApplicationsFolder(mate::Arguments* args) {
return ui::cocoa::AtomBundleMover::Move(args);
}
bool App::IsInApplicationsFolder() {
return ui::cocoa::AtomBundleMover::IsCurrentAppInApplicationsFolder();
}
int DockBounce(mate::Arguments* args) {
int request_id = -1;
std::string type = "informational";
args->GetNext(&type);
if (type == "critical")
request_id = Browser::Get()->DockBounce(Browser::BounceType::CRITICAL);
else if (type == "informational")
request_id = Browser::Get()->DockBounce(Browser::BounceType::INFORMATIONAL);
return request_id;
}
void DockSetMenu(electron::api::Menu* menu) {
Browser::Get()->DockSetMenu(menu->model());
}
v8::Local<v8::Value> App::GetDockAPI(v8::Isolate* isolate) {
if (dock_.IsEmpty()) {
// Initialize the Dock API, the methods are bound to "dock" which exists
// for the lifetime of "app"
auto browser = base::Unretained(Browser::Get());
mate::Dictionary dock_obj = mate::Dictionary::CreateEmpty(isolate);
dock_obj.SetMethod("bounce", &DockBounce);
dock_obj.SetMethod(
"cancelBounce",
base::BindRepeating(&Browser::DockCancelBounce, browser));
dock_obj.SetMethod(
"downloadFinished",
base::BindRepeating(&Browser::DockDownloadFinished, browser));
dock_obj.SetMethod(
"setBadge", base::BindRepeating(&Browser::DockSetBadgeText, browser));
dock_obj.SetMethod(
"getBadge", base::BindRepeating(&Browser::DockGetBadgeText, browser));
dock_obj.SetMethod("hide",
base::BindRepeating(&Browser::DockHide, browser));
dock_obj.SetMethod("show",
base::BindRepeating(&Browser::DockShow, browser));
dock_obj.SetMethod("isVisible",
base::BindRepeating(&Browser::DockIsVisible, browser));
dock_obj.SetMethod("setMenu", &DockSetMenu);
dock_obj.SetMethod("setIcon",
base::BindRepeating(&Browser::DockSetIcon, browser));
dock_.Reset(isolate, dock_obj.GetHandle());
}
return v8::Local<v8::Value>::New(isolate, dock_);
}
#endif
2016-04-25 01:17:54 +00:00
// static
mate::Handle<App> App::Create(v8::Isolate* isolate) {
2016-04-25 01:40:19 +00:00
return mate::CreateHandle(isolate, new App(isolate));
2016-04-25 01:17:54 +00:00
}
// static
2018-04-18 01:55:30 +00:00
void App::BuildPrototype(v8::Isolate* isolate,
v8::Local<v8::FunctionTemplate> prototype) {
2016-08-02 10:28:12 +00:00
prototype->SetClassName(mate::StringToV8(isolate, "App"));
auto browser = base::Unretained(Browser::Get());
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
.SetMethod("quit", base::BindRepeating(&Browser::Quit, browser))
.SetMethod("exit", base::BindRepeating(&Browser::Exit, browser))
.SetMethod("focus", base::BindRepeating(&Browser::Focus, browser))
.SetMethod("getVersion",
base::BindRepeating(&Browser::GetVersion, browser))
.SetMethod("setVersion",
base::BindRepeating(&Browser::SetVersion, browser))
.SetMethod("_getName", base::BindRepeating(&Browser::GetName, browser))
.SetMethod("_setName", base::BindRepeating(&Browser::SetName, browser))
.SetMethod("isReady", base::BindRepeating(&Browser::is_ready, browser))
.SetMethod("whenReady", base::BindRepeating(&Browser::WhenReady, browser))
2014-11-17 05:05:06 +00:00
.SetMethod("addRecentDocument",
base::BindRepeating(&Browser::AddRecentDocument, browser))
2014-11-17 08:13:47 +00:00
.SetMethod("clearRecentDocuments",
base::BindRepeating(&Browser::ClearRecentDocuments, browser))
.SetMethod("setAppUserModelId",
base::BindRepeating(&Browser::SetAppUserModelID, browser))
.SetMethod(
"isDefaultProtocolClient",
base::BindRepeating(&Browser::IsDefaultProtocolClient, browser))
.SetMethod(
"setAsDefaultProtocolClient",
base::BindRepeating(&Browser::SetAsDefaultProtocolClient, browser))
.SetMethod(
"removeAsDefaultProtocolClient",
base::BindRepeating(&Browser::RemoveAsDefaultProtocolClient, browser))
.SetMethod("_setBadgeCount",
base::BindRepeating(&Browser::SetBadgeCount, browser))
.SetMethod("_getBadgeCount",
base::BindRepeating(&Browser::GetBadgeCount, browser))
.SetMethod("getLoginItemSettings", &App::GetLoginItemSettings)
.SetMethod("setLoginItemSettings",
base::BindRepeating(&Browser::SetLoginItemSettings, browser))
2019-03-14 20:39:52 +00:00
.SetMethod("isEmojiPanelSupported",
base::BindRepeating(&Browser::IsEmojiPanelSupported, browser))
.SetProperty("badgeCount",
base::BindRepeating(&Browser::GetBadgeCount, browser),
base::BindRepeating(&Browser::SetBadgeCount, browser))
.SetProperty("name", base::BindRepeating(&Browser::GetName, browser),
base::BindRepeating(&Browser::SetName, browser))
2016-01-29 21:51:06 +00:00
#if defined(OS_MACOSX)
.SetMethod("hide", base::BindRepeating(&Browser::Hide, browser))
.SetMethod("show", base::BindRepeating(&Browser::Show, browser))
2016-04-30 05:05:36 +00:00
.SetMethod("setUserActivity",
base::BindRepeating(&Browser::SetUserActivity, browser))
2016-07-07 21:29:43 +00:00
.SetMethod("getCurrentActivityType",
base::BindRepeating(&Browser::GetCurrentActivityType, browser))
.SetMethod(
"invalidateCurrentActivity",
base::BindRepeating(&Browser::InvalidateCurrentActivity, browser))
.SetMethod("resignCurrentActivity",
base::BindRepeating(&Browser::ResignCurrentActivity, browser))
.SetMethod("updateCurrentActivity",
base::BindRepeating(&Browser::UpdateCurrentActivity, browser))
.SetMethod("moveToApplicationsFolder", &App::MoveToApplicationsFolder)
.SetMethod("isInApplicationsFolder", &App::IsInApplicationsFolder)
#endif
2016-10-10 20:30:58 +00:00
.SetMethod("setAboutPanelOptions",
base::BindRepeating(&Browser::SetAboutPanelOptions, browser))
.SetMethod("showAboutPanel",
base::BindRepeating(&Browser::ShowAboutPanel, browser))
2019-03-14 20:39:52 +00:00
#if defined(OS_MACOSX) || defined(OS_WIN)
.SetMethod("showEmojiPanel",
base::BindRepeating(&Browser::ShowEmojiPanel, browser))
.SetProperty("accessibilitySupportEnabled",
&App::IsAccessibilitySupportEnabled,
&App::SetAccessibilitySupportEnabled)
2019-03-14 20:39:52 +00:00
#endif
2014-11-17 09:19:41 +00:00
#if defined(OS_WIN)
.SetMethod("setUserTasks",
base::BindRepeating(&Browser::SetUserTasks, browser))
.SetMethod("getJumpListSettings", &App::GetJumpListSettings)
.SetMethod("setJumpList", &App::SetJumpList)
2016-07-01 08:39:01 +00:00
#endif
#if defined(OS_LINUX)
.SetMethod("isUnityRunning",
base::BindRepeating(&Browser::IsUnityRunning, browser))
2014-11-17 09:19:41 +00:00
#endif
2017-04-04 00:36:01 +00:00
.SetMethod("setAppPath", &App::SetAppPath)
.SetMethod("getAppPath", &App::GetAppPath)
.SetMethod("setPath", &App::SetPath)
.SetMethod("getPath", &App::GetPath)
.SetMethod("setAppLogsPath", &App::SetAppLogsPath)
2015-04-28 22:49:16 +00:00
.SetMethod("setDesktopName", &App::SetDesktopName)
2015-09-16 08:16:21 +00:00
.SetMethod("getLocale", &App::GetLocale)
.SetMethod("getLocaleCountryCode", &App::GetLocaleCountryCode)
#if defined(USE_NSS_CERTS)
.SetMethod("importCertificate", &App::ImportCertificate)
2016-04-18 15:35:33 +00:00
#endif
.SetMethod("hasSingleInstanceLock", &App::HasSingleInstanceLock)
.SetMethod("requestSingleInstanceLock", &App::RequestSingleInstanceLock)
.SetMethod("releaseSingleInstanceLock", &App::ReleaseSingleInstanceLock)
.SetMethod("relaunch", &App::Relaunch)
.SetMethod("_isAccessibilitySupportEnabled",
&App::IsAccessibilitySupportEnabled)
.SetMethod("_setAccessibilitySupportEnabled",
2017-08-24 14:22:28 +00:00
&App::SetAccessibilitySupportEnabled)
.SetMethod("disableHardwareAcceleration",
&App::DisableHardwareAcceleration)
.SetMethod("disableDomainBlockingFor3DAPIs",
&App::DisableDomainBlockingFor3DAPIs)
.SetMethod("getFileIcon", &App::GetFileIcon)
2017-05-26 14:51:17 +00:00
.SetMethod("getAppMetrics", &App::GetAppMetrics)
2017-05-30 17:06:08 +00:00
.SetMethod("getGPUFeatureStatus", &App::GetGPUFeatureStatus)
.SetMethod("getGPUInfo", &App::GetGPUInfo)
2018-04-18 01:55:30 +00:00
#if defined(MAS_BUILD)
.SetMethod("startAccessingSecurityScopedResource",
&App::StartAccessingSecurityScopedResource)
#endif
#if defined(OS_MACOSX)
.SetProperty("dock", &App::GetDockAPI)
2018-04-18 01:55:30 +00:00
#endif
.SetProperty("userAgentFallback", &App::GetUserAgentFallback,
&App::SetUserAgentFallback)
.SetMethod("enableSandbox", &App::EnableSandbox)
.SetProperty("allowRendererProcessReuse",
&App::CanBrowserClientUseCustomSiteInstance,
&App::SetBrowserClientCanUseCustomSiteInstance);
2013-05-30 11:24:47 +00:00
}
2014-04-17 09:13:46 +00:00
} // namespace api
} // namespace electron
2014-04-17 09:13:46 +00:00
namespace {
2018-04-18 01:55:30 +00:00
void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
v8::Isolate* isolate = context->GetIsolate();
2014-04-17 09:13:46 +00:00
mate::Dictionary dict(isolate, exports);
dict.Set("App", electron::api::App::GetConstructor(isolate)
->GetFunction(context)
.ToLocalChecked());
dict.Set("app", electron::api::App::Create(isolate));
2014-04-17 09:13:46 +00:00
}
} // namespace
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_app, Initialize)