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