| 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" |
| 11 #include "bindings/core/v8/V8Binding.h" | 11 #include "bindings/core/v8/V8Binding.h" |
| 12 #include "bindings/core/v8/V8ErrorEvent.h" |
| 12 #include "core/dom/ExecutionContext.h" | 13 #include "core/dom/ExecutionContext.h" |
| 14 #include "core/events/ErrorEvent.h" |
| 13 #include "platform/NotImplemented.h" | 15 #include "platform/NotImplemented.h" |
| 14 #include "public/platform/WebServiceWorkerEventResult.h" | 16 #include "public/platform/WebServiceWorkerEventResult.h" |
| 15 #include "wtf/Assertions.h" | 17 #include "wtf/Assertions.h" |
| 16 #include "wtf/RefCounted.h" | 18 #include "wtf/RefCounted.h" |
| 17 #include "wtf/RefPtr.h" | 19 #include "wtf/RefPtr.h" |
| 20 #include "core/workers/WorkerGlobalScope.h" |
| 21 #include "core/workers/WorkerThread.h" |
| 22 #include "core/workers/WorkerReportingProxy.h" |
| 23 #include "core/dom/ExecutionContext.h" |
| 18 #include <v8.h> | 24 #include <v8.h> |
| 19 | 25 |
| 26 #include "base/logging.h" |
| 27 |
| 20 namespace blink { | 28 namespace blink { |
| 21 | 29 |
| 22 class WaitUntilObserver::ThenFunction FINAL : public ScriptFunction { | 30 class WaitUntilObserver::ThenFunction FINAL : public ScriptFunction { |
| 23 public: | 31 public: |
| 24 enum ResolveType { | 32 enum ResolveType { |
| 25 Fulfilled, | 33 Fulfilled, |
| 26 Rejected, | 34 Rejected, |
| 27 }; | 35 }; |
| 28 | 36 |
| 29 static v8::Handle<v8::Function> createFunction(ScriptState* scriptState, Wai
tUntilObserver* observer, ResolveType type) | 37 static v8::Handle<v8::Function> createFunction(ScriptState* scriptState, Wai
tUntilObserver* observer, ResolveType type) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 : ContextLifecycleObserver(context) | 96 : ContextLifecycleObserver(context) |
| 89 , m_type(type) | 97 , m_type(type) |
| 90 , m_eventID(eventID) | 98 , m_eventID(eventID) |
| 91 , m_pendingActivity(0) | 99 , m_pendingActivity(0) |
| 92 , m_hasError(false) | 100 , m_hasError(false) |
| 93 { | 101 { |
| 94 } | 102 } |
| 95 | 103 |
| 96 void WaitUntilObserver::reportError(const ScriptValue& value) | 104 void WaitUntilObserver::reportError(const ScriptValue& value) |
| 97 { | 105 { |
| 98 // FIXME: Propagate error message to the client for onerror handling. | 106 VLOG(1) <<__FUNCTION__; |
| 99 notImplemented(); | 107 if(V8ErrorEvent::hasInstance(value.v8Value(), toIsolate(executionContext()))
) { |
| 108 ErrorEvent* errEvent = V8ErrorEvent::toImplWithTypeCheck(toIsolate(execu
tionContext()), value.v8Value()); |
| 109 toWorkerGlobalScope(executionContext())->thread()->workerReportingProxy(
) |
| 110 .reportException(errEvent->message(), |
| 111 errEvent->lineno(), |
| 112 errEvent->colno(), |
| 113 errEvent->filename()); |
| 114 VLOG(1) << errEvent->message().ascii().data(); |
| 115 VLOG(1) << errEvent->filename().ascii().data()<< " : "<< errEvent->linen
o() << " : " << errEvent->colno(); |
| 116 } |
| 100 | 117 |
| 101 m_hasError = true; | 118 m_hasError = true; |
| 102 } | 119 } |
| 103 | 120 |
| 104 void WaitUntilObserver::incrementPendingActivity() | 121 void WaitUntilObserver::incrementPendingActivity() |
| 105 { | 122 { |
| 106 ++m_pendingActivity; | 123 ++m_pendingActivity; |
| 107 } | 124 } |
| 108 | 125 |
| 109 void WaitUntilObserver::decrementPendingActivity() | 126 void WaitUntilObserver::decrementPendingActivity() |
| 110 { | 127 { |
| 111 ASSERT(m_pendingActivity > 0); | 128 ASSERT(m_pendingActivity > 0); |
| 112 if (!executionContext() || (!m_hasError && --m_pendingActivity)) | 129 if (!executionContext() || (!m_hasError && --m_pendingActivity)) |
| 113 return; | 130 return; |
| 114 | 131 |
| 115 ServiceWorkerGlobalScopeClient* client = ServiceWorkerGlobalScopeClient::fro
m(executionContext()); | 132 ServiceWorkerGlobalScopeClient* client = ServiceWorkerGlobalScopeClient::fro
m(executionContext()); |
| 116 WebServiceWorkerEventResult result = m_hasError ? WebServiceWorkerEventResul
tRejected : WebServiceWorkerEventResultCompleted; | 133 WebServiceWorkerEventResult result = m_hasError ? WebServiceWorkerEventResul
tRejected : WebServiceWorkerEventResultCompleted; |
| 117 switch (m_type) { | 134 switch (m_type) { |
| 118 case Activate: | 135 case Activate: |
| 119 client->didHandleActivateEvent(m_eventID, result); | 136 client->didHandleActivateEvent(m_eventID, result); |
| 120 break; | 137 break; |
| 121 case Install: | 138 case Install: |
| 122 client->didHandleInstallEvent(m_eventID, result); | 139 client->didHandleInstallEvent(m_eventID, result); |
| 123 break; | 140 break; |
| 124 } | 141 } |
| 125 observeContext(0); | 142 observeContext(0); |
| 126 } | 143 } |
| 127 | 144 |
| 128 } // namespace blink | 145 } // namespace blink |
| OLD | NEW |