Changeset 226088 in webkit


Ignore:
Timestamp:
Dec 18, 2017 5:16:57 PM (6 years ago)
Author:
beidson@apple.com
Message:

Add ability to API test Service Workers via a custom protocol.
https://bugs.webkit.org/show_bug.cgi?id=180911

Reviewed by Chris Dumez.

Source/WebCore:

Covered by API test ServiceWorkers.Basic

This adds a set of "Service Workers can handle this" schemes to the scheme registry
and uses it for SW decisions instead of a handful of previous techniques.

  • bindings/scripts/CodeGeneratorJS.pm:

(NeedsRuntimeCheck):
(GenerateRuntimeEnableConditionalString):

  • bindings/scripts/IDLAttributes.json:
  • dom/ScriptExecutionContext.cpp:

(WebCore::ScriptExecutionContext::hasServiceWorkerScheme):

  • dom/ScriptExecutionContext.h:
  • page/NavigatorServiceWorker.idl:
  • platform/SchemeRegistry.cpp:

(WebCore::serviceWorkerSchemesLock):
(WebCore::serviceWorkerSchemes):
(WebCore::SchemeRegistry::registerURLSchemeServiceWorkersCanHandle):
(WebCore::SchemeRegistry::canServiceWorkersHandleURLScheme):
(WebCore::SchemeRegistry::isServiceWorkerContainerCustomScheme):

  • platform/SchemeRegistry.h:
  • workers/service/ServiceWorkerContainer.cpp:

(WebCore::ServiceWorkerContainer::addRegistration):

  • workers/service/server/SWServerJobQueue.cpp:

(WebCore::SWServerJobQueue::runRegisterJob):

Source/WebKit:

This adds a set of "Service Workers can handle this" schemes to the scheme registry
and most of these WebKit changes are to support getting those values out to all processes.

Additionally, WebsiteDataRecords used to be file/http(s)-only. That seems bizarre and definitely
got in the way of testing. So I also added a way to allow any scheme to result in a valid record.

  • Shared/ChildProcess.cpp:

(WebKit::ChildProcess::registerURLSchemeServiceWorkersCanHandle const):

  • Shared/ChildProcess.h:
  • Shared/ChildProcess.messages.in:
  • Shared/Storage/StorageProcessCreationParameters.cpp:

(WebKit::StorageProcessCreationParameters::encode const):
(WebKit::StorageProcessCreationParameters::decode):

  • Shared/Storage/StorageProcessCreationParameters.h:
  • Shared/WebProcessCreationParameters.cpp:

(WebKit::WebProcessCreationParameters::encode const):
(WebKit::WebProcessCreationParameters::decode):

  • Shared/WebProcessCreationParameters.h:
  • StorageProcess/StorageProcess.cpp:

(WebKit::StorageProcess::initializeWebsiteDataStore):

  • UIProcess/API/Cocoa/WKProcessPool.mm:

(-[WKProcessPool _registerURLSchemeServiceWorkersCanHandle:]):

  • UIProcess/API/Cocoa/WKProcessPoolPrivate.h:
  • UIProcess/API/Cocoa/WKWebsiteDataStore.mm:

(+[WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins]):

  • UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
  • UIProcess/WebProcessPool.cpp:

(WebKit::WebProcessPool::ensureStorageProcessAndWebsiteDataStore):
(WebKit::WebProcessPool::initializeNewWebProcess):
(WebKit::WebProcessPool::registerURLSchemeServiceWorkersCanHandle):

  • UIProcess/WebProcessPool.h:
  • UIProcess/WebsiteData/WebsiteDataStore.cpp:

(WebKit::WebsiteDataStore::allowWebsiteDataRecordsForAllOrigins):
(WebKit::WebsiteDataStore::fetchDataAndApply):

  • UIProcess/WebsiteData/WebsiteDataStore.h:
  • WebProcess/Storage/WebServiceWorkerProvider.cpp:

(WebKit::WebServiceWorkerProvider::handleFetch):

  • WebProcess/WebProcess.cpp:

(WebKit::WebProcess::initializeWebProcess):

Tools:

Adds a very basic SW test:

  • Verify WebsiteDataStore can wipe all SW registration data.
  • Fire up a web page with a service worker
  • Verify SW registration data for that page exists in the WebsiteDataStore.
  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm: Added.
