From 60b9bf628363eb6bb6b5e5a8c4cdd02a0f096524 Mon Sep 17 00:00:00 2001 From: Chris Frank Date: Tue, 27 Jun 2023 00:10:44 -0700 Subject: [PATCH] all: Remove Base namespace and clean up (#22) Signed-off-by: Open592 Developer --- src/Browser.cpp | 4 ++-- src/Browser.hpp | 6 +++--- src/BrowserContext.cpp | 4 ---- src/BrowserContext.hpp | 6 +----- src/BrowserData.cpp | 8 ++------ src/BrowserData.hpp | 4 ---- src/browsercontrol.cpp | 18 +++++++++++------- src/platform/linux/BrowserWindow.cpp | 4 ++-- src/platform/linux/DesktopBrowserLauncher.cpp | 1 - src/platform/linux/LinuxBrowserContext.cpp | 14 +++++++------- src/platform/linux/LinuxBrowserContext.hpp | 4 +--- src/platform/linux/LinuxBrowserData.hpp | 2 +- src/platform/linux/init.cpp | 2 +- src/platform/windows/WebView2BrowserWindow.cpp | 2 -- src/platform/windows/WindowsBrowserContext.cpp | 4 ++-- src/platform/windows/WindowsBrowserContext.hpp | 2 +- src/platform/windows/WindowsBrowserData.hpp | 2 +- src/platform/windows/init.cpp | 2 +- 18 files changed, 36 insertions(+), 53 deletions(-) diff --git a/src/Browser.cpp b/src/Browser.cpp index 77a8d8d..2f13181 100644 --- a/src/Browser.cpp +++ b/src/Browser.cpp @@ -15,9 +15,9 @@ Browser::Browser() { } -Base::BrowserContext* Browser::GetBrowserContext() const noexcept { return m_context.get(); } +BrowserContext* Browser::GetContext() const noexcept { return m_context.get(); } -bool Browser::RegisterBrowserContext(std::unique_ptr context) noexcept +bool Browser::RegisterContext(std::unique_ptr context) noexcept { if (!context) { return false; diff --git a/src/Browser.hpp b/src/Browser.hpp index bb8b93b..27fbd98 100644 --- a/src/Browser.hpp +++ b/src/Browser.hpp @@ -41,12 +41,12 @@ class Browser { Browser& operator=(const Browser&) = delete; Browser& operator=(Browser&&) = delete; - [[nodiscard]] Base::BrowserContext* GetBrowserContext() const noexcept; + [[nodiscard]] BrowserContext* GetContext() const noexcept; - bool RegisterBrowserContext(std::unique_ptr) noexcept; + bool RegisterContext(std::unique_ptr) noexcept; private: Browser(); - std::unique_ptr m_context; + std::unique_ptr m_context; }; diff --git a/src/BrowserContext.cpp b/src/BrowserContext.cpp index 0e370b8..0490097 100644 --- a/src/BrowserContext.cpp +++ b/src/BrowserContext.cpp @@ -2,8 +2,6 @@ #include "BrowserContext.hpp" -namespace Base { - bool BrowserContext::Initialize(JNIEnv* env, jobject parentContainer, std::wstring initialDestination) { // We should not be initializing more than once. @@ -48,5 +46,3 @@ void BrowserContext::Navigate(std::wstring destination) PerformNavigate(); } - -} diff --git a/src/BrowserContext.hpp b/src/BrowserContext.hpp index f5aaa45..c5ec93d 100644 --- a/src/BrowserContext.hpp +++ b/src/BrowserContext.hpp @@ -6,8 +6,6 @@ #include "BrowserData.hpp" -namespace Base { - /** * Provide a generic browser context which exposes a interface for interacting * with all of the separate platform's browser controls. @@ -44,7 +42,7 @@ class BrowserContext { private: /** * Require implementors to provide their own implementation which exposes their - * platform specific implementations of Base::BrowserData + * platform specific implementations of BrowserData */ [[nodiscard]] virtual BrowserData& GetBrowserData() const noexcept = 0; @@ -57,5 +55,3 @@ class BrowserContext { virtual void PerformResize() = 0; virtual void PerformNavigate() = 0; }; - -} diff --git a/src/BrowserData.cpp b/src/BrowserData.cpp index 55cf60f..3552776 100644 --- a/src/BrowserData.cpp +++ b/src/BrowserData.cpp @@ -2,8 +2,6 @@ #include "BrowserData.hpp" -namespace Base { - const std::wstring& BrowserData::GetDestination() const noexcept { std::lock_guard lk(m_mutex); @@ -56,7 +54,7 @@ bool BrowserData::SetSize(int width, int height) noexcept return true; } -void BrowserData::SetState(Base::ApplicationState state) noexcept +void BrowserData::SetState(ApplicationState state) noexcept { { std::lock_guard lk(m_mutex); @@ -67,7 +65,7 @@ void BrowserData::SetState(Base::ApplicationState state) noexcept m_cv.notify_one(); } -void BrowserData::WaitForStateOrFailure(Base::ApplicationState state) noexcept +void BrowserData::WaitForStateOrFailure(ApplicationState state) noexcept { std::unique_lock lk(m_mutex); @@ -79,5 +77,3 @@ void BrowserData::WaitForStateOrFailure(Base::ApplicationState state) noexcept return m_state == state; }); } - -} diff --git a/src/BrowserData.hpp b/src/BrowserData.hpp index e224424..6b1b65d 100644 --- a/src/BrowserData.hpp +++ b/src/BrowserData.hpp @@ -10,8 +10,6 @@ #include -namespace Base { - enum class ApplicationState : uint8_t { /** * Represents the state of: @@ -113,5 +111,3 @@ class BrowserData { std::condition_variable m_cv; }; - -} diff --git a/src/browsercontrol.cpp b/src/browsercontrol.cpp index 387b001..0564a61 100644 --- a/src/browsercontrol.cpp +++ b/src/browsercontrol.cpp @@ -4,7 +4,9 @@ #include "Browser.hpp" -[[nodiscard]] static std::wstring ConvertJavaStringToWString(JNIEnv* env, jstring input) +namespace { + +[[nodiscard]] std::wstring convertJavaStringToWString(JNIEnv* env, jstring input) { std::wstring result; @@ -27,16 +29,18 @@ return result; } +} + JNIEXPORT jboolean JNICALL Java_nativeadvert_browsercontrol_browsercontrol0( JNIEnv* env, [[maybe_unused]] jclass thisObj, jobject advertCanvas, jstring URL) { - std::wstring initialDestination = ConvertJavaStringToWString(env, URL); + std::wstring initialDestination = convertJavaStringToWString(env, URL); if (initialDestination.empty()) { return JNI_FALSE; } - bool result = Browser::The().GetBrowserContext()->Initialize(env, advertCanvas, std::move(initialDestination)); + bool result = Browser::The().GetContext()->Initialize(env, advertCanvas, std::move(initialDestination)); if (result) { return JNI_TRUE; @@ -48,23 +52,23 @@ JNIEXPORT jboolean JNICALL Java_nativeadvert_browsercontrol_browsercontrol0( JNIEXPORT void JNICALL Java_nativeadvert_browsercontrol_destroy0( [[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass thisObj) { - Browser::The().GetBrowserContext()->Destroy(); + Browser::The().GetContext()->Destroy(); } JNIEXPORT void JNICALL Java_nativeadvert_browsercontrol_navigate0( JNIEnv* env, [[maybe_unused]] jclass thisObj, jstring URL) { - std::wstring destination = ConvertJavaStringToWString(env, URL); + std::wstring destination = convertJavaStringToWString(env, URL); if (destination.empty()) { return; } - Browser::The().GetBrowserContext()->Navigate(std::move(destination)); + Browser::The().GetContext()->Navigate(std::move(destination)); } JNIEXPORT void JNICALL Java_nativeadvert_browsercontrol_resize0( [[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass thisObj, jint width, jint height) { - Browser::The().GetBrowserContext()->Resize(width, height); + Browser::The().GetContext()->Resize(width, height); } diff --git a/src/platform/linux/BrowserWindow.cpp b/src/platform/linux/BrowserWindow.cpp index e853662..f3c0a04 100644 --- a/src/platform/linux/BrowserWindow.cpp +++ b/src/platform/linux/BrowserWindow.cpp @@ -27,7 +27,7 @@ void BrowserWindow::Create() const windowInfo, m_clientHandler.get(), m_data.GetDestination(), browserSettings, nullptr, nullptr); if (!result) { - m_data.SetState(Base::ApplicationState::FAILED); + m_data.SetState(ApplicationState::FAILED); return; } @@ -71,7 +71,7 @@ void BrowserWindow::OnBrowserCreated(CefRefPtr browser) m_browser = browser; } - m_data.SetState(Base::ApplicationState::STARTED); + m_data.SetState(ApplicationState::STARTED); } void BrowserWindow::OnBrowserClosed(CefRefPtr browser) diff --git a/src/platform/linux/DesktopBrowserLauncher.cpp b/src/platform/linux/DesktopBrowserLauncher.cpp index b267320..b2768f1 100644 --- a/src/platform/linux/DesktopBrowserLauncher.cpp +++ b/src/platform/linux/DesktopBrowserLauncher.cpp @@ -95,7 +95,6 @@ namespace DesktopBrowserLauncher { bool Open(const std::string& URL) { const std::string command = g_desktopBrowserCommand + ' ' + URL; - int status = std::system(command.c_str()); if (status < 0) { diff --git a/src/platform/linux/LinuxBrowserContext.cpp b/src/platform/linux/LinuxBrowserContext.cpp index c290901..ce086ee 100644 --- a/src/platform/linux/LinuxBrowserContext.cpp +++ b/src/platform/linux/LinuxBrowserContext.cpp @@ -45,7 +45,7 @@ void LinuxBrowserContext::OnBrowserWindowDestroyed() CefShutdown(); - m_data->SetState(Base::ApplicationState::PENDING); + m_data->SetState(ApplicationState::PENDING); } bool LinuxBrowserContext::PerformInitialize(JNIEnv* env, jobject canvas) @@ -58,7 +58,7 @@ bool LinuxBrowserContext::PerformInitialize(JNIEnv* env, jobject canvas) m_eventLoop->EnqueueWork(base::BindOnce(&LinuxBrowserContext::StartCEF, base::Unretained(this))); - m_data->WaitForStateOrFailure(Base::ApplicationState::STARTED); + m_data->WaitForStateOrFailure(ApplicationState::STARTED); return m_data->IsRunning(); } @@ -69,11 +69,11 @@ void LinuxBrowserContext::PerformDestroy() CefPostTask(TID_UI, base::BindOnce([](BrowserWindow* window) { window->Destroy(); }, base::Unretained(m_browserWindow.get()))); - m_data->WaitForStateOrFailure(Base::ApplicationState::PENDING); + m_data->WaitForStateOrFailure(ApplicationState::PENDING); } else { m_browserWindow->Destroy(); - m_data->WaitForStateOrFailure(Base::ApplicationState::PENDING); + m_data->WaitForStateOrFailure(ApplicationState::PENDING); } } @@ -101,8 +101,8 @@ void LinuxBrowserContext::StartCEF() const { DCHECK(m_eventLoop->CurrentlyOnBrowserThread()); - auto subProcessHelperPath = m_data->GetWorkingDirectory() / "browsercontrol_helper"; - auto cefDebugLogPath = m_data->GetWorkingDirectory() / "cef_debug.log"; + const auto subProcessHelperPath = m_data->GetWorkingDirectory() / "browsercontrol_helper"; + const auto cefDebugLogPath = m_data->GetWorkingDirectory() / "cef_debug.log"; char* argv[] = { const_cast("browsercontrol") }; CefMainArgs args(1, argv); @@ -120,7 +120,7 @@ void LinuxBrowserContext::StartCEF() const JVMSignals::Restore(); if (!result) { - m_data->SetState(Base::ApplicationState::FAILED); + m_data->SetState(ApplicationState::FAILED); return; } diff --git a/src/platform/linux/LinuxBrowserContext.hpp b/src/platform/linux/LinuxBrowserContext.hpp index 067a1a0..3a3c66a 100644 --- a/src/platform/linux/LinuxBrowserContext.hpp +++ b/src/platform/linux/LinuxBrowserContext.hpp @@ -11,9 +11,7 @@ #include "BrowserWindow.hpp" #include "LinuxBrowserData.hpp" -class LinuxBrowserContext final : public Base::BrowserContext, - public BrowserWindow::Delegate, - private BrowserApp::Delegate { +class LinuxBrowserContext final : public BrowserContext, public BrowserWindow::Delegate, private BrowserApp::Delegate { public: explicit LinuxBrowserContext(std::unique_ptr) noexcept; ~LinuxBrowserContext() override = default; diff --git a/src/platform/linux/LinuxBrowserData.hpp b/src/platform/linux/LinuxBrowserData.hpp index 0315611..9ab0977 100644 --- a/src/platform/linux/LinuxBrowserData.hpp +++ b/src/platform/linux/LinuxBrowserData.hpp @@ -9,7 +9,7 @@ #include "src/BrowserData.hpp" -class LinuxBrowserData : public Base::BrowserData { +class LinuxBrowserData : public BrowserData { public: [[nodiscard]] std::filesystem::path GetWorkingDirectory() const noexcept { return m_workingDirectory; } [[nodiscard]] xcb_window_t GetHostWindow() const noexcept { return m_hostWindow; } diff --git a/src/platform/linux/init.cpp b/src/platform/linux/init.cpp index c155b20..71eded6 100644 --- a/src/platform/linux/init.cpp +++ b/src/platform/linux/init.cpp @@ -40,5 +40,5 @@ __attribute__((constructor)) void setup() auto data = std::make_unique(); auto context = std::make_unique(std::move(data)); - Browser::The().RegisterBrowserContext(std::move(context)); + Browser::The().RegisterContext(std::move(context)); } diff --git a/src/platform/windows/WebView2BrowserWindow.cpp b/src/platform/windows/WebView2BrowserWindow.cpp index 3b21e1d..bdac8c6 100644 --- a/src/platform/windows/WebView2BrowserWindow.cpp +++ b/src/platform/windows/WebView2BrowserWindow.cpp @@ -6,8 +6,6 @@ using namespace Microsoft::WRL; -using Base::ApplicationState; - namespace { constexpr auto WINDOW_CLASS_NAME = L"Jb"; diff --git a/src/platform/windows/WindowsBrowserContext.cpp b/src/platform/windows/WindowsBrowserContext.cpp index ca833aa..1847a3e 100644 --- a/src/platform/windows/WindowsBrowserContext.cpp +++ b/src/platform/windows/WindowsBrowserContext.cpp @@ -35,7 +35,7 @@ bool WindowsBrowserContext::PerformInitialize(JNIEnv* env, jobject canvas) m_browserThread = std::thread([&] { StartMessagePump(); }); // Block until the browser reports that we are running - m_data->WaitForStateOrFailure(Base::ApplicationState::STARTED); + m_data->WaitForStateOrFailure(ApplicationState::STARTED); return m_data->IsRunning(); } @@ -70,7 +70,7 @@ void WindowsBrowserContext::StartMessagePump() handle_error: // Notify caller that we failed - m_data->SetState(Base::ApplicationState::FAILED); + m_data->SetState(ApplicationState::FAILED); } void WindowsBrowserContext::PerformDestroy() diff --git a/src/platform/windows/WindowsBrowserContext.hpp b/src/platform/windows/WindowsBrowserContext.hpp index 783bac0..7e40ec6 100644 --- a/src/platform/windows/WindowsBrowserContext.hpp +++ b/src/platform/windows/WindowsBrowserContext.hpp @@ -6,7 +6,7 @@ #include "WindowsBrowserData.hpp" -class WindowsBrowserContext : public Base::BrowserContext { +class WindowsBrowserContext : public BrowserContext { public: explicit WindowsBrowserContext(std::unique_ptr); ~WindowsBrowserContext() noexcept override; diff --git a/src/platform/windows/WindowsBrowserData.hpp b/src/platform/windows/WindowsBrowserData.hpp index 5edf030..7847e84 100644 --- a/src/platform/windows/WindowsBrowserData.hpp +++ b/src/platform/windows/WindowsBrowserData.hpp @@ -4,7 +4,7 @@ #include "src/BrowserData.hpp" -class WindowsBrowserData : public Base::BrowserData { +class WindowsBrowserData : public BrowserData { public: WindowsBrowserData() noexcept; ~WindowsBrowserData() override = default; diff --git a/src/platform/windows/init.cpp b/src/platform/windows/init.cpp index 65525bd..f36f620 100644 --- a/src/platform/windows/init.cpp +++ b/src/platform/windows/init.cpp @@ -12,7 +12,7 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, LPVOID lpRe auto data = std::make_unique(); auto context = std::make_unique(std::move(data)); - return Browser::The().RegisterBrowserContext(std::move(context)); + return Browser::The().RegisterContext(std::move(context)); } return true;