Changeset 225564 in webkit


Ignore:
Timestamp:
Dec 5, 2017 6:41:20 PM (6 years ago)
Author:
commit-queue@webkit.org
Message:

[Web App Manifest] Support fetching the app manifest
https://bugs.webkit.org/show_bug.cgi?id=180292

Patch by David Quesada <david_quesada@apple.com> on 2017-12-05
Reviewed by Geoffrey Garen.

Add support in WebCore for loading and parsing application manifests. This functionality
is currently exposed with two methods: DocumentLoader::loadApplicationManifest() to call
to start loading the manifest, and FrameLoaderClient::finishedLoadingApplicationManifest()
for clients to override in order to be notified of the loaded manifest.

No new tests, since no functionality is exposed to web content or embedders yet. The
needed SPI will be added in an upcoming patch.

  • Sources.txt:
  • WebCore.xcodeproj/project.pbxproj:

Added CachedApplicationManifest and ApplicationManifestLoader.

  • html/HTMLLinkElement.h:
  • html/LinkRelAttribute.cpp:

(WebCore::LinkRelAttribute::LinkRelAttribute):
(WebCore::LinkRelAttribute::isSupported):

Add "manifest" as a supported 'rel' type for links.

  • html/LinkRelAttribute.h:
  • inspector/agents/InspectorPageAgent.cpp:

(WebCore::InspectorPageAgent::resourceTypeJSON):
(WebCore::InspectorPageAgent::inspectorResourceType):

  • inspector/agents/InspectorPageAgent.h:
  • loader/ApplicationManifestLoader.cpp: Added.

Added a class ApplicationManifestLoader which handles creating a ResourceRequest,
loading the resource from the CachedResourceLoader, and parsing the resulting text.
This class and its relation to DocumentLoader are roughly based on that of IconLoader,
which serves a similar purpose - requesting a resource on the page and ultimately
providing it to the embedder.

(WebCore::ApplicationManifestLoader::ApplicationManifestLoader):
(WebCore::ApplicationManifestLoader::~ApplicationManifestLoader):
(WebCore::ApplicationManifestLoader::startLoading):
(WebCore::ApplicationManifestLoader::stopLoading):
(WebCore::ApplicationManifestLoader::processManifest):
(WebCore::ApplicationManifestLoader::notifyFinished):

  • loader/ApplicationManifestLoader.h: Copied from Source/WebCore/page/csp/ContentSecurityPolicyDirectiveNames.h.
  • loader/DocumentLoader.cpp:

(WebCore::DocumentLoader::stopLoading):
(WebCore::DocumentLoader::loadApplicationManifest):
(WebCore::DocumentLoader::finishedLoadingApplicationManifest):
(WebCore::DocumentLoader::notifyFinishedLoadingApplicationManifest):

  • loader/DocumentLoader.h:
  • loader/FrameLoaderClient.h:
  • loader/LinkLoader.cpp:

(WebCore::createLinkPreloadResourceClient):
(WebCore::LinkLoader::isSupportedType):

  • loader/ResourceLoadInfo.cpp:

(WebCore::toResourceType):

  • loader/SubresourceLoader.cpp:

(WebCore::logResourceLoaded):

  • loader/cache/CachedApplicationManifest.cpp: Added.

(WebCore::CachedApplicationManifest::CachedApplicationManifest):
(WebCore::CachedApplicationManifest::finishLoading):
(WebCore::CachedApplicationManifest::setEncoding):
(WebCore::CachedApplicationManifest::encoding const):
(WebCore::CachedApplicationManifest::process):

Add a method to process the fetched text into an ApplicationManifest. CachedApplicationManifest
does not store the resulting ApplicationManifest because the text of an application
manifest can yield a different ApplicationManifest depending on the URL of the document
processing it.

  • loader/cache/CachedApplicationManifest.h: Copied from Source/WebCore/page/csp/ContentSecurityPolicyDirectiveNames.h.
  • loader/cache/CachedResource.cpp:

(WebCore::CachedResource::defaultPriorityForResourceType):

  • loader/cache/CachedResource.h:
  • loader/cache/CachedResourceLoader.cpp:

(WebCore::createResource):
(WebCore::CachedResourceLoader::requestApplicationManifest):
(WebCore::contentTypeFromResourceType):
(WebCore::CachedResourceLoader::checkInsecureContent const):
(WebCore::CachedResourceLoader::allowedByContentSecurityPolicy const):

  • loader/cache/CachedResourceLoader.h:
  • page/DiagnosticLoggingKeys.cpp:

(WebCore::DiagnosticLoggingKeys::applicationManifestKey):

  • page/DiagnosticLoggingKeys.h:
  • page/csp/ContentSecurityPolicy.cpp:

(WebCore::ContentSecurityPolicy::allowManifestFromSource const):

  • page/csp/ContentSecurityPolicy.h:
  • page/csp/ContentSecurityPolicyDirectiveList.cpp:

(WebCore::ContentSecurityPolicyDirectiveList::violatedDirectiveForManifest const):
(WebCore::ContentSecurityPolicyDirectiveList::addDirective):

  • page/csp/ContentSecurityPolicyDirectiveList.h:
  • page/csp/ContentSecurityPolicyDirectiveNames.cpp:
  • page/csp/ContentSecurityPolicyDirectiveNames.h:
