Changeset 226510 in webkit


Ignore:
Timestamp:
Jan 8, 2018 6:43:50 AM (6 years ago)
Author:
commit-queue@webkit.org
Message:

navigator.onLine does not work inside service workers
https://bugs.webkit.org/show_bug.cgi?id=181079
<rdar://problem/36178606>

Patch by Youenn Fablet <youenn@apple.com> on 2018-01-08
Reviewed by Darin Adler.

Source/WebCore:

Test: http/wpt/service-workers/online.https.html

Added support for onLine by reusing a similar implementation as regular workers.
Added ServiceWorkerInternals as an interface for an object exposed as self.internals in WTR.
This object has currently one method to trigger change in the online/offline status.
This allows writing a test for the onLine feature.

Note that self.internals is inserted asynchronously after the script was evaluated.
When writing a worker script using self.internals, one must make sure to use self.internals when initialized.
online-worker.js for instance makes use of self.internals in a postMessage callback.

  • CMakeLists.txt:
  • DerivedSources.make:
  • WebCore.xcodeproj/project.pbxproj:
  • bindings/js/WorkerScriptController.h:
  • dom/ScriptExecutionContext.h:
  • testing/ServiceWorkerInternals.cpp: Added.

(WebCore::ServiceWorkerInternals::ServiceWorkerInternals):
(WebCore::ServiceWorkerInternals::setOnline):

  • testing/ServiceWorkerInternals.h: Added.
  • testing/ServiceWorkerInternals.idl: Added.
  • testing/js/WebCoreTestSupport.cpp:

(WebCoreTestSupport::setupNewlyCreateServiceWorker):

  • testing/js/WebCoreTestSupport.h:
  • workers/service/context/SWContextManager.cpp:

(WebCore::SWContextManager::registerServiceWorkerThreadForInstall):
(WebCore::SWContextManager::startedServiceWorker):

  • workers/service/context/SWContextManager.h:

(WebCore::SWContextManager::setServiceWorkerCreationCallback):
(WebCore::SWContextManager::workerByID):

  • workers/service/context/ServiceWorkerThread.cpp:

(WebCore::ServiceWorkerThread::ServiceWorkerThread):

  • workers/service/context/ServiceWorkerThreadProxy.cpp:

(WebCore::ServiceWorkerThreadProxy::ServiceWorkerThreadProxy):
(WebCore::ServiceWorkerThreadProxy::~ServiceWorkerThreadProxy):
(WebCore::ServiceWorkerThreadProxy::networkStateChanged):
(WebCore::ServiceWorkerThreadProxy::notifyNetworkStateChange):

  • workers/service/context/ServiceWorkerThreadProxy.h:

Source/WebKit:

Added support for a callback called for each service worker proxy creation.
Callback is used by WTR to inject a self.internals object used for testing.

  • WebProcess/InjectedBundle/API/c/WKBundle.cpp:

(WKBundleSetServiceWorkerProxyCreationCallback):

  • WebProcess/InjectedBundle/API/c/WKBundle.h:
  • WebProcess/InjectedBundle/InjectedBundle.cpp:

(WebKit::InjectedBundle::setServiceWorkerProxyCreationCallback):

  • WebProcess/InjectedBundle/InjectedBundle.h:

Tools:

  • WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:

(WTR::InjectedBundle::initialize): Setting service worker creation callback to inject ServiceWorkerInternals object.

LayoutTests:

  • http/wpt/service-workers/online-worker.js: Added.

(async.waitForOnlineEvent):
(async.doTest):

  • http/wpt/service-workers/online.https-expected.txt: Added.
  • http/wpt/service-workers/online.https.html: Added.
