⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 248344 in webkit


Ignore:
Timestamp:
Aug 6, 2019, 11:52:16 PM (7 years ago)
Author:
Kocsen Chung
Message:

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.
  1. 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.
  1. 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

Location:
branches/safari-608.1-branch
Files:
3 added
10 edited

Legend:

Unmodified
Added
Removed
  • branches/safari-608.1-branch/LayoutTests/ChangeLog

    r248341 r248344  
     12019-08-06  Kocsen Chung  <kocsen_chung@apple.com>
     2
     3        Cherry-pick r247720. rdar://problem/54017869
     4
     5    WebKit should strip away system font names from the pasted content
     6    https://bugs.webkit.org/show_bug.cgi?id=199975
     7    <rdar://problem/53336353>
     8   
     9    Reviewed by Darin Adler.
     10   
     11    Source/WebCore:
     12   
     13    Cocoa HTML Writer sometimes generate system font names such as ".AppleSystemUIFont", ".SFUI-Regular", and ".SF UI Mono".
     14    We need to strip away these font names upon paste to avoid these font names falling back to Times New Roman.
     15   
     16    Added the code to strip these font names away in EditingStyle::mergeStyleFromRulesForSerialization, which is used by
     17    StylizedMarkupAccumulator to generate HTML during copy. This works because WebContentReader::readWebArchive invokes
     18    sanitizeMarkupWithArchive which inserts the pasteboard content into a temporary document then re-serializes back to HTML
     19    using StylizedMarkupAccumulator before the actual pasting happens.
     20   
     21    This approach has a few benefits over stripping away these font names in ReplaceSelectionCommand:
     22   
     23    1. It would only affect clients that opts-in to copy & paste sanitization. e.g. it won't affect legacy WebKit clients
     24    and those that opt out of pasteboard content sanitization.
     25   
     26    2. It preserves font names such as ".SF Blah" that a website may insert as some kind of house keeping purposes if ever.
     27    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
     28    only affect cross-site and cross-app pasting, which is rare and less likely to affect real user scenarios.
     29   
     30    3. It avoids exposing bogus .Apple* or .SF* font names to websites that directly use event.clipboardData.getData.
     31    Indeed stripping away bogus markup like this is one of the key features / benefit of using copy & paste sanitization.
     32   
     33    Test: editing/pasteboard/paste-cocoa-writer-markup-with-system-fonts.html
     34   
     35    * editing/EditingStyle.cpp:
     36    (WebCore::usesForbiddenSystemFontAsOnlyFontFamilyName): Added.
     37    (WebCore::EditingStyle::mergeStyleFromRulesForSerialization): Added the code to remove font-family property when needed.
     38    * platform/graphics/FontCache.h:
     39    * platform/graphics/cocoa/FontCacheCoreText.cpp:
     40    (WebCore::isSystemFont): Moved.
     41    (WebCore::FontCache::isSystemFontForbiddenForEditing): Added.
     42    * platform/graphics/freetype/FontCacheFreeType.cpp:
     43    (WebCore::FontCache::isSystemFontForbiddenForEditing): Added. Always returns false.
     44    * platform/graphics/win/FontCacheWin.cpp:
     45    (WebCore::FontCache::isSystemFontForbiddenForEditing): Ditto.
     46   
     47    Tools:
     48   
     49    Added a test to strip away system font names such as ".AppleSystemUIFont", ".SFUI-Regular", and ".SF UI Mono".
     50   
     51    * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     52    * TestWebKitAPI/Tests/WebKitCocoa/PasteHTML.mm:
     53    * TestWebKitAPI/Tests/WebKitCocoa/cocoa-writer-markup-with-system-fonts.html: Added.
     54   
     55    LayoutTests:
     56   
     57    Added a test for ClipboardData.getData returning the original markup and execCommand('insertHTML', ~)
     58    not stripping away system font names.
     59   
     60    * editing/pasteboard/paste-cocoa-writer-markup-with-system-fonts-expected.txt: Added.
     61    * editing/pasteboard/paste-cocoa-writer-markup-with-system-fonts.html: Added.
     62   
     63   
     64    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@247720 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     65
     66    2019-07-23  Ryosuke Niwa  <rniwa@webkit.org>
     67
     68            WebKit should strip away system font names from the pasted content
     69            https://bugs.webkit.org/show_bug.cgi?id=199975
     70            <rdar://problem/53336353>
     71
     72            Reviewed by Darin Adler.
     73
     74            Added a test for ClipboardData.getData returning the original markup and execCommand('insertHTML', ~)
     75            not stripping away system font names.
     76
     77            * editing/pasteboard/paste-cocoa-writer-markup-with-system-fonts-expected.txt: Added.
     78            * editing/pasteboard/paste-cocoa-writer-markup-with-system-fonts.html: Added.
     79
    1802019-08-06  Kocsen Chung  <kocsen_chung@apple.com>
    281
  • branches/safari-608.1-branch/Source/WebCore/ChangeLog

    r248298 r248344  
     12019-08-06  Kocsen Chung  <kocsen_chung@apple.com>
     2
     3        Cherry-pick r247720. rdar://problem/54017869
     4
     5    WebKit should strip away system font names from the pasted content
     6    https://bugs.webkit.org/show_bug.cgi?id=199975
     7    <rdar://problem/53336353>
     8   
     9    Reviewed by Darin Adler.
     10   
     11    Source/WebCore:
     12   
     13    Cocoa HTML Writer sometimes generate system font names such as ".AppleSystemUIFont", ".SFUI-Regular", and ".SF UI Mono".
     14    We need to strip away these font names upon paste to avoid these font names falling back to Times New Roman.
     15   
     16    Added the code to strip these font names away in EditingStyle::mergeStyleFromRulesForSerialization, which is used by
     17    StylizedMarkupAccumulator to generate HTML during copy. This works because WebContentReader::readWebArchive invokes
     18    sanitizeMarkupWithArchive which inserts the pasteboard content into a temporary document then re-serializes back to HTML
     19    using StylizedMarkupAccumulator before the actual pasting happens.
     20   
     21    This approach has a few benefits over stripping away these font names in ReplaceSelectionCommand:
     22   
     23    1. It would only affect clients that opts-in to copy & paste sanitization. e.g. it won't affect legacy WebKit clients
     24    and those that opt out of pasteboard content sanitization.
     25   
     26    2. It preserves font names such as ".SF Blah" that a website may insert as some kind of house keeping purposes if ever.
     27    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
     28    only affect cross-site and cross-app pasting, which is rare and less likely to affect real user scenarios.
     29   
     30    3. It avoids exposing bogus .Apple* or .SF* font names to websites that directly use event.clipboardData.getData.
     31    Indeed stripping away bogus markup like this is one of the key features / benefit of using copy & paste sanitization.
     32   
     33    Test: editing/pasteboard/paste-cocoa-writer-markup-with-system-fonts.html
     34   
     35    * editing/EditingStyle.cpp:
     36    (WebCore::usesForbiddenSystemFontAsOnlyFontFamilyName): Added.
     37    (WebCore::EditingStyle::mergeStyleFromRulesForSerialization): Added the code to remove font-family property when needed.
     38    * platform/graphics/FontCache.h:
     39    * platform/graphics/cocoa/FontCacheCoreText.cpp:
     40    (WebCore::isSystemFont): Moved.
     41    (WebCore::FontCache::isSystemFontForbiddenForEditing): Added.
     42    * platform/graphics/freetype/FontCacheFreeType.cpp:
     43    (WebCore::FontCache::isSystemFontForbiddenForEditing): Added. Always returns false.
     44    * platform/graphics/win/FontCacheWin.cpp:
     45    (WebCore::FontCache::isSystemFontForbiddenForEditing): Ditto.
     46   
     47    Tools:
     48   
     49    Added a test to strip away system font names such as ".AppleSystemUIFont", ".SFUI-Regular", and ".SF UI Mono".
     50   
     51    * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     52    * TestWebKitAPI/Tests/WebKitCocoa/PasteHTML.mm:
     53    * TestWebKitAPI/Tests/WebKitCocoa/cocoa-writer-markup-with-system-fonts.html: Added.
     54   
     55    LayoutTests:
     56   
     57    Added a test for ClipboardData.getData returning the original markup and execCommand('insertHTML', ~)
     58    not stripping away system font names.
     59   
     60    * editing/pasteboard/paste-cocoa-writer-markup-with-system-fonts-expected.txt: Added.
     61    * editing/pasteboard/paste-cocoa-writer-markup-with-system-fonts.html: Added.
     62   
     63   
     64    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@247720 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     65
     66    2019-07-23  Ryosuke Niwa  <rniwa@webkit.org>
     67
     68            WebKit should strip away system font names from the pasted content
     69            https://bugs.webkit.org/show_bug.cgi?id=199975
     70            <rdar://problem/53336353>
     71
     72            Reviewed by Darin Adler.
     73
     74            Cocoa HTML Writer sometimes generate system font names such as ".AppleSystemUIFont", ".SFUI-Regular", and ".SF UI Mono".
     75            We need to strip away these font names upon paste to avoid these font names falling back to Times New Roman.
     76
     77            Added the code to strip these font names away in EditingStyle::mergeStyleFromRulesForSerialization, which is used by
     78            StylizedMarkupAccumulator to generate HTML during copy. This works because WebContentReader::readWebArchive invokes
     79            sanitizeMarkupWithArchive which inserts the pasteboard content into a temporary document then re-serializes back to HTML
     80            using StylizedMarkupAccumulator before the actual pasting happens.
     81
     82            This approach has a few benefits over stripping away these font names in ReplaceSelectionCommand:
     83
     84            1. It would only affect clients that opts-in to copy & paste sanitization. e.g. it won't affect legacy WebKit clients
     85            and those that opt out of pasteboard content sanitization.
     86
     87            2. It preserves font names such as ".SF Blah" that a website may insert as some kind of house keeping purposes if ever.
     88            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
     89            only affect cross-site and cross-app pasting, which is rare and less likely to affect real user scenarios.
     90
     91            3. It avoids exposing bogus .Apple* or .SF* font names to websites that directly use event.clipboardData.getData.
     92            Indeed stripping away bogus markup like this is one of the key features / benefit of using copy & paste sanitization.
     93
     94            Test: editing/pasteboard/paste-cocoa-writer-markup-with-system-fonts.html
     95
     96            * editing/EditingStyle.cpp:
     97            (WebCore::usesForbiddenSystemFontAsOnlyFontFamilyName): Added.
     98            (WebCore::EditingStyle::mergeStyleFromRulesForSerialization): Added the code to remove font-family property when needed.
     99            * platform/graphics/FontCache.h:
     100            * platform/graphics/cocoa/FontCacheCoreText.cpp:
     101            (WebCore::isSystemFont): Moved.
     102            (WebCore::FontCache::isSystemFontForbiddenForEditing): Added.
     103            * platform/graphics/freetype/FontCacheFreeType.cpp:
     104            (WebCore::FontCache::isSystemFontForbiddenForEditing): Added. Always returns false.
     105            * platform/graphics/win/FontCacheWin.cpp:
     106            (WebCore::FontCache::isSystemFontForbiddenForEditing): Ditto.
     107
    11082019-08-06  Kocsen Chung  <kocsen_chung@apple.com>
    2109
  • branches/safari-608.1-branch/Source/WebCore/editing/EditingStyle.cpp

    r246490 r248344  
    3030#include "ApplyStyleCommand.h"
    3131#include "CSSComputedStyleDeclaration.h"
     32#include "CSSFontFamily.h"
    3233#include "CSSFontStyleValue.h"
    3334#include "CSSParser.h"
     
    3839#include "Editing.h"
    3940#include "Editor.h"
     41#include "FontCache.h"
     42#include "FontCascade.h"
    4043#include "Frame.h"
    4144#include "HTMLFontElement.h"
     
    12801283}
    12811284
     1285static bool usesForbiddenSystemFontAsOnlyFontFamilyName(CSSValue& value)
     1286{
     1287    if (!is<CSSValueList>(value) || downcast<CSSValueList>(value).length() != 1)
     1288        return false;
     1289
     1290    auto& item = *downcast<CSSValueList>(value).item(0);
     1291    if (!is<CSSPrimitiveValue>(item))
     1292        return false;
     1293
     1294    auto& primitiveValue = downcast<CSSPrimitiveValue>(item);
     1295    if (!primitiveValue.isFontFamily())
     1296        return false;
     1297    return FontCache::isSystemFontForbiddenForEditing(primitiveValue.fontFamily().familyName);
     1298}
     1299
    12821300void EditingStyle::mergeStyleFromRulesForSerialization(StyledElement& element)
    12831301{
     
    12901308    ComputedStyleExtractor computedStyle(&element);
    12911309
     1310    bool shouldRemoveFontFamily = false;
    12921311    {
    12931312        unsigned propertyCount = m_mutableStyle->propertyCount();
    12941313        for (unsigned i = 0; i < propertyCount; ++i) {
    12951314            StyleProperties::PropertyReference property = m_mutableStyle->propertyAt(i);
    1296             CSSValue* value = property.value();
    1297             if (!is<CSSPrimitiveValue>(*value))
     1315            CSSValue& value = *property.value();
     1316            if (property.id() == CSSPropertyFontFamily && usesForbiddenSystemFontAsOnlyFontFamilyName(value)) {
     1317                shouldRemoveFontFamily = true;
    12981318                continue;
    1299             if (downcast<CSSPrimitiveValue>(*value).isPercentage()) {
     1319            }
     1320            if (!is<CSSPrimitiveValue>(value))
     1321                continue;
     1322            if (downcast<CSSPrimitiveValue>(value).isPercentage()) {
    13001323                if (auto computedPropertyValue = computedStyle.propertyValue(property.id()))
    13011324                    fromComputedStyle->addParsedProperty(CSSProperty(property.id(), WTFMove(computedPropertyValue)));
    13021325            }
    13031326        }
     1327    }
     1328    if (shouldRemoveFontFamily) {
     1329        m_mutableStyle->removeProperty(CSSPropertyFontFamily);
     1330        fromComputedStyle->removeProperty(CSSPropertyFontFamily);
    13041331    }
    13051332    m_mutableStyle->mergeAndOverrideOnConflict(fromComputedStyle.get());
  • branches/safari-608.1-branch/Source/WebCore/platform/graphics/FontCache.h

    r247574 r248344  
    198198    void platformInit();
    199199
     200    static bool isSystemFontForbiddenForEditing(const String&);
     201
    200202#if PLATFORM(COCOA)
    201203    WEBCORE_EXPORT static void setFontWhitelist(const Vector<String>&);
  • branches/safari-608.1-branch/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp

    r247632 r248344  
    784784}
    785785
     786static inline bool isSystemFont(const String& family)
     787{
     788    // AtomString's operator[] handles out-of-bounds by returning 0.
     789    return family[0] == '.';
     790}
     791
     792bool FontCache::isSystemFontForbiddenForEditing(const String& fontFamily)
     793{
     794    return isSystemFont(fontFamily);
     795}
     796
    786797static CTFontSymbolicTraits computeTraits(const FontDescription& fontDescription)
    787798{
     
    829840    for (auto& item : inputWhitelist)
    830841        whitelist.add(item);
    831 }
    832 
    833 static inline bool isSystemFont(const AtomString& family)
    834 {
    835     // AtomString's operator[] handles out-of-bounds by returning 0.
    836     return family[0] == '.';
    837842}
    838843
     
    11841189{
    11851190    const auto& whitelist = fontWhitelist();
    1186     if (!isSystemFont(family) && whitelist.size() && !whitelist.contains(family))
     1191    if (!isSystemFont(family.string()) && whitelist.size() && !whitelist.contains(family))
    11871192        return { nullptr };
    11881193
  • branches/safari-608.1-branch/Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp

    r246490 r248344  
    187187}
    188188
     189bool FontCache::isSystemFontForbiddenForEditing(const String&)
     190{
     191    return false;
     192}
     193
    189194Ref<Font> FontCache::lastResortFallbackFont(const FontDescription& fontDescription)
    190195{
  • branches/safari-608.1-branch/Source/WebCore/platform/graphics/win/FontCacheWin.cpp

    r246490 r248344  
    329329}
    330330
     331bool FontCache::isSystemFontForbiddenForEditing(const String&)
     332{
     333    return false;
     334}
     335
    331336RefPtr<Font> FontCache::fontFromDescriptionAndLogFont(const FontDescription& fontDescription, const LOGFONT& font, AtomString& outFontFamilyName)
    332337{
  • branches/safari-608.1-branch/Tools/ChangeLog

    r248343 r248344  
     12019-08-06  Kocsen Chung  <kocsen_chung@apple.com>
     2
     3        Cherry-pick r247720. rdar://problem/54017869
     4
     5    WebKit should strip away system font names from the pasted content
     6    https://bugs.webkit.org/show_bug.cgi?id=199975
     7    <rdar://problem/53336353>
     8   
     9    Reviewed by Darin Adler.
     10   
     11    Source/WebCore:
     12   
     13    Cocoa HTML Writer sometimes generate system font names such as ".AppleSystemUIFont", ".SFUI-Regular", and ".SF UI Mono".
     14    We need to strip away these font names upon paste to avoid these font names falling back to Times New Roman.
     15   
     16    Added the code to strip these font names away in EditingStyle::mergeStyleFromRulesForSerialization, which is used by
     17    StylizedMarkupAccumulator to generate HTML during copy. This works because WebContentReader::readWebArchive invokes
     18    sanitizeMarkupWithArchive which inserts the pasteboard content into a temporary document then re-serializes back to HTML
     19    using StylizedMarkupAccumulator before the actual pasting happens.
     20   
     21    This approach has a few benefits over stripping away these font names in ReplaceSelectionCommand:
     22   
     23    1. It would only affect clients that opts-in to copy & paste sanitization. e.g. it won't affect legacy WebKit clients
     24    and those that opt out of pasteboard content sanitization.
     25   
     26    2. It preserves font names such as ".SF Blah" that a website may insert as some kind of house keeping purposes if ever.
     27    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
     28    only affect cross-site and cross-app pasting, which is rare and less likely to affect real user scenarios.
     29   
     30    3. It avoids exposing bogus .Apple* or .SF* font names to websites that directly use event.clipboardData.getData.
     31    Indeed stripping away bogus markup like this is one of the key features / benefit of using copy & paste sanitization.
     32   
     33    Test: editing/pasteboard/paste-cocoa-writer-markup-with-system-fonts.html
     34   
     35    * editing/EditingStyle.cpp:
     36    (WebCore::usesForbiddenSystemFontAsOnlyFontFamilyName): Added.
     37    (WebCore::EditingStyle::mergeStyleFromRulesForSerialization): Added the code to remove font-family property when needed.
     38    * platform/graphics/FontCache.h:
     39    * platform/graphics/cocoa/FontCacheCoreText.cpp:
     40    (WebCore::isSystemFont): Moved.
     41    (WebCore::FontCache::isSystemFontForbiddenForEditing): Added.
     42    * platform/graphics/freetype/FontCacheFreeType.cpp:
     43    (WebCore::FontCache::isSystemFontForbiddenForEditing): Added. Always returns false.
     44    * platform/graphics/win/FontCacheWin.cpp:
     45    (WebCore::FontCache::isSystemFontForbiddenForEditing): Ditto.
     46   
     47    Tools:
     48   
     49    Added a test to strip away system font names such as ".AppleSystemUIFont", ".SFUI-Regular", and ".SF UI Mono".
     50   
     51    * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     52    * TestWebKitAPI/Tests/WebKitCocoa/PasteHTML.mm:
     53    * TestWebKitAPI/Tests/WebKitCocoa/cocoa-writer-markup-with-system-fonts.html: Added.
     54   
     55    LayoutTests:
     56   
     57    Added a test for ClipboardData.getData returning the original markup and execCommand('insertHTML', ~)
     58    not stripping away system font names.
     59   
     60    * editing/pasteboard/paste-cocoa-writer-markup-with-system-fonts-expected.txt: Added.
     61    * editing/pasteboard/paste-cocoa-writer-markup-with-system-fonts.html: Added.
     62   
     63   
     64    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@247720 268f45cc-cd09-0410-ab3c-d52691b4dbfc
     65
     66    2019-07-23  Ryosuke Niwa  <rniwa@webkit.org>
     67
     68            WebKit should strip away system font names from the pasted content
     69            https://bugs.webkit.org/show_bug.cgi?id=199975
     70            <rdar://problem/53336353>
     71
     72            Reviewed by Darin Adler.
     73
     74            Added a test to strip away system font names such as ".AppleSystemUIFont", ".SFUI-Regular", and ".SF UI Mono".
     75
     76            * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     77            * TestWebKitAPI/Tests/WebKitCocoa/PasteHTML.mm:
     78            * TestWebKitAPI/Tests/WebKitCocoa/cocoa-writer-markup-with-system-fonts.html: Added.
     79
    1802019-08-06  Kocsen Chung  <kocsen_chung@apple.com>
    281
  • branches/safari-608.1-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r248109 r248344  
    705705                9B7D740F1F8378770006C432 /* paste-rtfd.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9B7D740E1F8377E60006C432 /* paste-rtfd.html */; };
    706706                9BAD7F3E22690F2000F8DA66 /* DeallocWebViewInEventListener.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9BAD7F3D22690F1400F8DA66 /* DeallocWebViewInEventListener.mm */; };
     707                9BAE177B22E2BBFB00DF3098 /* cocoa-writer-markup-with-system-fonts.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9BAE177A22E2BB6B00DF3098 /* cocoa-writer-markup-with-system-fonts.html */; };
    707708                9BCB7C2820130600003E7C0C /* PasteHTML.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9BCB7C2620130600003E7C0C /* PasteHTML.mm */; };
    708709                9BCD411A206DBCA3001D71BE /* mso-list-on-h4.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9BCD4119206D5ED7001D71BE /* mso-list-on-h4.html */; };
     
    10731074                        dstSubfolderSpec = 7;
    10741075                        files = (
     1076                                9BAE177B22E2BBFB00DF3098 /* cocoa-writer-markup-with-system-fonts.html in Copy Resources */,
    10751077                                55A817FF2181021A0004A39A /* 100x100-red.tga in Copy Resources */,
    10761078                                1A9E52C913E65EF4006917F5 /* 18-characters.html in Copy Resources */,
     
    20312033                9B7D740E1F8377E60006C432 /* paste-rtfd.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "paste-rtfd.html"; sourceTree = "<group>"; };
    20322034                9BAD7F3D22690F1400F8DA66 /* DeallocWebViewInEventListener.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DeallocWebViewInEventListener.mm; sourceTree = "<group>"; };
     2035                9BAE177A22E2BB6B00DF3098 /* cocoa-writer-markup-with-system-fonts.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "cocoa-writer-markup-with-system-fonts.html"; sourceTree = "<group>"; };
    20332036                9BCB7C2620130600003E7C0C /* PasteHTML.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = PasteHTML.mm; sourceTree = "<group>"; };
    20342037                9BCD4119206D5ED7001D71BE /* mso-list-on-h4.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "mso-list-on-h4.html"; sourceTree = "<group>"; };
     
    32553258                                5120C83B1E674E350025B250 /* WebsiteDataStoreCustomPaths.html */,
    32563259                                2E131C171D83A97E001BA36C /* wide-autoplaying-video-with-audio.html */,
     3260                                9BAE177A22E2BB6B00DF3098 /* cocoa-writer-markup-with-system-fonts.html */,
    32573261                        );
    32583262                        name = Resources;
  • branches/safari-608.1-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/PasteHTML.mm

    r242339 r248344  
    328328}
    329329
     330TEST(PasteHTML, StripsSystemFontNames)
     331{
     332    writeHTMLToPasteboard([NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"cocoa-writer-markup-with-system-fonts" ofType:@"html" inDirectory:@"TestWebKitAPI.resources"] encoding:NSUTF8StringEncoding error:NULL]);
     333
     334    auto webView = createWebViewWithCustomPasteboardDataSetting(true);
     335    [webView synchronouslyLoadTestPageNamed:@"paste-rtfd"];
     336    [webView paste:nil];
     337
     338    EXPECT_WK_STREQ("[\"text/html\"]", [webView stringByEvaluatingJavaScript:@"JSON.stringify(clipboardData.types)"]);
     339    [webView stringByEvaluatingJavaScript:@"window.htmlInDataTransfer = clipboardData.values[0]"];
     340    [webView stringByEvaluatingJavaScript:@"window.pastedHTML = editor.innerHTML"];
     341
     342    EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"pastedHTML.includes('Hello Cocoa')"].boolValue);
     343    EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"pastedHTML.includes('font-weight: bold')"].boolValue);
     344    EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"!pastedHTML.includes('.AppleSystemUIFont')"].boolValue);
     345    EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"!pastedHTML.includes('.SFUI')"].boolValue);
     346    EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"!pastedHTML.includes('.SF')"].boolValue);
     347
     348    EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"htmlInDataTransfer.includes('Hello Cocoa')"].boolValue);
     349    EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"htmlInDataTransfer.includes('font-weight: bold')"].boolValue);
     350    EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"!htmlInDataTransfer.includes('.AppleSystemUIFont')"].boolValue);
     351    EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"!htmlInDataTransfer.includes('.SFUI')"].boolValue);
     352    EXPECT_TRUE([webView stringByEvaluatingJavaScript:@"!htmlInDataTransfer.includes('.SF')"].boolValue);
     353
     354    EXPECT_WK_STREQ([webView stringByEvaluatingJavaScript:@"getComputedStyle(document.querySelector('.s2')).fontFamily"],
     355        [webView stringByEvaluatingJavaScript:@"getComputedStyle(document.body).fontFamily"]);
     356    EXPECT_WK_STREQ([webView stringByEvaluatingJavaScript:@"getComputedStyle(document.querySelector('.s4')).fontFamily"],
     357        [webView stringByEvaluatingJavaScript:@"getComputedStyle(document.body).fontFamily"]);
     358}
    330359
    331360#endif // PLATFORM(COCOA)
Note: See TracChangeset for help on using the changeset viewer.