Diff
Modified: trunk/Source/WebCore/ChangeLog (230202 => 230203)
--- trunk/Source/WebCore/ChangeLog 2018-04-03 13:34:03 UTC (rev 230202)
+++ trunk/Source/WebCore/ChangeLog 2018-04-03 15:09:10 UTC (rev 230203)
@@ -1,3 +1,29 @@
+2018-04-03 Carlos Garcia Campos <cgar...@igalia.com>
+
+ [SOUP] Stop using ResourceHandle to load GResources
+ https://bugs.webkit.org/show_bug.cgi?id=184259
+
+ Reviewed by Sergio Villar Senin.
+
+ GResources are loaded in the WebProcess using ResourceHandle because soup handles them transparently. But now
+ that we no longer use ResourceHandle, we can add a simple loader for GResources, similar to the one used for
+ data URLS, since loading a GResource is a matter of calling g_resources_lookup_data() in the end.
+
+ * SourcesGTK.txt:
+ * SourcesWPE.txt:
+ * loader/ResourceLoader.cpp:
+ (WebCore::ResourceLoader::start): Check if resource to load is a GResource and call loadGResource().
+ * loader/ResourceLoader.h:
+ * loader/soup/ResourceLoaderSoup.cpp: Added.
+ (WebCore::ResourceLoader::loadGResource): Load the GResource in a GTask thread.
+ * platform/SharedBuffer.cpp:
+ (WebCore::SharedBuffer::DataSegment::data const):
+ (WebCore::SharedBuffer::DataSegment::size const):
+ * platform/SharedBuffer.h:
+ * platform/glib/SharedBufferGlib.cpp:
+ (WebCore::SharedBuffer::SharedBuffer):
+ (WebCore::SharedBuffer::create):
+
2018-04-02 Carlos Garcia Campos <cgar...@igalia.com>
[Enchant] Clean up TextCheckerEnchant
Modified: trunk/Source/WebCore/SourcesGTK.txt (230202 => 230203)
--- trunk/Source/WebCore/SourcesGTK.txt 2018-04-03 13:34:03 UTC (rev 230202)
+++ trunk/Source/WebCore/SourcesGTK.txt 2018-04-03 15:09:10 UTC (rev 230203)
@@ -41,6 +41,8 @@
editing/atk/FrameSelectionAtk.cpp
+loader/soup/ResourceLoaderSoup.cpp
+
page/linux/ResourceUsageOverlayLinux.cpp
page/linux/ResourceUsageThreadLinux.cpp
Modified: trunk/Source/WebCore/SourcesWPE.txt (230202 => 230203)
--- trunk/Source/WebCore/SourcesWPE.txt 2018-04-03 13:34:03 UTC (rev 230202)
+++ trunk/Source/WebCore/SourcesWPE.txt 2018-04-03 15:09:10 UTC (rev 230203)
@@ -26,6 +26,8 @@
editing/wpe/EditorWPE.cpp
+loader/soup/ResourceLoaderSoup.cpp
+
page/linux/ResourceUsageOverlayLinux.cpp
page/linux/ResourceUsageThreadLinux.cpp
Modified: trunk/Source/WebCore/loader/ResourceLoader.cpp (230202 => 230203)
--- trunk/Source/WebCore/loader/ResourceLoader.cpp 2018-04-03 13:34:03 UTC (rev 230202)
+++ trunk/Source/WebCore/loader/ResourceLoader.cpp 2018-04-03 15:09:10 UTC (rev 230203)
@@ -213,6 +213,13 @@
return;
}
+#if USE(SOUP)
+ if (m_request.url().protocolIs("resource")) {
+ loadGResource();
+ return;
+ }
+#endif
+
m_handle = ResourceHandle::create(frameLoader()->networkingContext(), m_request, this, m_defersLoading, m_options.sniffContent == SniffContent, m_options.sniffContentEncoding == ContentEncodingSniffingPolicy::Sniff);
}
Modified: trunk/Source/WebCore/loader/ResourceLoader.h (230202 => 230203)
--- trunk/Source/WebCore/loader/ResourceLoader.h 2018-04-03 13:34:03 UTC (rev 230202)
+++ trunk/Source/WebCore/loader/ResourceLoader.h 2018-04-03 15:09:10 UTC (rev 230203)
@@ -210,6 +210,10 @@
bool shouldCacheResponse(ResourceHandle*, CFCachedURLResponseRef) override;
#endif
+#if USE(SOUP)
+ void loadGResource();
+#endif
+
ResourceRequest m_request;
ResourceRequest m_originalRequest; // Before redirects.
RefPtr<SharedBuffer> m_resourceData;
Added: trunk/Source/WebCore/loader/soup/ResourceLoaderSoup.cpp (0 => 230203)
--- trunk/Source/WebCore/loader/soup/ResourceLoaderSoup.cpp (rev 0)
+++ trunk/Source/WebCore/loader/soup/ResourceLoaderSoup.cpp 2018-04-03 15:09:10 UTC (rev 230203)
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2018 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "ResourceLoader.h"
+
+#include "HTTPParsers.h"
+#include "ResourceError.h"
+#include "SharedBuffer.h"
+#include <gio/gio.h>
+#include <wtf/glib/GRefPtr.h>
+#include <wtf/glib/GUniquePtr.h>
+#include <wtf/glib/RunLoopSourcePriority.h>
+
+namespace WebCore {
+
+void ResourceLoader::loadGResource()
+{
+ RefPtr<ResourceLoader> protectedThis(this);
+ GRefPtr<GTask> task = adoptGRef(g_task_new(nullptr, nullptr, [](GObject*, GAsyncResult* result, gpointer userData) {
+ RefPtr<ResourceLoader> loader = adoptRef(static_cast<ResourceLoader*>(userData));
+ if (loader->reachedTerminalState())
+ return;
+
+ auto* task = G_TASK(result);
+ URL url({ }, String::fromUTF8(static_cast<const char*>(g_task_get_task_data(task))));
+
+ GUniqueOutPtr<GError> error;
+ GRefPtr<GBytes> bytes = adoptGRef(static_cast<GBytes*>(g_task_propagate_pointer(task, &error.outPtr())));
+ if (!bytes) {
+ loader->didFail(ResourceError(g_quark_to_string(error->domain), error->code, url, String::fromUTF8(error->message)));
+ return;
+ }
+
+ if (loader->wasCancelled())
+ return;
+
+ gsize dataSize;
+ const auto* data = "" guchar*>(g_bytes_get_data(bytes.get(), &dataSize));
+ GUniquePtr<char> fileName(g_path_get_basename(url.path().utf8().data()));
+ GUniquePtr<char> contentType(g_content_type_guess(fileName.get(), data, dataSize, nullptr));
+ ResourceResponse response { url, extractMIMETypeFromMediaType(contentType.get()), static_cast<long long>(dataSize), extractCharsetFromMediaType(contentType.get()) };
+ response.setHTTPStatusCode(200);
+ response.setHTTPStatusText(ASCIILiteral("OK"));
+ response.setHTTPHeaderField(HTTPHeaderName::ContentType, contentType.get());
+ response.setSource(ResourceResponse::Source::Network);
+ loader->deliverResponseAndData(response, SharedBuffer::create(bytes.get()));
+ }, protectedThis.leakRef()));
+
+ g_task_set_priority(task.get(), RunLoopSourcePriority::AsyncIONetwork);
+ g_task_set_task_data(task.get(), g_strdup(m_request.url().string().utf8().data()), g_free);
+ g_task_run_in_thread(task.get(), [](GTask* task, gpointer, gpointer taskData, GCancellable*) {
+ URL url({ }, String::fromUTF8(static_cast<const char*>(taskData)));
+ GError* error = nullptr;
+ GBytes* bytes = g_resources_lookup_data(url.path().utf8().data(), G_RESOURCE_LOOKUP_FLAGS_NONE, &error);
+ if (!bytes)
+ g_task_return_error(task, error);
+ else
+ g_task_return_pointer(task, bytes, reinterpret_cast<GDestroyNotify>(g_bytes_unref));
+ });
+}
+
+} // namespace WebCore
Modified: trunk/Source/WebCore/platform/SharedBuffer.cpp (230202 => 230203)
--- trunk/Source/WebCore/platform/SharedBuffer.cpp 2018-04-03 13:34:03 UTC (rev 230202)
+++ trunk/Source/WebCore/platform/SharedBuffer.cpp 2018-04-03 15:09:10 UTC (rev 230203)
@@ -31,10 +31,6 @@
#include <algorithm>
#include <wtf/unicode/UTF8.h>
-#if USE(SOUP)
-#include "GUniquePtrSoup.h"
-#endif
-
namespace WebCore {
SharedBuffer::SharedBuffer(const char* data, size_t size)
@@ -212,6 +208,9 @@
#if USE(SOUP)
[](const GUniquePtr<SoupBuffer>& data) { return data->data; },
#endif
+#if USE(GLIB)
+ [](const GRefPtr<GBytes>& data) { return reinterpret_cast<const char*>(g_bytes_get_data(data.get(), nullptr)); },
+#endif
[](const FileSystem::MappedFileData& data) { return reinterpret_cast<const char*>(data.data()); }
);
return WTF::visit(visitor, m_immutableData);
@@ -233,6 +232,9 @@
#if USE(SOUP)
[](const GUniquePtr<SoupBuffer>& data) { return static_cast<size_t>(data->length); },
#endif
+#if USE(GLIB)
+ [](const GRefPtr<GBytes>& data) { return g_bytes_get_size(data.get()); },
+#endif
[](const FileSystem::MappedFileData& data) { return data.size(); }
);
return WTF::visit(visitor, m_immutableData);
Modified: trunk/Source/WebCore/platform/SharedBuffer.h (230202 => 230203)
--- trunk/Source/WebCore/platform/SharedBuffer.h 2018-04-03 13:34:03 UTC (rev 230202)
+++ trunk/Source/WebCore/platform/SharedBuffer.h 2018-04-03 15:09:10 UTC (rev 230203)
@@ -43,6 +43,11 @@
#include "GUniquePtrSoup.h"
#endif
+#if USE(GLIB)
+#include <wtf/glib/GRefPtr.h>
+typedef struct _GBytes GBytes;
+#endif
+
#if USE(FOUNDATION)
OBJC_CLASS NSArray;
OBJC_CLASS NSData;
@@ -79,6 +84,10 @@
static Ref<SharedBuffer> wrapSoupBuffer(SoupBuffer*);
#endif
+#if USE(GLIB)
+ static Ref<SharedBuffer> create(GBytes*);
+#endif
+
// Calling data() causes all the data segments to be copied into one segment if they are not already.
// Iterate the segments using begin() and end() instead.
// FIXME: Audit the call sites of this function and replace them with iteration if possible.
@@ -114,6 +123,9 @@
#if USE(SOUP)
static Ref<DataSegment> create(GUniquePtr<SoupBuffer>&& data) { return adoptRef(*new DataSegment(WTFMove(data))); }
#endif
+#if USE(GLIB)
+ static Ref<DataSegment> create(GRefPtr<GBytes>&& data) { return adoptRef(*new DataSegment(WTFMove(data))); }
+#endif
static Ref<DataSegment> create(FileSystem::MappedFileData&& data) { return adoptRef(*new DataSegment(WTFMove(data))); }
private:
@@ -127,6 +139,10 @@
DataSegment(GUniquePtr<SoupBuffer>&& data)
: m_immutableData(WTFMove(data)) { }
#endif
+#if USE(GLIB)
+ DataSegment(GRefPtr<GBytes>&& data)
+ : m_immutableData(WTFMove(data)) { }
+#endif
DataSegment(FileSystem::MappedFileData&& data)
: m_immutableData(WTFMove(data)) { }
@@ -137,6 +153,9 @@
#if USE(SOUP)
GUniquePtr<SoupBuffer>,
#endif
+#if USE(GLIB)
+ GRefPtr<GBytes>,
+#endif
FileSystem::MappedFileData> m_immutableData;
friend class SharedBuffer;
};
@@ -166,6 +185,9 @@
#if USE(SOUP)
explicit SharedBuffer(SoupBuffer*);
#endif
+#if USE(GLIB)
+ explicit SharedBuffer(GBytes*);
+#endif
void combineIntoOneSegment() const;
Modified: trunk/Source/WebCore/platform/glib/SharedBufferGlib.cpp (230202 => 230203)
--- trunk/Source/WebCore/platform/glib/SharedBufferGlib.cpp 2018-04-03 13:34:03 UTC (rev 230202)
+++ trunk/Source/WebCore/platform/glib/SharedBufferGlib.cpp 2018-04-03 15:09:10 UTC (rev 230203)
@@ -25,9 +25,20 @@
#include <glib.h>
-
namespace WebCore {
+SharedBuffer::SharedBuffer(GBytes* bytes)
+{
+ ASSERT(bytes);
+ m_size = g_bytes_get_size(bytes);
+ m_segments.append({ 0, DataSegment::create(GRefPtr<GBytes>(bytes)) });
+}
+
+Ref<SharedBuffer> SharedBuffer::create(GBytes* bytes)
+{
+ return adoptRef(*new SharedBuffer(bytes));
+}
+
RefPtr<SharedBuffer> SharedBuffer::createFromReadingFile(const String& filePath)
{
if (filePath.isEmpty())