@@ -211,11 +211,13 @@ bool Instance::create(Config config) {
211211
212212 const ::base::has_weak_ptr guard;
213213 std::optional<bool > success;
214+ const auto debug = _debug;
214215 const auto r = config.opaqueBg .red ();
215216 const auto g = config.opaqueBg .green ();
216217 const auto b = config.opaqueBg .blue ();
217218 const auto a = config.opaqueBg .alpha ();
218- _helper.call_create (_debug, r, g, b, a, crl::guard (&guard, [&](
219+ const auto path = config.userDataPath ;
220+ _helper.call_create (debug, r, g, b, a, path, crl::guard (&guard, [&](
219221 GObject::Object source_object,
220222 Gio::AsyncResult res) {
221223 success = _helper.call_create_finish (res, nullptr );
@@ -263,7 +265,38 @@ bool Instance::create(Config config) {
263265 } else {
264266 gtk_widget_show_all (_window);
265267 }
266- _webview = webkit_web_view_new ();
268+
269+ const auto base = config.userDataPath ;
270+ const auto baseCache = base + " /cache" ;
271+ const auto baseData = base + " /data" ;
272+
273+ if (webkit_network_session_new) {
274+ _webview = GTK_WIDGET (g_object_new (
275+ WEBKIT_TYPE_WEB_VIEW,
276+ " network-session" ,
277+ webkit_network_session_new (baseData.c_str (), baseCache.c_str ())));
278+ } else {
279+ // const auto diskCache = base + "/disk";
280+ // const auto indexedDB = base + "/db";
281+ // const auto localStorage = base + "/local";
282+ // const auto offlineAppCache = base + "/offline";
283+ // const auto webSQL = base + "/sql";
284+ WebKitWebsiteDataManager *data = webkit_website_data_manager_new (
285+ " base-cache-directory" , baseCache.c_str (),
286+ " base-data-directory" , baseData.c_str (),
287+ // "disk-cache-directory", diskCache.c_str(),
288+ // "indexeddb-directory", indexedDB.c_str(),
289+ // "local-storage-directory", localStorage.c_str(),
290+ // "offline-application-cache-directory", offlineAppCache.c_str(),
291+ // "websql-directory", webSQL.c_str(),
292+ nullptr );
293+ WebKitWebContext *context = webkit_web_context_new_with_website_data_manager (data);
294+ g_object_unref (data);
295+
296+ _webview = webkit_web_view_new_with_context (context);
297+ g_object_unref (context);
298+ }
299+
267300 WebKitUserContentManager *manager =
268301 webkit_web_view_get_user_content_manager (WEBKIT_WEB_VIEW (_webview));
269302 g_signal_connect_swapped (
@@ -1054,8 +1087,13 @@ void Instance::registerHelperMethodHandlers() {
10541087 int r,
10551088 int g,
10561089 int b,
1057- int a) {
1058- if (create ({ .opaqueBg = QColor (r, g, b, a), .debug = debug })) {
1090+ int a,
1091+ const std::string &path) {
1092+ if (create ({
1093+ .opaqueBg = QColor (r, g, b, a),
1094+ .userDataPath = path,
1095+ .debug = debug,
1096+ })) {
10591097 _helper.complete_create (invocation);
10601098 } else {
10611099 invocation.return_gerror (MethodError ());
0 commit comments