Skip to content

Commit

Permalink
[wpe] Rename Browser prefixed files to WKRuntime
Browse files Browse the repository at this point in the history
  • Loading branch information
zhani committed Sep 5, 2024
1 parent f7e55bf commit 5986342
Show file tree
Hide file tree
Showing 43 changed files with 76 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.fragment.NavHostFragment
import org.wpewebkit.tools.minibrowser.R
import org.wpewebkit.tools.minibrowser.databinding.ActivityMainBinding


class MainActivity : AppCompatActivity(R.layout.activity_main) {

private val TAG = "MiniBrowser"

private val navHost by lazy {
supportFragmentManager.primaryNavigationFragment as NavHostFragment
}
Expand All @@ -42,12 +43,12 @@ class MainActivity : AppCompatActivity(R.layout.activity_main) {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Log.d("Browser", "onCreate")
Log.d(TAG, "onCreate")
binding = ActivityMainBinding.inflate(layoutInflater)
}

override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
Log.d("Browser", "onConfigurationChanged")
Log.d(TAG, "onConfigurationChanged")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import android.os.ParcelFileDescriptor
import android.util.Log
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import org.wpewebkit.wpe.ProcessType
import org.wpewebkit.wpe.WKProcessType
import org.wpewebkit.wpe.services.WPEServiceConnection
import org.wpewebkit.wpe.services.WPEServiceConnectionListener
import org.wpewebkit.wpeview.WPEChromeClient
Expand Down Expand Up @@ -109,7 +109,7 @@ class WebDriverActivity : AppCompatActivity() {
}

try {
val processType = ProcessType.WebDriverProcess
val processType = WKProcessType.WebDriverProcess
val serviceClass =
Class.forName("org.wpewebkit.wpe.services." + processType.name + "Service")
val parcelFd = ParcelFileDescriptor.fromFd(0)
Expand Down
30 changes: 15 additions & 15 deletions wpe/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,21 @@ target_link_libraries(WPEAndroidCommon ${android-lib} ${log-lib} ${sync-lib})
# libWPEAndroidBrowser
add_library(
WPEAndroidBrowser SHARED
Browser/Browser.cpp
Browser/EntryPoint.cpp
Browser/Fence.cpp
Browser/InputMethodContext.cpp
Browser/LooperThread.cpp
Browser/MessagePump.cpp
Browser/WKWebView.cpp
Browser/WKSettings.cpp
Browser/RendererSurfaceControl.cpp
Browser/SurfaceControl.cpp
Browser/WKCallback.cpp
Browser/WKCookieManager.cpp
Browser/WKNetworkSession.cpp
Browser/WKWebContext.cpp
Browser/WKWebsiteDataManager.cpp)
Runtime/EntryPoint.cpp
Runtime/Fence.cpp
Runtime/InputMethodContext.cpp
Runtime/LooperThread.cpp
Runtime/MessagePump.cpp
Runtime/RendererSurfaceControl.cpp
Runtime/SurfaceControl.cpp
Runtime/WKCallback.cpp
Runtime/WKCookieManager.cpp
Runtime/WKNetworkSession.cpp
Runtime/WKRuntime.cpp
Runtime/WKWebContext.cpp
Runtime/WKSettings.cpp
Runtime/WKWebsiteDataManager.cpp
Runtime/WKWebView.cpp)
target_configure_quality(WPEAndroidBrowser)
target_compile_definitions(WPEAndroidBrowser PRIVATE WPE_ENABLE_PROCESS)
target_link_libraries(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "Browser.h"
#include "WKCallback.h"
#include "WKCookieManager.h"
#include "WKNetworkSession.h"
#include "WKRuntime.h"
#include "WKSettings.h"
#include "WKWebContext.h"
#include "WKWebView.h"
Expand All @@ -31,7 +31,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* javaVM, void* /*reserved*/)
try {
JNI::initVM(javaVM);

Browser::configureJNIMappings();
WKRuntime::configureJNIMappings();
WKCallback::configureJNIMappings();
WKCookieManager::configureJNIMappings();
WKNetworkSession::configureJNIMappings();
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
#include <cassert>
#include <utility>

#include "Browser.h"
#include "Fence.h"
#include "Logging.h"
#include "SurfaceControl.h"
#include "WKRuntime.h"

RendererSurfaceControl::RendererSurfaceControl(WPEAndroidViewBackend* viewBackend, uint32_t width, uint32_t height)
: m_viewBackend(viewBackend)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

#include "SurfaceControl.h"

#include "Browser.h"
#include "ScopedWPEAndroidBuffer.h"
#include "WKRuntime.h"

namespace {

Expand Down Expand Up @@ -58,7 +58,7 @@ void onTransactionCommitedOnAnyThread(void* context, ASurfaceTransactionStats* /

// API documentation states that this callback can be dispatched from any thread.
// Let's relay the transaction completion to the UI thread.
Browser::instance().invokeOnUiThread(
WKRuntime::instance().invokeOnUiThread(
+[](void* userData) {
auto* ackCtx = reinterpret_cast<TransactionContext*>(userData);
std::move(ackCtx->m_commitCallback)();
Expand All @@ -74,7 +74,7 @@ void onTransactionCompletedOnAnyThread(void* context, ASurfaceTransactionStats*

// API documentation states that this callback can be dispatched from any thread.
// Let's relay the transaction completion to the UI thread.
Browser::instance().invokeOnUiThread(
WKRuntime::instance().invokeOnUiThread(
+[](void* userData) {
auto* ackCtx = reinterpret_cast<TransactionContext*>(userData);
std::move(ackCtx->m_completeCallback)(std::move(ackCtx->m_stats));
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "Browser.h"
#include "WKRuntime.h"

#include "Environment.h"
#include "Logging.h"
Expand All @@ -30,10 +30,10 @@
#include <wpe/webkit.h>

/***********************************************************************************************************************
* JNI mapping with Java Browser class
* JNI mapping with Java WKRuntime class
**********************************************************************************************************************/

DECLARE_JNI_CLASS_SIGNATURE(JNIBrowser, "org/wpewebkit/wpe/Browser");
DECLARE_JNI_CLASS_SIGNATURE(JNIBrowser, "org/wpewebkit/wpe/WKRuntime");

class JNIBrowserCache final : public JNI::TypedClass<JNIBrowser> {
public:
Expand Down Expand Up @@ -82,13 +82,13 @@ JNIBrowserCache::JNIBrowserCache()
registerNativeMethods(JNI::StaticNativeMethod<void()>(
"startNativeLooper",
+[](JNIEnv* /*env*/, jclass /*klass*/) {
Logging::logDebug("Browser::startNativeLooper() [tid %d]", gettid());
Logging::logDebug("WKRuntime::startNativeLooper() [tid %d]", gettid());
LooperThread::instance().startLooper();
}),
JNI::StaticNativeMethod<void(jstringArray)>(
"setupNativeEnvironment",
+[](JNIEnv* /*env*/, jclass /*klass*/, jstringArray envStringsArray) {
Logging::logDebug("Browser::setupNativeEnvironment() [tid %d]", gettid());
Logging::logDebug("WKRuntime::setupNativeEnvironment() [tid %d]", gettid());
Logging::pipeStdoutToLogcat();
Environment::configureEnvironment(envStringsArray);
}),
Expand All @@ -97,11 +97,11 @@ JNIBrowserCache::JNIBrowserCache()
+[](JNIEnv* env, jobject obj) {
getJNIBrowserCache().m_browserJavaInstance
= JNI::createTypedProtectedRef(env, reinterpret_cast<JNIBrowser>(obj), true);
Browser::instance().jniInit();
WKRuntime::instance().jniInit();
}),
JNI::NativeMethod<void()>(
"nativeShut", +[](JNIEnv*, jobject) {
Browser::instance().jniShut();
WKRuntime::instance().jniShut();
getJNIBrowserCache().m_browserJavaInstance = nullptr;
}));
}
Expand Down Expand Up @@ -145,7 +145,7 @@ void wpeTerminateProcess(void* /*backend*/, int64_t pid)
}
} // namespace

void Browser::configureJNIMappings()
void WKRuntime::configureJNIMappings()
{
getJNIBrowserCache();

Expand All @@ -161,22 +161,22 @@ void Browser::configureJNIMappings()
wpe_process_provider_register_interface(&s_processProviderInterface);
}

void Browser::jniInit()
void WKRuntime::jniInit()
{
Logging::logDebug("Browser::jniInit() [tid %d]", gettid());
Logging::logDebug("WKRuntime::jniInit() [tid %d]", gettid());
m_messagePump = std::make_unique<MessagePump>();
}

void Browser::jniShut() noexcept
void WKRuntime::jniShut() noexcept
{
try {
Logging::logDebug("Browser::jniShut() [tid %d]", gettid());
Logging::logDebug("WKRuntime::jniShut() [tid %d]", gettid());
m_messagePump = nullptr;
} catch (...) {
}
}

void Browser::invokeOnUiThread(void (*onExec)(void*), void (*onDestroy)(void*), void* userData) const noexcept
void WKRuntime::invokeOnUiThread(void (*onExec)(void*), void (*onDestroy)(void*), void* userData) const noexcept
{
m_messagePump->invoke(onExec, onDestroy, userData);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,27 @@

#include "MessagePump.h"

class Browser final {
class WKRuntime final {
public:
static void configureJNIMappings();

static Browser& instance() noexcept
static WKRuntime& instance() noexcept
{
static Browser s_singleton;
static WKRuntime s_singleton;
return s_singleton;
}

Browser(Browser&&) = delete;
Browser& operator=(Browser&&) = delete;
Browser(const Browser&) = delete;
Browser& operator=(const Browser&) = delete;
WKRuntime(WKRuntime&&) = delete;
WKRuntime& operator=(WKRuntime&&) = delete;
WKRuntime(const WKRuntime&) = delete;
WKRuntime& operator=(const WKRuntime&) = delete;

~Browser() { jniShut(); }
~WKRuntime() { jniShut(); }

void invokeOnUiThread(void (*onExec)(void*), void (*onDestroy)(void*), void* userData) const noexcept;

private:
Browser() = default;
WKRuntime() = default;

friend class JNIBrowserCache;
void jniInit();
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

#include "WKWebView.h"

#include "Browser.h"
#include "Logging.h"
#include "RendererSurfaceControl.h"
#include "WKCallback.h"
#include "WKRuntime.h"
#include "WKWebContext.h"

#include <android/native_window_jni.h>
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@
final class AuxiliaryProcessesContainer {
private static final int MAX_AUX_PROCESSES = 40;

private final AuxiliaryProcess[][] processes = new AuxiliaryProcess[ProcessType.values().length][MAX_AUX_PROCESSES];
private final AuxiliaryProcess[][] processes =
new AuxiliaryProcess[WKProcessType.values().length][MAX_AUX_PROCESSES];
private final Map<Long, AuxiliaryProcess> pidToProcessMap = new HashMap<>();
private final int[] firstAvailableSlot = new int[ProcessType.values().length];
private final int[] firstAvailableSlot = new int[WKProcessType.values().length];

public int getFirstAvailableSlot(@NonNull ProcessType processType) {
public int getFirstAvailableSlot(@NonNull WKProcessType processType) {
return firstAvailableSlot[processType.getValue()];
}

Expand Down Expand Up @@ -77,8 +78,8 @@ public AuxiliaryProcess(int processSlot, @NonNull WPEServiceConnection connectio

public int getProcessSlot() { return processSlot; }

public ProcessType getProcessType() { return serviceConnection.getProcessType(); }
public WKProcessType getProcessType() { return serviceConnection.getProcessType(); }

public void terminate() { Browser.getInstance().getApplicationContext().unbindService(serviceConnection); }
public void terminate() { WKRuntime.getInstance().getApplicationContext().unbindService(serviceConnection); }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@

import androidx.annotation.NonNull;

public enum ProcessType {
public enum WKProcessType {
WebProcess(0),
NetworkProcess(1),
WebDriverProcess(2);

private final int value;

ProcessType(int value) { this.value = value; }
WKProcessType(int value) { this.value = value; }

public static @NonNull ProcessType fromValue(int value) {
for (ProcessType entry : ProcessType.values()) {
public static @NonNull WKProcessType fromValue(int value) {
for (WKProcessType entry : WKProcessType.values()) {
if (entry.getValue() == value)
return entry;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import androidx.annotation.UiThread;
import androidx.annotation.WorkerThread;

import org.wpewebkit.wpe.AuxiliaryProcessesContainer;
import org.wpewebkit.wpe.services.WPEServiceConnection;
import org.wpewebkit.wpe.services.WPEServiceConnectionListener;

Expand All @@ -44,7 +43,7 @@
import java.util.List;

@UiThread
public final class Browser {
public final class WKRuntime {
private static final String LOGTAG = "WPEBrowser";

static { System.loadLibrary("WPEAndroidBrowser"); }
Expand All @@ -54,11 +53,11 @@ public final class Browser {
private native void nativeInit();
private native void nativeShut();

private static final Browser singleton = new Browser();
private static final WKRuntime singleton = new WKRuntime();

public static @NonNull Browser getInstance() { return singleton; }
public static @NonNull WKRuntime getInstance() { return singleton; }

private Browser() { Log.v(LOGTAG, "WPE Browser creation"); }
private WKRuntime() { Log.v(LOGTAG, "WPE WKRuntime creation"); }

private Context applicationContext = null;

Expand Down Expand Up @@ -134,7 +133,7 @@ public void onServiceDisconnected(@NonNull WPEServiceConnection connection) {
@Keep
@WorkerThread
public void launchProcess(long pid, int type, int fd) {
ProcessType processType = ProcessType.fromValue(type);
WKProcessType processType = WKProcessType.fromValue(type);
Log.d(LOGTAG, "launchProcess " + processType.name() + " (pid: " + pid + ", fd: " + fd + ")");

int processSlot = auxiliaryProcesses.getFirstAvailableSlot(processType);
Expand Down
2 changes: 1 addition & 1 deletion wpe/src/main/java/org/wpewebkit/wpe/WKWebContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface Client {
public WKWebContext(@NonNull Context context, int inspectorPort, boolean automationMode) {
this.context = context;

Browser.getInstance().initialize(context, inspectorPort);
WKRuntime.getInstance().initialize(context, inspectorPort);

nativePtr = nativeInit(automationMode);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import androidx.annotation.NonNull;

import org.wpewebkit.wpe.ProcessType;
import org.wpewebkit.wpe.WKProcessType;

import java.io.File;

Expand Down Expand Up @@ -69,6 +69,6 @@ protected void setupServiceEnvironment() {
protected void initializeServiceMain(long pid, @NonNull ParcelFileDescriptor parcelFd) {
Log.d(LOGTAG,
"initializeServiceMain() pid: " + pid + ", fd: " + parcelFd + ", native value: " + parcelFd.getFd());
initializeNativeMain(pid, ProcessType.NetworkProcess.getValue(), parcelFd.detachFd());
initializeNativeMain(pid, WKProcessType.NetworkProcess.getValue(), parcelFd.detachFd());
}
}
Loading

0 comments on commit 5986342

Please sign in to comment.