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

Unified Diff: Source/bindings/common/AbstractScriptPromiseResolver.h

Issue 1532413002: Added Dartium changes onto 45.0.2454.104 (Closed) Base URL: http://src.chromium.org/blink/branches/chromium/2454
Patch Set: Created 5 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/bindings/common/AbstractScriptPromise.h ('k') | Source/bindings/common/AbstractScriptValue.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/common/AbstractScriptPromiseResolver.h
diff --git a/Source/bindings/common/AbstractScriptPromiseResolver.h b/Source/bindings/common/AbstractScriptPromiseResolver.h
new file mode 100644
index 0000000000000000000000000000000000000000..6d8246067710f47f53de132c1600d8bd86362ec4
--- /dev/null
+++ b/Source/bindings/common/AbstractScriptPromiseResolver.h
@@ -0,0 +1,157 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef AbstractScriptPromiseResolver_h
+#define AbstractScriptPromiseResolver_h
+
+#include "bindings/common/ScriptPromise.h"
+#include "bindings/common/ScriptState.h"
+#include "bindings/core/v8/ScopedPersistent.h"
+#include "bindings/core/v8/V8Binding.h"
+#include "core/dom/ActiveDOMObject.h"
+#include "core/dom/ExecutionContext.h"
+#include "platform/Timer.h"
+#include "wtf/RefCounted.h"
+#include "wtf/Vector.h"
+#include <v8.h>
+
+namespace blink {
+
+class BatteryManager;
+class Blob;
+class BooleanValue;
+class Cache;
+class Credential;
+class CryptoKey;
+class DOMError;
+class DOMException;
+class ExecutionContext;
+class FontFace;
+class FontFaceSet;
+class GeofencingRegion;
+class ImageBitmap;
+class MIDIAccess;
+class MediaKeySession;
+class MediaKeys;
+class PushRegistration;
+class Response;
+class Request;
+class ServiceWorker;
+class ServiceWorkerClient;
+class ServiceWorkerRegistration;
+class StorageInfo;
+
+#define PROMISE_RESOLUTION_TYPES_LIST(V) \
+ V(AtomicString) \
+ V(BatteryManager*) \
+ V(Cache*) \
+ V(Credential*) \
+ V(CryptoKey*) \
+ V(DOMError*) \
+ V(DOMException*) \
+ V(HeapVector<Member<GeofencingRegion> >) \
+ V(HeapVector<Member<ServiceWorkerClient> >) \
+ V(MIDIAccess*) \
+ V(MediaKeys*) \
+ V(PassRefPtr<ArrayBuffer>) \
+ V(PassRefPtr<BatteryManager>) \
+ V(PassRefPtr<MediaKeySession>) \
+ V(PassRefPtrWillBeRawPtr<Blob>) \
+ V(PassRefPtrWillBeRawPtr<DOMError>) \
+ V(PassRefPtrWillBeRawPtr<DOMException>) \
+ V(PassRefPtrWillBeRawPtr<FontFace>) \
+ V(PassRefPtrWillBeRawPtr<FontFaceSet>) \
+ V(PassRefPtrWillBeRawPtr<ImageBitmap>) \
+ V(PassRefPtrWillBeRawPtr<MIDIAccess>) \
+ V(PassRefPtrWillBeRawPtr<ServiceWorker>) \
+ V(PassRefPtrWillBeRawPtr<ServiceWorkerRegistration>) \
+ V(PushRegistration*) \
+ V(Response*) \
+ V(ScriptValue) \
+ V(ServiceWorker*) \
+ V(ServiceWorkerRegistration*) \
+ V(StorageInfo*) \
+ V(String) \
+ V(V8BoolType) \
+ V(V8UndefinedType) \
+ V(Vector<String>) \
+ V(WillBeHeapVector<RefPtrWillBeMember<FontFace> >) \
+ V(const char*) \
+ V(v8::Handle<v8::Value>) \
+ V(HeapVector<Member<Response> >) \
+ V(HeapVector<Member<Request> >) \
+
+// This class wraps v8::Promise::Resolver and provides the following
+// functionalities.
+// - A ScriptPromiseResolver retains a ScriptState. A caller
+// can call resolve or reject from outside of a V8 context.
+// - This class is an ActiveDOMObject and keeps track of the associated
+// ExecutionContext state. When the ExecutionContext is suspended,
+// resolve or reject will be delayed. When it is stopped, resolve or reject
+// will be ignored.
+class AbstractScriptPromiseResolver {
+ WTF_MAKE_NONCOPYABLE(AbstractScriptPromiseResolver);
+public:
+ virtual ~AbstractScriptPromiseResolver() { }
+
+ // Note that an empty ScriptPromise will be returned after resolve or
+ // reject is called.
+ virtual PassRefPtr<AbstractScriptPromise> promise() = 0;
+
+ virtual void resolve() = 0;
+ virtual void reject() = 0;
+
+ template <typename T>
+ void resolve(T value) { resolveVirtual(value); }
+
+ template <typename T>
+ void reject(T error) { rejectVirtual(error); }
+
+ // Once this function is called this resolver stays alive while the
+ // promise is pending and the associated ExecutionContext isn't stopped.
+ virtual void keepAliveWhilePending() = 0;
+
+ virtual ScriptState* scriptState() = 0;
+ virtual ScriptState* scriptState() const = 0;
+
+ // Forwarded ActiveDOMObject implementation.
+ virtual void suspend() = 0;
+ virtual void resume() = 0;
+ virtual void stop() = 0;
+
+protected:
+ // You need to call suspendIfNeeded after the construction because
+ // this is an ActiveDOMObject.
+ AbstractScriptPromiseResolver() { }
+
+private:
+ // It would be preferable to simply expose these virtual methods as the
+ // public methods for resolve/reject. But we need to expose a resolve(bool),
+ // and if exposed this way the implicit conversion from a pointer type to
+ // bool interfers with conversions of RefPtr<X> to PassRefPtr<X> and can
+ // lead to subtle bugs when a new type needs to be added to the macro
+ // PROMISE_RESOLUTION_TYPES_LIST. Instead we use template specialization to
+ // expose a resolve(bool) that is not subject to implicit conversions.
+#define DECLARE_RESOLUTION_METHODS(type) \
+ virtual void resolveVirtual(type) = 0; \
+ virtual void rejectVirtual(type) = 0;
+PROMISE_RESOLUTION_TYPES_LIST(DECLARE_RESOLUTION_METHODS);
+#undef DECLARE_RESOLUTION_METHODS
+};
+
+template <>
+inline void AbstractScriptPromiseResolver::resolve<bool>(bool value)
+{
+ resolveVirtual(V8BoolType(value));
+}
+
+template <>
+inline void AbstractScriptPromiseResolver::reject<bool>(bool error)
+{
+ rejectVirtual(V8BoolType(error));
+}
+
+} // namespace blink
+
+#endif // #ifndef AbstractScriptPromiseResolver_h
« no previous file with comments | « Source/bindings/common/AbstractScriptPromise.h ('k') | Source/bindings/common/AbstractScriptValue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698