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.

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

mercurial