Changeset 243113 in webkit


Ignore:
Timestamp:
Mar 18, 2019 4:32:20 PM (5 years ago)
Author:
timothy@apple.com
Message:

Add new NSAttributedString API for converting HTML.
https://bugs.webkit.org/show_bug.cgi?id=195636
rdar://problem/45055697

Reviewed by Tim Horton.

Source/WebCore:

  • en.lproj/Localizable.strings: Updated.

Source/WebKit:

  • Platform/spi/ios/UIKitSPI.h:
  • SourcesCocoa.txt:
  • UIProcess/API/Cocoa/NSAttributedString.h: Added.
  • UIProcess/API/Cocoa/NSAttributedString.mm: Added.

(-[_WKAttributedStringNavigationDelegate webView:decidePolicyForNavigationAction:decisionHandler:]):
(-[_WKAttributedStringNavigationDelegate webView:didFailProvisionalNavigation:withError:]):
(-[_WKAttributedStringNavigationDelegate webView:didFailNavigation:withError:]):
(-[_WKAttributedStringNavigationDelegate webView:didFinishNavigation:]):
(+[_WKAttributedStringWebViewCache cache]):
(+[_WKAttributedStringWebViewCache configuration]):
(+[_WKAttributedStringWebViewCache clearConfiguration]):
(+[_WKAttributedStringWebViewCache retrieveOrCreateWebView]):
(+[_WKAttributedStringWebViewCache cacheWebView:]):
(+[_WKAttributedStringWebViewCache resetPurgeDelay]):
(+[_WKAttributedStringWebViewCache purgeSingleWebView]):
(+[_WKAttributedStringWebViewCache purgeAllWebViews]):
(+[NSAttributedString _loadFromHTMLWithOptions:contentLoader:completionHandler:]):
(+[NSAttributedString loadFromHTMLWithRequest:options:completionHandler:]):
(+[NSAttributedString loadFromHTMLWithFileURL:options:completionHandler:]):
(+[NSAttributedString loadFromHTMLWithString:options:completionHandler:]):
(+[NSAttributedString loadFromHTMLWithData:options:completionHandler:]):

  • UIProcess/API/Cocoa/NSAttributedStringPrivate.h: Copied from Source/WebKit/UIProcess/API/Cocoa/WKErrorInternal.h.
  • UIProcess/API/Cocoa/WKError.h:
  • UIProcess/API/Cocoa/WKError.mm:

(localizedDescriptionForErrorCode):
(createNSError):

  • UIProcess/API/Cocoa/WKErrorInternal.h:
  • WebKit.xcodeproj/project.pbxproj:
  • WebProcess/WebPage/Cocoa/WebPageCocoa.mm:

(WebKit::WebPage::getContentsAsAttributedString):