Location:
trunk/Source
Files:
2 added
27 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r225563 r225564  
     12017-12-05  David Quesada  <david_quesada@apple.com>
     2
     3        [Web App Manifest] Support fetching the app manifest
     4        https://bugs.webkit.org/show_bug.cgi?id=180292
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Add support in WebCore for loading and parsing application manifests. This functionality
     9        is currently exposed with two methods: DocumentLoader::loadApplicationManifest() to call
     10        to start loading the manifest, and FrameLoaderClient::finishedLoadingApplicationManifest()
     11        for clients to override in order to be notified of the loaded manifest.
     12
     13        No new tests, since no functionality is exposed to web content or embedders yet. The
     14        needed SPI will be added in an upcoming patch.
     15
     16        * Sources.txt:
     17        * WebCore.xcodeproj/project.pbxproj:
     18            Added CachedApplicationManifest and ApplicationManifestLoader.
     19        * html/HTMLLinkElement.h:
     20        * html/LinkRelAttribute.cpp:
     21        (WebCore::LinkRelAttribute::LinkRelAttribute):
     22        (WebCore::LinkRelAttribute::isSupported):
     23            Add "manifest" as a supported 'rel' type for links.
     24        * html/LinkRelAttribute.h:
     25        * inspector/agents/InspectorPageAgent.cpp:
     26        (WebCore::InspectorPageAgent::resourceTypeJSON):
     27        (WebCore::InspectorPageAgent::inspectorResourceType):
     28        * inspector/agents/InspectorPageAgent.h:
     29        * loader/ApplicationManifestLoader.cpp: Added.
     30            Added a class ApplicationManifestLoader which handles creating a ResourceRequest,
     31            loading the resource from the CachedResourceLoader, and parsing the resulting text.
     32            This class and its relation to DocumentLoader are roughly based on that of IconLoader,
     33            which serves a similar purpose - requesting a resource on the page and ultimately
     34            providing it to the embedder.
     35        (WebCore::ApplicationManifestLoader::ApplicationManifestLoader):
     36        (WebCore::ApplicationManifestLoader::~ApplicationManifestLoader):
     37        (WebCore::ApplicationManifestLoader::startLoading):
     38        (WebCore::ApplicationManifestLoader::stopLoading):
     39        (WebCore::ApplicationManifestLoader::processManifest):
     40        (WebCore::ApplicationManifestLoader::notifyFinished):
     41        * loader/ApplicationManifestLoader.h: Copied from Source/WebCore/page/csp/ContentSecurityPolicyDirectiveNames.h.
     42        * loader/DocumentLoader.cpp:
     43        (WebCore::DocumentLoader::stopLoading):
     44        (WebCore::DocumentLoader::loadApplicationManifest):
     45        (WebCore::DocumentLoader::finishedLoadingApplicationManifest):
     46        (WebCore::DocumentLoader::notifyFinishedLoadingApplicationManifest):
     47        * loader/DocumentLoader.h:
     48        * loader/FrameLoaderClient.h:
     49        * loader/LinkLoader.cpp:
     50        (WebCore::createLinkPreloadResourceClient):
     51        (WebCore::LinkLoader::isSupportedType):
     52        * loader/ResourceLoadInfo.cpp:
     53        (WebCore::toResourceType):
     54        * loader/SubresourceLoader.cpp:
     55        (WebCore::logResourceLoaded):
     56        * loader/cache/CachedApplicationManifest.cpp: Added.
     57        (WebCore::CachedApplicationManifest::CachedApplicationManifest):
     58        (WebCore::CachedApplicationManifest::finishLoading):
     59        (WebCore::CachedApplicationManifest::setEncoding):
     60        (WebCore::CachedApplicationManifest::encoding const):
     61        (WebCore::CachedApplicationManifest::process):
     62            Add a method to process the fetched text into an ApplicationManifest. CachedApplicationManifest
     63            does not store the resulting ApplicationManifest because the text of an application
     64            manifest can yield a different ApplicationManifest depending on the URL of the document
     65            processing it.
     66        * loader/cache/CachedApplicationManifest.h: Copied from Source/WebCore/page/csp/ContentSecurityPolicyDirectiveNames.h.
     67        * loader/cache/CachedResource.cpp:
     68        (WebCore::CachedResource::defaultPriorityForResourceType):
     69        * loader/cache/CachedResource.h:
     70        * loader/cache/CachedResourceLoader.cpp:
     71        (WebCore::createResource):
     72        (WebCore::CachedResourceLoader::requestApplicationManifest):
     73        (WebCore::contentTypeFromResourceType):
     74        (WebCore::CachedResourceLoader::checkInsecureContent const):
     75        (WebCore::CachedResourceLoader::allowedByContentSecurityPolicy const):
     76        * loader/cache/CachedResourceLoader.h:
     77        * page/DiagnosticLoggingKeys.cpp:
     78        (WebCore::DiagnosticLoggingKeys::applicationManifestKey):
     79        * page/DiagnosticLoggingKeys.h:
     80        * page/csp/ContentSecurityPolicy.cpp:
     81        (WebCore::ContentSecurityPolicy::allowManifestFromSource const):
     82        * page/csp/ContentSecurityPolicy.h:
     83        * page/csp/ContentSecurityPolicyDirectiveList.cpp:
     84        (WebCore::ContentSecurityPolicyDirectiveList::violatedDirectiveForManifest const):
     85        (WebCore::ContentSecurityPolicyDirectiveList::addDirective):
     86        * page/csp/ContentSecurityPolicyDirectiveList.h:
     87        * page/csp/ContentSecurityPolicyDirectiveNames.cpp:
     88        * page/csp/ContentSecurityPolicyDirectiveNames.h:
     89
    1902017-12-05  Stephan Szabo  <stephan.szabo@sony.com>
    291
  • trunk/Source/WebCore/Sources.txt

    r225555 r225564  
    2727
    2828Modules/applicationmanifest/ApplicationManifestParser.cpp
     29
     30loader/ApplicationManifestLoader.cpp
     31
     32loader/cache/CachedApplicationManifest.cpp
    2933
    3034#endif
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r225555 r225564  
    17521752                62C1217D11AB9E77003C462C /* SuspendableTimer.h in Headers */ = {isa = PBXBuildFile; fileRef = 62C1217B11AB9E77003C462C /* SuspendableTimer.h */; settings = {ATTRIBUTES = (Private, ); }; };
    17531753                62CD325A1157E57C0063B0A7 /* CustomEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 62CD32571157E57C0063B0A7 /* CustomEvent.h */; };
     1754                63152D191F9531EE007A5E4B /* ApplicationManifestLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 63152D171F9531EE007A5E4B /* ApplicationManifestLoader.h */; };
    17541755                63189AE30E83A33300012E41 /* NodeRareData.h in Headers */ = {isa = PBXBuildFile; fileRef = 63189AE20E83A33300012E41 /* NodeRareData.h */; settings = {ATTRIBUTES = (); }; };
     1756                6353E1E61F91743100A34208 /* CachedApplicationManifest.h in Headers */ = {isa = PBXBuildFile; fileRef = 6353E1E41F91743100A34208 /* CachedApplicationManifest.h */; settings = {ATTRIBUTES = (Private, ); }; };
    17551757                6354F4C91F7AFC9400D89DF3 /* ApplicationManifestParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 6354F4C71F7AFC9400D89DF3 /* ApplicationManifestParser.h */; settings = {ATTRIBUTES = (Private, ); }; };
    17561758                63BD4A5F1F778E9F00438722 /* ApplicationManifest.h in Headers */ = {isa = PBXBuildFile; fileRef = 63BD4A5D1F778E9F00438722 /* ApplicationManifest.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    83838385                62CD32571157E57C0063B0A7 /* CustomEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomEvent.h; sourceTree = "<group>"; };
    83848386                62CD32581157E57C0063B0A7 /* CustomEvent.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CustomEvent.idl; sourceTree = "<group>"; };
     8387                63152D171F9531EE007A5E4B /* ApplicationManifestLoader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ApplicationManifestLoader.h; sourceTree = "<group>"; };
     8388                63152D181F9531EE007A5E4B /* ApplicationManifestLoader.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ApplicationManifestLoader.cpp; sourceTree = "<group>"; };
    83858389                63189AE20E83A33300012E41 /* NodeRareData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NodeRareData.h; sourceTree = "<group>"; };
     8390                6353E1E41F91743100A34208 /* CachedApplicationManifest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CachedApplicationManifest.h; sourceTree = "<group>"; };
     8391                6353E1E51F91743100A34208 /* CachedApplicationManifest.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = CachedApplicationManifest.cpp; sourceTree = "<group>"; };
    83868392                6354F4C71F7AFC9400D89DF3 /* ApplicationManifestParser.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ApplicationManifestParser.h; sourceTree = "<group>"; };
    83878393                6354F4C81F7AFC9400D89DF3 /* ApplicationManifestParser.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ApplicationManifestParser.cpp; sourceTree = "<group>"; };
     
    2178921795                        isa = PBXGroup;
    2179021796                        children = (
     21797                                6353E1E51F91743100A34208 /* CachedApplicationManifest.cpp */,
     21798                                6353E1E41F91743100A34208 /* CachedApplicationManifest.h */,
    2179121799                                BCB16C000979C3BD00467741 /* CachedCSSStyleSheet.cpp */,
    2179221800                                BCB16C010979C3BD00467741 /* CachedCSSStyleSheet.h */,
     
    2330023308                                A15E31F01E0CB075004B371C /* ios */,
    2330123309                                93A1EAA20A5634D8006960A0 /* mac */,
     23310                                63152D181F9531EE007A5E4B /* ApplicationManifestLoader.cpp */,
     23311                                63152D171F9531EE007A5E4B /* ApplicationManifestLoader.h */,
    2330223312                                A149786C1ABAF33800CEF7E4 /* ContentFilter.cpp */,
    2330323313                                A149786D1ABAF33800CEF7E4 /* ContentFilter.h */,
     
    2608126091                                1A2AAC590DC2A3B100A20D9A /* ApplicationCacheStorage.h in Headers */,
    2608226092                                63BD4A5F1F778E9F00438722 /* ApplicationManifest.h in Headers */,
     26093                                63152D191F9531EE007A5E4B /* ApplicationManifestLoader.h in Headers */,
    2608326094                                6354F4C91F7AFC9400D89DF3 /* ApplicationManifestParser.h in Headers */,
    2608426095                                9B417064125662B3006B28FC /* ApplyBlockElementCommand.h in Headers */,
     
    2622126232                                1A569CFE0D7E2B82007C3983 /* c_utility.h in Headers */,
    2622226233                                07C046C41E42508B007201E7 /* CAAudioStreamDescription.h in Headers */,
     26234                                6353E1E61F91743100A34208 /* CachedApplicationManifest.h in Headers */,
    2622326235                                BCB16C1A0979C3BD00467741 /* CachedCSSStyleSheet.h in Headers */,
    2622426236                                BC64B4CC0CB4295D005F2B62 /* CachedFont.h in Headers */,
  • trunk/Source/WebCore/html/HTMLLinkElement.h

    r223802 r225564  
    7474    WEBCORE_EXPORT DOMTokenList& relList();
    7575
     76#if ENABLE(APPLICATION_MANIFEST)
     77    bool isApplicationManifest() const { return m_relAttribute.isApplicationManifest; }
     78#endif
     79
    7680private:
    7781    void parseAttribute(const QualifiedName&, const AtomicString&) final;
  • trunk/Source/WebCore/html/LinkRelAttribute.cpp

    r222613 r225564  
    6666        isStyleSheet = true;
    6767        isAlternate = true;
     68#if ENABLE(APPLICATION_MANIFEST)
     69    } else if (equalLettersIgnoringASCIICase(rel, "manifest")) {
     70        isApplicationManifest = true;
     71#endif
    6872    } else {
    6973        // Tokenize the rel attribute and set bits based on specific keywords that we find.
     
    99103        "prefetch", "subresource",
    100104#endif
     105#if ENABLE(APPLICATION_MANIFEST)
     106        "manifest",
     107#endif
    101108    };
    102109
  • trunk/Source/WebCore/html/LinkRelAttribute.h

    r222613 r225564  
    5252    bool isLinkSubresource { false };
    5353#endif
     54#if ENABLE(APPLICATION_MANIFEST)
     55    bool isApplicationManifest { false };
     56#endif
    5457
    5558    LinkRelAttribute();
  • trunk/Source/WebCore/inspector/agents/InspectorPageAgent.cpp

    r225546 r225564  
    7171#include <yarr/RegularExpression.h>
    7272
     73#if ENABLE(APPLICATION_MANIFEST)
     74#include "CachedApplicationManifest.h"
     75#endif
     76
    7377#if ENABLE(WEB_ARCHIVE) && USE(CF)
    7478#include "LegacyWebArchive.h"
     
    205209    case OtherResource:
    206210        return Inspector::Protocol::Page::ResourceType::Other;
     211#if ENABLE(APPLICATION_MANIFEST)
     212    case ApplicationManifestResource:
     213        break;
     214#endif
    207215    }
    208216    return Inspector::Protocol::Page::ResourceType::Other;
     
    230238    case CachedResource::Beacon:
    231239        return InspectorPageAgent::BeaconResource;
     240#if ENABLE(APPLICATION_MANIFEST)
     241    case CachedResource::ApplicationManifest:
     242        return InspectorPageAgent::ApplicationManifestResource;
     243#endif
    232244    case CachedResource::MediaResource:
    233245    case CachedResource::Icon:
  • trunk/Source/WebCore/inspector/agents/InspectorPageAgent.h

    r225546 r225564  
    7272        BeaconResource,
    7373        WebSocketResource,
     74#if ENABLE(APPLICATION_MANIFEST)
     75        ApplicationManifestResource,
     76#endif
    7477        OtherResource,
    7578    };
  • trunk/Source/WebCore/loader/ApplicationManifestLoader.h

    r225563 r225564  
    11/*
    2  * Copyright (C) 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2626#pragma once
    2727
     28#if ENABLE(APPLICATION_MANIFEST)
     29
     30#include "ApplicationManifest.h"
     31#include "CachedRawResourceClient.h"
     32#include "CachedResourceHandle.h"
     33#include "URL.h"
     34#include <wtf/Noncopyable.h>
     35
    2836namespace WebCore {
    2937
    30 namespace ContentSecurityPolicyDirectiveNames {
     38class CachedApplicationManifest;
     39class DocumentLoader;
    3140
    32 extern const char* const baseURI;
    33 extern const char* const childSrc;
    34 extern const char* const connectSrc;
    35 extern const char* const defaultSrc;
    36 extern const char* const fontSrc;
    37 extern const char* const formAction;
    38 extern const char* const frameAncestors;
    39 extern const char* const frameSrc;
    40 extern const char* const imgSrc;
    41 extern const char* const mediaSrc;
    42 extern const char* const objectSrc;
    43 extern const char* const pluginTypes;
    44 extern const char* const reportURI;
    45 extern const char* const sandbox;
    46 extern const char* const scriptSrc;
    47 extern const char* const styleSrc;
    48 extern const char* const upgradeInsecureRequests;
    49 extern const char* const blockAllMixedContent;
     41class ApplicationManifestLoader final : private CachedRawResourceClient {
     42WTF_MAKE_NONCOPYABLE(ApplicationManifestLoader); WTF_MAKE_FAST_ALLOCATED;
     43public:
     44    typedef WTF::Function<void (CachedResourceHandle<CachedApplicationManifest>)> CompletionHandlerType;
    5045
    51 } // namespace ContentSecurityPolicyDirectiveNames
     46    ApplicationManifestLoader(DocumentLoader&, const URL&, bool);
     47    virtual ~ApplicationManifestLoader();
     48
     49    bool startLoading();
     50    void stopLoading();
     51
     52    std::optional<ApplicationManifest>& processManifest();
     53
     54private:
     55    void notifyFinished(CachedResource&);
     56
     57    DocumentLoader& m_documentLoader;
     58    std::optional<ApplicationManifest> m_processedManifest;
     59    URL m_url;
     60    bool m_useCredentials;
     61    CachedResourceHandle<CachedApplicationManifest> m_resource;
     62};
    5263
    5364} // namespace WebCore
    5465
     66#endif // ENABLE(APPLICATION_MANIFEST)
  • trunk/Source/WebCore/loader/DocumentLoader.cpp

    r225526 r225564  
    8585#include <wtf/text/WTFString.h>
    8686
     87#if ENABLE(APPLICATION_MANIFEST)
     88#include "ApplicationManifestLoader.h"
     89#include "HTMLHeadElement.h"
     90#include "HTMLLinkElement.h"
     91#endif
     92
    8793#if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
    8894#include "ArchiveFactory.h"
     
    282288    m_iconLoaders.clear();
    283289    m_iconsPendingLoadDecision.clear();
     290   
     291#if ENABLE(APPLICATION_MANIFEST)
     292    for (auto callbackIdentifier : m_applicationManifestLoaders.values())
     293        notifyFinishedLoadingApplicationManifest(callbackIdentifier, std::nullopt);
     294    m_applicationManifestLoaders.clear();
     295#endif
    284296
    285297    // Always cancel multipart loaders
     
    10451057        checkLoadComplete();
    10461058}
     1059
     1060#if ENABLE(APPLICATION_MANIFEST)
     1061uint64_t DocumentLoader::loadApplicationManifest()
     1062{
     1063    static uint64_t nextCallbackID = 1;
     1064
     1065    auto* document = this->document();
     1066    if (!document)
     1067        return 0;
     1068
     1069    if (!m_frame->isMainFrame())
     1070        return 0;
     1071
     1072    if (document->url().isEmpty() || document->url().isBlankURL())
     1073        return 0;
     1074
     1075    auto head = document->head();
     1076    if (!head)
     1077        return 0;
     1078
     1079    URL manifestURL;
     1080    bool useCredentials = false;
     1081    for (const auto& link : childrenOfType<HTMLLinkElement>(*head)) {
     1082        if (link.isApplicationManifest()) {
     1083            manifestURL = link.href();
     1084            useCredentials = equalIgnoringASCIICase(link.attributeWithoutSynchronization(HTMLNames::crossoriginAttr), "use-credentials");
     1085            break;
     1086        }
     1087    }
     1088
     1089    if (manifestURL.isEmpty() || !manifestURL.isValid())
     1090        return 0;
     1091
     1092    auto manifestLoader = std::make_unique<ApplicationManifestLoader>(*this, manifestURL, useCredentials);
     1093    auto* rawManifestLoader = manifestLoader.get();
     1094    auto callbackID = nextCallbackID++;
     1095    m_applicationManifestLoaders.set(WTFMove(manifestLoader), callbackID);
     1096
     1097    if (!rawManifestLoader->startLoading()) {
     1098        m_applicationManifestLoaders.remove(rawManifestLoader);
     1099        return 0;
     1100    }
     1101
     1102    return callbackID;
     1103}
     1104
     1105void DocumentLoader::finishedLoadingApplicationManifest(ApplicationManifestLoader& loader)
     1106{
     1107    // If the DocumentLoader has detached from its frame, all manifest loads should have already been canceled.
     1108    ASSERT(m_frame);
     1109
     1110    auto callbackIdentifier = m_applicationManifestLoaders.get(&loader);
     1111    notifyFinishedLoadingApplicationManifest(callbackIdentifier, loader.processManifest());
     1112    m_applicationManifestLoaders.remove(&loader);
     1113}
     1114
     1115void DocumentLoader::notifyFinishedLoadingApplicationManifest(uint64_t callbackIdentifier, std::optional<ApplicationManifest> manifest)
     1116{
     1117    RELEASE_ASSERT(callbackIdentifier);
     1118    RELEASE_ASSERT(m_frame);
     1119    m_frame->loader().client().finishedLoadingApplicationManifest(callbackIdentifier, manifest);
     1120}
     1121#endif
    10471122
    10481123void DocumentLoader::setCustomHeaderFields(Vector<HTTPHeaderField>&& fields)
  • trunk/Source/WebCore/loader/DocumentLoader.h

    r224852 r225564  
    5151#include <wtf/Vector.h>
    5252
     53#if ENABLE(APPLICATION_MANIFEST)
     54#include "ApplicationManifest.h"
     55#endif
     56
    5357#if HAVE(RUNLOOP_TIMER)
    5458#include <wtf/RunLoopTimer.h>
     
    6266
    6367class ApplicationCacheHost;
     68class ApplicationManifestLoader;
    6469class Archive;
    6570class ArchiveResource;
     
    298303    const Vector<LinkIcon>& linkIcons() const { return m_linkIcons; }
    299304
     305#if ENABLE(APPLICATION_MANIFEST)
     306    WEBCORE_EXPORT uint64_t loadApplicationManifest();
     307    void finishedLoadingApplicationManifest(ApplicationManifestLoader&);
     308#endif
     309
    300310    WEBCORE_EXPORT void setCustomHeaderFields(Vector<HTTPHeaderField>&& fields);
    301311    const Vector<HTTPHeaderField>& customHeaderFields() { return m_customHeaderFields; }
     
    371381    void notifyFinishedLoadingIcon(uint64_t callbackIdentifier, SharedBuffer*);
    372382
     383#if ENABLE(APPLICATION_MANIFEST)
     384    void notifyFinishedLoadingApplicationManifest(uint64_t callbackIdentifier, std::optional<ApplicationManifest>);
     385#endif
     386
    373387    Ref<CachedResourceLoader> m_cachedResourceLoader;
    374388
     
    460474    Vector<LinkIcon> m_linkIcons;
    461475
     476#if ENABLE(APPLICATION_MANIFEST)
     477    HashMap<std::unique_ptr<ApplicationManifestLoader>, uint64_t> m_applicationManifestLoaders;
     478#endif
     479
    462480    Vector<HTTPHeaderField> m_customHeaderFields;
    463481   
  • trunk/Source/WebCore/loader/FrameLoaderClient.h

    r224846 r225564  
    3636#include <wtf/Forward.h>
    3737#include <wtf/text/WTFString.h>
     38
     39#if ENABLE(APPLICATION_MANIFEST)
     40#include "ApplicationManifest.h"
     41#endif
    3842
    3943#if ENABLE(CONTENT_FILTERING)
     
    357361    virtual void getLoadDecisionForIcons(const Vector<std::pair<WebCore::LinkIcon&, uint64_t>>&) { }
    358362    virtual void finishedLoadingIcon(uint64_t, SharedBuffer*) { }
     363
     364#if ENABLE(APPLICATION_MANIFEST)
     365    virtual void finishedLoadingApplicationManifest(uint64_t, const std::optional<ApplicationManifest>&) { }
     366#endif
    359367};
    360368
  • trunk/Source/WebCore/loader/LinkLoader.cpp

    r225499 r225564  
    172172        // None of these values is currently supported as an `as` value.
    173173        ASSERT_NOT_REACHED();
     174#if ENABLE(APPLICATION_MANIFEST)
     175    case CachedResource::ApplicationManifest:
     176        // FIXME: Support preloading the manifest.
     177        ASSERT_NOT_REACHED();
     178#endif
    174179    }
    175180    return nullptr;
     
    199204#endif
    200205    case CachedResource::RawResource:
     206#if ENABLE(APPLICATION_MANIFEST)
     207    case CachedResource::ApplicationManifest:
     208#endif
    201209        return true;
    202210    default:
  • trunk/Source/WebCore/loader/ResourceLoadInfo.cpp

    r220303 r225564  
    7171        ASSERT_NOT_REACHED();
    7272#endif
     73#if ENABLE(APPLICATION_MANIFEST)
     74    case CachedResource::ApplicationManifest:
     75        return ResourceType::Raw;
     76#endif
    7377    };
    7478    return ResourceType::Raw;
  • trunk/Source/WebCore/loader/SubresourceLoader.cpp

    r224699 r225564  
    472472        resourceType = DiagnosticLoggingKeys::svgDocumentKey();
    473473        break;
     474#if ENABLE(APPLICATION_MANIFEST)
     475    case CachedResource::ApplicationManifest:
     476        resourceType = DiagnosticLoggingKeys::applicationManifestKey();
     477        break;
     478#endif
    474479#if ENABLE(LINK_PREFETCH)
    475480    case CachedResource::LinkPrefetch:
  • trunk/Source/WebCore/loader/cache/CachedApplicationManifest.h

    r225563 r225564  
    11/*
    2  * Copyright (C) 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2017 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2626#pragma once
    2727
     28#if ENABLE(APPLICATION_MANIFEST)
     29
     30#include "ApplicationManifest.h"
     31#include "CachedResource.h"
     32#include <wtf/Optional.h>
     33
    2834namespace WebCore {
    2935
    30 namespace ContentSecurityPolicyDirectiveNames {
     36class ScriptExecutionContext;
     37class TextResourceDecoder;
    3138
    32 extern const char* const baseURI;
    33 extern const char* const childSrc;
    34 extern const char* const connectSrc;
    35 extern const char* const defaultSrc;
    36 extern const char* const fontSrc;
    37 extern const char* const formAction;
    38 extern const char* const frameAncestors;
    39 extern const char* const frameSrc;
    40 extern const char* const imgSrc;
    41 extern const char* const mediaSrc;
    42 extern const char* const objectSrc;
    43 extern const char* const pluginTypes;
    44 extern const char* const reportURI;
    45 extern const char* const sandbox;
    46 extern const char* const scriptSrc;
    47 extern const char* const styleSrc;
    48 extern const char* const upgradeInsecureRequests;
    49 extern const char* const blockAllMixedContent;
     39class CachedApplicationManifest final : public CachedResource {
     40public:
     41    CachedApplicationManifest(CachedResourceRequest&&, PAL::SessionID);
    5042
    51 } // namespace ContentSecurityPolicyDirectiveNames
     43    std::optional<struct ApplicationManifest> process(const URL& manifestURL, const URL& documentURL, RefPtr<ScriptExecutionContext> = nullptr);
     44
     45private:
     46    void finishLoading(SharedBuffer*) override;
     47    const TextResourceDecoder* textResourceDecoder() const override { return m_decoder.ptr(); }
     48    void setEncoding(const String&) override;
     49    String encoding() const override;
     50
     51    Ref<TextResourceDecoder> m_decoder;
     52    std::optional<String> m_text;
     53};
    5254
    5355} // namespace WebCore
    5456
     57SPECIALIZE_TYPE_TRAITS_CACHED_RESOURCE(CachedApplicationManifest, CachedResource::ApplicationManifest)
     58
     59#endif // ENABLE(APPLICATION_MANIFEST)
  • trunk/Source/WebCore/loader/cache/CachedResource.cpp

    r224699 r225564  
    103103        return ResourceLoadPriority::Low;
    104104#endif
     105#if ENABLE(APPLICATION_MANIFEST)
     106    case CachedResource::ApplicationManifest:
     107        return ResourceLoadPriority::Low;
     108#endif
    105109    }
    106110    ASSERT_NOT_REACHED();
  • trunk/Source/WebCore/loader/cache/CachedResource.h

    r224699 r225564  
    8585        , TextTrackResource
    8686#endif
     87#if ENABLE(APPLICATION_MANIFEST)
     88        , ApplicationManifest
     89#endif
    8790    };
    8891
  • trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp

    r225294 r225564  
    7878#include <wtf/text/WTFString.h>
    7979
     80#if ENABLE(APPLICATION_MANIFEST)
     81#include "CachedApplicationManifest.h"
     82#endif
     83
    8084#if ENABLE(VIDEO_TRACK)
    8185#include "CachedTextTrack.h"
     
    135139        return new CachedTextTrack(WTFMove(request), sessionID);
    136140#endif
     141#if ENABLE(APPLICATION_MANIFEST)
     142    case CachedResource::ApplicationManifest:
     143        return new CachedApplicationManifest(WTFMove(request), sessionID);
     144#endif
    137145    }
    138146    ASSERT_NOT_REACHED();
     
    323331}
    324332
     333#if ENABLE(APPLICATION_MANIFEST)
     334ResourceErrorOr<CachedResourceHandle<CachedApplicationManifest>> CachedResourceLoader::requestApplicationManifest(CachedResourceRequest&& request)
     335{
     336    return castCachedResourceTo<CachedApplicationManifest>(requestResource(CachedResource::ApplicationManifest, WTFMove(request)));
     337}
     338#endif // ENABLE(APPLICATION_MANIFEST)
     339
    325340static MixedContentChecker::ContentType contentTypeFromResourceType(CachedResource::Type type)
    326341{
     
    361376#if ENABLE(VIDEO_TRACK)
    362377    case CachedResource::TextTrackResource:
     378        return MixedContentChecker::ContentType::Active;
     379#endif
     380#if ENABLE(APPLICATION_MANIFEST)
     381    case CachedResource::ApplicationManifest:
    363382        return MixedContentChecker::ContentType::Active;
    364383#endif
     
    419438        // Prefetch cannot affect the current document.
    420439#endif
     440#if ENABLE(APPLICATION_MANIFEST)
     441    case CachedResource::ApplicationManifest:
     442#endif
    421443        break;
    422444    }
     
    467489    case CachedResource::RawResource:
    468490        return true;
     491#if ENABLE(APPLICATION_MANIFEST)
     492    case CachedResource::ApplicationManifest:
     493        if (!m_document->contentSecurityPolicy()->allowManifestFromSource(url, redirectResponseReceived))
     494            return false;
     495        break;
     496#endif
    469497    default:
    470498        ASSERT_NOT_REACHED();
  • trunk/Source/WebCore/loader/cache/CachedResourceLoader.h

    r220946 r225564  
    4242namespace WebCore {
    4343
     44#if ENABLE(APPLICATION_MANIFEST)
     45class CachedApplicationManifest;
     46#endif
    4447class CachedCSSStyleSheet;
    4548class CachedSVGDocument;
     
    9699#if ENABLE(VIDEO_TRACK)
    97100    ResourceErrorOr<CachedResourceHandle<CachedTextTrack>> requestTextTrack(CachedResourceRequest&&);
     101#endif
     102#if ENABLE(APPLICATION_MANIFEST)
     103    ResourceErrorOr<CachedResourceHandle<CachedApplicationManifest>> requestApplicationManifest(CachedResourceRequest&&);
    98104#endif
    99105
  • trunk/Source/WebCore/page/DiagnosticLoggingKeys.cpp

    r223785 r225564  
    414414}
    415415
     416#if ENABLE(APPLICATION_MANIFEST)
     417String DiagnosticLoggingKeys::applicationManifestKey()
     418{
     419    return ASCIILiteral("applicationManifest");
     420}
     421#endif
     422
    416423String DiagnosticLoggingKeys::audioKey()
    417424{
  • trunk/Source/WebCore/page/DiagnosticLoggingKeys.h

    r223785 r225564  
    3535    WEBCORE_EXPORT static String activeInBackgroundTabOnlyKey();
    3636    static String applicationCacheKey();
     37#if ENABLE(APPLICATION_MANIFEST)
     38    static String applicationManifestKey();
     39#endif
    3740    static String audioKey();
    3841    WEBCORE_EXPORT static String backNavigationDeltaKey();
  • trunk/Source/WebCore/page/csp/ContentSecurityPolicy.cpp

    r225231 r225564  
    550550}
    551551
     552#if ENABLE(APPLICATION_MANIFEST)
     553bool ContentSecurityPolicy::allowManifestFromSource(const URL& url, RedirectResponseReceived redirectResponseReceived) const
     554{
     555    return allowResourceFromSource(url, redirectResponseReceived, ContentSecurityPolicyDirectiveNames::manifestSrc, &ContentSecurityPolicyDirectiveList::violatedDirectiveForManifest);
     556}
     557#endif // ENABLE(APPLICATION_MANIFEST)
     558
    552559bool ContentSecurityPolicy::allowMediaFromSource(const URL& url, RedirectResponseReceived redirectResponseReceived) const
    553560{
  • trunk/Source/WebCore/page/csp/ContentSecurityPolicy.h

    r220549 r225564  
    104104    bool allowStyleFromSource(const URL&, RedirectResponseReceived = RedirectResponseReceived::No) const;
    105105    bool allowFontFromSource(const URL&, RedirectResponseReceived = RedirectResponseReceived::No) const;
     106#if ENABLE(APPLICATION_MANIFEST)
     107    bool allowManifestFromSource(const URL&, RedirectResponseReceived = RedirectResponseReceived::No) const;
     108#endif
    106109    bool allowMediaFromSource(const URL&, RedirectResponseReceived = RedirectResponseReceived::No) const;
    107110
  • trunk/Source/WebCore/page/csp/ContentSecurityPolicyDirectiveList.cpp

    r223476 r225564  
    244244}
    245245
     246#if ENABLE(APPLICATION_MANIFEST)
     247const ContentSecurityPolicyDirective* ContentSecurityPolicyDirectiveList::violatedDirectiveForManifest(const URL& url, bool didReceiveRedirectResponse) const
     248{
     249    ContentSecurityPolicySourceListDirective* operativeDirective = this->operativeDirective(m_manifestSrc.get());
     250    if (checkSource(operativeDirective, url, didReceiveRedirectResponse))
     251        return nullptr;
     252    return operativeDirective;
     253}
     254#endif // ENABLE(APPLICATION_MANIFEST)
     255
    246256const ContentSecurityPolicyDirective* ContentSecurityPolicyDirectiveList::violatedDirectiveForMedia(const URL& url, bool didReceiveRedirectResponse) const
    247257{
     
    476486    else if (equalIgnoringASCIICase(name, ContentSecurityPolicyDirectiveNames::fontSrc))
    477487        setCSPDirective<ContentSecurityPolicySourceListDirective>(name, value, m_fontSrc);
     488#if ENABLE(APPLICATION_MANIFEST)
     489    else if (equalIgnoringASCIICase(name, ContentSecurityPolicyDirectiveNames::manifestSrc))
     490        setCSPDirective<ContentSecurityPolicySourceListDirective>(name, value, m_manifestSrc);
     491#endif
    478492    else if (equalIgnoringASCIICase(name, ContentSecurityPolicyDirectiveNames::mediaSrc))
    479493        setCSPDirective<ContentSecurityPolicySourceListDirective>(name, value, m_mediaSrc);
  • trunk/Source/WebCore/page/csp/ContentSecurityPolicyDirectiveList.h

    r218951 r225564  
    6464    const ContentSecurityPolicyDirective* violatedDirectiveForFrameAncestor(const Frame&) const;
    6565    const ContentSecurityPolicyDirective* violatedDirectiveForImage(const URL&, bool didReceiveRedirectResponse) const;
     66#if ENABLE(APPLICATION_MANIFEST)
     67    const ContentSecurityPolicyDirective* violatedDirectiveForManifest(const URL&, bool didReceiveRedirectResponse) const;
     68#endif
    6669    const ContentSecurityPolicyDirective* violatedDirectiveForMedia(const URL&, bool didReceiveRedirectResponse) const;
    6770    const ContentSecurityPolicyDirective* violatedDirectiveForObjectSource(const URL&, bool didReceiveRedirectResponse, ContentSecurityPolicySourceListDirective::ShouldAllowEmptyURLIfSourceListIsNotNone) const;
     
    122125    std::unique_ptr<ContentSecurityPolicySourceListDirective> m_frameSrc;
    123126    std::unique_ptr<ContentSecurityPolicySourceListDirective> m_imgSrc;
     127#if ENABLE(APPLICATION_MANIFEST)
     128    std::unique_ptr<ContentSecurityPolicySourceListDirective> m_manifestSrc;
     129#endif
    124130    std::unique_ptr<ContentSecurityPolicySourceListDirective> m_mediaSrc;
    125131    std::unique_ptr<ContentSecurityPolicySourceListDirective> m_objectSrc;
  • trunk/Source/WebCore/page/csp/ContentSecurityPolicyDirectiveNames.cpp

    r209577 r225564  
    3939const char* const frameAncestors = "frame-ancestors";
    4040const char* const frameSrc = "frame-src";
     41#if ENABLE(APPLICATION_MANIFEST)
     42const char* const manifestSrc = "manifest-src";
     43#endif
    4144const char* const imgSrc = "img-src";
    4245const char* const mediaSrc = "media-src";
  • trunk/Source/WebCore/page/csp/ContentSecurityPolicyDirectiveNames.h

    r209577 r225564  
    3939extern const char* const frameSrc;
    4040extern const char* const imgSrc;
     41#if ENABLE(APPLICATION_MANIFEST)
     42extern const char* const manifestSrc;
     43#endif
    4144extern const char* const mediaSrc;
    4245extern const char* const objectSrc;
  • trunk/Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp

    r225297 r225564  
    122122#endif
    123123    case CachedResource::FontResource:
     124#if ENABLE(APPLICATION_MANIFEST)
     125    case CachedResource::ApplicationManifest:
     126#endif
    124127        return Seconds::infinity();
    125128    case CachedResource::ImageResource:
Note: See TracChangeset for help on using the changeset viewer.