Title: [272854] trunk/Source/WebKit
Revision
272854
Author
commit-qu...@webkit.org
Date
2021-02-15 09:07:49 -0800 (Mon, 15 Feb 2021)

Log Message

[WPE][GTK] BubblewrapLauncher should create flatpak-info keyfile only once
https://bugs.webkit.org/show_bug.cgi?id=221224

Patch by Michael Catanzaro <mcatanz...@gnome.org> on 2021-02-15
Reviewed by Adrian Perez de Castro.

BubblewrapLauncher should create its flatpak-info keyfile only once, because its contents
will never change. Makes more sense to cache this tiny string in memory than to recompute it
every time a subprocess is launched.

When working on this, I noticed a quirk in the documentation of g_key_file_to_data: although
the function has a GError parameter, it is legacy and the function is actually guaranteed to
succeed. So icky though it seems, I've removed the error checking for that, as recommended
by its documentation.

* UIProcess/Launcher/glib/BubblewrapLauncher.cpp:
(WebKit::createFlatpakInfo):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (272853 => 272854)


--- trunk/Source/WebKit/ChangeLog	2021-02-15 17:01:18 UTC (rev 272853)
+++ trunk/Source/WebKit/ChangeLog	2021-02-15 17:07:49 UTC (rev 272854)
@@ -1,3 +1,22 @@
+2021-02-15  Michael Catanzaro  <mcatanz...@gnome.org>
+
+        [WPE][GTK] BubblewrapLauncher should create flatpak-info keyfile only once
+        https://bugs.webkit.org/show_bug.cgi?id=221224
+
+        Reviewed by Adrian Perez de Castro.
+
+        BubblewrapLauncher should create its flatpak-info keyfile only once, because its contents
+        will never change. Makes more sense to cache this tiny string in memory than to recompute it
+        every time a subprocess is launched.
+
+        When working on this, I noticed a quirk in the documentation of g_key_file_to_data: although
+        the function has a GError parameter, it is legacy and the function is actually guaranteed to
+        succeed. So icky though it seems, I've removed the error checking for that, as recommended
+        by its documentation.
+
+        * UIProcess/Launcher/glib/BubblewrapLauncher.cpp:
+        (WebKit::createFlatpakInfo):
+
 2021-02-13  Alexey Proskuryakov  <a...@apple.com>
 
         Unreviewed build fix.

Modified: trunk/Source/WebKit/UIProcess/Launcher/glib/BubblewrapLauncher.cpp (272853 => 272854)


--- trunk/Source/WebKit/UIProcess/Launcher/glib/BubblewrapLauncher.cpp	2021-02-15 17:01:18 UTC (rev 272853)
+++ trunk/Source/WebKit/UIProcess/Launcher/glib/BubblewrapLauncher.cpp	2021-02-15 17:07:49 UTC (rev 272854)
@@ -694,26 +694,24 @@
 
 static int createFlatpakInfo()
 {
-    GUniquePtr<GKeyFile> keyFile(g_key_file_new());
+    static NeverDestroyed<GUniquePtr<char>> data;
+    static size_t size;
 
-    // xdg-desktop-portal relates your name to certain permissions so we want
-    // them to be application unique which is best done via GApplication.
-    GApplication* app = g_application_get_default();
-    if (!app) {
-        g_warning("GApplication is required for xdg-desktop-portal access in the WebKit sandbox. Actions that require xdg-desktop-portal will be broken.");
-        return -1;
-    }
-    g_key_file_set_string(keyFile.get(), "Application", "name", g_application_get_application_id(app));
+    if (!data.get()) {
+        // xdg-desktop-portal relates your name to certain permissions so we want
+        // them to be application unique which is best done via GApplication.
+        GApplication* app = g_application_get_default();
+        if (!app) {
+            g_warning("GApplication is required for xdg-desktop-portal access in the WebKit sandbox. Actions that require xdg-desktop-portal will be broken.");
+            return -1;
+        }
 
-    size_t size;
-    GUniqueOutPtr<GError> error;
-    GUniquePtr<char> data(g_key_file_to_data(keyFile.get(), &size, &error.outPtr()));
-    if (error.get()) {
-        g_warning("%s", error->message);
-        return -1;
+        GUniquePtr<GKeyFile> keyFile(g_key_file_new());
+        g_key_file_set_string(keyFile.get(), "Application", "name", g_application_get_application_id(app));
+        data->reset(g_key_file_to_data(keyFile.get(), &size, nullptr));
     }
 
-    return createSealedMemFdWithData("flatpak-info", data.get(), size);
+    return createSealedMemFdWithData("flatpak-info", data->get(), size);
 }
 
 GRefPtr<GSubprocess> bubblewrapSpawn(GSubprocessLauncher* launcher, const ProcessLauncher::LaunchOptions& launchOptions, char** argv, GError **error)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to