Index: third_party/WebKit/Source/web/FrameLoaderClientImpl.cpp |
diff --git a/third_party/WebKit/Source/web/FrameLoaderClientImpl.cpp b/third_party/WebKit/Source/web/FrameLoaderClientImpl.cpp |
index 4ac562aaae76c81a107b44a1694e8398609eda80..933575c0f013cf5c21995fe7bc6c598d464d925d 100644 |
--- a/third_party/WebKit/Source/web/FrameLoaderClientImpl.cpp |
+++ b/third_party/WebKit/Source/web/FrameLoaderClientImpl.cpp |
@@ -49,6 +49,7 @@ |
#include "core/loader/FrameLoadRequest.h" |
#include "core/loader/FrameLoader.h" |
#include "core/loader/HistoryItem.h" |
+#include "core/loader/LinkLoaderClient.h" |
#include "core/page/Page.h" |
#include "core/page/WindowFeatures.h" |
#include "modules/audio_output_devices/HTMLMediaElementAudioOutputDevice.h" |
@@ -61,6 +62,7 @@ |
#include "modules/mediasession/HTMLMediaElementMediaSession.h" |
#include "modules/mediasession/MediaSession.h" |
#include "modules/serviceworkers/NavigatorServiceWorker.h" |
+#include "modules/serviceworkers/ServiceWorkerContainer.h" |
#include "modules/storage/DOMWindowStorageController.h" |
#include "modules/vr/NavigatorVRDevice.h" |
#include "platform/Histogram.h" |
@@ -77,6 +79,7 @@ |
#include "public/platform/WebMediaPlayer.h" |
#include "public/platform/WebMimeRegistry.h" |
#include "public/platform/WebRTCPeerConnectionHandler.h" |
+#include "public/platform/WebScheduler.h" |
#include "public/platform/WebSecurityOrigin.h" |
#include "public/platform/WebURL.h" |
#include "public/platform/WebURLError.h" |
@@ -1029,4 +1032,46 @@ void FrameLoaderClientImpl::suddenTerminationDisablerChanged(bool present, Sudde |
} |
} |
+namespace { |
+ |
+class RegistrationCallback : public WebServiceWorkerProvider::WebServiceWorkerRegistrationCallbacks { |
+public: |
+ explicit RegistrationCallback(LinkLoaderClient* client) : m_client(client) {} |
+ ~RegistrationCallback() override {} |
+ |
+ void onSuccess(WebPassOwnPtr<WebServiceWorkerRegistration::Handle> handle) override |
+ { |
+ Platform::current()->currentThread()->scheduler()->timerTaskRunner()->postTask(BLINK_FROM_HERE, bind(&LinkLoaderClient::linkLoaded, m_client)); |
+ } |
+ |
+ void onError(const WebServiceWorkerError& error) override |
+ { |
+ Platform::current()->currentThread()->scheduler()->timerTaskRunner()->postTask(BLINK_FROM_HERE, bind(&LinkLoaderClient::linkLoadingErrored, m_client)); |
+ } |
+ |
+private: |
+ WTF_MAKE_NONCOPYABLE(RegistrationCallback); |
+ |
+ RawPtrWillBePersistent<LinkLoaderClient> m_client; |
+}; |
+ |
+} |
+ |
+void FrameLoaderClientImpl::registerServiceWorker(const KURL& scriptURL, const String& scope, LinkLoaderClient* client) |
+{ |
+ if (!client->shouldLoadLink()) |
+ return; |
+ |
+ Document* document = m_webFrame->frame()->document(); |
+ KURL scopeURL; |
+ if (scope.isNull()) |
+ scopeURL = KURL(scriptURL, "./"); |
+ else |
+ scopeURL = document->completeURL(scope); |
+ scopeURL.removeFragmentIdentifier(); |
+ |
+ TrackExceptionState exceptionState; |
+ NavigatorServiceWorker::serviceWorker(document, *m_webFrame->frame()->domWindow()->navigator(), exceptionState)->registerServiceWorkerImpl(document, scriptURL, scopeURL, adoptPtr(new RegistrationCallback(client))); |
+} |
+ |
} // namespace blink |