Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Unified Diff: Source/modules/serviceworkers/NavigatorServiceWorker.cpp

Issue 26078002: Rename WebServiceWorkerRegistry to WebServiceWorkerProvider (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: address comments Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/modules/serviceworkers/NavigatorServiceWorker.h ('k') | Source/web/FrameLoaderClientImpl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/serviceworkers/NavigatorServiceWorker.cpp
diff --git a/Source/modules/serviceworkers/NavigatorServiceWorker.cpp b/Source/modules/serviceworkers/NavigatorServiceWorker.cpp
index 172589dabc8495c7d21d80b0122b92f60e03ac66..4d583bf75811bcdc1c1eae90cdb6cb6dd442a8e3 100644
--- a/Source/modules/serviceworkers/NavigatorServiceWorker.cpp
+++ b/Source/modules/serviceworkers/NavigatorServiceWorker.cpp
@@ -34,6 +34,7 @@
#include "V8ServiceWorker.h"
#include "bindings/v8/ScriptPromiseResolver.h"
#include "core/dom/Document.h"
+#include "core/dom/ExceptionCode.h"
#include "core/loader/DocumentLoader.h"
#include "core/loader/FrameLoaderClient.h"
#include "core/page/Frame.h"
@@ -41,14 +42,19 @@
#include "core/workers/SharedWorker.h"
#include "modules/serviceworkers/CallbackPromiseAdapter.h"
#include "modules/serviceworkers/ServiceWorker.h"
-#include "public/platform/WebServiceWorkerRegistry.h"
+#include "public/platform/WebServiceWorkerProvider.h"
+#include "public/platform/WebServiceWorkerProviderClient.h"
#include "public/platform/WebString.h"
#include "public/platform/WebURL.h"
+using WebKit::WebServiceWorkerProvider;
+using WebKit::WebString;
+
namespace WebCore {
NavigatorServiceWorker::NavigatorServiceWorker(Navigator* navigator)
- : m_navigator(navigator)
+ : DOMWindowProperty(navigator->frame())
abarth-chromium 2013/10/11 19:02:41 Yeah, that's fine.
+ , m_navigator(navigator)
{
}
@@ -61,6 +67,19 @@ const char* NavigatorServiceWorker::supplementName()
return "NavigatorServiceWorker";
}
+WebServiceWorkerProvider* NavigatorServiceWorker::ensureProvider()
+{
+ if (!m_provider) {
+ Frame* frame = m_navigator->frame();
+ ASSERT(frame);
abarth-chromium 2013/10/11 19:02:41 I would move this ASSERT above the "if (!m_provide
+
+ FrameLoaderClient* client = frame->loader()->client();
+ // FIXME: This is temporarily hooked up here until we hook up to the loading process.
+ m_provider = client->createServiceWorkerProvider(nullptr);
+ }
+ return m_provider.get();
+}
+
NavigatorServiceWorker* NavigatorServiceWorker::from(Navigator* navigator)
{
NavigatorServiceWorker* supplement = toNavigatorServiceWorker(navigator);
@@ -76,21 +95,32 @@ ScriptPromise NavigatorServiceWorker::registerServiceWorker(ScriptExecutionConte
return from(navigator)->registerServiceWorker(context, pattern, url, es);
}
-
ScriptPromise NavigatorServiceWorker::registerServiceWorker(ScriptExecutionContext* scriptExecutionContext, const String& pattern, const String& scriptSrc, ExceptionState& es)
{
ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled());
- FrameLoaderClient* client = m_navigator->frame()->loader()->client();
- // WTF? Surely there's a better way to resolve a url?
- KURL scriptUrl = m_navigator->frame()->document()->completeURL(scriptSrc);
- WebKit::WebServiceWorkerRegistry* peer = client->serviceWorkerRegistry();
- RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptExecutionContext);
+ Frame* frame = m_navigator->frame();
+
+ if (!frame) {
+ es.throwDOMException(InvalidStateError, "No document available.");
+ return ScriptPromise();
+ }
+
+ RefPtr<SecurityOrigin> documentOrigin = frame->document()->securityOrigin();
+
+ KURL patternUrl = scriptExecutionContext->completeURL(pattern);
abarth-chromium 2013/10/11 19:02:41 patternUrl -> patternURL
+ if (documentOrigin->canRequest(patternUrl)) {
+ es.throwSecurityError("Can only register for patterns in the document's origin.");
+ return ScriptPromise();
+ }
- if (peer)
- peer->registerServiceWorker(pattern, scriptUrl, new CallbackPromiseAdapter(resolver, scriptExecutionContext));
- else
- resolver->reject(PassRefPtr<ServiceWorker>(0));
- // call here?
+ KURL scriptUrl = scriptExecutionContext->completeURL(scriptSrc);
abarth-chromium 2013/10/11 19:02:41 scriptUrl -> scriptURL (Notice, for example, that
+ if (documentOrigin->canRequest(scriptUrl)) {
+ es.throwSecurityError("Script must be in document's origin.");
+ return ScriptPromise();
+ }
+
+ RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptExecutionContext);
+ ensureProvider()->registerServiceWorker(patternUrl, scriptUrl, new CallbackPromiseAdapter(resolver, scriptExecutionContext));
return resolver->promise();
}
@@ -102,14 +132,30 @@ ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ScriptExecutionCon
ScriptPromise NavigatorServiceWorker::unregisterServiceWorker(ScriptExecutionContext* scriptExecutionContext, const String& pattern, ExceptionState& es)
{
ASSERT(RuntimeEnabledFeatures::serviceWorkerEnabled());
- FrameLoaderClient* client = m_navigator->frame()->loader()->client();
- WebKit::WebServiceWorkerRegistry* peer = client->serviceWorkerRegistry();
+ Frame* frame = m_navigator->frame();
+ if (!frame) {
+ es.throwDOMException(InvalidStateError, "No document available.");
+ return ScriptPromise();
+ }
+
+ RefPtr<SecurityOrigin> documentOrigin = frame->document()->securityOrigin();
+
+ KURL patternUrl = scriptExecutionContext->completeURL(pattern);
+ if (documentOrigin->canRequest(patternUrl)) {
+ es.throwSecurityError("Can only unregister for patterns in the document's origin.");
+ return ScriptPromise();
+ }
+
RefPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptExecutionContext);
- if (peer)
- peer->unregisterServiceWorker(pattern, new CallbackPromiseAdapter(resolver, scriptExecutionContext));
- else
- resolver->reject(PassRefPtr<ServiceWorker>(0));
+ ensureProvider()->unregisterServiceWorker(patternUrl, new CallbackPromiseAdapter(resolver, scriptExecutionContext));
return resolver->promise();
}
+void NavigatorServiceWorker::willDetachGlobalObjectFromFrame()
+{
+ m_provider = nullptr;
+ DOMWindowProperty::willDetachGlobalObjectFromFrame();
+}
+
+
} // namespace WebCore
« no previous file with comments | « Source/modules/serviceworkers/NavigatorServiceWorker.h ('k') | Source/web/FrameLoaderClientImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698