refactor: Chromium code style for enum classes (#26165)

This commit is contained in:
Milan Burda 2020-10-27 18:51:45 +01:00 committed by GitHub
parent dbf2931f0e
commit 1c99a9b425
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 300 additions and 295 deletions

View file

@ -49,29 +49,34 @@ namespace electron {
namespace { namespace {
enum class WidevineCdmFileCheck {
kNotChecked,
kFound,
kNotFound,
};
#if defined(WIDEVINE_CDM_AVAILABLE) #if defined(WIDEVINE_CDM_AVAILABLE)
bool IsWidevineAvailable( bool IsWidevineAvailable(
base::FilePath* cdm_path, base::FilePath* cdm_path,
std::vector<media::VideoCodec>* codecs_supported, std::vector<media::VideoCodec>* codecs_supported,
base::flat_set<media::CdmSessionType>* session_types_supported, base::flat_set<media::CdmSessionType>* session_types_supported,
base::flat_set<media::EncryptionMode>* modes_supported) { base::flat_set<media::EncryptionMode>* modes_supported) {
static enum { static WidevineCdmFileCheck widevine_cdm_file_check =
NOT_CHECKED, WidevineCdmFileCheck::kNotChecked;
FOUND,
NOT_FOUND,
} widevine_cdm_file_check = NOT_CHECKED;
if (widevine_cdm_file_check == NOT_CHECKED) { if (widevine_cdm_file_check == WidevineCdmFileCheck::kNotChecked) {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
*cdm_path = command_line->GetSwitchValuePath(switches::kWidevineCdmPath); *cdm_path = command_line->GetSwitchValuePath(switches::kWidevineCdmPath);
if (!cdm_path->empty()) { if (!cdm_path->empty()) {
*cdm_path = cdm_path->AppendASCII( *cdm_path = cdm_path->AppendASCII(
base::GetNativeLibraryName(kWidevineCdmLibraryName)); base::GetNativeLibraryName(kWidevineCdmLibraryName));
widevine_cdm_file_check = base::PathExists(*cdm_path) ? FOUND : NOT_FOUND; widevine_cdm_file_check = base::PathExists(*cdm_path)
? WidevineCdmFileCheck::kFound
: WidevineCdmFileCheck::kNotFound;
} }
} }
if (widevine_cdm_file_check == FOUND) { if (widevine_cdm_file_check == WidevineCdmFileCheck::kFound) {
// Add the supported codecs as if they came from the component manifest. // Add the supported codecs as if they came from the component manifest.
// This list must match the CDM that is being bundled with Chrome. // This list must match the CDM that is being bundled with Chrome.
codecs_supported->push_back(media::VideoCodec::kCodecVP8); codecs_supported->push_back(media::VideoCodec::kCodecVP8);

View file

@ -78,13 +78,13 @@ struct Converter<electron::ProcessIntegrityLevel> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
electron::ProcessIntegrityLevel value) { electron::ProcessIntegrityLevel value) {
switch (value) { switch (value) {
case electron::ProcessIntegrityLevel::Untrusted: case electron::ProcessIntegrityLevel::kUntrusted:
return StringToV8(isolate, "untrusted"); return StringToV8(isolate, "untrusted");
case electron::ProcessIntegrityLevel::Low: case electron::ProcessIntegrityLevel::kLow:
return StringToV8(isolate, "low"); return StringToV8(isolate, "low");
case electron::ProcessIntegrityLevel::Medium: case electron::ProcessIntegrityLevel::kMedium:
return StringToV8(isolate, "medium"); return StringToV8(isolate, "medium");
case electron::ProcessIntegrityLevel::High: case electron::ProcessIntegrityLevel::kHigh:
return StringToV8(isolate, "high"); return StringToV8(isolate, "high");
default: default:
return StringToV8(isolate, "unknown"); return StringToV8(isolate, "unknown");
@ -127,11 +127,11 @@ struct Converter<JumpListItem::Type> {
return false; return false;
if (item_type == "task") if (item_type == "task")
*out = JumpListItem::Type::TASK; *out = JumpListItem::Type::kTask;
else if (item_type == "separator") else if (item_type == "separator")
*out = JumpListItem::Type::SEPARATOR; *out = JumpListItem::Type::kSeparator;
else if (item_type == "file") else if (item_type == "file")
*out = JumpListItem::Type::FILE; *out = JumpListItem::Type::kFile;
else else
return false; return false;
@ -142,15 +142,15 @@ struct Converter<JumpListItem::Type> {
JumpListItem::Type val) { JumpListItem::Type val) {
std::string item_type; std::string item_type;
switch (val) { switch (val) {
case JumpListItem::Type::TASK: case JumpListItem::Type::kTask:
item_type = "task"; item_type = "task";
break; break;
case JumpListItem::Type::SEPARATOR: case JumpListItem::Type::kSeparator:
item_type = "separator"; item_type = "separator";
break; break;
case JumpListItem::Type::FILE: case JumpListItem::Type::kFile:
item_type = "file"; item_type = "file";
break; break;
} }
@ -171,7 +171,7 @@ struct Converter<JumpListItem> {
return false; return false;
switch (out->type) { switch (out->type) {
case JumpListItem::Type::TASK: case JumpListItem::Type::kTask:
if (!dict.Get("program", &(out->path)) || if (!dict.Get("program", &(out->path)) ||
!dict.Get("title", &(out->title))) !dict.Get("title", &(out->title)))
return false; return false;
@ -185,10 +185,10 @@ struct Converter<JumpListItem> {
dict.Get("workingDirectory", &(out->working_dir)); dict.Get("workingDirectory", &(out->working_dir));
return true; return true;
case JumpListItem::Type::SEPARATOR: case JumpListItem::Type::kSeparator:
return true; return true;
case JumpListItem::Type::FILE: case JumpListItem::Type::kFile:
return dict.Get("path", &(out->path)); return dict.Get("path", &(out->path));
} }
@ -202,7 +202,7 @@ struct Converter<JumpListItem> {
dict.Set("type", val.type); dict.Set("type", val.type);
switch (val.type) { switch (val.type) {
case JumpListItem::Type::TASK: case JumpListItem::Type::kTask:
dict.Set("program", val.path); dict.Set("program", val.path);
dict.Set("args", val.arguments); dict.Set("args", val.arguments);
dict.Set("title", val.title); dict.Set("title", val.title);
@ -212,10 +212,10 @@ struct Converter<JumpListItem> {
dict.Set("workingDirectory", val.working_dir); dict.Set("workingDirectory", val.working_dir);
break; break;
case JumpListItem::Type::SEPARATOR: case JumpListItem::Type::kSeparator:
break; break;
case JumpListItem::Type::FILE: case JumpListItem::Type::kFile:
dict.Set("path", val.path); dict.Set("path", val.path);
break; break;
} }
@ -233,13 +233,13 @@ struct Converter<JumpListCategory::Type> {
return false; return false;
if (category_type == "tasks") if (category_type == "tasks")
*out = JumpListCategory::Type::TASKS; *out = JumpListCategory::Type::kTasks;
else if (category_type == "frequent") else if (category_type == "frequent")
*out = JumpListCategory::Type::FREQUENT; *out = JumpListCategory::Type::kFrequent;
else if (category_type == "recent") else if (category_type == "recent")
*out = JumpListCategory::Type::RECENT; *out = JumpListCategory::Type::kRecent;
else if (category_type == "custom") else if (category_type == "custom")
*out = JumpListCategory::Type::CUSTOM; *out = JumpListCategory::Type::kCustom;
else else
return false; return false;
@ -250,19 +250,19 @@ struct Converter<JumpListCategory::Type> {
JumpListCategory::Type val) { JumpListCategory::Type val) {
std::string category_type; std::string category_type;
switch (val) { switch (val) {
case JumpListCategory::Type::TASKS: case JumpListCategory::Type::kTasks:
category_type = "tasks"; category_type = "tasks";
break; break;
case JumpListCategory::Type::FREQUENT: case JumpListCategory::Type::kFrequent:
category_type = "frequent"; category_type = "frequent";
break; break;
case JumpListCategory::Type::RECENT: case JumpListCategory::Type::kRecent:
category_type = "recent"; category_type = "recent";
break; break;
case JumpListCategory::Type::CUSTOM: case JumpListCategory::Type::kCustom:
category_type = "custom"; category_type = "custom";
break; break;
} }
@ -284,13 +284,13 @@ struct Converter<JumpListCategory> {
if (!dict.Get("type", &(out->type))) { if (!dict.Get("type", &(out->type))) {
if (out->name.empty()) if (out->name.empty())
out->type = JumpListCategory::Type::TASKS; out->type = JumpListCategory::Type::kTasks;
else else
out->type = JumpListCategory::Type::CUSTOM; out->type = JumpListCategory::Type::kCustom;
} }
if ((out->type == JumpListCategory::Type::TASKS) || if ((out->type == JumpListCategory::Type::kTasks) ||
(out->type == JumpListCategory::Type::CUSTOM)) { (out->type == JumpListCategory::Type::kCustom)) {
if (!dict.Get("items", &(out->items))) if (!dict.Get("items", &(out->items)))
return false; return false;
} }
@ -305,27 +305,27 @@ struct Converter<JumpListResult> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, JumpListResult val) { static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, JumpListResult val) {
std::string result_code; std::string result_code;
switch (val) { switch (val) {
case JumpListResult::SUCCESS: case JumpListResult::kSuccess:
result_code = "ok"; result_code = "ok";
break; break;
case JumpListResult::ARGUMENT_ERROR: case JumpListResult::kArgumentError:
result_code = "argumentError"; result_code = "argumentError";
break; break;
case JumpListResult::GENERIC_ERROR: case JumpListResult::kGenericError:
result_code = "error"; result_code = "error";
break; break;
case JumpListResult::CUSTOM_CATEGORY_SEPARATOR_ERROR: case JumpListResult::kCustomCategorySeparatorError:
result_code = "invalidSeparatorError"; result_code = "invalidSeparatorError";
break; break;
case JumpListResult::MISSING_FILE_TYPE_REGISTRATION_ERROR: case JumpListResult::kMissingFileTypeRegistrationError:
result_code = "fileTypeRegistrationError"; result_code = "fileTypeRegistrationError";
break; break;
case JumpListResult::CUSTOM_CATEGORY_ACCESS_DENIED_ERROR: case JumpListResult::kCustomCategoryAccessDeniedError:
result_code = "customCategoryAccessDeniedError"; result_code = "customCategoryAccessDeniedError";
break; break;
} }
@ -1253,19 +1253,19 @@ JumpListResult App::SetJumpList(v8::Local<v8::Value> val,
!gin::ConvertFromV8(args->isolate(), val, &categories)) { !gin::ConvertFromV8(args->isolate(), val, &categories)) {
gin_helper::ErrorThrower(args->isolate()) gin_helper::ErrorThrower(args->isolate())
.ThrowError("Argument must be null or an array of categories"); .ThrowError("Argument must be null or an array of categories");
return JumpListResult::ARGUMENT_ERROR; return JumpListResult::kArgumentError;
} }
JumpList jump_list(Browser::Get()->GetAppUserModelID()); JumpList jump_list(Browser::Get()->GetAppUserModelID());
if (delete_jump_list) { if (delete_jump_list) {
return jump_list.Delete() ? JumpListResult::SUCCESS return jump_list.Delete() ? JumpListResult::kSuccess
: JumpListResult::GENERIC_ERROR; : JumpListResult::kGenericError;
} }
// Start a transaction that updates the JumpList of this application. // Start a transaction that updates the JumpList of this application.
if (!jump_list.Begin()) if (!jump_list.Begin())
return JumpListResult::GENERIC_ERROR; return JumpListResult::kGenericError;
JumpListResult result = jump_list.AppendCategories(categories); JumpListResult result = jump_list.AppendCategories(categories);
// AppendCategories may have failed to add some categories, but it's better // AppendCategories may have failed to add some categories, but it's better
@ -1275,8 +1275,8 @@ JumpListResult App::SetJumpList(v8::Local<v8::Value> val,
// It's more useful to return the earlier error code that might give // 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 // some indication as to why the transaction actually failed, so don't
// overwrite it with a "generic error" code here. // overwrite it with a "generic error" code here.
if (result == JumpListResult::SUCCESS) if (result == JumpListResult::kSuccess)
result = JumpListResult::GENERIC_ERROR; result = JumpListResult::kGenericError;
} }
return result; return result;
@ -1488,9 +1488,10 @@ int DockBounce(gin::Arguments* args) {
args->GetNext(&type); args->GetNext(&type);
if (type == "critical") if (type == "critical")
request_id = Browser::Get()->DockBounce(Browser::BounceType::CRITICAL); request_id = Browser::Get()->DockBounce(Browser::BounceType::kCritical);
else if (type == "informational") else if (type == "informational")
request_id = Browser::Get()->DockBounce(Browser::BounceType::INFORMATIONAL); request_id =
Browser::Get()->DockBounce(Browser::BounceType::kInformational);
return request_id; return request_id;
} }

View file

@ -160,13 +160,13 @@ const char* kBuiltinSchemes[] = {
// Convert error code to string. // Convert error code to string.
std::string ErrorCodeToString(ProtocolError error) { std::string ErrorCodeToString(ProtocolError error) {
switch (error) { switch (error) {
case ProtocolError::REGISTERED: case ProtocolError::kRegistered:
return "The scheme has been registered"; return "The scheme has been registered";
case ProtocolError::NOT_REGISTERED: case ProtocolError::kNotRegistered:
return "The scheme has not been registered"; return "The scheme has not been registered";
case ProtocolError::INTERCEPTED: case ProtocolError::kIntercepted:
return "The scheme has been intercepted"; return "The scheme has been intercepted";
case ProtocolError::NOT_INTERCEPTED: case ProtocolError::kNotIntercepted:
return "The scheme has not been intercepted"; return "The scheme has not been intercepted";
default: default:
return "Unexpected error"; return "Unexpected error";
@ -184,14 +184,14 @@ ProtocolError Protocol::RegisterProtocol(ProtocolType type,
const std::string& scheme, const std::string& scheme,
const ProtocolHandler& handler) { const ProtocolHandler& handler) {
bool added = protocol_registry_->RegisterProtocol(type, scheme, handler); bool added = protocol_registry_->RegisterProtocol(type, scheme, handler);
return added ? ProtocolError::OK : ProtocolError::REGISTERED; return added ? ProtocolError::kOK : ProtocolError::kRegistered;
} }
bool Protocol::UnregisterProtocol(const std::string& scheme, bool Protocol::UnregisterProtocol(const std::string& scheme,
gin::Arguments* args) { gin::Arguments* args) {
bool removed = protocol_registry_->UnregisterProtocol(scheme); bool removed = protocol_registry_->UnregisterProtocol(scheme);
HandleOptionalCallback( HandleOptionalCallback(
args, removed ? ProtocolError::OK : ProtocolError::NOT_REGISTERED); args, removed ? ProtocolError::kOK : ProtocolError::kNotRegistered);
return removed; return removed;
} }
@ -203,14 +203,14 @@ ProtocolError Protocol::InterceptProtocol(ProtocolType type,
const std::string& scheme, const std::string& scheme,
const ProtocolHandler& handler) { const ProtocolHandler& handler) {
bool added = protocol_registry_->InterceptProtocol(type, scheme, handler); bool added = protocol_registry_->InterceptProtocol(type, scheme, handler);
return added ? ProtocolError::OK : ProtocolError::INTERCEPTED; return added ? ProtocolError::kOK : ProtocolError::kIntercepted;
} }
bool Protocol::UninterceptProtocol(const std::string& scheme, bool Protocol::UninterceptProtocol(const std::string& scheme,
gin::Arguments* args) { gin::Arguments* args) {
bool removed = protocol_registry_->UninterceptProtocol(scheme); bool removed = protocol_registry_->UninterceptProtocol(scheme);
HandleOptionalCallback( HandleOptionalCallback(
args, removed ? ProtocolError::OK : ProtocolError::NOT_INTERCEPTED); args, removed ? ProtocolError::kOK : ProtocolError::kNotIntercepted);
return removed; return removed;
} }
@ -248,7 +248,7 @@ void Protocol::HandleOptionalCallback(gin::Arguments* args,
env, env,
"The callback argument of protocol module APIs is no longer needed.", "The callback argument of protocol module APIs is no longer needed.",
"ProtocolDeprecateCallback"); "ProtocolDeprecateCallback");
if (error == ProtocolError::OK) if (error == ProtocolError::kOK)
callback.Run(v8::Null(args->isolate())); callback.Run(v8::Null(args->isolate()));
else else
callback.Run(v8::Exception::Error( callback.Run(v8::Exception::Error(

View file

@ -27,11 +27,11 @@ void RegisterSchemesAsPrivileged(gin_helper::ErrorThrower thrower,
// Possible errors. // Possible errors.
enum class ProtocolError { enum class ProtocolError {
OK, // no error kOK, // no error
REGISTERED, kRegistered,
NOT_REGISTERED, kNotRegistered,
INTERCEPTED, kIntercepted,
NOT_INTERCEPTED, kNotIntercepted,
}; };
// Protocol implementation based on network services. // Protocol implementation based on network services.
@ -78,7 +78,7 @@ class Protocol : public gin::Wrappable<Protocol> {
gin::Arguments* args) { gin::Arguments* args) {
auto result = RegisterProtocol(type, scheme, handler); auto result = RegisterProtocol(type, scheme, handler);
HandleOptionalCallback(args, result); HandleOptionalCallback(args, result);
return result == ProtocolError::OK; return result == ProtocolError::kOK;
} }
template <ProtocolType type> template <ProtocolType type>
bool InterceptProtocolFor(const std::string& scheme, bool InterceptProtocolFor(const std::string& scheme,
@ -86,7 +86,7 @@ class Protocol : public gin::Wrappable<Protocol> {
gin::Arguments* args) { gin::Arguments* args) {
auto result = InterceptProtocol(type, scheme, handler); auto result = InterceptProtocol(type, scheme, handler);
HandleOptionalCallback(args, result); HandleOptionalCallback(args, result);
return result == ProtocolError::OK; return result == ProtocolError::kOK;
} }
// Be compatible with old interface, which accepts optional callback. // Be compatible with old interface, which accepts optional callback.

View file

@ -33,19 +33,19 @@ struct Converter<electron::TrayIcon::IconType> {
std::string mode; std::string mode;
if (ConvertFromV8(isolate, val, &mode)) { if (ConvertFromV8(isolate, val, &mode)) {
if (mode == "none") { if (mode == "none") {
*out = IconType::None; *out = IconType::kNone;
return true; return true;
} else if (mode == "info") { } else if (mode == "info") {
*out = IconType::Info; *out = IconType::kInfo;
return true; return true;
} else if (mode == "warning") { } else if (mode == "warning") {
*out = IconType::Warning; *out = IconType::kWarning;
return true; return true;
} else if (mode == "error") { } else if (mode == "error") {
*out = IconType::Error; *out = IconType::kError;
return true; return true;
} else if (mode == "custom") { } else if (mode == "custom") {
*out = IconType::Custom; *out = IconType::kCustom;
return true; return true;
} }
} }

View file

@ -273,22 +273,22 @@ struct Converter<electron::api::WebContents::Type> {
using Type = electron::api::WebContents::Type; using Type = electron::api::WebContents::Type;
std::string type; std::string type;
switch (val) { switch (val) {
case Type::BACKGROUND_PAGE: case Type::kBackgroundPage:
type = "backgroundPage"; type = "backgroundPage";
break; break;
case Type::BROWSER_WINDOW: case Type::kBrowserWindow:
type = "window"; type = "window";
break; break;
case Type::BROWSER_VIEW: case Type::kBrowserView:
type = "browserView"; type = "browserView";
break; break;
case Type::REMOTE: case Type::kRemote:
type = "remote"; type = "remote";
break; break;
case Type::WEB_VIEW: case Type::kWebView:
type = "webview"; type = "webview";
break; break;
case Type::OFF_SCREEN: case Type::kOffScreen:
type = "offscreen"; type = "offscreen";
break; break;
default: default:
@ -305,14 +305,14 @@ struct Converter<electron::api::WebContents::Type> {
if (!ConvertFromV8(isolate, val, &type)) if (!ConvertFromV8(isolate, val, &type))
return false; return false;
if (type == "backgroundPage") { if (type == "backgroundPage") {
*out = Type::BACKGROUND_PAGE; *out = Type::kBackgroundPage;
} else if (type == "browserView") { } else if (type == "browserView") {
*out = Type::BROWSER_VIEW; *out = Type::kBrowserView;
} else if (type == "webview") { } else if (type == "webview") {
*out = Type::WEB_VIEW; *out = Type::kWebView;
#if BUILDFLAG(ENABLE_OSR) #if BUILDFLAG(ENABLE_OSR)
} else if (type == "offscreen") { } else if (type == "offscreen") {
*out = Type::OFF_SCREEN; *out = Type::kOffScreen;
#endif #endif
} else { } else {
return false; return false;
@ -428,7 +428,7 @@ const void* kElectronApiWebContentsKey = &kElectronApiWebContentsKey;
WebContents::Type GetTypeFromViewType(extensions::ViewType view_type) { WebContents::Type GetTypeFromViewType(extensions::ViewType view_type) {
switch (view_type) { switch (view_type) {
case extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE: case extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE:
return WebContents::Type::BACKGROUND_PAGE; return WebContents::Type::kBackgroundPage;
case extensions::VIEW_TYPE_APP_WINDOW: case extensions::VIEW_TYPE_APP_WINDOW:
case extensions::VIEW_TYPE_COMPONENT: case extensions::VIEW_TYPE_COMPONENT:
@ -438,7 +438,7 @@ WebContents::Type GetTypeFromViewType(extensions::ViewType view_type) {
case extensions::VIEW_TYPE_EXTENSION_GUEST: case extensions::VIEW_TYPE_EXTENSION_GUEST:
case extensions::VIEW_TYPE_TAB_CONTENTS: case extensions::VIEW_TYPE_TAB_CONTENTS:
case extensions::VIEW_TYPE_INVALID: case extensions::VIEW_TYPE_INVALID:
return WebContents::Type::REMOTE; return WebContents::Type::kRemote;
} }
} }
@ -447,7 +447,7 @@ WebContents::Type GetTypeFromViewType(extensions::ViewType view_type) {
WebContents::WebContents(v8::Isolate* isolate, WebContents::WebContents(v8::Isolate* isolate,
content::WebContents* web_contents) content::WebContents* web_contents)
: content::WebContentsObserver(web_contents), : content::WebContentsObserver(web_contents),
type_(Type::REMOTE), type_(Type::kRemote),
id_(GetAllWebContents().Add(this)), id_(GetAllWebContents().Add(this)),
weak_factory_(this) { weak_factory_(this) {
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS) #if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
@ -485,7 +485,7 @@ WebContents::WebContents(v8::Isolate* isolate,
type_(type), type_(type),
id_(GetAllWebContents().Add(this)), id_(GetAllWebContents().Add(this)),
weak_factory_(this) { weak_factory_(this) {
DCHECK(type != Type::REMOTE) DCHECK(type != Type::kRemote)
<< "Can't take ownership of a remote WebContents"; << "Can't take ownership of a remote WebContents";
auto session = Session::CreateFrom(isolate, GetBrowserContext()); auto session = Session::CreateFrom(isolate, GetBrowserContext());
session_.Reset(isolate, session.ToV8()); session_.Reset(isolate, session.ToV8());
@ -505,7 +505,7 @@ WebContents::WebContents(v8::Isolate* isolate,
#if BUILDFLAG(ENABLE_OSR) #if BUILDFLAG(ENABLE_OSR)
bool b = false; bool b = false;
if (options.Get(options::kOffscreen, &b) && b) if (options.Get(options::kOffscreen, &b) && b)
type_ = Type::OFF_SCREEN; type_ = Type::kOffScreen;
#endif #endif
// Init embedder earlier // Init embedder earlier
@ -517,7 +517,7 @@ WebContents::WebContents(v8::Isolate* isolate,
// BrowserViews are not attached to a window initially so they should start // BrowserViews are not attached to a window initially so they should start
// off as hidden. This is also important for compositor recycling. See: // off as hidden. This is also important for compositor recycling. See:
// https://github.com/electron/electron/pull/21372 // https://github.com/electron/electron/pull/21372
initially_shown_ = type_ != Type::BROWSER_VIEW; initially_shown_ = type_ != Type::kBrowserView;
options.Get(options::kShow, &initially_shown_); options.Get(options::kShow, &initially_shown_);
// Obtain the session. // Obtain the session.
@ -685,7 +685,7 @@ void WebContents::InitWithExtensionView(v8::Isolate* isolate,
extensions::ViewType view_type) { extensions::ViewType view_type) {
// Must reassign type prior to calling `Init`. // Must reassign type prior to calling `Init`.
type_ = GetTypeFromViewType(view_type); type_ = GetTypeFromViewType(view_type);
if (GetType() == Type::REMOTE) if (GetType() == Type::kRemote)
return; return;
// Allow toggling DevTools for background pages // Allow toggling DevTools for background pages
@ -701,7 +701,7 @@ WebContents::~WebContents() {
// The destroy() is called. // The destroy() is called.
if (managed_web_contents()) { if (managed_web_contents()) {
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS) #if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
if (type_ == Type::BACKGROUND_PAGE) { if (type_ == Type::kBackgroundPage) {
// Background pages are owned by extensions::ExtensionHost // Background pages are owned by extensions::ExtensionHost
managed_web_contents()->ReleaseWebContents(); managed_web_contents()->ReleaseWebContents();
} }
@ -713,7 +713,7 @@ WebContents::~WebContents() {
RenderViewDeleted(web_contents()->GetRenderViewHost()); RenderViewDeleted(web_contents()->GetRenderViewHost());
} }
if (type_ == Type::BROWSER_WINDOW && owner_window()) { if (type_ == Type::kBrowserWindow && owner_window()) {
// For BrowserWindow we should close the window and clean up everything // For BrowserWindow we should close the window and clean up everything
// before WebContents is destroyed. // before WebContents is destroyed.
for (ExtendedWebContentsObserver& observer : observers_) for (ExtendedWebContentsObserver& observer : observers_)
@ -727,7 +727,7 @@ WebContents::~WebContents() {
} else { } else {
// Destroy WebContents asynchronously unless app is shutting down, // Destroy WebContents asynchronously unless app is shutting down,
// because destroy() might be called inside WebContents's event handler. // because destroy() might be called inside WebContents's event handler.
bool is_browser_view = type_ == Type::BROWSER_VIEW; bool is_browser_view = type_ == Type::kBrowserView;
DestroyWebContents(!(IsGuest() || is_browser_view) /* async */); DestroyWebContents(!(IsGuest() || is_browser_view) /* async */);
// The WebContentsDestroyed will not be called automatically because we // The WebContentsDestroyed will not be called automatically because we
// destroy the webContents in the next tick. So we have to manually // destroy the webContents in the next tick. So we have to manually
@ -820,7 +820,7 @@ void WebContents::AddNewContents(
v8::Locker locker(isolate); v8::Locker locker(isolate);
v8::HandleScope handle_scope(isolate); v8::HandleScope handle_scope(isolate);
auto api_web_contents = auto api_web_contents =
CreateAndTake(isolate, std::move(new_contents), Type::BROWSER_WINDOW); CreateAndTake(isolate, std::move(new_contents), Type::kBrowserWindow);
if (Emit("-add-new-contents", api_web_contents, disposition, user_gesture, if (Emit("-add-new-contents", api_web_contents, disposition, user_gesture,
initial_rect.x(), initial_rect.y(), initial_rect.width(), initial_rect.x(), initial_rect.y(), initial_rect.width(),
initial_rect.height(), tracker->url, tracker->frame_name, initial_rect.height(), tracker->url, tracker->frame_name,
@ -848,7 +848,7 @@ content::WebContents* WebContents::OpenURLFromTab(
void WebContents::BeforeUnloadFired(content::WebContents* tab, void WebContents::BeforeUnloadFired(content::WebContents* tab,
bool proceed, bool proceed,
bool* proceed_to_fire_unload) { bool* proceed_to_fire_unload) {
if (type_ == Type::BROWSER_WINDOW || type_ == Type::OFF_SCREEN) if (type_ == Type::kBrowserWindow || type_ == Type::kOffScreen)
*proceed_to_fire_unload = proceed; *proceed_to_fire_unload = proceed;
else else
*proceed_to_fire_unload = true; *proceed_to_fire_unload = true;
@ -890,7 +890,7 @@ void WebContents::UpdateTargetURL(content::WebContents* source,
bool WebContents::HandleKeyboardEvent( bool WebContents::HandleKeyboardEvent(
content::WebContents* source, content::WebContents* source,
const content::NativeWebKeyboardEvent& event) { const content::NativeWebKeyboardEvent& event) {
if (type_ == Type::WEB_VIEW && embedder_) { if (type_ == Type::kWebView && embedder_) {
// Send the unhandled keyboard events back to the embedder. // Send the unhandled keyboard events back to the embedder.
return embedder_->HandleKeyboardEvent(source, event); return embedder_->HandleKeyboardEvent(source, event);
} else { } else {
@ -1800,14 +1800,14 @@ v8::Local<v8::Promise> WebContents::SavePage(
} }
void WebContents::OpenDevTools(gin::Arguments* args) { void WebContents::OpenDevTools(gin::Arguments* args) {
if (type_ == Type::REMOTE) if (type_ == Type::kRemote)
return; return;
if (!enable_devtools_) if (!enable_devtools_)
return; return;
std::string state; std::string state;
if (type_ == Type::WEB_VIEW || type_ == Type::BACKGROUND_PAGE || if (type_ == Type::kWebView || type_ == Type::kBackgroundPage ||
!owner_window()) { !owner_window()) {
state = "detach"; state = "detach";
} }
@ -1826,7 +1826,7 @@ void WebContents::OpenDevTools(gin::Arguments* args) {
} }
void WebContents::CloseDevTools() { void WebContents::CloseDevTools() {
if (type_ == Type::REMOTE) if (type_ == Type::kRemote)
return; return;
DCHECK(managed_web_contents()); DCHECK(managed_web_contents());
@ -1834,7 +1834,7 @@ void WebContents::CloseDevTools() {
} }
bool WebContents::IsDevToolsOpened() { bool WebContents::IsDevToolsOpened() {
if (type_ == Type::REMOTE) if (type_ == Type::kRemote)
return false; return false;
DCHECK(managed_web_contents()); DCHECK(managed_web_contents());
@ -1842,7 +1842,7 @@ bool WebContents::IsDevToolsOpened() {
} }
bool WebContents::IsDevToolsFocused() { bool WebContents::IsDevToolsFocused() {
if (type_ == Type::REMOTE) if (type_ == Type::kRemote)
return false; return false;
DCHECK(managed_web_contents()); DCHECK(managed_web_contents());
@ -1851,7 +1851,7 @@ bool WebContents::IsDevToolsFocused() {
void WebContents::EnableDeviceEmulation( void WebContents::EnableDeviceEmulation(
const blink::DeviceEmulationParams& params) { const blink::DeviceEmulationParams& params) {
if (type_ == Type::REMOTE) if (type_ == Type::kRemote)
return; return;
DCHECK(web_contents()); DCHECK(web_contents());
@ -1869,7 +1869,7 @@ void WebContents::EnableDeviceEmulation(
} }
void WebContents::DisableDeviceEmulation() { void WebContents::DisableDeviceEmulation() {
if (type_ == Type::REMOTE) if (type_ == Type::kRemote)
return; return;
DCHECK(web_contents()); DCHECK(web_contents());
@ -1894,7 +1894,7 @@ void WebContents::ToggleDevTools() {
} }
void WebContents::InspectElement(int x, int y) { void WebContents::InspectElement(int x, int y) {
if (type_ == Type::REMOTE) if (type_ == Type::kRemote)
return; return;
if (!enable_devtools_) if (!enable_devtools_)
@ -1907,7 +1907,7 @@ void WebContents::InspectElement(int x, int y) {
} }
void WebContents::InspectSharedWorkerById(const std::string& workerId) { void WebContents::InspectSharedWorkerById(const std::string& workerId) {
if (type_ == Type::REMOTE) if (type_ == Type::kRemote)
return; return;
if (!enable_devtools_) if (!enable_devtools_)
@ -1929,7 +1929,7 @@ std::vector<scoped_refptr<content::DevToolsAgentHost>>
WebContents::GetAllSharedWorkers() { WebContents::GetAllSharedWorkers() {
std::vector<scoped_refptr<content::DevToolsAgentHost>> shared_workers; std::vector<scoped_refptr<content::DevToolsAgentHost>> shared_workers;
if (type_ == Type::REMOTE) if (type_ == Type::kRemote)
return shared_workers; return shared_workers;
if (!enable_devtools_) if (!enable_devtools_)
@ -1945,7 +1945,7 @@ WebContents::GetAllSharedWorkers() {
} }
void WebContents::InspectSharedWorker() { void WebContents::InspectSharedWorker() {
if (type_ == Type::REMOTE) if (type_ == Type::kRemote)
return; return;
if (!enable_devtools_) if (!enable_devtools_)
@ -1962,7 +1962,7 @@ void WebContents::InspectSharedWorker() {
} }
void WebContents::InspectServiceWorker() { void WebContents::InspectServiceWorker() {
if (type_ == Type::REMOTE) if (type_ == Type::kRemote)
return; return;
if (!enable_devtools_) if (!enable_devtools_)
@ -2356,7 +2356,7 @@ bool WebContents::IsFocused() const {
if (!view) if (!view)
return false; return false;
if (GetType() != Type::BACKGROUND_PAGE) { if (GetType() != Type::kBackgroundPage) {
auto* window = web_contents()->GetNativeView()->GetToplevelWindow(); auto* window = web_contents()->GetNativeView()->GetToplevelWindow();
if (window && !window->IsVisible()) if (window && !window->IsVisible())
return false; return false;
@ -2624,7 +2624,7 @@ void WebContents::OnCursorChanged(const content::WebCursor& webcursor) {
} }
bool WebContents::IsGuest() const { bool WebContents::IsGuest() const {
return type_ == Type::WEB_VIEW; return type_ == Type::kWebView;
} }
void WebContents::AttachToIframe(content::WebContents* embedder_web_contents, void WebContents::AttachToIframe(content::WebContents* embedder_web_contents,
@ -2635,7 +2635,7 @@ void WebContents::AttachToIframe(content::WebContents* embedder_web_contents,
bool WebContents::IsOffScreen() const { bool WebContents::IsOffScreen() const {
#if BUILDFLAG(ENABLE_OSR) #if BUILDFLAG(ENABLE_OSR)
return type_ == Type::OFF_SCREEN; return type_ == Type::kOffScreen;
#else #else
return false; return false;
#endif #endif

View file

@ -146,12 +146,12 @@ class WebContents : public gin::Wrappable<WebContents>,
public mojom::ElectronBrowser { public mojom::ElectronBrowser {
public: public:
enum class Type { enum class Type {
BACKGROUND_PAGE, // An extension background page. kBackgroundPage, // An extension background page.
BROWSER_WINDOW, // Used by BrowserWindow. kBrowserWindow, // Used by BrowserWindow.
BROWSER_VIEW, // Used by BrowserView. kBrowserView, // Used by BrowserView.
REMOTE, // Thin wrap around an existing WebContents. kRemote, // Thin wrap around an existing WebContents.
WEB_VIEW, // Used by <webview>. kWebView, // Used by <webview>.
OFF_SCREEN, // Used for offscreen rendering kOffScreen, // Used for offscreen rendering
}; };
// Create a new WebContents and return the V8 wrapper of it. // Create a new WebContents and return the V8 wrapper of it.
@ -677,7 +677,7 @@ class WebContents : public gin::Wrappable<WebContents>,
WebContentsZoomController* zoom_controller_ = nullptr; WebContentsZoomController* zoom_controller_ = nullptr;
// The type of current WebContents. // The type of current WebContents.
Type type_ = Type::BROWSER_WINDOW; Type type_ = Type::kBrowserWindow;
int32_t id_; int32_t id_;

View file

@ -16,7 +16,7 @@ bool WebContents::IsFocused() const {
if (!view) if (!view)
return false; return false;
if (GetType() != Type::BACKGROUND_PAGE) { if (GetType() != Type::kBackgroundPage) {
auto window = [web_contents()->GetNativeView().GetNativeNSView() window]; auto window = [web_contents()->GetNativeView().GetNativeNSView() window];
// On Mac the render widget host view does not lose focus when the window // On Mac the render widget host view does not lose focus when the window
// loses focus so check if the top level window is the key window. // loses focus so check if the top level window is the key window.

View file

@ -92,7 +92,7 @@ ProcessMemoryInfo ProcessMetric::GetMemoryInfo() const {
ProcessIntegrityLevel ProcessMetric::GetIntegrityLevel() const { ProcessIntegrityLevel ProcessMetric::GetIntegrityLevel() const {
HANDLE token = nullptr; HANDLE token = nullptr;
if (!::OpenProcessToken(process.Handle(), TOKEN_QUERY, &token)) { if (!::OpenProcessToken(process.Handle(), TOKEN_QUERY, &token)) {
return ProcessIntegrityLevel::Unknown; return ProcessIntegrityLevel::kUnknown;
} }
base::win::ScopedHandle token_scoped(token); base::win::ScopedHandle token_scoped(token);
@ -101,7 +101,7 @@ ProcessIntegrityLevel ProcessMetric::GetIntegrityLevel() const {
if (::GetTokenInformation(token, TokenIntegrityLevel, nullptr, 0, if (::GetTokenInformation(token, TokenIntegrityLevel, nullptr, 0,
&token_info_length) || &token_info_length) ||
::GetLastError() != ERROR_INSUFFICIENT_BUFFER) { ::GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
return ProcessIntegrityLevel::Unknown; return ProcessIntegrityLevel::kUnknown;
} }
auto token_label_bytes = std::make_unique<char[]>(token_info_length); auto token_label_bytes = std::make_unique<char[]>(token_info_length);
@ -109,7 +109,7 @@ ProcessIntegrityLevel ProcessMetric::GetIntegrityLevel() const {
reinterpret_cast<TOKEN_MANDATORY_LABEL*>(token_label_bytes.get()); reinterpret_cast<TOKEN_MANDATORY_LABEL*>(token_label_bytes.get());
if (!::GetTokenInformation(token, TokenIntegrityLevel, token_label, if (!::GetTokenInformation(token, TokenIntegrityLevel, token_label,
token_info_length, &token_info_length)) { token_info_length, &token_info_length)) {
return ProcessIntegrityLevel::Unknown; return ProcessIntegrityLevel::kUnknown;
} }
DWORD integrity_level = *::GetSidSubAuthority( DWORD integrity_level = *::GetSidSubAuthority(
@ -119,31 +119,31 @@ ProcessIntegrityLevel ProcessMetric::GetIntegrityLevel() const {
if (integrity_level >= SECURITY_MANDATORY_UNTRUSTED_RID && if (integrity_level >= SECURITY_MANDATORY_UNTRUSTED_RID &&
integrity_level < SECURITY_MANDATORY_LOW_RID) { integrity_level < SECURITY_MANDATORY_LOW_RID) {
return ProcessIntegrityLevel::Untrusted; return ProcessIntegrityLevel::kUntrusted;
} }
if (integrity_level >= SECURITY_MANDATORY_LOW_RID && if (integrity_level >= SECURITY_MANDATORY_LOW_RID &&
integrity_level < SECURITY_MANDATORY_MEDIUM_RID) { integrity_level < SECURITY_MANDATORY_MEDIUM_RID) {
return ProcessIntegrityLevel::Low; return ProcessIntegrityLevel::kLow;
} }
if (integrity_level >= SECURITY_MANDATORY_MEDIUM_RID && if (integrity_level >= SECURITY_MANDATORY_MEDIUM_RID &&
integrity_level < SECURITY_MANDATORY_HIGH_RID) { integrity_level < SECURITY_MANDATORY_HIGH_RID) {
return ProcessIntegrityLevel::Medium; return ProcessIntegrityLevel::kMedium;
} }
if (integrity_level >= SECURITY_MANDATORY_HIGH_RID && if (integrity_level >= SECURITY_MANDATORY_HIGH_RID &&
integrity_level < SECURITY_MANDATORY_SYSTEM_RID) { integrity_level < SECURITY_MANDATORY_SYSTEM_RID) {
return ProcessIntegrityLevel::High; return ProcessIntegrityLevel::kHigh;
} }
return ProcessIntegrityLevel::Unknown; return ProcessIntegrityLevel::kUnknown;
} }
// static // static
bool ProcessMetric::IsSandboxed(ProcessIntegrityLevel integrity_level) { bool ProcessMetric::IsSandboxed(ProcessIntegrityLevel integrity_level) {
return integrity_level > ProcessIntegrityLevel::Unknown && return integrity_level > ProcessIntegrityLevel::kUnknown &&
integrity_level < ProcessIntegrityLevel::Medium; integrity_level < ProcessIntegrityLevel::kMedium;
} }
#elif defined(OS_MAC) #elif defined(OS_MAC)

View file

@ -26,11 +26,11 @@ struct ProcessMemoryInfo {
#if defined(OS_WIN) #if defined(OS_WIN)
enum class ProcessIntegrityLevel { enum class ProcessIntegrityLevel {
Unknown, kUnknown,
Untrusted, kUntrusted,
Low, kLow,
Medium, kMedium,
High, kHigh,
}; };
#endif #endif

View file

@ -201,8 +201,8 @@ class Browser : public WindowListObserver {
// Bounce the dock icon. // Bounce the dock icon.
enum class BounceType{ enum class BounceType{
CRITICAL = 0, // NSCriticalRequest kCritical = 0, // NSCriticalRequest
INFORMATIONAL = 10, // NSInformationalRequest kInformational = 10, // NSInformationalRequest
}; };
int DockBounce(BounceType type); int DockBounce(BounceType type);
void DockCancelBounce(int request_id); void DockCancelBounce(int request_id);

View file

@ -403,10 +403,10 @@ bool Browser::SetUserTasks(const std::vector<UserTask>& tasks) {
return false; return false;
JumpListCategory category; JumpListCategory category;
category.type = JumpListCategory::Type::TASKS; category.type = JumpListCategory::Type::kTasks;
category.items.reserve(tasks.size()); category.items.reserve(tasks.size());
JumpListItem item; JumpListItem item;
item.type = JumpListItem::Type::TASK; item.type = JumpListItem::Type::kTask;
for (const auto& task : tasks) { for (const auto& task : tasks) {
item.title = task.title; item.title = task.title;
item.path = task.program; item.path = task.program;

View file

@ -237,10 +237,10 @@ const base::FilePath::StringPieceType kPathDelimiter = FILE_PATH_LITERAL(":");
// granted to their RenderProcessHosts. This classification allows us to make // granted to their RenderProcessHosts. This classification allows us to make
// sure URLs are served by hosts with the right set of privileges. // sure URLs are served by hosts with the right set of privileges.
enum class RenderProcessHostPrivilege { enum class RenderProcessHostPrivilege {
Normal, kNormal,
Hosted, kHosted,
Isolated, kIsolated,
Extension, kExtension,
}; };
RenderProcessHostPrivilege GetPrivilegeRequiredByUrl( RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
@ -253,12 +253,12 @@ RenderProcessHostPrivilege GetPrivilegeRequiredByUrl(
// than normal webrenderer, the navigation logic will correct us out of band // than normal webrenderer, the navigation logic will correct us out of band
// anyways. // anyways.
if (!url.is_valid()) if (!url.is_valid())
return RenderProcessHostPrivilege::Normal; return RenderProcessHostPrivilege::kNormal;
if (!url.SchemeIs(extensions::kExtensionScheme)) if (!url.SchemeIs(extensions::kExtensionScheme))
return RenderProcessHostPrivilege::Normal; return RenderProcessHostPrivilege::kNormal;
return RenderProcessHostPrivilege::Extension; return RenderProcessHostPrivilege::kExtension;
} }
RenderProcessHostPrivilege GetProcessPrivilege( RenderProcessHostPrivilege GetProcessPrivilege(
@ -268,9 +268,9 @@ RenderProcessHostPrivilege GetProcessPrivilege(
std::set<std::string> extension_ids = std::set<std::string> extension_ids =
process_map->GetExtensionsInProcess(process_host->GetID()); process_map->GetExtensionsInProcess(process_host->GetID());
if (extension_ids.empty()) if (extension_ids.empty())
return RenderProcessHostPrivilege::Normal; return RenderProcessHostPrivilege::kNormal;
return RenderProcessHostPrivilege::Extension; return RenderProcessHostPrivilege::kExtension;
} }
const extensions::Extension* GetEnabledExtensionFromEffectiveURL( const extensions::Extension* GetEnabledExtensionFromEffectiveURL(

View file

@ -206,7 +206,7 @@ ElectronBrowserMainParts::ElectronBrowserMainParts(
: fake_browser_process_(new BrowserProcessImpl), : fake_browser_process_(new BrowserProcessImpl),
browser_(new Browser), browser_(new Browser),
node_bindings_( node_bindings_(
NodeBindings::Create(NodeBindings::BrowserEnvironment::BROWSER)), NodeBindings::Create(NodeBindings::BrowserEnvironment::kBrowser)),
electron_bindings_(new ElectronBindings(node_bindings_->uv_loop())) { electron_bindings_(new ElectronBindings(node_bindings_->uv_loop())) {
DCHECK(!self_) << "Cannot have two ElectronBrowserMainParts"; DCHECK(!self_) << "Cannot have two ElectronBrowserMainParts";
self_ = this; self_ = this;

View file

@ -34,19 +34,19 @@ void ZoomModeToZoomSettings(WebContentsZoomController::ZoomMode zoom_mode,
api::tabs::ZoomSettings* zoom_settings) { api::tabs::ZoomSettings* zoom_settings) {
DCHECK(zoom_settings); DCHECK(zoom_settings);
switch (zoom_mode) { switch (zoom_mode) {
case WebContentsZoomController::ZoomMode::DEFAULT: case WebContentsZoomController::ZoomMode::kDefault:
zoom_settings->mode = api::tabs::ZOOM_SETTINGS_MODE_AUTOMATIC; zoom_settings->mode = api::tabs::ZOOM_SETTINGS_MODE_AUTOMATIC;
zoom_settings->scope = api::tabs::ZOOM_SETTINGS_SCOPE_PER_ORIGIN; zoom_settings->scope = api::tabs::ZOOM_SETTINGS_SCOPE_PER_ORIGIN;
break; break;
case WebContentsZoomController::ZoomMode::ISOLATED: case WebContentsZoomController::ZoomMode::kIsolated:
zoom_settings->mode = api::tabs::ZOOM_SETTINGS_MODE_AUTOMATIC; zoom_settings->mode = api::tabs::ZOOM_SETTINGS_MODE_AUTOMATIC;
zoom_settings->scope = api::tabs::ZOOM_SETTINGS_SCOPE_PER_TAB; zoom_settings->scope = api::tabs::ZOOM_SETTINGS_SCOPE_PER_TAB;
break; break;
case WebContentsZoomController::ZoomMode::MANUAL: case WebContentsZoomController::ZoomMode::kManual:
zoom_settings->mode = api::tabs::ZOOM_SETTINGS_MODE_MANUAL; zoom_settings->mode = api::tabs::ZOOM_SETTINGS_MODE_MANUAL;
zoom_settings->scope = api::tabs::ZOOM_SETTINGS_SCOPE_PER_TAB; zoom_settings->scope = api::tabs::ZOOM_SETTINGS_SCOPE_PER_TAB;
break; break;
case WebContentsZoomController::ZoomMode::DISABLED: case WebContentsZoomController::ZoomMode::kDisabled:
zoom_settings->mode = api::tabs::ZOOM_SETTINGS_MODE_DISABLED; zoom_settings->mode = api::tabs::ZOOM_SETTINGS_MODE_DISABLED;
zoom_settings->scope = api::tabs::ZOOM_SETTINGS_SCOPE_PER_TAB; zoom_settings->scope = api::tabs::ZOOM_SETTINGS_SCOPE_PER_TAB;
break; break;
@ -282,24 +282,24 @@ ExtensionFunction::ResponseAction TabsSetZoomSettingsFunction::Run() {
// Determine the correct internal zoom mode to set |web_contents| to from the // Determine the correct internal zoom mode to set |web_contents| to from the
// user-specified |zoom_settings|. // user-specified |zoom_settings|.
WebContentsZoomController::ZoomMode zoom_mode = WebContentsZoomController::ZoomMode zoom_mode =
WebContentsZoomController::ZoomMode::DEFAULT; WebContentsZoomController::ZoomMode::kDefault;
switch (params->zoom_settings.mode) { switch (params->zoom_settings.mode) {
case tabs::ZOOM_SETTINGS_MODE_NONE: case tabs::ZOOM_SETTINGS_MODE_NONE:
case tabs::ZOOM_SETTINGS_MODE_AUTOMATIC: case tabs::ZOOM_SETTINGS_MODE_AUTOMATIC:
switch (params->zoom_settings.scope) { switch (params->zoom_settings.scope) {
case tabs::ZOOM_SETTINGS_SCOPE_NONE: case tabs::ZOOM_SETTINGS_SCOPE_NONE:
case tabs::ZOOM_SETTINGS_SCOPE_PER_ORIGIN: case tabs::ZOOM_SETTINGS_SCOPE_PER_ORIGIN:
zoom_mode = WebContentsZoomController::ZoomMode::DEFAULT; zoom_mode = WebContentsZoomController::ZoomMode::kDefault;
break; break;
case tabs::ZOOM_SETTINGS_SCOPE_PER_TAB: case tabs::ZOOM_SETTINGS_SCOPE_PER_TAB:
zoom_mode = WebContentsZoomController::ZoomMode::ISOLATED; zoom_mode = WebContentsZoomController::ZoomMode::kIsolated;
} }
break; break;
case tabs::ZOOM_SETTINGS_MODE_MANUAL: case tabs::ZOOM_SETTINGS_MODE_MANUAL:
zoom_mode = WebContentsZoomController::ZoomMode::MANUAL; zoom_mode = WebContentsZoomController::ZoomMode::kManual;
break; break;
case tabs::ZOOM_SETTINGS_MODE_DISABLED: case tabs::ZOOM_SETTINGS_MODE_DISABLED:
zoom_mode = WebContentsZoomController::ZoomMode::DISABLED; zoom_mode = WebContentsZoomController::ZoomMode::kDisabled;
} }
contents->GetZoomController()->SetZoomMode(zoom_mode); contents->GetZoomController()->SetZoomMode(zoom_mode);

View file

@ -164,16 +164,16 @@ class NativeWindowMac : public NativeWindow, public ui::NativeThemeObserver {
void OnNativeThemeUpdated(ui::NativeTheme* observed_theme) override; void OnNativeThemeUpdated(ui::NativeTheme* observed_theme) override;
enum class VisualEffectState { enum class VisualEffectState {
FOLLOW_WINDOW, kFollowWindow,
ACTIVE, kActive,
INACTIVE, kInactive,
}; };
enum class TitleBarStyle { enum class TitleBarStyle {
NORMAL, kNormal,
HIDDEN, kHidden,
HIDDEN_INSET, kHiddenInset,
CUSTOM_BUTTONS_ON_HOVER, kCustomButtonsOnHover,
}; };
TitleBarStyle title_bar_style() const { return title_bar_style_; } TitleBarStyle title_bar_style() const { return title_bar_style_; }
@ -228,10 +228,10 @@ class NativeWindowMac : public NativeWindow, public ui::NativeThemeObserver {
NSApplicationPresentationOptions kiosk_options_; NSApplicationPresentationOptions kiosk_options_;
// The "titleBarStyle" option. // The "titleBarStyle" option.
TitleBarStyle title_bar_style_ = TitleBarStyle::NORMAL; TitleBarStyle title_bar_style_ = TitleBarStyle::kNormal;
// The "visualEffectState" option. // The "visualEffectState" option.
VisualEffectState visual_effect_state_ = VisualEffectState::FOLLOW_WINDOW; VisualEffectState visual_effect_state_ = VisualEffectState::kFollowWindow;
// The visibility mode of window button controls when explicitly set through // The visibility mode of window button controls when explicitly set through
// setWindowButtonVisibility(). // setWindowButtonVisibility().

View file

@ -262,11 +262,11 @@ struct Converter<electron::NativeWindowMac::TitleBarStyle> {
if (!ConvertFromV8(isolate, val, &title_bar_style)) if (!ConvertFromV8(isolate, val, &title_bar_style))
return false; return false;
if (title_bar_style == "hidden") { if (title_bar_style == "hidden") {
*out = TitleBarStyle::HIDDEN; *out = TitleBarStyle::kHidden;
} else if (title_bar_style == "hiddenInset") { } else if (title_bar_style == "hiddenInset") {
*out = TitleBarStyle::HIDDEN_INSET; *out = TitleBarStyle::kHiddenInset;
} else if (title_bar_style == "customButtonsOnHover") { } else if (title_bar_style == "customButtonsOnHover") {
*out = TitleBarStyle::CUSTOM_BUTTONS_ON_HOVER; *out = TitleBarStyle::kCustomButtonsOnHover;
} else { } else {
return false; return false;
} }
@ -284,11 +284,11 @@ struct Converter<electron::NativeWindowMac::VisualEffectState> {
if (!ConvertFromV8(isolate, val, &visual_effect_state)) if (!ConvertFromV8(isolate, val, &visual_effect_state))
return false; return false;
if (visual_effect_state == "followWindow") { if (visual_effect_state == "followWindow") {
*out = VisualEffectState::FOLLOW_WINDOW; *out = VisualEffectState::kFollowWindow;
} else if (visual_effect_state == "active") { } else if (visual_effect_state == "active") {
*out = VisualEffectState::ACTIVE; *out = VisualEffectState::kActive;
} else if (visual_effect_state == "inactive") { } else if (visual_effect_state == "inactive") {
*out = VisualEffectState::INACTIVE; *out = VisualEffectState::kInactive;
} else { } else {
return false; return false;
} }
@ -392,8 +392,7 @@ NativeWindowMac::NativeWindowMac(const gin_helper::Dictionary& options,
} }
NSUInteger styleMask = NSWindowStyleMaskTitled; NSUInteger styleMask = NSWindowStyleMaskTitled;
bool customOnHover = bool customOnHover = title_bar_style_ == TitleBarStyle::kCustomButtonsOnHover;
title_bar_style_ == TitleBarStyle::CUSTOM_BUTTONS_ON_HOVER;
if (customOnHover && (!useStandardWindow || transparent() || !has_frame())) if (customOnHover && (!useStandardWindow || transparent() || !has_frame()))
styleMask = NSWindowStyleMaskFullSizeContentView; styleMask = NSWindowStyleMaskFullSizeContentView;
@ -405,7 +404,7 @@ NativeWindowMac::NativeWindowMac(const gin_helper::Dictionary& options,
styleMask |= NSResizableWindowMask; styleMask |= NSResizableWindowMask;
// The window without titlebar is treated the same with frameless window. // The window without titlebar is treated the same with frameless window.
if (title_bar_style_ != TitleBarStyle::NORMAL) if (title_bar_style_ != TitleBarStyle::kNormal)
set_has_frame(false); set_has_frame(false);
if (!useStandardWindow || transparent() || !has_frame()) if (!useStandardWindow || transparent() || !has_frame())
styleMask |= NSTexturedBackgroundWindowMask; styleMask |= NSTexturedBackgroundWindowMask;
@ -470,12 +469,12 @@ NativeWindowMac::NativeWindowMac(const gin_helper::Dictionary& options,
} }
// Hide the title bar background // Hide the title bar background
if (title_bar_style_ != TitleBarStyle::NORMAL) { if (title_bar_style_ != TitleBarStyle::kNormal) {
[window_ setTitlebarAppearsTransparent:YES]; [window_ setTitlebarAppearsTransparent:YES];
} }
// Hide the title bar. // Hide the title bar.
if (title_bar_style_ == TitleBarStyle::HIDDEN_INSET) { if (title_bar_style_ == TitleBarStyle::kHiddenInset) {
base::scoped_nsobject<NSToolbar> toolbar( base::scoped_nsobject<NSToolbar> toolbar(
[[NSToolbar alloc] initWithIdentifier:@"titlebarStylingToolbar"]); [[NSToolbar alloc] initWithIdentifier:@"titlebarStylingToolbar"]);
[toolbar setShowsBaselineSeparator:NO]; [toolbar setShowsBaselineSeparator:NO];
@ -1044,7 +1043,7 @@ void NativeWindowMac::Invalidate() {
void NativeWindowMac::SetTitle(const std::string& title) { void NativeWindowMac::SetTitle(const std::string& title) {
[window_ setTitle:base::SysUTF8ToNSString(title)]; [window_ setTitle:base::SysUTF8ToNSString(title)];
if (title_bar_style_ == TitleBarStyle::HIDDEN) { if (title_bar_style_ == TitleBarStyle::kHidden) {
RedrawTrafficLights(); RedrawTrafficLights();
} }
} }
@ -1445,7 +1444,7 @@ bool NativeWindowMac::AddTabbedWindow(NativeWindow* window) {
} }
bool NativeWindowMac::SetWindowButtonVisibility(bool visible) { bool NativeWindowMac::SetWindowButtonVisibility(bool visible) {
if (title_bar_style_ == TitleBarStyle::CUSTOM_BUTTONS_ON_HOVER) { if (title_bar_style_ == TitleBarStyle::kCustomButtonsOnHover) {
return false; return false;
} }
@ -1477,7 +1476,7 @@ void NativeWindowMac::SetVibrancy(const std::string& type) {
background_color_before_vibrancy_.reset([[window_ backgroundColor] retain]); background_color_before_vibrancy_.reset([[window_ backgroundColor] retain]);
transparency_before_vibrancy_ = [window_ titlebarAppearsTransparent]; transparency_before_vibrancy_ = [window_ titlebarAppearsTransparent];
if (title_bar_style_ != TitleBarStyle::NORMAL) { if (title_bar_style_ != TitleBarStyle::kNormal) {
[window_ setTitlebarAppearsTransparent:YES]; [window_ setTitlebarAppearsTransparent:YES];
[window_ setBackgroundColor:[NSColor clearColor]]; [window_ setBackgroundColor:[NSColor clearColor]];
} }
@ -1491,9 +1490,9 @@ void NativeWindowMac::SetVibrancy(const std::string& type) {
[effect_view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; [effect_view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[effect_view setBlendingMode:NSVisualEffectBlendingModeBehindWindow]; [effect_view setBlendingMode:NSVisualEffectBlendingModeBehindWindow];
if (visual_effect_state_ == VisualEffectState::ACTIVE) { if (visual_effect_state_ == VisualEffectState::kActive) {
[effect_view setState:NSVisualEffectStateActive]; [effect_view setState:NSVisualEffectStateActive];
} else if (visual_effect_state_ == VisualEffectState::INACTIVE) { } else if (visual_effect_state_ == VisualEffectState::kInactive) {
[effect_view setState:NSVisualEffectStateInactive]; [effect_view setState:NSVisualEffectStateInactive];
} else { } else {
[effect_view setState:NSVisualEffectStateFollowsWindowActiveState]; [effect_view setState:NSVisualEffectStateFollowsWindowActiveState];
@ -1698,7 +1697,7 @@ void NativeWindowMac::AddContentViewLayers(bool minimizable, bool closable) {
// The fullscreen button should always be hidden for frameless window. // The fullscreen button should always be hidden for frameless window.
[[window_ standardWindowButton:NSWindowFullScreenButton] setHidden:YES]; [[window_ standardWindowButton:NSWindowFullScreenButton] setHidden:YES];
if (title_bar_style_ == TitleBarStyle::CUSTOM_BUTTONS_ON_HOVER) { if (title_bar_style_ == TitleBarStyle::kCustomButtonsOnHover) {
buttons_view_.reset( buttons_view_.reset(
[[CustomWindowButtonView alloc] initWithFrame:NSZeroRect]); [[CustomWindowButtonView alloc] initWithFrame:NSZeroRect]);
@ -1712,7 +1711,7 @@ void NativeWindowMac::AddContentViewLayers(bool minimizable, bool closable) {
[[window_ contentView] addSubview:buttons_view_]; [[window_ contentView] addSubview:buttons_view_];
} else { } else {
if (title_bar_style_ != TitleBarStyle::NORMAL) if (title_bar_style_ != TitleBarStyle::kNormal)
return; return;
// Hide the window buttons. // Hide the window buttons.

View file

@ -380,15 +380,15 @@ void ProxyingWebSocket::OnAuthRequiredComplete(AuthRequiredResponse rv) {
CHECK(auth_required_callback_); CHECK(auth_required_callback_);
ResumeIncomingMethodCallProcessing(); ResumeIncomingMethodCallProcessing();
switch (rv) { switch (rv) {
case AuthRequiredResponse::AUTH_REQUIRED_RESPONSE_NO_ACTION: case AuthRequiredResponse::kNoAction:
case AuthRequiredResponse::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH: case AuthRequiredResponse::kCancelAuth:
std::move(auth_required_callback_).Run(base::nullopt); std::move(auth_required_callback_).Run(base::nullopt);
break; break;
case AuthRequiredResponse::AUTH_REQUIRED_RESPONSE_SET_AUTH: case AuthRequiredResponse::kSetAuth:
std::move(auth_required_callback_).Run(auth_credentials_); std::move(auth_required_callback_).Run(auth_credentials_);
break; break;
case AuthRequiredResponse::AUTH_REQUIRED_RESPONSE_IO_PENDING: case AuthRequiredResponse::kIoPending:
NOTREACHED(); NOTREACHED();
break; break;
} }
@ -406,7 +406,7 @@ void ProxyingWebSocket::OnHeadersReceivedCompleteForAuth(
auto continuation = base::BindRepeating( auto continuation = base::BindRepeating(
&ProxyingWebSocket::OnAuthRequiredComplete, weak_factory_.GetWeakPtr()); &ProxyingWebSocket::OnAuthRequiredComplete, weak_factory_.GetWeakPtr());
auto auth_rv = AuthRequiredResponse::AUTH_REQUIRED_RESPONSE_IO_PENDING; auto auth_rv = AuthRequiredResponse::kIoPending;
PauseIncomingMethodCallProcessing(); PauseIncomingMethodCallProcessing();
OnAuthRequiredComplete(auth_rv); OnAuthRequiredComplete(auth_rv);

View file

@ -40,16 +40,16 @@ class ProxyingWebSocket : public network::mojom::WebSocketHandshakeClient,
// AuthRequiredResponse indicates how an OnAuthRequired call is handled. // AuthRequiredResponse indicates how an OnAuthRequired call is handled.
enum class AuthRequiredResponse { enum class AuthRequiredResponse {
// No credentials were provided. // No credentials were provided.
AUTH_REQUIRED_RESPONSE_NO_ACTION, kNoAction,
// AuthCredentials is filled in with a username and password, which should // AuthCredentials is filled in with a username and password, which should
// be used in a response to the provided auth challenge. // be used in a response to the provided auth challenge.
AUTH_REQUIRED_RESPONSE_SET_AUTH, kSetAuth,
// The request should be canceled. // The request should be canceled.
AUTH_REQUIRED_RESPONSE_CANCEL_AUTH, kCancelAuth,
// The action will be decided asynchronously. |callback| will be invoked // The action will be decided asynchronously. |callback| will be invoked
// when the decision is made, and one of the other AuthRequiredResponse // when the decision is made, and one of the other AuthRequiredResponse
// values will be passed in with the same semantics as described above. // values will be passed in with the same semantics as described above.
AUTH_REQUIRED_RESPONSE_IO_PENDING, kIoPending,
}; };
ProxyingWebSocket( ProxyingWebSocket(

View file

@ -17,7 +17,7 @@ class Arguments;
namespace electron { namespace electron {
// Possible bundle movement conflicts // Possible bundle movement conflicts
enum class BundlerMoverConflictType { EXISTS, EXISTS_AND_RUNNING }; enum class BundlerMoverConflictType { kExists, kExistsAndRunning };
class ElectronBundleMover { class ElectronBundleMover {
public: public:

View file

@ -24,9 +24,9 @@ struct Converter<electron::BundlerMoverConflictType> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
electron::BundlerMoverConflictType value) { electron::BundlerMoverConflictType value) {
switch (value) { switch (value) {
case electron::BundlerMoverConflictType::EXISTS: case electron::BundlerMoverConflictType::kExists:
return gin::StringToV8(isolate, "exists"); return gin::StringToV8(isolate, "exists");
case electron::BundlerMoverConflictType::EXISTS_AND_RUNNING: case electron::BundlerMoverConflictType::kExistsAndRunning:
return gin::StringToV8(isolate, "existsAndRunning"); return gin::StringToV8(isolate, "existsAndRunning");
default: default:
return gin::StringToV8(isolate, ""); return gin::StringToV8(isolate, "");
@ -117,7 +117,7 @@ bool ElectronBundleMover::Move(gin_helper::ErrorThrower thrower,
if (IsApplicationAtPathRunning(destinationPath)) { if (IsApplicationAtPathRunning(destinationPath)) {
// Check for callback handler and get user choice for open/quit // Check for callback handler and get user choice for open/quit
if (!ShouldContinueMove( if (!ShouldContinueMove(
thrower, BundlerMoverConflictType::EXISTS_AND_RUNNING, args)) thrower, BundlerMoverConflictType::kExistsAndRunning, args))
return false; return false;
// Unless explicitly denied, give running app focus and terminate self // Unless explicitly denied, give running app focus and terminate self
@ -130,7 +130,7 @@ bool ElectronBundleMover::Move(gin_helper::ErrorThrower thrower,
return true; return true;
} else { } else {
// Check callback handler and get user choice for app trashing // Check callback handler and get user choice for app trashing
if (!ShouldContinueMove(thrower, BundlerMoverConflictType::EXISTS, if (!ShouldContinueMove(thrower, BundlerMoverConflictType::kExists,
args)) args))
return false; return false;

View file

@ -193,7 +193,7 @@ bool ScopedDisableResize::disable_resize_ = false;
- (void)performClose:(id)sender { - (void)performClose:(id)sender {
if (shell_->title_bar_style() == if (shell_->title_bar_style() ==
electron::NativeWindowMac::TitleBarStyle::CUSTOM_BUTTONS_ON_HOVER) { electron::NativeWindowMac::TitleBarStyle::kCustomButtonsOnHover) {
[[self delegate] windowShouldClose:self]; [[self delegate] windowShouldClose:self];
} else if (shell_->IsSimpleFullScreen()) { } else if (shell_->IsSimpleFullScreen()) {
if ([[self delegate] respondsToSelector:@selector(windowShouldClose:)]) { if ([[self delegate] respondsToSelector:@selector(windowShouldClose:)]) {
@ -234,7 +234,7 @@ bool ScopedDisableResize::disable_resize_ = false;
- (void)performMiniaturize:(id)sender { - (void)performMiniaturize:(id)sender {
if (shell_->title_bar_style() == if (shell_->title_bar_style() ==
electron::NativeWindowMac::TitleBarStyle::CUSTOM_BUTTONS_ON_HOVER) electron::NativeWindowMac::TitleBarStyle::kCustomButtonsOnHover)
[self miniaturize:self]; [self miniaturize:self];
else else
[super performMiniaturize:sender]; [super performMiniaturize:sender];

View file

@ -151,7 +151,7 @@ using TitleBarStyle = electron::NativeWindowMac::TitleBarStyle;
- (void)windowDidResize:(NSNotification*)notification { - (void)windowDidResize:(NSNotification*)notification {
[super windowDidResize:notification]; [super windowDidResize:notification];
shell_->NotifyWindowResize(); shell_->NotifyWindowResize();
if (shell_->title_bar_style() == TitleBarStyle::HIDDEN) { if (shell_->title_bar_style() == TitleBarStyle::kHidden) {
shell_->RedrawTrafficLights(); shell_->RedrawTrafficLights();
} }
} }
@ -216,7 +216,7 @@ using TitleBarStyle = electron::NativeWindowMac::TitleBarStyle;
shell_->SetResizable(true); shell_->SetResizable(true);
// Hide the native toolbar before entering fullscreen, so there is no visual // Hide the native toolbar before entering fullscreen, so there is no visual
// artifacts. // artifacts.
if (shell_->title_bar_style() == TitleBarStyle::HIDDEN_INSET) { if (shell_->title_bar_style() == TitleBarStyle::kHiddenInset) {
NSWindow* window = shell_->GetNativeWindow().GetNativeNSWindow(); NSWindow* window = shell_->GetNativeWindow().GetNativeNSWindow();
[window setToolbar:nil]; [window setToolbar:nil];
} }
@ -233,14 +233,14 @@ using TitleBarStyle = electron::NativeWindowMac::TitleBarStyle;
// FIXME(zcbenz): Showing titlebar for hiddenInset window is weird under // FIXME(zcbenz): Showing titlebar for hiddenInset window is weird under
// fullscreen mode. // fullscreen mode.
// Show title if fullscreen_window_title flag is set // Show title if fullscreen_window_title flag is set
(shell_->title_bar_style() != TitleBarStyle::HIDDEN_INSET || (shell_->title_bar_style() != TitleBarStyle::kHiddenInset ||
shell_->fullscreen_window_title())) { shell_->fullscreen_window_title())) {
[window setTitleVisibility:NSWindowTitleVisible]; [window setTitleVisibility:NSWindowTitleVisible];
} }
// Restore the native toolbar immediately after entering fullscreen, if we // Restore the native toolbar immediately after entering fullscreen, if we
// do this before leaving fullscreen, traffic light buttons will be jumping. // do this before leaving fullscreen, traffic light buttons will be jumping.
if (shell_->title_bar_style() == TitleBarStyle::HIDDEN_INSET) { if (shell_->title_bar_style() == TitleBarStyle::kHiddenInset) {
base::scoped_nsobject<NSToolbar> toolbar( base::scoped_nsobject<NSToolbar> toolbar(
[[NSToolbar alloc] initWithIdentifier:@"titlebarStylingToolbar"]); [[NSToolbar alloc] initWithIdentifier:@"titlebarStylingToolbar"]);
[toolbar setShowsBaselineSeparator:NO]; [toolbar setShowsBaselineSeparator:NO];
@ -257,18 +257,18 @@ using TitleBarStyle = electron::NativeWindowMac::TitleBarStyle;
// Restore the titlebar visibility. // Restore the titlebar visibility.
NSWindow* window = shell_->GetNativeWindow().GetNativeNSWindow(); NSWindow* window = shell_->GetNativeWindow().GetNativeNSWindow();
if ((shell_->transparent() || !shell_->has_frame()) && if ((shell_->transparent() || !shell_->has_frame()) &&
(shell_->title_bar_style() != TitleBarStyle::HIDDEN_INSET || (shell_->title_bar_style() != TitleBarStyle::kHiddenInset ||
shell_->fullscreen_window_title())) { shell_->fullscreen_window_title())) {
[window setTitleVisibility:NSWindowTitleHidden]; [window setTitleVisibility:NSWindowTitleHidden];
} }
// Turn off the style for toolbar. // Turn off the style for toolbar.
if (shell_->title_bar_style() == TitleBarStyle::HIDDEN_INSET) { if (shell_->title_bar_style() == TitleBarStyle::kHiddenInset) {
shell_->SetStyleMask(false, NSWindowStyleMaskFullSizeContentView); shell_->SetStyleMask(false, NSWindowStyleMaskFullSizeContentView);
[window setTitlebarAppearsTransparent:YES]; [window setTitlebarAppearsTransparent:YES];
} }
shell_->SetExitingFullScreen(true); shell_->SetExitingFullScreen(true);
if (shell_->title_bar_style() == TitleBarStyle::HIDDEN) { if (shell_->title_bar_style() == TitleBarStyle::kHidden) {
shell_->RedrawTrafficLights(); shell_->RedrawTrafficLights();
} }
} }
@ -277,7 +277,7 @@ using TitleBarStyle = electron::NativeWindowMac::TitleBarStyle;
shell_->SetResizable(is_resizable_); shell_->SetResizable(is_resizable_);
shell_->NotifyWindowLeaveFullScreen(); shell_->NotifyWindowLeaveFullScreen();
shell_->SetExitingFullScreen(false); shell_->SetExitingFullScreen(false);
if (shell_->title_bar_style() == TitleBarStyle::HIDDEN) { if (shell_->title_bar_style() == TitleBarStyle::kHidden) {
shell_->RedrawTrafficLights(); shell_->RedrawTrafficLights();
} }
} }

View file

@ -55,10 +55,10 @@ class TrayIcon {
virtual std::string GetTitle() = 0; virtual std::string GetTitle() = 0;
#endif #endif
enum class IconType { None, Info, Warning, Error, Custom }; enum class IconType { kNone, kInfo, kWarning, kError, kCustom };
struct BalloonOptions { struct BalloonOptions {
IconType icon_type = IconType::Custom; IconType icon_type = IconType::kCustom;
#if defined(OS_WIN) #if defined(OS_WIN)
HICON icon = nullptr; HICON icon = nullptr;
#else #else

View file

@ -83,7 +83,7 @@ bool ConvertShellLinkToJumpListItem(IShellLink* shell_link,
DCHECK(shell_link); DCHECK(shell_link);
DCHECK(item); DCHECK(item);
item->type = JumpListItem::Type::TASK; item->type = JumpListItem::Type::kTask;
wchar_t path[MAX_PATH]; wchar_t path[MAX_PATH];
if (FAILED(shell_link->GetPath(path, base::size(path), nullptr, 0))) if (FAILED(shell_link->GetPath(path, base::size(path), nullptr, 0)))
return false; return false;
@ -134,7 +134,7 @@ void ConvertRemovedJumpListItems(IObjectArray* in,
IShellLink* shell_link; IShellLink* shell_link;
for (UINT i = 0; i < removed_count; ++i) { for (UINT i = 0; i < removed_count; ++i) {
if (SUCCEEDED(in->GetAt(i, IID_PPV_ARGS(&shell_item)))) { if (SUCCEEDED(in->GetAt(i, IID_PPV_ARGS(&shell_item)))) {
item.type = JumpListItem::Type::FILE; item.type = JumpListItem::Type::kFile;
GetShellItemFileName(shell_item, &item.path); GetShellItemFileName(shell_item, &item.path);
out->push_back(item); out->push_back(item);
shell_item->Release(); shell_item->Release();
@ -217,22 +217,22 @@ bool JumpList::Delete() {
JumpListResult JumpList::AppendCategory(const JumpListCategory& category) { JumpListResult JumpList::AppendCategory(const JumpListCategory& category) {
DCHECK(destinations_); DCHECK(destinations_);
if (!destinations_) if (!destinations_)
return JumpListResult::GENERIC_ERROR; return JumpListResult::kGenericError;
if (category.items.empty()) if (category.items.empty())
return JumpListResult::SUCCESS; return JumpListResult::kSuccess;
CComPtr<IObjectCollection> collection; CComPtr<IObjectCollection> collection;
if (FAILED(collection.CoCreateInstance(CLSID_EnumerableObjectCollection))) { if (FAILED(collection.CoCreateInstance(CLSID_EnumerableObjectCollection))) {
return JumpListResult::GENERIC_ERROR; return JumpListResult::kGenericError;
} }
auto result = JumpListResult::SUCCESS; auto result = JumpListResult::kSuccess;
// Keep track of how many items were actually appended to the category. // Keep track of how many items were actually appended to the category.
int appended_count = 0; int appended_count = 0;
for (const auto& item : category.items) { for (const auto& item : category.items) {
switch (item.type) { switch (item.type) {
case JumpListItem::Type::TASK: case JumpListItem::Type::kTask:
if (AppendTask(item, collection)) if (AppendTask(item, collection))
++appended_count; ++appended_count;
else else
@ -241,8 +241,8 @@ JumpListResult JumpList::AppendCategory(const JumpListCategory& category) {
"to Jump List."; "to Jump List.";
break; break;
case JumpListItem::Type::SEPARATOR: case JumpListItem::Type::kSeparator:
if (category.type == JumpListCategory::Type::TASKS) { if (category.type == JumpListCategory::Type::kTasks) {
if (AppendSeparator(collection)) if (AppendSeparator(collection))
++appended_count; ++appended_count;
} else { } else {
@ -250,11 +250,11 @@ JumpListResult JumpList::AppendCategory(const JumpListCategory& category) {
<< "'" << category.name << "'. " << "'" << category.name << "'. "
<< "Separators are only allowed in the standard 'Tasks' " << "Separators are only allowed in the standard 'Tasks' "
"Jump List category."; "Jump List category.";
result = JumpListResult::CUSTOM_CATEGORY_SEPARATOR_ERROR; result = JumpListResult::kCustomCategorySeparatorError;
} }
break; break;
case JumpListItem::Type::FILE: case JumpListItem::Type::kFile:
if (AppendFile(item, collection)) if (AppendFile(item, collection))
++appended_count; ++appended_count;
else else
@ -269,17 +269,17 @@ JumpListResult JumpList::AppendCategory(const JumpListCategory& category) {
return result; return result;
if ((static_cast<size_t>(appended_count) < category.items.size()) && if ((static_cast<size_t>(appended_count) < category.items.size()) &&
(result == JumpListResult::SUCCESS)) { (result == JumpListResult::kSuccess)) {
result = JumpListResult::GENERIC_ERROR; result = JumpListResult::kGenericError;
} }
CComQIPtr<IObjectArray> items(collection); CComQIPtr<IObjectArray> items(collection);
if (category.type == JumpListCategory::Type::TASKS) { if (category.type == JumpListCategory::Type::kTasks) {
if (FAILED(destinations_->AddUserTasks(items))) { if (FAILED(destinations_->AddUserTasks(items))) {
LOG(ERROR) << "Failed to append items to the standard Tasks category."; LOG(ERROR) << "Failed to append items to the standard Tasks category.";
if (result == JumpListResult::SUCCESS) if (result == JumpListResult::kSuccess)
result = JumpListResult::GENERIC_ERROR; result = JumpListResult::kGenericError;
} }
} else { } else {
HRESULT hr = destinations_->AppendCategory(category.name.c_str(), items); HRESULT hr = destinations_->AppendCategory(category.name.c_str(), items);
@ -288,17 +288,17 @@ JumpListResult JumpList::AppendCategory(const JumpListCategory& category) {
LOG(ERROR) << "Failed to append custom category " LOG(ERROR) << "Failed to append custom category "
<< "'" << category.name << "' " << "'" << category.name << "' "
<< "to Jump List due to missing file type registration."; << "to Jump List due to missing file type registration.";
result = JumpListResult::MISSING_FILE_TYPE_REGISTRATION_ERROR; result = JumpListResult::kMissingFileTypeRegistrationError;
} else if (hr == E_ACCESSDENIED) { } else if (hr == E_ACCESSDENIED) {
LOG(ERROR) << "Failed to append custom category " LOG(ERROR) << "Failed to append custom category "
<< "'" << category.name << "' " << "'" << category.name << "' "
<< "to Jump List due to system privacy settings."; << "to Jump List due to system privacy settings.";
result = JumpListResult::CUSTOM_CATEGORY_ACCESS_DENIED_ERROR; result = JumpListResult::kCustomCategoryAccessDeniedError;
} else { } else {
LOG(ERROR) << "Failed to append custom category " LOG(ERROR) << "Failed to append custom category "
<< "'" << category.name << "' to Jump List."; << "'" << category.name << "' to Jump List.";
if (result == JumpListResult::SUCCESS) if (result == JumpListResult::kSuccess)
result = JumpListResult::GENERIC_ERROR; result = JumpListResult::kGenericError;
} }
} }
} }
@ -313,36 +313,36 @@ JumpListResult JumpList::AppendCategories(
const std::vector<JumpListCategory>& categories) { const std::vector<JumpListCategory>& categories) {
DCHECK(destinations_); DCHECK(destinations_);
if (!destinations_) if (!destinations_)
return JumpListResult::GENERIC_ERROR; return JumpListResult::kGenericError;
auto result = JumpListResult::SUCCESS; auto result = JumpListResult::kSuccess;
for (const auto& category : categories) { for (const auto& category : categories) {
auto latestResult = JumpListResult::SUCCESS; auto latestResult = JumpListResult::kSuccess;
switch (category.type) { switch (category.type) {
case JumpListCategory::Type::TASKS: case JumpListCategory::Type::kTasks:
case JumpListCategory::Type::CUSTOM: case JumpListCategory::Type::kCustom:
latestResult = AppendCategory(category); latestResult = AppendCategory(category);
break; break;
case JumpListCategory::Type::RECENT: case JumpListCategory::Type::kRecent:
if (FAILED(destinations_->AppendKnownCategory(KDC_RECENT))) { if (FAILED(destinations_->AppendKnownCategory(KDC_RECENT))) {
LOG(ERROR) << "Failed to append Recent category to Jump List."; LOG(ERROR) << "Failed to append Recent category to Jump List.";
latestResult = JumpListResult::GENERIC_ERROR; latestResult = JumpListResult::kGenericError;
} }
break; break;
case JumpListCategory::Type::FREQUENT: case JumpListCategory::Type::kFrequent:
if (FAILED(destinations_->AppendKnownCategory(KDC_FREQUENT))) { if (FAILED(destinations_->AppendKnownCategory(KDC_FREQUENT))) {
LOG(ERROR) << "Failed to append Frequent category to Jump List."; LOG(ERROR) << "Failed to append Frequent category to Jump List.";
latestResult = JumpListResult::GENERIC_ERROR; latestResult = JumpListResult::kGenericError;
} }
break; break;
} }
// Keep the first non-generic error code as only one can be returned from // Keep the first non-generic error code as only one can be returned from
// the function (so try to make it the most useful one). // the function (so try to make it the most useful one).
if (((result == JumpListResult::SUCCESS) || if (((result == JumpListResult::kSuccess) ||
(result == JumpListResult::GENERIC_ERROR)) && (result == JumpListResult::kGenericError)) &&
(latestResult != JumpListResult::SUCCESS)) (latestResult != JumpListResult::kSuccess))
result = latestResult; result = latestResult;
} }
return result; return result;

View file

@ -15,34 +15,34 @@
namespace electron { namespace electron {
enum class JumpListResult : int { enum class JumpListResult : int {
SUCCESS = 0, kSuccess = 0,
// In JS code this error will manifest as an exception. // In JS code this error will manifest as an exception.
ARGUMENT_ERROR = 1, kArgumentError = 1,
// Generic error, the runtime logs may provide some clues. // Generic error, the runtime logs may provide some clues.
GENERIC_ERROR = 2, kGenericError = 2,
// Custom categories can't contain separators. // Custom categories can't contain separators.
CUSTOM_CATEGORY_SEPARATOR_ERROR = 3, kCustomCategorySeparatorError = 3,
// The app isn't registered to handle a file type found in a custom category. // The app isn't registered to handle a file type found in a custom category.
MISSING_FILE_TYPE_REGISTRATION_ERROR = 4, kMissingFileTypeRegistrationError = 4,
// Custom categories can't be created due to user privacy settings. // Custom categories can't be created due to user privacy settings.
CUSTOM_CATEGORY_ACCESS_DENIED_ERROR = 5, kCustomCategoryAccessDeniedError = 5,
}; };
struct JumpListItem { struct JumpListItem {
enum class Type { enum class Type {
// A task will launch an app (usually the one that created the Jump List) // A task will launch an app (usually the one that created the Jump List)
// with specific arguments. // with specific arguments.
TASK, kTask,
// Separators can only be inserted between items in the standard Tasks // Separators can only be inserted between items in the standard Tasks
// category, they can't appear in custom categories. // category, they can't appear in custom categories.
SEPARATOR, kSeparator,
// A file link will open a file using the app that created the Jump List, // A file link will open a file using the app that created the Jump List,
// for this to work the app must be registered as a handler for the file // for this to work the app must be registered as a handler for the file
// type (though the app doesn't have to be the default handler). // type (though the app doesn't have to be the default handler).
FILE kFile
}; };
Type type = Type::TASK; Type type = Type::kTask;
// For tasks this is the path to the program executable, for file links this // For tasks this is the path to the program executable, for file links this
// is the full filename. // is the full filename.
base::FilePath path; base::FilePath path;
@ -61,18 +61,18 @@ struct JumpListItem {
struct JumpListCategory { struct JumpListCategory {
enum class Type { enum class Type {
// A custom category can contain tasks and files, but not separators. // A custom category can contain tasks and files, but not separators.
CUSTOM, kCustom,
// Frequent/Recent categories are managed by the OS, their name and items // Frequent/Recent categories are managed by the OS, their name and items
// can't be set by the app (though items can be set indirectly). // can't be set by the app (though items can be set indirectly).
FREQUENT, kFrequent,
RECENT, kRecent,
// The standard Tasks category can't be renamed by the app, but the app // The standard Tasks category can't be renamed by the app, but the app
// can set the items that should appear in this category, and those items // can set the items that should appear in this category, and those items
// can include tasks, files, and separators. // can include tasks, files, and separators.
TASKS kTasks
}; };
Type type = Type::TASKS; Type type = Type::kTasks;
base::string16 name; base::string16 name;
std::vector<JumpListItem> items; std::vector<JumpListItem> items;

View file

@ -25,15 +25,15 @@ namespace {
UINT ConvertIconType(electron::TrayIcon::IconType type) { UINT ConvertIconType(electron::TrayIcon::IconType type) {
using IconType = electron::TrayIcon::IconType; using IconType = electron::TrayIcon::IconType;
switch (type) { switch (type) {
case IconType::None: case IconType::kNone:
return NIIF_NONE; return NIIF_NONE;
case IconType::Info: case IconType::kInfo:
return NIIF_INFO; return NIIF_INFO;
case IconType::Warning: case IconType::kWarning:
return NIIF_WARNING; return NIIF_WARNING;
case IconType::Error: case IconType::kError:
return NIIF_ERROR; return NIIF_ERROR;
case IconType::Custom: case IconType::kCustom:
return NIIF_USER; return NIIF_USER;
default: default:
NOTREACHED() << "Invalid icon type"; NOTREACHED() << "Invalid icon type";

View file

@ -44,14 +44,14 @@ void WebContentsZoomController::SetEmbedderZoomController(
void WebContentsZoomController::SetZoomLevel(double level) { void WebContentsZoomController::SetZoomLevel(double level) {
if (!web_contents()->GetRenderViewHost()->IsRenderViewLive() || if (!web_contents()->GetRenderViewHost()->IsRenderViewLive() ||
blink::PageZoomValuesEqual(GetZoomLevel(), level) || blink::PageZoomValuesEqual(GetZoomLevel(), level) ||
zoom_mode_ == ZoomMode::DISABLED) zoom_mode_ == ZoomMode::kDisabled)
return; return;
int render_process_id = int render_process_id =
web_contents()->GetRenderViewHost()->GetProcess()->GetID(); web_contents()->GetRenderViewHost()->GetProcess()->GetID();
int render_view_id = web_contents()->GetRenderViewHost()->GetRoutingID(); int render_view_id = web_contents()->GetRenderViewHost()->GetRoutingID();
if (zoom_mode_ == ZoomMode::MANUAL) { if (zoom_mode_ == ZoomMode::kManual) {
zoom_level_ = level; zoom_level_ = level;
for (Observer& observer : observers_) for (Observer& observer : observers_)
@ -62,7 +62,7 @@ void WebContentsZoomController::SetZoomLevel(double level) {
content::HostZoomMap* zoom_map = content::HostZoomMap* zoom_map =
content::HostZoomMap::GetForWebContents(web_contents()); content::HostZoomMap::GetForWebContents(web_contents());
if (zoom_mode_ == ZoomMode::ISOLATED || if (zoom_mode_ == ZoomMode::kIsolated ||
zoom_map->UsesTemporaryZoomLevel(render_process_id, render_view_id)) { zoom_map->UsesTemporaryZoomLevel(render_process_id, render_view_id)) {
zoom_map->SetTemporaryZoomLevel(render_process_id, render_view_id, level); zoom_map->SetTemporaryZoomLevel(render_process_id, render_view_id, level);
// Notify observers of zoom level changes. // Notify observers of zoom level changes.
@ -78,7 +78,7 @@ void WebContentsZoomController::SetZoomLevel(double level) {
} }
double WebContentsZoomController::GetZoomLevel() { double WebContentsZoomController::GetZoomLevel() {
return zoom_mode_ == ZoomMode::MANUAL return zoom_mode_ == ZoomMode::kManual
? zoom_level_ ? zoom_level_
: content::HostZoomMap::GetZoomLevel(web_contents()); : content::HostZoomMap::GetZoomLevel(web_contents());
} }
@ -120,7 +120,7 @@ void WebContentsZoomController::SetZoomMode(ZoomMode new_mode) {
double original_zoom_level = GetZoomLevel(); double original_zoom_level = GetZoomLevel();
switch (new_mode) { switch (new_mode) {
case ZoomMode::DEFAULT: { case ZoomMode::kDefault: {
content::NavigationEntry* entry = content::NavigationEntry* entry =
web_contents()->GetController().GetLastCommittedEntry(); web_contents()->GetController().GetLastCommittedEntry();
@ -148,11 +148,11 @@ void WebContentsZoomController::SetZoomMode(ZoomMode new_mode) {
zoom_map->ClearTemporaryZoomLevel(render_process_id, render_view_id); zoom_map->ClearTemporaryZoomLevel(render_process_id, render_view_id);
break; break;
} }
case ZoomMode::ISOLATED: { case ZoomMode::kIsolated: {
// Unless the zoom mode was |ZoomMode::DISABLED| before this call, the // Unless the zoom mode was |ZoomMode::kDisabled| before this call, the
// page needs an initial isolated zoom back to the same level it was at // page needs an initial isolated zoom back to the same level it was at
// in the other mode. // in the other mode.
if (zoom_mode_ != ZoomMode::DISABLED) { if (zoom_mode_ != ZoomMode::kDisabled) {
zoom_map->SetTemporaryZoomLevel(render_process_id, render_view_id, zoom_map->SetTemporaryZoomLevel(render_process_id, render_view_id,
original_zoom_level); original_zoom_level);
} else { } else {
@ -164,11 +164,11 @@ void WebContentsZoomController::SetZoomMode(ZoomMode new_mode) {
} }
break; break;
} }
case ZoomMode::MANUAL: { case ZoomMode::kManual: {
// Unless the zoom mode was |ZoomMode::DISABLED| before this call, the // Unless the zoom mode was |ZoomMode::kDisabled| before this call, the
// page needs to be resized to the default zoom. While in manual mode, // page needs to be resized to the default zoom. While in manual mode,
// the zoom level is handled independently. // the zoom level is handled independently.
if (zoom_mode_ != ZoomMode::DISABLED) { if (zoom_mode_ != ZoomMode::kDisabled) {
zoom_map->SetTemporaryZoomLevel(render_process_id, render_view_id, zoom_map->SetTemporaryZoomLevel(render_process_id, render_view_id,
GetDefaultZoomLevel()); GetDefaultZoomLevel());
zoom_level_ = original_zoom_level; zoom_level_ = original_zoom_level;
@ -181,7 +181,7 @@ void WebContentsZoomController::SetZoomMode(ZoomMode new_mode) {
} }
break; break;
} }
case ZoomMode::DISABLED: { case ZoomMode::kDisabled: {
// The page needs to be zoomed back to default before disabling the zoom // The page needs to be zoomed back to default before disabling the zoom
zoom_map->SetTemporaryZoomLevel(render_process_id, render_view_id, zoom_map->SetTemporaryZoomLevel(render_process_id, render_view_id,
GetDefaultZoomLevel()); GetDefaultZoomLevel());
@ -194,7 +194,7 @@ void WebContentsZoomController::SetZoomMode(ZoomMode new_mode) {
void WebContentsZoomController::ResetZoomModeOnNavigationIfNeeded( void WebContentsZoomController::ResetZoomModeOnNavigationIfNeeded(
const GURL& url) { const GURL& url) {
if (zoom_mode_ != ZoomMode::ISOLATED && zoom_mode_ != ZoomMode::MANUAL) if (zoom_mode_ != ZoomMode::kIsolated && zoom_mode_ != ZoomMode::kManual)
return; return;
int render_process_id = int render_process_id =
@ -208,7 +208,7 @@ void WebContentsZoomController::ResetZoomModeOnNavigationIfNeeded(
for (Observer& observer : observers_) for (Observer& observer : observers_)
observer.OnZoomLevelChanged(web_contents(), new_zoom_level, false); observer.OnZoomLevelChanged(web_contents(), new_zoom_level, false);
zoom_map->ClearTemporaryZoomLevel(render_process_id, render_view_id); zoom_map->ClearTemporaryZoomLevel(render_process_id, render_view_id);
zoom_mode_ = ZoomMode::DEFAULT; zoom_mode_ = ZoomMode::kDefault;
} }
void WebContentsZoomController::DidFinishNavigation( void WebContentsZoomController::DidFinishNavigation(

View file

@ -36,19 +36,19 @@ class WebContentsZoomController
// Results in default zoom behavior, i.e. zoom changes are handled // Results in default zoom behavior, i.e. zoom changes are handled
// automatically and on a per-origin basis, meaning that other tabs // automatically and on a per-origin basis, meaning that other tabs
// navigated to the same origin will also zoom. // navigated to the same origin will also zoom.
DEFAULT, kDefault,
// Results in zoom changes being handled automatically, but on a per-tab // Results in zoom changes being handled automatically, but on a per-tab
// basis. Tabs in this zoom mode will not be affected by zoom changes in // basis. Tabs in this zoom mode will not be affected by zoom changes in
// other tabs, and vice versa. // other tabs, and vice versa.
ISOLATED, kIsolated,
// Overrides the automatic handling of zoom changes. The |onZoomChange| // Overrides the automatic handling of zoom changes. The |onZoomChange|
// event will still be dispatched, but the page will not actually be zoomed. // event will still be dispatched, but the page will not actually be zoomed.
// These zoom changes can be handled manually by listening for the // These zoom changes can be handled manually by listening for the
// |onZoomChange| event. Zooming in this mode is also on a per-tab basis. // |onZoomChange| event. Zooming in this mode is also on a per-tab basis.
MANUAL, kManual,
// Disables all zooming in this tab. The tab will revert to the default // Disables all zooming in this tab. The tab will revert to the default
// zoom level, and all attempted zoom changes will be ignored. // zoom level, and all attempted zoom changes will be ignored.
DISABLED, kDisabled,
}; };
explicit WebContentsZoomController(content::WebContents* web_contents); explicit WebContentsZoomController(content::WebContents* web_contents);
@ -95,7 +95,7 @@ class WebContentsZoomController
void SetZoomFactorOnNavigationIfNeeded(const GURL& url); void SetZoomFactorOnNavigationIfNeeded(const GURL& url);
// The current zoom mode. // The current zoom mode.
ZoomMode zoom_mode_ = ZoomMode::DEFAULT; ZoomMode zoom_mode_ = ZoomMode::kDefault;
// Current zoom level. // Current zoom level.
double zoom_level_ = 1.0; double zoom_level_ = 1.0;

View file

@ -281,7 +281,7 @@ base::FilePath GetResourcesPath() {
NodeBindings::NodeBindings(BrowserEnvironment browser_env) NodeBindings::NodeBindings(BrowserEnvironment browser_env)
: browser_env_(browser_env), weak_factory_(this) { : browser_env_(browser_env), weak_factory_(this) {
if (browser_env == BrowserEnvironment::WORKER) { if (browser_env == BrowserEnvironment::kWorker) {
uv_loop_init(&worker_loop_); uv_loop_init(&worker_loop_);
uv_loop_ = &worker_loop_; uv_loop_ = &worker_loop_;
} else { } else {
@ -331,7 +331,7 @@ void NodeBindings::Initialize() {
#if defined(OS_LINUX) #if defined(OS_LINUX)
// Get real command line in renderer process forked by zygote. // Get real command line in renderer process forked by zygote.
if (browser_env_ != BrowserEnvironment::BROWSER) if (browser_env_ != BrowserEnvironment::kBrowser)
ElectronCommandLine::InitializeFromCommandLine(); ElectronCommandLine::InitializeFromCommandLine();
#endif #endif
@ -360,7 +360,7 @@ void NodeBindings::Initialize() {
#if defined(OS_WIN) #if defined(OS_WIN)
// uv_init overrides error mode to suppress the default crash dialog, bring // uv_init overrides error mode to suppress the default crash dialog, bring
// it back if user wants to show it. // it back if user wants to show it.
if (browser_env_ == BrowserEnvironment::BROWSER || if (browser_env_ == BrowserEnvironment::kBrowser ||
env->HasVar("ELECTRON_DEFAULT_ERROR_MODE")) env->HasVar("ELECTRON_DEFAULT_ERROR_MODE"))
SetErrorMode(GetErrorMode() & ~SEM_NOGPFAULTERRORBOX); SetErrorMode(GetErrorMode() & ~SEM_NOGPFAULTERRORBOX);
#endif #endif
@ -383,13 +383,13 @@ node::Environment* NodeBindings::CreateEnvironment(
// Feed node the path to initialization script. // Feed node the path to initialization script.
std::string process_type; std::string process_type;
switch (browser_env_) { switch (browser_env_) {
case BrowserEnvironment::BROWSER: case BrowserEnvironment::kBrowser:
process_type = "browser"; process_type = "browser";
break; break;
case BrowserEnvironment::RENDERER: case BrowserEnvironment::kRenderer:
process_type = "renderer"; process_type = "renderer";
break; break;
case BrowserEnvironment::WORKER: case BrowserEnvironment::kWorker:
process_type = "worker"; process_type = "worker";
break; break;
} }
@ -398,7 +398,7 @@ node::Environment* NodeBindings::CreateEnvironment(
// Do not set DOM globals for renderer process. // Do not set DOM globals for renderer process.
// We must set this before the node bootstrapper which is run inside // We must set this before the node bootstrapper which is run inside
// CreateEnvironment // CreateEnvironment
if (browser_env_ != BrowserEnvironment::BROWSER) if (browser_env_ != BrowserEnvironment::kBrowser)
global.Set("_noBrowserGlobals", true); global.Set("_noBrowserGlobals", true);
std::vector<std::string> exec_args; std::vector<std::string> exec_args;
@ -411,7 +411,7 @@ node::Environment* NodeBindings::CreateEnvironment(
node::CreateIsolateData(context->GetIsolate(), uv_loop_, platform); node::CreateIsolateData(context->GetIsolate(), uv_loop_, platform);
node::Environment* env; node::Environment* env;
if (browser_env_ != BrowserEnvironment::BROWSER) { if (browser_env_ != BrowserEnvironment::kBrowser) {
// Only one ESM loader can be registered per isolate - // Only one ESM loader can be registered per isolate -
// in renderer processes this should be blink. We need to tell Node.js // in renderer processes this should be blink. We need to tell Node.js
// not to register its handler (overriding blinks) in non-browser processes. // not to register its handler (overriding blinks) in non-browser processes.
@ -436,7 +436,7 @@ node::Environment* NodeBindings::CreateEnvironment(
// Clean up the global _noBrowserGlobals that we unironically injected into // Clean up the global _noBrowserGlobals that we unironically injected into
// the global scope // the global scope
if (browser_env_ != BrowserEnvironment::BROWSER) { if (browser_env_ != BrowserEnvironment::kBrowser) {
// We need to bootstrap the env in non-browser processes so that // We need to bootstrap the env in non-browser processes so that
// _noBrowserGlobals is read correctly before we remove it // _noBrowserGlobals is read correctly before we remove it
global.Delete("_noBrowserGlobals"); global.Delete("_noBrowserGlobals");
@ -458,7 +458,7 @@ node::Environment* NodeBindings::CreateEnvironment(
// renderer process. // renderer process.
is.allow_wasm_code_generation_callback = AllowWasmCodeGenerationCallback; is.allow_wasm_code_generation_callback = AllowWasmCodeGenerationCallback;
if (browser_env_ == BrowserEnvironment::BROWSER) { if (browser_env_ == BrowserEnvironment::kBrowser) {
// Node.js requires that microtask checkpoints be explicitly invoked. // Node.js requires that microtask checkpoints be explicitly invoked.
is.policy = v8::MicrotasksPolicy::kExplicit; is.policy = v8::MicrotasksPolicy::kExplicit;
} else { } else {
@ -532,13 +532,13 @@ void NodeBindings::UvRunOnce() {
// Perform microtask checkpoint after running JavaScript. // Perform microtask checkpoint after running JavaScript.
gin_helper::MicrotasksScope microtasks_scope(env->isolate()); gin_helper::MicrotasksScope microtasks_scope(env->isolate());
if (browser_env_ != BrowserEnvironment::BROWSER) if (browser_env_ != BrowserEnvironment::kBrowser)
TRACE_EVENT_BEGIN0("devtools.timeline", "FunctionCall"); TRACE_EVENT_BEGIN0("devtools.timeline", "FunctionCall");
// Deal with uv events. // Deal with uv events.
int r = uv_run(uv_loop_, UV_RUN_NOWAIT); int r = uv_run(uv_loop_, UV_RUN_NOWAIT);
if (browser_env_ != BrowserEnvironment::BROWSER) if (browser_env_ != BrowserEnvironment::kBrowser)
TRACE_EVENT_END0("devtools.timeline", "FunctionCall"); TRACE_EVENT_END0("devtools.timeline", "FunctionCall");
if (r == 0) if (r == 0)

View file

@ -76,7 +76,7 @@ class UvHandle {
class NodeBindings { class NodeBindings {
public: public:
enum class BrowserEnvironment { BROWSER, RENDERER, WORKER }; enum class BrowserEnvironment { kBrowser, kRenderer, kWorker };
static NodeBindings* Create(BrowserEnvironment browser_env); static NodeBindings* Create(BrowserEnvironment browser_env);
static void RegisterBuiltinModules(); static void RegisterBuiltinModules();

View file

@ -128,7 +128,7 @@ v8::MaybeLocal<v8::Value> GetPrivate(v8::Local<v8::Context> context,
} }
// Where the context bridge should create the exception it is about to throw // Where the context bridge should create the exception it is about to throw
enum BridgeErrorTarget { enum class BridgeErrorTarget {
// The source / calling context. This is default and correct 99% of the time, // The source / calling context. This is default and correct 99% of the time,
// the caller / context asking for the conversion will receive the error and // the caller / context asking for the conversion will receive the error and
// therefore the error should be made in that context // therefore the error should be made in that context

View file

@ -39,7 +39,7 @@ ElectronRendererClient* ElectronRendererClient::self_ = nullptr;
ElectronRendererClient::ElectronRendererClient() ElectronRendererClient::ElectronRendererClient()
: node_bindings_( : node_bindings_(
NodeBindings::Create(NodeBindings::BrowserEnvironment::RENDERER)), NodeBindings::Create(NodeBindings::BrowserEnvironment::kRenderer)),
electron_bindings_(new ElectronBindings(node_bindings_->uv_loop())) { electron_bindings_(new ElectronBindings(node_bindings_->uv_loop())) {
DCHECK(!self_) << "Cannot have two ElectronRendererClient"; DCHECK(!self_) << "Cannot have two ElectronRendererClient";
self_ = this; self_ = this;

View file

@ -30,7 +30,7 @@ WebWorkerObserver* WebWorkerObserver::GetCurrent() {
WebWorkerObserver::WebWorkerObserver() WebWorkerObserver::WebWorkerObserver()
: node_bindings_( : node_bindings_(
NodeBindings::Create(NodeBindings::BrowserEnvironment::WORKER)), NodeBindings::Create(NodeBindings::BrowserEnvironment::kWorker)),
electron_bindings_(new ElectronBindings(node_bindings_->uv_loop())) { electron_bindings_(new ElectronBindings(node_bindings_->uv_loop())) {
lazy_tls.Pointer()->Set(this); lazy_tls.Pointer()->Set(this);
} }