[iOS] Mapping to UTI from tag and tag class should be performed in the UI process
authorpvollan@apple.com <pvollan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 8 Mar 2020 23:52:40 +0000 (23:52 +0000)
committerpvollan@apple.com <pvollan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 8 Mar 2020 23:52:40 +0000 (23:52 +0000)
https://bugs.webkit.org/show_bug.cgi?id=208783

Reviewed by Brent Fulgham.

Source/WebCore:

This mapping should be done in the UI process, since it is using a system service that will no longer be available
in the WebContent process. To achieve this, the method +[UTTypeRecord typeRecordWithTagOverride] is swizzled in
the WebContent process, and is using the cached mapping sent from the UI process.

API test: WebKit.UTIFromTag

* WebCore.xcodeproj/project.pbxproj:
* platform/cocoa/UTTypeRecordSwizzler.h: Added.
(WebCore::UTTypeItem::encode const):
(WebCore::UTTypeItem::decode):
* platform/cocoa/UTTypeRecordSwizzler.mm: Added.
(-[WebUTTypeRecord setIdentifier:]):
(WebCore::vectorOfUTTypeRecords):
(WebCore::typeRecordWithTagOverride):
(WebCore::createVectorOfUTTypeItem):
(WebCore::setVectorOfUTTypeItem):
(WebCore::swizzleUTTypeRecord):
* platform/network/mac/UTIUtilities.h:
* platform/network/mac/UTIUtilities.mm:
(WebCore::UTIFromTag):
* testing/Internals.cpp:
(WebCore::Internals::getUTIFromTag):
* testing/Internals.h:
* testing/Internals.idl:
* testing/Internals.mm:
(WebCore::Internals::getUTIFromTag):

Source/WebCore/PAL:

* PAL.xcodeproj/project.pbxproj:
* pal/spi/cocoa/NSUTTypeRecordSPI.h: Added.

Source/WebKit:

Send mapping from tag/tag class to UTI from the UI process to the WebContent process as part of the WebProcess
creation parameters. Also, issue some mach-lookup extensions to the WebContent process if Accessibility is
enabled.

* Resources/SandboxProfiles/ios/com.apple.WebKit.WebContent.sb:
* Shared/WebProcessCreationParameters.cpp:
(WebKit::WebProcessCreationParameters::encode const):
(WebKit::WebProcessCreationParameters::decode):
* Shared/WebProcessCreationParameters.h:
* UIProcess/Cocoa/WebProcessPoolCocoa.mm:
(WebKit::WebProcessPool::platformInitializeWebProcess):
* WebProcess/cocoa/WebProcessCocoa.mm:
(WebKit::WebProcess::platformInitializeWebProcess):

Source/WTF:

* wtf/PlatformUse.h:

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:

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

24 files changed:
Source/WTF/ChangeLog
Source/WTF/wtf/PlatformUse.h
Source/WebCore/ChangeLog
Source/WebCore/PAL/ChangeLog
Source/WebCore/PAL/PAL.xcodeproj/project.pbxproj
Source/WebCore/PAL/pal/spi/cocoa/NSUTTypeRecordSPI.h [new file with mode: 0644]
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/cocoa/UTTypeRecordSwizzler.h [new file with mode: 0644]
Source/WebCore/platform/cocoa/UTTypeRecordSwizzler.mm [new file with mode: 0644]
Source/WebCore/platform/network/mac/UTIUtilities.h
Source/WebCore/platform/network/mac/UTIUtilities.mm
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl
Source/WebCore/testing/Internals.mm
Source/WebKit/ChangeLog
Source/WebKit/Resources/SandboxProfiles/ios/com.apple.WebKit.WebContent.sb
Source/WebKit/Shared/WebProcessCreationParameters.cpp
Source/WebKit/Shared/WebProcessCreationParameters.h
Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm
Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKit/UTIFromTag.mm [new file with mode: 0644]

index 96f2c63..4e398d5 100644 (file)
@@ -1,3 +1,12 @@
+2020-03-08  Per Arne Vollan  <pvollan@apple.com>
+
+        [iOS] Mapping to UTI from tag and tag class should be performed in the UI process
+        https://bugs.webkit.org/show_bug.cgi?id=208783
+
+        Reviewed by Brent Fulgham.
+
+        * wtf/PlatformUse.h:
+
 2020-03-08  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         Lazily generate CGPaths for some simple types of paths, such as arcs and lines
index d2c0653..55ee64e 100644 (file)
 #if PLATFORM(COCOA) && !(PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101600)
 #define USE_CTFONTTRANSFORMGLYPHSWITHLANGUAGE 1
 #endif