Location:
trunk
Files:
1 added
31 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r226087 r226088  
     12017-12-18  Brady Eidson  <beidson@apple.com>
     2
     3        Add ability to API test Service Workers via a custom protocol.
     4        https://bugs.webkit.org/show_bug.cgi?id=180911
     5
     6        Reviewed by Chris Dumez.
     7
     8        Covered by API test ServiceWorkers.Basic
     9
     10        This adds a set of "Service Workers can handle this" schemes to the scheme registry
     11        and uses it for SW decisions instead of a handful of previous techniques.
     12
     13        * bindings/scripts/CodeGeneratorJS.pm:
     14        (NeedsRuntimeCheck):
     15        (GenerateRuntimeEnableConditionalString):
     16        * bindings/scripts/IDLAttributes.json:
     17
     18        * dom/ScriptExecutionContext.cpp:
     19        (WebCore::ScriptExecutionContext::hasServiceWorkerScheme):
     20        * dom/ScriptExecutionContext.h:
     21
     22        * page/NavigatorServiceWorker.idl:
     23
     24        * platform/SchemeRegistry.cpp:
     25        (WebCore::serviceWorkerSchemesLock):
     26        (WebCore::serviceWorkerSchemes):
     27        (WebCore::SchemeRegistry::registerURLSchemeServiceWorkersCanHandle):
     28        (WebCore::SchemeRegistry::canServiceWorkersHandleURLScheme):
     29        (WebCore::SchemeRegistry::isServiceWorkerContainerCustomScheme):
     30        * platform/SchemeRegistry.h:
     31
     32        * workers/service/ServiceWorkerContainer.cpp:
     33        (WebCore::ServiceWorkerContainer::addRegistration):
     34
     35        * workers/service/server/SWServerJobQueue.cpp:
     36        (WebCore::SWServerJobQueue::runRegisterJob):
     37
    1382017-12-18  Chris Dumez  <cdumez@apple.com>
    239
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r225314 r226088  
    16971697        || $context->extendedAttributes->{EnabledForWorld}
    16981698        || $context->extendedAttributes->{EnabledBySetting}
    1699         || $context->extendedAttributes->{SecureContext};
     1699        || $context->extendedAttributes->{SecureContext}
     1700        || $context->extendedAttributes->{ContextHasServiceWorkerScheme};
    17001701}
    17011702
     
    36503651        AddToImplIncludes("ScriptExecutionContext.h");
    36513652
    3652         push(@conjuncts, "jsCast<JSDOMGlobalObject*>(globalObject())->scriptExecutionContext()->isSecureContext()");
     3653        if ($context->extendedAttributes->{ContextHasServiceWorkerScheme}) {
     3654            push(@conjuncts, "(jsCast<JSDOMGlobalObject*>(globalObject())->scriptExecutionContext()->isSecureContext() || jsCast<JSDOMGlobalObject*>(globalObject())->scriptExecutionContext()->hasServiceWorkerScheme())");
     3655        } else {
     3656            push(@conjuncts, "jsCast<JSDOMGlobalObject*>(globalObject())->scriptExecutionContext()->isSecureContext()");
     3657        }
     3658    } else {
     3659        if ($context->extendedAttributes->{ContextHasServiceWorkerScheme}) {
     3660            AddToImplIncludes("ScriptExecutionContext.h");
     3661
     3662            push(@conjuncts, "jsCast<JSDOMGlobalObject*>(globalObject())->scriptExecutionContext()->hasServiceWorkerScheme()");
     3663        }
    36533664    }
    36543665
  • trunk/Source/WebCore/bindings/scripts/IDLAttributes.json

    r222613 r226088  
    8686            "contextsAllowed": ["interface"]
    8787        },
     88        "ContextHasServiceWorkerScheme": {
     89            "contextsAllowed": ["attribute"]
     90        },
    8891        "Custom": {
    8992            "contextsAllowed": ["attribute", "operation"]
  • trunk/Source/WebCore/dom/ScriptExecutionContext.cpp

    r225526 r226088  
    4646#include "SWClientConnection.h"
    4747#include "SWContextManager.h"
     48#include "SchemeRegistry.h"
    4849#include "ScriptState.h"
    4950#include "ServiceWorker.h"
     
    539540#if ENABLE(SERVICE_WORKER)
    540541
     542bool ScriptExecutionContext::hasServiceWorkerScheme()
     543{
     544    ASSERT(securityOrigin());
     545    return SchemeRegistry::isServiceWorkerContainerCustomScheme(securityOrigin()->protocol());
     546}
     547
    541548ServiceWorker* ScriptExecutionContext::activeServiceWorker() const
    542549{
  • trunk/Source/WebCore/dom/ScriptExecutionContext.h

    r225513 r226088  
    239239
    240240#if ENABLE(SERVICE_WORKER)
     241    bool hasServiceWorkerScheme();
    241242    ServiceWorker* activeServiceWorker() const;
    242243    void setActiveServiceWorker(RefPtr<ServiceWorker>&&);
  • trunk/Source/WebCore/page/NavigatorServiceWorker.idl

    r220220 r226088  
    2929    EnabledAtRuntime=ServiceWorker
    3030] interface NavigatorServiceWorker {
    31     [SecureContext, SameObject] readonly attribute ServiceWorkerContainer serviceWorker;
     31    [SecureContext, ContextHasServiceWorkerScheme, SameObject] readonly attribute ServiceWorkerContainer serviceWorker;
    3232};
  • trunk/Source/WebCore/platform/SchemeRegistry.cpp

    r219595 r226088  
    2828
    2929#include "URLParser.h"
     30#include <wtf/Lock.h>
     31#include <wtf/Locker.h>
    3032#include <wtf/MainThread.h>
    3133#include <wtf/NeverDestroyed.h>
     
    253255}
    254256
     257static Lock& serviceWorkerSchemesLock()
     258{
     259    static NeverDestroyed<Lock> lock;
     260    return lock;
     261}
     262
     263static URLSchemesMap& serviceWorkerSchemes()
     264{
     265    ASSERT(serviceWorkerSchemesLock().isHeld());
     266    static NeverDestroyed<URLSchemesMap> schemes;
     267    return schemes;
     268}
     269
    255270static URLSchemesMap& alwaysRevalidatedSchemes()
    256271{
     
    429444{
    430445    return !scheme.isNull() && cachePartitioningSchemes().contains(scheme);
     446}
     447
     448void SchemeRegistry::registerURLSchemeServiceWorkersCanHandle(const String& scheme)
     449{
     450    if (scheme.isNull())
     451        return;
     452
     453    Locker<Lock> locker(serviceWorkerSchemesLock());
     454    serviceWorkerSchemes().add(scheme);
     455}
     456
     457bool SchemeRegistry::canServiceWorkersHandleURLScheme(const String& scheme)
     458{
     459    if (scheme.isNull())
     460        return false;
     461
     462    if (scheme.startsWithIgnoringASCIICase(ASCIILiteral("http"))) {
     463        if (scheme.length() == 4)
     464            return true;
     465        if (scheme.length() == 5 && isASCIIAlphaCaselessEqual(scheme[4], 's'))
     466            return true;
     467    }
     468
     469    Locker<Lock> locker(serviceWorkerSchemesLock());
     470    return serviceWorkerSchemes().contains(scheme);
     471}
     472
     473bool SchemeRegistry::isServiceWorkerContainerCustomScheme(const String& scheme)
     474{
     475    Locker<Lock> locker(serviceWorkerSchemesLock());
     476    return !scheme.isNull() && serviceWorkerSchemes().contains(scheme);
    431477}
    432478
  • trunk/Source/WebCore/platform/SchemeRegistry.h

    r217738 r226088  
    100100    static bool shouldPartitionCacheForURLScheme(const String& scheme);
    101101
     102    // Schemes besides http(s) that service workers are allowed to handle
     103    WEBCORE_EXPORT static void registerURLSchemeServiceWorkersCanHandle(const String& scheme);
     104    WEBCORE_EXPORT static bool canServiceWorkersHandleURLScheme(const String& scheme);
     105    static bool isServiceWorkerContainerCustomScheme(const String& scheme);
     106
    102107    static bool isUserExtensionScheme(const String& scheme);
    103108};
  • trunk/Source/WebCore/workers/service/ServiceWorkerContainer.cpp

    r225916 r226088  
    3939#include "NavigatorBase.h"
    4040#include "ResourceError.h"
     41#include "SchemeRegistry.h"
    4142#include "ScriptExecutionContext.h"
    4243#include "SecurityOrigin.h"
     
    130131    }
    131132
    132     // FIXME: The spec disallows scripts outside of HTTP(S), but we'll likely support app custom URL schemes in WebKit.
    133     if (!jobData.scriptURL.protocolIsInHTTPFamily()) {
     133    if (!SchemeRegistry::canServiceWorkersHandleURLScheme(jobData.scriptURL.protocol().toStringWithoutCopying())) {
    134134        promise->reject(Exception { TypeError, ASCIILiteral("serviceWorker.register() must be called with a script URL whose protocol is either HTTP or HTTPS") });
    135135        return;
     
    146146        jobData.scopeURL = context->completeURL(scope);
    147147
    148     if (!jobData.scopeURL.isNull() && !jobData.scopeURL.protocolIsInHTTPFamily()) {
     148    if (!jobData.scopeURL.isNull() && !SchemeRegistry::canServiceWorkersHandleURLScheme(jobData.scopeURL.protocol().toStringWithoutCopying())) {
    149149        promise->reject(Exception { TypeError, ASCIILiteral("Scope URL provided to serviceWorker.register() must be either HTTP or HTTPS") });
    150150        return;
  • trunk/Source/WebCore/workers/service/server/SWServerJobQueue.cpp

    r225997 r226088  
    3232#include "SWServer.h"
    3333#include "SWServerWorker.h"
     34#include "SchemeRegistry.h"
    3435#include "SecurityOrigin.h"
    3536#include "ServiceWorkerFetchResult.h"
     
    240241    ASSERT(job.type == ServiceWorkerJobType::Register);
    241242
    242     if (!shouldTreatAsPotentiallyTrustworthy(job.scriptURL))
     243    if (!shouldTreatAsPotentiallyTrustworthy(job.scriptURL) && !SchemeRegistry::isServiceWorkerContainerCustomScheme(job.scriptURL.protocol().toStringWithoutCopying()))
    243244        return rejectCurrentJob(ExceptionData { SecurityError, ASCIILiteral("Script URL is not potentially trustworthy") });
    244245
  • trunk/Source/WebKit/ChangeLog

    r226083 r226088  
     12017-12-18  Brady Eidson  <beidson@apple.com>
     2
     3        Add ability to API test Service Workers via a custom protocol.
     4        https://bugs.webkit.org/show_bug.cgi?id=180911
     5
     6        Reviewed by Chris Dumez.
     7
     8        This adds a set of "Service Workers can handle this" schemes to the scheme registry
     9        and most of these WebKit changes are to support getting those values out to all processes.
     10       
     11        Additionally, WebsiteDataRecords used to be file/http(s)-only. That seems bizarre and definitely
     12        got in the way of testing. So I also added a way to allow any scheme to result in a valid record.
     13
     14        * Shared/ChildProcess.cpp:
     15        (WebKit::ChildProcess::registerURLSchemeServiceWorkersCanHandle const):
     16        * Shared/ChildProcess.h:
     17        * Shared/ChildProcess.messages.in:
     18       
     19        * Shared/Storage/StorageProcessCreationParameters.cpp:
     20        (WebKit::StorageProcessCreationParameters::encode const):
     21        (WebKit::StorageProcessCreationParameters::decode):
     22        * Shared/Storage/StorageProcessCreationParameters.h:
     23       
     24        * Shared/WebProcessCreationParameters.cpp:
     25        (WebKit::WebProcessCreationParameters::encode const):
     26        (WebKit::WebProcessCreationParameters::decode):
     27        * Shared/WebProcessCreationParameters.h:
     28       
     29        * StorageProcess/StorageProcess.cpp:
     30        (WebKit::StorageProcess::initializeWebsiteDataStore):
     31       
     32        * UIProcess/API/Cocoa/WKProcessPool.mm:
     33        (-[WKProcessPool _registerURLSchemeServiceWorkersCanHandle:]):
     34        * UIProcess/API/Cocoa/WKProcessPoolPrivate.h:
     35       
     36        * UIProcess/API/Cocoa/WKWebsiteDataStore.mm:
     37        (+[WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins]):
     38        * UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h:
     39       
     40        * UIProcess/WebProcessPool.cpp:
     41        (WebKit::WebProcessPool::ensureStorageProcessAndWebsiteDataStore):
     42        (WebKit::WebProcessPool::initializeNewWebProcess):
     43        (WebKit::WebProcessPool::registerURLSchemeServiceWorkersCanHandle):
     44        * UIProcess/WebProcessPool.h:
     45       
     46        * UIProcess/WebsiteData/WebsiteDataStore.cpp:
     47        (WebKit::WebsiteDataStore::allowWebsiteDataRecordsForAllOrigins):
     48        (WebKit::WebsiteDataStore::fetchDataAndApply):
     49        * UIProcess/WebsiteData/WebsiteDataStore.h:
     50       
     51        * WebProcess/Storage/WebServiceWorkerProvider.cpp:
     52        (WebKit::WebServiceWorkerProvider::handleFetch):
     53       
     54        * WebProcess/WebProcess.cpp:
     55        (WebKit::WebProcess::initializeWebProcess):
     56
    1572017-12-18  Brady Eidson  <beidson@apple.com>
    258
  • trunk/Source/WebKit/Shared/ChildProcess.cpp

    r220887 r226088  
    2929#include "Logging.h"
    3030#include "SandboxInitializationParameters.h"
     31#include <WebCore/SchemeRegistry.h>
    3132#include <pal/SessionID.h>
    3233#include <unistd.h>
     
    192193}
    193194
     195void ChildProcess::registerURLSchemeServiceWorkersCanHandle(const String& urlScheme) const
     196{
     197    WebCore::SchemeRegistry::registerURLSchemeServiceWorkersCanHandle(urlScheme);
     198}
     199
    194200#if !PLATFORM(COCOA)
    195201void ChildProcess::platformInitialize()
  • trunk/Source/WebKit/Shared/ChildProcess.h

    r225597 r226088  
    105105    void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
    106106
     107    void registerURLSchemeServiceWorkersCanHandle(const String&) const;
     108
    107109private:
    108110    // IPC::MessageSender
  • trunk/Source/WebKit/Shared/ChildProcess.messages.in

    r184503 r226088  
    2323messages -> ChildProcess {
    2424    ShutDown()
     25    RegisterURLSchemeServiceWorkersCanHandle(String scheme)
    2526}
  • trunk/Source/WebKit/Shared/Storage/StorageProcessCreationParameters.cpp

    r225826 r226088  
    4242#endif
    4343#if ENABLE(SERVICE_WORKER)
    44     encoder << serviceWorkerRegistrationDirectory << serviceWorkerRegistrationDirectoryExtensionHandle;
     44    encoder << serviceWorkerRegistrationDirectory << serviceWorkerRegistrationDirectoryExtensionHandle << urlSchemesServiceWorkersCanHandle;
    4545#endif
    4646}
     
    6969        return false;
    7070    result.serviceWorkerRegistrationDirectoryExtensionHandle = WTFMove(*serviceWorkerRegistrationDirectoryExtensionHandle);
     71
     72    if (!decoder.decode(result.urlSchemesServiceWorkersCanHandle))
     73        return false;
    7174#endif
    7275
  • trunk/Source/WebKit/Shared/Storage/StorageProcessCreationParameters.h

    r225490 r226088  
    5454    String serviceWorkerRegistrationDirectory;
    5555    SandboxExtension::Handle serviceWorkerRegistrationDirectoryExtensionHandle;
     56    Vector<String> urlSchemesServiceWorkersCanHandle;
    5657#endif
    5758};
  • trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp

    r225826 r226088  
    8585    encoder << urlSchemesRegisteredAsAlwaysRevalidated;
    8686    encoder << urlSchemesRegisteredAsCachePartitioned;
     87    encoder << urlSchemesServiceWorkersCanHandle;
    8788    encoder.encodeEnum(cacheModel);
    8889    encoder << shouldAlwaysUseComplexTextCodePath;
     
    272273    if (!decoder.decode(parameters.urlSchemesRegisteredAsCachePartitioned))
    273274        return false;
     275    if (!decoder.decode(parameters.urlSchemesServiceWorkersCanHandle))
     276        return false;
    274277    if (!decoder.decodeEnum(parameters.cacheModel))
    275278        return false;
  • trunk/Source/WebKit/Shared/WebProcessCreationParameters.h

    r225655 r226088  
    108108    Vector<String> urlSchemesRegisteredAsAlwaysRevalidated;
    109109    Vector<String> urlSchemesRegisteredAsCachePartitioned;
     110    Vector<String> urlSchemesServiceWorkersCanHandle;
    110111
    111112    Vector<String> fontWhitelist;
  • trunk/Source/WebKit/StorageProcess/StorageProcess.cpp

    r226003 r226088  
    192192        postStorageTask(createCrossThreadTask(*this, &StorageProcess::ensurePathExists, parameters.serviceWorkerRegistrationDirectory));
    193193    }
     194
     195    for (auto& scheme : parameters.urlSchemesServiceWorkersCanHandle)
     196        registerURLSchemeServiceWorkersCanHandle(scheme);
    194197#endif
    195198}
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm

    r225935 r226088  
    176176{
    177177    _processPool->allowSpecificHTTPSCertificateForHost(WebKit::WebCertificateInfo::create(WebCore::CertificateInfo((CFArrayRef)certificateChain)).ptr(), host);
     178}
     179
     180- (void)_registerURLSchemeServiceWorkersCanHandle:(NSString *)scheme
     181{
     182    _processPool->registerURLSchemeServiceWorkersCanHandle(scheme);
    178183}
    179184
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h

    r225935 r226088  
    9696// Test only.
    9797- (void)_setAllowsAnySSLCertificateForServiceWorker:(BOOL)allows WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
     98- (void)_registerURLSchemeServiceWorkersCanHandle:(NSString *)scheme WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
    9899
    99100@property (nonatomic, getter=_isCookieStoragePartitioningEnabled, setter=_setCookieStoragePartitioningEnabled:) BOOL _cookieStoragePartitioningEnabled WK_API_AVAILABLE(macosx(10.12.3), ios(10.3));
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm

    r225006 r226088  
    591591}
    592592
     593+ (void)_allowWebsiteDataRecordsForAllOrigins
     594{
     595    WebKit::WebsiteDataStore::allowWebsiteDataRecordsForAllOrigins();
     596}
     597
    593598@end
    594599
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h

    r225006 r226088  
    8484- (void)_resourceLoadStatisticsResetToConsistentState WK_API_AVAILABLE(macosx(10.13), ios(11.0));
    8585- (void)_setResourceLoadStatisticsTestingCallback:(nullable void (^)(WKWebsiteDataStore *, NSString *))callback WK_API_AVAILABLE(macosx(10.13), ios(11.0));
    86 
     86+ (void)_allowWebsiteDataRecordsForAllOrigins WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
    8787@end
    8888
  • trunk/Source/WebKit/UIProcess/WebProcessPool.cpp

    r225980 r226088  
    3636#include "APIPageConfiguration.h"
    3737#include "APIProcessPoolConfiguration.h"
     38#include "ChildProcessMessages.h"
    3839#include "DownloadProxy.h"
    3940#include "DownloadProxyMessages.h"
     
    558559            SandboxExtension::createHandleForReadWriteDirectory(parameters.serviceWorkerRegistrationDirectory, parameters.serviceWorkerRegistrationDirectoryExtensionHandle);
    559560        }
     561
     562        if (!m_schemesServiceWorkersCanHandle.isEmpty())
     563            parameters.urlSchemesServiceWorkersCanHandle = copyToVector(m_schemesServiceWorkersCanHandle);
    560564#endif
    561565
     
    778782    parameters.urlSchemesRegisteredAsAlwaysRevalidated = copyToVector(m_schemesToRegisterAsAlwaysRevalidated);
    779783    parameters.urlSchemesRegisteredAsCachePartitioned = copyToVector(m_schemesToRegisterAsCachePartitioned);
     784    parameters.urlSchemesServiceWorkersCanHandle = copyToVector(m_schemesServiceWorkersCanHandle);
    780785
    781786    parameters.shouldAlwaysUseComplexTextCodePath = m_alwaysUsesComplexTextCodePath;
     
    12891294    m_schemesToRegisterAsCachePartitioned.add(urlScheme);
    12901295    sendToAllProcesses(Messages::WebProcess::RegisterURLSchemeAsCachePartitioned(urlScheme));
     1296}
     1297
     1298void WebProcessPool::registerURLSchemeServiceWorkersCanHandle(const String& urlScheme)
     1299{
     1300    m_schemesServiceWorkersCanHandle.add(urlScheme);
     1301    sendToAllProcesses(Messages::ChildProcess::RegisterURLSchemeServiceWorkersCanHandle(urlScheme));
     1302    if (m_storageProcess)
     1303        m_storageProcess->send(Messages::ChildProcess::RegisterURLSchemeServiceWorkersCanHandle(urlScheme), 0);
    12911304}
    12921305
  • trunk/Source/WebKit/UIProcess/WebProcessPool.h

    r225980 r226088  
    219219    void registerURLSchemeAsCORSEnabled(const String&);
    220220    void registerURLSchemeAsCachePartitioned(const String&);
     221    void registerURLSchemeServiceWorkersCanHandle(const String&);
    221222    void preconnectToServer(const WebCore::URL&);
    222223
     
    539540    HashSet<String> m_schemesToRegisterAsAlwaysRevalidated;
    540541    HashSet<String> m_schemesToRegisterAsCachePartitioned;
     542    HashSet<String> m_schemesServiceWorkersCanHandle;
    541543
    542544    bool m_alwaysUsesComplexTextCodePath { false };
  • trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.cpp

    r226083 r226088  
    5656namespace WebKit {
    5757
     58static bool allowsWebsiteDataRecordsForAllOrigins;
     59void WebsiteDataStore::allowWebsiteDataRecordsForAllOrigins()
     60{
     61    allowsWebsiteDataRecordsForAllOrigins = true;
     62}
     63
    5864static HashMap<PAL::SessionID, WebsiteDataStore*>& nonDefaultDataStores()
    5965{
     
    239245            for (auto& entry : websiteData.entries) {
    240246                auto displayName = WebsiteDataRecord::displayNameForOrigin(entry.origin);
    241                 if (!displayName)
    242                     continue;
     247                if (!displayName) {
     248                    if (!allowsWebsiteDataRecordsForAllOrigins)
     249                        continue;
     250
     251                    displayName = makeString(entry.origin.protocol, " ", entry.origin.host);
     252                }
    243253
    244254                auto& record = m_websiteDataRecords.add(displayName, WebsiteDataRecord { }).iterator->value;
  • trunk/Source/WebKit/UIProcess/WebsiteData/WebsiteDataStore.h

    r226016 r226088  
    157157    AllowsCellularAccess allowsCellularAccess() { return m_allowsCellularAccess; }
    158158
     159    static void allowWebsiteDataRecordsForAllOrigins();
     160
    159161private:
    160162    explicit WebsiteDataStore(PAL::SessionID);
  • trunk/Source/WebKit/WebProcess/Storage/WebServiceWorkerProvider.cpp

    r225980 r226088  
    3535#include <WebCore/Exception.h>
    3636#include <WebCore/ExceptionCode.h>
     37#include <WebCore/SchemeRegistry.h>
    3738#include <WebCore/ServiceWorkerJob.h>
    3839#include <pal/SessionID.h>
     
    7273void WebServiceWorkerProvider::handleFetch(ResourceLoader& loader, CachedResource* resource, PAL::SessionID sessionID, bool shouldClearReferrerOnHTTPSToHTTPRedirect, ServiceWorkerClientFetch::Callback&& callback)
    7374{
    74     if (!loader.request().url().protocolIsInHTTPFamily() || !shouldHandleFetch(loader.options())) {
     75    if (!SchemeRegistry::canServiceWorkersHandleURLScheme(loader.request().url().protocol().toStringWithoutCopying()) || !shouldHandleFetch(loader.options())) {
    7576        callback(ServiceWorkerClientFetch::Result::Unhandled);
    7677        return;
  • trunk/Source/WebKit/WebProcess/WebProcess.cpp

    r226018 r226088  
    368368        registerURLSchemeAsCachePartitioned(scheme);
    369369
     370    for (auto& scheme : parameters.urlSchemesServiceWorkersCanHandle)
     371        registerURLSchemeServiceWorkersCanHandle(scheme);
     372
    370373    setDefaultRequestTimeoutInterval(parameters.defaultRequestTimeoutInterval);
    371374
  • trunk/Tools/ChangeLog

    r226085 r226088  
     12017-12-18  Brady Eidson  <beidson@apple.com>
     2
     3        Add ability to API test Service Workers via a custom protocol.
     4        https://bugs.webkit.org/show_bug.cgi?id=180911
     5
     6        Reviewed by Chris Dumez.
     7
     8        Adds a very basic SW test:
     9        - Verify WebsiteDataStore can wipe all SW registration data.
     10        - Fire up a web page with a service worker
     11        - Verify SW registration data for that page exists in the WebsiteDataStore.
     12
     13        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     14        * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm: Added.
     15
    1162017-12-18  Wenson Hsieh  <wenson_hsieh@apple.com>
    217
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r226015 r226088  
    198198                51E6A8941D2F1C0A00C004B6 /* LocalStorageClear.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51E6A8921D2F1BEC00C004B6 /* LocalStorageClear.mm */; };
    199199                51E6A8961D2F1CA700C004B6 /* LocalStorageClear.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 51E6A8951D2F1C7700C004B6 /* LocalStorageClear.html */; };
     200                51EB12941FDF052500A5A1BD /* ServiceWorkerBasic.mm in Sources */ = {isa = PBXBuildFile; fileRef = 51EB12931FDF050500A5A1BD /* ServiceWorkerBasic.mm */; };
    200201                51FCF7A11534B2A000104491 /* ShouldGoToBackForwardListItem_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 51FCF7971534AC6D00104491 /* ShouldGoToBackForwardListItem_Bundle.cpp */; };
    201202                520BCF4C141EB09E00937EA8 /* WebArchive_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 520BCF4A141EB09E00937EA8 /* WebArchive_Bundle.cpp */; };
     
    13421343                51E780371919AFF8001829A2 /* simple3.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = simple3.html; sourceTree = "<group>"; };
    13431344                51E93016156B13E1004C99DF /* WKPageGetScaleFactorNotZero.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKPageGetScaleFactorNotZero.cpp; sourceTree = "<group>"; };
     1345                51EB12931FDF050500A5A1BD /* ServiceWorkerBasic.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ServiceWorkerBasic.mm; sourceTree = "<group>"; };
    13441346                51FBBB4C1513D4E900822738 /* WebViewCanPasteURL.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebViewCanPasteURL.mm; sourceTree = "<group>"; };
    13451347                51FCF7971534AC6D00104491 /* ShouldGoToBackForwardListItem_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ShouldGoToBackForwardListItem_Bundle.cpp; sourceTree = "<group>"; };
     
    21032105                                37BCA61B1B596BA9002012CA /* ShouldOpenExternalURLsInNewWindowActions.mm */,
    21042106                                2D9A53AE1B31FA8D0074D5AA /* ShrinkToFit.mm */,
     2107                                51EB12931FDF050500A5A1BD /* ServiceWorkerBasic.mm */,
    21052108                                2DFF7B6C1DA487AF00814614 /* SnapshotStore.mm */,
    21062109                                515BE1701D428BD100DD7C68 /* StoreBlobThenDelete.mm */,
     
    34233426                                5C69BDD51F82A7EF000F4F4B /* JavaScriptDuringNavigation.mm in Sources */,
    34243427                                7CCE7EAD1A411A3400447C4C /* JavaScriptTest.cpp in Sources */,
     3428                                51EB12941FDF052500A5A1BD /* ServiceWorkerBasic.mm in Sources */,
    34253429                                7CCE7EA51A411A0800447C4C /* JavaScriptTestMac.mm in Sources */,
    34263430                                7CCE7EC41A411A7E00447C4C /* JSWrapperForNodeInWebFrame.mm in Sources */,
Note: See TracChangeset for help on using the changeset viewer.