Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1016)

Unified Diff: Source/core/html/HTMLLinkElement.cpp

Issue 196743002: Parse the link element's size attribute (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: use charactersToInt Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/html/HTMLLinkElement.cpp
diff --git a/Source/core/html/HTMLLinkElement.cpp b/Source/core/html/HTMLLinkElement.cpp
index 9025639b7fae91cba4e8635db5337f4b3d32c78f..20a30c632f6b99422a682517c41432f1b3b986a6 100644
--- a/Source/core/html/HTMLLinkElement.cpp
+++ b/Source/core/html/HTMLLinkElement.cpp
@@ -52,12 +52,85 @@ namespace WebCore {
using namespace HTMLNames;
+template <typename CharacterType>
+static void parseSizes(const CharacterType value, unsigned length, Vector<IntSize>& iconSizes)
Inactive 2014/03/14 20:36:18 const CharacterType* ?
michaelbai 2014/03/14 20:49:06 Done.
+{
+ enum State {
+ ParseStart,
+ ParseWidth,
+ ParseHeight
+ };
+ int width = 0;
+ unsigned start = 0;
+ unsigned i = 0;
+ State state = ParseStart;
+ bool invalid = false;
+ while (i < length) {
Inactive 2014/03/14 20:36:18 I think a for loop would be slightly better here s
michaelbai 2014/03/14 20:49:06 Done.
+ if (state == ParseWidth) {
+ if (value[i] == 'x' || value[i] == 'X') {
+ if (i == start) {
+ invalid = true;
+ break;
+ }
+ width = charactersToInt(value + start, i - start);
+ start = i + 1;
+ state = ParseHeight;
+ } else if (value[i] < '0' || value[i] > '9') {
+ invalid = true;
+ break;
+ }
+ } else if (state == ParseHeight) {
+ if (value[i] == ' ') {
+ if (i == start) {
+ invalid = true;
+ break;
+ }
+ int height = charactersToInt(value + start, i - start);
+ iconSizes.append(IntSize(width, height));
+ start = i + 1;
+ state = ParseStart;
+ } else if (value[i] < '0' || value[i] > '9') {
+ invalid = true;
+ break;
+ }
+ } else if (state == ParseStart) {
+ if (value[i] >= '0' && value[i] <= '9') {
+ start = i;
+ state = ParseWidth;
+ } else if (value[i] != ' ') {
+ invalid = true;
+ break;
+ }
+ }
+ ++i;
+ }
+ if (invalid || state == ParseWidth || (state == ParseHeight && start == i)) {
+ iconSizes.clear();
+ return;
+ }
+ if (state == ParseHeight && i > start) {
+ int height = charactersToInt(value + start, i - start);
+ iconSizes.append(IntSize(width, height));
+ }
+}
+
static LinkEventSender& linkLoadEventSender()
{
DEFINE_STATIC_LOCAL(LinkEventSender, sharedLoadEventSender, (EventTypeNames::load));
return sharedLoadEventSender;
}
+void HTMLLinkElement::parseSizesAttribute(const AtomicString& value, Vector<IntSize>& iconSizes)
+{
+ ASSERT(iconSizes.isEmpty());
+ if (value.isEmpty())
+ return;
+ if (value.is8Bit())
+ parseSizes(value.characters8(), value.length(), iconSizes);
+ else
+ parseSizes(value.characters16(), value.length(), iconSizes);
+}
+
inline HTMLLinkElement::HTMLLinkElement(Document& document, bool createdByParser)
: HTMLElement(linkTag, document)
, m_linkLoader(this)
@@ -96,6 +169,7 @@ void HTMLLinkElement::parseAttribute(const QualifiedName& name, const AtomicStri
process();
} else if (name == sizesAttr) {
m_sizes->setValue(value);
+ parseSizesAttribute(value, m_iconSizes);
process();
} else if (name == mediaAttr) {
m_media = value.string().lower();
@@ -347,9 +421,9 @@ IconType HTMLLinkElement::iconType() const
return m_relAttribute.iconType();
}
-const AtomicString& HTMLLinkElement::iconSizes() const
+const Vector<IntSize>& HTMLLinkElement::iconSizes() const
{
- return m_sizes->toString();
+ return m_iconSizes;
}
DOMSettableTokenList* HTMLLinkElement::sizes() const

Powered by Google App Engine
This is Rietveld 408576698