+
+#if PLATFORM(IOS_FAMILY) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 140000
+#define USE_UTTYPE_SWIZZLER 1
+#endif
index ab338f4..30f4136 100644 (file)
@@ -1,3 +1,37 @@
+2020-03-08  Per Arne Vollan  <pvollan@apple.com>
+
+        [iOS] Mapping to UTI from tag and tag class should be performed in the UI process
+        https://bugs.webkit.org/show_bug.cgi?id=208783
+
+        Reviewed by Brent Fulgham.
+
+        This mapping should be done in the UI process, since it is using a system service that will no longer be available
+        in the WebContent process. To achieve this, the method +[UTTypeRecord typeRecordWithTagOverride] is swizzled in
+        the WebContent process, and is using the cached mapping sent from the UI process.
+
+        API test: WebKit.UTIFromTag
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/cocoa/UTTypeRecordSwizzler.h: Added.
+        (WebCore::UTTypeItem::encode const):
+        (WebCore::UTTypeItem::decode):
+        * platform/cocoa/UTTypeRecordSwizzler.mm: Added.
+        (-[WebUTTypeRecord setIdentifier:]):
+        (WebCore::vectorOfUTTypeRecords):
+        (WebCore::typeRecordWithTagOverride):
+        (WebCore::createVectorOfUTTypeItem):
+        (WebCore::setVectorOfUTTypeItem):
+        (WebCore::swizzleUTTypeRecord):
+        * platform/network/mac/UTIUtilities.h:
+        * platform/network/mac/UTIUtilities.mm:
+        (WebCore::UTIFromTag):
+        * testing/Internals.cpp:
+        (WebCore::Internals::getUTIFromTag):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+        * testing/Internals.mm:
+        (WebCore::Internals::getUTIFromTag):
+
 2020-03-08  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         Lazily generate CGPaths for some simple types of paths, such as arcs and lines
index 6a53ee3..1cc336f 100644 (file)
@@ -1,3 +1,13 @@
+2020-03-08  Per Arne Vollan  <pvollan@apple.com>
+
+        [iOS] Mapping to UTI from tag and tag class should be performed in the UI process
+        https://bugs.webkit.org/show_bug.cgi?id=208783
+
+        Reviewed by Brent Fulgham.
+
+        * PAL.xcodeproj/project.pbxproj:
+        * pal/spi/cocoa/NSUTTypeRecordSPI.h: Added.
+
 2020-03-08  Konstantin Tokarev  <annulen@yandex.ru>
 
         [CMake] Some fixes for building Mac port
index cdff9af..56d0790 100644 (file)
                CDACB35F23873E480018D7CE /* MediaToolboxSoftLink.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MediaToolboxSoftLink.h; sourceTree = "<group>"; };
                CDF91112220E4EEC001EA39E /* CelestialSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CelestialSPI.h; sourceTree = "<group>"; };
                CE5673862151A7B9002F92D7 /* IOKitSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IOKitSPI.h; sourceTree = "<group>"; };
+               E3037F4F2415ADF40031CA0F /* NSUTTypeRecordSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NSUTTypeRecordSPI.h; sourceTree = "<group>"; };
                E5D45D112106A07400D2B738 /* NSColorWellSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSColorWellSPI.h; sourceTree = "<group>"; };
                E5D45D132106A18700D2B738 /* NSPopoverColorWellSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSPopoverColorWellSPI.h; sourceTree = "<group>"; };
                F442915D1FA52473002CC93E /* NSFileSizeFormatterSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NSFileSizeFormatterSPI.h; sourceTree = "<group>"; };
                                0C2DA1371F3BEB4900DBC317 /* NSURLDownloadSPI.h */,
                                0C2DA1381F3BEB4900DBC317 /* NSURLFileTypeMappingsSPI.h */,
                                C15CBB3223F34A1200300CC7 /* NSUserDefaultsSPI.h */,
+                               E3037F4F2415ADF40031CA0F /* NSUTTypeRecordSPI.h */,
                                570AB8F820AF6E3D00B8BE87 /* NSXPCConnectionSPI.h */,
                                0C2DA1391F3BEB4900DBC317 /* PassKitSPI.h */,
                                0C2DA13A1F3BEB4900DBC317 /* pthreadSPI.h */,
