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 "config.h" | 5 #include "config.h" |
6 #include "modules/serviceworkers/WaitUntilObserver.h" | 6 #include "modules/serviceworkers/WaitUntilObserver.h" |
7 | 7 |
8 #include "bindings/core/v8/ScriptFunction.h" | 8 #include "bindings/core/v8/ScriptFunction.h" |
9 #include "bindings/core/v8/ScriptPromise.h" | 9 #include "bindings/core/v8/ScriptPromise.h" |
10 #include "bindings/core/v8/ScriptValue.h" | 10 #include "bindings/core/v8/ScriptValue.h" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 { | 85 { |
86 if (m_eventDispatched) { | 86 if (m_eventDispatched) { |
87 exceptionState.throwDOMException(InvalidStateError, "The event handler i
s already finished."); | 87 exceptionState.throwDOMException(InvalidStateError, "The event handler i
s already finished."); |
88 return; | 88 return; |
89 } | 89 } |
90 | 90 |
91 if (!executionContext()) | 91 if (!executionContext()) |
92 return; | 92 return; |
93 | 93 |
94 // When handling a notificationclick event, we want to allow one window to | 94 // When handling a notificationclick event, we want to allow one window to |
95 // be focused. Regardless of whether one window was focused, | 95 // be focused or opened. Regardless of whether such action happened, |
96 // |consumeWindowFocus| will be called when all the pending activities will | 96 // |consumeWindowInteraction| will be called when all the pending activities |
97 // be resolved. | 97 // will be resolved or after a |
98 if (m_type == NotificationClick) | 98 if (m_type == NotificationClick) { |
99 executionContext()->allowWindowFocus(); | 99 executionContext()->allowWindowInteraction(); |
| 100 m_consumeWindowInteractionTimer.startOneShot(ServiceWorkerGlobalScope::k
WindowInteractionTimeout, FROM_HERE); |
| 101 } |
100 | 102 |
101 incrementPendingActivity(); | 103 incrementPendingActivity(); |
102 ScriptPromise::cast(scriptState, value).then( | 104 ScriptPromise::cast(scriptState, value).then( |
103 ThenFunction::createFunction(scriptState, this, ThenFunction::Fulfilled)
, | 105 ThenFunction::createFunction(scriptState, this, ThenFunction::Fulfilled)
, |
104 ThenFunction::createFunction(scriptState, this, ThenFunction::Rejected))
; | 106 ThenFunction::createFunction(scriptState, this, ThenFunction::Rejected))
; |
105 } | 107 } |
106 | 108 |
107 WaitUntilObserver::WaitUntilObserver(ExecutionContext* context, EventType type,
int eventID) | 109 WaitUntilObserver::WaitUntilObserver(ExecutionContext* context, EventType type,
int eventID) |
108 : ContextLifecycleObserver(context) | 110 : ContextLifecycleObserver(context) |
109 , m_type(type) | 111 , m_type(type) |
110 , m_eventID(eventID) | 112 , m_eventID(eventID) |
111 , m_pendingActivity(0) | 113 , m_pendingActivity(0) |
112 , m_hasError(false) | 114 , m_hasError(false) |
113 , m_eventDispatched(false) | 115 , m_eventDispatched(false) |
| 116 , m_consumeWindowInteractionTimer(this, &WaitUntilObserver::consumeWindowInt
eraction) |
114 { | 117 { |
115 } | 118 } |
116 | 119 |
117 void WaitUntilObserver::reportError(const ScriptValue& value) | 120 void WaitUntilObserver::reportError(const ScriptValue& value) |
118 { | 121 { |
119 // FIXME: Propagate error message to the client for onerror handling. | 122 // FIXME: Propagate error message to the client for onerror handling. |
120 notImplemented(); | 123 notImplemented(); |
121 | 124 |
122 m_hasError = true; | 125 m_hasError = true; |
123 } | 126 } |
(...skipping 13 matching lines...) Expand all Loading... |
137 WebServiceWorkerEventResult result = m_hasError ? WebServiceWorkerEventResul
tRejected : WebServiceWorkerEventResultCompleted; | 140 WebServiceWorkerEventResult result = m_hasError ? WebServiceWorkerEventResul
tRejected : WebServiceWorkerEventResultCompleted; |
138 switch (m_type) { | 141 switch (m_type) { |
139 case Activate: | 142 case Activate: |
140 client->didHandleActivateEvent(m_eventID, result); | 143 client->didHandleActivateEvent(m_eventID, result); |
141 break; | 144 break; |
142 case Install: | 145 case Install: |
143 client->didHandleInstallEvent(m_eventID, result); | 146 client->didHandleInstallEvent(m_eventID, result); |
144 break; | 147 break; |
145 case NotificationClick: | 148 case NotificationClick: |
146 client->didHandleNotificationClickEvent(m_eventID, result); | 149 client->didHandleNotificationClickEvent(m_eventID, result); |
147 executionContext()->consumeWindowFocus(); | 150 m_consumeWindowInteractionTimer.stop(); |
| 151 consumeWindowInteraction(nullptr); |
148 break; | 152 break; |
149 case Push: | 153 case Push: |
150 client->didHandlePushEvent(m_eventID, result); | 154 client->didHandlePushEvent(m_eventID, result); |
151 break; | 155 break; |
152 } | 156 } |
153 observeContext(0); | 157 observeContext(0); |
154 } | 158 } |
155 | 159 |
| 160 void WaitUntilObserver::consumeWindowInteraction(Timer<WaitUntilObserver>*) |
| 161 { |
| 162 if (!executionContext()) |
| 163 return; |
| 164 executionContext()->consumeWindowInteraction(); |
| 165 } |
| 166 |
156 void WaitUntilObserver::trace(Visitor* visitor) | 167 void WaitUntilObserver::trace(Visitor* visitor) |
157 { | 168 { |
158 ContextLifecycleObserver::trace(visitor); | 169 ContextLifecycleObserver::trace(visitor); |
159 } | 170 } |
160 | 171 |
161 } // namespace blink | 172 } // namespace blink |
OLD | NEW |