From 2d5ec57287637ee063c20cede8e3028b5fc043fb Mon Sep 17 00:00:00 2001
From: Anonymous <fake-email@univ.edu>
Date: Mon, 7 Jul 2025 09:30:15 -0000
Subject: [PATCH] Visiblev8 webview for Chrome 138

---
 .../base/process_launcher/BindService.java    |  2 +-
 build/install-build-deps.py                   | 10 +++-
 chrome/android/java/AndroidManifest.xml       |  4 +-
 .../java/gin_java_method_invocation_helper.cc |  2 +
 .../gin_java_function_invocation_helper.cc    | 47 ++++++++++++++++++-
 content/renderer/renderer_main.cc             |  3 +-
 .../modules/remote_objects/remote_object.cc   |  1 +
 .../renderer/platform/bindings/v8_binding.h   |  1 +
 8 files changed, 63 insertions(+), 7 deletions(-)

diff --git a/base/android/java/src/org/chromium/base/process_launcher/BindService.java b/base/android/java/src/org/chromium/base/process_launcher/BindService.java
index c002b23dbe42e..fa5e777826fee 100644
--- a/base/android/java/src/org/chromium/base/process_launcher/BindService.java
+++ b/base/android/java/src/org/chromium/base/process_launcher/BindService.java
@@ -30,7 +30,7 @@ final class BindService {
 
     static boolean supportVariableConnections() {
         return Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
-                && !BuildConfig.IS_INCREMENTAL_INSTALL;
+                && !true;  // VisibleV8 android change required disabling renderer isolation.
     }
 
     // Note that handler is not guaranteed to be used, and client still need to correctly handle
diff --git a/build/install-build-deps.py b/build/install-build-deps.py
index f699b9b876e58..1793098953a84 100755
--- a/build/install-build-deps.py
+++ b/build/install-build-deps.py
@@ -878,8 +878,16 @@ def install_packages(options):
   try:
     packages = find_missing_packages(options)
     if packages:
+      env = os.environ.copy()
+      env["LANGUAGE"] = "en"
+      env["LANG"] = "C"
+      env["DEBIAN_FRONTEND"] = 'noninteractive'
       quiet = ["-qq", "--assume-yes"] if options.no_prompt else []
-      subprocess.check_call(["sudo", "apt-get", "install"] + quiet + packages)
+      if options.no_prompt:
+        subprocess.check_call(["sudo", "-E", "apt-get", "install"] + quiet + packages, env=env)
+      else:
+        subprocess.check_call(["sudo", "apt-get", "install"] + quiet + packages)
+
       print(file=sys.stderr)
     else:
       print("No missing packages, and the packages are up to date.",
diff --git a/chrome/android/java/AndroidManifest.xml b/chrome/android/java/AndroidManifest.xml
index f8815b416307b..ffd280d16f241 100644
--- a/chrome/android/java/AndroidManifest.xml
+++ b/chrome/android/java/AndroidManifest.xml
@@ -1246,13 +1246,13 @@ by a child template that "extends" this file.
       <service android:name="org.chromium.content.app.SandboxedProcessService{{ i }}"
           android:process=":sandboxed_process{{ i }}"
           android:permission="{{ manifest_package }}.permission.CHILD_SERVICE"
-          android:isolatedProcess="true"
+          android:isolatedProcess="false"
           android:exported="{{sandboxed_service_exported|default(false)}}"
           {% if (i == 0) %}
           android:useAppZygote="true"
           {% endif %}
           {% if (sandboxed_service_exported|default(false)) == 'true' %}
-          android:externalService="true"
+          android:externalService="false"
           tools:ignore="ExportedService"
           android:visibleToInstantApps="true"
           {% endif %} />
diff --git a/content/browser/android/java/gin_java_method_invocation_helper.cc b/content/browser/android/java/gin_java_method_invocation_helper.cc
index 719faf03919fa..2811c11c26cc0 100644
--- a/content/browser/android/java/gin_java_method_invocation_helper.cc
+++ b/content/browser/android/java/gin_java_method_invocation_helper.cc
@@ -12,6 +12,8 @@
 #include "base/android/event_log.h"
 #include "base/android/jni_android.h"
 #include "base/android/jni_string.h"
+#include "base/logging.h"
+#include "base/debug/stack_trace.h"
 #include "content/browser/android/java/gin_java_script_to_java_types_coercion.h"
 #include "content/browser/android/java/java_method.h"
 #include "content/common/android/gin_java_bridge_value.h"
diff --git a/content/renderer/java/gin_java_function_invocation_helper.cc b/content/renderer/java/gin_java_function_invocation_helper.cc
index 5acf523b3d342..4658ba570580f 100644
--- a/content/renderer/java/gin_java_function_invocation_helper.cc
+++ b/content/renderer/java/gin_java_function_invocation_helper.cc
@@ -13,6 +13,7 @@
 #include "content/renderer/java/gin_java_bridge_object.h"
 #include "content/renderer/java/gin_java_bridge_value_converter.h"
 #include "v8/include/v8-exception.h"
+#include "v8/include/v8-visiblev8.h"
 
 namespace content {
 
@@ -73,6 +74,13 @@ v8::Local<v8::Value> GinJavaFunctionInvocationHelper::Invoke(
     }
   }
 
+  std::vector<v8::Local<v8::Value>> visv8_args;
+
+  v8::Local<v8::Value> val;
+  while (args->GetNext(&val)) {
+    visv8_args.push_back(val);
+  }
+
   mojom::GinJavaBridgeError error =
       mojom::GinJavaBridgeError::kGinJavaBridgeNoError;
 
@@ -88,12 +96,25 @@ v8::Local<v8::Value> GinJavaFunctionInvocationHelper::Invoke(
       error = mojom::GinJavaBridgeError::kGinJavaBridgeObjectIsGone;
     }
   }
+
   if (!result.get()) {
     args->isolate()->ThrowException(v8::Exception::Error(gin::StringToV8(
         args->isolate(), GinJavaBridgeErrorToString(error))));
+    auto* functionCallbackInfo = args->GetFunctionCallbackInfo();
+    v8::visv8_log_java_api_call(
+        args->isolate(), false, functionCallbackInfo->Data().As<v8::String>(),
+        functionCallbackInfo->This().As<v8::Object>(),
+        v8::Undefined(args->isolate()), visv8_args, visv8_args.size());
     return v8::Undefined(args->isolate());
   }
   if (!result->is_blob()) {
+    auto* functionCallbackInfo = args->GetFunctionCallbackInfo();
+    v8::visv8_log_java_api_call(
+        args->isolate(), false, functionCallbackInfo->Data().As<v8::String>(),
+        functionCallbackInfo->This().As<v8::Object>(),
+        converter_->ToV8Value(result.get(),
+                              args->isolate()->GetCurrentContext()),
+        visv8_args, visv8_args.size());
     return converter_->ToV8Value(result.get(),
                                  args->isolate()->GetCurrentContext());
   }
@@ -109,15 +130,39 @@ v8::Local<v8::Value> GinJavaFunctionInvocationHelper::Invoke(
     if (object_result) {
       gin::Handle<GinJavaBridgeObject> controller =
           gin::CreateHandle(args->isolate(), object_result);
-      if (controller.IsEmpty())
+      if (controller.IsEmpty()) {
+        auto* functionCallbackInfo = args->GetFunctionCallbackInfo();
+        v8::visv8_log_java_api_call(
+            args->isolate(), false,
+            functionCallbackInfo->Data().As<v8::String>(),
+            functionCallbackInfo->This().As<v8::Object>(),
+            v8::Undefined(args->isolate()), visv8_args, visv8_args.size());
         return v8::Undefined(args->isolate());
+      }
+      auto* functionCallbackInfo = args->GetFunctionCallbackInfo();
+      v8::visv8_log_java_api_call(
+          args->isolate(), false, functionCallbackInfo->Data().As<v8::String>(),
+          functionCallbackInfo->This().As<v8::Object>(), controller.ToV8(),
+          visv8_args, visv8_args.size());
       return controller.ToV8();
     }
   } else if (gin_value->IsType(GinJavaBridgeValue::TYPE_NONFINITE)) {
     float float_value;
     gin_value->GetAsNonFinite(&float_value);
+    auto* functionCallbackInfo = args->GetFunctionCallbackInfo();
+    v8::visv8_log_java_api_call(args->isolate(), false,
+                                functionCallbackInfo->Data().As<v8::String>(),
+                                functionCallbackInfo->This().As<v8::Object>(),
+                                v8::Number::New(args->isolate(), float_value),
+                                visv8_args, visv8_args.size());
     return v8::Number::New(args->isolate(), float_value);
   }
+
+  auto* functionCallbackInfo = args->GetFunctionCallbackInfo();
+  v8::visv8_log_java_api_call(
+      args->isolate(), false, functionCallbackInfo->Data().As<v8::String>(),
+      functionCallbackInfo->This().As<v8::Object>(),
+      v8::Undefined(args->isolate()), visv8_args, visv8_args.size());
   return v8::Undefined(args->isolate());
 }
 
