Line data Source code
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/. */
6 :
7 : #include "mozilla/dom/Headers.h"
8 :
9 : #include "mozilla/ErrorResult.h"
10 : #include "mozilla/dom/WorkerPrivate.h"
11 : #include "mozilla/Preferences.h"
12 :
13 : namespace mozilla {
14 : namespace dom {
15 :
16 0 : NS_IMPL_CYCLE_COLLECTING_ADDREF(Headers)
17 0 : NS_IMPL_CYCLE_COLLECTING_RELEASE(Headers)
18 0 : NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Headers, mOwner)
19 :
20 0 : NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Headers)
21 0 : NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
22 0 : NS_INTERFACE_MAP_ENTRY(nsISupports)
23 0 : NS_INTERFACE_MAP_END
24 :
25 : // static
26 : already_AddRefed<Headers>
27 0 : Headers::Constructor(const GlobalObject& aGlobal,
28 : const Optional<HeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord>& aInit,
29 : ErrorResult& aRv)
30 : {
31 0 : RefPtr<InternalHeaders> ih = new InternalHeaders();
32 0 : RefPtr<Headers> headers = new Headers(aGlobal.GetAsSupports(), ih);
33 :
34 0 : if (!aInit.WasPassed()) {
35 0 : return headers.forget();
36 : }
37 :
38 0 : if (aInit.Value().IsHeaders()) {
39 0 : ih->Fill(*aInit.Value().GetAsHeaders().mInternalHeaders, aRv);
40 0 : } else if (aInit.Value().IsByteStringSequenceSequence()) {
41 0 : ih->Fill(aInit.Value().GetAsByteStringSequenceSequence(), aRv);
42 0 : } else if (aInit.Value().IsByteStringByteStringRecord()) {
43 0 : ih->Fill(aInit.Value().GetAsByteStringByteStringRecord(), aRv);
44 : }
45 :
46 0 : if (aRv.Failed()) {
47 0 : return nullptr;
48 : }
49 :
50 0 : return headers.forget();
51 : }
52 :
53 : // static
54 : already_AddRefed<Headers>
55 0 : Headers::Constructor(const GlobalObject& aGlobal,
56 : const OwningHeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord& aInit,
57 : ErrorResult& aRv)
58 : {
59 0 : nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
60 0 : return Create(global, aInit, aRv);
61 : }
62 :
63 : /* static */ already_AddRefed<Headers>
64 0 : Headers::Create(nsIGlobalObject* aGlobal,
65 : const OwningHeadersOrByteStringSequenceSequenceOrByteStringByteStringRecord& aInit,
66 : ErrorResult& aRv)
67 : {
68 0 : RefPtr<InternalHeaders> ih = new InternalHeaders();
69 0 : RefPtr<Headers> headers = new Headers(aGlobal, ih);
70 :
71 0 : if (aInit.IsHeaders()) {
72 0 : ih->Fill(*(aInit.GetAsHeaders().get()->mInternalHeaders), aRv);
73 0 : } else if (aInit.IsByteStringSequenceSequence()) {
74 0 : ih->Fill(aInit.GetAsByteStringSequenceSequence(), aRv);
75 0 : } else if (aInit.IsByteStringByteStringRecord()) {
76 0 : ih->Fill(aInit.GetAsByteStringByteStringRecord(), aRv);
77 : }
78 :
79 0 : if (NS_WARN_IF(aRv.Failed())) {
80 0 : return nullptr;
81 : }
82 :
83 0 : return headers.forget();
84 : }
85 :
86 : JSObject*
87 0 : Headers::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
88 : {
89 0 : return mozilla::dom::HeadersBinding::Wrap(aCx, this, aGivenProto);
90 : }
91 :
92 0 : Headers::~Headers()
93 : {
94 0 : }
95 :
96 : } // namespace dom
97 : } // namespace mozilla
|