Diff
Modified: branches/safari-608.1-branch/LayoutTests/ChangeLog (248343 => 248344)
--- branches/safari-608.1-branch/LayoutTests/ChangeLog 2019-08-07 06:52:11 UTC (rev 248343)
+++ branches/safari-608.1-branch/LayoutTests/ChangeLog 2019-08-07 06:52:16 UTC (rev 248344)
@@ -1,5 +1,84 @@
2019-08-06 Kocsen Chung <[email protected]>
+ Cherry-pick r247720. rdar://problem/54017869
+
+ WebKit should strip away system font names from the pasted content
+ https://bugs.webkit.org/show_bug.cgi?id=199975
+ <rdar://problem/53336353>
+
+ Reviewed by Darin Adler.
+
+ Source/WebCore:
+
+ Cocoa HTML Writer sometimes generate system font names such as ".AppleSystemUIFont", ".SFUI-Regular", and ".SF UI Mono".
+ We need to strip away these font names upon paste to avoid these font names falling back to Times New Roman.
+
+ Added the code to strip these font names away in EditingStyle::mergeStyleFromRulesForSerialization, which is used by
+ StylizedMarkupAccumulator to generate HTML during copy. This works because WebContentReader::readWebArchive invokes
+ sanitizeMarkupWithArchive which inserts the pasteboard content into a temporary document then re-serializes back to HTML
+ using StylizedMarkupAccumulator before the actual pasting happens.
+
+ This approach has a few benefits over stripping away these font names in ReplaceSelectionCommand:
+
+ 1. It would only affect clients that opts-in to copy & paste sanitization. e.g. it won't affect legacy WebKit clients
+ and those that opt out of pasteboard content sanitization.
+
+ 2. It preserves font names such as ".SF Blah" that a website may insert as some kind of house keeping purposes if ever.
+ While we don't have any evidence that there is any such a website but it's a real risk nonetheless. The copy side fix would
+ only affect cross-site and cross-app pasting, which is rare and less likely to affect real user scenarios.
+
+ 3. It avoids exposing bogus .Apple* or .SF* font names to websites that directly use event.clipboardData.getData.
+ Indeed stripping away bogus markup like this is one of the key features / benefit of using copy & paste sanitization.
+
+ Test: editing/pasteboard/paste-cocoa-writer-markup-with-system-fonts.html
+
+ * editing/EditingStyle.cpp:
+ (WebCore::usesForbiddenSystemFontAsOnlyFontFamilyName): Added.
+ (WebCore::EditingStyle::mergeStyleFromRulesForSerialization): Added the code to remove font-family property when needed.
+ * platform/graphics/FontCache.h:
+ * platform/graphics/cocoa/FontCacheCoreText.cpp:
+ (WebCore::isSystemFont): Moved.
+ (WebCore::FontCache::isSystemFontForbiddenForEditing): Added.
+ * platform/graphics/freetype/FontCacheFreeType.cpp:
+ (WebCore::FontCache::isSystemFontForbiddenForEditing): Added. Always returns false.
+ * platform/graphics/win/FontCacheWin.cpp:
+ (WebCore::FontCache::isSystemFontForbiddenForEditing): Ditto.
+
+ Tools:
+
+ Added a test to strip away system font names such as ".AppleSystemUIFont", ".SFUI-Regular", and ".SF UI Mono".
+
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+ * TestWebKitAPI/Tests/WebKitCocoa/PasteHTML.mm:
+ * TestWebKitAPI/Tests/WebKitCocoa/cocoa-writer-markup-with-system-fonts.html: Added.
+
+ LayoutTests:
+
+ Added a test for ClipboardData.getData returning the original markup and execCommand('insertHTML', ~)
+ not stripping away system font names.
+
+ * editing/pasteboard/paste-cocoa-writer-markup-with-system-fonts-expected.txt: Added.
+ * editing/pasteboard/paste-cocoa-writer-markup-with-system-fonts.html: Added.
+
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@247720 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2019-07-23 Ryosuke Niwa <[email protected]>
+
+ WebKit should strip away system font names from the pasted content
+ https://bugs.webkit.org/show_bug.cgi?id=199975
+ <rdar://problem/53336353>
+
+ Reviewed by Darin Adler.
+
+ Added a test for ClipboardData.getData returning the original markup and execCommand('insertHTML', ~)
+ not stripping away system font names.
+
+ * editing/pasteboard/paste-cocoa-writer-markup-with-system-fonts-expected.txt: Added.
+ * editing/pasteboard/paste-cocoa-writer-markup-with-system-fonts.html: Added.
+
+2019-08-06 Kocsen Chung <[email protected]>
+
Cherry-pick r247651. rdar://problem/54017866
[iOS] Entering 2FA code on idmsa.apple.com causes unexpected scrolling
Added: branches/safari-608.1-branch/LayoutTests/editing/pasteboard/paste-cocoa-writer-markup-with-system-fonts-expected.txt (0 => 248344)
--- branches/safari-608.1-branch/LayoutTests/editing/pasteboard/paste-cocoa-writer-markup-with-system-fonts-expected.txt (rev 0)
+++ branches/safari-608.1-branch/LayoutTests/editing/pasteboard/paste-cocoa-writer-markup-with-system-fonts-expected.txt 2019-08-07 06:52:16 UTC (rev 248344)
@@ -0,0 +1,14 @@
+This tests pasting a markup from Cocoa HTML Writer with system font references. WebKit should strip system font names away upon paste.
+To manually test, click on "start" first then trigger paste from menu or callout bar or press cmd+v
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS event.clipboardData.getData('text/html') is markup
+PASS editor.innerHTML.includes('.AppleSystemUIFont') is true
+PASS editor.innerHTML.includes('.SFUI-Regular') is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+Start
+
Added: branches/safari-608.1-branch/LayoutTests/editing/pasteboard/paste-cocoa-writer-markup-with-system-fonts.html (0 => 248344)
--- branches/safari-608.1-branch/LayoutTests/editing/pasteboard/paste-cocoa-writer-markup-with-system-fonts.html (rev 0)
+++ branches/safari-608.1-branch/LayoutTests/editing/pasteboard/paste-cocoa-writer-markup-with-system-fonts.html 2019-08-07 06:52:16 UTC (rev 248344)
@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+<html>
+<body>
+<button id="start">Start</button>
+<div id="editor" contenteditable>hello</div>
+<script src=""
+<script>
+
+jsTestIsAsync = true;
+
+description(`This tests pasting a markup from Cocoa HTML Writer with system font references. WebKit should strip system font names away upon paste.<br>
+To manually test, click on "start" first then trigger paste from menu or callout bar or press cmd+v`);
+
+const markup = `<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<meta http-equiv="Content-Style-Type" content="text/css">
+<meta name="Generator" content="Cocoa HTML Writer">
+</head>
+<body>
+<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px '.AppleSystemUIFont'; color: #454545"><span style="font-family: '.SFUI-Regular'; font-weight: normal; font-style: normal; font-size: 17.00pt">Hello</span></p>
+</body>
+</html>`;
+
+editor.focus();
+start.addEventListener('click', () => {
+ editor.focus();
+ document.execCommand('selectAll');
+ document.execCommand('copy');
+ if (window.testRunner)
+ document.execCommand('paste');
+});
+editor.addEventListener('copy', (event) => {
+ event.clipboardData.setData('text/html', markup);
+ event.preventDefault();
+});
+editor.addEventListener('paste', (event) => {
+ shouldBe(`event.clipboardData.getData('text/html')`, `markup`);
+ document.execCommand('insertHTML', false, event.clipboardData.getData('text/html'));
+ shouldBeTrue(`editor.innerHTML.includes('.AppleSystemUIFont')`);
+ shouldBeTrue(`editor.innerHTML.includes('.SFUI-Regular')`);
+ editor.innerHTML = '';
+ event.preventDefault();
+ finishJSTest();
+});
+
+if (window.testRunner)
+ start.click();
+
+</script>
+</body>
+</html>
Modified: branches/safari-608.1-branch/Source/WebCore/ChangeLog (248343 => 248344)
--- branches/safari-608.1-branch/Source/WebCore/ChangeLog 2019-08-07 06:52:11 UTC (rev 248343)
+++ branches/safari-608.1-branch/Source/WebCore/ChangeLog 2019-08-07 06:52:16 UTC (rev 248344)
@@ -1,5 +1,112 @@
2019-08-06 Kocsen Chung <[email protected]>
+ Cherry-pick r247720. rdar://problem/54017869
+
+ WebKit should strip away system font names from the pasted content
+ https://bugs.webkit.org/show_bug.cgi?id=199975
+ <rdar://problem/53336353>
+
+ Reviewed by Darin Adler.
+
+ Source/WebCore:
+
+ Cocoa HTML Writer sometimes generate system font names such as ".AppleSystemUIFont", ".SFUI-Regular", and ".SF UI Mono".
+ We need to strip away these font names upon paste to avoid these font names falling back to Times New Roman.
+
+ Added the code to strip these font names away in EditingStyle::mergeStyleFromRulesForSerialization, which is used by
+ StylizedMarkupAccumulator to generate HTML during copy. This works because WebContentReader::readWebArchive invokes
+ sanitizeMarkupWithArchive which inserts the pasteboard content into a temporary document then re-serializes back to HTML
+ using StylizedMarkupAccumulator before the actual pasting happens.
+
+ This approach has a few benefits over stripping away these font names in ReplaceSelectionCommand:
+
+ 1. It would only affect clients that opts-in to copy & paste sanitization. e.g. it won't affect legacy WebKit clients
+ and those that opt out of pasteboard content sanitization.
+
+ 2. It preserves font names such as ".SF Blah" that a website may insert as some kind of house keeping purposes if ever.
+ While we don't have any evidence that there is any such a website but it's a real risk nonetheless. The copy side fix would
+ only affect cross-site and cross-app pasting, which is rare and less likely to affect real user scenarios.
+
+ 3. It avoids exposing bogus .Apple* or .SF* font names to websites that directly use event.clipboardData.getData.
+ Indeed stripping away bogus markup like this is one of the key features / benefit of using copy & paste sanitization.
+
+ Test: editing/pasteboard/paste-cocoa-writer-markup-with-system-fonts.html
+
+ * editing/EditingStyle.cpp:
+ (WebCore::usesForbiddenSystemFontAsOnlyFontFamilyName): Added.
+ (WebCore::EditingStyle::mergeStyleFromRulesForSerialization): Added the code to remove font-family property when needed.
+ * platform/graphics/FontCache.h:
+ * platform/graphics/cocoa/FontCacheCoreText.cpp:
+ (WebCore::isSystemFont): Moved.
+ (WebCore::FontCache::isSystemFontForbiddenForEditing): Added.
+ * platform/graphics/freetype/FontCacheFreeType.cpp:
+ (WebCore::FontCache::isSystemFontForbiddenForEditing): Added. Always returns false.
+ * platform/graphics/win/FontCacheWin.cpp:
+ (WebCore::FontCache::isSystemFontForbiddenForEditing): Ditto.
+
+ Tools:
+
+ Added a test to strip away system font names such as ".AppleSystemUIFont", ".SFUI-Regular", and ".SF UI Mono".
+
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+ * TestWebKitAPI/Tests/WebKitCocoa/PasteHTML.mm:
+ * TestWebKitAPI/Tests/WebKitCocoa/cocoa-writer-markup-with-system-fonts.html: Added.
+
+ LayoutTests:
+
+ Added a test for ClipboardData.getData returning the original markup and execCommand('insertHTML', ~)
+ not stripping away system font names.
+
+ * editing/pasteboard/paste-cocoa-writer-markup-with-system-fonts-expected.txt: Added.
+ * editing/pasteboard/paste-cocoa-writer-markup-with-system-fonts.html: Added.
+
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@247720 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2019-07-23 Ryosuke Niwa <[email protected]>
+
+ WebKit should strip away system font names from the pasted content
+ https://bugs.webkit.org/show_bug.cgi?id=199975
+ <rdar://problem/53336353>
+
+ Reviewed by Darin Adler.
+
+ Cocoa HTML Writer sometimes generate system font names such as ".AppleSystemUIFont", ".SFUI-Regular", and ".SF UI Mono".
+ We need to strip away these font names upon paste to avoid these font names falling back to Times New Roman.
+
+ Added the code to strip these font names away in EditingStyle::mergeStyleFromRulesForSerialization, which is used by
+ StylizedMarkupAccumulator to generate HTML during copy. This works because WebContentReader::readWebArchive invokes
+ sanitizeMarkupWithArchive which inserts the pasteboard content into a temporary document then re-serializes back to HTML
+ using StylizedMarkupAccumulator before the actual pasting happens.
+
+ This approach has a few benefits over stripping away these font names in ReplaceSelectionCommand:
+
+ 1. It would only affect clients that opts-in to copy & paste sanitization. e.g. it won't affect legacy WebKit clients
+ and those that opt out of pasteboard content sanitization.
+
+ 2. It preserves font names such as ".SF Blah" that a website may insert as some kind of house keeping purposes if ever.
+ While we don't have any evidence that there is any such a website but it's a real risk nonetheless. The copy side fix would
+ only affect cross-site and cross-app pasting, which is rare and less likely to affect real user scenarios.
+
+ 3. It avoids exposing bogus .Apple* or .SF* font names to websites that directly use event.clipboardData.getData.
+ Indeed stripping away bogus markup like this is one of the key features / benefit of using copy & paste sanitization.
+
+ Test: editing/pasteboard/paste-cocoa-writer-markup-with-system-fonts.html
+
+ * editing/EditingStyle.cpp:
+ (WebCore::usesForbiddenSystemFontAsOnlyFontFamilyName): Added.
+ (WebCore::EditingStyle::mergeStyleFromRulesForSerialization): Added the code to remove font-family property when needed.
+ * platform/graphics/FontCache.h:
+ * platform/graphics/cocoa/FontCacheCoreText.cpp:
+ (WebCore::isSystemFont): Moved.
+ (WebCore::FontCache::isSystemFontForbiddenForEditing): Added.
+ * platform/graphics/freetype/FontCacheFreeType.cpp:
+ (WebCore::FontCache::isSystemFontForbiddenForEditing): Added. Always returns false.
+ * platform/graphics/win/FontCacheWin.cpp:
+ (WebCore::FontCache::isSystemFontForbiddenForEditing): Ditto.
+
+2019-08-06 Kocsen Chung <[email protected]>
+
Cherry-pick r247837. rdar://problem/53973599
Add helper for ignoring deprecated implementation warnings
Modified: branches/safari-608.1-branch/Source/WebCore/editing/EditingStyle.cpp (248343 => 248344)
--- branches/safari-608.1-branch/Source/WebCore/editing/EditingStyle.cpp 2019-08-07 06:52:11 UTC (rev 248343)
+++ branches/safari-608.1-branch/Source/WebCore/editing/EditingStyle.cpp 2019-08-07 06:52:16 UTC (rev 248344)
@@ -29,6 +29,7 @@
#include "ApplyStyleCommand.h"
#include "CSSComputedStyleDeclaration.h"
+#include "CSSFontFamily.h"
#include "CSSFontStyleValue.h"
#include "CSSParser.h"
#include "CSSRuleList.h"
@@ -37,6 +38,8 @@
#include "CSSValuePool.h"
#include "Editing.h"
#include "Editor.h"
+#include "FontCache.h"
+#include "FontCascade.h"
#include "Frame.h"
#include "HTMLFontElement.h"
#include "HTMLInterchange.h"
@@ -1279,6 +1282,21 @@
m_mutableStyle = styleFromMatchedRules;
}
+static bool usesForbiddenSystemFontAsOnlyFontFamilyName(CSSValue& value)
+{
+ if (!is<CSSValueList>(value) || downcast<CSSValueList>(value).length() != 1)
+ return false;
+
+ auto& item = *downcast<CSSValueList>(value).item(0);
+ if (!is<CSSPrimitiveValue>(item))
+ return false;
+
+ auto& primitiveValue = downcast<CSSPrimitiveValue>(item);
+ if (!primitiveValue.isFontFamily())
+ return false;
+ return FontCache::isSystemFontForbiddenForEditing(primitiveValue.fontFamily().familyName);
+}
+
void EditingStyle::mergeStyleFromRulesForSerialization(StyledElement& element)
{
mergeStyleFromRules(element);
@@ -1289,19 +1307,28 @@
auto fromComputedStyle = MutableStyleProperties::create();
ComputedStyleExtractor computedStyle(&element);
+ bool shouldRemoveFontFamily = false;
{
unsigned propertyCount = m_mutableStyle->propertyCount();
for (unsigned i = 0; i < propertyCount; ++i) {
StyleProperties::PropertyReference property = m_mutableStyle->propertyAt(i);
- CSSValue* value = property.value();
- if (!is<CSSPrimitiveValue>(*value))
+ CSSValue& value = *property.value();
+ if (property.id() == CSSPropertyFontFamily && usesForbiddenSystemFontAsOnlyFontFamilyName(value)) {
+ shouldRemoveFontFamily = true;
continue;
- if (downcast<CSSPrimitiveValue>(*value).isPercentage()) {
+ }
+ if (!is<CSSPrimitiveValue>(value))
+ continue;
+ if (downcast<CSSPrimitiveValue>(value).isPercentage()) {
if (auto computedPropertyValue = computedStyle.propertyValue(property.id()))
fromComputedStyle->addParsedProperty(CSSProperty(property.id(), WTFMove(computedPropertyValue)));
}
}
}
+ if (shouldRemoveFontFamily) {
+ m_mutableStyle->removeProperty(CSSPropertyFontFamily);
+ fromComputedStyle->removeProperty(CSSPropertyFontFamily);
+ }
m_mutableStyle->mergeAndOverrideOnConflict(fromComputedStyle.get());
}
Modified: branches/safari-608.1-branch/Source/WebCore/platform/graphics/FontCache.h (248343 => 248344)
--- branches/safari-608.1-branch/Source/WebCore/platform/graphics/FontCache.h 2019-08-07 06:52:11 UTC (rev 248343)
+++ branches/safari-608.1-branch/Source/WebCore/platform/graphics/FontCache.h 2019-08-07 06:52:16 UTC (rev 248344)
@@ -197,6 +197,8 @@
Vector<String> systemFontFamilies();
void platformInit();
+ static bool isSystemFontForbiddenForEditing(const String&);
+
#if PLATFORM(COCOA)
WEBCORE_EXPORT static void setFontWhitelist(const Vector<String>&);
#endif
Modified: branches/safari-608.1-branch/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp (248343 => 248344)
--- branches/safari-608.1-branch/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp 2019-08-07 06:52:11 UTC (rev 248343)
+++ branches/safari-608.1-branch/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp 2019-08-07 06:52:16 UTC (rev 248344)
@@ -783,6 +783,17 @@
return fontFamilies;
}
+static inline bool isSystemFont(const String& family)
+{
+ // AtomString's operator[] handles out-of-bounds by returning 0.
+ return family[0] == '.';
+}
+
+bool FontCache::isSystemFontForbiddenForEditing(const String& fontFamily)
+{
+ return isSystemFont(fontFamily);
+}
+
static CTFontSymbolicTraits computeTraits(const FontDescription& fontDescription)
{
CTFontSymbolicTraits traits = 0;
@@ -830,12 +841,6 @@
whitelist.add(item);
}
-static inline bool isSystemFont(const AtomString& family)
-{
- // AtomString's operator[] handles out-of-bounds by returning 0.
- return family[0] == '.';
-}
-
class FontDatabase {
public:
#if !HAVE(DISALLOWABLE_USER_INSTALLED_FONTS)
@@ -1183,7 +1188,7 @@
static FontLookup platformFontLookupWithFamily(const AtomString& family, FontSelectionRequest request, float size, AllowUserInstalledFonts allowUserInstalledFonts)
{
const auto& whitelist = fontWhitelist();
- if (!isSystemFont(family) && whitelist.size() && !whitelist.contains(family))
+ if (!isSystemFont(family.string()) && whitelist.size() && !whitelist.contains(family))
return { nullptr };
if (equalLettersIgnoringASCIICase(family, ".applesystemuifontserif")
Modified: branches/safari-608.1-branch/Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp (248343 => 248344)
--- branches/safari-608.1-branch/Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp 2019-08-07 06:52:11 UTC (rev 248343)
+++ branches/safari-608.1-branch/Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp 2019-08-07 06:52:16 UTC (rev 248344)
@@ -186,6 +186,11 @@
return fontFamilies;
}
+bool FontCache::isSystemFontForbiddenForEditing(const String&)
+{
+ return false;
+}
+
Ref<Font> FontCache::lastResortFallbackFont(const FontDescription& fontDescription)
{
// We want to return a fallback font here, otherwise the logic preventing FontConfig
Modified: branches/safari-608.1-branch/Source/WebCore/platform/graphics/win/FontCacheWin.cpp (248343 => 248344)
--- branches/safari-608.1-branch/Source/WebCore/platform/graphics/win/FontCacheWin.cpp 2019-08-07 06:52:11 UTC (rev 248343)
+++ branches/safari-608.1-branch/Source/WebCore/platform/graphics/win/FontCacheWin.cpp 2019-08-07 06:52:16 UTC (rev 248344)
@@ -328,6 +328,11 @@
return fontFamilies;
}
+bool FontCache::isSystemFontForbiddenForEditing(const String&)
+{
+ return false;
+}
+
RefPtr<Font> FontCache::fontFromDescriptionAndLogFont(const FontDescription& fontDescription, const LOGFONT& font, AtomString& outFontFamilyName)
{
AtomString familyName(font.lfFaceName, wcsnlen(font.lfFaceName, LF_FACESIZE));
Modified: branches/safari-608.1-branch/Tools/ChangeLog (248343 => 248344)
--- branches/safari-608.1-branch/Tools/ChangeLog 2019-08-07 06:52:11 UTC (rev 248343)
+++ branches/safari-608.1-branch/Tools/ChangeLog 2019-08-07 06:52:16 UTC (rev 248344)
@@ -1,5 +1,84 @@
2019-08-06 Kocsen Chung <[email protected]>
+ Cherry-pick r247720. rdar://problem/54017869
+
+ WebKit should strip away system font names from the pasted content
+ https://bugs.webkit.org/show_bug.cgi?id=199975
+ <rdar://problem/53336353>
+
+ Reviewed by Darin Adler.
+
+ Source/WebCore:
+
+ Cocoa HTML Writer sometimes generate system font names such as ".AppleSystemUIFont", ".SFUI-Regular", and ".SF UI Mono".
+ We need to strip away these font names upon paste to avoid these font names falling back to Times New Roman.
+
+ Added the code to strip these font names away in EditingStyle::mergeStyleFromRulesForSerialization, which is used by
+ StylizedMarkupAccumulator to generate HTML during copy. This works because WebContentReader::readWebArchive invokes
+ sanitizeMarkupWithArchive which inserts the pasteboard content into a temporary document then re-serializes back to HTML
+ using StylizedMarkupAccumulator before the actual pasting happens.
+
+ This approach has a few benefits over stripping away these font names in ReplaceSelectionCommand:
+
+ 1. It would only affect clients that opts-in to copy & paste sanitization. e.g. it won't affect legacy WebKit clients
+ and those that opt out of pasteboard content sanitization.
+
+ 2. It preserves font names such as ".SF Blah" that a website may insert as some kind of house keeping purposes if ever.
+ While we don't have any evidence that there is any such a website but it's a real risk nonetheless. The copy side fix would
+ only affect cross-site and cross-app pasting, which is rare and less likely to affect real user scenarios.
+
+ 3. It avoids exposing bogus .Apple* or .SF* font names to websites that directly use event.clipboardData.getData.
+ Indeed stripping away bogus markup like this is one of the key features / benefit of using copy & paste sanitization.
+
+ Test: editing/pasteboard/paste-cocoa-writer-markup-with-system-fonts.html
+
+ * editing/EditingStyle.cpp:
+ (WebCore::usesForbiddenSystemFontAsOnlyFontFamilyName): Added.
+ (WebCore::EditingStyle::mergeStyleFromRulesForSerialization): Added the code to remove font-family property when needed.
+ * platform/graphics/FontCache.h:
+ * platform/graphics/cocoa/FontCacheCoreText.cpp:
+ (WebCore::isSystemFont): Moved.
+ (WebCore::FontCache::isSystemFontForbiddenForEditing): Added.
+ * platform/graphics/freetype/FontCacheFreeType.cpp:
+ (WebCore::FontCache::isSystemFontForbiddenForEditing): Added. Always returns false.
+ * platform/graphics/win/FontCacheWin.cpp:
+ (WebCore::FontCache::isSystemFontForbiddenForEditing): Ditto.
+
+ Tools:
+
+ Added a test to strip away system font names such as ".AppleSystemUIFont", ".SFUI-Regular", and ".SF UI Mono".
+
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+ * TestWebKitAPI/Tests/WebKitCocoa/PasteHTML.mm:
+ * TestWebKitAPI/Tests/WebKitCocoa/cocoa-writer-markup-with-system-fonts.html: Added.
+
+ LayoutTests:
+
+ Added a test for ClipboardData.getData returning the original markup and execCommand('insertHTML', ~)
+ not stripping away system font names.
+
+ * editing/pasteboard/paste-cocoa-writer-markup-with-system-fonts-expected.txt: Added.
+ * editing/pasteboard/paste-cocoa-writer-markup-with-system-fonts.html: Added.
+
+
+ git-svn-id: https://svn.webkit.org/repository/webkit/trunk@247720 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+ 2019-07-23 Ryosuke Niwa <[email protected]>
+
+ WebKit should strip away system font names from the pasted content
+ https://bugs.webkit.org/show_bug.cgi?id=199975
+ <rdar://problem/53336353>
+
+ Reviewed by Darin Adler.
+
+ Added a test to strip away system font names such as ".AppleSystemUIFont", ".SFUI-Regular", and ".SF UI Mono".
+
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+ * TestWebKitAPI/Tests/WebKitCocoa/PasteHTML.mm:
+ * TestWebKitAPI/Tests/WebKitCocoa/cocoa-writer-markup-with-system-fonts.html: Added.
+
+2019-08-06 Kocsen Chung <[email protected]>
+
Cherry-pick r247679. rdar://problem/54017903
[iOS] [WebKit2] Add limited support for -isPosition:atBoundary:inDirection: in WKContentView
Modified: branches/safari-608.1-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (248343 => 248344)
--- branches/safari-608.1-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2019-08-07 06:52:11 UTC (rev 248343)
+++ branches/safari-608.1-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2019-08-07 06:52:16 UTC (rev 248344)
@@ -704,6 +704,7 @@
9B7A37C41F8AEBA5004AA228 /* CopyURL.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9B7A37C21F8AEBA5004AA228 /* CopyURL.mm */; };
9B7D740F1F8378770006C432 /* paste-rtfd.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9B7D740E1F8377E60006C432 /* paste-rtfd.html */; };
9BAD7F3E22690F2000F8DA66 /* DeallocWebViewInEventListener.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9BAD7F3D22690F1400F8DA66 /* DeallocWebViewInEventListener.mm */; };
+ 9BAE177B22E2BBFB00DF3098 /* cocoa-writer-markup-with-system-fonts.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9BAE177A22E2BB6B00DF3098 /* cocoa-writer-markup-with-system-fonts.html */; };
9BCB7C2820130600003E7C0C /* PasteHTML.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9BCB7C2620130600003E7C0C /* PasteHTML.mm */; };
9BCD411A206DBCA3001D71BE /* mso-list-on-h4.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9BCD4119206D5ED7001D71BE /* mso-list-on-h4.html */; };
9BD4239A1E04BD9800200395 /* AttributedSubstringForProposedRangeWithImage.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9BD423991E04BD9800200395 /* AttributedSubstringForProposedRangeWithImage.mm */; };
@@ -1072,6 +1073,7 @@
dstPath = TestWebKitAPI.resources;
dstSubfolderSpec = 7;
files = (
+ 9BAE177B22E2BBFB00DF3098 /* cocoa-writer-markup-with-system-fonts.html in Copy Resources */,
55A817FF2181021A0004A39A /* 100x100-red.tga in Copy Resources */,
1A9E52C913E65EF4006917F5 /* 18-characters.html in Copy Resources */,
55A81800218102210004A39A /* 400x400-green.png in Copy Resources */,
@@ -2030,6 +2032,7 @@
9B7A37C21F8AEBA5004AA228 /* CopyURL.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = CopyURL.mm; sourceTree = "<group>"; };
9B7D740E1F8377E60006C432 /* paste-rtfd.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "paste-rtfd.html"; sourceTree = "<group>"; };
9BAD7F3D22690F1400F8DA66 /* DeallocWebViewInEventListener.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DeallocWebViewInEventListener.mm; sourceTree = "<group>"; };
+ 9BAE177A22E2BB6B00DF3098 /* cocoa-writer-markup-with-system-fonts.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "cocoa-writer-markup-with-system-fonts.html"; sourceTree = "<group>"; };
9BCB7C2620130600003E7C0C /* PasteHTML.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PasteHTML.mm; sourceTree = "<group>"; };
9BCD4119206D5ED7001D71BE /* mso-list-on-h4.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "mso-list-on-h4.html"; sourceTree = "<group>"; };
9BD423991E04BD9800200395 /* AttributedSubstringForProposedRangeWithImage.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AttributedSubstringForProposedRangeWithImage.mm; sourceTree = "<group>"; };
@@ -3254,6 +3257,7 @@
51714EB31CF8C761004723C4 /* WebProcessKillIDBCleanup-2.html */,
5120C83B1E674E350025B250 /* WebsiteDataStoreCustomPaths.html */,
2E131C171D83A97E001BA36C /* wide-autoplaying-video-with-audio.html */,
+ 9BAE177A22E2BB6B00DF3098 /* cocoa-writer-markup-with-system-fonts.html */,
);
name = Resources;
sourceTree = "<group>";
Modified: branches/safari-608.1-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/PasteHTML.mm (248343 => 248344)
--- branches/safari-608.1-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/PasteHTML.mm 2019-08-07 06:52:11 UTC (rev 248343)
+++ branches/safari-608.1-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/PasteHTML.mm 2019-08-07 06:52:16 UTC (rev 248344)
@@ -327,5 +327,34 @@
EXPECT_WK_STREQ("rgb(255, 0, 0)", [webView stringByEvaluatingJavaScript:@"document.queryCommandValue('foreColor')"]);
}
+TEST(PasteHTML, StripsSystemFontNames)
+{
+ writeHTMLToPasteboard([NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"cocoa-writer-markup-with-system-fonts" ofType:@"html" inDirectory:@"TestWebKitAPI.resources"] encoding:NSUTF8StringEncoding error:NULL]);
+ auto webView = createWebViewWithCustomPasteboardDataSetting(true);
+ [webView synchronouslyLoadTestPageNamed:@"paste-rtfd"];
+ [webView paste:nil];
+
+ EXPECT_WK_STREQ("[\"text/html\"]", [webView stringByEvaluatingJavaScript:@"JSON.stringify(clipboardData.types)"]);
+ [webView stringByEvaluatingJavaScript:@"window.htmlInDataTransfer = clipboardData.values[0]"];
+ [webView stringByEvaluatingJavaScript:@"window.pastedHTML = editor.innerHTML"];
+
+ EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"pastedHTML.includes('Hello Cocoa')"].boolValue);
+ EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"pastedHTML.includes('font-weight: bold')"].boolValue);
+ EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"!pastedHTML.includes('.AppleSystemUIFont')"].boolValue);
+ EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"!pastedHTML.includes('.SFUI')"].boolValue);
+ EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"!pastedHTML.includes('.SF')"].boolValue);
+
+ EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"htmlInDataTransfer.includes('Hello Cocoa')"].boolValue);
+ EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"htmlInDataTransfer.includes('font-weight: bold')"].boolValue);
+ EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"!htmlInDataTransfer.includes('.AppleSystemUIFont')"].boolValue);
+ EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"!htmlInDataTransfer.includes('.SFUI')"].boolValue);
+ EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"!htmlInDataTransfer.includes('.SF')"].boolValue);
+
+ EXPECT_WK_STREQ([webView stringByEvaluatingJavaScript:@"getComputedStyle(document.querySelector('.s2')).fontFamily"],
+ [webView stringByEvaluatingJavaScript:@"getComputedStyle(document.body).fontFamily"]);
+ EXPECT_WK_STREQ([webView stringByEvaluatingJavaScript:@"getComputedStyle(document.querySelector('.s4')).fontFamily"],
+ [webView stringByEvaluatingJavaScript:@"getComputedStyle(document.body).fontFamily"]);
+}
+
#endif // PLATFORM(COCOA)
Added: branches/safari-608.1-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/cocoa-writer-markup-with-system-fonts.html (0 => 248344)
--- branches/safari-608.1-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/cocoa-writer-markup-with-system-fonts.html (rev 0)
+++ branches/safari-608.1-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/cocoa-writer-markup-with-system-fonts.html 2019-08-07 06:52:16 UTC (rev 248344)
@@ -0,0 +1,31 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<meta http-equiv="Content-Style-Type" content="text/css">
+<title></title>
+<meta name="Generator" content="Cocoa HTML Writer">
+<style type="text/css">
+p.p1 {margin: 0.0px 0.0px 3.0px 0.0px; font: 22.0px '.AppleSystemUIFont'; color: #454545; min-height: 26.3px}
+p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px '.AppleSystemUIFont'; color: #454545; min-height: 20.3px}
+p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px '.AppleSystemUIFont'; color: #454545}
+p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 17.0px '.SF UI Mono'; color: #454545}
+p.p5 {margin: 0.0px 0.0px 4.0px 0.0px; font: 21.0px '.AppleSystemUIFont'; color: #454545}
+span.s1 {font-family: '.SFUI-Heavy'; font-weight: bold; font-style: normal; font-size: 22.00pt}
+span.s2 {font-family: '.SFUI-Regular'; font-weight: normal; font-style: normal; font-size: 17.00pt}
+span.s3 {font-family: '.SFUIMono-Regular'; font-weight: normal; font-style: normal; font-size: 17.00pt}
+span.s4 {font-family: '.SFUI-Semibold'; font-weight: bold; font-style: normal; font-size: 21.00pt}
+</style>
+</head>
+<body>
+<p class="p1"><span class="s1"></span><br></p>
+<p class="p2"><span class="s2"></span><br></p>
+<p class="p3"><span class="s2">Hello</span></p>
+<p class="p2"><span class="s2"></span><br></p>
+<p class="p4"><span class="s3">World</span></p>
+<p class="p2"><span class="s2"></span><br></p>
+<p class="p3"><span class="s2">Hello Cocoa</span></p>
+<p class="p2"><span class="s2"></span><br></p>
+<p class="p5"><span class="s4">Heading</span></p>
+</body>
+</html>