refactor: Chromium code style for enum classes (#26165)
This commit is contained in:
parent
dbf2931f0e
commit
1c99a9b425
34 changed files with 300 additions and 295 deletions
|
@ -78,13 +78,13 @@ struct Converter<electron::ProcessIntegrityLevel> {
|
|||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
electron::ProcessIntegrityLevel value) {
|
||||
switch (value) {
|
||||
case electron::ProcessIntegrityLevel::Untrusted:
|
||||
case electron::ProcessIntegrityLevel::kUntrusted:
|
||||
return StringToV8(isolate, "untrusted");
|
||||
case electron::ProcessIntegrityLevel::Low:
|
||||
case electron::ProcessIntegrityLevel::kLow:
|
||||
return StringToV8(isolate, "low");
|
||||
case electron::ProcessIntegrityLevel::Medium:
|
||||
case electron::ProcessIntegrityLevel::kMedium:
|
||||
return StringToV8(isolate, "medium");
|
||||
case electron::ProcessIntegrityLevel::High:
|
||||
case electron::ProcessIntegrityLevel::kHigh:
|
||||
return StringToV8(isolate, "high");
|
||||
default:
|
||||
return StringToV8(isolate, "unknown");
|
||||
|
@ -127,11 +127,11 @@ struct Converter<JumpListItem::Type> {
|
|||
return false;
|
||||
|
||||
if (item_type == "task")
|
||||
*out = JumpListItem::Type::TASK;
|
||||
*out = JumpListItem::Type::kTask;
|
||||
else if (item_type == "separator")
|
||||
*out = JumpListItem::Type::SEPARATOR;
|
||||
*out = JumpListItem::Type::kSeparator;
|
||||
else if (item_type == "file")
|
||||
*out = JumpListItem::Type::FILE;
|
||||
*out = JumpListItem::Type::kFile;
|
||||
else
|
||||
return false;
|
||||
|
||||
|
@ -142,15 +142,15 @@ struct Converter<JumpListItem::Type> {
|
|||
JumpListItem::Type val) {
|
||||
std::string item_type;
|
||||
switch (val) {
|
||||
case JumpListItem::Type::TASK:
|
||||
case JumpListItem::Type::kTask:
|
||||
item_type = "task";
|
||||
break;
|
||||
|
||||
case JumpListItem::Type::SEPARATOR:
|
||||
case JumpListItem::Type::kSeparator:
|
||||
item_type = "separator";
|
||||
break;
|
||||
|
||||
case JumpListItem::Type::FILE:
|
||||
case JumpListItem::Type::kFile:
|
||||
item_type = "file";
|
||||
break;
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ struct Converter<JumpListItem> {
|
|||
return false;
|
||||
|
||||
switch (out->type) {
|
||||
case JumpListItem::Type::TASK:
|
||||
case JumpListItem::Type::kTask:
|
||||
if (!dict.Get("program", &(out->path)) ||
|
||||
!dict.Get("title", &(out->title)))
|
||||
return false;
|
||||
|
@ -185,10 +185,10 @@ struct Converter<JumpListItem> {
|
|||
dict.Get("workingDirectory", &(out->working_dir));
|
||||
return true;
|
||||
|
||||
case JumpListItem::Type::SEPARATOR:
|
||||
case JumpListItem::Type::kSeparator:
|
||||
return true;
|
||||
|
||||
case JumpListItem::Type::FILE:
|
||||
case JumpListItem::Type::kFile:
|
||||
return dict.Get("path", &(out->path));
|
||||
}
|
||||
|
||||
|
@ -202,7 +202,7 @@ struct Converter<JumpListItem> {
|
|||
dict.Set("type", val.type);
|
||||
|
||||
switch (val.type) {
|
||||
case JumpListItem::Type::TASK:
|
||||
case JumpListItem::Type::kTask:
|
||||
dict.Set("program", val.path);
|
||||
dict.Set("args", val.arguments);
|
||||
dict.Set("title", val.title);
|
||||
|
@ -212,10 +212,10 @@ struct Converter<JumpListItem> {
|
|||
dict.Set("workingDirectory", val.working_dir);
|
||||
break;
|
||||
|
||||
case JumpListItem::Type::SEPARATOR:
|
||||
case JumpListItem::Type::kSeparator:
|
||||
break;
|
||||
|
||||
case JumpListItem::Type::FILE:
|
||||
case JumpListItem::Type::kFile:
|
||||
dict.Set("path", val.path);
|
||||
break;
|
||||
}
|
||||
|
@ -233,13 +233,13 @@ struct Converter<JumpListCategory::Type> {
|
|||
return false;
|
||||
|
||||
if (category_type == "tasks")
|
||||
*out = JumpListCategory::Type::TASKS;
|
||||
*out = JumpListCategory::Type::kTasks;
|
||||
else if (category_type == "frequent")
|
||||
*out = JumpListCategory::Type::FREQUENT;
|
||||
*out = JumpListCategory::Type::kFrequent;
|
||||
else if (category_type == "recent")
|
||||
*out = JumpListCategory::Type::RECENT;
|
||||
*out = JumpListCategory::Type::kRecent;
|
||||
else if (category_type == "custom")
|
||||
*out = JumpListCategory::Type::CUSTOM;
|
||||
*out = JumpListCategory::Type::kCustom;
|
||||
else
|
||||
return false;
|
||||
|
||||
|
@ -250,19 +250,19 @@ struct Converter<JumpListCategory::Type> {
|
|||
JumpListCategory::Type val) {
|
||||
std::string category_type;
|
||||
switch (val) {
|
||||
case JumpListCategory::Type::TASKS:
|
||||
case JumpListCategory::Type::kTasks:
|
||||
category_type = "tasks";
|
||||
break;
|
||||
|
||||
case JumpListCategory::Type::FREQUENT:
|
||||
case JumpListCategory::Type::kFrequent:
|
||||
category_type = "frequent";
|
||||
break;
|
||||
|
||||
case JumpListCategory::Type::RECENT:
|
||||
case JumpListCategory::Type::kRecent:
|
||||
category_type = "recent";
|
||||
break;
|
||||
|
||||
case JumpListCategory::Type::CUSTOM:
|
||||
case JumpListCategory::Type::kCustom:
|
||||
category_type = "custom";
|
||||
break;
|
||||
}
|
||||
|
@ -284,13 +284,13 @@ struct Converter<JumpListCategory> {
|
|||
|
||||
if (!dict.Get("type", &(out->type))) {
|
||||
if (out->name.empty())
|
||||
out->type = JumpListCategory::Type::TASKS;
|
||||
out->type = JumpListCategory::Type::kTasks;
|
||||
else
|
||||
out->type = JumpListCategory::Type::CUSTOM;
|
||||
out->type = JumpListCategory::Type::kCustom;
|
||||
}
|
||||
|
||||
if ((out->type == JumpListCategory::Type::TASKS) ||
|
||||
(out->type == JumpListCategory::Type::CUSTOM)) {
|
||||
if ((out->type == JumpListCategory::Type::kTasks) ||
|
||||
(out->type == JumpListCategory::Type::kCustom)) {
|
||||
if (!dict.Get("items", &(out->items)))
|
||||
return false;
|
||||
}
|
||||
|
@ -305,27 +305,27 @@ struct Converter<JumpListResult> {
|
|||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate, JumpListResult val) {
|
||||
std::string result_code;
|
||||
switch (val) {
|
||||
case JumpListResult::SUCCESS:
|
||||
case JumpListResult::kSuccess:
|
||||
result_code = "ok";
|
||||
break;
|
||||
|
||||
case JumpListResult::ARGUMENT_ERROR:
|
||||
case JumpListResult::kArgumentError:
|
||||
result_code = "argumentError";
|
||||
break;
|
||||
|
||||
case JumpListResult::GENERIC_ERROR:
|
||||
case JumpListResult::kGenericError:
|
||||
result_code = "error";
|
||||
break;
|
||||
|
||||
case JumpListResult::CUSTOM_CATEGORY_SEPARATOR_ERROR:
|
||||
case JumpListResult::kCustomCategorySeparatorError:
|
||||
result_code = "invalidSeparatorError";
|
||||
break;
|
||||
|
||||
case JumpListResult::MISSING_FILE_TYPE_REGISTRATION_ERROR:
|
||||
case JumpListResult::kMissingFileTypeRegistrationError:
|
||||
result_code = "fileTypeRegistrationError";
|
||||
break;
|
||||
|
||||
case JumpListResult::CUSTOM_CATEGORY_ACCESS_DENIED_ERROR:
|
||||
case JumpListResult::kCustomCategoryAccessDeniedError:
|
||||
result_code = "customCategoryAccessDeniedError";
|
||||
break;
|
||||
}
|
||||
|
@ -1253,19 +1253,19 @@ JumpListResult App::SetJumpList(v8::Local<v8::Value> val,
|
|||
!gin::ConvertFromV8(args->isolate(), val, &categories)) {
|
||||
gin_helper::ErrorThrower(args->isolate())
|
||||
.ThrowError("Argument must be null or an array of categories");
|
||||
return JumpListResult::ARGUMENT_ERROR;
|
||||
return JumpListResult::kArgumentError;
|
||||
}
|
||||
|
||||
JumpList jump_list(Browser::Get()->GetAppUserModelID());
|
||||
|
||||
if (delete_jump_list) {
|
||||
return jump_list.Delete() ? JumpListResult::SUCCESS
|
||||
: JumpListResult::GENERIC_ERROR;
|
||||
return jump_list.Delete() ? JumpListResult::kSuccess
|
||||
: JumpListResult::kGenericError;
|
||||
}
|
||||
|
||||
// Start a transaction that updates the JumpList of this application.
|
||||
if (!jump_list.Begin())
|
||||
return JumpListResult::GENERIC_ERROR;
|
||||
return JumpListResult::kGenericError;
|
||||
|
||||
JumpListResult result = jump_list.AppendCategories(categories);
|
||||
// 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
|
||||
// some indication as to why the transaction actually failed, so don't
|
||||
// overwrite it with a "generic error" code here.
|
||||
if (result == JumpListResult::SUCCESS)
|
||||
result = JumpListResult::GENERIC_ERROR;
|
||||
if (result == JumpListResult::kSuccess)
|
||||
result = JumpListResult::kGenericError;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -1488,9 +1488,10 @@ int DockBounce(gin::Arguments* args) {
|
|||
args->GetNext(&type);
|
||||
|
||||
if (type == "critical")
|
||||
request_id = Browser::Get()->DockBounce(Browser::BounceType::CRITICAL);
|
||||
request_id = Browser::Get()->DockBounce(Browser::BounceType::kCritical);
|
||||
else if (type == "informational")
|
||||
request_id = Browser::Get()->DockBounce(Browser::BounceType::INFORMATIONAL);
|
||||
request_id =
|
||||
Browser::Get()->DockBounce(Browser::BounceType::kInformational);
|
||||
return request_id;
|
||||
}
|
||||
|
||||
|
|
|
@ -160,13 +160,13 @@ const char* kBuiltinSchemes[] = {
|
|||
// Convert error code to string.
|
||||
std::string ErrorCodeToString(ProtocolError error) {
|
||||
switch (error) {
|
||||
case ProtocolError::REGISTERED:
|
||||
case ProtocolError::kRegistered:
|
||||
return "The scheme has been registered";
|
||||
case ProtocolError::NOT_REGISTERED:
|
||||
case ProtocolError::kNotRegistered:
|
||||
return "The scheme has not been registered";
|
||||
case ProtocolError::INTERCEPTED:
|
||||
case ProtocolError::kIntercepted:
|
||||
return "The scheme has been intercepted";
|
||||
case ProtocolError::NOT_INTERCEPTED:
|
||||
case ProtocolError::kNotIntercepted:
|
||||
return "The scheme has not been intercepted";
|
||||
default:
|
||||
return "Unexpected error";
|
||||
|
@ -184,14 +184,14 @@ ProtocolError Protocol::RegisterProtocol(ProtocolType type,
|
|||
const std::string& scheme,
|
||||
const ProtocolHandler& 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,
|
||||
gin::Arguments* args) {
|
||||
bool removed = protocol_registry_->UnregisterProtocol(scheme);
|
||||
HandleOptionalCallback(
|
||||
args, removed ? ProtocolError::OK : ProtocolError::NOT_REGISTERED);
|
||||
args, removed ? ProtocolError::kOK : ProtocolError::kNotRegistered);
|
||||
return removed;
|
||||
}
|
||||
|
||||
|
@ -203,14 +203,14 @@ ProtocolError Protocol::InterceptProtocol(ProtocolType type,
|
|||
const std::string& scheme,
|
||||
const ProtocolHandler& 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,
|
||||
gin::Arguments* args) {
|
||||
bool removed = protocol_registry_->UninterceptProtocol(scheme);
|
||||
HandleOptionalCallback(
|
||||
args, removed ? ProtocolError::OK : ProtocolError::NOT_INTERCEPTED);
|
||||
args, removed ? ProtocolError::kOK : ProtocolError::kNotIntercepted);
|
||||
return removed;
|
||||
}
|
||||
|
||||
|
@ -248,7 +248,7 @@ void Protocol::HandleOptionalCallback(gin::Arguments* args,
|
|||
env,
|
||||
"The callback argument of protocol module APIs is no longer needed.",
|
||||
"ProtocolDeprecateCallback");
|
||||
if (error == ProtocolError::OK)
|
||||
if (error == ProtocolError::kOK)
|
||||
callback.Run(v8::Null(args->isolate()));
|
||||
else
|
||||
callback.Run(v8::Exception::Error(
|
||||
|
|
|
@ -27,11 +27,11 @@ void RegisterSchemesAsPrivileged(gin_helper::ErrorThrower thrower,
|
|||
|
||||
// Possible errors.
|
||||
enum class ProtocolError {
|
||||
OK, // no error
|
||||
REGISTERED,
|
||||
NOT_REGISTERED,
|
||||
INTERCEPTED,
|
||||
NOT_INTERCEPTED,
|
||||
kOK, // no error
|
||||
kRegistered,
|
||||
kNotRegistered,
|
||||
kIntercepted,
|
||||
kNotIntercepted,
|
||||
};
|
||||
|
||||
// Protocol implementation based on network services.
|
||||
|
@ -78,7 +78,7 @@ class Protocol : public gin::Wrappable<Protocol> {
|
|||
gin::Arguments* args) {
|
||||
auto result = RegisterProtocol(type, scheme, handler);
|
||||
HandleOptionalCallback(args, result);
|
||||
return result == ProtocolError::OK;
|
||||
return result == ProtocolError::kOK;
|
||||
}
|
||||
template <ProtocolType type>
|
||||
bool InterceptProtocolFor(const std::string& scheme,
|
||||
|
@ -86,7 +86,7 @@ class Protocol : public gin::Wrappable<Protocol> {
|
|||
gin::Arguments* args) {
|
||||
auto result = InterceptProtocol(type, scheme, handler);
|
||||
HandleOptionalCallback(args, result);
|
||||
return result == ProtocolError::OK;
|
||||
return result == ProtocolError::kOK;
|
||||
}
|
||||
|
||||
// Be compatible with old interface, which accepts optional callback.
|
||||
|
|
|
@ -33,19 +33,19 @@ struct Converter<electron::TrayIcon::IconType> {
|
|||
std::string mode;
|
||||
if (ConvertFromV8(isolate, val, &mode)) {
|
||||
if (mode == "none") {
|
||||
*out = IconType::None;
|
||||
*out = IconType::kNone;
|
||||
return true;
|
||||
} else if (mode == "info") {
|
||||
*out = IconType::Info;
|
||||
*out = IconType::kInfo;
|
||||
return true;
|
||||
} else if (mode == "warning") {
|
||||
*out = IconType::Warning;
|
||||
*out = IconType::kWarning;
|
||||
return true;
|
||||
} else if (mode == "error") {
|
||||
*out = IconType::Error;
|
||||
*out = IconType::kError;
|
||||
return true;
|
||||
} else if (mode == "custom") {
|
||||
*out = IconType::Custom;
|
||||
*out = IconType::kCustom;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -273,22 +273,22 @@ struct Converter<electron::api::WebContents::Type> {
|
|||
using Type = electron::api::WebContents::Type;
|
||||
std::string type;
|
||||
switch (val) {
|
||||
case Type::BACKGROUND_PAGE:
|
||||
case Type::kBackgroundPage:
|
||||
type = "backgroundPage";
|
||||
break;
|
||||
case Type::BROWSER_WINDOW:
|
||||
case Type::kBrowserWindow:
|
||||
type = "window";
|
||||
break;
|
||||
case Type::BROWSER_VIEW:
|
||||
case Type::kBrowserView:
|
||||
type = "browserView";
|
||||
break;
|
||||
case Type::REMOTE:
|
||||
case Type::kRemote:
|
||||
type = "remote";
|
||||
break;
|
||||
case Type::WEB_VIEW:
|
||||
case Type::kWebView:
|
||||
type = "webview";
|
||||
break;
|
||||
case Type::OFF_SCREEN:
|
||||
case Type::kOffScreen:
|
||||
type = "offscreen";
|
||||
break;
|
||||
default:
|
||||
|
@ -305,14 +305,14 @@ struct Converter<electron::api::WebContents::Type> {
|
|||
if (!ConvertFromV8(isolate, val, &type))
|
||||
return false;
|
||||
if (type == "backgroundPage") {
|
||||
*out = Type::BACKGROUND_PAGE;
|
||||
*out = Type::kBackgroundPage;
|
||||
} else if (type == "browserView") {
|
||||
*out = Type::BROWSER_VIEW;
|
||||
*out = Type::kBrowserView;
|
||||
} else if (type == "webview") {
|
||||
*out = Type::WEB_VIEW;
|
||||
*out = Type::kWebView;
|
||||
#if BUILDFLAG(ENABLE_OSR)
|
||||
} else if (type == "offscreen") {
|
||||
*out = Type::OFF_SCREEN;
|
||||
*out = Type::kOffScreen;
|
||||
#endif
|
||||
} else {
|
||||
return false;
|
||||
|
@ -428,7 +428,7 @@ const void* kElectronApiWebContentsKey = &kElectronApiWebContentsKey;
|
|||
WebContents::Type GetTypeFromViewType(extensions::ViewType view_type) {
|
||||
switch (view_type) {
|
||||
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_COMPONENT:
|
||||
|
@ -438,7 +438,7 @@ WebContents::Type GetTypeFromViewType(extensions::ViewType view_type) {
|
|||
case extensions::VIEW_TYPE_EXTENSION_GUEST:
|
||||
case extensions::VIEW_TYPE_TAB_CONTENTS:
|
||||
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,
|
||||
content::WebContents* web_contents)
|
||||
: content::WebContentsObserver(web_contents),
|
||||
type_(Type::REMOTE),
|
||||
type_(Type::kRemote),
|
||||
id_(GetAllWebContents().Add(this)),
|
||||
weak_factory_(this) {
|
||||
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
||||
|
@ -485,7 +485,7 @@ WebContents::WebContents(v8::Isolate* isolate,
|
|||
type_(type),
|
||||
id_(GetAllWebContents().Add(this)),
|
||||
weak_factory_(this) {
|
||||
DCHECK(type != Type::REMOTE)
|
||||
DCHECK(type != Type::kRemote)
|
||||
<< "Can't take ownership of a remote WebContents";
|
||||
auto session = Session::CreateFrom(isolate, GetBrowserContext());
|
||||
session_.Reset(isolate, session.ToV8());
|
||||
|
@ -505,7 +505,7 @@ WebContents::WebContents(v8::Isolate* isolate,
|
|||
#if BUILDFLAG(ENABLE_OSR)
|
||||
bool b = false;
|
||||
if (options.Get(options::kOffscreen, &b) && b)
|
||||
type_ = Type::OFF_SCREEN;
|
||||
type_ = Type::kOffScreen;
|
||||
#endif
|
||||
|
||||
// Init embedder earlier
|
||||
|
@ -517,7 +517,7 @@ WebContents::WebContents(v8::Isolate* isolate,
|
|||
// BrowserViews are not attached to a window initially so they should start
|
||||
// off as hidden. This is also important for compositor recycling. See:
|
||||
// https://github.com/electron/electron/pull/21372
|
||||
initially_shown_ = type_ != Type::BROWSER_VIEW;
|
||||
initially_shown_ = type_ != Type::kBrowserView;
|
||||
options.Get(options::kShow, &initially_shown_);
|
||||
|
||||
// Obtain the session.
|
||||
|
@ -685,7 +685,7 @@ void WebContents::InitWithExtensionView(v8::Isolate* isolate,
|
|||
extensions::ViewType view_type) {
|
||||
// Must reassign type prior to calling `Init`.
|
||||
type_ = GetTypeFromViewType(view_type);
|
||||
if (GetType() == Type::REMOTE)
|
||||
if (GetType() == Type::kRemote)
|
||||
return;
|
||||
|
||||
// Allow toggling DevTools for background pages
|
||||
|
@ -701,7 +701,7 @@ WebContents::~WebContents() {
|
|||
// The destroy() is called.
|
||||
if (managed_web_contents()) {
|
||||
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
||||
if (type_ == Type::BACKGROUND_PAGE) {
|
||||
if (type_ == Type::kBackgroundPage) {
|
||||
// Background pages are owned by extensions::ExtensionHost
|
||||
managed_web_contents()->ReleaseWebContents();
|
||||
}
|
||||
|
@ -713,7 +713,7 @@ WebContents::~WebContents() {
|
|||
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
|
||||
// before WebContents is destroyed.
|
||||
for (ExtendedWebContentsObserver& observer : observers_)
|
||||
|
@ -727,7 +727,7 @@ WebContents::~WebContents() {
|
|||
} else {
|
||||
// Destroy WebContents asynchronously unless app is shutting down,
|
||||
// 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 */);
|
||||
// The WebContentsDestroyed will not be called automatically because we
|
||||
// destroy the webContents in the next tick. So we have to manually
|
||||
|
@ -820,7 +820,7 @@ void WebContents::AddNewContents(
|
|||
v8::Locker locker(isolate);
|
||||
v8::HandleScope handle_scope(isolate);
|
||||
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,
|
||||
initial_rect.x(), initial_rect.y(), initial_rect.width(),
|
||||
initial_rect.height(), tracker->url, tracker->frame_name,
|
||||
|
@ -848,7 +848,7 @@ content::WebContents* WebContents::OpenURLFromTab(
|
|||
void WebContents::BeforeUnloadFired(content::WebContents* tab,
|
||||
bool proceed,
|
||||
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;
|
||||
else
|
||||
*proceed_to_fire_unload = true;
|
||||
|
@ -890,7 +890,7 @@ void WebContents::UpdateTargetURL(content::WebContents* source,
|
|||
bool WebContents::HandleKeyboardEvent(
|
||||
content::WebContents* source,
|
||||
const content::NativeWebKeyboardEvent& event) {
|
||||
if (type_ == Type::WEB_VIEW && embedder_) {
|
||||
if (type_ == Type::kWebView && embedder_) {
|
||||
// Send the unhandled keyboard events back to the embedder.
|
||||
return embedder_->HandleKeyboardEvent(source, event);
|
||||
} else {
|
||||
|
@ -1800,14 +1800,14 @@ v8::Local<v8::Promise> WebContents::SavePage(
|
|||
}
|
||||
|
||||
void WebContents::OpenDevTools(gin::Arguments* args) {
|
||||
if (type_ == Type::REMOTE)
|
||||
if (type_ == Type::kRemote)
|
||||
return;
|
||||
|
||||
if (!enable_devtools_)
|
||||
return;
|
||||
|
||||
std::string state;
|
||||
if (type_ == Type::WEB_VIEW || type_ == Type::BACKGROUND_PAGE ||
|
||||
if (type_ == Type::kWebView || type_ == Type::kBackgroundPage ||
|
||||
!owner_window()) {
|
||||
state = "detach";
|
||||
}
|
||||
|
@ -1826,7 +1826,7 @@ void WebContents::OpenDevTools(gin::Arguments* args) {
|
|||
}
|
||||
|
||||
void WebContents::CloseDevTools() {
|
||||
if (type_ == Type::REMOTE)
|
||||
if (type_ == Type::kRemote)
|
||||
return;
|
||||
|
||||
DCHECK(managed_web_contents());
|
||||
|
@ -1834,7 +1834,7 @@ void WebContents::CloseDevTools() {
|
|||
}
|
||||
|
||||
bool WebContents::IsDevToolsOpened() {
|
||||
if (type_ == Type::REMOTE)
|
||||
if (type_ == Type::kRemote)
|
||||
return false;
|
||||
|
||||
DCHECK(managed_web_contents());
|
||||
|
@ -1842,7 +1842,7 @@ bool WebContents::IsDevToolsOpened() {
|
|||
}
|
||||
|
||||
bool WebContents::IsDevToolsFocused() {
|
||||
if (type_ == Type::REMOTE)
|
||||
if (type_ == Type::kRemote)
|
||||
return false;
|
||||
|
||||
DCHECK(managed_web_contents());
|
||||
|
@ -1851,7 +1851,7 @@ bool WebContents::IsDevToolsFocused() {
|
|||
|
||||
void WebContents::EnableDeviceEmulation(
|
||||
const blink::DeviceEmulationParams& params) {
|
||||
if (type_ == Type::REMOTE)
|
||||
if (type_ == Type::kRemote)
|
||||
return;
|
||||
|
||||
DCHECK(web_contents());
|
||||
|
@ -1869,7 +1869,7 @@ void WebContents::EnableDeviceEmulation(
|
|||
}
|
||||
|
||||
void WebContents::DisableDeviceEmulation() {
|
||||
if (type_ == Type::REMOTE)
|
||||
if (type_ == Type::kRemote)
|
||||
return;
|
||||
|
||||
DCHECK(web_contents());
|
||||
|
@ -1894,7 +1894,7 @@ void WebContents::ToggleDevTools() {
|
|||
}
|
||||
|
||||
void WebContents::InspectElement(int x, int y) {
|
||||
if (type_ == Type::REMOTE)
|
||||
if (type_ == Type::kRemote)
|
||||
return;
|
||||
|
||||
if (!enable_devtools_)
|
||||
|
@ -1907,7 +1907,7 @@ void WebContents::InspectElement(int x, int y) {
|
|||
}
|
||||
|
||||
void WebContents::InspectSharedWorkerById(const std::string& workerId) {
|
||||
if (type_ == Type::REMOTE)
|
||||
if (type_ == Type::kRemote)
|
||||
return;
|
||||
|
||||
if (!enable_devtools_)
|
||||
|
@ -1929,7 +1929,7 @@ std::vector<scoped_refptr<content::DevToolsAgentHost>>
|
|||
WebContents::GetAllSharedWorkers() {
|
||||
std::vector<scoped_refptr<content::DevToolsAgentHost>> shared_workers;
|
||||
|
||||
if (type_ == Type::REMOTE)
|
||||
if (type_ == Type::kRemote)
|
||||
return shared_workers;
|
||||
|
||||
if (!enable_devtools_)
|
||||
|
@ -1945,7 +1945,7 @@ WebContents::GetAllSharedWorkers() {
|
|||
}
|
||||
|
||||
void WebContents::InspectSharedWorker() {
|
||||
if (type_ == Type::REMOTE)
|
||||
if (type_ == Type::kRemote)
|
||||
return;
|
||||
|
||||
if (!enable_devtools_)
|
||||
|
@ -1962,7 +1962,7 @@ void WebContents::InspectSharedWorker() {
|
|||
}
|
||||
|
||||
void WebContents::InspectServiceWorker() {
|
||||
if (type_ == Type::REMOTE)
|
||||
if (type_ == Type::kRemote)
|
||||
return;
|
||||
|
||||
if (!enable_devtools_)
|
||||
|
@ -2356,7 +2356,7 @@ bool WebContents::IsFocused() const {
|
|||
if (!view)
|
||||
return false;
|
||||
|
||||
if (GetType() != Type::BACKGROUND_PAGE) {
|
||||
if (GetType() != Type::kBackgroundPage) {
|
||||
auto* window = web_contents()->GetNativeView()->GetToplevelWindow();
|
||||
if (window && !window->IsVisible())
|
||||
return false;
|
||||
|
@ -2624,7 +2624,7 @@ void WebContents::OnCursorChanged(const content::WebCursor& webcursor) {
|
|||
}
|
||||
|
||||
bool WebContents::IsGuest() const {
|
||||
return type_ == Type::WEB_VIEW;
|
||||
return type_ == Type::kWebView;
|
||||
}
|
||||
|
||||
void WebContents::AttachToIframe(content::WebContents* embedder_web_contents,
|
||||
|
@ -2635,7 +2635,7 @@ void WebContents::AttachToIframe(content::WebContents* embedder_web_contents,
|
|||
|
||||
bool WebContents::IsOffScreen() const {
|
||||
#if BUILDFLAG(ENABLE_OSR)
|
||||
return type_ == Type::OFF_SCREEN;
|
||||
return type_ == Type::kOffScreen;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
|
|
|
@ -146,12 +146,12 @@ class WebContents : public gin::Wrappable<WebContents>,
|
|||
public mojom::ElectronBrowser {
|
||||
public:
|
||||
enum class Type {
|
||||
BACKGROUND_PAGE, // An extension background page.
|
||||
BROWSER_WINDOW, // Used by BrowserWindow.
|
||||
BROWSER_VIEW, // Used by BrowserView.
|
||||
REMOTE, // Thin wrap around an existing WebContents.
|
||||
WEB_VIEW, // Used by <webview>.
|
||||
OFF_SCREEN, // Used for offscreen rendering
|
||||
kBackgroundPage, // An extension background page.
|
||||
kBrowserWindow, // Used by BrowserWindow.
|
||||
kBrowserView, // Used by BrowserView.
|
||||
kRemote, // Thin wrap around an existing WebContents.
|
||||
kWebView, // Used by <webview>.
|
||||
kOffScreen, // Used for offscreen rendering
|
||||
};
|
||||
|
||||
// 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;
|
||||
|
||||
// The type of current WebContents.
|
||||
Type type_ = Type::BROWSER_WINDOW;
|
||||
Type type_ = Type::kBrowserWindow;
|
||||
|
||||
int32_t id_;
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ bool WebContents::IsFocused() const {
|
|||
if (!view)
|
||||
return false;
|
||||
|
||||
if (GetType() != Type::BACKGROUND_PAGE) {
|
||||
if (GetType() != Type::kBackgroundPage) {
|
||||
auto window = [web_contents()->GetNativeView().GetNativeNSView() 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.
|
||||
|
|
|
@ -92,7 +92,7 @@ ProcessMemoryInfo ProcessMetric::GetMemoryInfo() const {
|
|||
ProcessIntegrityLevel ProcessMetric::GetIntegrityLevel() const {
|
||||
HANDLE token = nullptr;
|
||||
if (!::OpenProcessToken(process.Handle(), TOKEN_QUERY, &token)) {
|
||||
return ProcessIntegrityLevel::Unknown;
|
||||
return ProcessIntegrityLevel::kUnknown;
|
||||
}
|
||||
|
||||
base::win::ScopedHandle token_scoped(token);
|
||||
|
@ -101,7 +101,7 @@ ProcessIntegrityLevel ProcessMetric::GetIntegrityLevel() const {
|
|||
if (::GetTokenInformation(token, TokenIntegrityLevel, nullptr, 0,
|
||||
&token_info_length) ||
|
||||
::GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
|
||||
return ProcessIntegrityLevel::Unknown;
|
||||
return ProcessIntegrityLevel::kUnknown;
|
||||
}
|
||||
|
||||
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());
|
||||
if (!::GetTokenInformation(token, TokenIntegrityLevel, token_label,
|
||||
token_info_length, &token_info_length)) {
|
||||
return ProcessIntegrityLevel::Unknown;
|
||||
return ProcessIntegrityLevel::kUnknown;
|
||||
}
|
||||
|
||||
DWORD integrity_level = *::GetSidSubAuthority(
|
||||
|
@ -119,31 +119,31 @@ ProcessIntegrityLevel ProcessMetric::GetIntegrityLevel() const {
|
|||
|
||||
if (integrity_level >= SECURITY_MANDATORY_UNTRUSTED_RID &&
|
||||
integrity_level < SECURITY_MANDATORY_LOW_RID) {
|
||||
return ProcessIntegrityLevel::Untrusted;
|
||||
return ProcessIntegrityLevel::kUntrusted;
|
||||
}
|
||||
|
||||
if (integrity_level >= SECURITY_MANDATORY_LOW_RID &&
|
||||
integrity_level < SECURITY_MANDATORY_MEDIUM_RID) {
|
||||
return ProcessIntegrityLevel::Low;
|
||||
return ProcessIntegrityLevel::kLow;
|
||||
}
|
||||
|
||||
if (integrity_level >= SECURITY_MANDATORY_MEDIUM_RID &&
|
||||
integrity_level < SECURITY_MANDATORY_HIGH_RID) {
|
||||
return ProcessIntegrityLevel::Medium;
|
||||
return ProcessIntegrityLevel::kMedium;
|
||||
}
|
||||
|
||||
if (integrity_level >= SECURITY_MANDATORY_HIGH_RID &&
|
||||
integrity_level < SECURITY_MANDATORY_SYSTEM_RID) {
|
||||
return ProcessIntegrityLevel::High;
|
||||
return ProcessIntegrityLevel::kHigh;
|
||||
}
|
||||
|
||||
return ProcessIntegrityLevel::Unknown;
|
||||
return ProcessIntegrityLevel::kUnknown;
|
||||
}
|
||||
|
||||
// static
|
||||
bool ProcessMetric::IsSandboxed(ProcessIntegrityLevel integrity_level) {
|
||||
return integrity_level > ProcessIntegrityLevel::Unknown &&
|
||||
integrity_level < ProcessIntegrityLevel::Medium;
|
||||
return integrity_level > ProcessIntegrityLevel::kUnknown &&
|
||||
integrity_level < ProcessIntegrityLevel::kMedium;
|
||||
}
|
||||
|
||||
#elif defined(OS_MAC)
|
||||
|
|
|
@ -26,11 +26,11 @@ struct ProcessMemoryInfo {
|
|||
|
||||
#if defined(OS_WIN)
|
||||
enum class ProcessIntegrityLevel {
|
||||
Unknown,
|
||||
Untrusted,
|
||||
Low,
|
||||
Medium,
|
||||
High,
|
||||
kUnknown,
|
||||
kUntrusted,
|
||||
kLow,
|
||||
kMedium,
|
||||
kHigh,
|
||||
};
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue