Skip to content

Commit

Permalink
[wpe] Move wpewebkit injected modules to application files folder
Browse files Browse the repository at this point in the history
  • Loading branch information
zhani committed Sep 7, 2024
1 parent 9c56aa4 commit 021d0ba
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/wpe/src/main/jniLibs/
/wpe/src/main/assets/gstreamer-1.0
/wpe/src/main/assets/gio
/wpe/src/main/assets/injected-bundles
/wpe/src/main/java/org/freedesktop/gstreamer
/tools/minibrowser/src/main/resources/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import org.wpewebkit.wpeview.WPEView
import org.wpewebkit.wpeview.WPEViewClient


const val INITIAL_URL = "https://davidwalsh.name/demo/fullscreen.php"///"https://igalia.com"
const val INITIAL_URL = "https://igalia.com"
const val SEARCH_URI_BASE = "https://duckduckgo.com/?q="

class BrowserFragment : Fragment(R.layout.fragment_browser) {
Expand Down
17 changes: 15 additions & 2 deletions tools/scripts/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,18 @@ def _copy_gio_modules(self, target_dir):
for plugin_path in Path(target_dir).rglob("*.so"):
self._replace_soname_values(plugin_path)

def _copy_wpe_injected_modules(self, target_dir):
shutil.rmtree(target_dir, True)
os.makedirs(target_dir)
sysroot_inspector_resources_file = os.path.join(
self._sysroot_dir, "lib", "wpe-webkit-2.0", "libWPEWebInspectorResources.so")
shutil.copy(sysroot_inspector_resources_file, target_dir)
sysroot_injected_bundle_file = os.path.join(
self._sysroot_dir, "lib", "wpe-webkit-2.0", "injected-bundle", "libWPEInjectedBundle.so")
shutil.copy(sysroot_injected_bundle_file, target_dir)
for injected_module_path in Path(target_dir).rglob("*.so"):
self._replace_soname_values(injected_module_path)

def _copy_gst_android_classes(self, target_dir):
shutil.rmtree(target_dir, True)
os.makedirs(target_dir)
Expand All @@ -352,8 +364,6 @@ def _copy_system_libs(self, target_dir):
sysroot_lib_dir = os.path.join(self._sysroot_dir, "lib")

libs_paths = list(Path(sysroot_lib_dir).glob("*.so"))
libs_paths.extend(list(Path(os.path.join(sysroot_lib_dir, "wpe-webkit-2.0")).glob("*.so")))
libs_paths.extend(list(Path(os.path.join(sysroot_lib_dir, "wpe-webkit-2.0", "injected-bundle")).glob("*.so")))

self._soname_replacements = Bootstrap._soname_replacements.copy()

Expand Down Expand Up @@ -464,6 +474,9 @@ def install_deps(self):
wpe_assets_gio_dir = os.path.join(wpe_src_main_dir, "assets", "gio", android_abi)
self._copy_gio_modules(wpe_assets_gio_dir)

wpe_assets_injected_bundle_dir = os.path.join(wpe_src_main_dir, "assets", "injected-bundles", android_abi)
self._copy_wpe_injected_modules(wpe_assets_injected_bundle_dir)

self._copy_gst_android_classes(os.path.join(wpe_src_main_dir, "java", "org", "freedesktop", "gstreamer"))
self._resolve_deps(wpe_imported_lib_dir, [wpe_assets_gst_dir, wpe_assets_gio_dir])

Expand Down
18 changes: 17 additions & 1 deletion wpe/src/main/java/org/wpewebkit/wpe/WKRuntime.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.os.Looper;
import android.os.ParcelFileDescriptor;
import android.util.Log;
Expand All @@ -35,6 +36,7 @@
import androidx.annotation.UiThread;
import androidx.annotation.WorkerThread;

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

Expand All @@ -44,7 +46,11 @@

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

// Bump this version number if you make any changes to the font config
// or the gstreamer plugins or else they won't be applied.
private static final String assetsVersion = "ui_process_assets_2.44.1";

static { System.loadLibrary("WPEAndroidBrowser"); }

Expand All @@ -68,9 +74,19 @@ public final class WKRuntime {
public void initialize(@NonNull Context context, int inspectorPort) {
if (applicationContext == null) {
applicationContext = context.getApplicationContext();

if (ServiceUtils.needAssets(applicationContext, assetsVersion)) {
ServiceUtils.copyFileOrDir(applicationContext, applicationContext.getAssets(), "injected-bundles",
true);
ServiceUtils.saveAssetsVersion(applicationContext, assetsVersion);
}

ApplicationInfo appInfo = applicationContext.getApplicationInfo();
List<String> envStrings = new ArrayList<>(46);
envStrings.add("GIO_EXTRA_MODULES");
envStrings.add(new File(context.getFilesDir(), "gio").getAbsolutePath());
envStrings.add("WEBKIT_INJECTED_BUNDLE_PATH");
envStrings.add(new File(context.getFilesDir(), "injected-bundles").getAbsolutePath());
if (inspectorPort > 0) {
String inspectorAddress = "127.0.0.1:" + inspectorPort;
envStrings.add("WEBKIT_INSPECTOR_SERVER");
Expand Down

0 comments on commit 021d0ba

Please sign in to comment.