diff --git a/content/renderer/renderer_main.cc b/content/renderer/renderer_main.cc
index 1613e02e24fab..efa5ef53c422d 100644
--- a/content/renderer/renderer_main.cc
+++ b/content/renderer/renderer_main.cc
@@ -229,8 +229,7 @@ int RendererMain(MainFunctionParams parameters) {
   {
     content::ContentRendererClient* client = GetContentClient()->renderer();
     bool should_run_loop = true;
-    bool need_sandbox =
-        !command_line.HasSwitch(sandbox::policy::switches::kNoSandbox);
+    bool need_sandbox = false; // VisibleV8 disable sandbox for desktop
 
     if (!need_sandbox) {
       // The post-sandbox actions still need to happen at some point.
diff --git a/third_party/blink/renderer/modules/remote_objects/remote_object.cc b/third_party/blink/renderer/modules/remote_objects/remote_object.cc
index a12edc4ffec4f..bbae0070689fa 100644
--- a/third_party/blink/renderer/modules/remote_objects/remote_object.cc
+++ b/third_party/blink/renderer/modules/remote_objects/remote_object.cc
@@ -6,6 +6,7 @@
 
 #include <tuple>
 
+#include "base/logging.h"
 #include "base/numerics/safe_conversions.h"
 #include "gin/converter.h"
 #include "third_party/blink/public/web/blink.h"
diff --git a/third_party/blink/renderer/platform/bindings/v8_binding.h b/third_party/blink/renderer/platform/bindings/v8_binding.h
index 4c7d81cd06492..bd023d9841c10 100644
--- a/third_party/blink/renderer/platform/bindings/v8_binding.h
+++ b/third_party/blink/renderer/platform/bindings/v8_binding.h
@@ -50,6 +50,7 @@
 #include "v8/include/v8-maybe.h"
 #include "v8/include/v8-persistent-handle.h"
 #include "v8/include/v8-primitive.h"
+#include "v8/include/v8-visiblev8.h"
 #include "v8/include/v8-value.h"
 
 namespace blink {
-- 
2.43.0

