Don't expose internal CSSValues in API
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Apr 2012 17:01:06 +0000 (17:01 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 9 Apr 2012 17:01:06 +0000 (17:01 +0000)
commit4ec41ca500c9bc17a03c79e6249529d6bd8dd396
tree69dcfedde8c2711a8c4ea5824bde2943e4983fe7
parent550929dfc2e6a8d18bfe7a2de634c8f74b28b1f7
Don't expose internal CSSValues in API
https://bugs.webkit.org/show_bug.cgi?id=83426

Reviewed by Andreas Kling.

The CSSValues returned from functions like CSSStyleDeclaration.getPropertyCSSValue() are currently
the same instances we use internally. This creates various problems. The values can't be shared between
documents as the wrappers would be shared too. Having to maintain per-document CSSValuePools complicate
the architecture and increase memory usage. This also blocks sharing style sheet data structures
between documents.

This patch adds a concept of CSSOM-safe CSSValue. Only the safe values can be wrapped for JS access.
Values are unsafe by default. The CSSOM functions that return CSSValues create safe instances by
cloning the internal values.

The use of APIs that return CSSValues is very rare (the currect CSSOM draft deprecates them) and
cloning is cheap in any case. Future patches will eliminate the per-document value pool in favor
of a global one for a memory win.

In the future we want to replace internally used CSSValues with true internal types (StyleValues) and
use CSSValues exclusively as wrappers (similar to how CSSStyleRule wraps internal StyleRule).

* bindings/js/JSCSSValueCustom.cpp:
(WebCore::toJS):
* css/CSSComputedStyleDeclaration.cpp:
(WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue):
(WebCore::CSSComputedStyleDeclaration::getPropertyCSSValueInternal):
* css/CSSImageSetValue.cpp:
(WebCore::CSSImageSetValue::CSSImageSetValue):
(WebCore):
(WebCore::CSSImageSetValue::cloneForCSSOM):
* css/CSSImageSetValue.h:
(CSSImageSetValue):
* css/CSSPrimitiveValue.cpp:
(WebCore::CSSPrimitiveValue::cleanup):

    Opportunistically fix a string leak for CSS_COUNTER_NAME values.
    Add all cases, remove default.

(WebCore::CSSPrimitiveValue::cloneForCSSOM):
(WebCore):
* css/CSSPrimitiveValue.h:
(CSSPrimitiveValue):
(WebCore::CSSPrimitiveValue::setCSSOMSafe):
* css/CSSValue.cpp:
(WebCore):
(TextCloneCSSValue):
(WebCore::TextCloneCSSValue::create):
(WebCore::TextCloneCSSValue::cssText):
(WebCore::TextCloneCSSValue::TextCloneCSSValue):

    Most non-primitive value types are not exposed in CSSOM. For those we create a dummy value
    that contains only the data that is accessible though the base CSSValue interface.

(WebCore::CSSValue::addSubresourceStyleURLs):
(WebCore::CSSValue::cssText):
(WebCore::CSSValue::destroy):
(WebCore::CSSValue::cloneForCSSOM):
* css/CSSValue.h:
(WebCore):
(CSSValue):
(WebCore::CSSValue::isCSSOMSafe):
(WebCore::CSSValue::isSubtypeExposedToCSSOM):
(WebCore::CSSValue::CSSValue):
* css/CSSValueList.cpp:
(WebCore::CSSValueList::CSSValueList):
(WebCore):
(WebCore::CSSValueList::cloneForCSSOM):
* css/CSSValueList.h:
(CSSValueList):
* css/Counter.h:
(Counter):
(WebCore::Counter::cloneForCSSOM):
* css/PropertySetCSSStyleDeclaration.cpp:
(WebCore::PropertySetCSSStyleDeclaration::setCssText):
(WebCore::PropertySetCSSStyleDeclaration::getPropertyCSSValue):
(WebCore::PropertySetCSSStyleDeclaration::setProperty):
(WebCore::PropertySetCSSStyleDeclaration::removeProperty):
(WebCore::PropertySetCSSStyleDeclaration::getPropertyCSSValueInternal):
(WebCore::PropertySetCSSStyleDeclaration::setPropertyInternal):
(WebCore::PropertySetCSSStyleDeclaration::didMutate):
(WebCore):
(WebCore::PropertySetCSSStyleDeclaration::cloneAndCacheForCSSOM):

    Maintain a map of safe CSSValues so we can maintain object identity.

* css/PropertySetCSSStyleDeclaration.h:
(WebCore::PropertySetCSSStyleDeclaration::setNeedsStyleRecalc):
(PropertySetCSSStyleDeclaration):
* css/RGBColor.cpp:
(WebCore::RGBColor::red):
(WebCore::RGBColor::green):
(WebCore::RGBColor::blue):
(WebCore::RGBColor::alpha):
* css/Rect.h:
(WebCore::RectBase::RectBase):
(RectBase):
(Rect):
(WebCore::Rect::cloneForCSSOM):
(WebCore::Rect::Rect):
(Quad):
(WebCore::Quad::cloneForCSSOM):
(WebCore::Quad::Quad):
* css/WebKitCSSFilterValue.cpp:
(WebCore::WebKitCSSFilterValue::WebKitCSSFilterValue):
(WebCore):
(WebCore::WebKitCSSFilterValue::cloneForCSSOM):
* css/WebKitCSSFilterValue.h:
(WebKitCSSFilterValue):
* css/WebKitCSSTransformValue.cpp:
(WebCore::WebKitCSSTransformValue::WebKitCSSTransformValue):
(WebCore):
(WebCore::WebKitCSSTransformValue::cloneForCSSOM):
* css/WebKitCSSTransformValue.h:
(WebKitCSSTransformValue):
* svg/SVGColor.cpp:
(WebCore::SVGColor::SVGColor):
(WebCore):
(WebCore::SVGColor::cloneForCSSOM):
* svg/SVGColor.h:
(SVGColor):
* svg/SVGPaint.cpp:
(WebCore::SVGPaint::SVGPaint):
(WebCore):
(WebCore::SVGPaint::cloneForCSSOM):
* svg/SVGPaint.h:
(SVGPaint):
* svg/SVGStyledElement.cpp:
(WebCore::SVGStyledElement::getPresentationAttribute):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@113588 268f45cc-cd09-0410-ab3c-d52691b4dbfc
25 files changed:
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSCSSValueCustom.cpp
Source/WebCore/css/CSSComputedStyleDeclaration.cpp
Source/WebCore/css/CSSImageSetValue.cpp
Source/WebCore/css/CSSImageSetValue.h
Source/WebCore/css/CSSPrimitiveValue.cpp
Source/WebCore/css/CSSPrimitiveValue.h
Source/WebCore/css/CSSValue.cpp
Source/WebCore/css/CSSValue.h
Source/WebCore/css/CSSValueList.cpp
Source/WebCore/css/CSSValueList.h
Source/WebCore/css/Counter.h
Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp
Source/WebCore/css/PropertySetCSSStyleDeclaration.h
Source/WebCore/css/RGBColor.cpp
Source/WebCore/css/Rect.h
Source/WebCore/css/WebKitCSSFilterValue.cpp
Source/WebCore/css/WebKitCSSFilterValue.h
Source/WebCore/css/WebKitCSSTransformValue.cpp
Source/WebCore/css/WebKitCSSTransformValue.h
Source/WebCore/svg/SVGColor.cpp
Source/WebCore/svg/SVGColor.h
Source/WebCore/svg/SVGPaint.cpp
Source/WebCore/svg/SVGPaint.h
Source/WebCore/svg/SVGStyledElement.cpp