| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * Copyright (C) 2009, 2010 Google Inc. All rights reserved. | 2  * Copyright (C) 2009, 2010 Google Inc. All rights reserved. | 
| 3  * | 3  * | 
| 4  * Redistribution and use in source and binary forms, with or without | 4  * Redistribution and use in source and binary forms, with or without | 
| 5  * modification, are permitted provided that the following conditions are | 5  * modification, are permitted provided that the following conditions are | 
| 6  * met: | 6  * met: | 
| 7  * | 7  * | 
| 8  *     * Redistributions of source code must retain the above copyright | 8  *     * Redistributions of source code must retain the above copyright | 
| 9  * notice, this list of conditions and the following disclaimer. | 9  * notice, this list of conditions and the following disclaimer. | 
| 10  *     * Redistributions in binary form must reproduce the above | 10  *     * Redistributions in binary form must reproduce the above | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
| 40 namespace WTF { | 40 namespace WTF { | 
| 41 | 41 | 
| 42 class ArrayBuffer; | 42 class ArrayBuffer; | 
| 43 class ArrayBufferContents; | 43 class ArrayBufferContents; | 
| 44 | 44 | 
| 45 } | 45 } | 
| 46 | 46 | 
| 47 namespace WebCore { | 47 namespace WebCore { | 
| 48 | 48 | 
| 49 class BlobDataHandle; | 49 class BlobDataHandle; | 
|  | 50 class ExceptionState; | 
| 50 class MessagePort; | 51 class MessagePort; | 
| 51 | 52 | 
| 52 typedef Vector<RefPtr<MessagePort>, 1> MessagePortArray; | 53 typedef Vector<RefPtr<MessagePort>, 1> MessagePortArray; | 
| 53 typedef Vector<RefPtr<WTF::ArrayBuffer>, 1> ArrayBufferArray; | 54 typedef Vector<RefPtr<WTF::ArrayBuffer>, 1> ArrayBufferArray; | 
| 54 typedef HashMap<String, RefPtr<BlobDataHandle> > BlobDataHandleMap; | 55 typedef HashMap<String, RefPtr<BlobDataHandle> > BlobDataHandleMap; | 
| 55 | 56 | 
| 56 class SerializedScriptValue FINAL : public ThreadSafeRefCounted<SerializedScript
     Value> { | 57 class SerializedScriptValue FINAL : public ThreadSafeRefCounted<SerializedScript
     Value> { | 
| 57 public: | 58 public: | 
| 58     // Increment this for each incompatible change to the wire format. | 59     // Increment this for each incompatible change to the wire format. | 
| 59     // Version 2: Added StringUCharTag for UChar v8 strings. | 60     // Version 2: Added StringUCharTag for UChar v8 strings. | 
| 60     // Version 3: Switched to using uuids as blob data identifiers. | 61     // Version 3: Switched to using uuids as blob data identifiers. | 
| 61     // Version 4: Extended File serialization to be complete. | 62     // Version 4: Extended File serialization to be complete. | 
| 62     static const uint32_t wireFormatVersion = 4; | 63     static const uint32_t wireFormatVersion = 4; | 
| 63 | 64 | 
| 64     ~SerializedScriptValue(); | 65     ~SerializedScriptValue(); | 
| 65 | 66 | 
| 66     // If a serialization error occurs (e.g., cyclic input value) this | 67     // If a serialization error occurs (e.g., cyclic input value) this | 
| 67     // function returns an empty representation, schedules a V8 exception to | 68     // function returns an empty representation, schedules a V8 exception to | 
| 68     // be thrown using v8::ThrowException(), and sets |didThrow|. In this case | 69     // be thrown using v8::ThrowException(), and sets |didThrow|. In this case | 
| 69     // the caller must not invoke any V8 operations until control returns to | 70     // the caller must not invoke any V8 operations until control returns to | 
| 70     // V8. When serialization is successful, |didThrow| is false. | 71     // V8. When serialization is successful, |didThrow| is false. | 
| 71     static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>, Messa
     gePortArray*, ArrayBufferArray*, bool& didThrow, v8::Isolate*); | 72     static PassRefPtr<SerializedScriptValue> create(v8::Handle<v8::Value>, Messa
     gePortArray*, ArrayBufferArray*, ExceptionState&, v8::Isolate*); | 
| 72     static PassRefPtr<SerializedScriptValue> createFromWire(const String&); | 73     static PassRefPtr<SerializedScriptValue> createFromWire(const String&); | 
| 73     static PassRefPtr<SerializedScriptValue> createFromWireBytes(const Vector<ui
     nt8_t>&); | 74     static PassRefPtr<SerializedScriptValue> createFromWireBytes(const Vector<ui
     nt8_t>&); | 
| 74     static PassRefPtr<SerializedScriptValue> create(const String&); | 75     static PassRefPtr<SerializedScriptValue> create(const String&); | 
| 75     static PassRefPtr<SerializedScriptValue> create(const String&, v8::Isolate*)
     ; | 76     static PassRefPtr<SerializedScriptValue> create(const String&, v8::Isolate*)
     ; | 
| 76     static PassRefPtr<SerializedScriptValue> create(); | 77     static PassRefPtr<SerializedScriptValue> create(); | 
| 77 | 78 | 
| 78     static PassRefPtr<SerializedScriptValue> create(const ScriptValue&, bool& di
     dThrow, ScriptState*); | 79     static PassRefPtr<SerializedScriptValue> create(const ScriptValue&, Exceptio
     nState&, ScriptState*); | 
| 79 | 80 | 
| 80     // Never throws exceptions. | 81     // Never throws exceptions. | 
| 81     static PassRefPtr<SerializedScriptValue> createAndSwallowExceptions(v8::Hand
     le<v8::Value>, v8::Isolate*); | 82     static PassRefPtr<SerializedScriptValue> createAndSwallowExceptions(v8::Hand
     le<v8::Value>, v8::Isolate*); | 
| 82 | 83 | 
| 83     static PassRefPtr<SerializedScriptValue> nullValue(); | 84     static PassRefPtr<SerializedScriptValue> nullValue(); | 
| 84     static PassRefPtr<SerializedScriptValue> nullValue(v8::Isolate*); | 85     static PassRefPtr<SerializedScriptValue> nullValue(v8::Isolate*); | 
| 85 | 86 | 
| 86     String toWireString() const { return m_data; } | 87     String toWireString() const { return m_data; } | 
| 87     void toWireBytes(Vector<char>&) const; | 88     void toWireBytes(Vector<char>&) const; | 
| 88 | 89 | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
| 99     // to GC counters to eventually trigger a GC, otherwise flood of postMessage
     () can cause OOM. | 100     // to GC counters to eventually trigger a GC, otherwise flood of postMessage
     () can cause OOM. | 
| 100     // Ok to invoke multiple times (only adds memory once). | 101     // Ok to invoke multiple times (only adds memory once). | 
| 101     // The memory registration is revoked automatically in destructor. | 102     // The memory registration is revoked automatically in destructor. | 
| 102     void registerMemoryAllocatedWithCurrentScriptContext(); | 103     void registerMemoryAllocatedWithCurrentScriptContext(); | 
| 103 | 104 | 
| 104 private: | 105 private: | 
| 105     enum StringDataMode { | 106     enum StringDataMode { | 
| 106         StringValue, | 107         StringValue, | 
| 107         WireData | 108         WireData | 
| 108     }; | 109     }; | 
| 109     enum ExceptionPolicy { |  | 
| 110         ThrowExceptions, |  | 
| 111         DoNotThrowExceptions |  | 
| 112     }; |  | 
| 113     typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; | 110     typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; | 
| 114 | 111 | 
| 115     SerializedScriptValue(); | 112     SerializedScriptValue(); | 
| 116     SerializedScriptValue(v8::Handle<v8::Value>, MessagePortArray*, ArrayBufferA
     rray*, bool& didThrow, v8::Isolate*, ExceptionPolicy = ThrowExceptions); | 113     SerializedScriptValue(v8::Handle<v8::Value>, MessagePortArray*, ArrayBufferA
     rray*, ExceptionState&, v8::Isolate*); | 
| 117     explicit SerializedScriptValue(const String& wireData); | 114     explicit SerializedScriptValue(const String& wireData); | 
| 118 | 115 | 
| 119     static PassOwnPtr<ArrayBufferContentsArray> transferArrayBuffers(ArrayBuffer
     Array&, bool& didThrow, v8::Isolate*); | 116     static PassOwnPtr<ArrayBufferContentsArray> transferArrayBuffers(ArrayBuffer
     Array&, ExceptionState&, v8::Isolate*); | 
| 120 | 117 | 
| 121     String m_data; | 118     String m_data; | 
| 122     OwnPtr<ArrayBufferContentsArray> m_arrayBufferContentsArray; | 119     OwnPtr<ArrayBufferContentsArray> m_arrayBufferContentsArray; | 
| 123     BlobDataHandleMap m_blobDataHandles; | 120     BlobDataHandleMap m_blobDataHandles; | 
| 124     intptr_t m_externallyAllocatedMemory; | 121     intptr_t m_externallyAllocatedMemory; | 
| 125 }; | 122 }; | 
| 126 | 123 | 
| 127 } // namespace WebCore | 124 } // namespace WebCore | 
| 128 | 125 | 
| 129 #endif // SerializedScriptValue_h | 126 #endif // SerializedScriptValue_h | 
| OLD | NEW | 
|---|