commit b832b6e5b60910e79c6abc5c572b1868f233f310
parent 721a9822b0156de73cce0a0cea0963bd497637d0
Author: Makoto Kato <m_kato@ga2.so-net.ne.jp>
Date: Tue, 16 Dec 2025 01:29:21 +0000
Bug 2005985 - JNI's Ref should use C++11 style bool operator instead of pre-C++11 safe-bool idiom. r=geckoview-reviewers,ohall
Currently, GeckoView's JNI code uses the pre-C++11 safe-bool idiom to
provide boolean operator. But GeckoView can use C++11 features, so we
can simplify the code by using C++11 style bool operator.
Also, `WebResponse.Builder.isSecure` accepts the `boolean` parameter, not
`Boolean` object, so we need to change the code to pass it correctly.
Differential Revision: https://phabricator.services.mozilla.com/D276407
Diffstat:
3 files changed, 9 insertions(+), 18 deletions(-)
diff --git a/mobile/android/components/geckoview/GeckoViewStreamListener.cpp b/mobile/android/components/geckoview/GeckoViewStreamListener.cpp
@@ -273,35 +273,30 @@ void GeckoViewStreamListener::InitializeStreamSupport(nsIRequest* aRequest) {
mSupport, mozilla::MakeUnique<StreamSupport>(mSupport, aRequest));
}
-std::tuple<jni::ByteArray::LocalRef, java::sdk::Boolean::LocalRef>
+std::tuple<jni::ByteArray::LocalRef, bool>
GeckoViewStreamListener::CertificateFromChannel(nsIChannel* aChannel) {
MOZ_ASSERT(aChannel);
nsCOMPtr<nsITransportSecurityInfo> securityInfo;
aChannel->GetSecurityInfo(getter_AddRefs(securityInfo));
if (!securityInfo) {
- return std::make_tuple((jni::ByteArray::LocalRef) nullptr,
- (java::sdk::Boolean::LocalRef) nullptr);
+ return std::make_tuple((jni::ByteArray::LocalRef) nullptr, false);
}
uint32_t securityState = 0;
securityInfo->GetSecurityState(&securityState);
- auto isSecure = securityState == nsIWebProgressListener::STATE_IS_SECURE
- ? java::sdk::Boolean::TRUE()
- : java::sdk::Boolean::FALSE();
+ bool isSecure = securityState == nsIWebProgressListener::STATE_IS_SECURE;
nsCOMPtr<nsIX509Cert> cert;
securityInfo->GetServerCert(getter_AddRefs(cert));
if (!cert) {
- return std::make_tuple((jni::ByteArray::LocalRef) nullptr,
- (java::sdk::Boolean::LocalRef) nullptr);
+ return std::make_tuple((jni::ByteArray::LocalRef) nullptr, false);
}
nsTArray<uint8_t> derBytes;
nsresult rv = cert->GetRawDER(derBytes);
NS_ENSURE_SUCCESS(rv,
- std::make_tuple((jni::ByteArray::LocalRef) nullptr,
- (java::sdk::Boolean::LocalRef) nullptr));
+ std::make_tuple((jni::ByteArray::LocalRef) nullptr, false));
auto certBytes = jni::ByteArray::New(
reinterpret_cast<const int8_t*>(derBytes.Elements()), derBytes.Length());
diff --git a/mobile/android/components/geckoview/GeckoViewStreamListener.h b/mobile/android/components/geckoview/GeckoViewStreamListener.h
@@ -30,8 +30,8 @@ class GeckoViewStreamListener : public nsIStreamListener,
explicit GeckoViewStreamListener() {}
- static std::tuple<jni::ByteArray::LocalRef, java::sdk::Boolean::LocalRef>
- CertificateFromChannel(nsIChannel* aChannel);
+ static std::tuple<jni::ByteArray::LocalRef, bool> CertificateFromChannel(
+ nsIChannel* aChannel);
protected:
virtual ~GeckoViewStreamListener() {}
diff --git a/widget/android/jni/Refs.h b/widget/android/jni/Refs.h
@@ -55,8 +55,6 @@ class Ref {
friend class Ref;
using Self = Ref<Cls, Type>;
- using bool_type = void (Self::*)() const;
- void non_null_reference() const {}
// A Cls-derivative that allows copying
// (e.g. when acting as a return value).
@@ -169,10 +167,8 @@ class Ref {
return Ref<Object, jobject>(mInstance);
}
- // Null checking (e.g. !!ref) using the safe-bool idiom.
- operator bool_type() const {
- return mInstance ? &Self::non_null_reference : nullptr;
- }
+ // Null checking (e.g. !!ref)
+ explicit operator bool() const { return !!mInstance; }
// We don't allow implicit conversion to jobject because that can lead
// to easy mistakes such as assigning a temporary LocalRef to a jobject,