diff --git a/Source/WebCore/PAL/pal/spi/cocoa/NSUTTypeRecordSPI.h b/Source/WebCore/PAL/pal/spi/cocoa/NSUTTypeRecordSPI.h
new file mode 100644 (file)
index 0000000..b0a333a
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2020 Apple Inc.  All rights reserved.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``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 INC. OR
+ * 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
+
+#if USE(APPLE_INTERNAL_SDK)
+
+#import <CoreServices/LSPropertyListPriv.h>
+#import <CoreServices/UTTypeRecordPriv.h>
+
+#else
+
+__attribute__((visibility("default")))
+@interface LSRecord : NSObject <NSCopying, NSDiscardableContent>
+@end
+
+__attribute__((visibility("default")))
+@interface UTTypeRecord : LSRecord
++ (nullable instancetype)typeRecordWithTag:(NSString *)tag ofClass:(NSString *)tagClass conformingToIdentifier:(NSString *)conformsTo;
+@property (readonly) NSString *identifier;
+@end
+
+#endif
index 98e2084..a311536 100644 (file)
                E3BBC24723835526006EC39F /* CSSValueKey.h in Headers */ = {isa = PBXBuildFile; fileRef = E3BBC2452383551A006EC39F /* CSSValueKey.h */; settings = {ATTRIBUTES = (Private, ); }; };
                E3C99A091DC3D41C00794AD3 /* DOMJITCheckDOM.h in Headers */ = {isa = PBXBuildFile; fileRef = E3C99A081DC3D41700794AD3 /* DOMJITCheckDOM.h */; };
                E3C9AECB2113149900419B92 /* JSMicrotaskCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = E3C9AEC92113147400419B92 /* JSMicrotaskCallback.h */; };
