toolkit/components/autocomplete/nsAutoCompleteSimpleResult.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #include "nsAutoCompleteSimpleResult.h"
michael@0 6
michael@0 7 NS_IMPL_ISUPPORTS(nsAutoCompleteSimpleResult,
michael@0 8 nsIAutoCompleteResult,
michael@0 9 nsIAutoCompleteSimpleResult)
michael@0 10
michael@0 11 nsAutoCompleteSimpleResult::nsAutoCompleteSimpleResult() :
michael@0 12 mDefaultIndex(-1),
michael@0 13 mSearchResult(RESULT_NOMATCH),
michael@0 14 mTypeAheadResult(false)
michael@0 15 {
michael@0 16 }
michael@0 17
michael@0 18 // searchString
michael@0 19 NS_IMETHODIMP
michael@0 20 nsAutoCompleteSimpleResult::GetSearchString(nsAString &aSearchString)
michael@0 21 {
michael@0 22 aSearchString = mSearchString;
michael@0 23 return NS_OK;
michael@0 24 }
michael@0 25 NS_IMETHODIMP
michael@0 26 nsAutoCompleteSimpleResult::SetSearchString(const nsAString &aSearchString)
michael@0 27 {
michael@0 28 mSearchString.Assign(aSearchString);
michael@0 29 return NS_OK;
michael@0 30 }
michael@0 31
michael@0 32 // searchResult
michael@0 33 NS_IMETHODIMP
michael@0 34 nsAutoCompleteSimpleResult::GetSearchResult(uint16_t *aSearchResult)
michael@0 35 {
michael@0 36 *aSearchResult = mSearchResult;
michael@0 37 return NS_OK;
michael@0 38 }
michael@0 39 NS_IMETHODIMP
michael@0 40 nsAutoCompleteSimpleResult::SetSearchResult(uint16_t aSearchResult)
michael@0 41 {
michael@0 42 mSearchResult = aSearchResult;
michael@0 43 return NS_OK;
michael@0 44 }
michael@0 45
michael@0 46 // defaultIndex
michael@0 47 NS_IMETHODIMP
michael@0 48 nsAutoCompleteSimpleResult::GetDefaultIndex(int32_t *aDefaultIndex)
michael@0 49 {
michael@0 50 *aDefaultIndex = mDefaultIndex;
michael@0 51 return NS_OK;
michael@0 52 }
michael@0 53 NS_IMETHODIMP
michael@0 54 nsAutoCompleteSimpleResult::SetDefaultIndex(int32_t aDefaultIndex)
michael@0 55 {
michael@0 56 mDefaultIndex = aDefaultIndex;
michael@0 57 return NS_OK;
michael@0 58 }
michael@0 59
michael@0 60 // errorDescription
michael@0 61 NS_IMETHODIMP
michael@0 62 nsAutoCompleteSimpleResult::GetErrorDescription(nsAString & aErrorDescription)
michael@0 63 {
michael@0 64 aErrorDescription = mErrorDescription;
michael@0 65 return NS_OK;
michael@0 66 }
michael@0 67 NS_IMETHODIMP
michael@0 68 nsAutoCompleteSimpleResult::SetErrorDescription(
michael@0 69 const nsAString &aErrorDescription)
michael@0 70 {
michael@0 71 mErrorDescription.Assign(aErrorDescription);
michael@0 72 return NS_OK;
michael@0 73 }
michael@0 74
michael@0 75 // typeAheadResult
michael@0 76 NS_IMETHODIMP
michael@0 77 nsAutoCompleteSimpleResult::GetTypeAheadResult(bool *aTypeAheadResult)
michael@0 78 {
michael@0 79 *aTypeAheadResult = mTypeAheadResult;
michael@0 80 return NS_OK;
michael@0 81 }
michael@0 82 NS_IMETHODIMP
michael@0 83 nsAutoCompleteSimpleResult::SetTypeAheadResult(bool aTypeAheadResult)
michael@0 84 {
michael@0 85 mTypeAheadResult = aTypeAheadResult;
michael@0 86 return NS_OK;
michael@0 87 }
michael@0 88
michael@0 89 NS_IMETHODIMP
michael@0 90 nsAutoCompleteSimpleResult::AppendMatch(const nsAString& aValue,
michael@0 91 const nsAString& aComment,
michael@0 92 const nsAString& aImage,
michael@0 93 const nsAString& aStyle,
michael@0 94 const nsAString& aFinalCompleteValue)
michael@0 95 {
michael@0 96 CheckInvariants();
michael@0 97
michael@0 98 if (! mValues.AppendElement(aValue))
michael@0 99 return NS_ERROR_OUT_OF_MEMORY;
michael@0 100 if (! mComments.AppendElement(aComment)) {
michael@0 101 mValues.RemoveElementAt(mValues.Length() - 1);
michael@0 102 return NS_ERROR_OUT_OF_MEMORY;
michael@0 103 }
michael@0 104 if (! mImages.AppendElement(aImage)) {
michael@0 105 mValues.RemoveElementAt(mValues.Length() - 1);
michael@0 106 mComments.RemoveElementAt(mComments.Length() - 1);
michael@0 107 return NS_ERROR_OUT_OF_MEMORY;
michael@0 108 }
michael@0 109 if (! mStyles.AppendElement(aStyle)) {
michael@0 110 mValues.RemoveElementAt(mValues.Length() - 1);
michael@0 111 mComments.RemoveElementAt(mComments.Length() - 1);
michael@0 112 mImages.RemoveElementAt(mImages.Length() - 1);
michael@0 113 return NS_ERROR_OUT_OF_MEMORY;
michael@0 114 }
michael@0 115 if (!mFinalCompleteValues.AppendElement(aFinalCompleteValue)) {
michael@0 116 mValues.RemoveElementAt(mValues.Length() - 1);
michael@0 117 mComments.RemoveElementAt(mComments.Length() - 1);
michael@0 118 mImages.RemoveElementAt(mImages.Length() - 1);
michael@0 119 mStyles.RemoveElementAt(mStyles.Length() - 1);
michael@0 120 return NS_ERROR_OUT_OF_MEMORY;
michael@0 121 }
michael@0 122 return NS_OK;
michael@0 123 }
michael@0 124
michael@0 125 NS_IMETHODIMP
michael@0 126 nsAutoCompleteSimpleResult::GetMatchCount(uint32_t *aMatchCount)
michael@0 127 {
michael@0 128 CheckInvariants();
michael@0 129
michael@0 130 *aMatchCount = mValues.Length();
michael@0 131 return NS_OK;
michael@0 132 }
michael@0 133
michael@0 134 NS_IMETHODIMP
michael@0 135 nsAutoCompleteSimpleResult::GetValueAt(int32_t aIndex, nsAString& _retval)
michael@0 136 {
michael@0 137 NS_ENSURE_TRUE(aIndex >= 0 && aIndex < int32_t(mValues.Length()),
michael@0 138 NS_ERROR_ILLEGAL_VALUE);
michael@0 139 CheckInvariants();
michael@0 140
michael@0 141 _retval = mValues[aIndex];
michael@0 142 return NS_OK;
michael@0 143 }
michael@0 144
michael@0 145 NS_IMETHODIMP
michael@0 146 nsAutoCompleteSimpleResult::GetLabelAt(int32_t aIndex, nsAString& _retval)
michael@0 147 {
michael@0 148 return GetValueAt(aIndex, _retval);
michael@0 149 }
michael@0 150
michael@0 151 NS_IMETHODIMP
michael@0 152 nsAutoCompleteSimpleResult::GetCommentAt(int32_t aIndex, nsAString& _retval)
michael@0 153 {
michael@0 154 NS_ENSURE_TRUE(aIndex >= 0 && aIndex < int32_t(mComments.Length()),
michael@0 155 NS_ERROR_ILLEGAL_VALUE);
michael@0 156 CheckInvariants();
michael@0 157 _retval = mComments[aIndex];
michael@0 158 return NS_OK;
michael@0 159 }
michael@0 160
michael@0 161 NS_IMETHODIMP
michael@0 162 nsAutoCompleteSimpleResult::GetImageAt(int32_t aIndex, nsAString& _retval)
michael@0 163 {
michael@0 164 NS_ENSURE_TRUE(aIndex >= 0 && aIndex < int32_t(mImages.Length()),
michael@0 165 NS_ERROR_ILLEGAL_VALUE);
michael@0 166 CheckInvariants();
michael@0 167 _retval = mImages[aIndex];
michael@0 168 return NS_OK;
michael@0 169 }
michael@0 170
michael@0 171 NS_IMETHODIMP
michael@0 172 nsAutoCompleteSimpleResult::GetStyleAt(int32_t aIndex, nsAString& _retval)
michael@0 173 {
michael@0 174 NS_ENSURE_TRUE(aIndex >= 0 && aIndex < int32_t(mStyles.Length()),
michael@0 175 NS_ERROR_ILLEGAL_VALUE);
michael@0 176 CheckInvariants();
michael@0 177 _retval = mStyles[aIndex];
michael@0 178 return NS_OK;
michael@0 179 }
michael@0 180
michael@0 181 NS_IMETHODIMP
michael@0 182 nsAutoCompleteSimpleResult::GetFinalCompleteValueAt(int32_t aIndex,
michael@0 183 nsAString& _retval)
michael@0 184 {
michael@0 185 NS_ENSURE_TRUE(aIndex >= 0 && aIndex < int32_t(mFinalCompleteValues.Length()),
michael@0 186 NS_ERROR_ILLEGAL_VALUE);
michael@0 187 CheckInvariants();
michael@0 188 _retval = mFinalCompleteValues[aIndex];
michael@0 189 if (_retval.Length() == 0)
michael@0 190 _retval = mValues[aIndex];
michael@0 191 return NS_OK;
michael@0 192 }
michael@0 193
michael@0 194 NS_IMETHODIMP
michael@0 195 nsAutoCompleteSimpleResult::SetListener(nsIAutoCompleteSimpleResultListener* aListener)
michael@0 196 {
michael@0 197 mListener = aListener;
michael@0 198 return NS_OK;
michael@0 199 }
michael@0 200
michael@0 201 NS_IMETHODIMP
michael@0 202 nsAutoCompleteSimpleResult::RemoveValueAt(int32_t aRowIndex,
michael@0 203 bool aRemoveFromDb)
michael@0 204 {
michael@0 205 NS_ENSURE_TRUE(aRowIndex >= 0 && aRowIndex < int32_t(mValues.Length()),
michael@0 206 NS_ERROR_ILLEGAL_VALUE);
michael@0 207
michael@0 208 nsAutoString removedValue(mValues[aRowIndex]);
michael@0 209 mValues.RemoveElementAt(aRowIndex);
michael@0 210 mComments.RemoveElementAt(aRowIndex);
michael@0 211 mImages.RemoveElementAt(aRowIndex);
michael@0 212 mStyles.RemoveElementAt(aRowIndex);
michael@0 213 mFinalCompleteValues.RemoveElementAt(aRowIndex);
michael@0 214
michael@0 215 if (mListener)
michael@0 216 mListener->OnValueRemoved(this, removedValue, aRemoveFromDb);
michael@0 217
michael@0 218 return NS_OK;
michael@0 219 }

mercurial