1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_StructuredCloneBlob_h
8 #define mozilla_dom_StructuredCloneBlob_h
10 #include "js/TypeDecls.h"
11 #include "mozilla/AlreadyAddRefed.h"
12 #include "mozilla/Maybe.h"
13 #include "mozilla/RefPtr.h"
14 #include "mozilla/dom/StructuredCloneHolder.h"
15 #include "nsIMemoryReporter.h"
16 #include "nsISupports.h"
18 struct JSStructuredCloneReader
;
19 struct JSStructuredCloneWriter
;
29 class StructuredCloneBlob final
: public nsIMemoryReporter
{
30 MOZ_DEFINE_MALLOC_SIZE_OF(MallocSizeOf
)
34 NS_DECL_NSIMEMORYREPORTER
36 static JSObject
* ReadStructuredClone(JSContext
* aCx
,
37 JSStructuredCloneReader
* aReader
,
38 StructuredCloneHolder
* aHolder
);
39 bool WriteStructuredClone(JSContext
* aCx
, JSStructuredCloneWriter
* aWriter
,
40 StructuredCloneHolder
* aHolder
);
42 static already_AddRefed
<StructuredCloneBlob
> Constructor(
43 GlobalObject
& aGlobal
, const nsACString
& aName
,
44 const nsACString
& aAnonymizedName
, JS::Handle
<JS::Value
> aValue
,
45 JS::Handle
<JSObject
*> aTargetGlobal
, ErrorResult
& aRv
);
47 void Deserialize(JSContext
* aCx
, JS::Handle
<JSObject
*> aTargetScope
,
48 bool aKeepData
, JS::MutableHandle
<JS::Value
> aResult
,
51 nsISupports
* GetParentObject() const { return nullptr; }
52 JSObject
* GetWrapper() const { return nullptr; }
54 bool WrapObject(JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
,
55 JS::MutableHandle
<JSObject
*> aResult
);
58 virtual ~StructuredCloneBlob();
61 explicit StructuredCloneBlob();
63 class Holder
: public StructuredCloneHolder
{
65 using StructuredCloneHolder::StructuredCloneHolder
;
67 bool ReadStructuredCloneInternal(JSContext
* aCx
,
68 JSStructuredCloneReader
* aReader
,
69 StructuredCloneHolder
* aHolder
);
71 bool WriteStructuredClone(JSContext
* aCx
, JSStructuredCloneWriter
* aWriter
,
72 StructuredCloneHolder
* aHolder
);
76 nsCString mAnonymizedName
;
77 Maybe
<Holder
> mHolder
;
79 static already_AddRefed
<StructuredCloneBlob
> Create() {
80 RefPtr
<StructuredCloneBlob
> holder
= new StructuredCloneBlob();
81 RegisterWeakMemoryReporter(holder
);
82 return holder
.forget();
87 } // namespace mozilla
89 #endif // mozilla_dom_StructuredCloneBlob_h