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/v8/ScriptFunction.h" | 8 #include "bindings/v8/ScriptFunction.h" |
9 #include "bindings/v8/ScriptPromise.h" | 9 #include "bindings/v8/ScriptPromise.h" |
10 #include "bindings/v8/ScriptValue.h" | 10 #include "bindings/v8/ScriptValue.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 m_observer->reportError(value); | 46 m_observer->reportError(value); |
47 m_observer->decrementPendingActivity(); | 47 m_observer->decrementPendingActivity(); |
48 m_observer = nullptr; | 48 m_observer = nullptr; |
49 return value; | 49 return value; |
50 } | 50 } |
51 | 51 |
52 RefPtr<WaitUntilObserver> m_observer; | 52 RefPtr<WaitUntilObserver> m_observer; |
53 ResolveType m_resolveType; | 53 ResolveType m_resolveType; |
54 }; | 54 }; |
55 | 55 |
56 PassRefPtr<WaitUntilObserver> WaitUntilObserver::create(ExecutionContext* contex
t, int eventID) | 56 PassRefPtr<WaitUntilObserver> WaitUntilObserver::create(ExecutionContext* contex
t, EventType type, int eventID) |
57 { | 57 { |
58 return adoptRef(new WaitUntilObserver(context, eventID)); | 58 return adoptRef(new WaitUntilObserver(context, type, eventID)); |
59 } | 59 } |
60 | 60 |
61 WaitUntilObserver::~WaitUntilObserver() | 61 WaitUntilObserver::~WaitUntilObserver() |
62 { | 62 { |
63 ASSERT(!m_pendingActivity); | 63 ASSERT(!m_pendingActivity); |
64 } | 64 } |
65 | 65 |
66 void WaitUntilObserver::willDispatchEvent() | 66 void WaitUntilObserver::willDispatchEvent() |
67 { | 67 { |
68 incrementPendingActivity(); | 68 incrementPendingActivity(); |
69 } | 69 } |
70 | 70 |
71 void WaitUntilObserver::didDispatchEvent() | 71 void WaitUntilObserver::didDispatchEvent() |
72 { | 72 { |
73 decrementPendingActivity(); | 73 decrementPendingActivity(); |
74 } | 74 } |
75 | 75 |
76 void WaitUntilObserver::waitUntil(const ScriptValue& value) | 76 void WaitUntilObserver::waitUntil(const ScriptValue& value) |
77 { | 77 { |
78 incrementPendingActivity(); | 78 incrementPendingActivity(); |
79 ScriptPromise::cast(value).then( | 79 ScriptPromise::cast(value).then( |
80 ThenFunction::create(this, ThenFunction::Fulfilled), | 80 ThenFunction::create(this, ThenFunction::Fulfilled), |
81 ThenFunction::create(this, ThenFunction::Rejected)); | 81 ThenFunction::create(this, ThenFunction::Rejected)); |
82 } | 82 } |
83 | 83 |
84 WaitUntilObserver::WaitUntilObserver(ExecutionContext* context, int eventID) | 84 WaitUntilObserver::WaitUntilObserver(ExecutionContext* context, EventType type,
int eventID) |
85 : ContextLifecycleObserver(context) | 85 : ContextLifecycleObserver(context) |
| 86 , m_type(type) |
86 , m_eventID(eventID) | 87 , m_eventID(eventID) |
87 , m_pendingActivity(0) | 88 , m_pendingActivity(0) |
88 , m_hasError(false) | 89 , m_hasError(false) |
89 { | 90 { |
90 } | 91 } |
91 | 92 |
92 void WaitUntilObserver::reportError(const ScriptValue& value) | 93 void WaitUntilObserver::reportError(const ScriptValue& value) |
93 { | 94 { |
94 // FIXME: Propagate error message to the client for onerror handling. | 95 // FIXME: Propagate error message to the client for onerror handling. |
95 notImplemented(); | 96 notImplemented(); |
96 | 97 |
97 m_hasError = true; | 98 m_hasError = true; |
98 } | 99 } |
99 | 100 |
100 void WaitUntilObserver::incrementPendingActivity() | 101 void WaitUntilObserver::incrementPendingActivity() |
101 { | 102 { |
102 ++m_pendingActivity; | 103 ++m_pendingActivity; |
103 } | 104 } |
104 | 105 |
105 void WaitUntilObserver::decrementPendingActivity() | 106 void WaitUntilObserver::decrementPendingActivity() |
106 { | 107 { |
107 ASSERT(m_pendingActivity > 0); | 108 ASSERT(m_pendingActivity > 0); |
108 if (--m_pendingActivity || !executionContext()) | 109 if (--m_pendingActivity || !executionContext()) |
109 return; | 110 return; |
110 | 111 |
| 112 ServiceWorkerGlobalScopeClient* client = ServiceWorkerGlobalScopeClient::fro
m(executionContext()); |
111 blink::WebServiceWorkerEventResult result = m_hasError ? blink::WebServiceWo
rkerEventResultRejected : blink::WebServiceWorkerEventResultCompleted; | 113 blink::WebServiceWorkerEventResult result = m_hasError ? blink::WebServiceWo
rkerEventResultRejected : blink::WebServiceWorkerEventResultCompleted; |
112 ServiceWorkerGlobalScopeClient::from(executionContext())->didHandleInstallEv
ent(m_eventID, result); | 114 switch (m_type) { |
| 115 case Activate: |
| 116 client->didHandleActivateEvent(m_eventID, result); |
| 117 break; |
| 118 case Install: |
| 119 client->didHandleInstallEvent(m_eventID, result); |
| 120 break; |
| 121 } |
113 observeContext(0); | 122 observeContext(0); |
114 } | 123 } |
115 | 124 |
116 } // namespace WebCore | 125 } // namespace WebCore |
OLD | NEW |