| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "modules/background_sync/SyncManager.h" | 6 #include "modules/background_sync/SyncManager.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 8 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
| 9 #include "bindings/core/v8/ScriptPromise.h" | 9 #include "bindings/core/v8/ScriptPromise.h" |
| 10 #include "bindings/core/v8/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 { | 39 { |
| 40 ASSERT(registration); | 40 ASSERT(registration); |
| 41 } | 41 } |
| 42 | 42 |
| 43 ScriptPromise SyncManager::registerFunction(ScriptState* scriptState, ExecutionC
ontext* context, const String& tag) | 43 ScriptPromise SyncManager::registerFunction(ScriptState* scriptState, ExecutionC
ontext* context, const String& tag) |
| 44 { | 44 { |
| 45 // TODO(jkarlin): Wait for the registration to become active instead of reje
cting. See crbug.com/542437. | 45 // TODO(jkarlin): Wait for the registration to become active instead of reje
cting. See crbug.com/542437. |
| 46 if (!m_registration->active()) | 46 if (!m_registration->active()) |
| 47 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "Registration failed - no active Service Worker")); | 47 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(AbortError, "Registration failed - no active Service Worker")); |
| 48 | 48 |
| 49 if (scriptState->executionContext()->isDocument()) { |
| 50 Document* document = toDocument(scriptState->executionContext()); |
| 51 if (!document->domWindow() || !document->frame()) |
| 52 return ScriptPromise::rejectWithDOMException(scriptState, DOMExcepti
on::create(InvalidStateError, "Document is detached from window.")); |
| 53 if (!document->frame()->isMainFrame()) |
| 54 return ScriptPromise::rejectWithDOMException(scriptState, DOMExcepti
on::create(AbortError, "Registration failed - not called from a main frame.")); |
| 55 } |
| 56 |
| 49 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 57 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 50 ScriptPromise promise = resolver->promise(); | 58 ScriptPromise promise = resolver->promise(); |
| 51 | 59 |
| 52 WebSyncRegistration* webSyncRegistration = new WebSyncRegistration( | 60 WebSyncRegistration* webSyncRegistration = new WebSyncRegistration( |
| 53 WebSyncRegistration::UNREGISTERED_SYNC_ID /* id */, | 61 WebSyncRegistration::UNREGISTERED_SYNC_ID /* id */, |
| 54 WebSyncRegistration::PeriodicityOneShot, | 62 WebSyncRegistration::PeriodicityOneShot, |
| 55 tag, | 63 tag, |
| 56 0 /* minPeriod */, | 64 0 /* minPeriod */, |
| 57 WebSyncRegistration::NetworkStateOnline /* networkState */, | 65 WebSyncRegistration::NetworkStateOnline /* networkState */, |
| 58 WebSyncRegistration::PowerStateAuto /* powerState */ | 66 WebSyncRegistration::PowerStateAuto /* powerState */ |
| (...skipping 12 matching lines...) Expand all Loading... |
| 71 | 79 |
| 72 return promise; | 80 return promise; |
| 73 } | 81 } |
| 74 | 82 |
| 75 DEFINE_TRACE(SyncManager) | 83 DEFINE_TRACE(SyncManager) |
| 76 { | 84 { |
| 77 visitor->trace(m_registration); | 85 visitor->trace(m_registration); |
| 78 } | 86 } |
| 79 | 87 |
| 80 } // namespace blink | 88 } // namespace blink |
| OLD | NEW |