Location:
trunk
Files:
6 added
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r226507 r226510  
     12018-01-08  Youenn Fablet  <youenn@apple.com>
     2
     3        navigator.onLine does not work inside service workers
     4        https://bugs.webkit.org/show_bug.cgi?id=181079
     5        <rdar://problem/36178606>
     6
     7        Reviewed by Darin Adler.
     8
     9        * http/wpt/service-workers/online-worker.js: Added.
     10        (async.waitForOnlineEvent):
     11        (async.doTest):
     12        * http/wpt/service-workers/online.https-expected.txt: Added.
     13        * http/wpt/service-workers/online.https.html: Added.
     14
    1152018-01-08  Youenn Fablet  <youenn@apple.com>
    216
  • trunk/Source/WebCore/CMakeLists.txt

    r226332 r226510  
    15501550    testing/MockContentFilterSettings.idl
    15511551    testing/MockPageOverlay.idl
     1552    testing/ServiceWorkerInternals.idl
    15521553    testing/TypeConversions.idl
    15531554)
     
    15691570    testing/MockPageOverlay.cpp
    15701571    testing/MockPageOverlayClient.cpp
    1571 
     1572    testing/ServiceWorkerInternals.cpp
    15721573    testing/js/WebCoreTestSupport.cpp
    15731574)
  • trunk/Source/WebCore/ChangeLog

    r226509 r226510  
     12018-01-08  Youenn Fablet  <youenn@apple.com>
     2
     3        navigator.onLine does not work inside service workers
     4        https://bugs.webkit.org/show_bug.cgi?id=181079
     5        <rdar://problem/36178606>
     6
     7        Reviewed by Darin Adler.
     8
     9        Test: http/wpt/service-workers/online.https.html
     10
     11        Added support for onLine by reusing a similar implementation as regular workers.
     12        Added ServiceWorkerInternals as an interface for an object exposed as self.internals in WTR.
     13        This object has currently one method to trigger change in the online/offline status.
     14        This allows writing a test for the onLine feature.
     15
     16        Note that self.internals is inserted asynchronously after the script was evaluated.
     17        When writing a worker script using self.internals, one must make sure to use self.internals when initialized.
     18        online-worker.js for instance makes use of self.internals in a postMessage callback.
     19
     20        * CMakeLists.txt:
     21        * DerivedSources.make:
     22        * WebCore.xcodeproj/project.pbxproj:
     23        * bindings/js/WorkerScriptController.h:
     24        * dom/ScriptExecutionContext.h:
     25        * testing/ServiceWorkerInternals.cpp: Added.
     26        (WebCore::ServiceWorkerInternals::ServiceWorkerInternals):
     27        (WebCore::ServiceWorkerInternals::setOnline):
     28        * testing/ServiceWorkerInternals.h: Added.
     29        * testing/ServiceWorkerInternals.idl: Added.
     30        * testing/js/WebCoreTestSupport.cpp:
     31        (WebCoreTestSupport::setupNewlyCreateServiceWorker):
     32        * testing/js/WebCoreTestSupport.h:
     33        * workers/service/context/SWContextManager.cpp:
     34        (WebCore::SWContextManager::registerServiceWorkerThreadForInstall):
     35        (WebCore::SWContextManager::startedServiceWorker):
     36        * workers/service/context/SWContextManager.h:
     37        (WebCore::SWContextManager::setServiceWorkerCreationCallback):
     38        (WebCore::SWContextManager::workerByID):
     39        * workers/service/context/ServiceWorkerThread.cpp:
     40        (WebCore::ServiceWorkerThread::ServiceWorkerThread):
     41        * workers/service/context/ServiceWorkerThreadProxy.cpp:
     42        (WebCore::ServiceWorkerThreadProxy::ServiceWorkerThreadProxy):
     43        (WebCore::ServiceWorkerThreadProxy::~ServiceWorkerThreadProxy):
     44        (WebCore::ServiceWorkerThreadProxy::networkStateChanged):
     45        (WebCore::ServiceWorkerThreadProxy::notifyNetworkStateChange):
     46        * workers/service/context/ServiceWorkerThreadProxy.h:
     47
    1482018-01-08  Zan Dobersek  <zdobersek@igalia.com>
    249
  • trunk/Source/WebCore/DerivedSources.make

    r226332 r226510  
    941941    $(WebCore)/testing/MockPaymentAddress.idl \
    942942    $(WebCore)/testing/MockPaymentCoordinator.idl \
     943    $(WebCore)/testing/ServiceWorkerInternals.idl \
    943944    $(WebCore)/testing/TypeConversions.idl \
    944945    $(WebCore)/workers/AbstractWorker.idl \
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r226468 r226510  
    10251025                417DA6DA13734E6E007C57FB /* Internals.h in Headers */ = {isa = PBXBuildFile; fileRef = 417DA4CE13734326007C57FB /* Internals.h */; };
    10261026                417DA71D13735DFA007C57FB /* JSInternals.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 417DA71B13735DFA007C57FB /* JSInternals.cpp */; };
     1027                427DA71D13735DFA007C57FB /* JSServiceWorkerInternals.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 427DA71B13735DFA007C57FB /* JSServiceWorkerInternals.cpp */; };
    10271028                417DA71E13735DFA007C57FB /* JSInternals.h in Headers */ = {isa = PBXBuildFile; fileRef = 417DA71C13735DFA007C57FB /* JSInternals.h */; };
     1029                427DA71E13735DFA007C57FB /* JSServiceWorkerInternals.h in Headers */ = {isa = PBXBuildFile; fileRef = 427DA71C13735DFA007C57FB /* JSServiceWorkerInternals.h */; };
     1030                417F0D821FFEE979008EF303 /* ServiceWorkerInternals.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 417F0D801FFEE14F008EF303 /* ServiceWorkerInternals.cpp */; };
    10281031                41815C1E138319830057AAA4 /* WebCoreTestSupport.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41815C1C138319830057AAA4 /* WebCoreTestSupport.cpp */; };
    10291032                41815C1F138319830057AAA4 /* WebCoreTestSupport.h in Headers */ = {isa = PBXBuildFile; fileRef = 41815C1D138319830057AAA4 /* WebCoreTestSupport.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    70267029                417DA6D013734E02007C57FB /* libWebCoreTestSupport.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = libWebCoreTestSupport.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
    70277030                417DA71B13735DFA007C57FB /* JSInternals.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSInternals.cpp; sourceTree = "<group>"; };
     7031                427DA71B13735DFA007C57FB /* JSServiceWorkerInternals.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSServiceWorkerInternals.cpp; sourceTree = "<group>"; };
    70287032                417DA71C13735DFA007C57FB /* JSInternals.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSInternals.h; sourceTree = "<group>"; };
     7033                427DA71C13735DFA007C57FB /* JSServiceWorkerInternals.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSServiceWorkerInternals.h; sourceTree = "<group>"; };
     7034                417F0D7E1FFEE14E008EF303 /* ServiceWorkerInternals.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ServiceWorkerInternals.h; sourceTree = "<group>"; };
     7035                417F0D801FFEE14F008EF303 /* ServiceWorkerInternals.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ServiceWorkerInternals.cpp; sourceTree = "<group>"; };
     7036                417F0D811FFEE150008EF303 /* ServiceWorkerInternals.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ServiceWorkerInternals.idl; sourceTree = "<group>"; };
    70297037                41813F9113818AD60057AAA4 /* Internals.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Internals.idl; sourceTree = "<group>"; };
    70307038                41815C1C138319830057AAA4 /* WebCoreTestSupport.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebCoreTestSupport.cpp; sourceTree = "<group>"; };
     
    1639716405                                A14061891E2ECA0A0032B34E /* MockPreviewLoaderClient.cpp */,
    1639816406                                A140618A1E2ECA0A0032B34E /* MockPreviewLoaderClient.h */,
     16407                                417F0D801FFEE14F008EF303 /* ServiceWorkerInternals.cpp */,
     16408                                417F0D7E1FFEE14E008EF303 /* ServiceWorkerInternals.h */,
     16409                                417F0D811FFEE150008EF303 /* ServiceWorkerInternals.idl */,
    1639916410                                EB081CD81696084400553730 /* TypeConversions.h */,
    1640016411                                EB081CD91696084400553730 /* TypeConversions.idl */,
     
    1642916440                                A146D3191F99BCBB00D29196 /* JSMockPaymentCoordinator.cpp */,
    1643016441                                A146D3181F99BCBA00D29196 /* JSMockPaymentCoordinator.h */,
     16442                                427DA71B13735DFA007C57FB /* JSServiceWorkerInternals.cpp */,
     16443                                427DA71C13735DFA007C57FB /* JSServiceWorkerInternals.h */,
    1643116444                                EBF5121A1696496C0056BD25 /* JSTypeConversions.cpp */,
    1643216445                                EBF5121B1696496C0056BD25 /* JSTypeConversions.h */,
     
    2617126184                                A146D3231F99D0EF00D29196 /* JSMockPaymentAddress.h in Headers */,
    2617226185                                A146D31B1F99BCFB00D29196 /* JSMockPaymentCoordinator.h in Headers */,
     26186                                427DA71E13735DFA007C57FB /* JSServiceWorkerInternals.h in Headers */,
    2617326187                                EBF5121D1696496C0056BD25 /* JSTypeConversions.h in Headers */,
    2617426188                                CDC26B41160A8CCE0026757B /* LegacyMockCDM.h in Headers */,
     
    3046430478                                A146D3221F99D0EC00D29196 /* JSMockPaymentAddress.cpp in Sources */,
    3046530479                                A146D31A1F99BCF800D29196 /* JSMockPaymentCoordinator.cpp in Sources */,
     30480                                427DA71D13735DFA007C57FB /* JSServiceWorkerInternals.cpp in Sources */,
    3046630481                                EBF5121C1696496C0056BD25 /* JSTypeConversions.cpp in Sources */,
    3046730482                                CDC26B40160A8CC60026757B /* LegacyMockCDM.cpp in Sources */,
     
    3047730492                                A140618B1E2ECA0A0032B34E /* MockPreviewLoaderClient.cpp in Sources */,
    3047830493                                AA5F3B8F16CC4B3900455EB0 /* PlatformSpeechSynthesizerMock.cpp in Sources */,
     30494                                417F0D821FFEE979008EF303 /* ServiceWorkerInternals.cpp in Sources */,
    3047930495                                DE7710861FA2F0D600460016 /* WebArchiveDumpSupport.mm in Sources */,
    3048030496                                41815C1E138319830057AAA4 /* WebCoreTestSupport.cpp in Sources */,
  • trunk/Source/WebCore/bindings/js/WorkerScriptController.h

    r224295 r226510  
    9595            initScript();
    9696    }
    97     void initScript();
     97    WEBCORE_EXPORT void initScript();
    9898
    9999    RefPtr<JSC::VM> m_vm;
  • trunk/Source/WebCore/dom/ScriptExecutionContext.h

    r226274 r226510  
    236236    }
    237237
    238     JSC::ExecState* execState();
     238    WEBCORE_EXPORT JSC::ExecState* execState();
    239239
    240240    WEBCORE_EXPORT String domainForCachePartition() const;
  • trunk/Source/WebCore/testing/js/WebCoreTestSupport.cpp

    r223476 r226510  
    3333#include "JSDocument.h"
    3434#include "JSInternals.h"
     35#include "JSServiceWorkerInternals.h"
     36#include "JSWorkerGlobalScope.h"
    3537#include "LogInitialization.h"
    3638#include "MockGamepadProvider.h"
    3739#include "Page.h"
     40#include "SWContextManager.h"
     41#include "ServiceWorkerGlobalScope.h"
    3842#include "URLParser.h"
    3943#include "WheelEventTestTrigger.h"
     
    181185}
    182186
    183 }
     187void setupNewlyCreatedServiceWorker(uint64_t serviceWorkerIdentifier)
     188{
     189#if ENABLE(SERVICE_WORKER)
     190    auto identifier = makeObjectIdentifier<ServiceWorkerIdentifierType>(serviceWorkerIdentifier);
     191    SWContextManager::singleton().postTaskToServiceWorker(identifier, [identifier] (ServiceWorkerGlobalScope& globalScope) {
     192        auto* script = globalScope.script();
     193        if (!script)
     194            return;
     195
     196        auto& state = *globalScope.execState();
     197        JSLockHolder locker(state.vm());
     198        auto* contextWrapper = script->workerGlobalScopeWrapper();
     199        contextWrapper->putDirect(state.vm(), Identifier::fromString(&state, Internals::internalsId), toJS(&state, contextWrapper, ServiceWorkerInternals::create(identifier)));
     200    });
     201#endif
     202}
     203
     204}
  • trunk/Source/WebCore/testing/js/WebCoreTestSupport.h

    r208668 r226510  
    6464void setMockGamepadButtonValue(unsigned index, unsigned buttonIndex, double value) TEST_SUPPORT_EXPORT;
    6565
     66void setupNewlyCreatedServiceWorker(uint64_t serviceWorkerIdentifier) TEST_SUPPORT_EXPORT;
     67
    6668} // namespace WebCoreTestSupport
  • trunk/Source/WebCore/workers/service/context/SWContextManager.cpp

    r226399 r226510  
    5959   
    6060    threadProxy->thread().start([jobDataIdentifier, serviceWorkerIdentifier](const String& exceptionMessage) {
    61         SWContextManager::singleton().connection()->serviceWorkerStartedWithMessage(jobDataIdentifier, serviceWorkerIdentifier, exceptionMessage);
     61        SWContextManager::singleton().startedServiceWorker(jobDataIdentifier, serviceWorkerIdentifier, exceptionMessage);
    6262    });
     63}
     64
     65void SWContextManager::startedServiceWorker(std::optional<ServiceWorkerJobDataIdentifier> jobDataIdentifier, ServiceWorkerIdentifier serviceWorkerIdentifier, const String& exceptionMessage)
     66{
     67    connection()->serviceWorkerStartedWithMessage(jobDataIdentifier, serviceWorkerIdentifier, exceptionMessage);
     68    if (m_serviceWorkerCreationCallback)
     69        m_serviceWorkerCreationCallback(serviceWorkerIdentifier.toUInt64());
    6370}
    6471
  • trunk/Source/WebCore/workers/service/context/SWContextManager.h

    r226274 r226510  
    7777    WEBCORE_EXPORT bool postTaskToServiceWorker(ServiceWorkerIdentifier, WTF::Function<void(ServiceWorkerGlobalScope&)>&&);
    7878
     79    using ServiceWorkerCreationCallback = void(uint64_t);
     80    void setServiceWorkerCreationCallback(ServiceWorkerCreationCallback* callback) { m_serviceWorkerCreationCallback = callback; }
     81
     82    ServiceWorkerThreadProxy* workerByID(ServiceWorkerIdentifier identifier) { return m_workerMap.get(identifier); }
     83
    7984private:
    8085    SWContextManager() = default;
    8186
     87    void startedServiceWorker(std::optional<ServiceWorkerJobDataIdentifier>, ServiceWorkerIdentifier, const String& exceptionMessage);
     88
    8289    HashMap<ServiceWorkerIdentifier, RefPtr<ServiceWorkerThreadProxy>> m_workerMap;
    8390    std::unique_ptr<Connection> m_connection;
     91    ServiceWorkerCreationCallback* m_serviceWorkerCreationCallback { nullptr };
    8492};
    8593
  • trunk/Source/WebCore/workers/service/context/ServiceWorkerThread.cpp

    r226191 r226510  
    3434#include "ExtendableMessageEvent.h"
    3535#include "JSDOMPromise.h"
     36#include "NetworkStateNotifier.h"
    3637#include "SecurityOrigin.h"
    3738#include "ServiceWorkerFetch.h"
     
    6869// FIXME: Use a valid WorkerReportingProxy
    6970// FIXME: Use a valid WorkerObjectProxy
    70 // FIXME: Use a valid isOnline flag
    7171// FIXME: Use valid runtime flags
    7272
    7373ServiceWorkerThread::ServiceWorkerThread(const ServiceWorkerContextData& data, PAL::SessionID, String&& userAgent, WorkerLoaderProxy& loaderProxy, WorkerDebuggerProxy& debuggerProxy, IDBClient::IDBConnectionProxy* idbConnectionProxy, SocketProvider* socketProvider)
    74     : WorkerThread(data.scriptURL, "serviceworker:" + Inspector::IdentifiersFactory::createIdentifier(), WTFMove(userAgent), /* isOnline */ false, data.script, loaderProxy, debuggerProxy, DummyServiceWorkerThreadProxy::shared(), WorkerThreadStartMode::Normal, ContentSecurityPolicyResponseHeaders { }, false, SecurityOrigin::create(data.scriptURL).get(), MonotonicTime::now(), idbConnectionProxy, socketProvider, JSC::RuntimeFlags::createAllEnabled(), SessionID::defaultSessionID())
     74    : WorkerThread(data.scriptURL, "serviceworker:" + Inspector::IdentifiersFactory::createIdentifier(), WTFMove(userAgent), NetworkStateNotifier::singleton().onLine(), data.script, loaderProxy, debuggerProxy, DummyServiceWorkerThreadProxy::shared(), WorkerThreadStartMode::Normal, ContentSecurityPolicyResponseHeaders { }, false, SecurityOrigin::create(data.scriptURL).get(), MonotonicTime::now(), idbConnectionProxy, socketProvider, JSC::RuntimeFlags::createAllEnabled(), SessionID::defaultSessionID())
    7575    , m_data(data.isolatedCopy())
    7676    , m_workerObjectProxy(DummyServiceWorkerThreadProxy::shared())
  • trunk/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.cpp

    r226399 r226510  
    7878}
    7979
     80static HashSet<ServiceWorkerThreadProxy*>& allServiceWorkerThreadProxies()
     81{
     82    static NeverDestroyed<HashSet<ServiceWorkerThreadProxy*>> set;
     83    return set;
     84}
     85
    8086ServiceWorkerThreadProxy::ServiceWorkerThreadProxy(PageConfiguration&& pageConfiguration, const ServiceWorkerContextData& data, PAL::SessionID sessionID, String&& userAgent, CacheStorageProvider& cacheStorageProvider, SecurityOrigin::StorageBlockingPolicy storageBlockingPolicy)
    8187    : m_page(createPageForServiceWorker(WTFMove(pageConfiguration), data, storageBlockingPolicy))
     
    8692    , m_inspectorProxy(*this)
    8793{
     94    static bool addedListener;
     95    if (!addedListener) {
     96        NetworkStateNotifier::singleton().addListener(&networkStateChanged);
     97        addedListener = true;
     98    }
     99
     100    ASSERT(!allServiceWorkerThreadProxies().contains(this));
     101    allServiceWorkerThreadProxies().add(this);
     102
    88103#if ENABLE(REMOTE_INSPECTOR)
    89104    m_remoteDebuggable = std::make_unique<ServiceWorkerDebuggable>(*this, data);
     
    91106    m_remoteDebuggable->init();
    92107#endif
     108}
     109
     110ServiceWorkerThreadProxy::~ServiceWorkerThreadProxy()
     111{
     112    ASSERT(allServiceWorkerThreadProxies().contains(this));
     113    allServiceWorkerThreadProxies().remove(this);
    93114}
    94115
     
    142163}
    143164
     165void ServiceWorkerThreadProxy::networkStateChanged(bool isOnLine)
     166{
     167    for (auto* proxy : allServiceWorkerThreadProxies())
     168        proxy->notifyNetworkStateChange(isOnLine);
     169}
     170
     171void ServiceWorkerThreadProxy::notifyNetworkStateChange(bool isOnline)
     172{
     173    if (m_isTerminatingOrTerminated)
     174        return;
     175
     176    postTaskForModeToWorkerGlobalScope([isOnline] (ScriptExecutionContext& context) {
     177        auto& globalScope = downcast<WorkerGlobalScope>(context);
     178        globalScope.setIsOnline(isOnline);
     179        globalScope.dispatchEvent(Event::create(isOnline ? eventNames().onlineEvent : eventNames().offlineEvent, false, false));
     180    }, WorkerRunLoop::defaultMode());
     181}
     182
    144183} // namespace WebCore
    145184
  • trunk/Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.h

    r226399 r226510  
    5555        return adoptRef(*new ServiceWorkerThreadProxy(std::forward<Args>(args)...));
    5656    }
     57    ~ServiceWorkerThreadProxy();
    5758
    5859    ServiceWorkerIdentifier identifier() const { return m_serviceWorkerThread->identifier(); }
     
    6566    WEBCORE_EXPORT std::unique_ptr<FetchLoader> createBlobLoader(FetchLoaderClient&, const URL&);
    6667
     68    // Public only for testing purposes.
     69    WEBCORE_TESTSUPPORT_EXPORT void notifyNetworkStateChange(bool isOnline);
     70
    6771private:
    6872    WEBCORE_EXPORT ServiceWorkerThreadProxy(PageConfiguration&&, const ServiceWorkerContextData&, PAL::SessionID, String&& userAgent, CacheStorageProvider&, SecurityOrigin::StorageBlockingPolicy);
     73
     74    WEBCORE_EXPORT static void networkStateChanged(bool isOnLine);
    6975
    7076    // WorkerLoaderProxy
  • trunk/Source/WebKit/ChangeLog

    r226499 r226510  
     12018-01-08  Youenn Fablet  <youenn@apple.com>
     2
     3        navigator.onLine does not work inside service workers
     4        https://bugs.webkit.org/show_bug.cgi?id=181079
     5        <rdar://problem/36178606>
     6
     7        Reviewed by Darin Adler.
     8
     9        Added support for a callback called for each service worker proxy creation.
     10        Callback is used by WTR to inject a self.internals object used for testing.
     11
     12        * WebProcess/InjectedBundle/API/c/WKBundle.cpp:
     13        (WKBundleSetServiceWorkerProxyCreationCallback):
     14        * WebProcess/InjectedBundle/API/c/WKBundle.h:
     15        * WebProcess/InjectedBundle/InjectedBundle.cpp:
     16        (WebKit::InjectedBundle::setServiceWorkerProxyCreationCallback):
     17        * WebProcess/InjectedBundle/InjectedBundle.h:
     18
    1192018-01-07  David Kilzer  <ddkilzer@apple.com>
    220
  • trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundle.cpp

    r223565 r226510  
    4141#include <WebCore/DatabaseTracker.h>
    4242#include <WebCore/ResourceLoadObserver.h>
     43#include <WebCore/ServiceWorkerThreadProxy.h>
    4344
    4445using namespace WebCore;
     
    5354{
    5455    toImpl(bundleRef)->setClient(std::make_unique<InjectedBundleClient>(wkClient));
     56}
     57
     58void WKBundleSetServiceWorkerProxyCreationCallback(WKBundleRef bundleRef, void (*callback)(uint64_t))
     59{
     60    toImpl(bundleRef)->setServiceWorkerProxyCreationCallback(callback);
    5561}
    5662
  • trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundle.h

    r188279 r226510  
    7272
    7373WK_EXPORT void WKBundleSetClient(WKBundleRef bundle, WKBundleClientBase* client);
     74WK_EXPORT void WKBundleSetServiceWorkerProxyCreationCallback(WKBundleRef bundle, void (*)(uint64_t));
    7475
    7576WK_EXPORT void WKBundlePostMessage(WKBundleRef bundle, WKStringRef messageName, WKTypeRef messageBody);
  • trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundle.cpp

    r226211 r226510  
    7171#include <WebCore/ResourceHandle.h>
    7272#include <WebCore/RuntimeEnabledFeatures.h>
     73#include <WebCore/SWContextManager.h>
    7374#include <WebCore/ScriptController.h>
    7475#include <WebCore/SecurityOrigin.h>
     
    117118    else
    118119        m_client = WTFMove(client);
     120}
     121
     122void InjectedBundle::setServiceWorkerProxyCreationCallback(void (*callback)(uint64_t))
     123{
     124#if ENABLE(SERVICE_WORKER)
     125    SWContextManager::singleton().setServiceWorkerCreationCallback(callback);
     126#endif
    119127}
    120128
  • trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundle.h

    r225926 r226510  
    8888    void postMessage(const String&, API::Object*);
    8989    void postSynchronousMessage(const String&, API::Object*, RefPtr<API::Object>& returnData);
     90    void setServiceWorkerProxyCreationCallback(void (*)(uint64_t));
    9091
    9192    WebConnection* webConnectionToUIProcess() const;
  • trunk/Tools/ChangeLog

    r226493 r226510  
     12018-01-08  Youenn Fablet  <youenn@apple.com>
     2
     3        navigator.onLine does not work inside service workers
     4        https://bugs.webkit.org/show_bug.cgi?id=181079
     5        <rdar://problem/36178606>
     6
     7        Reviewed by Darin Adler.
     8
     9        * WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
     10        (WTR::InjectedBundle::initialize): Setting service worker creation callback to inject ServiceWorkerInternals object.
     11
    1122018-01-07  Saam Barati  <sbarati@apple.com>
    213
  • trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp

    r225598 r226510  
    9898    };
    9999    WKBundleSetClient(m_bundle, &client.base);
    100 
     100    WKBundleSetServiceWorkerProxyCreationCallback(m_bundle, WebCoreTestSupport::setupNewlyCreatedServiceWorker);
    101101    platformInitialize(initializationUserData);
    102102
Note: See TracChangeset for help on using the changeset viewer.