2014-10-31 18:17:05 +00:00
|
|
|
// 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.
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/api/electron_api_app.h"
|
2013-05-02 16:05:09 +00:00
|
|
|
|
2019-09-16 22:12:00 +00:00
|
|
|
#include <memory>
|
2024-01-10 22:23:35 +00:00
|
|
|
#include <optional>
|
2014-03-16 01:13:06 +00:00
|
|
|
#include <string>
|
2024-01-11 01:00:37 +00:00
|
|
|
#include <string_view>
|
2021-06-01 01:34:44 +00:00
|
|
|
#include <utility>
|
2014-08-13 12:24:35 +00:00
|
|
|
#include <vector>
|
2014-03-16 01:13:06 +00:00
|
|
|
|
2013-05-17 07:39:44 +00:00
|
|
|
#include "base/command_line.h"
|
2023-06-14 21:00:46 +00:00
|
|
|
#include "base/containers/fixed_flat_map.h"
|
2021-06-25 00:06:42 +00:00
|
|
|
#include "base/containers/span.h"
|
2014-08-12 15:01:56 +00:00
|
|
|
#include "base/environment.h"
|
|
|
|
#include "base/files/file_path.h"
|
2016-04-18 05:11:31 +00:00
|
|
|
#include "base/files/file_util.h"
|
2023-02-03 11:43:42 +00:00
|
|
|
#include "base/functional/callback_helpers.h"
|
2014-08-12 15:01:56 +00:00
|
|
|
#include "base/path_service.h"
|
2019-01-09 20:14:47 +00:00
|
|
|
#include "base/system/sys_info.h"
|
2021-10-15 01:32:32 +00:00
|
|
|
#include "base/values.h"
|
2023-09-20 20:15:19 +00:00
|
|
|
#include "base/win/windows_version.h"
|
2017-02-17 08:33:46 +00:00
|
|
|
#include "chrome/browser/browser_process.h"
|
2016-11-02 18:57:16 +00:00
|
|
|
#include "chrome/browser/icon_manager.h"
|
2021-08-31 18:55:30 +00:00
|
|
|
#include "chrome/common/chrome_features.h"
|
2015-11-13 05:05:16 +00:00
|
|
|
#include "chrome/common/chrome_paths.h"
|
2024-02-22 17:08:25 +00:00
|
|
|
#include "components/proxy_config/proxy_config_dictionary.h"
|
|
|
|
#include "components/proxy_config/proxy_config_pref_names.h"
|
|
|
|
#include "components/proxy_config/proxy_prefs.h"
|
2019-03-05 05:08:55 +00:00
|
|
|
#include "content/browser/gpu/compositor_util.h" // nogncheck
|
|
|
|
#include "content/browser/gpu/gpu_data_manager_impl.h" // nogncheck
|
2016-07-11 21:04:56 +00:00
|
|
|
#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"
|
2015-06-11 15:22:07 +00:00
|
|
|
#include "content/public/browser/client_certificate_delegate.h"
|
2015-06-25 12:28:07 +00:00
|
|
|
#include "content/public/browser/gpu_data_manager.h"
|
2021-08-31 18:55:30 +00:00
|
|
|
#include "content/public/browser/network_service_instance.h"
|
2015-11-18 02:39:25 +00:00
|
|
|
#include "content/public/browser/render_frame_host.h"
|
2015-10-07 04:15:48 +00:00
|
|
|
#include "content/public/common/content_switches.h"
|
2022-02-10 02:58:52 +00:00
|
|
|
#include "crypto/crypto_buildflags.h"
|
2016-10-07 10:45:30 +00:00
|
|
|
#include "media/audio/audio_manager.h"
|
2022-02-25 18:17:35 +00:00
|
|
|
#include "net/dns/public/dns_over_https_config.h"
|
2022-05-17 16:48:40 +00:00
|
|
|
#include "net/dns/public/dns_over_https_server_config.h"
|
2021-08-31 18:55:30 +00:00
|
|
|
#include "net/dns/public/util.h"
|
2017-10-23 07:54:17 +00:00
|
|
|
#include "net/ssl/client_cert_identity.h"
|
2015-06-11 15:22:07 +00:00
|
|
|
#include "net/ssl/ssl_cert_request_info.h"
|
2021-08-24 00:52:17 +00:00
|
|
|
#include "net/ssl/ssl_private_key.h"
|
2020-07-14 01:13:34 +00:00
|
|
|
#include "sandbox/policy/switches.h"
|
2021-08-31 18:55:30 +00:00
|
|
|
#include "services/network/network_service.h"
|
2021-09-03 21:16:33 +00:00
|
|
|
#include "shell/app/command_line_args.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/api/electron_api_menu.h"
|
|
|
|
#include "shell/browser/api/electron_api_session.h"
|
2022-10-20 05:49:49 +00:00
|
|
|
#include "shell/browser/api/electron_api_utility_process.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/api/electron_api_web_contents.h"
|
|
|
|
#include "shell/browser/api/gpuinfo_manager.h"
|
2022-09-23 18:50:46 +00:00
|
|
|
#include "shell/browser/browser_process_impl.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/electron_browser_context.h"
|
|
|
|
#include "shell/browser/electron_browser_main_parts.h"
|
2020-06-22 16:35:24 +00:00
|
|
|
#include "shell/browser/javascript_environment.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/login_handler.h"
|
|
|
|
#include "shell/browser/relauncher.h"
|
|
|
|
#include "shell/common/application_info.h"
|
|
|
|
#include "shell/common/electron_command_line.h"
|
2020-05-07 20:31:26 +00:00
|
|
|
#include "shell/common/electron_paths.h"
|
2020-11-17 19:13:58 +00:00
|
|
|
#include "shell/common/gin_converters/base_converter.h"
|
2021-10-15 01:32:32 +00:00
|
|
|
#include "shell/common/gin_converters/blink_converter.h"
|
2019-10-24 05:47:58 +00:00
|
|
|
#include "shell/common/gin_converters/callback_converter.h"
|
|
|
|
#include "shell/common/gin_converters/file_path_converter.h"
|
|
|
|
#include "shell/common/gin_converters/gurl_converter.h"
|
|
|
|
#include "shell/common/gin_converters/image_converter.h"
|
2024-07-22 09:31:32 +00:00
|
|
|
#include "shell/common/gin_converters/login_item_settings_converter.h"
|
2019-10-24 05:47:58 +00:00
|
|
|
#include "shell/common/gin_converters/net_converter.h"
|
2019-10-31 07:56:00 +00:00
|
|
|
#include "shell/common/gin_converters/value_converter.h"
|
2019-09-08 15:10:18 +00:00
|
|
|
#include "shell/common/gin_helper/dictionary.h"
|
2019-10-24 05:47:58 +00:00
|
|
|
#include "shell/common/gin_helper/object_template_builder.h"
|
2022-11-09 15:50:43 +00:00
|
|
|
#include "shell/common/language_util.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/common/node_includes.h"
|
|
|
|
#include "shell/common/options_switches.h"
|
2020-05-13 02:27:56 +00:00
|
|
|
#include "shell/common/platform_util.h"
|
2022-11-17 19:59:23 +00:00
|
|
|
#include "shell/common/thread_restrictions.h"
|
2021-10-15 01:32:32 +00:00
|
|
|
#include "shell/common/v8_value_serializer.h"
|
2016-01-23 23:30:14 +00:00
|
|
|
#include "ui/gfx/image/image.h"
|
2013-12-11 07:48:19 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2015-04-29 07:13:46 +00:00
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/ui/win/jump_list.h"
|
2015-04-29 07:13:46 +00:00
|
|
|
#endif
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2018-11-20 20:33:23 +00:00
|
|
|
#include <CoreFoundation/CoreFoundation.h>
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/ui/cocoa/electron_bundle_mover.h"
|
2017-08-31 14:37:12 +00:00
|
|
|
#endif
|
|
|
|
|
2014-04-17 09:13:46 +00:00
|
|
|
using electron::Browser;
|
|
|
|
|
2019-10-24 05:47:58 +00:00
|
|
|
namespace gin {
|
2014-11-17 09:19:41 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2019-06-14 19:39:55 +00:00
|
|
|
template <>
|
|
|
|
struct Converter<electron::ProcessIntegrityLevel> {
|
|
|
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
|
|
|
electron::ProcessIntegrityLevel value) {
|
|
|
|
switch (value) {
|
2020-10-27 17:51:45 +00:00
|
|
|
case electron::ProcessIntegrityLevel::kUntrusted:
|
2019-10-24 05:47:58 +00:00
|
|
|
return StringToV8(isolate, "untrusted");
|
2020-10-27 17:51:45 +00:00
|
|
|
case electron::ProcessIntegrityLevel::kLow:
|
2019-10-24 05:47:58 +00:00
|
|
|
return StringToV8(isolate, "low");
|
2020-10-27 17:51:45 +00:00
|
|
|
case electron::ProcessIntegrityLevel::kMedium:
|
2019-10-24 05:47:58 +00:00
|
|
|
return StringToV8(isolate, "medium");
|
2020-10-27 17:51:45 +00:00
|
|
|
case electron::ProcessIntegrityLevel::kHigh:
|
2019-10-24 05:47:58 +00:00
|
|
|
return StringToV8(isolate, "high");
|
2019-06-14 19:39:55 +00:00
|
|
|
default:
|
2019-10-24 05:47:58 +00:00
|
|
|
return StringToV8(isolate, "unknown");
|
2019-06-14 19:39:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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) {
|
2019-10-24 05:47:58 +00:00
|
|
|
gin_helper::Dictionary dict;
|
2014-11-17 09:19:41 +00:00
|
|
|
if (!ConvertFromV8(isolate, val, &dict))
|
|
|
|
return false;
|
2014-11-17 09:26:44 +00:00
|
|
|
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;
|
2014-11-17 09:26:44 +00:00
|
|
|
dict.Get("arguments", &(out->arguments));
|
|
|
|
dict.Get("description", &(out->description));
|
2019-05-13 16:17:12 +00:00
|
|
|
dict.Get("workingDirectory", &(out->working_dir));
|
2014-11-17 09:26:44 +00:00
|
|
|
return true;
|
2014-11-17 09:19:41 +00:00
|
|
|
}
|
|
|
|
};
|
2016-08-12 09:31:17 +00:00
|
|
|
|
|
|
|
using electron::JumpListCategory;
|
2018-04-18 01:55:30 +00:00
|
|
|
using electron::JumpListItem;
|
2016-08-12 09:31:17 +00:00
|
|
|
using electron::JumpListResult;
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
template <>
|
2016-08-12 09:31:17 +00:00
|
|
|
struct Converter<JumpListItem::Type> {
|
2018-04-18 01:55:30 +00:00
|
|
|
static bool FromV8(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Value> val,
|
2016-08-12 09:31:17 +00:00
|
|
|
JumpListItem::Type* out) {
|
2023-06-19 08:33:09 +00:00
|
|
|
return FromV8WithLookup(isolate, val, Lookup, out);
|
2016-08-12 09:31:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
|
|
|
JumpListItem::Type val) {
|
2023-06-19 08:33:09 +00:00
|
|
|
for (const auto& [name, item_val] : Lookup)
|
|
|
|
if (item_val == val)
|
|
|
|
return gin::ConvertToV8(isolate, name);
|
2016-08-12 09:31:17 +00:00
|
|
|
|
2023-06-19 08:33:09 +00:00
|
|
|
return gin::ConvertToV8(isolate, "");
|
2016-08-12 09:31:17 +00:00
|
|
|
}
|
2023-06-19 08:33:09 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
static constexpr auto Lookup =
|
2024-01-11 01:00:37 +00:00
|
|
|
base::MakeFixedFlatMap<std::string_view, JumpListItem::Type>({
|
2023-06-19 08:33:09 +00:00
|
|
|
{"file", JumpListItem::Type::kFile},
|
|
|
|
{"separator", JumpListItem::Type::kSeparator},
|
|
|
|
{"task", JumpListItem::Type::kTask},
|
|
|
|
});
|
2016-08-12 09:31:17 +00:00
|
|
|
};
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
template <>
|
2016-08-12 09:31:17 +00:00
|
|
|
struct Converter<JumpListItem> {
|
2018-04-18 01:55:30 +00:00
|
|
|
static bool FromV8(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Value> val,
|
2016-08-12 09:31:17 +00:00
|
|
|
JumpListItem* out) {
|
2019-10-24 05:47:58 +00:00
|
|
|
gin_helper::Dictionary dict;
|
2016-08-12 09:31:17 +00:00
|
|
|
if (!ConvertFromV8(isolate, val, &dict))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (!dict.Get("type", &(out->type)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
switch (out->type) {
|
2020-10-27 17:51:45 +00:00
|
|
|
case JumpListItem::Type::kTask:
|
2016-08-12 09:31:17 +00:00
|
|
|
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));
|
2019-05-13 16:17:12 +00:00
|
|
|
dict.Get("workingDirectory", &(out->working_dir));
|
2016-08-12 09:31:17 +00:00
|
|
|
return true;
|
|
|
|
|
2020-10-27 17:51:45 +00:00
|
|
|
case JumpListItem::Type::kSeparator:
|
2016-08-12 09:31:17 +00:00
|
|
|
return true;
|
|
|
|
|
2020-10-27 17:51:45 +00:00
|
|
|
case JumpListItem::Type::kFile:
|
2016-08-12 09:31:17 +00:00
|
|
|
return dict.Get("path", &(out->path));
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(false);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
|
|
|
const JumpListItem& val) {
|
2023-08-21 01:43:41 +00:00
|
|
|
auto dict = gin_helper::Dictionary::CreateEmpty(isolate);
|
2016-08-12 09:31:17 +00:00
|
|
|
dict.Set("type", val.type);
|
|
|
|
|
|
|
|
switch (val.type) {
|
2020-10-27 17:51:45 +00:00
|
|
|
case JumpListItem::Type::kTask:
|
2016-08-12 09:31:17 +00:00
|
|
|
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);
|
2019-05-13 16:17:12 +00:00
|
|
|
dict.Set("workingDirectory", val.working_dir);
|
2016-08-12 09:31:17 +00:00
|
|
|
break;
|
|
|
|
|
2020-10-27 17:51:45 +00:00
|
|
|
case JumpListItem::Type::kSeparator:
|
2016-08-12 09:31:17 +00:00
|
|
|
break;
|
|
|
|
|
2020-10-27 17:51:45 +00:00
|
|
|
case JumpListItem::Type::kFile:
|
2016-08-12 09:31:17 +00:00
|
|
|
dict.Set("path", val.path);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return dict.GetHandle();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
template <>
|
2016-08-12 09:31:17 +00:00
|
|
|
struct Converter<JumpListCategory::Type> {
|
2018-04-18 01:55:30 +00:00
|
|
|
static bool FromV8(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Value> val,
|
2016-08-12 09:31:17 +00:00
|
|
|
JumpListCategory::Type* out) {
|
2023-06-19 08:33:09 +00:00
|
|
|
return FromV8WithLookup(isolate, val, Lookup, out);
|
2016-08-12 09:31:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
|
|
|
JumpListCategory::Type val) {
|
2023-06-19 08:33:09 +00:00
|
|
|
for (const auto& [name, type_val] : Lookup)
|
|
|
|
if (type_val == val)
|
|
|
|
return gin::ConvertToV8(isolate, name);
|
2016-08-12 09:31:17 +00:00
|
|
|
|
2023-06-19 08:33:09 +00:00
|
|
|
return gin::ConvertToV8(isolate, "");
|
2016-08-12 09:31:17 +00:00
|
|
|
}
|
2023-06-19 08:33:09 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
static constexpr auto Lookup =
|
2024-01-11 01:00:37 +00:00
|
|
|
base::MakeFixedFlatMap<std::string_view, JumpListCategory::Type>({
|
2023-06-19 08:33:09 +00:00
|
|
|
{"custom", JumpListCategory::Type::kCustom},
|
|
|
|
{"frequent", JumpListCategory::Type::kFrequent},
|
|
|
|
{"recent", JumpListCategory::Type::kRecent},
|
|
|
|
{"tasks", JumpListCategory::Type::kTasks},
|
|
|
|
});
|
2016-08-12 09:31:17 +00:00
|
|
|
};
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
template <>
|
2016-08-12 09:31:17 +00:00
|
|
|
struct Converter<JumpListCategory> {
|
2018-04-18 01:55:30 +00:00
|
|
|
static bool FromV8(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Value> val,
|
2016-08-12 09:31:17 +00:00
|
|
|
JumpListCategory* out) {
|
2019-10-24 05:47:58 +00:00
|
|
|
gin_helper::Dictionary dict;
|
2016-08-12 09:31:17 +00:00
|
|
|
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())
|
2020-10-27 17:51:45 +00:00
|
|
|
out->type = JumpListCategory::Type::kTasks;
|
2016-08-12 09:31:17 +00:00
|
|
|
else
|
2020-10-27 17:51:45 +00:00
|
|
|
out->type = JumpListCategory::Type::kCustom;
|
2016-08-12 09:31:17 +00:00
|
|
|
}
|
|
|
|
|
2020-10-27 17:51:45 +00:00
|
|
|
if ((out->type == JumpListCategory::Type::kTasks) ||
|
|
|
|
(out->type == JumpListCategory::Type::kCustom)) {
|
2016-08-12 09:31:17 +00:00
|
|
|
if (!dict.Get("items", &(out->items)))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// static
|
2018-04-18 01:55:30 +00:00
|
|
|
template <>
|
2016-08-12 09:31:17 +00:00
|
|
|
struct Converter<JumpListResult> {
|
|
|
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, JumpListResult val) {
|
|
|
|
std::string result_code;
|
|
|
|
switch (val) {
|
2020-10-27 17:51:45 +00:00
|
|
|
case JumpListResult::kSuccess:
|
2016-08-12 09:31:17 +00:00
|
|
|
result_code = "ok";
|
|
|
|
break;
|
|
|
|
|
2020-10-27 17:51:45 +00:00
|
|
|
case JumpListResult::kArgumentError:
|
2016-08-12 09:31:17 +00:00
|
|
|
result_code = "argumentError";
|
|
|
|
break;
|
|
|
|
|
2020-10-27 17:51:45 +00:00
|
|
|
case JumpListResult::kGenericError:
|
2016-08-12 09:31:17 +00:00
|
|
|
result_code = "error";
|
|
|
|
break;
|
|
|
|
|
2020-10-27 17:51:45 +00:00
|
|
|
case JumpListResult::kCustomCategorySeparatorError:
|
2016-08-12 09:31:17 +00:00
|
|
|
result_code = "invalidSeparatorError";
|
|
|
|
break;
|
|
|
|
|
2020-10-27 17:51:45 +00:00
|
|
|
case JumpListResult::kMissingFileTypeRegistrationError:
|
2016-08-12 09:31:17 +00:00
|
|
|
result_code = "fileTypeRegistrationError";
|
|
|
|
break;
|
|
|
|
|
2020-10-27 17:51:45 +00:00
|
|
|
case JumpListResult::kCustomCategoryAccessDeniedError:
|
2016-08-12 09:31:17 +00:00
|
|
|
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-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
|
2021-06-23 23:40:51 +00:00
|
|
|
: content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY;
|
2016-11-30 07:30:03 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-08-31 18:55:30 +00:00
|
|
|
template <>
|
|
|
|
struct Converter<net::SecureDnsMode> {
|
|
|
|
static bool FromV8(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Value> val,
|
|
|
|
net::SecureDnsMode* out) {
|
2023-06-19 08:33:09 +00:00
|
|
|
static constexpr auto Lookup =
|
2024-01-11 01:00:37 +00:00
|
|
|
base::MakeFixedFlatMap<std::string_view, net::SecureDnsMode>({
|
2023-06-19 08:33:09 +00:00
|
|
|
{"automatic", net::SecureDnsMode::kAutomatic},
|
|
|
|
{"off", net::SecureDnsMode::kOff},
|
|
|
|
{"secure", net::SecureDnsMode::kSecure},
|
|
|
|
});
|
|
|
|
return FromV8WithLookup(isolate, val, Lookup, out);
|
2021-08-31 18:55:30 +00:00
|
|
|
}
|
|
|
|
};
|
2019-10-24 05:47:58 +00:00
|
|
|
} // namespace gin
|
2014-11-17 09:19:41 +00:00
|
|
|
|
2022-06-29 19:55:47 +00:00
|
|
|
namespace electron::api {
|
2013-05-02 16:05:09 +00:00
|
|
|
|
2020-07-28 23:43:43 +00:00
|
|
|
gin::WrapperInfo App::kWrapperInfo = {gin::kEmbedderNativeGin};
|
|
|
|
|
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
|
|
|
|
2015-01-19 01:52:15 +00:00
|
|
|
// Return the path constant from string.
|
2024-01-11 01:00:37 +00:00
|
|
|
int GetPathConstant(std::string_view name) {
|
2023-06-14 21:00:46 +00:00
|
|
|
// clang-format off
|
2024-01-11 01:00:37 +00:00
|
|
|
constexpr auto Lookup = base::MakeFixedFlatMap<std::string_view, int>({
|
2023-06-14 21:00:46 +00:00
|
|
|
{"appData", DIR_APP_DATA},
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_POSIX)
|
2023-06-14 21:00:46 +00:00
|
|
|
{"cache", base::DIR_CACHE},
|
2021-06-15 00:32:56 +00:00
|
|
|
#else
|
2023-06-14 21:00:46 +00:00
|
|
|
{"cache", base::DIR_ROAMING_APP_DATA},
|
2021-06-15 00:32:56 +00:00
|
|
|
#endif
|
2023-06-14 21:00:46 +00:00
|
|
|
{"crashDumps", DIR_CRASH_DUMPS},
|
|
|
|
{"desktop", base::DIR_USER_DESKTOP},
|
|
|
|
{"documents", chrome::DIR_USER_DOCUMENTS},
|
|
|
|
{"downloads", chrome::DIR_DEFAULT_DOWNLOADS},
|
|
|
|
{"exe", base::FILE_EXE},
|
|
|
|
{"home", base::DIR_HOME},
|
|
|
|
{"logs", DIR_APP_LOGS},
|
|
|
|
{"module", base::FILE_MODULE},
|
|
|
|
{"music", chrome::DIR_USER_MUSIC},
|
|
|
|
{"pictures", chrome::DIR_USER_PICTURES},
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2023-06-14 21:00:46 +00:00
|
|
|
{"recent", electron::DIR_RECENT},
|
2020-05-13 02:27:56 +00:00
|
|
|
#endif
|
2023-06-14 21:00:46 +00:00
|
|
|
{"sessionData", DIR_SESSION_DATA},
|
|
|
|
{"temp", base::DIR_TEMP},
|
|
|
|
{"userCache", DIR_USER_CACHE},
|
|
|
|
{"userData", chrome::DIR_USER_DATA},
|
|
|
|
{"userDesktop", base::DIR_USER_DESKTOP},
|
|
|
|
{"videos", chrome::DIR_USER_VIDEOS},
|
|
|
|
});
|
|
|
|
// clang-format on
|
|
|
|
const auto* iter = Lookup.find(name);
|
|
|
|
return iter != Lookup.end() ? iter->second : -1;
|
2015-01-19 01:52:15 +00:00
|
|
|
}
|
|
|
|
|
2015-10-22 08:24:35 +00:00
|
|
|
bool NotificationCallbackWrapper(
|
2019-04-27 04:42:56 +00:00
|
|
|
const base::RepeatingCallback<
|
2024-02-29 09:31:13 +00:00
|
|
|
void(base::CommandLine command_line,
|
2021-10-15 01:32:32 +00:00
|
|
|
const base::FilePath& current_directory,
|
2024-04-15 17:32:48 +00:00
|
|
|
const std::vector<uint8_t> additional_data)>& callback,
|
2024-02-29 09:31:13 +00:00
|
|
|
base::CommandLine cmd,
|
2021-10-15 01:32:32 +00:00
|
|
|
const base::FilePath& cwd,
|
2024-04-15 17:32:48 +00:00
|
|
|
const std::vector<uint8_t> additional_data) {
|
2015-10-22 09:12:09 +00:00
|
|
|
// Make sure the callback is called after app gets ready.
|
|
|
|
if (Browser::Get()->is_ready()) {
|
2024-02-29 09:31:13 +00:00
|
|
|
callback.Run(std::move(cmd), cwd, std::move(additional_data));
|
2015-10-22 09:12:09 +00:00
|
|
|
} else {
|
|
|
|
scoped_refptr<base::SingleThreadTaskRunner> task_runner(
|
2023-02-03 11:43:42 +00:00
|
|
|
base::SingleThreadTaskRunner::GetCurrentDefault());
|
2021-10-15 01:32:32 +00:00
|
|
|
|
|
|
|
// Make a copy of the span so that the data isn't lost.
|
2024-02-29 09:31:13 +00:00
|
|
|
task_runner->PostTask(
|
|
|
|
FROM_HERE, base::BindOnce(base::IgnoreResult(callback), std::move(cmd),
|
|
|
|
cwd, std::move(additional_data)));
|
2015-10-22 09:12:09 +00:00
|
|
|
}
|
2023-11-13 03:51:56 +00:00
|
|
|
// ProcessSingleton needs to know whether current process is quitting.
|
2015-10-22 08:24:35 +00:00
|
|
|
return !Browser::Get()->is_shutting_down();
|
|
|
|
}
|
|
|
|
|
2017-10-23 07:54:17 +00:00
|
|
|
void GotPrivateKey(std::shared_ptr<content::ClientCertificateDelegate> delegate,
|
|
|
|
scoped_refptr<net::X509Certificate> cert,
|
|
|
|
scoped_refptr<net::SSLPrivateKey> private_key) {
|
|
|
|
delegate->ContinueWithCertificate(cert, private_key);
|
|
|
|
}
|
|
|
|
|
2015-06-11 15:22:07 +00:00
|
|
|
void OnClientCertificateSelected(
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
std::shared_ptr<content::ClientCertificateDelegate> delegate,
|
2017-10-23 07:54:17 +00:00
|
|
|
std::shared_ptr<net::ClientCertIdentityList> identities,
|
2020-07-28 23:43:43 +00:00
|
|
|
gin::Arguments* args) {
|
2016-12-07 10:03:56 +00:00
|
|
|
if (args->Length() == 2) {
|
2017-08-31 20:18:09 +00:00
|
|
|
delegate->ContinueWithCertificate(nullptr, nullptr);
|
2016-12-07 10:03:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Local<v8::Value> val;
|
|
|
|
args->GetNext(&val);
|
|
|
|
if (val->IsNull()) {
|
2017-08-31 20:18:09 +00:00
|
|
|
delegate->ContinueWithCertificate(nullptr, nullptr);
|
2015-06-11 15:22:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-10-24 05:47:58 +00:00
|
|
|
gin_helper::Dictionary cert_data;
|
|
|
|
if (!gin::ConvertFromV8(isolate, val, &cert_data)) {
|
2020-07-28 23:43:43 +00:00
|
|
|
gin_helper::ErrorThrower(isolate).ThrowError(
|
|
|
|
"Must pass valid certificate object.");
|
2016-12-07 10:03:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-17 11:48:09 +00:00
|
|
|
std::string data;
|
2016-03-05 09:57:46 +00:00
|
|
|
if (!cert_data.Get("data", &data))
|
|
|
|
return;
|
2015-06-11 15:22:07 +00:00
|
|
|
|
2016-03-05 09:57:46 +00:00
|
|
|
auto certs = net::X509Certificate::CreateCertificateListFromBytes(
|
2024-04-16 23:48:54 +00:00
|
|
|
base::as_bytes(base::make_span(data)), net::X509Certificate::FORMAT_AUTO);
|
2017-08-31 20:18:09 +00:00
|
|
|
if (!certs.empty()) {
|
|
|
|
scoped_refptr<net::X509Certificate> cert(certs[0].get());
|
2020-10-27 17:22:24 +00:00
|
|
|
for (auto& identity : *identities) {
|
2021-06-07 13:40:43 +00:00
|
|
|
scoped_refptr<net::X509Certificate> identity_cert =
|
|
|
|
identity->certificate();
|
|
|
|
// Since |cert| was recreated from |data|, it won't include any
|
|
|
|
// intermediates. That's fine for checking equality, but once a match is
|
|
|
|
// found then |identity_cert| should be used since it will include the
|
|
|
|
// intermediates which would otherwise be lost.
|
|
|
|
if (cert->EqualsExcludingChain(identity_cert.get())) {
|
2017-10-23 07:54:17 +00:00
|
|
|
net::ClientCertIdentity::SelfOwningAcquirePrivateKey(
|
2021-06-07 13:40:43 +00:00
|
|
|
std::move(identity), base::BindRepeating(&GotPrivateKey, delegate,
|
|
|
|
std::move(identity_cert)));
|
2017-10-23 07:54:17 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-08-31 20:18:09 +00:00
|
|
|
}
|
2015-06-11 15:22:07 +00:00
|
|
|
}
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(USE_NSS_CERTS)
|
2020-04-13 20:52:07 +00:00
|
|
|
int ImportIntoCertStore(CertificateManagerModel* model, base::Value options) {
|
2016-04-18 15:35:33 +00:00
|
|
|
std::string file_data, cert_path;
|
2021-03-16 16:18:45 +00:00
|
|
|
std::u16string password;
|
2018-03-12 06:28:55 +00:00
|
|
|
net::ScopedCERTCertificateList imported_certs;
|
2016-04-19 05:17:28 +00:00
|
|
|
int rv = -1;
|
2020-04-13 20:52:07 +00:00
|
|
|
|
2023-03-20 14:38:45 +00:00
|
|
|
if (const base::Value::Dict* dict = options.GetIfDict(); dict != nullptr) {
|
|
|
|
if (const std::string* str = dict->FindString("certificate"); str)
|
|
|
|
cert_path = *str;
|
2020-04-13 20:52:07 +00:00
|
|
|
|
2023-03-20 14:38:45 +00:00
|
|
|
if (const std::string* str = dict->FindString("password"); str)
|
|
|
|
password = base::UTF8ToUTF16(*str);
|
|
|
|
}
|
2016-04-18 15:35:33 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
2016-04-19 05:17:28 +00:00
|
|
|
#endif
|
2016-04-18 05:11:31 +00:00
|
|
|
|
2019-11-01 06:10:32 +00:00
|
|
|
void OnIconDataAvailable(gin_helper::Promise<gfx::Image> promise,
|
|
|
|
gfx::Image icon) {
|
2019-05-01 00:18:22 +00:00
|
|
|
if (!icon.IsEmpty()) {
|
2019-11-01 06:10:32 +00:00
|
|
|
promise.Resolve(icon);
|
2016-11-05 18:23:49 +00:00
|
|
|
} else {
|
2019-02-21 12:32:44 +00:00
|
|
|
promise.RejectWithErrorMessage("Failed to get file icon.");
|
2016-11-05 18:23:49 +00:00
|
|
|
}
|
2016-11-02 18:57:16 +00:00
|
|
|
}
|
|
|
|
|
2014-08-19 13:26:45 +00:00
|
|
|
} // namespace
|
|
|
|
|
2020-07-28 23:43:43 +00:00
|
|
|
App::App() {
|
2015-11-18 02:07:03 +00:00
|
|
|
static_cast<ElectronBrowserClient*>(ElectronBrowserClient::Get())
|
|
|
|
->set_delegate(this);
|
2013-05-03 02:53:54 +00:00
|
|
|
Browser::Get()->AddObserver(this);
|
2018-09-27 14:59:23 +00:00
|
|
|
|
2020-12-01 01:47:46 +00:00
|
|
|
auto pid = content::ChildProcessHost::kInvalidUniqueID;
|
2018-06-18 07:32:55 +00:00
|
|
|
auto process_metric = std::make_unique<electron::ProcessMetric>(
|
2019-06-14 19:39:55 +00:00
|
|
|
content::PROCESS_TYPE_BROWSER, base::GetCurrentProcessHandle(),
|
2018-06-18 07:32:55 +00:00
|
|
|
base::ProcessMetrics::CreateCurrentProcessMetrics());
|
2017-05-16 00:41:45 +00:00
|
|
|
app_metrics_[pid] = std::move(process_metric);
|
2013-05-03 02:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
App::~App() {
|
2018-04-18 01:55:30 +00:00
|
|
|
static_cast<ElectronBrowserClient*>(ElectronBrowserClient::Get())
|
|
|
|
->set_delegate(nullptr);
|
2013-05-03 02:53:54 +00:00
|
|
|
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);
|
2013-05-03 02:53:54 +00:00
|
|
|
}
|
|
|
|
|
2015-02-26 03:33:42 +00:00
|
|
|
void App::OnBeforeQuit(bool* prevent_default) {
|
2018-04-19 10:39:17 +00:00
|
|
|
if (Emit("before-quit")) {
|
|
|
|
*prevent_default = true;
|
|
|
|
}
|
2015-02-26 03:33:42 +00:00
|
|
|
}
|
|
|
|
|
2013-05-03 02:53:54 +00:00
|
|
|
void App::OnWillQuit(bool* prevent_default) {
|
2018-04-19 10:39:17 +00:00
|
|
|
if (Emit("will-quit")) {
|
|
|
|
*prevent_default = true;
|
|
|
|
}
|
2013-05-03 02:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void App::OnWindowAllClosed() {
|
|
|
|
Emit("window-all-closed");
|
|
|
|
}
|
|
|
|
|
2015-12-10 02:19:51 +00:00
|
|
|
void App::OnQuit() {
|
chore: bump chromium to 92.0.4475.0 (master) (#28462)
* chore: bump chromium in DEPS to 91.0.4464.0
* chore: rebuild chromium/dcheck.patch with import-patches -3
Mechanical only; no code changes
* chore: remove content_browser_main_loop.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2725153
The function being patched (BrowserMainLoop::MainMessageLoopRun()) no
longer exists.
NB: if removing this introduces regressions the likely fix will be to
add a similar patch for ShellBrowserMainParts::WillRunMainMessageLoop()
which has similar code and was added at the same time this was removed.
* chore: rebuild chromium/put_back_deleted_colors_for_autofill.patch with import-patches -3
Mechanical only; no code changes
* chore: rebuild chromium/disable_color_correct_rendering.patch with import-patches -3
Mechanical only; no code changes
* chore: rebuild chromium/eat_allow_disabling_blink_scheduler_throttling_per_renderview.patch with patch
Mechanical only; no code changes
* chore: rebuild chromium/gpu_notify_when_dxdiag_request_fails.patch with import-patches -3
Mechanical only; no code changes
* chore: rebuild chromium/ui_gtk_public_header.patch manually
no code changes
* chore: rebuild chromium/web_contents.patch with import-patches -3
Mechanical only; no code changes
* chore: remove v8/skip_global_registration_of_shared_arraybuffer_backing_stores.patch
Refs: https://chromium-review.googlesource.com/c/v8/v8/+/2763874
This patch has been merged upstream
* chore: export patches
* chore: update add_trustedauthclient_to_urlloaderfactory.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2757969
Sync with removal of render_frame_id_
* chore: sync chromium/put_back_deleted_colors_for_autofill.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2785841
SkColorFromColorId() no longer takes theme, scheme args
* chore: sync chromium/put_back_deleted_colors_for_autofill.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2772143
Change new calls to GetDarkSchemeColor to fit our patched call signature
* chore: update add_trustedauthclient_to_urlloaderfactory.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2757969
Sync with removal of render_frame_id_ in our mojom
* chore: update chromium/frame_host_manager.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2740008
UrlInfo ctor now takes UrlInfo::OriginIsolationRequest instead of a bool
* chore: update chromium/revert_remove_contentrendererclient_shouldfork.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2755314
Upstream has removed `history_list_length_` which we were comparing to 0
to calculate our `is_initial_navigation` bool when calling ShouldFork().
ShouldFork() is ours and none of the code paths actually use that param,
so this commit removes it altogether.
* chore: update permissions_to_register
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2789074
Replace all uses of APIPermission::ID enum with Mojo type
* refactor: update return type of PreMainMessageLoopRun()
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2725153
Used to return void; now returns an int errorcode.
Note: 2725153 also has some nice doc updates about Browser's "stages"
* refactor: sync ElectronBrowserMainParts to MainParts changes
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2725153
RunMainMessageLoopParts has been replaced with WillRunMainMessageLoop
so `BrowserMainLoop::result_code_` is no longer available to us for our
exit_code_ pointer.
This variable held a dual role: (1) of course, hold the exit code, but
also (2) was a nullptr before the message loop was ready, indicating to
anyone calling SetExitCode() that we were still in startup and could
just exit() without any extra steps. exit_code_ still fulfills these two
roles but is now a base::Optional.
* chore: update ElectronBrowserMainParts::PreDefaultMainMessageLoopRun
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2725153
BrowserMainParts::BrowsePreDefaultMainMesssageLoopRun() has been
removed; move that work to the new WillRunMainMessageLoop().
* refactor: stop using CallbackList; it has been removed.
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2785973
* refactor: update use of threadpools.
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2773408
The upstream code is still in flux (e.g. reverts and re-lands) but the
tl;dr for this commit is (1) include thread_pool.h if you're using it
and (2) don't instantiate pools directly.
* refactor: remove routing_id from CreateLoaderAndStart
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2762858
NB: One logic branch in ProxyingURLLoaderFactory::CreateLoaderAndStart
calls std::make_unique<InProgressRequest>, which needs a routing_id.
This PR uses the member field `routing_id_` since there's no longer one
being passed into CreateLoaderAndStart.
* refactor: sync to upstream ParittionOptions churn
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2771318
PartitionOptions' enums have changed.
* refactor: update Manifest::Location usage
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2771320
tldr: s/Manifest::FOO/ManifestLocation::kFoo/
* chore: bump chromium in DEPS to 91.0.4465.0
* update patches
* refactor: update extensions::Manifest to upstream
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2771320
- extensions::Manifest::COMPONENT
+ extensions::mojom::ManifestLocation::kExternalComponent
* refactor: sync with upstream UrlInfo ctor changes
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2740008
UrlInfo ctor now takes UrlInfo::OriginIsolationRequest instead of a bool
* chore: update invocation of convert_protocol_to_json.py
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2792623
python3 is being used in parts of the upstream build, but the copy of
convert_protocol_to_json.py invoked in v8/third_party/inspector_protocol
is not python3-friendly. Node has a py2+3-friendly version of it in its
tools directory, so call it instead.
* chore: use extensions::mojom::APIPermissionID
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2791122
tldr:
- extensions::APIPermission::kFoo
+ extensions::mojom::APIPermissionID::kFoo
* chore: Remove support for TLS1.0/1.1 in SSLVersionMin policy
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2765737
Remove TLS v1.0 & 1.1 from our SSLProtocolVersionFromString() function.
This is the same change made upstream at
https://chromium-review.googlesource.com/c/chromium/src/+/2765737/8/chrome/browser/ssl/ssl_config_service_manager_pref.cc
* fixup! chore: update ElectronBrowserMainParts::PreDefaultMainMessageLoopRun
* chore: Use IDType for permission change subscriptions.
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2791431
tldr: {Subscribe,Unsubscribe}PermissionStatusChange's tag type used to
be an int; now it's the new SubscriptionId type (which is an IdType64).
* chore: sync PowerMonitor code to upstream refactor
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2752635
tldr: PowerMonitor has been split into PowerStateObserver,
PowerSuspendObserver, and PowerThermalObserver to reduce number of tasks
posted to consumers who only need notifications for one of those things
instead of all of them.
* chore: use PartitionOptions's new Cookies field
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2771318
* Revert "refactor: remove routing_id from CreateLoaderAndStart"
This reverts commit 8c9773b87a3c84f9073a47089eb2b6889d745245.
8c9773b was only a partial fix; reverting to start & try again.
* update patches
* chore: bump chromium in DEPS to 91.0.4466.0
* chore: update chromium/accelerator.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2795472
tldr: sync patch with upstream renamed variable & macro names.
* chore: update chromium/gtk_visibility.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2796200
tldr: no code changes; just updating the diff to apply cleanly.
note: ooh upstream Wayland hacking!
* chore: update chromium/picture-in-picture.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2710023
tldr: no code changes; just updating the diff to apply cleanly.
* chore: update chromium/worker_feat_add_hook_to_notify_script_ready.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2775573
tldr: no code changes; just updating the diff to apply cleanly.
* chore: export_all_patches
* chore: update chromium/feat_add_set_theme_source_to_allow_apps_to.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2796511
tldr: NotifyObservers has been renamed to NotifyOnNativeThemeUpdated,
so update the invocation in our patch.
* chore: update ElectronBrowserClient w/upstream API
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2797454
tldr: GetDevToolsManagerDelegate() was returning an owned raw pointer.
Replaced it with CreateDevToolsManagerDelegate() which uses unique_ptr<>.
* chore: handle new content::PermissionType::FILE_HANDLING in toV8()
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2762201
`file-handling` string confirmed in https://chromium-review.googlesource.com/c/chromium/src/+/2762201/18/chrome/browser/ui/webui/settings/site_settings_helper.cc
* refactor: remove routing_id from CreateLoaderAndStart pt 1
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2762858
Part 1: the easiest ones
* 2796724: Support Python3
https://chromium-review.googlesource.com/c/infra/luci/python-adb/+/2796724
* chore: bump chromium in DEPS to 91.0.4468.0
* 2668974: WebShare: Implement SharingServicePicker
https://chromium-review.googlesource.com/c/chromium/src/+/2668974
* 2802766: Apply modernize-make-unique to media/
https://chromium-review.googlesource.com/c/chromium/src/+/2802766
* 2802823: Apply modernize-make-unique to gpu/
https://chromium-review.googlesource.com/c/chromium/src/+/2802823
* 2803041: Apply modernize-make-unique to remaining files
https://chromium-review.googlesource.com/c/chromium/src/+/2803041
* 2798873: Convert GtkKeyBindingsHandler build checks to runtime checks
https://chromium-review.googlesource.com/c/chromium/src/+/2798873
* 2733595: [ch-r] Parse ACCEPT_CH H2/3 frame and restart with new headers if needed
https://chromium-review.googlesource.com/c/chromium/src/+/2733595
* chore: update patch indices
* 2795107: Remove unused PermissionRequest IDs.
https://chromium-review.googlesource.com/c/chromium/src/+/2795107
* chore: bump chromium in DEPS to 91.0.4469.0
* chore: fixup patch indices
* chore: bump chromium in DEPS to 91.0.4469.5
* PiP 1.5: Add microphone, camera, and hang up buttons to the PiP window
https://chromium-review.googlesource.com/c/chromium/src/+/2710023
* fixup! refactor: remove routing_id from CreateLoaderAndStart
* refactor: use URLLoaderNetworkServiceObserver for auth requests from SimpleURLLoader
* fixup! chore: fixup patch indices
* 2724817: Expand scope of wasm-eval to all URLs
https://chromium-review.googlesource.com/c/chromium/src/+/2724817
* Fixup patch after rebase
* chore: bump chromium in DEPS to 91.0.4472.0
* 2797341: [ozone/x11] Enabled the global shortcut listener.
https://chromium-review.googlesource.com/c/chromium/src/+/2797341
* 2805553: Reland Add GTK ColorMixers to ColorPipeline P1
https://chromium-review.googlesource.com/c/chromium/src/+/2805553
* 2804366: PiP 1.5: Label back to tab button with origin and center it
https://chromium-review.googlesource.com/c/chromium/src/+/2804366
* 2784730: Fix crash on AX mode change in NativeViewHost without a Widget
https://chromium-review.googlesource.com/c/chromium/src/+/2784730
* chore: update patch indices
* 2810174: Add PdfAnnotationsEnabled policy.
https://chromium-review.googlesource.com/c/chromium/src/+/2810174
* 2807829: Allow capturers to indicate if they want a WakeLock or not.
https://chromium-review.googlesource.com/c/chromium/src/+/2807829
* chore: bump chromium in DEPS to 92.0.4473.0
* chore: bump chromium in DEPS to 92.0.4474.0
* chore: bump chromium in DEPS to 92.0.4475.0
* chore: update patches
* chore: updates patches
* chore: update is_media_key patch to handle new ozone impl
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2797341
* fix: ExecuteJavascript requests now need to be flagged as non-bf-aware
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2787195
* chore: icon_util_x11 is now icon_util_linux
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2791362
* build: update sysroots
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2628496
* build: fix missing symbols on linux build
* use_ozone and use_x11 are not exclusive
* new button view to build for pip
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2797341
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2804366
* chore: fix broken gtk_util color patch
* chore: remove patch conflict
* build: update linux manifests
* chore: build bttlb on all platforms for pip
* chore: add thread_pool include for views delegate win
* chore: fix lint
* chore: add node patches for V8 changes
* build: add missing base include on windows
* fix: update frame host manager patch for new state transitions
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2714464
* chore: update windows zip manifests
* chore: update mac zip manifests
* chore: fix patch linting
* refactor: implement missing URLLoaderNetworkServiceObserver methods
It is against The Mojo Rules to leave hanging callbacks. These always
have to be called.
Refs: https://github.com/electron/electron/commit/186528aab9f8e29d658f07d220bb7f627980edda
* spec: fix locale test on local linux
* fix: pass the exit code correctly in new PreMainMessageLoopRun
Refs: https://github.com/electron/electron/commit/2622e91c4493ceb032e2f80cb484885bb8f97475
* fix: ensure we early-exit when request_handler_ is not provided
Refs: https://github.com/electron/electron/commit/93077afbfb6db248a0c0cc447d7ad2c9ccfda1d5
* fix: strongly set result_code in the BrowserMainLoop
* fix: invalid usage of non-targetted PostTask
You must always either use a host threadpool or specify a target
thread. In this case we did neither after this refactor.
Refs: https://github.com/electron/electron/pull/28462/commits/4e33ee0ad35a710bd34641cb0376bdee6aea2d1f
* chore: fix gn check
* chore: remove stray .rej files in patch
* chore: add mojo error code to url loader failure
* build: ensure CI is truthy in arm test env
* fix: handle windowCaptureMacV2 being enabled when fetching media source id
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2709931
Co-authored-by: Charles Kerr <charles@charleskerr.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
Co-authored-by: deepak1556 <hop2deep@gmail.com>
Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com>
Co-authored-by: Samuel Attard <sattard@slack-corp.com>
2021-04-15 17:44:35 +00:00
|
|
|
const int exitCode = ElectronBrowserMainParts::Get()->GetExitCode();
|
2015-12-10 02:19:51 +00:00
|
|
|
Emit("quit", exitCode);
|
2018-01-03 09:59:12 +00:00
|
|
|
|
|
|
|
if (process_singleton_) {
|
|
|
|
process_singleton_->Cleanup();
|
|
|
|
process_singleton_.reset();
|
|
|
|
}
|
2014-09-25 13:47:54 +00:00
|
|
|
}
|
|
|
|
|
2013-05-30 08:03:10 +00:00
|
|
|
void App::OnOpenFile(bool* prevent_default, const std::string& file_path) {
|
2018-04-19 10:39:17 +00:00
|
|
|
if (Emit("open-file", file_path)) {
|
|
|
|
*prevent_default = true;
|
|
|
|
}
|
2013-05-30 08:03:10 +00:00
|
|
|
}
|
|
|
|
|
2013-07-10 08:10:38 +00:00
|
|
|
void App::OnOpenURL(const std::string& url) {
|
2015-01-15 01:51:54 +00:00
|
|
|
Emit("open-url", url);
|
2013-07-10 08:10:38 +00:00
|
|
|
}
|
|
|
|
|
2015-09-15 02:05:53 +00:00
|
|
|
void App::OnActivate(bool has_visible_windows) {
|
|
|
|
Emit("activate", has_visible_windows);
|
2015-09-14 11:28:13 +00:00
|
|
|
}
|
|
|
|
|
2013-06-03 07:31:46 +00:00
|
|
|
void App::OnWillFinishLaunching() {
|
|
|
|
Emit("will-finish-launching");
|
|
|
|
}
|
|
|
|
|
2022-06-23 06:28:41 +00:00
|
|
|
void App::OnFinishLaunching(base::Value::Dict launch_info) {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_LINUX)
|
2016-10-07 10:45:30 +00:00
|
|
|
// Set the application name for audio streams shown in external
|
|
|
|
// applications. Only affects pulseaudio currently.
|
|
|
|
media::AudioManager::SetGlobalAppName(Browser::Get()->GetName());
|
2016-10-07 20:44:31 +00:00
|
|
|
#endif
|
2022-06-23 06:28:41 +00:00
|
|
|
Emit("ready", base::Value(std::move(launch_info)));
|
2017-09-14 13:08:18 +00:00
|
|
|
}
|
2017-09-14 12:33:13 +00:00
|
|
|
|
2017-12-22 15:55:57 +00:00
|
|
|
void App::OnPreMainMessageLoopRun() {
|
|
|
|
content::BrowserChildProcessObserver::Add(this);
|
2022-08-19 22:45:58 +00:00
|
|
|
if (process_singleton_ && watch_singleton_socket_on_ready_) {
|
|
|
|
process_singleton_->StartWatching();
|
|
|
|
watch_singleton_socket_on_ready_ = false;
|
2018-01-03 09:59:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-13 23:39:26 +00:00
|
|
|
void App::OnPreCreateThreads() {
|
|
|
|
DCHECK(!content::GpuDataManager::Initialized());
|
|
|
|
content::GpuDataManager* manager = content::GpuDataManager::GetInstance();
|
|
|
|
manager->AddObserver(this);
|
|
|
|
|
|
|
|
if (disable_hw_acceleration_) {
|
|
|
|
manager->DisableHardwareAcceleration();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (disable_domain_blocking_for_3DAPIs_) {
|
|
|
|
content::GpuDataManagerImpl::GetInstance()
|
|
|
|
->DisableDomainBlockingFor3DAPIsForTesting();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-03 09:59:12 +00:00
|
|
|
void App::OnAccessibilitySupportChanged() {
|
|
|
|
Emit("accessibility-support-changed", IsAccessibilitySupportEnabled());
|
2017-12-22 15:55:57 +00:00
|
|
|
}
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2018-04-18 01:55:30 +00:00
|
|
|
void App::OnWillContinueUserActivity(bool* prevent_default,
|
|
|
|
const std::string& type) {
|
2018-04-19 10:39:17 +00:00
|
|
|
if (Emit("will-continue-activity", type)) {
|
|
|
|
*prevent_default = true;
|
|
|
|
}
|
2017-06-26 19:14:44 +00:00
|
|
|
}
|
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) {
|
2017-06-26 19:14:44 +00:00
|
|
|
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,
|
2022-06-23 06:28:41 +00:00
|
|
|
base::Value::Dict user_info,
|
|
|
|
base::Value::Dict details) {
|
|
|
|
if (Emit("continue-activity", type, base::Value(std::move(user_info)),
|
|
|
|
base::Value(std::move(details)))) {
|
2018-04-19 10:39:17 +00:00
|
|
|
*prevent_default = true;
|
|
|
|
}
|
2016-04-30 00:36:04 +00:00
|
|
|
}
|
2017-09-14 07:12:34 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void App::OnUserActivityWasContinued(const std::string& type,
|
2022-06-23 06:28:41 +00:00
|
|
|
base::Value::Dict user_info) {
|
|
|
|
Emit("activity-was-continued", type, base::Value(std::move(user_info)));
|
2017-06-26 19:14:44 +00:00
|
|
|
}
|
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,
|
2022-06-23 06:28:41 +00:00
|
|
|
base::Value::Dict user_info) {
|
|
|
|
if (Emit("update-activity-state", type, base::Value(std::move(user_info)))) {
|
2018-04-19 10:39:17 +00:00
|
|
|
*prevent_default = true;
|
|
|
|
}
|
2017-06-26 19:14:44 +00:00
|
|
|
}
|
2017-09-14 07:12:34 +00:00
|
|
|
|
2017-06-11 08:19:01 +00:00
|
|
|
void App::OnNewWindowForTab() {
|
|
|
|
Emit("new-window-for-tab");
|
|
|
|
}
|
2020-06-16 17:03:41 +00:00
|
|
|
|
|
|
|
void App::OnDidBecomeActive() {
|
|
|
|
Emit("did-become-active");
|
|
|
|
}
|
2023-04-18 14:53:39 +00:00
|
|
|
|
|
|
|
void App::OnDidResignActive() {
|
|
|
|
Emit("did-resign-active");
|
|
|
|
}
|
2016-05-05 03:26:23 +00:00
|
|
|
#endif
|
2016-04-30 00:36:04 +00:00
|
|
|
|
2017-12-07 04:12:38 +00:00
|
|
|
bool App::CanCreateWindow(
|
|
|
|
content::RenderFrameHost* opener,
|
|
|
|
const GURL& opener_url,
|
|
|
|
const GURL& opener_top_level_frame_url,
|
2019-01-21 18:14:57 +00:00
|
|
|
const url::Origin& source_origin,
|
2017-12-07 04:12:38 +00:00
|
|
|
content::mojom::WindowContainerType container_type,
|
2016-10-09 23:30:38 +00:00
|
|
|
const GURL& target_url,
|
2017-12-07 04:12:38 +00:00
|
|
|
const content::Referrer& referrer,
|
2016-10-09 23:30:38 +00:00
|
|
|
const std::string& frame_name,
|
|
|
|
WindowOpenDisposition disposition,
|
2017-12-07 04:12:38 +00:00
|
|
|
const blink::mojom::WindowFeatures& features,
|
2020-03-26 18:05:45 +00:00
|
|
|
const std::string& raw_features,
|
2018-04-11 08:42:14 +00:00
|
|
|
const scoped_refptr<network::ResourceRequestBody>& body,
|
2017-12-07 04:12:38 +00:00
|
|
|
bool user_gesture,
|
|
|
|
bool opener_suppressed,
|
|
|
|
bool* no_javascript_access) {
|
2020-07-28 23:43:43 +00:00
|
|
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
2016-03-31 14:21:18 +00:00
|
|
|
content::WebContents* web_contents =
|
2017-08-04 21:38:06 +00:00
|
|
|
content::WebContents::FromRenderFrameHost(opener);
|
2016-03-31 14:21:18 +00:00
|
|
|
if (web_contents) {
|
2020-07-16 23:16:05 +00:00
|
|
|
WebContents* api_web_contents = WebContents::From(web_contents);
|
2018-10-19 08:52:07 +00:00
|
|
|
// No need to emit any event if the WebContents is not available in JS.
|
2020-07-16 23:16:05 +00:00
|
|
|
if (api_web_contents) {
|
2018-10-19 08:52:07 +00:00
|
|
|
api_web_contents->OnCreateWindow(target_url, referrer, frame_name,
|
2020-03-26 18:05:45 +00:00
|
|
|
disposition, raw_features, body);
|
2018-10-19 08:52:07 +00:00
|
|
|
}
|
2016-03-31 14:21:18 +00:00
|
|
|
}
|
2017-12-07 04:12:38 +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,
|
2019-05-13 21:24:39 +00:00
|
|
|
bool is_main_frame_request,
|
2015-11-18 02:39:25 +00:00
|
|
|
bool strict_enforcement,
|
2019-12-11 00:22:35 +00:00
|
|
|
base::OnceCallback<void(content::CertificateRequestResultType)> callback) {
|
2020-01-31 17:25:46 +00:00
|
|
|
auto adapted_callback = base::AdaptCallbackForRepeating(std::move(callback));
|
2020-07-28 23:43:43 +00:00
|
|
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
2021-09-21 06:49:15 +00:00
|
|
|
bool prevent_default = Emit(
|
|
|
|
"certificate-error", WebContents::FromOrCreate(isolate, web_contents),
|
|
|
|
request_url, net::ErrorToString(cert_error), ssl_info.cert,
|
|
|
|
adapted_callback, is_main_frame_request);
|
2015-11-18 02:39:25 +00:00
|
|
|
|
|
|
|
// Deny the certificate by default.
|
|
|
|
if (!prevent_default)
|
2020-01-31 17:25:46 +00:00
|
|
|
adapted_callback.Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
|
2015-11-18 02:39:25 +00:00
|
|
|
}
|
|
|
|
|
2019-07-03 01:22:09 +00:00
|
|
|
base::OnceClosure App::SelectClientCertificate(
|
2023-07-20 07:36:59 +00:00
|
|
|
content::BrowserContext* browser_context,
|
2015-11-18 02:07:03 +00:00
|
|
|
content::WebContents* web_contents,
|
|
|
|
net::SSLCertRequestInfo* cert_request_info,
|
2017-08-20 21:35:04 +00:00
|
|
|
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());
|
2017-08-20 21:35:04 +00:00
|
|
|
|
|
|
|
// 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)
|
2019-09-13 14:26:59 +00:00
|
|
|
client_certs.emplace_back(identity->certificate());
|
2017-08-20 21:35:04 +00:00
|
|
|
|
2017-10-23 07:54:17 +00:00
|
|
|
auto shared_identities =
|
|
|
|
std::make_shared<net::ClientCertIdentityList>(std::move(identities));
|
|
|
|
|
2020-07-28 23:43:43 +00:00
|
|
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
2020-08-07 03:50:41 +00:00
|
|
|
v8::HandleScope handle_scope(isolate);
|
2015-11-18 02:07:03 +00:00
|
|
|
bool prevent_default =
|
2015-11-18 02:10:21 +00:00
|
|
|
Emit("select-client-certificate",
|
2020-07-28 23:43:43 +00:00
|
|
|
WebContents::FromOrCreate(isolate, web_contents),
|
2017-10-23 07:54:17 +00:00
|
|
|
cert_request_info->host_and_port.ToString(), std::move(client_certs),
|
2020-07-28 23:43:43 +00:00
|
|
|
base::BindOnce(&OnClientCertificateSelected, isolate,
|
2019-04-27 04:42:56 +00:00
|
|
|
shared_delegate, shared_identities));
|
2015-11-18 02:07:03 +00:00
|
|
|
|
|
|
|
// Default to first certificate from the platform store.
|
2017-08-31 20:18:09 +00:00
|
|
|
if (!prevent_default) {
|
2017-10-23 07:54:17 +00:00
|
|
|
scoped_refptr<net::X509Certificate> cert =
|
|
|
|
(*shared_identities)[0]->certificate();
|
|
|
|
net::ClientCertIdentity::SelfOwningAcquirePrivateKey(
|
|
|
|
std::move((*shared_identities)[0]),
|
2019-04-27 04:42:56 +00:00
|
|
|
base::BindRepeating(&GotPrivateKey, shared_delegate, std::move(cert)));
|
2017-08-31 20:18:09 +00:00
|
|
|
}
|
2019-07-03 01:22:09 +00:00
|
|
|
return base::OnceClosure();
|
2015-11-18 02:07:03 +00:00
|
|
|
}
|
|
|
|
|
2019-05-18 01:06:48 +00:00
|
|
|
void App::OnGpuInfoUpdate() {
|
|
|
|
Emit("gpu-info-update");
|
|
|
|
}
|
|
|
|
|
2017-05-16 00:41:45 +00:00
|
|
|
void App::BrowserChildProcessLaunchedAndConnected(
|
|
|
|
const content::ChildProcessData& data) {
|
2020-12-01 01:47:46 +00:00
|
|
|
ChildProcessLaunched(data.process_type, data.id, data.GetProcess().Handle(),
|
2020-10-19 11:55:47 +00:00
|
|
|
data.metrics_name, base::UTF16ToUTF8(data.name));
|
2017-05-16 00:41:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void App::BrowserChildProcessHostDisconnected(
|
|
|
|
const content::ChildProcessData& data) {
|
2020-12-01 01:47:46 +00:00
|
|
|
ChildProcessDisconnected(data.id);
|
2017-05-16 00:41:45 +00:00
|
|
|
}
|
|
|
|
|
2018-09-15 00:11:49 +00:00
|
|
|
void App::BrowserChildProcessCrashed(
|
|
|
|
const content::ChildProcessData& data,
|
|
|
|
const content::ChildProcessTerminationInfo& info) {
|
2020-12-01 01:47:46 +00:00
|
|
|
ChildProcessDisconnected(data.id);
|
2020-07-20 14:34:16 +00:00
|
|
|
BrowserChildProcessCrashedOrKilled(data, info);
|
2017-05-26 15:32:08 +00:00
|
|
|
}
|
|
|
|
|
2018-09-15 00:11:49 +00:00
|
|
|
void App::BrowserChildProcessKilled(
|
|
|
|
const content::ChildProcessData& data,
|
|
|
|
const content::ChildProcessTerminationInfo& info) {
|
2020-12-01 01:47:46 +00:00
|
|
|
ChildProcessDisconnected(data.id);
|
2020-07-20 14:34:16 +00:00
|
|
|
BrowserChildProcessCrashedOrKilled(data, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
void App::BrowserChildProcessCrashedOrKilled(
|
|
|
|
const content::ChildProcessData& data,
|
|
|
|
const content::ChildProcessTerminationInfo& info) {
|
2020-07-28 23:43:43 +00:00
|
|
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
auto details = gin_helper::Dictionary::CreateEmpty(isolate);
|
2020-07-20 14:34:16 +00:00
|
|
|
details.Set("type", content::GetProcessTypeNameInEnglish(data.process_type));
|
|
|
|
details.Set("reason", info.status);
|
|
|
|
details.Set("exitCode", info.exit_code);
|
2020-10-19 11:55:47 +00:00
|
|
|
details.Set("serviceName", data.metrics_name);
|
2020-07-20 14:34:16 +00:00
|
|
|
if (!data.name.empty()) {
|
|
|
|
details.Set("name", data.name);
|
|
|
|
}
|
|
|
|
Emit("child-process-gone", details);
|
2017-05-26 15:32:08 +00:00
|
|
|
}
|
|
|
|
|
2017-05-26 14:51:17 +00:00
|
|
|
void App::RenderProcessReady(content::RenderProcessHost* host) {
|
2020-12-01 01:47:46 +00:00
|
|
|
ChildProcessLaunched(content::PROCESS_TYPE_RENDERER, host->GetID(),
|
2018-09-15 00:13:02 +00:00
|
|
|
host->GetProcess().Handle());
|
2017-05-16 00:41:45 +00:00
|
|
|
}
|
|
|
|
|
2020-12-01 01:47:46 +00:00
|
|
|
void App::RenderProcessExited(content::RenderProcessHost* host) {
|
|
|
|
ChildProcessDisconnected(host->GetID());
|
2017-05-16 00:41:45 +00:00
|
|
|
}
|
|
|
|
|
2020-07-07 18:00:45 +00:00
|
|
|
void App::ChildProcessLaunched(int process_type,
|
2020-12-01 01:47:46 +00:00
|
|
|
int pid,
|
2020-07-07 18:00:45 +00:00
|
|
|
base::ProcessHandle handle,
|
2020-10-19 11:55:47 +00:00
|
|
|
const std::string& service_name,
|
2020-07-07 18:00:45 +00:00
|
|
|
const std::string& name) {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2019-06-14 19:39:55 +00:00
|
|
|
auto metrics = base::ProcessMetrics::CreateProcessMetrics(
|
|
|
|
handle, content::BrowserChildProcessHost::GetPortProvider());
|
2017-05-16 00:41:45 +00:00
|
|
|
#else
|
2019-06-14 19:39:55 +00:00
|
|
|
auto metrics = base::ProcessMetrics::CreateProcessMetrics(handle);
|
2017-05-16 00:41:45 +00:00
|
|
|
#endif
|
2019-06-14 19:39:55 +00:00
|
|
|
app_metrics_[pid] = std::make_unique<electron::ProcessMetric>(
|
2020-10-19 11:55:47 +00:00
|
|
|
process_type, handle, std::move(metrics), service_name, name);
|
2017-05-16 00:41:45 +00:00
|
|
|
}
|
|
|
|
|
2020-12-01 01:47:46 +00:00
|
|
|
void App::ChildProcessDisconnected(int 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;
|
|
|
|
}
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if !BUILDFLAG(IS_MAC)
|
2019-09-06 05:52:54 +00:00
|
|
|
void App::SetAppLogsPath(gin_helper::ErrorThrower thrower,
|
2024-01-10 22:23:35 +00:00
|
|
|
std::optional<base::FilePath> custom_path) {
|
2019-08-19 22:16:00 +00:00
|
|
|
if (custom_path.has_value()) {
|
|
|
|
if (!custom_path->IsAbsolute()) {
|
2019-08-23 22:49:54 +00:00
|
|
|
thrower.ThrowError("Path must be absolute");
|
2019-04-19 05:04:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-04-21 19:28:01 +00:00
|
|
|
{
|
2022-11-17 19:59:23 +00:00
|
|
|
ScopedAllowBlockingForElectron allow_blocking;
|
2020-04-21 19:28:01 +00:00
|
|
|
base::PathService::Override(DIR_APP_LOGS, custom_path.value());
|
|
|
|
}
|
2019-04-19 05:04:58 +00:00
|
|
|
} else {
|
|
|
|
base::FilePath path;
|
2021-06-15 00:32:56 +00:00
|
|
|
if (base::PathService::Get(chrome::DIR_USER_DATA, &path)) {
|
2019-04-19 05:04:58 +00:00
|
|
|
path = path.Append(base::FilePath::FromUTF8Unsafe("logs"));
|
2020-04-21 19:28:01 +00:00
|
|
|
{
|
2022-11-17 19:59:23 +00:00
|
|
|
ScopedAllowBlockingForElectron allow_blocking;
|
2020-04-21 19:28:01 +00:00
|
|
|
base::PathService::Override(DIR_APP_LOGS, path);
|
|
|
|
}
|
2019-04-19 05:04:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-06-02 19:17:08 +00:00
|
|
|
// static
|
|
|
|
bool App::IsPackaged() {
|
2021-06-03 05:46:44 +00:00
|
|
|
auto env = base::Environment::Create();
|
|
|
|
if (env->HasVar("ELECTRON_FORCE_IS_PACKAGED"))
|
|
|
|
return true;
|
|
|
|
|
2021-06-02 19:17:08 +00:00
|
|
|
base::FilePath exe_path;
|
|
|
|
base::PathService::Get(base::FILE_EXE, &exe_path);
|
|
|
|
base::FilePath::StringType base_name =
|
|
|
|
base::ToLowerASCII(exe_path.BaseName().value());
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2021-06-02 19:17:08 +00:00
|
|
|
return base_name != FILE_PATH_LITERAL("electron.exe");
|
|
|
|
#else
|
|
|
|
return base_name != FILE_PATH_LITERAL("electron");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2019-09-06 05:52:54 +00:00
|
|
|
base::FilePath App::GetPath(gin_helper::ErrorThrower thrower,
|
2019-08-23 22:49:54 +00:00
|
|
|
const std::string& name) {
|
2014-08-12 15:01:56 +00:00
|
|
|
base::FilePath path;
|
2019-08-19 22:16:00 +00:00
|
|
|
|
2015-01-19 01:52:15 +00:00
|
|
|
int key = GetPathConstant(name);
|
2021-06-15 00:32:56 +00:00
|
|
|
if (key < 0 || !base::PathService::Get(key, &path))
|
2019-08-23 22:49:54 +00:00
|
|
|
thrower.ThrowError("Failed to get '" + name + "' path");
|
2019-08-19 22:16:00 +00:00
|
|
|
|
2015-01-19 01:11:27 +00:00
|
|
|
return path;
|
2014-08-12 15:01:56 +00:00
|
|
|
}
|
|
|
|
|
2019-09-06 05:52:54 +00:00
|
|
|
void App::SetPath(gin_helper::ErrorThrower thrower,
|
2015-01-19 04:24:58 +00:00
|
|
|
const std::string& name,
|
|
|
|
const base::FilePath& path) {
|
2016-04-21 05:37:29 +00:00
|
|
|
if (!path.IsAbsolute()) {
|
2019-08-23 22:49:54 +00:00
|
|
|
thrower.ThrowError("Path must be absolute");
|
2016-04-21 05:37:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-01-19 01:52:15 +00:00
|
|
|
int key = GetPathConstant(name);
|
2021-06-15 00:32:56 +00:00
|
|
|
if (key < 0 || !base::PathService::OverrideAndCreateIfNeeded(
|
|
|
|
key, path, /* is_absolute = */ true, /* create = */ false))
|
2019-08-23 22:49:54 +00:00
|
|
|
thrower.ThrowError("Failed to set path");
|
2015-01-19 01:52:15 +00:00
|
|
|
}
|
|
|
|
|
2014-09-18 11:12:24 +00:00
|
|
|
void App::SetDesktopName(const std::string& desktop_name) {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_LINUX)
|
2021-06-04 00:23:06 +00:00
|
|
|
auto 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() {
|
2017-12-16 09:21:29 +00:00
|
|
|
return g_browser_process->GetApplicationLocale();
|
2015-09-16 08:16:21 +00:00
|
|
|
}
|
|
|
|
|
2022-09-23 18:50:46 +00:00
|
|
|
std::string App::GetSystemLocale(gin_helper::ErrorThrower thrower) const {
|
|
|
|
if (!Browser::Get()->is_ready()) {
|
|
|
|
thrower.ThrowError(
|
|
|
|
"app.getSystemLocale() can only be called "
|
|
|
|
"after app is ready");
|
|
|
|
return std::string();
|
|
|
|
}
|
|
|
|
return static_cast<BrowserProcessImpl*>(g_browser_process)->GetSystemLocale();
|
|
|
|
}
|
|
|
|
|
2018-11-20 20:33:23 +00:00
|
|
|
std::string App::GetLocaleCountryCode() {
|
|
|
|
std::string region;
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2018-11-20 20:33:23 +00:00
|
|
|
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), ®ion);
|
|
|
|
}
|
2022-02-10 02:58:52 +00:00
|
|
|
#elif BUILDFLAG(IS_MAC)
|
2018-11-20 20:33:23 +00:00
|
|
|
CFLocaleRef locale = CFLocaleCopyCurrent();
|
|
|
|
CFStringRef value = CFStringRef(
|
|
|
|
static_cast<CFTypeRef>(CFLocaleGetValue(locale, kCFLocaleCountryCode)));
|
2022-01-03 21:54:58 +00:00
|
|
|
if (value != nil) {
|
|
|
|
char temporaryCString[3];
|
|
|
|
const CFIndex kCStringSize = sizeof(temporaryCString);
|
|
|
|
if (CFStringGetCString(value, temporaryCString, kCStringSize,
|
|
|
|
kCFStringEncodingUTF8)) {
|
|
|
|
region = temporaryCString;
|
|
|
|
}
|
|
|
|
}
|
2018-11-20 20:33:23 +00:00
|
|
|
#else
|
2019-09-16 22:12:00 +00:00
|
|
|
const char* locale_ptr = setlocale(LC_TIME, nullptr);
|
2018-11-20 20:33:23 +00:00
|
|
|
if (!locale_ptr)
|
2019-09-16 22:12:00 +00:00
|
|
|
locale_ptr = setlocale(LC_NUMERIC, nullptr);
|
2018-11-20 20:33:23 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2024-02-29 09:31:13 +00:00
|
|
|
void App::OnSecondInstance(base::CommandLine cmd,
|
2022-05-23 05:20:54 +00:00
|
|
|
const base::FilePath& cwd,
|
2024-04-15 17:32:48 +00:00
|
|
|
const std::vector<uint8_t> additional_data) {
|
2021-10-15 01:32:32 +00:00
|
|
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
v8::Local<v8::Value> data_value =
|
|
|
|
DeserializeV8Value(isolate, std::move(additional_data));
|
2022-05-23 05:20:54 +00:00
|
|
|
Emit("second-instance", cmd.argv(), cwd, data_value);
|
2018-05-07 15:29:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool App::HasSingleInstanceLock() const {
|
2018-01-03 09:59:12 +00:00
|
|
|
if (process_singleton_)
|
2018-05-07 15:29:18 +00:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-10-15 01:32:32 +00:00
|
|
|
bool App::RequestSingleInstanceLock(gin::Arguments* args) {
|
2018-05-07 15:29:18 +00:00
|
|
|
if (HasSingleInstanceLock())
|
|
|
|
return true;
|
2015-10-21 20:17:56 +00:00
|
|
|
|
2021-09-03 21:16:33 +00:00
|
|
|
std::string program_name = electron::Browser::Get()->GetName();
|
|
|
|
|
2018-01-03 09:59:12 +00:00
|
|
|
base::FilePath user_dir;
|
2021-06-15 00:32:56 +00:00
|
|
|
base::PathService::Get(chrome::DIR_USER_DATA, &user_dir);
|
2022-04-04 01:39:55 +00:00
|
|
|
// The user_dir may not have been created yet.
|
|
|
|
base::CreateDirectoryAndGetError(user_dir, nullptr);
|
2018-05-07 15:29:18 +00:00
|
|
|
|
2019-04-27 04:42:56 +00:00
|
|
|
auto cb = base::BindRepeating(&App::OnSecondInstance, base::Unretained(this));
|
2018-05-07 15:29:18 +00:00
|
|
|
|
2021-10-15 01:32:32 +00:00
|
|
|
blink::CloneableMessage additional_data_message;
|
|
|
|
args->GetNext(&additional_data_message);
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2021-09-03 21:16:33 +00:00
|
|
|
bool app_is_sandboxed =
|
|
|
|
IsSandboxEnabled(base::CommandLine::ForCurrentProcess());
|
|
|
|
process_singleton_ = std::make_unique<ProcessSingleton>(
|
2021-10-15 01:32:32 +00:00
|
|
|
program_name, user_dir, additional_data_message.encoded_message,
|
2022-05-23 05:20:54 +00:00
|
|
|
app_is_sandboxed, base::BindRepeating(NotificationCallbackWrapper, cb));
|
2021-09-03 21:16:33 +00:00
|
|
|
#else
|
2019-09-16 22:12:00 +00:00
|
|
|
process_singleton_ = std::make_unique<ProcessSingleton>(
|
2022-05-23 05:20:54 +00:00
|
|
|
user_dir, additional_data_message.encoded_message,
|
|
|
|
base::BindRepeating(NotificationCallbackWrapper, cb));
|
2021-09-03 21:16:33 +00:00
|
|
|
#endif
|
2015-10-20 01:02:54 +00:00
|
|
|
|
2018-01-03 09:59:12 +00:00
|
|
|
switch (process_singleton_->NotifyOtherProcessOrCreate()) {
|
2022-08-19 22:45:58 +00:00
|
|
|
case ProcessSingleton::NotifyResult::PROCESS_NONE:
|
|
|
|
if (content::BrowserThread::IsThreadInitialized(
|
|
|
|
content::BrowserThread::IO)) {
|
|
|
|
process_singleton_->StartWatching();
|
|
|
|
} else {
|
|
|
|
watch_singleton_socket_on_ready_ = true;
|
|
|
|
}
|
|
|
|
return true;
|
2015-10-19 23:21:03 +00:00
|
|
|
case ProcessSingleton::NotifyResult::LOCK_ERROR:
|
|
|
|
case ProcessSingleton::NotifyResult::PROFILE_IN_USE:
|
2017-12-11 07:55:49 +00:00
|
|
|
case ProcessSingleton::NotifyResult::PROCESS_NOTIFIED: {
|
2018-01-03 09:59:12 +00:00
|
|
|
process_singleton_.reset();
|
2018-05-07 15:29:18 +00:00
|
|
|
return false;
|
2017-12-11 07:55:49 +00:00
|
|
|
}
|
2015-10-19 23:21:03 +00:00
|
|
|
}
|
2015-10-19 21:43:04 +00:00
|
|
|
}
|
|
|
|
|
2018-05-07 15:29:18 +00:00
|
|
|
void App::ReleaseSingleInstanceLock() {
|
2018-01-03 09:59:12 +00:00
|
|
|
if (process_singleton_) {
|
|
|
|
process_singleton_->Cleanup();
|
|
|
|
process_singleton_.reset();
|
2016-05-26 18:07:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-28 23:43:43 +00:00
|
|
|
bool App::Relaunch(gin::Arguments* js_args) {
|
2016-06-02 12:49:29 +00:00
|
|
|
// Parse parameters.
|
|
|
|
bool override_argv = false;
|
|
|
|
base::FilePath exec_path;
|
|
|
|
relauncher::StringVector args;
|
|
|
|
|
2019-10-24 05:47:58 +00:00
|
|
|
gin_helper::Dictionary options;
|
2016-06-02 12:49:29 +00:00
|
|
|
if (js_args->GetNext(&options)) {
|
2022-08-08 08:12:06 +00:00
|
|
|
bool has_exec_path = options.Get("execPath", &exec_path);
|
|
|
|
bool has_args = options.Get("args", &args);
|
|
|
|
if (has_exec_path || has_args)
|
2016-06-02 12:49:29 +00:00
|
|
|
override_argv = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!override_argv) {
|
|
|
|
const relauncher::StringVector& argv =
|
|
|
|
electron::ElectronCommandLine::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, ¤t_exe_path);
|
2016-06-02 12:49:29 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-09-06 05:52:54 +00:00
|
|
|
void App::DisableHardwareAcceleration(gin_helper::ErrorThrower thrower) {
|
2016-06-06 11:19:55 +00:00
|
|
|
if (Browser::Get()->is_ready()) {
|
2019-08-23 22:49:54 +00:00
|
|
|
thrower.ThrowError(
|
2018-04-18 01:55:30 +00:00
|
|
|
"app.disableHardwareAcceleration() can only be called "
|
|
|
|
"before app is ready");
|
2016-06-06 11:19:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-04-13 23:39:26 +00:00
|
|
|
if (content::GpuDataManager::Initialized()) {
|
|
|
|
content::GpuDataManager::GetInstance()->DisableHardwareAcceleration();
|
|
|
|
} else {
|
|
|
|
disable_hw_acceleration_ = true;
|
|
|
|
}
|
2016-06-06 11:19:55 +00:00
|
|
|
}
|
|
|
|
|
2019-09-06 05:52:54 +00:00
|
|
|
void App::DisableDomainBlockingFor3DAPIs(gin_helper::ErrorThrower thrower) {
|
2017-07-13 22:27:03 +00:00
|
|
|
if (Browser::Get()->is_ready()) {
|
2019-08-23 22:49:54 +00:00
|
|
|
thrower.ThrowError(
|
2017-07-13 22:27:03 +00:00
|
|
|
"app.disableDomainBlockingFor3DAPIs() can only be called "
|
|
|
|
"before app is ready");
|
|
|
|
return;
|
|
|
|
}
|
2020-04-13 23:39:26 +00:00
|
|
|
if (content::GpuDataManager::Initialized()) {
|
|
|
|
content::GpuDataManagerImpl::GetInstance()
|
|
|
|
->DisableDomainBlockingFor3DAPIsForTesting();
|
|
|
|
} else {
|
|
|
|
disable_domain_blocking_for_3DAPIs_ = true;
|
|
|
|
}
|
2017-07-13 22:27:03 +00:00
|
|
|
}
|
|
|
|
|
2016-07-11 21:32:14 +00:00
|
|
|
bool App::IsAccessibilitySupportEnabled() {
|
2018-04-17 22:41:47 +00:00
|
|
|
auto* ax_state = content::BrowserAccessibilityState::GetInstance();
|
2016-07-11 21:04:56 +00:00
|
|
|
return ax_state->IsAccessibleBrowser();
|
|
|
|
}
|
|
|
|
|
2019-09-06 05:52:54 +00:00
|
|
|
void App::SetAccessibilitySupportEnabled(gin_helper::ErrorThrower thrower,
|
2019-08-23 22:49:54 +00:00
|
|
|
bool enabled) {
|
2019-01-04 15:20:06 +00:00
|
|
|
if (!Browser::Get()->is_ready()) {
|
2019-08-23 22:49:54 +00:00
|
|
|
thrower.ThrowError(
|
2019-01-04 15:20:06 +00:00
|
|
|
"app.setAccessibilitySupportEnabled() can only be called "
|
|
|
|
"after app is ready");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-17 22:41:47 +00:00
|
|
|
auto* ax_state = content::BrowserAccessibilityState::GetInstance();
|
2017-08-27 14:53:25 +00:00
|
|
|
if (enabled) {
|
2017-08-24 14:22:28 +00:00
|
|
|
ax_state->OnScreenReaderDetected();
|
|
|
|
} else {
|
|
|
|
ax_state->DisableAccessibility();
|
|
|
|
}
|
|
|
|
Browser::Get()->OnAccessibilitySupportChanged();
|
|
|
|
}
|
|
|
|
|
2024-03-22 13:00:21 +00:00
|
|
|
v8::Local<v8::Value> App::GetLoginItemSettings(gin::Arguments* args) {
|
|
|
|
LoginItemSettings options;
|
2017-01-30 22:01:40 +00:00
|
|
|
args->GetNext(&options);
|
|
|
|
return Browser::Get()->GetLoginItemSettings(options);
|
|
|
|
}
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(USE_NSS_CERTS)
|
2020-04-13 20:52:07 +00:00
|
|
|
void App::ImportCertificate(gin_helper::ErrorThrower thrower,
|
|
|
|
base::Value options,
|
|
|
|
net::CompletionOnceCallback callback) {
|
|
|
|
if (!options.is_dict()) {
|
|
|
|
thrower.ThrowTypeError("Expected options to be an object");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-18 05:11:31 +00:00
|
|
|
if (!certificate_manager_model_) {
|
2024-02-06 00:12:34 +00:00
|
|
|
CertificateManagerModel::Create(base::BindOnce(
|
|
|
|
&App::OnCertificateManagerModelCreated, base::Unretained(this),
|
|
|
|
std::move(options), std::move(callback)));
|
2016-04-18 05:11:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-13 20:52:07 +00:00
|
|
|
int rv =
|
|
|
|
ImportIntoCertStore(certificate_manager_model_.get(), std::move(options));
|
2019-04-20 17:20:37 +00:00
|
|
|
std::move(callback).Run(rv);
|
2016-04-18 05:11:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void App::OnCertificateManagerModelCreated(
|
2020-04-13 20:52:07 +00:00
|
|
|
base::Value options,
|
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 =
|
2020-04-13 20:52:07 +00:00
|
|
|
ImportIntoCertStore(certificate_manager_model_.get(), std::move(options));
|
2019-04-20 17:20:37 +00:00
|
|
|
std::move(callback).Run(rv);
|
2016-04-18 05:11:31 +00:00
|
|
|
}
|
2016-04-19 05:17:28 +00:00
|
|
|
#endif
|
2016-04-18 05:11:31 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-08-12 09:31:17 +00:00
|
|
|
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.";
|
|
|
|
}
|
|
|
|
|
2020-07-28 23:43:43 +00:00
|
|
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
2023-08-21 01:43:41 +00:00
|
|
|
auto dict = gin_helper::Dictionary::CreateEmpty(isolate);
|
2016-08-12 09:31:17 +00:00
|
|
|
dict.Set("minItems", min_items);
|
2020-07-28 23:43:43 +00:00
|
|
|
dict.Set("removedItems", gin::ConvertToV8(isolate, removed_items));
|
2016-08-12 09:31:17 +00:00
|
|
|
return dict.GetHandle();
|
|
|
|
}
|
|
|
|
|
|
|
|
JumpListResult App::SetJumpList(v8::Local<v8::Value> val,
|
2020-07-28 23:43:43 +00:00
|
|
|
gin::Arguments* args) {
|
2016-08-12 09:31:17 +00:00
|
|
|
std::vector<JumpListCategory> categories;
|
|
|
|
bool delete_jump_list = val->IsNull();
|
|
|
|
if (!delete_jump_list &&
|
2019-10-24 05:47:58 +00:00
|
|
|
!gin::ConvertFromV8(args->isolate(), val, &categories)) {
|
2020-07-28 23:43:43 +00:00
|
|
|
gin_helper::ErrorThrower(args->isolate())
|
2024-03-21 23:01:54 +00:00
|
|
|
.ThrowTypeError("Argument must be null or an array of categories");
|
2020-10-27 17:51:45 +00:00
|
|
|
return JumpListResult::kArgumentError;
|
2016-08-12 09:31:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
JumpList jump_list(Browser::Get()->GetAppUserModelID());
|
|
|
|
|
|
|
|
if (delete_jump_list) {
|
2020-10-27 17:51:45 +00:00
|
|
|
return jump_list.Delete() ? JumpListResult::kSuccess
|
|
|
|
: JumpListResult::kGenericError;
|
2016-08-12 09:31:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Start a transaction that updates the JumpList of this application.
|
|
|
|
if (!jump_list.Begin())
|
2020-10-27 17:51:45 +00:00
|
|
|
return JumpListResult::kGenericError;
|
2016-08-12 09:31:17 +00:00
|
|
|
|
|
|
|
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.
|
2020-10-27 17:51:45 +00:00
|
|
|
if (result == JumpListResult::kSuccess)
|
|
|
|
result = JumpListResult::kGenericError;
|
2016-08-12 09:31:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2022-02-10 02:58:52 +00:00
|
|
|
#endif // BUILDFLAG(IS_WIN)
|
2016-08-12 09:31:17 +00:00
|
|
|
|
2018-12-05 16:50:12 +00:00
|
|
|
v8::Local<v8::Promise> App::GetFileIcon(const base::FilePath& path,
|
2020-07-28 23:43:43 +00:00
|
|
|
gin::Arguments* args) {
|
|
|
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
|
|
|
gin_helper::Promise<gfx::Image> promise(isolate);
|
2019-02-21 12:32:44 +00:00
|
|
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
2016-11-05 18:55:23 +00:00
|
|
|
base::FilePath normalized_path = path.NormalizePathSeparators();
|
|
|
|
|
2018-12-05 16:50:12 +00:00
|
|
|
IconLoader::IconSize icon_size;
|
2019-10-24 05:47:58 +00:00
|
|
|
gin_helper::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
|
|
|
}
|
|
|
|
|
2018-10-05 19:12:53 +00:00
|
|
|
auto* icon_manager = ElectronBrowserMainParts::Get()->GetIconManager();
|
2017-02-17 08:33:46 +00:00
|
|
|
gfx::Image* icon =
|
2021-04-27 21:27:34 +00:00
|
|
|
icon_manager->LookupIconFromFilepath(normalized_path, icon_size, 1.0f);
|
2016-11-02 18:57:16 +00:00
|
|
|
if (icon) {
|
2019-11-01 06:10:32 +00:00
|
|
|
promise.Resolve(*icon);
|
2016-11-02 18:57:16 +00:00
|
|
|
} else {
|
2019-02-21 12:32:44 +00:00
|
|
|
icon_manager->LoadIcon(
|
2021-04-27 21:27:34 +00:00
|
|
|
normalized_path, icon_size, 1.0f,
|
2019-02-21 12:32:44 +00:00
|
|
|
base::BindOnce(&OnIconDataAvailable, std::move(promise)),
|
|
|
|
&cancelable_task_tracker_);
|
2016-11-02 18:57:16 +00:00
|
|
|
}
|
2019-02-21 12:32:44 +00:00
|
|
|
return handle;
|
2016-11-02 18:57:16 +00:00
|
|
|
}
|
|
|
|
|
2019-10-24 05:47:58 +00:00
|
|
|
std::vector<gin_helper::Dictionary> App::GetAppMetrics(v8::Isolate* isolate) {
|
|
|
|
std::vector<gin_helper::Dictionary> result;
|
2019-01-25 14:39:32 +00:00
|
|
|
result.reserve(app_metrics_.size());
|
2017-05-16 00:41:45 +00:00
|
|
|
int processor_count = base::SysInfo::NumberOfProcessors();
|
2017-04-17 11:59:16 +00:00
|
|
|
|
2017-05-16 00:41:45 +00:00
|
|
|
for (const auto& process_metric : app_metrics_) {
|
2023-08-21 01:43:41 +00:00
|
|
|
auto pid_dict = gin_helper::Dictionary::CreateEmpty(isolate);
|
|
|
|
auto cpu_dict = gin_helper::Dictionary::CreateEmpty(isolate);
|
2017-04-27 04:04:53 +00:00
|
|
|
|
2024-06-11 14:38:03 +00:00
|
|
|
// Default usage percentage to 0 for compatibility
|
|
|
|
double usagePercent = 0;
|
|
|
|
if (auto usage = process_metric.second->metrics->GetCumulativeCPUUsage();
|
|
|
|
usage.has_value()) {
|
|
|
|
cpu_dict.Set("cumulativeCPUUsage", usage->InSecondsF());
|
|
|
|
usagePercent =
|
|
|
|
process_metric.second->metrics->GetPlatformIndependentCPUUsage(
|
|
|
|
*usage);
|
|
|
|
}
|
|
|
|
|
|
|
|
cpu_dict.Set("percentCPUUsage", usagePercent / processor_count);
|
2017-10-27 21:21:46 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if !BUILDFLAG(IS_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());
|
2017-10-27 21:21:46 +00:00
|
|
|
#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);
|
2019-06-14 19:39:55 +00:00
|
|
|
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));
|
2023-11-01 14:02:12 +00:00
|
|
|
pid_dict.Set("creationTime", process_metric.second->process.CreationTime()
|
|
|
|
.InMillisecondsFSinceUnixEpoch());
|
2019-06-14 19:39:55 +00:00
|
|
|
|
2020-10-19 11:55:47 +00:00
|
|
|
if (!process_metric.second->service_name.empty()) {
|
|
|
|
pid_dict.Set("serviceName", process_metric.second->service_name);
|
|
|
|
}
|
|
|
|
|
2020-07-07 18:00:45 +00:00
|
|
|
if (!process_metric.second->name.empty()) {
|
|
|
|
pid_dict.Set("name", process_metric.second->name);
|
|
|
|
}
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if !BUILDFLAG(IS_LINUX)
|
2019-07-23 20:41:59 +00:00
|
|
|
auto memory_info = process_metric.second->GetMemoryInfo();
|
|
|
|
|
2023-08-21 01:43:41 +00:00
|
|
|
auto memory_dict = gin_helper::Dictionary::CreateEmpty(isolate);
|
2019-07-23 20:41:59 +00:00
|
|
|
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));
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2019-07-23 20:41:59 +00:00
|
|
|
memory_dict.Set("privateBytes",
|
|
|
|
static_cast<double>(memory_info.private_bytes >> 10));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
pid_dict.Set("memory", memory_dict);
|
|
|
|
#endif
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2019-06-14 19:39:55 +00:00
|
|
|
pid_dict.Set("sandboxed", process_metric.second->IsSandboxed());
|
2022-02-10 02:58:52 +00:00
|
|
|
#elif BUILDFLAG(IS_WIN)
|
2019-06-14 19:39:55 +00:00
|
|
|
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);
|
2017-04-17 11:59:16 +00:00
|
|
|
}
|
|
|
|
|
2017-04-28 04:07:35 +00:00
|
|
|
return result;
|
2017-04-17 11:59:16 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 20:00:55 +00:00
|
|
|
v8::Local<v8::Value> App::GetGPUFeatureStatus(v8::Isolate* isolate) {
|
2021-05-14 01:21:36 +00:00
|
|
|
return gin::ConvertToV8(isolate, content::GetFeatureStatus());
|
2017-05-30 17:06:08 +00:00
|
|
|
}
|
|
|
|
|
2018-09-27 14:59:23 +00:00
|
|
|
v8::Local<v8::Promise> App::GetGPUInfo(v8::Isolate* isolate,
|
|
|
|
const std::string& info_type) {
|
|
|
|
auto* const gpu_data_manager = content::GpuDataManagerImpl::GetInstance();
|
2022-06-28 16:52:59 +00:00
|
|
|
gin_helper::Promise<base::Value> promise(isolate);
|
2019-02-21 12:32:44 +00:00
|
|
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
2018-10-02 01:34:52 +00:00
|
|
|
if (info_type != "basic" && info_type != "complete") {
|
2019-02-21 12:32:44 +00:00
|
|
|
promise.RejectWithErrorMessage(
|
2018-10-02 01:34:52 +00:00
|
|
|
"Invalid info type. Use 'basic' or 'complete'");
|
2019-02-21 12:32:44 +00:00
|
|
|
return handle;
|
2018-10-02 01:34:52 +00:00
|
|
|
}
|
|
|
|
std::string reason;
|
|
|
|
if (!gpu_data_manager->GpuAccessAllowed(&reason)) {
|
2019-02-21 12:32:44 +00:00
|
|
|
promise.RejectWithErrorMessage("GPU access not allowed. Reason: " + reason);
|
|
|
|
return handle;
|
2018-09-27 14:59:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto* const info_mgr = GPUInfoManager::GetInstance();
|
|
|
|
if (info_type == "complete") {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)
|
2019-02-21 12:32:44 +00:00
|
|
|
info_mgr->FetchCompleteInfo(std::move(promise));
|
2018-10-02 01:34:52 +00:00
|
|
|
#else
|
2019-02-21 12:32:44 +00:00
|
|
|
info_mgr->FetchBasicInfo(std::move(promise));
|
2018-10-02 01:34:52 +00:00
|
|
|
#endif
|
2018-09-27 14:59:23 +00:00
|
|
|
} else /* (info_type == "basic") */ {
|
2019-02-21 12:32:44 +00:00
|
|
|
info_mgr->FetchBasicInfo(std::move(promise));
|
2018-09-27 14:59:23 +00:00
|
|
|
}
|
2019-02-21 12:32:44 +00:00
|
|
|
return handle;
|
2018-09-27 14:59:23 +00:00
|
|
|
}
|
|
|
|
|
2018-10-10 04:32:09 +00:00
|
|
|
static void RemoveNoSandboxSwitch(base::CommandLine* command_line) {
|
2020-07-14 01:13:34 +00:00
|
|
|
if (command_line->HasSwitch(sandbox::policy::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
|
|
|
}
|
|
|
|
|
2019-09-06 05:52:54 +00:00
|
|
|
void App::EnableSandbox(gin_helper::ErrorThrower thrower) {
|
2018-10-10 04:32:09 +00:00
|
|
|
if (Browser::Get()->is_ready()) {
|
2019-08-23 22:49:54 +00:00
|
|
|
thrower.ThrowError(
|
2018-10-10 04:32:09 +00:00
|
|
|
"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);
|
|
|
|
}
|
|
|
|
|
2024-02-22 17:08:25 +00:00
|
|
|
v8::Local<v8::Promise> App::SetProxy(gin::Arguments* args) {
|
|
|
|
v8::Isolate* isolate = args->isolate();
|
|
|
|
gin_helper::Promise<void> promise(isolate);
|
|
|
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
|
|
|
|
|
|
|
gin_helper::Dictionary options;
|
|
|
|
args->GetNext(&options);
|
|
|
|
|
|
|
|
if (!Browser::Get()->is_ready()) {
|
|
|
|
promise.RejectWithErrorMessage(
|
|
|
|
"app.setProxy() can only be called after app is ready.");
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!g_browser_process->local_state()) {
|
|
|
|
promise.RejectWithErrorMessage(
|
|
|
|
"app.setProxy() failed due to internal error.");
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string mode, proxy_rules, bypass_list, pac_url;
|
|
|
|
|
|
|
|
options.Get("pacScript", &pac_url);
|
|
|
|
options.Get("proxyRules", &proxy_rules);
|
|
|
|
options.Get("proxyBypassRules", &bypass_list);
|
|
|
|
|
|
|
|
ProxyPrefs::ProxyMode proxy_mode = ProxyPrefs::MODE_FIXED_SERVERS;
|
|
|
|
if (!options.Get("mode", &mode)) {
|
|
|
|
// pacScript takes precedence over proxyRules.
|
|
|
|
if (!pac_url.empty()) {
|
|
|
|
proxy_mode = ProxyPrefs::MODE_PAC_SCRIPT;
|
|
|
|
}
|
|
|
|
} else if (!ProxyPrefs::StringToProxyMode(mode, &proxy_mode)) {
|
|
|
|
promise.RejectWithErrorMessage(
|
|
|
|
"Invalid mode, must be one of direct, auto_detect, pac_script, "
|
|
|
|
"fixed_servers or system");
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
base::Value::Dict proxy_config;
|
|
|
|
switch (proxy_mode) {
|
|
|
|
case ProxyPrefs::MODE_DIRECT:
|
|
|
|
proxy_config = ProxyConfigDictionary::CreateDirect();
|
|
|
|
break;
|
|
|
|
case ProxyPrefs::MODE_SYSTEM:
|
|
|
|
proxy_config = ProxyConfigDictionary::CreateSystem();
|
|
|
|
break;
|
|
|
|
case ProxyPrefs::MODE_AUTO_DETECT:
|
|
|
|
proxy_config = ProxyConfigDictionary::CreateAutoDetect();
|
|
|
|
break;
|
|
|
|
case ProxyPrefs::MODE_PAC_SCRIPT:
|
|
|
|
proxy_config = ProxyConfigDictionary::CreatePacScript(pac_url, true);
|
|
|
|
break;
|
|
|
|
case ProxyPrefs::MODE_FIXED_SERVERS:
|
|
|
|
proxy_config =
|
|
|
|
ProxyConfigDictionary::CreateFixedServers(proxy_rules, bypass_list);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NOTIMPLEMENTED();
|
|
|
|
}
|
|
|
|
|
|
|
|
static_cast<BrowserProcessImpl*>(g_browser_process)
|
|
|
|
->in_memory_pref_store()
|
|
|
|
->SetValue(proxy_config::prefs::kProxy,
|
|
|
|
base::Value{std::move(proxy_config)},
|
|
|
|
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
|
|
|
|
|
|
|
|
g_browser_process->system_network_context_manager()
|
|
|
|
->GetContext()
|
|
|
|
->ForceReloadProxyConfig(base::BindOnce(
|
|
|
|
gin_helper::Promise<void>::ResolvePromise, std::move(promise)));
|
|
|
|
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
v8::Local<v8::Promise> App::ResolveProxy(gin::Arguments* args) {
|
|
|
|
v8::Isolate* isolate = args->isolate();
|
|
|
|
gin_helper::Promise<std::string> promise(isolate);
|
|
|
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
|
|
|
|
|
|
|
GURL url;
|
|
|
|
args->GetNext(&url);
|
|
|
|
|
|
|
|
static_cast<BrowserProcessImpl*>(g_browser_process)
|
|
|
|
->GetResolveProxyHelper()
|
|
|
|
->ResolveProxy(
|
|
|
|
url, base::BindOnce(gin_helper::Promise<std::string>::ResolvePromise,
|
|
|
|
std::move(promise)));
|
|
|
|
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
2019-05-01 23:34:42 +00:00
|
|
|
void App::SetUserAgentFallback(const std::string& user_agent) {
|
|
|
|
ElectronBrowserClient::Get()->SetUserAgent(user_agent);
|
|
|
|
}
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2021-06-02 07:16:33 +00:00
|
|
|
bool App::IsRunningUnderARM64Translation() const {
|
2023-09-20 20:15:19 +00:00
|
|
|
return base::win::OSInfo::IsRunningEmulatedOnArm64();
|
2021-06-02 07:16:33 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-05-01 23:34:42 +00:00
|
|
|
std::string App::GetUserAgentFallback() {
|
|
|
|
return ElectronBrowserClient::Get()->GetUserAgent();
|
|
|
|
}
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2019-09-06 05:52:54 +00:00
|
|
|
bool App::MoveToApplicationsFolder(gin_helper::ErrorThrower thrower,
|
2019-10-24 05:47:58 +00:00
|
|
|
gin::Arguments* args) {
|
|
|
|
return ElectronBundleMover::Move(thrower, args);
|
2017-08-31 14:37:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool App::IsInApplicationsFolder() {
|
2019-09-06 05:52:54 +00:00
|
|
|
return ElectronBundleMover::IsCurrentAppInApplicationsFolder();
|
2017-08-31 14:37:12 +00:00
|
|
|
}
|
2019-02-14 22:29:20 +00:00
|
|
|
|
2020-07-28 23:43:43 +00:00
|
|
|
int DockBounce(gin::Arguments* args) {
|
2019-02-14 22:29:20 +00:00
|
|
|
int request_id = -1;
|
2019-07-31 15:20:45 +00:00
|
|
|
std::string type = "informational";
|
|
|
|
args->GetNext(&type);
|
|
|
|
|
2019-02-14 22:29:20 +00:00
|
|
|
if (type == "critical")
|
2020-10-27 17:51:45 +00:00
|
|
|
request_id = Browser::Get()->DockBounce(Browser::BounceType::kCritical);
|
2019-02-14 22:29:20 +00:00
|
|
|
else if (type == "informational")
|
2020-10-27 17:51:45 +00:00
|
|
|
request_id =
|
|
|
|
Browser::Get()->DockBounce(Browser::BounceType::kInformational);
|
2019-02-14 22:29:20 +00:00
|
|
|
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());
|
2023-08-21 01:43:41 +00:00
|
|
|
auto dock_obj = gin_helper::Dictionary::CreateEmpty(isolate);
|
2019-02-14 22:29:20 +00:00
|
|
|
dock_obj.SetMethod("bounce", &DockBounce);
|
2019-04-27 04:42:56 +00:00
|
|
|
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));
|
2019-02-14 22:29:20 +00:00
|
|
|
dock_obj.SetMethod("isVisible",
|
2019-04-27 04:42:56 +00:00
|
|
|
base::BindRepeating(&Browser::DockIsVisible, browser));
|
2019-02-14 22:29:20 +00:00
|
|
|
dock_obj.SetMethod("setMenu", &DockSetMenu);
|
2019-04-27 04:42:56 +00:00
|
|
|
dock_obj.SetMethod("setIcon",
|
|
|
|
base::BindRepeating(&Browser::DockSetIcon, browser));
|
2019-02-14 22:29:20 +00:00
|
|
|
|
|
|
|
dock_.Reset(isolate, dock_obj.GetHandle());
|
|
|
|
}
|
|
|
|
return v8::Local<v8::Value>::New(isolate, dock_);
|
|
|
|
}
|
2017-08-31 14:37:12 +00:00
|
|
|
#endif
|
|
|
|
|
2021-08-31 18:55:30 +00:00
|
|
|
void ConfigureHostResolver(v8::Isolate* isolate,
|
|
|
|
const gin_helper::Dictionary& opts) {
|
|
|
|
gin_helper::ErrorThrower thrower(isolate);
|
2022-03-08 00:52:40 +00:00
|
|
|
if (!Browser::Get()->is_ready()) {
|
|
|
|
thrower.ThrowError(
|
|
|
|
"configureHostResolver cannot be called before the app is ready");
|
|
|
|
return;
|
|
|
|
}
|
2021-08-31 18:55:30 +00:00
|
|
|
net::SecureDnsMode secure_dns_mode = net::SecureDnsMode::kOff;
|
|
|
|
std::string default_doh_templates;
|
2022-02-25 18:17:35 +00:00
|
|
|
net::DnsOverHttpsConfig doh_config;
|
2021-08-31 18:55:30 +00:00
|
|
|
if (!default_doh_templates.empty() &&
|
|
|
|
secure_dns_mode != net::SecureDnsMode::kOff) {
|
2022-02-25 18:17:35 +00:00
|
|
|
auto maybe_doh_config =
|
|
|
|
net::DnsOverHttpsConfig::FromString(default_doh_templates);
|
|
|
|
if (maybe_doh_config.has_value())
|
|
|
|
doh_config = maybe_doh_config.value();
|
2021-08-31 18:55:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool enable_built_in_resolver =
|
2024-01-31 23:04:13 +00:00
|
|
|
base::FeatureList::IsEnabled(net::features::kAsyncDns);
|
2021-08-31 18:55:30 +00:00
|
|
|
bool additional_dns_query_types_enabled = true;
|
|
|
|
|
|
|
|
if (opts.Has("enableBuiltInResolver") &&
|
|
|
|
!opts.Get("enableBuiltInResolver", &enable_built_in_resolver)) {
|
|
|
|
thrower.ThrowTypeError("enableBuiltInResolver must be a boolean");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opts.Has("secureDnsMode") &&
|
|
|
|
!opts.Get("secureDnsMode", &secure_dns_mode)) {
|
|
|
|
thrower.ThrowTypeError(
|
|
|
|
"secureDnsMode must be one of: off, automatic, secure");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> secure_dns_server_strings;
|
|
|
|
if (opts.Has("secureDnsServers")) {
|
|
|
|
if (!opts.Get("secureDnsServers", &secure_dns_server_strings)) {
|
|
|
|
thrower.ThrowTypeError("secureDnsServers must be an array of strings");
|
|
|
|
return;
|
|
|
|
}
|
2022-02-25 18:17:35 +00:00
|
|
|
|
|
|
|
// Validate individual server templates prior to batch-assigning to
|
|
|
|
// doh_config.
|
2022-05-17 16:48:40 +00:00
|
|
|
std::vector<net::DnsOverHttpsServerConfig> servers;
|
2021-08-31 18:55:30 +00:00
|
|
|
for (const std::string& server_template : secure_dns_server_strings) {
|
2024-01-10 22:23:35 +00:00
|
|
|
std::optional<net::DnsOverHttpsServerConfig> server_config =
|
2022-05-17 16:48:40 +00:00
|
|
|
net::DnsOverHttpsServerConfig::FromString(server_template);
|
2022-02-25 18:17:35 +00:00
|
|
|
if (!server_config.has_value()) {
|
2021-08-31 18:55:30 +00:00
|
|
|
thrower.ThrowTypeError(std::string("not a valid DoH template: ") +
|
|
|
|
server_template);
|
|
|
|
return;
|
|
|
|
}
|
2022-05-17 16:48:40 +00:00
|
|
|
servers.push_back(*server_config);
|
2021-08-31 18:55:30 +00:00
|
|
|
}
|
2022-05-17 16:48:40 +00:00
|
|
|
doh_config = net::DnsOverHttpsConfig(std::move(servers));
|
2021-08-31 18:55:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (opts.Has("enableAdditionalDnsQueryTypes") &&
|
|
|
|
!opts.Get("enableAdditionalDnsQueryTypes",
|
|
|
|
&additional_dns_query_types_enabled)) {
|
|
|
|
thrower.ThrowTypeError("enableAdditionalDnsQueryTypes must be a boolean");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Configure the stub resolver. This must be done after the system
|
|
|
|
// NetworkContext is created, but before anything has the chance to use it.
|
|
|
|
content::GetNetworkService()->ConfigureStubHostResolver(
|
2022-02-25 18:17:35 +00:00
|
|
|
enable_built_in_resolver, secure_dns_mode, doh_config,
|
|
|
|
additional_dns_query_types_enabled);
|
2021-08-31 18:55:30 +00:00
|
|
|
}
|
|
|
|
|
2020-05-19 17:18:12 +00:00
|
|
|
// static
|
|
|
|
App* App::Get() {
|
2020-07-28 23:43:43 +00:00
|
|
|
static base::NoDestructor<App> app;
|
2020-05-19 17:18:12 +00:00
|
|
|
return app.get();
|
|
|
|
}
|
|
|
|
|
2016-04-25 01:17:54 +00:00
|
|
|
// static
|
2019-10-24 05:47:58 +00:00
|
|
|
gin::Handle<App> App::Create(v8::Isolate* isolate) {
|
2020-05-19 17:18:12 +00:00
|
|
|
return gin::CreateHandle(isolate, Get());
|
2016-04-25 01:17:54 +00:00
|
|
|
}
|
|
|
|
|
2020-07-28 23:43:43 +00:00
|
|
|
gin::ObjectTemplateBuilder App::GetObjectTemplateBuilder(v8::Isolate* isolate) {
|
2014-10-30 14:27:29 +00:00
|
|
|
auto browser = base::Unretained(Browser::Get());
|
2020-07-28 23:43:43 +00:00
|
|
|
return gin_helper::EventEmitterMixin<App>::GetObjectTemplateBuilder(isolate)
|
2019-04-27 04:42:56 +00:00
|
|
|
.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))
|
2020-03-18 17:06:41 +00:00
|
|
|
.SetMethod("getName", base::BindRepeating(&Browser::GetName, browser))
|
|
|
|
.SetMethod("setName", base::BindRepeating(&Browser::SetName, browser))
|
2019-04-27 04:42:56 +00:00
|
|
|
.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",
|
2019-04-27 04:42:56 +00:00
|
|
|
base::BindRepeating(&Browser::AddRecentDocument, browser))
|
2014-11-17 08:13:47 +00:00
|
|
|
.SetMethod("clearRecentDocuments",
|
2019-04-27 04:42:56 +00:00
|
|
|
base::BindRepeating(&Browser::ClearRecentDocuments, browser))
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2015-11-03 07:09:31 +00:00
|
|
|
.SetMethod("setAppUserModelId",
|
2019-04-30 00:40:39 +00:00
|
|
|
base::BindRepeating(&Browser::SetAppUserModelID, browser))
|
2021-03-24 17:55:32 +00:00
|
|
|
#endif
|
2019-04-27 04:42:56 +00:00
|
|
|
.SetMethod(
|
|
|
|
"isDefaultProtocolClient",
|
|
|
|
base::BindRepeating(&Browser::IsDefaultProtocolClient, browser))
|
|
|
|
.SetMethod(
|
|
|
|
"setAsDefaultProtocolClient",
|
|
|
|
base::BindRepeating(&Browser::SetAsDefaultProtocolClient, browser))
|
|
|
|
.SetMethod(
|
|
|
|
"removeAsDefaultProtocolClient",
|
|
|
|
base::BindRepeating(&Browser::RemoveAsDefaultProtocolClient, browser))
|
2022-02-10 02:58:52 +00:00
|
|
|
#if !BUILDFLAG(IS_LINUX)
|
2020-06-30 19:22:30 +00:00
|
|
|
.SetMethod(
|
|
|
|
"getApplicationInfoForProtocol",
|
|
|
|
base::BindRepeating(&Browser::GetApplicationInfoForProtocol, browser))
|
|
|
|
#endif
|
2019-11-07 01:50:33 +00:00
|
|
|
.SetMethod(
|
|
|
|
"getApplicationNameForProtocol",
|
|
|
|
base::BindRepeating(&Browser::GetApplicationNameForProtocol, browser))
|
2020-03-18 17:06:41 +00:00
|
|
|
.SetMethod("setBadgeCount",
|
2019-04-27 04:42:56 +00:00
|
|
|
base::BindRepeating(&Browser::SetBadgeCount, browser))
|
2020-03-18 17:06:41 +00:00
|
|
|
.SetMethod("getBadgeCount",
|
2024-02-09 09:29:14 +00:00
|
|
|
base::BindRepeating(&Browser::badge_count, browser))
|
2017-01-30 22:01:40 +00:00
|
|
|
.SetMethod("getLoginItemSettings", &App::GetLoginItemSettings)
|
2016-07-11 17:57:53 +00:00
|
|
|
.SetMethod("setLoginItemSettings",
|
2019-04-27 04:42:56 +00:00
|
|
|
base::BindRepeating(&Browser::SetLoginItemSettings, browser))
|
2019-03-14 20:39:52 +00:00
|
|
|
.SetMethod("isEmojiPanelSupported",
|
2019-04-27 04:42:56 +00:00
|
|
|
base::BindRepeating(&Browser::IsEmojiPanelSupported, browser))
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2019-04-27 04:42:56 +00:00
|
|
|
.SetMethod("hide", base::BindRepeating(&Browser::Hide, browser))
|
2022-03-30 01:34:07 +00:00
|
|
|
.SetMethod("isHidden", base::BindRepeating(&Browser::IsHidden, browser))
|
2019-04-27 04:42:56 +00:00
|
|
|
.SetMethod("show", base::BindRepeating(&Browser::Show, browser))
|
2016-04-30 05:05:36 +00:00
|
|
|
.SetMethod("setUserActivity",
|
2019-04-27 04:42:56 +00:00
|
|
|
base::BindRepeating(&Browser::SetUserActivity, browser))
|
2016-07-07 21:29:43 +00:00
|
|
|
.SetMethod("getCurrentActivityType",
|
2019-04-27 04:42:56 +00:00
|
|
|
base::BindRepeating(&Browser::GetCurrentActivityType, browser))
|
|
|
|
.SetMethod(
|
|
|
|
"invalidateCurrentActivity",
|
|
|
|
base::BindRepeating(&Browser::InvalidateCurrentActivity, browser))
|
2019-06-07 05:16:03 +00:00
|
|
|
.SetMethod("resignCurrentActivity",
|
|
|
|
base::BindRepeating(&Browser::ResignCurrentActivity, browser))
|
2017-06-26 19:14:44 +00:00
|
|
|
.SetMethod("updateCurrentActivity",
|
2019-04-27 04:42:56 +00:00
|
|
|
base::BindRepeating(&Browser::UpdateCurrentActivity, browser))
|
2018-11-13 22:12:24 +00:00
|
|
|
.SetMethod("moveToApplicationsFolder", &App::MoveToApplicationsFolder)
|
|
|
|
.SetMethod("isInApplicationsFolder", &App::IsInApplicationsFolder)
|
2020-02-05 19:12:25 +00:00
|
|
|
.SetMethod("setActivationPolicy", &App::SetActivationPolicy)
|
2018-11-13 22:12:24 +00:00
|
|
|
#endif
|
2016-10-10 20:30:58 +00:00
|
|
|
.SetMethod("setAboutPanelOptions",
|
2019-04-27 04:42:56 +00:00
|
|
|
base::BindRepeating(&Browser::SetAboutPanelOptions, browser))
|
2018-11-12 03:52:27 +00:00
|
|
|
.SetMethod("showAboutPanel",
|
2019-04-27 04:42:56 +00:00
|
|
|
base::BindRepeating(&Browser::ShowAboutPanel, browser))
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2020-05-21 15:53:44 +00:00
|
|
|
.SetMethod(
|
|
|
|
"isSecureKeyboardEntryEnabled",
|
|
|
|
base::BindRepeating(&Browser::IsSecureKeyboardEntryEnabled, browser))
|
|
|
|
.SetMethod(
|
|
|
|
"setSecureKeyboardEntryEnabled",
|
|
|
|
base::BindRepeating(&Browser::SetSecureKeyboardEntryEnabled, browser))
|
|
|
|
#endif
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN)
|
2019-03-14 20:39:52 +00:00
|
|
|
.SetMethod("showEmojiPanel",
|
2019-04-27 04:42:56 +00:00
|
|
|
base::BindRepeating(&Browser::ShowEmojiPanel, browser))
|
2019-03-14 20:39:52 +00:00
|
|
|
#endif
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2019-04-27 04:42:56 +00:00
|
|
|
.SetMethod("setUserTasks",
|
|
|
|
base::BindRepeating(&Browser::SetUserTasks, browser))
|
2016-08-12 09:31:17 +00:00
|
|
|
.SetMethod("getJumpListSettings", &App::GetJumpListSettings)
|
|
|
|
.SetMethod("setJumpList", &App::SetJumpList)
|
2016-07-01 08:39:01 +00:00
|
|
|
#endif
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_LINUX)
|
2016-07-01 08:39:01 +00:00
|
|
|
.SetMethod("isUnityRunning",
|
2019-04-27 04:42:56 +00:00
|
|
|
base::BindRepeating(&Browser::IsUnityRunning, browser))
|
2014-11-17 09:19:41 +00:00
|
|
|
#endif
|
2021-06-02 19:17:08 +00:00
|
|
|
.SetProperty("isPackaged", &App::IsPackaged)
|
2017-04-04 00:36:01 +00:00
|
|
|
.SetMethod("setAppPath", &App::SetAppPath)
|
|
|
|
.SetMethod("getAppPath", &App::GetAppPath)
|
2015-01-19 01:52:15 +00:00
|
|
|
.SetMethod("setPath", &App::SetPath)
|
|
|
|
.SetMethod("getPath", &App::GetPath)
|
2019-04-19 05:04:58 +00:00
|
|
|
.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)
|
2022-11-09 15:50:43 +00:00
|
|
|
.SetMethod("getPreferredSystemLanguages", &GetPreferredLanguages)
|
2022-09-23 18:50:46 +00:00
|
|
|
.SetMethod("getSystemLocale", &App::GetSystemLocale)
|
2018-11-20 20:33:23 +00:00
|
|
|
.SetMethod("getLocaleCountryCode", &App::GetLocaleCountryCode)
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(USE_NSS_CERTS)
|
2016-04-20 03:15:49 +00:00
|
|
|
.SetMethod("importCertificate", &App::ImportCertificate)
|
2016-04-18 15:35:33 +00:00
|
|
|
#endif
|
2018-05-07 15:29:18 +00:00
|
|
|
.SetMethod("hasSingleInstanceLock", &App::HasSingleInstanceLock)
|
|
|
|
.SetMethod("requestSingleInstanceLock", &App::RequestSingleInstanceLock)
|
|
|
|
.SetMethod("releaseSingleInstanceLock", &App::ReleaseSingleInstanceLock)
|
2016-06-06 11:19:55 +00:00
|
|
|
.SetMethod("relaunch", &App::Relaunch)
|
2020-03-18 17:06:41 +00:00
|
|
|
.SetMethod("isAccessibilitySupportEnabled",
|
2016-07-11 21:32:14 +00:00
|
|
|
&App::IsAccessibilitySupportEnabled)
|
2020-03-18 17:06:41 +00:00
|
|
|
.SetMethod("setAccessibilitySupportEnabled",
|
2017-08-24 14:22:28 +00:00
|
|
|
&App::SetAccessibilitySupportEnabled)
|
2016-06-06 11:19:55 +00:00
|
|
|
.SetMethod("disableHardwareAcceleration",
|
2016-11-02 18:57:16 +00:00
|
|
|
&App::DisableHardwareAcceleration)
|
2017-07-13 22:27:03 +00:00
|
|
|
.SetMethod("disableDomainBlockingFor3DAPIs",
|
|
|
|
&App::DisableDomainBlockingFor3DAPIs)
|
2017-04-17 11:59:16 +00:00
|
|
|
.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)
|
2018-09-27 14:59:23 +00:00
|
|
|
.SetMethod("getGPUInfo", &App::GetGPUInfo)
|
2022-11-14 20:46:52 +00:00
|
|
|
#if IS_MAS_BUILD()
|
2018-02-12 18:25:06 +00:00
|
|
|
.SetMethod("startAccessingSecurityScopedResource",
|
|
|
|
&App::StartAccessingSecurityScopedResource)
|
2019-02-14 22:29:20 +00:00
|
|
|
#endif
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2019-02-14 22:29:20 +00:00
|
|
|
.SetProperty("dock", &App::GetDockAPI)
|
2021-06-02 07:16:33 +00:00
|
|
|
#endif
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN)
|
2021-06-02 07:16:33 +00:00
|
|
|
.SetProperty("runningUnderARM64Translation",
|
|
|
|
&App::IsRunningUnderARM64Translation)
|
2018-04-18 01:55:30 +00:00
|
|
|
#endif
|
2019-05-01 23:34:42 +00:00
|
|
|
.SetProperty("userAgentFallback", &App::GetUserAgentFallback,
|
|
|
|
&App::SetUserAgentFallback)
|
2021-08-31 18:55:30 +00:00
|
|
|
.SetMethod("configureHostResolver", &ConfigureHostResolver)
|
2024-02-22 17:08:25 +00:00
|
|
|
.SetMethod("enableSandbox", &App::EnableSandbox)
|
|
|
|
.SetMethod("setProxy", &App::SetProxy)
|
|
|
|
.SetMethod("resolveProxy", &App::ResolveProxy);
|
2013-05-30 11:24:47 +00:00
|
|
|
}
|
|
|
|
|
2020-07-28 23:43:43 +00:00
|
|
|
const char* App::GetTypeName() {
|
|
|
|
return "App";
|
|
|
|
}
|
|
|
|
|
2022-06-29 19:55:47 +00:00
|
|
|
} // namespace electron::api
|
2013-12-05 02:32:58 +00:00
|
|
|
|
2014-04-17 09:13:46 +00:00
|
|
|
namespace {
|
2013-05-17 07:39:44 +00:00
|
|
|
|
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) {
|
2014-06-29 12:48:44 +00:00
|
|
|
v8::Isolate* isolate = context->GetIsolate();
|
2019-10-24 05:47:58 +00:00
|
|
|
gin_helper::Dictionary dict(isolate, exports);
|
2014-04-17 09:13:46 +00:00
|
|
|
dict.Set("app", electron::api::App::Create(isolate));
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2023-02-09 01:31:38 +00:00
|
|
|
NODE_LINKED_BINDING_CONTEXT_AWARE(electron_browser_app, Initialize)
|