Location:
trunk/Source
Files:
2 added
10 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r243112 r243113  
     12019-03-18  Timothy Hatcher  <timothy@apple.com>
     2
     3        Add new NSAttributedString API for converting HTML.
     4        https://bugs.webkit.org/show_bug.cgi?id=195636
     5        rdar://problem/45055697
     6
     7        Reviewed by Tim Horton.
     8
     9        * en.lproj/Localizable.strings: Updated.
     10
    1112019-03-18  Zalan Bujtas  <zalan@apple.com>
    212
  • trunk/Source/WebCore/en.lproj/Localizable.strings

    r242920 r243113  
    110110"Are you sure you wish to go to this site?" = "Are you sure you wish to go to this site?";
    111111
     112/* WKErrorAttributedStringContentFailedToLoad description */
     113"Attributed string content failed to load" = "Attributed string content failed to load";
     114
    112115/* Menu item label for automatic track selection behavior */
    113116"Auto (Recommended)" = "Auto (Recommended)";
     
    803806"Tighten Kerning (Undo action name)" = "Tighten Kerning";
    804807
     808/* WKErrorAttributedStringContentLoadTimedOut description */
     809"Timed out while loading attributed string content" = "Timed out while loading attributed string content";
     810
    805811/* prompt string in authentication panel */
    806812"To view this page, you must log in to area “%@” on %@." = "To view this page, you must log in to area “%@” on %@.";
  • trunk/Source/WebKit/ChangeLog

    r243110 r243113  
     12019-03-18  Timothy Hatcher  <timothy@apple.com>
     2
     3        Add new NSAttributedString API for converting HTML.
     4        https://bugs.webkit.org/show_bug.cgi?id=195636
     5        rdar://problem/45055697
     6
     7        Reviewed by Tim Horton.
     8
     9        * Platform/spi/ios/UIKitSPI.h:
     10        * SourcesCocoa.txt:
     11        * UIProcess/API/Cocoa/NSAttributedString.h: Added.
     12        * UIProcess/API/Cocoa/NSAttributedString.mm: Added.
     13        (-[_WKAttributedStringNavigationDelegate webView:decidePolicyForNavigationAction:decisionHandler:]):
     14        (-[_WKAttributedStringNavigationDelegate webView:didFailProvisionalNavigation:withError:]):
     15        (-[_WKAttributedStringNavigationDelegate webView:didFailNavigation:withError:]):
     16        (-[_WKAttributedStringNavigationDelegate webView:didFinishNavigation:]):
     17        (+[_WKAttributedStringWebViewCache cache]):
     18        (+[_WKAttributedStringWebViewCache configuration]):
     19        (+[_WKAttributedStringWebViewCache clearConfiguration]):
     20        (+[_WKAttributedStringWebViewCache retrieveOrCreateWebView]):
     21        (+[_WKAttributedStringWebViewCache cacheWebView:]):
     22        (+[_WKAttributedStringWebViewCache resetPurgeDelay]):
     23        (+[_WKAttributedStringWebViewCache purgeSingleWebView]):
     24        (+[_WKAttributedStringWebViewCache purgeAllWebViews]):
     25        (+[NSAttributedString _loadFromHTMLWithOptions:contentLoader:completionHandler:]):
     26        (+[NSAttributedString loadFromHTMLWithRequest:options:completionHandler:]):
     27        (+[NSAttributedString loadFromHTMLWithFileURL:options:completionHandler:]):
     28        (+[NSAttributedString loadFromHTMLWithString:options:completionHandler:]):
     29        (+[NSAttributedString loadFromHTMLWithData:options:completionHandler:]):
     30        * UIProcess/API/Cocoa/NSAttributedStringPrivate.h: Copied from Source/WebKit/UIProcess/API/Cocoa/WKErrorInternal.h.
     31        * UIProcess/API/Cocoa/WKError.h:
     32        * UIProcess/API/Cocoa/WKError.mm:
     33        (localizedDescriptionForErrorCode):
     34        (createNSError):
     35        * UIProcess/API/Cocoa/WKErrorInternal.h:
     36        * WebKit.xcodeproj/project.pbxproj:
     37        * WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
     38        (WebKit::WebPage::getContentsAsAttributedString):
     39
    1402019-03-18  Alex Christensen  <achristensen@webkit.org>
    241
  • trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h

    r242807 r243113  
    11941194extern NSString *const UIBacklightLevelChangedNotification;
    11951195
     1196extern NSString * const NSTextEncodingNameDocumentOption;
     1197extern NSString * const NSBaseURLDocumentOption;
     1198extern NSString * const NSTimeoutDocumentOption;
     1199extern NSString * const NSWebPreferencesDocumentOption;
     1200extern NSString * const NSWebResourceLoadDelegateDocumentOption;
     1201extern NSString * const NSTextSizeMultiplierDocumentOption;
     1202
    11961203WTF_EXTERN_C_END
  • trunk/Source/WebKit/SourcesCocoa.txt

    r243110 r243113  
    273273UIProcess/API/Cocoa/APIWebsiteDataStoreCocoa.mm
    274274UIProcess/API/Cocoa/LegacyBundleForClass.mm
     275UIProcess/API/Cocoa/NSAttributedString.mm
    275276UIProcess/API/Cocoa/WKBackForwardList.mm
    276277UIProcess/API/Cocoa/WKBackForwardListItem.mm
  • trunk/Source/WebKit/UIProcess/API/Cocoa/NSAttributedStringPrivate.h

    r243112 r243113  
    11/*
    2  * Copyright (C) 2014 Apple Inc. All rights reserved.
     2 * Copyright (C) 2019 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #import "WKErrorPrivate.h"
     26#import <WebKit/NSAttributedString.h>
    2727
    28 #import <wtf/RetainPtr.h>
    29 #import "GenericCallback.h"
     28@class WKNavigation;
     29@class WKWebView;
    3030
    31 RetainPtr<NSError> createNSError(WKErrorCode);
    32 NSString *localizedDescriptionForErrorCode(WKErrorCode);
     31NS_ASSUME_NONNULL_BEGIN
     32
     33/*!
     34 @discussion Private extension of @link //apple_ref/occ/NSAttributedString NSAttributedString @/link to
     35 translate HTML content into attributed strings using WebKit.
     36 */
     37@interface NSAttributedString (WKPrivate)
     38
     39/*!
     40 @abstract Converts the contents loaded by a content loader block into an attributed string.
     41 @param options Document attributes for interpreting the document contents.
     42 NSTextSizeMultiplierDocumentOption, and NSTimeoutDocumentOption are supported option keys.
     43 @param contentLoader A block to invoke when content needs to be loaded in the supplied
     44 @link WKWebView @/link. A @link WKNavigation @/link for the main frame must be returned.
     45 @param completionHandler A block to invoke when the translation completes or fails.
     46 @discussion The completionHandler is passed the attributed string result along with any
     47 document-level attributes, or an error.
     48 */
     49+ (void)_loadFromHTMLWithOptions:(NSDictionary<NSAttributedStringDocumentReadingOptionKey, id> *)options contentLoader:(WKNavigation *(^)(WKWebView *))loadWebContent completionHandler:(NSAttributedStringCompletionHandler)completionHandler;
     50
     51@end
     52
     53NS_ASSUME_NONNULL_END
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKError.h

    r242339 r243113  
    4444 @constant WKErrorContentRuleListStoreRemoveFailed     Indicates that removing a WKUserContentRuleList failed.
    4545 @constant WKErrorContentRuleListStoreVersionMismatch  Indicates that the WKUserContentRuleList version did not match the latest.
     46 @constant WKErrorAttributedStringContentFailedToLoad  Indicates that the attributed string content failed to load.
     47 @constant WKErrorAttributedStringContentLoadTimedOut  Indicates that loading attributed string content timed out.
    4648 */
    4749typedef NS_ENUM(NSInteger, WKErrorCode) {
     
    5557    WKErrorContentRuleListStoreRemoveFailed WK_API_AVAILABLE(macosx(10.13), ios(11.0)),
    5658    WKErrorContentRuleListStoreVersionMismatch WK_API_AVAILABLE(macosx(10.13), ios(11.0)),
     59    WKErrorAttributedStringContentFailedToLoad WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)),
     60    WKErrorAttributedStringContentLoadTimedOut WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA)),
    5761} WK_API_AVAILABLE(macosx(10.10), ios(8.0));
    5862
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKError.mm

    r242339 r243113  
    6868    case WKErrorContentRuleListStoreRemoveFailed:
    6969        return WEB_UI_STRING("Removing a WKContentRuleList failed", "WKErrorContentRuleListStoreRemoveFailed description");
     70
     71    case WKErrorAttributedStringContentFailedToLoad:
     72        return WEB_UI_STRING("Attributed string content failed to load", "WKErrorAttributedStringContentFailedToLoad description");
     73
     74    case WKErrorAttributedStringContentLoadTimedOut:
     75        return WEB_UI_STRING("Timed out while loading attributed string content", "WKErrorAttributedStringContentLoadTimedOut description");
    7076    }
    7177}
    7278
    73 RetainPtr<NSError> createNSError(WKErrorCode errorCode)
     79RetainPtr<NSError> createNSError(WKErrorCode errorCode, NSError* underlyingError)
    7480{
    75     auto userInfo = adoptNS([[NSDictionary alloc] initWithObjectsAndKeys:localizedDescriptionForErrorCode(errorCode), NSLocalizedDescriptionKey, nil]);
     81    NSDictionary *userInfo = nil;
     82    if (underlyingError)
     83        userInfo = @{ NSLocalizedDescriptionKey: localizedDescriptionForErrorCode(errorCode), NSUnderlyingErrorKey: underlyingError };
     84    else
     85        userInfo = @{ NSLocalizedDescriptionKey: localizedDescriptionForErrorCode(errorCode) };
    7686
    77     return adoptNS([[NSError alloc] initWithDomain:WKErrorDomain code:errorCode userInfo:userInfo.get()]);
     87    return adoptNS([[NSError alloc] initWithDomain:WKErrorDomain code:errorCode userInfo:userInfo]);
    7888}
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKErrorInternal.h

    r242339 r243113  
    2929#import "GenericCallback.h"
    3030
    31 RetainPtr<NSError> createNSError(WKErrorCode);
     31RetainPtr<NSError> createNSError(WKErrorCode, NSError* underlyingError = nil);
    3232NSString *localizedDescriptionForErrorCode(WKErrorCode);
  • trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj

    r243110 r243113  
    386386                1C0A19581C90068F00FE0EBB /* WebAutomationSessionMessages.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C0A19561C90068F00FE0EBB /* WebAutomationSessionMessages.h */; };
    387387                1C0A195C1C916E1B00FE0EBB /* WebAutomationSessionProxyScriptSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C0A195B1C916E1B00FE0EBB /* WebAutomationSessionProxyScriptSource.h */; };
     388                1C20936022318CB000026A39 /* NSAttributedString.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C20935E22318CB000026A39 /* NSAttributedString.h */; settings = {ATTRIBUTES = (Private, ); }; };
     389                1C2184022233872800BAC700 /* NSAttributedStringPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C2184012233872800BAC700 /* NSAttributedStringPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; };
    388390                1C891D6619B124FF00BA79DD /* WebInspectorUI.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C891D6319B124FF00BA79DD /* WebInspectorUI.h */; };
    389391                1C8E28201275D15400BC7BD0 /* WebInspector.h in Headers */ = {isa = PBXBuildFile; fileRef = 1C8E281E1275D15400BC7BD0 /* WebInspector.h */; };
     
    23972399                1C0A195A1C91669500FE0EBB /* WebAutomationSessionProxy.js */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.javascript; path = WebAutomationSessionProxy.js; sourceTree = "<group>"; };
    23982400                1C0A195B1C916E1B00FE0EBB /* WebAutomationSessionProxyScriptSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WebAutomationSessionProxyScriptSource.h; path = DerivedSources/WebKit2/WebAutomationSessionProxyScriptSource.h; sourceTree = BUILT_PRODUCTS_DIR; };
     2401                1C20935E22318CB000026A39 /* NSAttributedString.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NSAttributedString.h; sourceTree = "<group>"; };
     2402                1C20935F22318CB000026A39 /* NSAttributedString.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = NSAttributedString.mm; sourceTree = "<group>"; };
     2403                1C2184012233872800BAC700 /* NSAttributedStringPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSAttributedStringPrivate.h; sourceTree = "<group>"; };
    23992404                1C77C1951288A872006A742F /* WebInspectorProxy.messages.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = WebInspectorProxy.messages.in; sourceTree = "<group>"; };
    24002405                1C891D6219B124FF00BA79DD /* WebInspectorUI.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebInspectorUI.cpp; sourceTree = "<group>"; };
     
    61426147                                1A3635AB1A3145E500ED6197 /* APIWebsiteDataStoreCocoa.mm */,
    61436148                                1AFDE64319510B5500C48FFA /* LegacyBundleForClass.mm */,
     6149                                1C20935E22318CB000026A39 /* NSAttributedString.h */,
     6150                                1C20935F22318CB000026A39 /* NSAttributedString.mm */,
     6151                                1C2184012233872800BAC700 /* NSAttributedStringPrivate.h */,
    61446152                                37C4C08B1814AC5C003688B9 /* WKBackForwardList.h */,
    61456153                                37C4C08A1814AC5C003688B9 /* WKBackForwardList.mm */,
     
    92949302                                1A2162B111F38971008AD0F5 /* NPRuntimeUtilities.h in Headers */,
    92959303                                1A2D84A3127F6AD1001EB962 /* NPVariantData.h in Headers */,
     9304                                1C20936022318CB000026A39 /* NSAttributedString.h in Headers */,
     9305                                1C2184022233872800BAC700 /* NSAttributedStringPrivate.h in Headers */,
    92969306                                3754D5451B3A29FD003A4C7F /* NSInvocationSPI.h in Headers */,
    92979307                                BC8ACA1316670D89004C1941 /* ObjCObjectGraph.h in Headers */,
  • trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm

    r243012 r243113  
    209209
    210210    RefPtr<Range> range = TextIterator::rangeFromLocationAndLength(frame.document()->documentElement(), 0, INT_MAX);
     211    if (!range) {
     212        completionHandler({ });
     213        return;
     214    }
    211215
    212216    NSDictionary* documentAttributes = nil;
Note: See TracChangeset for help on using the changeset viewer.