+               E3CAAA6124155F8700CED2E2 /* UTTypeRecordSwizzler.h in Headers */ = {isa = PBXBuildFile; fileRef = E3CAAA5E24155EF200CED2E2 /* UTTypeRecordSwizzler.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               E3CAAA622415613200CED2E2 /* UTTypeRecordSwizzler.mm in Sources */ = {isa = PBXBuildFile; fileRef = E3CAAA6024155EF300CED2E2 /* UTTypeRecordSwizzler.mm */; };
                E3E4E2A81E3B17100023BB8A /* ScriptElementCachedScriptFetcher.h in Headers */ = {isa = PBXBuildFile; fileRef = E3E4E2A61E3B16FC0023BB8A /* ScriptElementCachedScriptFetcher.h */; settings = {ATTRIBUTES = (Private, ); }; };
                E3FA38641D71812D00AA5950 /* PendingScriptClient.h in Headers */ = {isa = PBXBuildFile; fileRef = E3FA38611D716E7600AA5950 /* PendingScriptClient.h */; };
                E401C27517CE53EC00C41A35 /* ElementIteratorAssertions.h in Headers */ = {isa = PBXBuildFile; fileRef = E401C27417CE53EC00C41A35 /* ElementIteratorAssertions.h */; settings = {ATTRIBUTES = (Private, ); }; };
                E3BF19E722AF309F009C9926 /* SecurityPolicyViolationEvent.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SecurityPolicyViolationEvent.cpp; sourceTree = "<group>"; };
                E3C99A081DC3D41700794AD3 /* DOMJITCheckDOM.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMJITCheckDOM.h; sourceTree = "<group>"; };
                E3C9AEC92113147400419B92 /* JSMicrotaskCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSMicrotaskCallback.h; sourceTree = "<group>"; };
+               E3CAAA5E24155EF200CED2E2 /* UTTypeRecordSwizzler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UTTypeRecordSwizzler.h; sourceTree = "<group>"; };
+               E3CAAA6024155EF300CED2E2 /* UTTypeRecordSwizzler.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = UTTypeRecordSwizzler.mm; sourceTree = "<group>"; };
                E3D049931DADC04500718F3C /* NodeConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NodeConstants.h; sourceTree = "<group>"; };
                E3E4E2A51E3B16FC0023BB8A /* ScriptElementCachedScriptFetcher.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScriptElementCachedScriptFetcher.cpp; sourceTree = "<group>"; };
                E3E4E2A61E3B16FC0023BB8A /* ScriptElementCachedScriptFetcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScriptElementCachedScriptFetcher.h; sourceTree = "<group>"; };
                                310D71941B335C9D009C7B73 /* ThemeCocoa.h */,
                                310D71931B335C9D009C7B73 /* ThemeCocoa.mm */,
                                A3AF9D81203252EE006CAD06 /* UserAgentCocoa.mm */,
+                               E3CAAA5E24155EF200CED2E2 /* UTTypeRecordSwizzler.h */,
+                               E3CAAA6024155EF300CED2E2 /* UTTypeRecordSwizzler.mm */,
                                52B0D4BF1C57FD660077CE53 /* VideoFullscreenChangeObserver.h */,
                                52D5A1A41C57488900DE34A3 /* VideoFullscreenModel.h */,
                                52D5A1A51C57488900DE34A3 /* VideoFullscreenModelVideoElement.h */,
                                572B40362176A922000AD43E /* UserVerificationRequirement.h in Headers */,
                                55AF14E61EAAC59B0026EEAA /* UTIRegistry.h in Headers */,
                                1FAFBF1915A5FA7400083A20 /* UTIUtilities.h in Headers */,
+                               E3CAAA6124155F8700CED2E2 /* UTTypeRecordSwizzler.h in Headers */,
                                83C45B8E1DC2B68A008871BA /* ValidationBubble.h in Headers */,
                                F5A154281279534D00D0B0C0 /* ValidationMessage.h in Headers */,
                                F513A3EA15FF4841001526DB /* ValidationMessageClient.h in Headers */,
                                7C3B79711908757B00B47A2D /* UserMessageHandler.cpp in Sources */,
                                7CE68344192143A800F4D928 /* UserMessageHandlerDescriptor.cpp in Sources */,
                                7C73FB07191EF417007DE061 /* UserMessageHandlersNamespace.cpp in Sources */,
+                               E3CAAA622415613200CED2E2 /* UTTypeRecordSwizzler.mm in Sources */,
                                3FBC4AF3189881560046EE38 /* VideoFullscreenInterfaceAVKit.mm in Sources */,
                                52D5A18F1C54592300DE34A3 /* VideoLayerManagerObjC.mm in Sources */,
                                BE88E0DE1715D2A200658D98 /* VideoTrack.cpp in Sources */,
diff --git a/Source/WebCore/platform/cocoa/UTTypeRecordSwizzler.h b/Source/WebCore/platform/cocoa/UTTypeRecordSwizzler.h
new file mode 100644 (file)
index 0000000..aa25286
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. 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 INC. 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
+
+#if USE(UTTYPE_SWIZZLER)
+
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+struct UTTypeItem {
+    String tag;
+    String tagClass;
+    String identifier;
+    String uti;
+
+    template<class Encoder> void encode(Encoder&) const;
+    template<class Decoder> static Optional<UTTypeItem> decode(Decoder&);
+};
+
+WEBCORE_EXPORT void swizzleUTTypeRecord();
+
+WEBCORE_EXPORT const Vector<UTTypeItem>& createVectorOfUTTypeItem();
+WEBCORE_EXPORT void setVectorOfUTTypeItem(Vector<UTTypeItem>&&);
+
+template<class Encoder>
+void UTTypeItem::encode(Encoder& encoder) const
+{
+    encoder << tag;
+    encoder << tagClass;
+    encoder << identifier;
+    encoder << uti;
+}
+
+template<class Decoder>
+Optional<UTTypeItem> UTTypeItem::decode(Decoder& decoder)
+{
+    Optional<String> tag;
+    decoder >> tag;
+    if (!tag)
+        return WTF::nullopt;
+
+    Optional<String> tagClass;
+    decoder >> tagClass;
+    if (!tagClass)
+        return WTF::nullopt;
+
+    Optional<String> identifier;
+    decoder >> identifier;
+    if (!identifier)
+        return WTF::nullopt;
+
+    Optional<String> uti;
+    decoder >> uti;
+    if (!uti)
+        return WTF::nullopt;
+
+    return UTTypeItem { *tag, *tagClass, *identifier, *uti };
+}
+};
+
+#endif
diff --git a/Source/WebCore/platform/cocoa/UTTypeRecordSwizzler.mm b/Source/WebCore/platform/cocoa/UTTypeRecordSwizzler.mm
new file mode 100644 (file)
index 0000000..b010689
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+* Copyright (C) 2020 Apple Inc. All rights reserved.
+*
+* 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.
+*
+* THIS SOFTWARE IS PROVIDED BY APPLE INC. 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 INC. 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.
+*/
+
+#import "config.h"
+#import "UTTypeRecordSwizzler.h"
+
+#if USE(UTTYPE_SWIZZLER)
+
+#import <MobileCoreServices/MobileCoreServices.h>
+
+#import <WebCore/UTIUtilities.h>
+#import <pal/spi/cocoa/NSUTTypeRecordSPI.h>
+#import <wtf/NeverDestroyed.h>
+#import <wtf/ObjCRuntimeExtras.h>
+#import <wtf/SoftLinking.h>
+#import <wtf/Vector.h>
+#import <wtf/text/WTFString.h>
+
+__attribute__((visibility("default")))
+@interface WebUTTypeRecord : UTTypeRecord
+- (void)setIdentifier:(NSString *)i;
+@end
+
+@implementation WebUTTypeRecord {
+@package
+    NSString *_identifier;
+}
+@synthesize identifier=_identifier;
+- (void)setIdentifier:(NSString *)i
+{
+    _identifier = i;
+}
+@end
+
+namespace WebCore {
+
+static Vector<UTTypeItem>& vectorOfUTTypeRecords()
+{
+    static NeverDestroyed<Vector<UTTypeItem>> vector;
+    return vector;
+}
+
+static IMP typeRecordWithTagOriginal = nil;
+
+static UTTypeRecord *typeRecordWithTagOverride(id self, SEL selector, NSString *tag, NSString *tagClass, NSString *identifier)
+{
+    for (auto& r : vectorOfUTTypeRecords()) {
+        if (r.tag == String(tag) && r.tagClass == String(tagClass) && r.identifier == String(identifier)) {
+            WebUTTypeRecord *record = [WebUTTypeRecord alloc];
+            [record setIdentifier:r.uti];
+            return [record autorelease];
+        }
+    }
+    WTFLogAlways("UTI not found for tag: %s %s %s\n", String(tag).utf8().data(), String(tagClass).utf8().data(), String(identifier).utf8().data());
+    return wtfCallIMP<UTTypeRecord *>(typeRecordWithTagOriginal, self, selector, tag, tagClass, identifier);
+}
+
+const Vector<UTTypeItem>& createVectorOfUTTypeItem()
+{
+    static NeverDestroyed<Vector<UTTypeItem>> vector = [] {
+        Vector<UTTypeItem> v = std::initializer_list<UTTypeItem> {
+            { "dat"_s, "public.filename-extension"_s, static_cast<char*>(nullptr), static_cast<char*>(nullptr) },
+            { "mp4"_s, "public.filename-extension"_s, static_cast<char*>(nullptr), static_cast<char*>(nullptr) },
+            { "otf"_s, "public.filename-extension"_s, static_cast<char*>(nullptr), static_cast<char*>(nullptr) },
+        };
+        for (auto& r : v) {
+            auto uti = adoptCF(UTTypeCreatePreferredIdentifierForTag(r.tagClass.createCFString().get(), r.tag.createCFString().get(), r.identifier.isNull() ? nullptr : r.identifier.createCFString().get()));
+            r.uti = uti.get();
+        }
+        for (auto& it : createUTIFromMIMETypeMap()) {
+            UTTypeItem i = { it.key, "public.mime-type"_s, static_cast<char*>(nullptr), static_cast<char*>(nullptr) };
+            auto uti = adoptCF(UTTypeCreatePreferredIdentifierForTag(i.tagClass.createCFString().get(), i.tag.createCFString().get(), i.identifier.isNull() ? nullptr : i.identifier.createCFString().get()));
+            i.uti = uti.get();
+            v.append(WTFMove(i));
+        }
+        return v;
+    }();
+    return vector;
+}
+
+void setVectorOfUTTypeItem(Vector<UTTypeItem>&& vector)
+{
+    vectorOfUTTypeRecords() = WTFMove(vector);
+}
+
+void swizzleUTTypeRecord()
+{
+    Method typeRecordWithTagMethod = class_getClassMethod(objc_getClass("UTTypeRecord"), @selector(typeRecordWithTag: ofClass: conformingToIdentifier:));
+    typeRecordWithTagOriginal = method_setImplementation(typeRecordWithTagMethod, (IMP)typeRecordWithTagOverride);
+}
+
+};
+
+#endif
index 739558e..09ab09f 100644 (file)
@@ -33,6 +33,7 @@ WEBCORE_EXPORT String MIMETypeFromUTI(const String&);
 String MIMETypeFromUTITree(const String&);
 WEBCORE_EXPORT String UTIFromMIMEType(const String&);
 bool isDeclaredUTI(const String&);
