-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[wpe] Switch to libsoup3 based wpewebkit
This also implies using 2022_GLIB_API from wpewebkit
- Loading branch information
Showing
21 changed files
with
268 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#include "WKNetworkSession.h" | ||
|
||
#include "Logging.h" | ||
#include "WKWebContext.h" | ||
|
||
#include <unistd.h> | ||
|
||
/*********************************************************************************************************************** | ||
* JNI mapping with Java WKNetworkSession class | ||
**********************************************************************************************************************/ | ||
|
||
class JNIWKNetworkSessionCache; | ||
const JNIWKNetworkSessionCache& getJNIWKNetworkSessionCache(); | ||
|
||
class JNIWKNetworkSessionCache final : public JNI::TypedClass<JNIWKNetworkSession> { | ||
public: | ||
JNIWKNetworkSessionCache(); | ||
|
||
private: | ||
static jlong nativeInit( | ||
JNIEnv* env, jobject obj, jlong wkWebContextPtr, jboolean automationMode, jstring dataDir, jstring cacheDir); | ||
static void nativeDestroy(JNIEnv* env, jobject obj, jlong networkSessionPtr) noexcept; | ||
static jlong nativeCookieManager(JNIEnv* env, jobject obj, jlong networkSessionPtr) noexcept; | ||
static jlong nativeWebsiteDataManager(JNIEnv* env, jobject obj, jlong networkSessionPtr) noexcept; | ||
}; | ||
|
||
const JNIWKNetworkSessionCache& getJNIWKNetworkSessionCache() | ||
{ | ||
static const JNIWKNetworkSessionCache s_singleton; | ||
return s_singleton; | ||
} | ||
|
||
JNIWKNetworkSessionCache::JNIWKNetworkSessionCache() | ||
: JNI::TypedClass<JNIWKNetworkSession>(true) | ||
{ | ||
registerNativeMethods( | ||
JNI::NativeMethod<jlong(jlong, jboolean, jstring, jstring)>("nativeInit", JNIWKNetworkSessionCache::nativeInit), | ||
JNI::NativeMethod<void(jlong)>("nativeDestroy", JNIWKNetworkSessionCache::nativeDestroy), | ||
JNI::NativeMethod<jlong(jlong)>("nativeCookieManager", JNIWKNetworkSessionCache::nativeCookieManager), | ||
JNI::NativeMethod<jlong(jlong)>( | ||
"nativeWebsiteDataManager", JNIWKNetworkSessionCache::nativeWebsiteDataManager)); | ||
} | ||
|
||
jlong JNIWKNetworkSessionCache::nativeInit( | ||
JNIEnv* env, jobject obj, jlong wkWebContextPtr, jboolean automationMode, jstring dataDir, jstring cacheDir) | ||
{ | ||
Logging::logDebug("JNIWKNetworkSessionCache::nativeInit(%p, %d, %d) [tid %d]", obj, gettid()); | ||
auto* wkWebContext = reinterpret_cast<WKWebContext*>(wkWebContextPtr); // NOLINT(performance-no-int-to-ptr) | ||
// NOLINTNEXTLINE(cppcoreguidelines-owning-memory) | ||
auto* wkNetworkSession = new WKNetworkSession(env, reinterpret_cast<JNIWKNetworkSession>(obj), wkWebContext, | ||
static_cast<unsigned int>(automationMode) != 0U, JNI::String(dataDir).getContent().get(), | ||
JNI::String(cacheDir).getContent().get()); | ||
return reinterpret_cast<jlong>(wkNetworkSession); | ||
} | ||
|
||
void JNIWKNetworkSessionCache::nativeDestroy(JNIEnv* /*env*/, jobject /*obj*/, jlong networkSessionPtr) noexcept | ||
{ | ||
Logging::logDebug("JNIWKNetworkSessionCache::nativeDestroy() [tid %d]", gettid()); | ||
auto* wkNetworkSession | ||
= reinterpret_cast<WKNetworkSession*>(networkSessionPtr); // NOLINT(performance-no-int-to-ptr) | ||
delete wkNetworkSession; // NOLINT(cppcoreguidelines-owning-memory) | ||
} | ||
|
||
jlong JNIWKNetworkSessionCache::nativeCookieManager(JNIEnv* /*env*/, jobject /*obj*/, jlong networkSessionPtr) noexcept | ||
{ | ||
auto* wkNetworkSession | ||
= reinterpret_cast<WKNetworkSession*>(networkSessionPtr); // NOLINT(performance-no-int-to-ptr) | ||
return reinterpret_cast<jlong>(webkit_network_session_get_cookie_manager(wkNetworkSession->networkSession())); | ||
} | ||
|
||
jlong JNIWKNetworkSessionCache::nativeWebsiteDataManager( | ||
JNIEnv* /*env*/, jobject /*obj*/, jlong networkSessionPtr) noexcept | ||
{ | ||
auto* wkNetworkSession | ||
= reinterpret_cast<WKNetworkSession*>(networkSessionPtr); // NOLINT(performance-no-int-to-ptr) | ||
return reinterpret_cast<jlong>(webkit_network_session_get_website_data_manager(wkNetworkSession->networkSession())); | ||
} | ||
|
||
/*********************************************************************************************************************** | ||
* Native WKWebsiteDataManager class implementation | ||
**********************************************************************************************************************/ | ||
|
||
void WKNetworkSession::configureJNIMappings() { getJNIWKNetworkSessionCache(); } | ||
|
||
WKNetworkSession::WKNetworkSession(JNIEnv* env, JNIWKNetworkSession jniWKNetworkSession, WKWebContext* wkWebContext, | ||
bool automationMode, const char* dataDir, const char* cacheDir) | ||
: m_networkSessionJavaInstance(JNI::createTypedProtectedRef(env, jniWKNetworkSession, true)) | ||
{ | ||
if (automationMode) { | ||
m_networkSession | ||
= {g_object_ref(webkit_web_context_get_network_session_for_automation(wkWebContext->webContext())), | ||
[](auto* ptr) { g_object_unref(ptr); }}; | ||
} else { | ||
m_networkSession = {webkit_network_session_new(dataDir, cacheDir), [](auto* ptr) { g_object_unref(ptr); }}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* Copyright (C) 2024 Igalia S.L. <[email protected]> | ||
* Author: Jani Hautakangas <[email protected]> | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "JNI/JNI.h" | ||
|
||
#include <wpe/webkit.h> | ||
|
||
DECLARE_JNI_CLASS_SIGNATURE(JNIWKNetworkSession, "com/wpe/wpe/WKNetworkSession"); | ||
|
||
class WKWebContext; | ||
|
||
class WKNetworkSession final { | ||
public: | ||
static void configureJNIMappings(); | ||
|
||
WKNetworkSession(WKNetworkSession&&) = delete; | ||
WKNetworkSession& operator=(WKNetworkSession&&) = delete; | ||
WKNetworkSession(const WKNetworkSession&) = delete; | ||
WKNetworkSession& operator=(const WKNetworkSession&) = delete; | ||
|
||
~WKNetworkSession() = default; | ||
|
||
WebKitNetworkSession* networkSession() const noexcept { return m_networkSession.get(); } | ||
|
||
private: | ||
friend class JNIWKNetworkSessionCache; | ||
|
||
WKNetworkSession(JNIEnv* env, JNIWKNetworkSession jniWKNetworkSession, WKWebContext* wkWebContext, | ||
bool automationMode, const char* dataDir, const char* cacheDir); | ||
|
||
template <typename T> using ProtectedUniquePointer = std::unique_ptr<T, std::function<void(T*)>>; | ||
|
||
JNI::ProtectedType<JNIWKNetworkSession> m_networkSessionJavaInstance; | ||
|
||
ProtectedUniquePointer<WebKitNetworkSession> m_networkSession {}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.