[GTK] Compile all installed resources as GResources
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 May 2014 08:06:29 +0000 (08:06 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 May 2014 08:06:29 +0000 (08:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=131099

Reviewed by Philippe Normand.

Source/WebCore:
* PlatformGTK.cmake: Do not install the resources.
* platform/audio/gtk/AudioBusGtk.cpp:
(WebCore::AudioBus::loadPlatformResource): Load the audio resource
from GResources and use createBusFromInMemoryAudioFile().
* platform/graphics/Image.h: Remove unsued function loadPlatformThemeIcon.
* platform/graphics/gtk/ImageGtk.cpp:
(WebCore::loadImageFromGResource): Load the given icon name from GResources.
(WebCore::loadResourceSharedBuffer): Use char* instead of CString.
(WebCore::loadMissingImageIconFromTheme): Try to load the missing
icon from the current GTK icon theme.
(WebCore::Image::loadPlatformResource): Call
loadMissingImageIconFromTheme for missing icon or
loadImageFromGResource for any other icon name.
(WebCore::getPathToImageResource): Deleted.
(WebCore::getThemeIconFileName): Deleted.
(WebCore::loadImageFromFile): Deleted.
(WebCore::Image::loadPlatformThemeIcon): Deleted.

Source/WebKit2:
It avoids conflicts with old WebKit versions, and resources are
always found even without installing or using environment variables.

* PlatformGTK.cmake: Add rules to write the xml file with the
resources depending on the configure options and to generate and
build the GResources file.

Tools:
* Scripts/webkitpy/port/gtk.py:
(GtkPort.setup_environ_for_server): Removed now unneeded
AUDIO_RESOURCES_PATH env var.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@168894 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/PlatformGTK.cmake
Source/WebCore/platform/audio/gtk/AudioBusGtk.cpp
Source/WebCore/platform/graphics/Image.h
Source/WebCore/platform/graphics/gtk/ImageGtk.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/PlatformGTK.cmake
Tools/ChangeLog
Tools/Scripts/webkitpy/port/gtk.py

index 6db234c..375a0ff 100644 (file)
@@ -1,3 +1,28 @@
+2014-05-15  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Compile all installed resources as GResources
+        https://bugs.webkit.org/show_bug.cgi?id=131099
+
+        Reviewed by Philippe Normand.
+
+        * PlatformGTK.cmake: Do not install the resources.
+        * platform/audio/gtk/AudioBusGtk.cpp:
+        (WebCore::AudioBus::loadPlatformResource): Load the audio resource
+        from GResources and use createBusFromInMemoryAudioFile().
+        * platform/graphics/Image.h: Remove unsued function loadPlatformThemeIcon.
+        * platform/graphics/gtk/ImageGtk.cpp:
+        (WebCore::loadImageFromGResource): Load the given icon name from GResources.
+        (WebCore::loadResourceSharedBuffer): Use char* instead of CString.
+        (WebCore::loadMissingImageIconFromTheme): Try to load the missing
+        icon from the current GTK icon theme.
+        (WebCore::Image::loadPlatformResource): Call
+        loadMissingImageIconFromTheme for missing icon or
+        loadImageFromGResource for any other icon name.
+        (WebCore::getPathToImageResource): Deleted.
+        (WebCore::getThemeIconFileName): Deleted.
+        (WebCore::loadImageFromFile): Deleted.
+        (WebCore::Image::loadPlatformThemeIcon): Deleted.
+
 2014-05-14  Beth Dakin  <bdakin@apple.com>
 
         Tiled scrolling indicator needs to take topContentInset into account
index 80561a9..24125d6 100644 (file)
@@ -385,22 +385,6 @@ if (WTF_USE_EGL)
     )
 endif ()
 
-install(FILES "${WEBCORE_DIR}/Resources/textAreaResizeCorner.png"
-              "${WEBCORE_DIR}/Resources/nullPlugin.png"
-              "${WEBCORE_DIR}/Resources/urlIcon.png"
-              "${WEBCORE_DIR}/Resources/missingImage.png"
-              "${WEBCORE_DIR}/Resources/panIcon.png"
-              "${WEBCORE_DIR}/Resources/deleteButton.png"
-              "${WEBCORE_DIR}/Resources/inputSpeech.png"
-        DESTINATION "${DATA_INSTALL_DIR}/images"
-)
-
-if (ENABLE_WEB_AUDIO)
-    install(FILES "${WEBCORE_DIR}/platform/audio/resources/Composite.wav"
-            DESTINATION "${DATA_INSTALL_DIR}/resources/audio"
-    )
-endif ()
-
 if (ENABLE_WEBKIT2)
     # WebKit2 needs a version of WebCore compiled against GTK+2, so we've isolated all the GTK+
     # dependent files into a separate library which can be used to construct a GTK+2 WebCore
index 2adee9b..7a7e78d 100644 (file)
 #include "AudioBus.h"
 
 #include "AudioFileReader.h"
-#include "FileSystem.h"
-#include <glib.h>
+#include <gio/gio.h>
+#include <wtf/gobject/GRefPtr.h>
 #include <wtf/gobject/GUniquePtr.h>
-#include <wtf/text/CString.h>
 
 namespace WebCore {
 
 PassRefPtr<AudioBus> AudioBus::loadPlatformResource(const char* name, float sampleRate)
 {
-    GUniquePtr<gchar> filename(g_strdup_printf("%s.wav", name));
-    const char* environmentPath = getenv("AUDIO_RESOURCES_PATH");
-    GUniquePtr<gchar> absoluteFilename;
-    if (environmentPath)
-        absoluteFilename.reset(g_build_filename(environmentPath, filename.get(), NULL));
-    else
-        absoluteFilename.reset(g_build_filename(sharedResourcesPath().data(), "resources", "audio", filename.get(), NULL));
-    return createBusFromAudioFile(absoluteFilename.get(), false, sampleRate);
+    GUniquePtr<char> path(g_strdup_printf("/org/webkitgtk/resources/audio/%s", name));
+    GRefPtr<GBytes> data = adoptGRef(g_resources_lookup_data(path.get(), G_RESOURCE_LOOKUP_FLAGS_NONE, nullptr));
+    ASSERT(data);
+    return createBusFromInMemoryAudioFile(g_bytes_get_data(data.get(), nullptr), g_bytes_get_size(data.get()), false, sampleRate);
 }
 
 } // namespace WebCore
index be9fde2..5e456f6 100644 (file)
@@ -152,7 +152,6 @@ public:
 
 #if PLATFORM(GTK)
     virtual GdkPixbuf* getGdkPixbuf() { return 0; }
-    static PassRefPtr<Image> loadPlatformThemeIcon(const char* name, int size);
 #endif
 
 #if PLATFORM(EFL)
index d242b72..0a3b5c3 100644 (file)
 #include "config.h"
 
 #include "BitmapImage.h"
-#include "FileSystem.h"
 #include "GUniquePtrGtk.h"
 #include "GdkCairoUtilities.h"
 #include "SharedBuffer.h"
-#include <wtf/gobject/GUniquePtr.h>
-#include <wtf/text/CString.h>
 #include <cairo.h>
 #include <gtk/gtk.h>
+#include <wtf/gobject/GRefPtr.h>
+#include <wtf/gobject/GUniquePtr.h>
 
 namespace WebCore {
 
-static char* getPathToImageResource(char* resource)
-{
-    if (g_getenv("WEBKIT_TOP_LEVEL"))
-        return g_build_filename(g_getenv("WEBKIT_TOP_LEVEL"), "Source", "WebCore", "Resources", resource, NULL);
-
-    return g_build_filename(sharedResourcesPath().data(), "images", resource, NULL);
-}
-
-static CString getThemeIconFileName(const char* name, int size)
+static PassRefPtr<Image> loadImageFromGResource(const char* iconName)
 {
-    GtkIconInfo* iconInfo = gtk_icon_theme_lookup_icon(gtk_icon_theme_get_default(),
-                                                       name, size, GTK_ICON_LOOKUP_NO_SVG);
-    // Try to fallback on MISSING_IMAGE.
-    if (!iconInfo)
-        iconInfo = gtk_icon_theme_lookup_icon(gtk_icon_theme_get_default(),
-                                              GTK_STOCK_MISSING_IMAGE, size,
-                                              GTK_ICON_LOOKUP_NO_SVG);
-    if (iconInfo) {
-        GUniquePtr<GtkIconInfo> info(iconInfo);
-        return CString(gtk_icon_info_get_filename(info.get()));
-    }
-
-    // No icon was found, this can happen if not GTK theme is set. In
-    // that case an empty Image will be created.
-    return CString();
+    RefPtr<BitmapImage> icon = BitmapImage::create();
+    GUniquePtr<char> path(g_strdup_printf("/org/webkitgtk/resources/images/%s", iconName));
+    GRefPtr<GBytes> data = adoptGRef(g_resources_lookup_data(path.get(), G_RESOURCE_LOOKUP_FLAGS_NONE, nullptr));
+    ASSERT(data);
+    icon->setData(SharedBuffer::create(static_cast<const unsigned char*>(g_bytes_get_data(data.get(), nullptr)), g_bytes_get_size(data.get())), true);
+    return icon.release();
 }
 
-static PassRefPtr<SharedBuffer> loadResourceSharedBuffer(CString name)
+static PassRefPtr<SharedBuffer> loadResourceSharedBuffer(const char* filename)
 {
     GUniqueOutPtr<gchar> content;
     gsize length;
-    if (!g_file_get_contents(name.data(), &content.outPtr(), &length, 0))
+    if (!g_file_get_contents(filename, &content.outPtr(), &length, nullptr))
         return SharedBuffer::create();
 
     return SharedBuffer::create(content.get(), length);
@@ -78,33 +60,22 @@ void BitmapImage::invalidatePlatformData()
 {
 }
 
-PassRefPtr<Image> loadImageFromFile(CString fileName)
-{
-    RefPtr<BitmapImage> img = BitmapImage::create();
-    if (!fileName.isNull()) {
-        RefPtr<SharedBuffer> buffer = loadResourceSharedBuffer(fileName);
-        img->setData(buffer.release(), true);
-    }
-    return img.release();
-}
-
-PassRefPtr<Image> Image::loadPlatformResource(const char* name)
+static PassRefPtr<Image> loadMissingImageIconFromTheme()
 {
-    CString fileName;
-    if (!strcmp("missingImage", name))
-        fileName = getThemeIconFileName(GTK_STOCK_MISSING_IMAGE, 16);
-    if (fileName.isNull()) {
-        GUniquePtr<gchar> imageName(g_strdup_printf("%s.png", name));
-        GUniquePtr<gchar> glibFileName(getPathToImageResource(imageName.get()));
-        fileName = glibFileName.get();
+    RefPtr<BitmapImage> icon = BitmapImage::create();
+    GUniquePtr<GtkIconInfo> iconInfo(gtk_icon_theme_lookup_icon(gtk_icon_theme_get_default(), GTK_STOCK_MISSING_IMAGE, 16, GTK_ICON_LOOKUP_NO_SVG));
+    if (iconInfo) {
+        RefPtr<SharedBuffer> buffer = loadResourceSharedBuffer(gtk_icon_info_get_filename(iconInfo.get()));
+        icon->setData(buffer.release(), true);
+        return icon.release();
     }
 
-    return loadImageFromFile(fileName);
+    return loadImageFromGResource("missingImage");
 }
 
-PassRefPtr<Image> Image::loadPlatformThemeIcon(const char* name, int size)
+PassRefPtr<Image> Image::loadPlatformResource(const char* name)
 {
-    return loadImageFromFile(getThemeIconFileName(name, size));
+    return !strcmp("missingImage", name) ? loadMissingImageIconFromTheme() : loadImageFromGResource(name);
 }
 
 GdkPixbuf* BitmapImage::getGdkPixbuf()
index bee1844..60a76e9 100644 (file)
@@ -1,3 +1,17 @@
+2014-05-15  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Compile all installed resources as GResources
+        https://bugs.webkit.org/show_bug.cgi?id=131099
+
+        Reviewed by Philippe Normand.
+
+        It avoids conflicts with old WebKit versions, and resources are
+        always found even without installing or using environment variables.
+
+        * PlatformGTK.cmake: Add rules to write the xml file with the
+        resources depending on the configure options and to generate and
+        build the GResources file.
+
 2014-05-14  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
 
         [EFL][WK2] Fix an unit test of ewk_context_url_scheme_register()
index f0504c8..d18188f 100644 (file)
@@ -17,6 +17,7 @@ set(WebKit2_USE_PREFIX_HEADER ON)
 list(APPEND WebKit2_SOURCES
     ${DERIVED_SOURCES_WEBKIT2GTK_DIR}/InspectorGResourceBundle.c
     ${DERIVED_SOURCES_WEBKIT2GTK_DIR}/WebKit2InspectorGResourceBundle.c
+    ${DERIVED_SOURCES_WEBKIT2GTK_DIR}/WebKit2ResourcesGResourceBundle.c
 
     ${DERIVED_SOURCES_WEBKIT2GTK_API_DIR}/WebKitEnumTypes.cpp
     ${DERIVED_SOURCES_WEBKIT2GTK_API_DIR}/WebKitMarshal.cpp
@@ -504,6 +505,47 @@ add_custom_command(
     VERBATIM
 )
 
+set(WebKit2Resources
+    "        <file alias=\"images/deleteButton\">deleteButton.png</file>\n"
+    "        <file alias=\"images/missingImage\">missingImage.png</file>\n"
+    "        <file alias=\"images/panIcon\">panIcon.png</file>\n"
+    "        <file alias=\"images/textAreaResizeCorner\">textAreaResizeCorner.png</file>\n"
+)
+
+if (ENABLE_ICONDATABASE)
+    list(APPEND WebKit2Resources
+        "        <file alias=\"images/urlIcon\">urlIcon.png</file>\n"
+    )
+endif ()
+
+if (ENABLE_INPUT_SPEECH)
+    list(APPEND WebKit2Resources
+        "        <file alias=\"images/inputSpeech\">inputSpeech.png</file>\n"
+    )
+endif ()
+
+if (ENABLE_WEB_AUDIO)
+    list(APPEND WebKit2Resources
+        "        <file alias=\"audio/Composite\">Composite.wav</file>\n"
+    )
+endif ()
+
+file(WRITE ${DERIVED_SOURCES_WEBKIT2GTK_DIR}/WebKit2ResourcesGResourceBundle.xml
+    "<?xml version=1.0 encoding=UTF-8?>\n"
+    "<gresources>\n"
+    "    <gresource prefix=\"/org/webkitgtk/resources\">\n"
+    ${WebKit2Resources}
+    "    </gresource>\n"
+    "</gresources>\n"
+)
+
+add_custom_command(
+    OUTPUT ${DERIVED_SOURCES_WEBKIT2GTK_DIR}/WebKit2ResourcesGResourceBundle.c
+    DEPENDS ${DERIVED_SOURCES_WEBKIT2GTK_DIR}/WebKit2ResourcesGResourceBundle.xml
+    COMMAND glib-compile-resources --generate --sourcedir=${CMAKE_SOURCE_DIR}/Source/WebCore/Resources --sourcedir=${CMAKE_SOURCE_DIR}/Source/WebCore/platform/audio/resources --target=${DERIVED_SOURCES_WEBKIT2GTK_DIR}/WebKit2ResourcesGResourceBundle.c ${DERIVED_SOURCES_WEBKIT2GTK_DIR}/WebKit2ResourcesGResourceBundle.xml
+    VERBATIM
+)
+
 add_custom_target(webkit2gtk-forwarding-headers
     COMMAND ${PERL_EXECUTABLE} ${WEBKIT2_DIR}/Scripts/generate-forwarding-headers.pl ${WEBKIT2_DIR} ${FORWARDING_HEADERS_DIR} gtk
     COMMAND ${PERL_EXECUTABLE} ${WEBKIT2_DIR}/Scripts/generate-forwarding-headers.pl ${WEBKIT2_DIR} ${FORWARDING_HEADERS_DIR} soup
index d447280..e294f77 100644 (file)
@@ -1,3 +1,14 @@
+2014-05-15  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Compile all installed resources as GResources
+        https://bugs.webkit.org/show_bug.cgi?id=131099
+
+        Reviewed by Philippe Normand.
+
+        * Scripts/webkitpy/port/gtk.py:
+        (GtkPort.setup_environ_for_server): Removed now unneeded
+        AUDIO_RESOURCES_PATH env var.
+
 2014-05-14  Tibor Meszaros  <tmeszaros.u-szeged@partner.samsung.com>
 
         Remove CSS_STICKY_POSITION guards
index afa319c..aef3387 100644 (file)
@@ -102,7 +102,6 @@ class GtkPort(Port):
         environment['LIBOVERLAY_SCROLLBAR'] = '0'
         environment['TEST_RUNNER_INJECTED_BUNDLE_FILENAME'] = self._build_path('lib', 'libTestRunnerInjectedBundle.so')
         environment['TEST_RUNNER_TEST_PLUGIN_PATH'] = self._build_path('lib')
-        environment['AUDIO_RESOURCES_PATH'] = self.path_from_webkit_base('Source', 'WebCore', 'platform', 'audio', 'resources')
         self._copy_value_from_environ_if_set(environment, 'WEBKIT_OUTPUTDIR')
         if self.get_option("leaks"):
             #  Turn off GLib memory optimisations https://wiki.gnome.org/Valgrind.