OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef SerializedScriptValueFactory_h |
| 6 #define SerializedScriptValueFactory_h |
| 7 |
| 8 #include "bindings/core/v8/ScriptValueSerializer.h" |
| 9 #include "bindings/core/v8/SerializedScriptValue.h" |
| 10 #include "wtf/Noncopyable.h" |
| 11 |
| 12 namespace blink { |
| 13 |
| 14 class SerializedScriptValueFactory { |
| 15 WTF_MAKE_NONCOPYABLE(SerializedScriptValueFactory); |
| 16 public: |
| 17 SerializedScriptValueFactory() { } |
| 18 |
| 19 // If a serialization error occurs (e.g., cyclic input value) this |
| 20 // function returns an empty representation, schedules a V8 exception to |
| 21 // be thrown using v8::ThrowException(), and sets |didThrow|. In this case |
| 22 // the caller must not invoke any V8 operations until control returns to |
| 23 // V8. When serialization is successful, |didThrow| is false. |
| 24 virtual PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>, Mess
agePortArray*, ArrayBufferArray*, WebBlobInfoArray*, ExceptionState&, v8::Isolat
e*); |
| 25 PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>, MessagePortA
rray*, ArrayBufferArray*, ExceptionState&, v8::Isolate*); |
| 26 PassRefPtr<SerializedScriptValue> createFromWire(const String&); |
| 27 PassRefPtr<SerializedScriptValue> createFromWireBytes(const Vector<uint8_t>&
); |
| 28 PassRefPtr<SerializedScriptValue> create(const String&); |
| 29 virtual PassRefPtr<SerializedScriptValue> create(const String&, v8::Isolate*
); |
| 30 PassRefPtr<SerializedScriptValue> create(); |
| 31 PassRefPtr<SerializedScriptValue> create(const ScriptValue&, WebBlobInfoArra
y*, ExceptionState&, v8::Isolate*); |
| 32 |
| 33 // Never throws exceptions. |
| 34 PassRefPtr<SerializedScriptValue> createAndSwallowExceptions(v8::Isolate*, v
8::Handle<v8::Value>); |
| 35 |
| 36 v8::Handle<v8::Value> deserialize(SerializedScriptValue*, v8::Isolate*, Mess
agePortArray*, const WebBlobInfoArray*); |
| 37 |
| 38 static SerializedScriptValueFactory& instance() |
| 39 { |
| 40 if (!m_instance) { |
| 41 ASSERT_NOT_REACHED(); |
| 42 m_instance = new SerializedScriptValueFactory(); |
| 43 } |
| 44 return *m_instance; |
| 45 } |
| 46 |
| 47 // SerializedScriptValueFactory::initialize() should be invoked when Blink i
s initialized, |
| 48 // i.e. initializeWithoutV8() in WebKit.cpp. |
| 49 static void initialize(SerializedScriptValueFactory* newFactory) |
| 50 { |
| 51 ASSERT(!m_instance); |
| 52 m_instance = newFactory; |
| 53 } |
| 54 |
| 55 protected: |
| 56 ScriptValueSerializer::Status doSerialize(v8::Handle<v8::Value>, SerializedS
criptValueWriter&, MessagePortArray*, ArrayBufferArray*, WebBlobInfoArray*, Seri
alizedScriptValue*, v8::TryCatch&, String& errorMessage, v8::Isolate*); |
| 57 virtual ScriptValueSerializer::Status doSerialize(v8::Handle<v8::Value>, Ser
ializedScriptValueWriter&, MessagePortArray*, ArrayBufferArray*, WebBlobInfoArra
y*, BlobDataHandleMap&, v8::TryCatch&, String& errorMessage, v8::Isolate*); |
| 58 void transferData(SerializedScriptValue*, SerializedScriptValueWriter&, Arra
yBufferArray*, ExceptionState&, v8::Isolate*); |
| 59 |
| 60 virtual v8::Handle<v8::Value> deserialize(String& data, BlobDataHandleMap& b
lobDataHandles, ArrayBufferContentsArray*, v8::Isolate*, MessagePortArray* messa
gePorts, const WebBlobInfoArray*); |
| 61 |
| 62 private: |
| 63 static SerializedScriptValueFactory* m_instance; |
| 64 }; |
| 65 |
| 66 } // namespace blink |
| 67 |
| 68 #endif // SerializedScriptValueFactory_h |
| 69 |
OLD | NEW |