[cr145][Android] Fix for jni method overrides (#33528)

* [cr145][Android] Fix for jni method overrides

These overrides do not work unless we call appropriate DEFINE_JNI in our class.
We have to suppress this call in the upstream file to avoid class redefinition errors.

* Presubmit fixes
This commit is contained in:
samartnik
2026-01-30 17:59:49 -05:00
committed by GitHub
parent f97e43c30f
commit d511fbd06c
3 changed files with 31 additions and 17 deletions
@@ -10,13 +10,16 @@
#define JNI_AboutSettingsBridge_GetApplicationVersion \
JNI_AboutSettingsBridge_GetApplicationVersion_ChromiumImpl
// Suppress DEFINE_JNI in included file - we call it ourselves at the end
#pragma push_macro("DEFINE_JNI")
#undef DEFINE_JNI
#define DEFINE_JNI(...)
#include <chrome/browser/android/preferences/about_settings_bridge.cc>
#undef DEFINE_JNI
#pragma pop_macro("DEFINE_JNI")
#undef JNI_AboutSettingsBridge_GetApplicationVersion
// We can't use DEFINE_JNI when override upstream's JNI method as it causes
// class redefinition issues. So we use [[maybe_unused]] to suppress the error.
[[maybe_unused]] static std::string
JNI_AboutSettingsBridge_GetApplicationVersion(JNIEnv* env) {
static std::string JNI_AboutSettingsBridge_GetApplicationVersion(JNIEnv* env) {
JNI_AboutSettingsBridge_GetApplicationVersion_ChromiumImpl(env);
std::string application(base::android::apk_info::host_package_label());
@@ -28,3 +31,5 @@ JNI_AboutSettingsBridge_GetApplicationVersion(JNIEnv* env) {
return application;
}
DEFINE_JNI(AboutSettingsBridge)
@@ -24,16 +24,18 @@
#define JNI_WebsitePreferenceBridge_ClearCookieData \
JNI_WebsitePreferenceBridge_ClearCookieData_ChromiumImpl
// Suppress DEFINE_JNI in included file - we call it ourselves at the end
#pragma push_macro("DEFINE_JNI")
#undef DEFINE_JNI
#define DEFINE_JNI(...)
#include <components/browser_ui/site_settings/android/website_preference_bridge.cc>
#undef DEFINE_JNI
#pragma pop_macro("DEFINE_JNI")
#undef BACKGROUND_SYNC
#undef CLIPBOARD_READ_WRITE
#undef JNI_WebsitePreferenceBridge_ClearCookieData
// We can't use DEFINE_JNI when override upstream's JNI method as it causes
// class redefinition issues. So we use [[maybe_unused]] to suppress the error.
[[maybe_unused]] static void JNI_WebsitePreferenceBridge_ClearCookieData(
static void JNI_WebsitePreferenceBridge_ClearCookieData(
JNIEnv* env,
const jni_zero::JavaRef<jobject>& jbrowser_context_handle,
const jni_zero::JavaRef<jstring>& jorigin) {
@@ -59,3 +61,6 @@
ContentSettingsType::BRAVE_SHIELDS_METADATA, base::Value());
}
}
DEFINE_JNI(GeolocationSetting)
DEFINE_JNI(WebsitePreferenceBridge)
@@ -19,11 +19,16 @@
#include "content/public/browser/web_contents.h"
#include "url/gurl.h"
#define JNI_InterceptNavigationDelegateImpl_AssociateWithWebContents \
JNI_InterceptNavigationDelegateImpl_AssociateWithWebContents_ChromiumImpl
#define JNI_InterceptNavigationDelegateImpl_AssociateWithWebContents \
JNI_InterceptNavigationDelegateImpl_AssociateWithWebContents_ChromiumImpl \
[[maybe_unused]]
// Suppress DEFINE_JNI in included file - we call it ourselves at the end
#pragma push_macro("DEFINE_JNI")
#undef DEFINE_JNI
#define DEFINE_JNI(...)
#include <components/external_intents/android/intercept_navigation_delegate_impl.cc>
#undef DEFINE_JNI
#pragma pop_macro("DEFINE_JNI")
#undef JNI_InterceptNavigationDelegateImpl_AssociateWithWebContents
namespace external_intents {
@@ -75,10 +80,7 @@ class BraveInterceptNavigationDelegate : public InterceptNavigationDelegate {
} // namespace
// We can't use DEFINE_JNI when override upstream's JNI method as it causes
// class redefinition issues. So we use [[maybe_unused]] to suppress the error.
[[maybe_unused]] static void
JNI_InterceptNavigationDelegateImpl_AssociateWithWebContents(
static void JNI_InterceptNavigationDelegateImpl_AssociateWithWebContents(
JNIEnv* env,
const base::android::JavaRef<jobject>& jdelegate,
const base::android::JavaRef<jobject>& jweb_contents) {
@@ -93,3 +95,5 @@ JNI_InterceptNavigationDelegateImpl_AssociateWithWebContents(
}
} // namespace external_intents
DEFINE_JNI(InterceptNavigationDelegateImpl)