WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
WIP Patch
bug-176236.diff (text/plain), 14.49 KB, created by
Don Olmstead
on 2022-01-19 20:39:59 PST
(
hide
)
Description:
WIP Patch
Filename:
MIME Type:
Creator:
Don Olmstead
Created:
2022-01-19 20:39:59 PST
Size:
14.49 KB
patch
obsolete
>diff --git a/Source/WTF/wtf/CMakeLists.txt b/Source/WTF/wtf/CMakeLists.txt >index ca421ba45a4d..743e1526f266 100644 >--- a/Source/WTF/wtf/CMakeLists.txt >+++ b/Source/WTF/wtf/CMakeLists.txt >@@ -224,6 +224,7 @@ set(WTF_PUBLIC_HEADERS > RefCountedLeakCounter.h > RefCounter.h > RefPtr.h >+ ResourceBundle.h > ResourceUsage.h > RetainPtr.h > RobinHoodHashMap.h >@@ -459,6 +460,7 @@ set(WTF_SOURCES > ReadWriteLock.cpp > RefCounted.cpp > RefCountedLeakCounter.cpp >+ ResourceBundle.cpp > RunLoop.cpp > SHA1.cpp > SafeStrerror.cpp >diff --git a/Source/WTF/wtf/PlatformWin.cmake b/Source/WTF/wtf/PlatformWin.cmake >index cc43a21c8eff..3b2803d459f5 100644 >--- a/Source/WTF/wtf/PlatformWin.cmake >+++ b/Source/WTF/wtf/PlatformWin.cmake >@@ -45,6 +45,7 @@ if (USE_CF) > list(APPEND WTF_SOURCES > cf/CFURLExtras.cpp > cf/FileSystemCF.cpp >+ cf/ResourceBundleCF.cpp > cf/URLCF.cpp > > text/cf/AtomStringImplCF.cpp >diff --git a/Source/WTF/wtf/ResourceBundle.cpp b/Source/WTF/wtf/ResourceBundle.cpp >new file mode 100644 >index 000000000000..8391f9c997cc >--- /dev/null >+++ b/Source/WTF/wtf/ResourceBundle.cpp >@@ -0,0 +1,74 @@ >+/* >+ * Copyright (C) 2022 Sony Interactive Entertainment Inc. >+ * >+ * 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 <wtf/ResourceBundle.h> >+ >+#if !USE(CF) >+ >+#include <wtf/FileSystem.h> >+#include <wtf/URL.h> >+ >+namespace WTF { >+ >+std::unique_ptr<ResourceBundle> ResourceBundle::create(String path) >+{ >+ if (!FileSystem::fileExists(path)) >+ return nullptr; >+ >+ return std::unique_ptr<ResourceBundle>(new ResourceBundle(path)); >+} >+ >+ResourceBundle::ResourceBundle(String root) >+ : m_root(root) >+{ } >+ >+String ResourceBundle::bundlePath() const >+{ >+ return m_root; >+} >+ >+URL ResourceBundle::bundleURL() const >+{ >+ return URL::fileURLWithFileSystemPath(m_root); >+} >+ >+String ResourceBundle::resourcePath(String name, String type, String directory) const >+{ >+ String fileName = name + "."_s + type; >+ return FileSystem::pathByAppendingComponents(m_root, { directory, fileName }); >+} >+ >+URL ResourceBundle::resourceURL(String name, String type, String directory) const >+{ >+ return URL::fileURLWithFileSystemPath(resourcePath(name, type, directory)); >+} >+ >+} // namespace WTF >+ >+#endif // !USE(CF) >diff --git a/Source/WTF/wtf/ResourceBundle.h b/Source/WTF/wtf/ResourceBundle.h >new file mode 100644 >index 000000000000..e6d9d98b31d1 >--- /dev/null >+++ b/Source/WTF/wtf/ResourceBundle.h >@@ -0,0 +1,67 @@ >+/* >+ * Copyright (C) 2022 Sony Interactive Entertainment Inc. >+ * >+ * 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. >+ */ >+ >+#pragma once >+ >+#include <wtf/Forward.h> >+ >+#if USE(CF) >+#include <wtf/RetainPtr.h> >+typedef struct __CFBundle* CFBundleRef; >+#else >+#include <wtf/text/WTFString.h> >+#endif >+ >+namespace WTF { >+ >+class ResourceBundle final { >+ WTF_MAKE_FAST_ALLOCATED; >+public: >+ WTF_EXPORT_PRIVATE static std::unique_ptr<ResourceBundle> create(String); >+ >+#if USE(CF) >+ inline operator CFBundleRef() const { return m_bundle.get(); } >+#endif >+ >+ WTF_EXPORT_PRIVATE String bundlePath() const; >+ WTF_EXPORT_PRIVATE URL bundleURL() const; >+ >+ WTF_EXPORT_PRIVATE String resourcePath(String name, String type, String directory) const; >+ WTF_EXPORT_PRIVATE URL resourceURL(String name, String type, String directory) const; >+ >+private: >+#if USE(CF) >+ ResourceBundle(CFBundleRef); >+ RetainPtr<CFBundleRef> m_bundle; >+#else >+ ResourceBundle(String); >+ String m_root; >+#endif >+}; >+ >+} // namespace WTF >diff --git a/Source/WTF/wtf/cf/ResourceBundleCF.cpp b/Source/WTF/wtf/cf/ResourceBundleCF.cpp >new file mode 100644 >index 000000000000..7fbfb0d0ccbb >--- /dev/null >+++ b/Source/WTF/wtf/cf/ResourceBundleCF.cpp >@@ -0,0 +1,91 @@ >+/* >+ * Copyright (C) 2022 Sony Interactive Entertainment Inc. >+ * >+ * 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 <wtf/ResourceBundle.h> >+ >+#include <CoreFoundation/CFBundle.h> >+#include <wtf/URL.h> >+#include <wtf/text/WTFString.h> >+ >+namespace WTF { >+ >+std::unique_ptr<ResourceBundle> ResourceBundle::create(String path) >+{ >+ auto url = CFURLCreateWithFileSystemPath( >+ kCFAllocatorDefault, >+ path.createCFString().get(), >+#if PLATFORM(WIN) >+ kCFURLWindowsPathStyle, >+#else >+ kCFURLPOSIXPathStyle, >+#endif >+ false); >+ >+ auto bundle = CFBundleCreate(kCFAllocatorDefault, url); >+ if (!bundle) >+ return nullptr; >+ >+ return std::unique_ptr<ResourceBundle>(new ResourceBundle(bundle)); >+} >+ >+ResourceBundle::ResourceBundle(CFBundleRef bundle) >+ : m_bundle(adoptCF(bundle)) >+{ } >+ >+String ResourceBundle::bundlePath() const >+{ >+ return bundleURL().fileSystemPath(); >+} >+ >+URL ResourceBundle::bundleURL() const >+{ >+ return URL(CFBundleCopyBundleURL(m_bundle.get())); >+} >+ >+String ResourceBundle::resourcePath(String name, String type, String directory) const >+{ >+ RetainPtr<CFURLRef> requestedURLRef = CFBundleCopyResourceURL(m_bundle.get(), name.createCFString().get(), type.createCFString().get(), directory.createCFString().get()); >+ if (!requestedURLRef) >+ return String(); >+ >+ static constexpr size_t maxPathSize = 4096; >+ UInt8 requestedFilePath[maxPathSize]; >+ >+ if (!CFURLGetFileSystemRepresentation(requestedURLRef.get(), false, requestedFilePath, maxPathSize)) >+ return String(); >+ >+ return String(requestedFilePath); >+} >+ >+URL ResourceBundle::resourceURL(String name, String type, String directory) const >+{ >+ return URL(CFBundleCopyResourceURL(m_bundle.get(), name.createCFString().get(), type.createCFString().get(), directory.createCFString().get())); >+} >+ >+} // namespace WTF >diff --git a/Tools/TestWebKitAPI/CMakeLists.txt b/Tools/TestWebKitAPI/CMakeLists.txt >index a1a9142ffa8b..96c938cbf0ee 100644 >--- a/Tools/TestWebKitAPI/CMakeLists.txt >+++ b/Tools/TestWebKitAPI/CMakeLists.txt >@@ -79,6 +79,7 @@ set(TestWTF_SOURCES > Tests/WTF/RefCounter.cpp > Tests/WTF/RefLogger.cpp > Tests/WTF/RefPtr.cpp >+ Tests/WTF/ResourceBundle.cpp > Tests/WTF/RobinHoodHashMap.cpp > Tests/WTF/RobinHoodHashSet.cpp > Tests/WTF/RunLoop.cpp >diff --git a/Tools/TestWebKitAPI/Tests/WTF/ResourceBundle.cpp b/Tools/TestWebKitAPI/Tests/WTF/ResourceBundle.cpp >new file mode 100644 >index 000000000000..0dfe8a147f16 >--- /dev/null >+++ b/Tools/TestWebKitAPI/Tests/WTF/ResourceBundle.cpp >@@ -0,0 +1,94 @@ >+/* >+ * Copyright (C) 2022 Sony Interactive Entertainment Inc. >+ * >+ * 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 "Test.h" >+#include <wtf/FileSystem.h> >+#include <wtf/ResourceBundle.h> >+#include <wtf/URL.h> >+ >+namespace TestWebKitAPI { >+ >+class ResourceBundleTest : public testing::Test { >+public: >+ void SetUp() override >+ { >+ // Create a temp directory to make a bundle in >+ FileSystem::PlatformFileHandle handle; >+ m_root = FileSystem::openTemporaryFile("WebKit.resources", handle); >+ FileSystem::closeFile(handle); >+ FileSystem::deleteFile(m_root); >+ >+ // Create the bundle structure >+ FileSystem::makeAllDirectories(FileSystem::pathByAppendingComponents(m_root, { "WebInspectorUI", "Protocol" })); >+ auto inspectorBackendFile = FileSystem::openFile(FileSystem::pathByAppendingComponents(m_root, { "WebInspectorUI", "Protocol", "InspectorBackendCommands.js" }), FileSystem::FileOpenMode::Write); >+ FileSystem::closeFile(inspectorBackendFile); >+ } >+ >+ void TearDown() override >+ { >+ FileSystem::deleteNonEmptyDirectory(m_root); >+ } >+ >+protected: >+ String m_root; >+}; >+ >+TEST_F(ResourceBundleTest, BundlePath) >+{ >+ auto bundle = WTF::ResourceBundle::create(m_root); >+ auto actual = bundle->bundlePath(); >+ EXPECT_TRUE(m_root == actual); >+} >+ >+TEST_F(ResourceBundleTest, BundleURL) >+{ >+ auto bundle = WTF::ResourceBundle::create(m_root); >+ auto actual = bundle->bundleURL(); >+ EXPECT_TRUE(URL::fileURLWithFileSystemPath(StringView(m_root)) == actual); >+} >+ >+TEST_F(ResourceBundleTest, ResourcePath) >+{ >+ auto bundle = WTF::ResourceBundle::create(m_root); >+ auto actual = bundle->resourcePath("InspectorBackendCommands", "js", FileSystem::pathByAppendingComponent("WebInspectorUI"_s, "Protocol"_s)); >+ auto expected = FileSystem::pathByAppendingComponents(m_root, { "WebInspectorUI", "Protocol", "InspectorBackendCommands.js" }); >+ EXPECT_TRUE(expected == actual); >+} >+ >+TEST_F(ResourceBundleTest, ResourceURL) >+{ >+ auto bundle = WTF::ResourceBundle::create(m_root); >+ auto actual = bundle->resourceURL("InspectorBackendCommands", "js", FileSystem::pathByAppendingComponent("WebInspectorUI"_s, "Protocol"_s)); >+ auto expected = FileSystem::pathByAppendingComponents(m_root, { "WebInspectorUI", "Protocol", "InspectorBackendCommands.js" }); >+ >+ EXPECT_TRUE(URL::fileURLWithFileSystemPath(StringView(expected)) == actual); >+} >+ >+} // namespace TestWebKitAPI
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
ews-feeder
:
commit-queue-
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 176236
:
449527
|
449548
|
449551
|
449606
|
449612
|
449660
|
449666
|
449677
|
449678