| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "modules/serviceworkers/ServiceWorkerRegistration.h" | 5 #include "modules/serviceworkers/ServiceWorkerRegistration.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
| 8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
| 9 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
| 10 #include "core/dom/DOMException.h" | 10 #include "core/dom/DOMException.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 return newRegistration; | 64 return newRegistration; |
| 65 } | 65 } |
| 66 | 66 |
| 67 String ServiceWorkerRegistration::scope() const | 67 String ServiceWorkerRegistration::scope() const |
| 68 { | 68 { |
| 69 return m_handle->registration()->scope().string(); | 69 return m_handle->registration()->scope().string(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 ScriptPromise ServiceWorkerRegistration::update(ScriptState* scriptState) | 72 ScriptPromise ServiceWorkerRegistration::update(ScriptState* scriptState) |
| 73 { | 73 { |
| 74 ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::from(ge
tExecutionContext()); |
| 75 if (!client || !client->provider()) |
| 76 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(InvalidStateError, "Failed to update a ServiceWorkerRegistration: No asso
ciated provider is available.")); |
| 77 |
| 74 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 78 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 75 ScriptPromise promise = resolver->promise(); | 79 ScriptPromise promise = resolver->promise(); |
| 76 | 80 m_handle->registration()->update(client->provider(), new CallbackPromiseAdap
ter<void, ServiceWorkerError>(resolver)); |
| 77 if (!m_provider) { | |
| 78 resolver->reject(DOMException::create(InvalidStateError, "Failed to upda
te a ServiceWorkerRegistration: No associated provider is available.")); | |
| 79 return promise; | |
| 80 } | |
| 81 | |
| 82 m_handle->registration()->update(m_provider, new CallbackPromiseAdapter<void
, ServiceWorkerError>(resolver)); | |
| 83 return promise; | 81 return promise; |
| 84 } | 82 } |
| 85 | 83 |
| 86 ScriptPromise ServiceWorkerRegistration::unregister(ScriptState* scriptState) | 84 ScriptPromise ServiceWorkerRegistration::unregister(ScriptState* scriptState) |
| 87 { | 85 { |
| 86 ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::from(ge
tExecutionContext()); |
| 87 if (!client || !client->provider()) |
| 88 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(InvalidStateError, "Failed to unregister a ServiceWorkerRegistration: No
associated provider is available.")); |
| 89 |
| 88 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 90 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 89 ScriptPromise promise = resolver->promise(); | 91 ScriptPromise promise = resolver->promise(); |
| 90 | 92 m_handle->registration()->unregister(client->provider(), new CallbackPromise
Adapter<bool, ServiceWorkerError>(resolver)); |
| 91 if (!m_provider) { | |
| 92 resolver->reject(DOMException::create(InvalidStateError, "Failed to unre
gister a ServiceWorkerRegistration: No associated provider is available.")); | |
| 93 return promise; | |
| 94 } | |
| 95 | |
| 96 m_handle->registration()->unregister(m_provider, new CallbackPromiseAdapter<
bool, ServiceWorkerError>(resolver)); | |
| 97 return promise; | 93 return promise; |
| 98 } | 94 } |
| 99 | 95 |
| 100 ServiceWorkerRegistration::ServiceWorkerRegistration(ExecutionContext* execution
Context, PassOwnPtr<WebServiceWorkerRegistration::Handle> handle) | 96 ServiceWorkerRegistration::ServiceWorkerRegistration(ExecutionContext* execution
Context, PassOwnPtr<WebServiceWorkerRegistration::Handle> handle) |
| 101 : ActiveScriptWrappable(this) | 97 : ActiveScriptWrappable(this) |
| 102 , ActiveDOMObject(executionContext) | 98 , ActiveDOMObject(executionContext) |
| 103 , m_handle(std::move(handle)) | 99 , m_handle(std::move(handle)) |
| 104 , m_provider(nullptr) | |
| 105 , m_stopped(false) | 100 , m_stopped(false) |
| 106 { | 101 { |
| 107 ASSERT(m_handle); | 102 ASSERT(m_handle); |
| 108 ASSERT(!m_handle->registration()->proxy()); | 103 ASSERT(!m_handle->registration()->proxy()); |
| 109 ThreadState::current()->registerPreFinalizer(this); | 104 ThreadState::current()->registerPreFinalizer(this); |
| 110 | 105 |
| 111 if (!executionContext) | 106 if (!executionContext) |
| 112 return; | 107 return; |
| 113 if (ServiceWorkerContainerClient* client = ServiceWorkerContainerClient::fro
m(executionContext)) | |
| 114 m_provider = client->provider(); | |
| 115 m_handle->registration()->setProxy(this); | 108 m_handle->registration()->setProxy(this); |
| 116 } | 109 } |
| 117 | 110 |
| 118 ServiceWorkerRegistration::~ServiceWorkerRegistration() | 111 ServiceWorkerRegistration::~ServiceWorkerRegistration() |
| 119 { | 112 { |
| 120 } | 113 } |
| 121 | 114 |
| 122 void ServiceWorkerRegistration::dispose() | 115 void ServiceWorkerRegistration::dispose() |
| 123 { | 116 { |
| 124 // Promptly clears a raw reference from content/ to an on-heap object | 117 // Promptly clears a raw reference from content/ to an on-heap object |
| (...skipping 18 matching lines...) Expand all Loading... |
| 143 | 136 |
| 144 void ServiceWorkerRegistration::stop() | 137 void ServiceWorkerRegistration::stop() |
| 145 { | 138 { |
| 146 if (m_stopped) | 139 if (m_stopped) |
| 147 return; | 140 return; |
| 148 m_stopped = true; | 141 m_stopped = true; |
| 149 m_handle->registration()->proxyStopped(); | 142 m_handle->registration()->proxyStopped(); |
| 150 } | 143 } |
| 151 | 144 |
| 152 } // namespace blink | 145 } // namespace blink |
| OLD | NEW |