/src/mozilla-central/toolkit/components/windowwatcher/nsDialogParamBlock.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 "nsDialogParamBlock.h" |
8 | | #include "nsString.h" |
9 | | #include "nsReadableUtils.h" |
10 | | |
11 | | NS_IMPL_ISUPPORTS(nsDialogParamBlock, nsIDialogParamBlock) |
12 | | |
13 | | nsDialogParamBlock::nsDialogParamBlock() |
14 | | : mNumStrings(0) |
15 | | , mString(nullptr) |
16 | 0 | { |
17 | 0 | for (int32_t i = 0; i < kNumInts; i++) { |
18 | 0 | mInt[i] = 0; |
19 | 0 | } |
20 | 0 | } |
21 | | |
22 | | nsDialogParamBlock::~nsDialogParamBlock() |
23 | 0 | { |
24 | 0 | delete[] mString; |
25 | 0 | } |
26 | | |
27 | | NS_IMETHODIMP |
28 | | nsDialogParamBlock::SetNumberStrings(int32_t aNumStrings) |
29 | 0 | { |
30 | 0 | if (mString) { |
31 | 0 | return NS_ERROR_ALREADY_INITIALIZED; |
32 | 0 | } |
33 | 0 | |
34 | 0 | mString = new nsString[aNumStrings]; |
35 | 0 | if (!mString) { |
36 | 0 | return NS_ERROR_OUT_OF_MEMORY; |
37 | 0 | } |
38 | 0 | mNumStrings = aNumStrings; |
39 | 0 | return NS_OK; |
40 | 0 | } |
41 | | |
42 | | NS_IMETHODIMP |
43 | | nsDialogParamBlock::GetInt(int32_t aIndex, int32_t* aResult) |
44 | 0 | { |
45 | 0 | nsresult rv = InBounds(aIndex, kNumInts); |
46 | 0 | if (rv == NS_OK) { |
47 | 0 | *aResult = mInt[aIndex]; |
48 | 0 | } |
49 | 0 | return rv; |
50 | 0 | } |
51 | | |
52 | | NS_IMETHODIMP |
53 | | nsDialogParamBlock::SetInt(int32_t aIndex, int32_t aInt) |
54 | 0 | { |
55 | 0 | nsresult rv = InBounds(aIndex, kNumInts); |
56 | 0 | if (rv == NS_OK) { |
57 | 0 | mInt[aIndex] = aInt; |
58 | 0 | } |
59 | 0 | return rv; |
60 | 0 | } |
61 | | |
62 | | NS_IMETHODIMP |
63 | | nsDialogParamBlock::GetString(int32_t aIndex, char16_t** aResult) |
64 | 0 | { |
65 | 0 | if (mNumStrings == 0) { |
66 | 0 | SetNumberStrings(kNumStrings); |
67 | 0 | } |
68 | 0 | nsresult rv = InBounds(aIndex, mNumStrings); |
69 | 0 | if (rv == NS_OK) { |
70 | 0 | *aResult = ToNewUnicode(mString[aIndex]); |
71 | 0 | } |
72 | 0 | return rv; |
73 | 0 | } |
74 | | |
75 | | NS_IMETHODIMP |
76 | | nsDialogParamBlock::SetString(int32_t aIndex, const char16_t* aString) |
77 | 0 | { |
78 | 0 | if (mNumStrings == 0) { |
79 | 0 | SetNumberStrings(kNumStrings); |
80 | 0 | } |
81 | 0 | nsresult rv = InBounds(aIndex, mNumStrings); |
82 | 0 | if (rv == NS_OK) { |
83 | 0 | mString[aIndex] = aString; |
84 | 0 | } |
85 | 0 | return rv; |
86 | 0 | } |
87 | | |
88 | | NS_IMETHODIMP |
89 | | nsDialogParamBlock::GetObjects(nsIMutableArray** aObjects) |
90 | 0 | { |
91 | 0 | NS_ENSURE_ARG_POINTER(aObjects); |
92 | 0 | NS_IF_ADDREF(*aObjects = mObjects); |
93 | 0 | return NS_OK; |
94 | 0 | } |
95 | | |
96 | | NS_IMETHODIMP |
97 | | nsDialogParamBlock::SetObjects(nsIMutableArray* aObjects) |
98 | 0 | { |
99 | 0 | mObjects = aObjects; |
100 | 0 | return NS_OK; |
101 | 0 | } |