+WEBCORE_EXPORT String UTIFromTag(const String& tagClass, const String& tag, const String& conformingToUTI);
 
 WEBCORE_EXPORT void setUTIFromMIMETypeMap(HashMap<String, String>&&);
 WEBCORE_EXPORT const HashMap<String, String>& createUTIFromMIMETypeMap();
index 8c64665..3d2acfc 100644 (file)
@@ -161,6 +161,12 @@ bool isDeclaredUTI(const String& UTI)
     return UTTypeIsDeclared(UTI.createCFString().get());
 }
 
+String UTIFromTag(const String& tagClass, const String& tag, const String& conformingToUTI)
+{
+    auto u = adoptCF(UTTypeCreatePreferredIdentifierForTag(tagClass.createCFString().get(), tag.createCFString().get(), conformingToUTI.createCFString().get()));
+    return String(u.get());
+}
+
 static const Vector<String>& additionalMIMETypes()
 {
     static NeverDestroyed<Vector<String>> mimeTypes = std::initializer_list<String> {
index 91dad5e..3dd675a 100644 (file)
@@ -5501,6 +5501,11 @@ String Internals::getUTIFromMIMEType(const String& mimeType)
 {
     return emptyString();
 }
+
+String Internals::getUTIFromTag(const String& tagClass, const String& tag, const String& conformingToUTI)
+{
+    return emptyString();
+}
 #endif
 
 String Internals::mediaMIMETypeForExtension(const String& extension)
index 8984e9d..7b9775a 100644 (file)
@@ -943,6 +943,7 @@ public:
     String mediaMIMETypeForExtension(const String& extension);
 
     String getUTIFromMIMEType(const String& mimeType);
+    String getUTIFromTag(const String& tagClass, const String& tag, const String& conformingToUTI);
 
     bool supportsPictureInPicture();
 
index 5bbe04d..5086054 100644 (file)
@@ -853,6 +853,7 @@ enum CompositingPolicy {
     DOMString mediaMIMETypeForExtension(DOMString extension);
 
     DOMString getUTIFromMIMEType(DOMString mimeType);
+    DOMString getUTIFromTag(DOMString tagClass, DOMString tag, DOMString conformingToUTI);
 
     boolean supportsPictureInPicture();
 };
index 69f43a7..a567c8c 100644 (file)
@@ -106,4 +106,9 @@ String Internals::getUTIFromMIMEType(const String& mimeType)
     return UTIFromMIMEType(mimeType);
 }
 
+String Internals::getUTIFromTag(const String& tagClass, const String& tag, const String& conformingToUTI)
+{
+    return UTIFromTag(tagClass, tag, conformingToUTI);
+}
+
 }
