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 #ifndef SerializedScriptValueFactory_h | 5 #ifndef SerializedScriptValueFactory_h |
6 #define SerializedScriptValueFactory_h | 6 #define SerializedScriptValueFactory_h |
7 | 7 |
8 #include "bindings/core/v8/ScriptValueSerializer.h" | 8 #include "bindings/core/v8/ScriptValueSerializer.h" |
9 #include "bindings/core/v8/SerializedScriptValue.h" | 9 #include "bindings/core/v8/SerializedScriptValue.h" |
10 #include "core/CoreExport.h" | 10 #include "core/CoreExport.h" |
11 #include "wtf/Allocator.h" | 11 #include "wtf/Allocator.h" |
12 #include "wtf/Noncopyable.h" | 12 #include "wtf/Noncopyable.h" |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
16 class CORE_EXPORT SerializedScriptValueFactory { | 16 class CORE_EXPORT SerializedScriptValueFactory { |
17 WTF_MAKE_NONCOPYABLE(SerializedScriptValueFactory); | 17 WTF_MAKE_NONCOPYABLE(SerializedScriptValueFactory); |
18 USING_FAST_MALLOC(SerializedScriptValueFactory); | 18 USING_FAST_MALLOC(SerializedScriptValueFactory); |
19 | 19 |
20 public: | 20 public: |
21 // SerializedScriptValueFactory::initialize() should be invoked when Blink is
initialized, | 21 // SerializedScriptValueFactory::initialize() should be invoked when Blink is |
22 // i.e. initialize() in WebKit.cpp. | 22 // initialized, i.e. initialize() in WebKit.cpp. |
23 static void initialize(SerializedScriptValueFactory* newFactory) { | 23 static void initialize(SerializedScriptValueFactory* newFactory) { |
24 DCHECK(!m_instance); | 24 DCHECK(!m_instance); |
25 m_instance = newFactory; | 25 m_instance = newFactory; |
26 } | 26 } |
27 | 27 |
28 protected: | 28 protected: |
29 friend class SerializedScriptValue; | 29 friend class SerializedScriptValue; |
30 | 30 |
31 // Following 2 methods are expected to be called by SerializedScriptValue. | 31 // Following 2 methods are expected to be called by SerializedScriptValue. |
32 | 32 |
33 // If a serialization error occurs (e.g., cyclic input value) this | 33 // If a serialization error occurs (e.g., cyclic input value) this |
34 // function returns an empty representation, schedules a V8 exception to | 34 // function returns an empty representation, schedules a V8 exception to |
35 // be thrown using v8::ThrowException(), and sets |didThrow|. In this case | 35 // be thrown using v8::ThrowException(), and sets |didThrow|. In this case |
36 // the caller must not invoke any V8 operations until control returns to | 36 // the caller must not invoke any V8 operations until control returns to |
37 // V8. When serialization is successful, |didThrow| is false. | 37 // V8. When serialization is successful, |didThrow| is false. |
38 virtual PassRefPtr<SerializedScriptValue> create(v8::Isolate*, | 38 virtual PassRefPtr<SerializedScriptValue> create(v8::Isolate*, |
39 v8::Local<v8::Value>, | 39 v8::Local<v8::Value>, |
40 Transferables*, | 40 Transferables*, |
41 WebBlobInfoArray*, | 41 WebBlobInfoArray*, |
42 ExceptionState&); | 42 ExceptionState&); |
43 | 43 |
44 virtual v8::Local<v8::Value> deserialize(SerializedScriptValue*, | 44 virtual v8::Local<v8::Value> deserialize(SerializedScriptValue*, |
45 v8::Isolate*, | 45 v8::Isolate*, |
46 MessagePortArray*, | 46 MessagePortArray*, |
47 const WebBlobInfoArray*); | 47 const WebBlobInfoArray*); |
48 | 48 |
49 // Following methods are expected to be called in SerializedScriptValueFactory
{ForModules}. | 49 // Following methods are expected to be called in |
| 50 // SerializedScriptValueFactory{ForModules}. |
50 SerializedScriptValueFactory() {} | 51 SerializedScriptValueFactory() {} |
51 | 52 |
52 private: | 53 private: |
53 static SerializedScriptValueFactory& instance() { | 54 static SerializedScriptValueFactory& instance() { |
54 if (!m_instance) { | 55 if (!m_instance) { |
55 NOTREACHED(); | 56 NOTREACHED(); |
56 m_instance = new SerializedScriptValueFactory; | 57 m_instance = new SerializedScriptValueFactory; |
57 } | 58 } |
58 return *m_instance; | 59 return *m_instance; |
59 } | 60 } |
60 | 61 |
61 static SerializedScriptValueFactory* m_instance; | 62 static SerializedScriptValueFactory* m_instance; |
62 }; | 63 }; |
63 | 64 |
64 } // namespace blink | 65 } // namespace blink |
65 | 66 |
66 #endif // SerializedScriptValueFactory_h | 67 #endif // SerializedScriptValueFactory_h |
OLD | NEW |