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 "StreamBlobImpl.h"
8 : #include "nsStringStream.h"
9 :
10 : namespace mozilla {
11 : namespace dom {
12 :
13 0 : NS_IMPL_ISUPPORTS_INHERITED(StringBlobImpl, BlobImpl, nsIMemoryReporter)
14 :
15 : /* static */ already_AddRefed<StringBlobImpl>
16 0 : StringBlobImpl::Create(const nsACString& aData, const nsAString& aContentType)
17 : {
18 0 : RefPtr<StringBlobImpl> blobImpl = new StringBlobImpl(aData, aContentType);
19 0 : RegisterWeakMemoryReporter(blobImpl);
20 0 : return blobImpl.forget();
21 : }
22 :
23 0 : StringBlobImpl::StringBlobImpl(const nsACString& aData,
24 0 : const nsAString& aContentType)
25 0 : : BaseBlobImpl(aContentType, aData.Length())
26 0 : , mData(aData)
27 : {
28 0 : }
29 :
30 0 : StringBlobImpl::~StringBlobImpl()
31 : {
32 0 : UnregisterWeakMemoryReporter(this);
33 0 : }
34 :
35 : already_AddRefed<BlobImpl>
36 0 : StringBlobImpl::CreateSlice(uint64_t aStart, uint64_t aLength,
37 : const nsAString& aContentType,
38 : ErrorResult& aRv)
39 : {
40 : RefPtr<BlobImpl> impl =
41 0 : new StringBlobImpl(Substring(mData, aStart, aLength),
42 0 : aContentType);
43 0 : return impl.forget();
44 : }
45 :
46 : void
47 0 : StringBlobImpl::GetInternalStream(nsIInputStream** aStream, ErrorResult& aRv)
48 : {
49 0 : aRv = NS_NewCStringInputStream(aStream, mData);
50 0 : }
51 :
52 : NS_IMETHODIMP
53 0 : StringBlobImpl::CollectReports(nsIHandleReportCallback* aHandleReport,
54 : nsISupports* aData, bool aAnonymize)
55 : {
56 0 : MOZ_COLLECT_REPORT(
57 : "explicit/dom/memory-file-data/string", KIND_HEAP, UNITS_BYTES,
58 : mData.SizeOfExcludingThisIfUnshared(MallocSizeOf),
59 0 : "Memory used to back a File/Blob based on a string.");
60 0 : return NS_OK;
61 : }
62 :
63 : } // namespace dom
64 9 : } // namespace mozilla
|