index 9416d14..b2f8cd8 100644 (file)
@@ -1,5 +1,26 @@
 2020-03-08  Per Arne Vollan  <pvollan@apple.com>
 
+        [iOS] Mapping to UTI from tag and tag class should be performed in the UI process
+        https://bugs.webkit.org/show_bug.cgi?id=208783
+
+        Reviewed by Brent Fulgham.
+
+        Send mapping from tag/tag class to UTI from the UI process to the WebContent process as part of the WebProcess
+        creation parameters. Also, issue some mach-lookup extensions to the WebContent process if Accessibility is
+        enabled.
+
+        * Resources/SandboxProfiles/ios/com.apple.WebKit.WebContent.sb:
+        * Shared/WebProcessCreationParameters.cpp:
+        (WebKit::WebProcessCreationParameters::encode const):
+        (WebKit::WebProcessCreationParameters::decode):
+        * Shared/WebProcessCreationParameters.h:
+        * UIProcess/Cocoa/WebProcessPoolCocoa.mm:
+        (WebKit::WebProcessPool::platformInitializeWebProcess):
+        * WebProcess/cocoa/WebProcessCocoa.mm:
+        (WebKit::WebProcess::platformInitializeWebProcess):
+
+2020-03-08  Per Arne Vollan  <pvollan@apple.com>
+
         REGRESSION (r258064): API tests intermittently crashing under WebKit::registerDefaultsOverride
         https://bugs.webkit.org/show_bug.cgi?id=208784
         <rdar://problem/60201631>
