| 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/WaitUntilObserver.h" | 5 #include "modules/serviceworkers/WaitUntilObserver.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptFunction.h" | 7 #include "bindings/core/v8/ScriptFunction.h" |
| 8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
| 9 #include "bindings/core/v8/ScriptValue.h" | 9 #include "bindings/core/v8/ScriptValue.h" |
| 10 #include "bindings/core/v8/V8Binding.h" | 10 #include "bindings/core/v8/V8Binding.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 , m_resolveType(type) | 62 , m_resolveType(type) |
| 63 { | 63 { |
| 64 } | 64 } |
| 65 | 65 |
| 66 ScriptValue call(ScriptValue value) override | 66 ScriptValue call(ScriptValue value) override |
| 67 { | 67 { |
| 68 ASSERT(m_observer); | 68 ASSERT(m_observer); |
| 69 ASSERT(m_resolveType == Fulfilled || m_resolveType == Rejected); | 69 ASSERT(m_resolveType == Fulfilled || m_resolveType == Rejected); |
| 70 if (m_resolveType == Rejected) { | 70 if (m_resolveType == Rejected) { |
| 71 m_observer->reportError(value); | 71 m_observer->reportError(value); |
| 72 value = ScriptPromise::reject(value.scriptState(), value).getScriptV
alue(); | 72 value = ScriptPromise::reject(value.getScriptState(), value).getScri
ptValue(); |
| 73 } | 73 } |
| 74 m_observer->decrementPendingActivity(); | 74 m_observer->decrementPendingActivity(); |
| 75 m_observer = nullptr; | 75 m_observer = nullptr; |
| 76 return value; | 76 return value; |
| 77 } | 77 } |
| 78 | 78 |
| 79 Member<WaitUntilObserver> m_observer; | 79 Member<WaitUntilObserver> m_observer; |
| 80 ResolveType m_resolveType; | 80 ResolveType m_resolveType; |
| 81 }; | 81 }; |
| 82 | 82 |
| 83 WaitUntilObserver* WaitUntilObserver::create(ExecutionContext* context, EventTyp
e type, int eventID) | 83 WaitUntilObserver* WaitUntilObserver::create(ExecutionContext* context, EventTyp
e type, int eventID) |
| 84 { | 84 { |
| 85 return new WaitUntilObserver(context, type, eventID); | 85 return new WaitUntilObserver(context, type, eventID); |
| 86 } | 86 } |
| 87 | 87 |
| 88 void WaitUntilObserver::willDispatchEvent() | 88 void WaitUntilObserver::willDispatchEvent() |
| 89 { | 89 { |
| 90 // When handling a notificationclick event, we want to allow one window to | 90 // When handling a notificationclick event, we want to allow one window to |
| 91 // be focused or opened. These calls are allowed between the call to | 91 // be focused or opened. These calls are allowed between the call to |
| 92 // willDispatchEvent() and the last call to decrementPendingActivity(). If | 92 // willDispatchEvent() and the last call to decrementPendingActivity(). If |
| 93 // waitUntil() isn't called, that means between willDispatchEvent() and | 93 // waitUntil() isn't called, that means between willDispatchEvent() and |
| 94 // didDispatchEvent(). | 94 // didDispatchEvent(). |
| 95 if (m_type == NotificationClick) | 95 if (m_type == NotificationClick) |
| 96 executionContext()->allowWindowInteraction(); | 96 getExecutionContext()->allowWindowInteraction(); |
| 97 | 97 |
| 98 incrementPendingActivity(); | 98 incrementPendingActivity(); |
| 99 } | 99 } |
| 100 | 100 |
| 101 void WaitUntilObserver::didDispatchEvent(bool errorOccurred) | 101 void WaitUntilObserver::didDispatchEvent(bool errorOccurred) |
| 102 { | 102 { |
| 103 if (errorOccurred) | 103 if (errorOccurred) |
| 104 m_hasError = true; | 104 m_hasError = true; |
| 105 decrementPendingActivity(); | 105 decrementPendingActivity(); |
| 106 m_eventDispatched = true; | 106 m_eventDispatched = true; |
| 107 } | 107 } |
| 108 | 108 |
| 109 void WaitUntilObserver::waitUntil(ScriptState* scriptState, ScriptPromise script
Promise, ExceptionState& exceptionState) | 109 void WaitUntilObserver::waitUntil(ScriptState* scriptState, ScriptPromise script
Promise, ExceptionState& exceptionState) |
| 110 { | 110 { |
| 111 if (m_eventDispatched) { | 111 if (m_eventDispatched) { |
| 112 exceptionState.throwDOMException(InvalidStateError, "The event handler i
s already finished."); | 112 exceptionState.throwDOMException(InvalidStateError, "The event handler i
s already finished."); |
| 113 return; | 113 return; |
| 114 } | 114 } |
| 115 | 115 |
| 116 if (!executionContext()) | 116 if (!getExecutionContext()) |
| 117 return; | 117 return; |
| 118 | 118 |
| 119 // When handling a notificationclick event, we want to allow one window to | 119 // When handling a notificationclick event, we want to allow one window to |
| 120 // be focused or opened. See comments in ::willDispatchEvent(). When | 120 // be focused or opened. See comments in ::willDispatchEvent(). When |
| 121 // waitUntil() is being used, opening or closing a window must happen in a | 121 // waitUntil() is being used, opening or closing a window must happen in a |
| 122 // timeframe specified by windowInteractionTimeout(), otherwise the calls | 122 // timeframe specified by windowInteractionTimeout(), otherwise the calls |
| 123 // will fail. | 123 // will fail. |
| 124 if (m_type == NotificationClick) | 124 if (m_type == NotificationClick) |
| 125 m_consumeWindowInteractionTimer.startOneShot(windowInteractionTimeout(),
BLINK_FROM_HERE); | 125 m_consumeWindowInteractionTimer.startOneShot(windowInteractionTimeout(),
BLINK_FROM_HERE); |
| 126 | 126 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 150 } | 150 } |
| 151 | 151 |
| 152 void WaitUntilObserver::incrementPendingActivity() | 152 void WaitUntilObserver::incrementPendingActivity() |
| 153 { | 153 { |
| 154 ++m_pendingActivity; | 154 ++m_pendingActivity; |
| 155 } | 155 } |
| 156 | 156 |
| 157 void WaitUntilObserver::decrementPendingActivity() | 157 void WaitUntilObserver::decrementPendingActivity() |
| 158 { | 158 { |
| 159 ASSERT(m_pendingActivity > 0); | 159 ASSERT(m_pendingActivity > 0); |
| 160 if (!executionContext() || (!m_hasError && --m_pendingActivity)) | 160 if (!getExecutionContext() || (!m_hasError && --m_pendingActivity)) |
| 161 return; | 161 return; |
| 162 | 162 |
| 163 ServiceWorkerGlobalScopeClient* client = ServiceWorkerGlobalScopeClient::fro
m(executionContext()); | 163 ServiceWorkerGlobalScopeClient* client = ServiceWorkerGlobalScopeClient::fro
m(getExecutionContext()); |
| 164 WebServiceWorkerEventResult result = m_hasError ? WebServiceWorkerEventResul
tRejected : WebServiceWorkerEventResultCompleted; | 164 WebServiceWorkerEventResult result = m_hasError ? WebServiceWorkerEventResul
tRejected : WebServiceWorkerEventResultCompleted; |
| 165 switch (m_type) { | 165 switch (m_type) { |
| 166 case Activate: | 166 case Activate: |
| 167 client->didHandleActivateEvent(m_eventID, result); | 167 client->didHandleActivateEvent(m_eventID, result); |
| 168 break; | 168 break; |
| 169 case Install: | 169 case Install: |
| 170 client->didHandleInstallEvent(m_eventID, result); | 170 client->didHandleInstallEvent(m_eventID, result); |
| 171 break; | 171 break; |
| 172 case Message: | 172 case Message: |
| 173 client->didHandleExtendableMessageEvent(m_eventID, result); | 173 client->didHandleExtendableMessageEvent(m_eventID, result); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 185 break; | 185 break; |
| 186 case Sync: | 186 case Sync: |
| 187 client->didHandleSyncEvent(m_eventID, result); | 187 client->didHandleSyncEvent(m_eventID, result); |
| 188 break; | 188 break; |
| 189 } | 189 } |
| 190 setContext(nullptr); | 190 setContext(nullptr); |
| 191 } | 191 } |
| 192 | 192 |
| 193 void WaitUntilObserver::consumeWindowInteraction(Timer<WaitUntilObserver>*) | 193 void WaitUntilObserver::consumeWindowInteraction(Timer<WaitUntilObserver>*) |
| 194 { | 194 { |
| 195 if (!executionContext()) | 195 if (!getExecutionContext()) |
| 196 return; | 196 return; |
| 197 executionContext()->consumeWindowInteraction(); | 197 getExecutionContext()->consumeWindowInteraction(); |
| 198 } | 198 } |
| 199 | 199 |
| 200 DEFINE_TRACE(WaitUntilObserver) | 200 DEFINE_TRACE(WaitUntilObserver) |
| 201 { | 201 { |
| 202 ContextLifecycleObserver::trace(visitor); | 202 ContextLifecycleObserver::trace(visitor); |
| 203 } | 203 } |
| 204 | 204 |
| 205 } // namespace blink | 205 } // namespace blink |
| OLD | NEW |