| Index: third_party/WebKit/Source/core/css/serializer/CSSDeserializeStream.cpp
|
| diff --git a/third_party/WebKit/Source/core/css/serializer/CSSDeserializeStream.cpp b/third_party/WebKit/Source/core/css/serializer/CSSDeserializeStream.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..d707dee92a5b695b74528d1e92d6951bb6327a28
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/core/css/serializer/CSSDeserializeStream.cpp
|
| @@ -0,0 +1,184 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "core/css/serializer/CSSDeserializeStream.h"
|
| +
|
| +#include "core/HTMLNames.h"
|
| +#include "core/css/CSSProperty.h"
|
| +#include "core/css/serializer/CSSSerializeStream.h" // FIXME: Remove
|
| +#include "platform/weborigin/Referrer.h"
|
| +
|
| +namespace blink {
|
| +
|
| +inline void CSSDeserializeStream::padIfNeeded()
|
| +{
|
| + uintptr_t misalign = reinterpret_cast<uintptr_t>(m_ptr) & 0x3;
|
| + if (!misalign)
|
| + return;
|
| + unsigned padding = 4 - static_cast<unsigned>(misalign);
|
| + CSDEBUG("padding %d\n", padding);
|
| + m_ptr += padding;
|
| +}
|
| +
|
| +CSSDeserializeStream::CSSDeserializeStream(const char* data, size_t size)
|
| + : m_ptr(data)
|
| + , m_ptrEnd(data + size)
|
| +{
|
| +}
|
| +
|
| +inline size_t CSSDeserializeStream::unconsumedSize() const
|
| +{
|
| + return m_ptrEnd - m_ptr;
|
| +}
|
| +
|
| +CSSValue::ClassType CSSDeserializeStream::readClassType()
|
| +{
|
| + CSDEBUG("read classType ");
|
| + return static_cast<CSSValue::ClassType>(readUnsigned());
|
| +}
|
| +
|
| +Color CSSDeserializeStream::readColor()
|
| +{
|
| + CSDEBUG("read color ");
|
| + return Color(static_cast<RGBA32>(readUnsigned()));
|
| +}
|
| +
|
| +bool CSSDeserializeStream::readBool()
|
| +{
|
| + RELEASE_ASSERT(unconsumedSize() >= 1);
|
| +
|
| + char c = *reinterpret_cast<const char*>(m_ptr);
|
| + m_ptr += 1;
|
| + CSDEBUG("read bool %d\n", c);
|
| +
|
| + return c;
|
| +}
|
| +
|
| +int CSSDeserializeStream::readInt()
|
| +{
|
| + padIfNeeded();
|
| + RELEASE_ASSERT(unconsumedSize() >= sizeof(int));
|
| +
|
| + int n = *reinterpret_cast<const int*>(m_ptr);
|
| + m_ptr += sizeof(int);
|
| + CSDEBUG("read int %d %x\n", n, n);
|
| +
|
| + return n;
|
| +}
|
| +
|
| +unsigned CSSDeserializeStream::readUnsigned()
|
| +{
|
| + padIfNeeded();
|
| + RELEASE_ASSERT(unconsumedSize() >= sizeof(unsigned));
|
| +
|
| + unsigned u = *reinterpret_cast<const unsigned*>(m_ptr);
|
| + m_ptr += sizeof(unsigned);
|
| + CSDEBUG("read unsigned %u %x\n", u, u);
|
| +
|
| + return u;
|
| +}
|
| +
|
| +double CSSDeserializeStream::readDouble()
|
| +{
|
| + padIfNeeded();
|
| + RELEASE_ASSERT(unconsumedSize() >= sizeof(double));
|
| +
|
| + double d = *reinterpret_cast<const double*>(m_ptr);
|
| + m_ptr += sizeof(double);
|
| + CSDEBUG("read double %f\n", d);
|
| +
|
| + return d;
|
| +}
|
| +
|
| +UChar32 CSSDeserializeStream::readUChar32()
|
| +{
|
| + padIfNeeded();
|
| + RELEASE_ASSERT(unconsumedSize() >= sizeof(UChar32));
|
| +
|
| + UChar32 u = *reinterpret_cast<const UChar32*>(m_ptr);
|
| + m_ptr += sizeof(UChar32);
|
| + CSDEBUG("read UChar32 %u\n", u);
|
| +
|
| + return u;
|
| +}
|
| +
|
| +String CSSDeserializeStream::readString()
|
| +{
|
| + unsigned length = readUnsigned();
|
| + if (!length) {
|
| + CSDEBUG("read String <empty>\n");
|
| + return emptyString();
|
| + } else if (length == 0xffffffff) {
|
| + CSDEBUG("read String <null>\n");
|
| + return String();
|
| + }
|
| + bool is8Bit = readUnsigned();
|
| +
|
| + if (is8Bit) {
|
| + RELEASE_ASSERT(unconsumedSize() >= length);
|
| + String ret(reinterpret_cast<const LChar*>(m_ptr), length);
|
| + m_ptr += length;
|
| +
|
| + CSDEBUG("read String "); CSSHOW(ret);
|
| + return ret;
|
| + } else {
|
| + RELEASE_ASSERT(unconsumedSize() >= length);
|
| + String ret(reinterpret_cast<const UChar*>(m_ptr), length);
|
| + m_ptr += length * 2;
|
| +
|
| + CSDEBUG("read String "); CSSHOW(ret);
|
| + return ret;
|
| + }
|
| +}
|
| +
|
| +AtomicString CSSDeserializeStream::readAtomicString()
|
| +{
|
| + CSDEBUG("read AtomicString ");
|
| + String str = readString();
|
| + unsigned hash = readUnsigned();
|
| + if (hash)
|
| + str.impl()->setHash(hash);
|
| + return AtomicString(str);
|
| +}
|
| +
|
| +static const HTMLQualifiedName** htmlTagsArray()
|
| +{
|
| + DEFINE_STATIC_LOCAL(OwnPtr<const HTMLQualifiedName*[]>, array, ());
|
| + if (!array) {
|
| + array = HTMLNames::getHTMLTags();
|
| + }
|
| + return array.get();
|
| +}
|
| +
|
| +QualifiedName CSSDeserializeStream::readQualifiedName()
|
| +{
|
| + CSDEBUG("read QualifiedName ");
|
| +
|
| + int id = readInt();
|
| + if (id >= 0) {
|
| + return *htmlTagsArray()[id];
|
| + }
|
| +
|
| + AtomicString namespaceURI = starAtom;
|
| + AtomicString localName(readAtomicString());
|
| +
|
| + return QualifiedName(nullAtom, localName, namespaceURI);
|
| +}
|
| +
|
| +StylePropertyMetadata CSSDeserializeStream::readStylePropertyMetadata()
|
| +{
|
| + CSDEBUG("read StylePropertyMetadata ");
|
| + unsigned u = readUnsigned();
|
| + return *reinterpret_cast<StylePropertyMetadata*>(&u);
|
| +}
|
| +
|
| +Referrer CSSDeserializeStream::readReferrer()
|
| +{
|
| + Referrer referrer;
|
| + referrer.referrer = readAtomicString();
|
| + referrer.referrerPolicy = readIntAsEnum<ReferrerPolicy>();
|
| + return referrer;
|
| +}
|
| +
|
| +} // namespace blink
|
|
|