Bug 1665252 - remove allowpaymentrequest attribute from HTMLIFrameElement r=dom-worke...
[gecko.git] / dom / base / BodyUtil.h
blob3e56ad93a1a4d778098b6025ca6e4b2afea4e02c
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_BodyUtil_h
8 #define mozilla_dom_BodyUtil_h
10 #include "nsString.h"
11 #include "nsError.h"
13 #include "mozilla/ErrorResult.h"
14 #include "mozilla/dom/File.h"
15 #include "mozilla/dom/FormData.h"
17 namespace mozilla {
18 namespace dom {
20 class BodyUtil final {
21 private:
22 BodyUtil() = delete;
24 public:
25 /**
26 * Creates an array buffer from an array, assigning the result to |aValue|.
27 * The array buffer takes ownership of |aInput|, which must be allocated
28 * by |malloc|.
30 static void ConsumeArrayBuffer(JSContext* aCx,
31 JS::MutableHandle<JSObject*> aValue,
32 uint32_t aInputLength, uint8_t* aInput,
33 ErrorResult& aRv);
35 /**
36 * Creates an in-memory blob from an array. The blob takes ownership of
37 * |aInput|, which must be allocated by |malloc|.
39 static already_AddRefed<Blob> ConsumeBlob(nsIGlobalObject* aParent,
40 const nsString& aMimeType,
41 uint32_t aInputLength,
42 uint8_t* aInput, ErrorResult& aRv);
44 /**
45 * Creates a form data object from a UTF-8 encoded |aStr|. Returns |nullptr|
46 * and sets |aRv| to MSG_BAD_FORMDATA if |aStr| contains invalid data.
48 static already_AddRefed<FormData> ConsumeFormData(nsIGlobalObject* aParent,
49 const nsCString& aMimeType,
50 const nsCString& aStr,
51 ErrorResult& aRv);
53 /**
54 * UTF-8 decodes |aInput| into |aText|. The caller may free |aInput|
55 * once this method returns.
57 static nsresult ConsumeText(uint32_t aInputLength, uint8_t* aInput,
58 nsString& aText);
60 /**
61 * Parses a UTF-8 encoded |aStr| as JSON, assigning the result to |aValue|.
62 * Sets |aRv| to a syntax error if |aStr| contains invalid data.
64 static void ConsumeJson(JSContext* aCx, JS::MutableHandle<JS::Value> aValue,
65 const nsString& aStr, ErrorResult& aRv);
68 } // namespace dom
69 } // namespace mozilla
71 #endif // mozilla_dom_BodyUtil_h