refactor: convert C++ enums to C++11 enum classes (#18087)

This commit is contained in:
Milan Burda 2019-05-03 20:11:41 +02:00 committed by Alexey Kuzmin
parent a59dc56fa6
commit c25c31e018
36 changed files with 199 additions and 204 deletions

View file

@ -268,7 +268,7 @@ struct WebContents::FrameDispatchHelper {
WebContents::WebContents(v8::Isolate* isolate,
content::WebContents* web_contents)
: content::WebContentsObserver(web_contents), type_(REMOTE) {
: content::WebContentsObserver(web_contents), type_(Type::REMOTE) {
web_contents->SetUserAgentOverride(GetBrowserContext()->GetUserAgent(),
false);
Init(isolate);
@ -284,7 +284,8 @@ WebContents::WebContents(v8::Isolate* isolate,
std::unique_ptr<content::WebContents> web_contents,
Type type)
: content::WebContentsObserver(web_contents.get()), type_(type) {
DCHECK(type != REMOTE) << "Can't take ownership of a remote WebContents";
DCHECK(type != Type::REMOTE)
<< "Can't take ownership of a remote WebContents";
auto session = Session::CreateFrom(isolate, GetBrowserContext());
session_.Reset(isolate, session.ToV8());
InitWithSessionAndOptions(isolate, std::move(web_contents), session,
@ -303,14 +304,14 @@ WebContents::WebContents(v8::Isolate* isolate,
// Remvoe this after we upgraded to use VS 2015 Update 3.
bool b = false;
if (options.Get("isGuest", &b) && b)
type_ = WEB_VIEW;
type_ = Type::WEB_VIEW;
else if (options.Get("isBackgroundPage", &b) && b)
type_ = BACKGROUND_PAGE;
type_ = Type::BACKGROUND_PAGE;
else if (options.Get("isBrowserView", &b) && b)
type_ = BROWSER_VIEW;
type_ = Type::BROWSER_VIEW;
#if BUILDFLAG(ENABLE_OSR)
else if (options.Get(options::kOffscreen, &b) && b)
type_ = OFF_SCREEN;
type_ = Type::OFF_SCREEN;
#endif
// Init embedder earlier
@ -457,12 +458,12 @@ WebContents::~WebContents() {
RenderViewDeleted(web_contents()->GetRenderViewHost());
if (type_ == WEB_VIEW) {
if (type_ == Type::WEB_VIEW) {
DCHECK(!web_contents()->GetOuterWebContents())
<< "Should never manually destroy an attached webview";
// For webview simply destroy the WebContents immediately.
DestroyWebContents(false /* async */);
} else if (type_ == BROWSER_WINDOW && owner_window()) {
} else if (type_ == Type::BROWSER_WINDOW && owner_window()) {
// For BrowserWindow we should close the window and clean up everything
// before WebContents is destroyed.
for (ExtendedWebContentsObserver& observer : observers_)
@ -509,7 +510,7 @@ void WebContents::OnCreateWindow(
WindowOpenDisposition disposition,
const std::vector<std::string>& features,
const scoped_refptr<network::ResourceRequestBody>& body) {
if (type_ == BROWSER_WINDOW || type_ == OFF_SCREEN)
if (type_ == Type::BROWSER_WINDOW || type_ == Type::OFF_SCREEN)
Emit("-new-window", target_url, frame_name, disposition, features, body,
referrer);
else
@ -541,7 +542,7 @@ void WebContents::AddNewContents(
v8::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());
auto api_web_contents =
CreateAndTake(isolate(), std::move(new_contents), BROWSER_WINDOW);
CreateAndTake(isolate(), std::move(new_contents), Type::BROWSER_WINDOW);
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)) {
@ -554,7 +555,7 @@ content::WebContents* WebContents::OpenURLFromTab(
content::WebContents* source,
const content::OpenURLParams& params) {
if (params.disposition != WindowOpenDisposition::CURRENT_TAB) {
if (type_ == BROWSER_WINDOW || type_ == OFF_SCREEN)
if (type_ == Type::BROWSER_WINDOW || type_ == Type::OFF_SCREEN)
Emit("-new-window", params.url, "", params.disposition);
else
Emit("new-window", params.url, "", params.disposition);
@ -576,7 +577,7 @@ content::WebContents* WebContents::OpenURLFromTab(
void WebContents::BeforeUnloadFired(content::WebContents* tab,
bool proceed,
bool* proceed_to_fire_unload) {
if (type_ == BROWSER_WINDOW || type_ == OFF_SCREEN)
if (type_ == Type::BROWSER_WINDOW || type_ == Type::OFF_SCREEN)
*proceed_to_fire_unload = proceed;
else
*proceed_to_fire_unload = true;
@ -610,7 +611,7 @@ void WebContents::UpdateTargetURL(content::WebContents* source,
bool WebContents::HandleKeyboardEvent(
content::WebContents* source,
const content::NativeWebKeyboardEvent& event) {
if (type_ == WEB_VIEW && embedder_) {
if (type_ == Type::WEB_VIEW && embedder_) {
// Send the unhandled keyboard events back to the embedder.
return embedder_->HandleKeyboardEvent(source, event);
} else {
@ -1390,14 +1391,14 @@ v8::Local<v8::Promise> WebContents::SavePage(
}
void WebContents::OpenDevTools(mate::Arguments* args) {
if (type_ == REMOTE)
if (type_ == Type::REMOTE)
return;
if (!enable_devtools_)
return;
std::string state;
if (type_ == WEB_VIEW || !owner_window()) {
if (type_ == Type::WEB_VIEW || !owner_window()) {
state = "detach";
}
bool activate = true;
@ -1413,21 +1414,21 @@ void WebContents::OpenDevTools(mate::Arguments* args) {
}
void WebContents::CloseDevTools() {
if (type_ == REMOTE)
if (type_ == Type::REMOTE)
return;
managed_web_contents()->CloseDevTools();
}
bool WebContents::IsDevToolsOpened() {
if (type_ == REMOTE)
if (type_ == Type::REMOTE)
return false;
return managed_web_contents()->IsDevToolsViewShowing();
}
bool WebContents::IsDevToolsFocused() {
if (type_ == REMOTE)
if (type_ == Type::REMOTE)
return false;
return managed_web_contents()->GetView()->IsDevToolsViewFocused();
@ -1435,7 +1436,7 @@ bool WebContents::IsDevToolsFocused() {
void WebContents::EnableDeviceEmulation(
const blink::WebDeviceEmulationParams& params) {
if (type_ == REMOTE)
if (type_ == Type::REMOTE)
return;
auto* frame_host = web_contents()->GetMainFrame();
@ -1450,7 +1451,7 @@ void WebContents::EnableDeviceEmulation(
}
void WebContents::DisableDeviceEmulation() {
if (type_ == REMOTE)
if (type_ == Type::REMOTE)
return;
auto* frame_host = web_contents()->GetMainFrame();
@ -1472,7 +1473,7 @@ void WebContents::ToggleDevTools() {
}
void WebContents::InspectElement(int x, int y) {
if (type_ == REMOTE)
if (type_ == Type::REMOTE)
return;
if (!enable_devtools_)
@ -1484,7 +1485,7 @@ void WebContents::InspectElement(int x, int y) {
}
void WebContents::InspectSharedWorker() {
if (type_ == REMOTE)
if (type_ == Type::REMOTE)
return;
if (!enable_devtools_)
@ -1501,7 +1502,7 @@ void WebContents::InspectSharedWorker() {
}
void WebContents::InspectServiceWorker() {
if (type_ == REMOTE)
if (type_ == Type::REMOTE)
return;
if (!enable_devtools_)
@ -1701,7 +1702,7 @@ bool WebContents::IsFocused() const {
if (!view)
return false;
if (GetType() != BACKGROUND_PAGE) {
if (GetType() != Type::BACKGROUND_PAGE) {
auto* window = web_contents()->GetNativeView()->GetToplevelWindow();
if (window && !window->IsVisible())
return false;
@ -1933,7 +1934,7 @@ void WebContents::OnCursorChange(const content::WebCursor& cursor) {
}
bool WebContents::IsGuest() const {
return type_ == WEB_VIEW;
return type_ == Type::WEB_VIEW;
}
void WebContents::AttachToIframe(content::WebContents* embedder_web_contents,
@ -1944,7 +1945,7 @@ void WebContents::AttachToIframe(content::WebContents* embedder_web_contents,
bool WebContents::IsOffScreen() const {
#if BUILDFLAG(ENABLE_OSR)
return type_ == OFF_SCREEN;
return type_ == Type::OFF_SCREEN;
#else
return false;
#endif