Skip to content

Commit

Permalink
all: Remove Base namespace and clean up (#22)
Browse files Browse the repository at this point in the history
Signed-off-by: Open592 Developer <[email protected]>
  • Loading branch information
cfrank authored Jun 27, 2023
1 parent af09d73 commit 60b9bf6
Show file tree
Hide file tree
Showing 18 changed files with 36 additions and 53 deletions.
4 changes: 2 additions & 2 deletions src/Browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Base::BrowserContext> context) noexcept
bool Browser::RegisterContext(std::unique_ptr<BrowserContext> context) noexcept
{
if (!context) {
return false;
Expand Down
6 changes: 3 additions & 3 deletions src/Browser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Base::BrowserContext>) noexcept;
bool RegisterContext(std::unique_ptr<BrowserContext>) noexcept;

private:
Browser();

std::unique_ptr<Base::BrowserContext> m_context;
std::unique_ptr<BrowserContext> m_context;
};
4 changes: 0 additions & 4 deletions src/BrowserContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -48,5 +46,3 @@ void BrowserContext::Navigate(std::wstring destination)

PerformNavigate();
}

}
6 changes: 1 addition & 5 deletions src/BrowserContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;

Expand All @@ -57,5 +55,3 @@ class BrowserContext {
virtual void PerformResize() = 0;
virtual void PerformNavigate() = 0;
};

}
8 changes: 2 additions & 6 deletions src/BrowserData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#include "BrowserData.hpp"

namespace Base {

const std::wstring& BrowserData::GetDestination() const noexcept
{
std::lock_guard<std::mutex> lk(m_mutex);
Expand Down Expand Up @@ -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<std::mutex> lk(m_mutex);
Expand All @@ -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<std::mutex> lk(m_mutex);

Expand All @@ -79,5 +77,3 @@ void BrowserData::WaitForStateOrFailure(Base::ApplicationState state) noexcept
return m_state == state;
});
}

}
4 changes: 0 additions & 4 deletions src/BrowserData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

#include <jni.h>

namespace Base {

enum class ApplicationState : uint8_t {
/**
* Represents the state of:
Expand Down Expand Up @@ -113,5 +111,3 @@ class BrowserData {

std::condition_variable m_cv;
};

}
18 changes: 11 additions & 7 deletions src/browsercontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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);
}
4 changes: 2 additions & 2 deletions src/platform/linux/BrowserWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -71,7 +71,7 @@ void BrowserWindow::OnBrowserCreated(CefRefPtr<CefBrowser> browser)
m_browser = browser;
}

m_data.SetState(Base::ApplicationState::STARTED);
m_data.SetState(ApplicationState::STARTED);
}

void BrowserWindow::OnBrowserClosed(CefRefPtr<CefBrowser> browser)
Expand Down
1 change: 0 additions & 1 deletion src/platform/linux/DesktopBrowserLauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 7 additions & 7 deletions src/platform/linux/LinuxBrowserContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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();
}
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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<char*>("browsercontrol") };
CefMainArgs args(1, argv);
Expand All @@ -120,7 +120,7 @@ void LinuxBrowserContext::StartCEF() const
JVMSignals::Restore();

if (!result) {
m_data->SetState(Base::ApplicationState::FAILED);
m_data->SetState(ApplicationState::FAILED);

return;
}
Expand Down
4 changes: 1 addition & 3 deletions src/platform/linux/LinuxBrowserContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<LinuxBrowserData>) noexcept;
~LinuxBrowserContext() override = default;
Expand Down
2 changes: 1 addition & 1 deletion src/platform/linux/LinuxBrowserData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
2 changes: 1 addition & 1 deletion src/platform/linux/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ __attribute__((constructor)) void setup()
auto data = std::make_unique<LinuxBrowserData>();
auto context = std::make_unique<LinuxBrowserContext>(std::move(data));

Browser::The().RegisterBrowserContext(std::move(context));
Browser::The().RegisterContext(std::move(context));
}
2 changes: 0 additions & 2 deletions src/platform/windows/WebView2BrowserWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

using namespace Microsoft::WRL;

using Base::ApplicationState;

namespace {

constexpr auto WINDOW_CLASS_NAME = L"Jb";
Expand Down
4 changes: 2 additions & 2 deletions src/platform/windows/WindowsBrowserContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/platform/windows/WindowsBrowserContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "WindowsBrowserData.hpp"

class WindowsBrowserContext : public Base::BrowserContext {
class WindowsBrowserContext : public BrowserContext {
public:
explicit WindowsBrowserContext(std::unique_ptr<WindowsBrowserData>);
~WindowsBrowserContext() noexcept override;
Expand Down
2 changes: 1 addition & 1 deletion src/platform/windows/WindowsBrowserData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "src/BrowserData.hpp"

class WindowsBrowserData : public Base::BrowserData {
class WindowsBrowserData : public BrowserData {
public:
WindowsBrowserData() noexcept;
~WindowsBrowserData() override = default;
Expand Down
2 changes: 1 addition & 1 deletion src/platform/windows/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, LPVOID lpRe
auto data = std::make_unique<WindowsBrowserData>();
auto context = std::make_unique<WindowsBrowserContext>(std::move(data));

return Browser::The().RegisterBrowserContext(std::move(context));
return Browser::The().RegisterContext(std::move(context));
}

return true;
Expand Down

0 comments on commit 60b9bf6

Please sign in to comment.