index beaf491..0bb2f28 100644 (file)
 (allow mach-lookup
     (require-all
         (extension "com.apple.webkit.extension.mach")
-        (global-name "com.apple.iphone.axserver-systemwide" "com.apple.tccd" "com.apple.nehelper" "com.apple.nesessionmanager.content-filter" "com.apple.uikit.viewservice.com.apple.WebContentFilter.remoteUI" "com.apple.diagnosticd" "com.apple.lsd.open" "com.apple.mobileassetd" "com.apple.mobileassetd.v2" "com.apple.frontboard.systemappservices" "com.apple.iconservices" "com.apple.webinspector" "com.apple.PowerManagement.control" "com.apple.cfprefsd.daemon"
+        (global-name "com.apple.iphone.axserver-systemwide" "com.apple.tccd" "com.apple.nehelper" "com.apple.nesessionmanager.content-filter" "com.apple.uikit.viewservice.com.apple.WebContentFilter.remoteUI" "com.apple.diagnosticd" "com.apple.lsd.open" "com.apple.mobileassetd" "com.apple.mobileassetd.v2" "com.apple.frontboard.systemappservices" "com.apple.iconservices" "com.apple.webinspector" "com.apple.PowerManagement.control" "com.apple.cfprefsd.daemon" "com.apple.lsd.mapdb"
 
             ;;; FIXME(207716): The following should be removed when the GPU process is complete
             "com.apple.airplay.apsynccontroller.xpc" "com.apple.audio.AURemoteIOServer" "com.apple.audio.AudioComponentRegistrar"
index 665cc03..04d3f8b 100644 (file)
@@ -180,6 +180,9 @@ void WebProcessCreationParameters::encode(IPC::Encoder& encoder) const
     encoder << cssValueToSystemColorMap;
     encoder << focusRingColor;
     encoder << localizedDeviceModel;
+#if USE(UTTYPE_SWIZZLER)
+    encoder << vectorOfUTTypeItem;
+#endif
 #endif
 
 #if PLATFORM(COCOA)
@@ -493,6 +496,14 @@ bool WebProcessCreationParameters::decode(IPC::Decoder& decoder, WebProcessCreat
     
     if (!decoder.decode(parameters.localizedDeviceModel))
         return false;
+    
+#if USE(UTTYPE_SWIZZLER)
+    Optional<Vector<UTTypeItem>> vectorOfUTTypeItem;
+    decoder >> vectorOfUTTypeItem;
+    if (!vectorOfUTTypeItem)
+        return false;
+    parameters.vectorOfUTTypeItem = WTFMove(*vectorOfUTTypeItem);
+#endif
 #endif
 
 #if PLATFORM(COCOA)
index 7d42b1e..5cde19e 100644 (file)
@@ -53,6 +53,7 @@
 
 #if PLATFORM(IOS_FAMILY)
 #include <WebCore/RenderThemeIOS.h>
+#include <WebCore/UTTypeRecordSwizzler.h>
 #endif
 
 namespace API {
@@ -223,6 +224,9 @@ struct WebProcessCreationParameters {
     WebCore::RenderThemeIOS::CSSValueToSystemColorMap cssValueToSystemColorMap;
     WebCore::Color focusRingColor;
     String localizedDeviceModel;
+#if USE(UTTYPE_SWIZZLER)
+    Vector<WebCore::UTTypeItem> vectorOfUTTypeItem;
+#endif
 #endif
 
 #if PLATFORM(COCOA)
index 8291e1c..61abef1 100644 (file)
@@ -377,9 +377,10 @@ void WebProcessPool::platformInitializeWebProcess(const WebProcessProxy& process
 #endif
 
 #if PLATFORM(IOS_FAMILY)
-    if (!WebCore::IOSApplication::isMobileSafari()) {
+    if (!WebCore::IOSApplication::isMobileSafari() || _AXSApplicationAccessibilityEnabled()) {
         static const char* services[] = {
             "com.apple.lsd.open",
+            "com.apple.lsd.mapdb",
             "com.apple.mobileassetd",
             "com.apple.iconservices",
             "com.apple.PowerManagement.control",
@@ -430,8 +431,10 @@ void WebProcessPool::platformInitializeWebProcess(const WebProcessProxy& process
     parameters.cssValueToSystemColorMap = RenderThemeIOS::cssValueToSystemColorMap();
     parameters.focusRingColor = RenderTheme::singleton().focusRingColor(OptionSet<StyleColor::Options>());
     parameters.localizedDeviceModel = localizedDeviceModel();
+#if USE(UTTYPE_SWIZZLER)
+    parameters.vectorOfUTTypeItem = createVectorOfUTTypeItem();
+#endif
 #endif
-
     
     // Allow microphone access if either preference is set because WebRTC requires microphone access.
     bool needWebProcessExtensions = !m_defaultPageGroup->preferences().useGPUProcessForMedia()
index 6cc7727..3f3df2e 100644 (file)
 #import "UserInterfaceIdiom.h"
 #import "WKAccessibilityWebPageObjectIOS.h"
 #import <UIKit/UIAccessibility.h>
+#import <WebCore/UTTypeRecordSwizzler.h>
 #import <pal/spi/ios/GraphicsServicesSPI.h>
 #endif
 
@@ -296,6 +297,11 @@ void WebProcess::platformInitializeWebProcess(WebProcessCreationParameters& para
         _CFPrefsSetDirectModeEnabled(false);
     }
 #endif
+        
+#if USE(UTTYPE_SWIZZLER)
+    swizzleUTTypeRecord();
+    setVectorOfUTTypeItem(WTFMove(parameters.vectorOfUTTypeItem));
+#endif
 }
 
 void WebProcess::platformSetWebsiteDataStoreParameters(WebProcessDataStoreParameters&& parameters)
index a2a5ba9..48c49e3 100644 (file)
@@ -1,3 +1,12 @@
+2020-03-08  Per Arne Vollan  <pvollan@apple.com>
+
+        [iOS] Mapping to UTI from tag and tag class should be performed in the UI process
+        https://bugs.webkit.org/show_bug.cgi?id=208783
+
+        Reviewed by Brent Fulgham.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+
 2020-03-07  Ross Kirsling  <ross.kirsling@sony.com>
 
         Replace the use of term "rollout" to "revert" in various tools
index edc58d2..35fa392 100644 (file)
                E3A1E78221B25B7A008C6007 /* URL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E3A1E78021B25B79008C6007 /* URL.cpp */; };
                E3A1E78521B25B91008C6007 /* URLParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E3A1E78421B25B91008C6007 /* URLParser.cpp */; };
                E3C21A7C21B25CA2003B31A3 /* URLExtras.mm in Sources */ = {isa = PBXBuildFile; fileRef = E3C21A7B21B25CA2003B31A3 /* URLExtras.mm */; };
+               E3CAAA4C2415505100CED2E2 /* UTIFromTag.mm in Sources */ = {isa = PBXBuildFile; fileRef = E3CAAA4B2415505100CED2E2 /* UTIFromTag.mm */; };
                E3DEA8111F0A589000CBC2E8 /* ThreadGroup.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E3DEA8101F0A588000CBC2E8 /* ThreadGroup.cpp */; };
                E5036F78211BC25400BFDBE2 /* color-drop.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = E5036F77211BC22800BFDBE2 /* color-drop.html */; };
                ECA680CE1E68CC0900731D20 /* StringUtilities.mm in Sources */ = {isa = PBXBuildFile; fileRef = ECA680CD1E68CC0900731D20 /* StringUtilities.mm */; };
                E3A1E78021B25B79008C6007 /* URL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = URL.cpp; sourceTree = "<group>"; };
                E3A1E78421B25B91008C6007 /* URLParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = URLParser.cpp; sourceTree = "<group>"; };
                E3C21A7B21B25CA2003B31A3 /* URLExtras.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = URLExtras.mm; sourceTree = "<group>"; };
+               E3CAAA4B2415505100CED2E2 /* UTIFromTag.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = UTIFromTag.mm; sourceTree = "<group>"; };
                E3DEA8101F0A588000CBC2E8 /* ThreadGroup.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ThreadGroup.cpp; sourceTree = "<group>"; };
                E40019301ACE9B5C001B0A2A /* BloomFilter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BloomFilter.cpp; sourceTree = "<group>"; };
                E490296714E2E3A4002BEDD1 /* TypingStyleCrash.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = TypingStyleCrash.mm; sourceTree = "<group>"; };
                                E325C90623E3870200BC7D3B /* PictureInPictureSupport.mm */,
                                C15CBB3E23FB177A00300CC7 /* PreferenceChanges.mm */,
                                C194E31C2409DF43002939ED /* UTIFromMIMEType.mm */,
+                               E3CAAA4B2415505100CED2E2 /* UTIFromTag.mm */,
                                0F139E751A423A5300F590F5 /* WeakObjCPtr.mm */,
                        );
                        name = cocoa;
                                7CCE7F181A411AE600447C4C /* UserMessage.cpp in Sources */,
                                2EB242B821D4140B0055C1C0 /* UseSelectionAsFindString.mm in Sources */,
                                C194E31D2409DF43002939ED /* UTIFromMIMEType.mm in Sources */,
+                               E3CAAA4C2415505100CED2E2 /* UTIFromTag.mm in Sources */,
                                7C83E03A1D0A602700FEBCF3 /* UtilitiesCocoa.mm in Sources */,
                                7C83E0C61D0A654E00FEBCF3 /* VideoControlsManager.mm in Sources */,
                                CD3065E02165682E00E895DF /* VideoQualityDisplayCompositing.mm in Sources */,
diff --git a/Tools/TestWebKitAPI/Tests/WebKit/UTIFromTag.mm b/Tools/TestWebKitAPI/Tests/WebKit/UTIFromTag.mm
new file mode 100644 (file)
index 0000000..1411867
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. 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 INC. 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"
+
+#if WK_HAVE_C_SPI
+
+#if USE(UTTYPE_SWIZZLER)
+
+#import "PlatformUtilities.h"
+#import "TestWKWebView.h"
+#import <WebCore/UTIUtilities.h>
+#import <WebCore/UTTypeRecordSwizzler.h>
+
+TEST(WebKit, UTIFromTag)
+{
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    WKRetainPtr<WKContextRef> context = adoptWK(TestWebKitAPI::Util::createContextForInjectedBundleTest("InternalsInjectedBundleTest"));
+    configuration.get().processPool = (WKProcessPool *)context.get();
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration.get() addToWindow:YES]);
+
+    for (auto& item : WebCore::createVectorOfUTTypeItem()) {
+        auto js = [NSString stringWithFormat:@"window.internals.getUTIFromTag(\"%s\", \"%s\", \"%s\")", item.tag.utf8().data(), item.tagClass.utf8().data(), , item.identifier.utf8().data()];
+
+        auto uti = [webView stringByEvaluatingJavaScript:js];
+
+        ASSERT_TRUE(WebCore::UTIFromTag(item.tagClass, item.tag, item.identifier) == String(uti));
+    }
+}
+#endif
+
+#endif // WK_HAVE_C_SPI