layout/style/nsDOMCSSValueList.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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 /* DOM object representing lists of values in DOM computed style */
michael@0 6
michael@0 7 #include "nsDOMCSSValueList.h"
michael@0 8 #include "mozilla/dom/CSSValueListBinding.h"
michael@0 9 #include "nsAutoPtr.h"
michael@0 10
michael@0 11 using namespace mozilla;
michael@0 12
michael@0 13 nsDOMCSSValueList::nsDOMCSSValueList(bool aCommaDelimited, bool aReadonly)
michael@0 14 : CSSValue(), mCommaDelimited(aCommaDelimited), mReadonly(aReadonly)
michael@0 15 {
michael@0 16 SetIsDOMBinding();
michael@0 17 }
michael@0 18
michael@0 19 nsDOMCSSValueList::~nsDOMCSSValueList()
michael@0 20 {
michael@0 21 }
michael@0 22
michael@0 23 NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMCSSValueList)
michael@0 24 NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMCSSValueList)
michael@0 25
michael@0 26 // QueryInterface implementation for nsDOMCSSValueList
michael@0 27 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDOMCSSValueList)
michael@0 28 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
michael@0 29 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSValue)
michael@0 30 NS_INTERFACE_MAP_ENTRY(nsIDOMCSSValueList)
michael@0 31 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, CSSValue)
michael@0 32 NS_INTERFACE_MAP_END
michael@0 33
michael@0 34 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(nsDOMCSSValueList, mCSSValues)
michael@0 35
michael@0 36 JSObject*
michael@0 37 nsDOMCSSValueList::WrapObject(JSContext *cx)
michael@0 38 {
michael@0 39 return dom::CSSValueListBinding::Wrap(cx, this);
michael@0 40 }
michael@0 41
michael@0 42 void
michael@0 43 nsDOMCSSValueList::AppendCSSValue(CSSValue* aValue)
michael@0 44 {
michael@0 45 mCSSValues.AppendElement(aValue);
michael@0 46 }
michael@0 47
michael@0 48 // nsIDOMCSSValue
michael@0 49
michael@0 50 NS_IMETHODIMP
michael@0 51 nsDOMCSSValueList::GetCssText(nsAString& aCssText)
michael@0 52 {
michael@0 53 aCssText.Truncate();
michael@0 54
michael@0 55 uint32_t count = mCSSValues.Length();
michael@0 56
michael@0 57 nsAutoString separator;
michael@0 58 if (mCommaDelimited) {
michael@0 59 separator.AssignLiteral(", ");
michael@0 60 }
michael@0 61 else {
michael@0 62 separator.Assign(char16_t(' '));
michael@0 63 }
michael@0 64
michael@0 65 nsAutoString tmpStr;
michael@0 66 for (uint32_t i = 0; i < count; ++i) {
michael@0 67 CSSValue *cssValue = mCSSValues[i];
michael@0 68 NS_ASSERTION(cssValue, "Eek! Someone filled the value list with null CSSValues!");
michael@0 69 ErrorResult dummy;
michael@0 70 if (cssValue) {
michael@0 71 cssValue->GetCssText(tmpStr, dummy);
michael@0 72
michael@0 73 if (tmpStr.IsEmpty()) {
michael@0 74
michael@0 75 #ifdef DEBUG_caillon
michael@0 76 NS_ERROR("Eek! An empty CSSValue! Bad!");
michael@0 77 #endif
michael@0 78
michael@0 79 continue;
michael@0 80 }
michael@0 81
michael@0 82 // If this isn't the first item in the list, then
michael@0 83 // it's ok to append a separator.
michael@0 84 if (!aCssText.IsEmpty()) {
michael@0 85 aCssText.Append(separator);
michael@0 86 }
michael@0 87 aCssText.Append(tmpStr);
michael@0 88 }
michael@0 89 }
michael@0 90
michael@0 91 return NS_OK;
michael@0 92 }
michael@0 93
michael@0 94 void
michael@0 95 nsDOMCSSValueList::GetCssText(nsString& aText, ErrorResult& aRv)
michael@0 96 {
michael@0 97 aRv = GetCssText(aText);
michael@0 98 }
michael@0 99
michael@0 100 NS_IMETHODIMP
michael@0 101 nsDOMCSSValueList::SetCssText(const nsAString& aCssText)
michael@0 102 {
michael@0 103 if (mReadonly) {
michael@0 104 return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
michael@0 105 }
michael@0 106
michael@0 107 NS_NOTYETIMPLEMENTED("Can't SetCssText yet: please write me!");
michael@0 108 return NS_OK;
michael@0 109 }
michael@0 110
michael@0 111 void
michael@0 112 nsDOMCSSValueList::SetCssText(const nsAString& aText, ErrorResult& aRv)
michael@0 113 {
michael@0 114 aRv = SetCssText(aText);
michael@0 115 }
michael@0 116
michael@0 117 NS_IMETHODIMP
michael@0 118 nsDOMCSSValueList::GetCssValueType(uint16_t* aValueType)
michael@0 119 {
michael@0 120 NS_ENSURE_ARG_POINTER(aValueType);
michael@0 121 *aValueType = nsIDOMCSSValue::CSS_VALUE_LIST;
michael@0 122 return NS_OK;
michael@0 123 }
michael@0 124
michael@0 125 uint16_t
michael@0 126 nsDOMCSSValueList::CssValueType() const
michael@0 127 {
michael@0 128 return nsIDOMCSSValue::CSS_VALUE_LIST;
michael@0 129 }

mercurial