Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: Source/modules/serviceworkers/WaitUntilObserver.cpp

Issue 901663005: Revert r189385 "Remove LifecycleContext" and r189391, r189530, r189456 that block it (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/modules/serviceworkers/WaitUntilObserver.h ('k') | Source/platform/LifecycleContext.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 or opened. Regardless of whether such action happened, 95 // be focused. Regardless of whether one window was focused,
96 // |consumeWindowInteraction| will be called when all the pending activities 96 // |consumeWindowFocus| will be called when all the pending activities will
97 // will be resolved or after a 97 // be resolved.
98 if (m_type == NotificationClick) { 98 if (m_type == NotificationClick)
99 executionContext()->allowWindowInteraction(); 99 executionContext()->allowWindowFocus();
100 m_consumeWindowInteractionTimer.startOneShot(ServiceWorkerGlobalScope::k WindowInteractionTimeout, FROM_HERE);
101 }
102 100
103 incrementPendingActivity(); 101 incrementPendingActivity();
104 ScriptPromise::cast(scriptState, value).then( 102 ScriptPromise::cast(scriptState, value).then(
105 ThenFunction::createFunction(scriptState, this, ThenFunction::Fulfilled) , 103 ThenFunction::createFunction(scriptState, this, ThenFunction::Fulfilled) ,
106 ThenFunction::createFunction(scriptState, this, ThenFunction::Rejected)) ; 104 ThenFunction::createFunction(scriptState, this, ThenFunction::Rejected)) ;
107 } 105 }
108 106
109 WaitUntilObserver::WaitUntilObserver(ExecutionContext* context, EventType type, int eventID) 107 WaitUntilObserver::WaitUntilObserver(ExecutionContext* context, EventType type, int eventID)
110 : ContextLifecycleObserver(context) 108 : ContextLifecycleObserver(context)
111 , m_type(type) 109 , m_type(type)
112 , m_eventID(eventID) 110 , m_eventID(eventID)
113 , m_pendingActivity(0) 111 , m_pendingActivity(0)
114 , m_hasError(false) 112 , m_hasError(false)
115 , m_eventDispatched(false) 113 , m_eventDispatched(false)
116 , m_consumeWindowInteractionTimer(this, &WaitUntilObserver::consumeWindowInt eraction)
117 { 114 {
118 } 115 }
119 116
120 void WaitUntilObserver::reportError(const ScriptValue& value) 117 void WaitUntilObserver::reportError(const ScriptValue& value)
121 { 118 {
122 // FIXME: Propagate error message to the client for onerror handling. 119 // FIXME: Propagate error message to the client for onerror handling.
123 notImplemented(); 120 notImplemented();
124 121
125 m_hasError = true; 122 m_hasError = true;
126 } 123 }
(...skipping 13 matching lines...) Expand all
140 WebServiceWorkerEventResult result = m_hasError ? WebServiceWorkerEventResul tRejected : WebServiceWorkerEventResultCompleted; 137 WebServiceWorkerEventResult result = m_hasError ? WebServiceWorkerEventResul tRejected : WebServiceWorkerEventResultCompleted;
141 switch (m_type) { 138 switch (m_type) {
142 case Activate: 139 case Activate:
143 client->didHandleActivateEvent(m_eventID, result); 140 client->didHandleActivateEvent(m_eventID, result);
144 break; 141 break;
145 case Install: 142 case Install:
146 client->didHandleInstallEvent(m_eventID, result); 143 client->didHandleInstallEvent(m_eventID, result);
147 break; 144 break;
148 case NotificationClick: 145 case NotificationClick:
149 client->didHandleNotificationClickEvent(m_eventID, result); 146 client->didHandleNotificationClickEvent(m_eventID, result);
150 m_consumeWindowInteractionTimer.stop(); 147 executionContext()->consumeWindowFocus();
151 consumeWindowInteraction(nullptr);
152 break; 148 break;
153 case Push: 149 case Push:
154 client->didHandlePushEvent(m_eventID, result); 150 client->didHandlePushEvent(m_eventID, result);
155 break; 151 break;
156 } 152 }
157 setContext(nullptr); 153 observeContext(0);
158 }
159
160 void WaitUntilObserver::consumeWindowInteraction(Timer<WaitUntilObserver>*)
161 {
162 if (!executionContext())
163 return;
164 executionContext()->consumeWindowInteraction();
165 } 154 }
166 155
167 void WaitUntilObserver::trace(Visitor* visitor) 156 void WaitUntilObserver::trace(Visitor* visitor)
168 { 157 {
169 ContextLifecycleObserver::trace(visitor); 158 ContextLifecycleObserver::trace(visitor);
170 } 159 }
171 160
172 } // namespace blink 161 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/serviceworkers/WaitUntilObserver.h ('k') | Source/platform/LifecycleContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698