Bug 1863873 - Block ability to perform audio decoding outside of Utility on release...
[gecko.git] / dom / file / StringBlobImpl.cpp
blob8cb657ca5f09e603c49b8bcb6dde36fb90a53288
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 #include "StringBlobImpl.h"
8 #include "nsStringStream.h"
10 namespace mozilla::dom {
12 NS_IMPL_ISUPPORTS_INHERITED(StringBlobImpl, BlobImpl, nsIMemoryReporter)
14 /* static */
15 already_AddRefed<StringBlobImpl> StringBlobImpl::Create(
16 const nsACString& aData, const nsAString& aContentType) {
17 RefPtr<StringBlobImpl> blobImpl = new StringBlobImpl(aData, aContentType);
18 RegisterWeakMemoryReporter(blobImpl);
19 return blobImpl.forget();
22 StringBlobImpl::StringBlobImpl(const nsACString& aData,
23 const nsAString& aContentType)
24 : BaseBlobImpl(aContentType, aData.Length()), mData(aData) {}
26 StringBlobImpl::~StringBlobImpl() { UnregisterWeakMemoryReporter(this); }
28 already_AddRefed<BlobImpl> StringBlobImpl::CreateSlice(
29 uint64_t aStart, uint64_t aLength, const nsAString& aContentType,
30 ErrorResult& aRv) const {
31 RefPtr<BlobImpl> impl =
32 new StringBlobImpl(Substring(mData, aStart, aLength), aContentType);
33 return impl.forget();
36 void StringBlobImpl::CreateInputStream(nsIInputStream** aStream,
37 ErrorResult& aRv) const {
38 aRv = NS_NewCStringInputStream(aStream, mData);
41 NS_IMETHODIMP
42 StringBlobImpl::CollectReports(nsIHandleReportCallback* aHandleReport,
43 nsISupports* aData, bool aAnonymize) {
44 MOZ_COLLECT_REPORT("explicit/dom/memory-file-data/string", KIND_HEAP,
45 UNITS_BYTES,
46 mData.SizeOfExcludingThisIfUnshared(MallocSizeOf),
47 "Memory used to back a File/Blob based on a string.");
48 return NS_OK;
51 } // namespace mozilla::dom