Index: third_party/WebKit/Source/modules/background_sync/SyncManager.cpp |
diff --git a/third_party/WebKit/Source/modules/background_sync/SyncManager.cpp b/third_party/WebKit/Source/modules/background_sync/SyncManager.cpp |
index 459367201ca31b97e0398bf22db0b6e2233f7934..5f1ea85fc176221bc32320167018f84d4c877141 100644 |
--- a/third_party/WebKit/Source/modules/background_sync/SyncManager.cpp |
+++ b/third_party/WebKit/Source/modules/background_sync/SyncManager.cpp |
@@ -46,6 +46,14 @@ ScriptPromise SyncManager::registerFunction(ScriptState* scriptState, ExecutionC |
if (!m_registration->active()) |
return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(AbortError, "Registration failed - no active Service Worker")); |
+ if (scriptState->executionContext()->isDocument()) { |
+ Document* document = toDocument(scriptState->executionContext()); |
+ if (!document->domWindow() || !document->frame()) |
+ return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(InvalidStateError, "Document is detached from window.")); |
+ if (!document->frame()->isMainFrame()) |
+ return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(AbortError, "Registration failed - not called from a main frame.")); |
+ } |
+ |
ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
ScriptPromise promise = resolver->promise(); |