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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2003, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv ed. 5 * Copyright (C) 2003, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv ed.
6 * Copyright (C) 2009 Rob Buis (rwlbuis@gmail.com) 6 * Copyright (C) 2009 Rob Buis (rwlbuis@gmail.com)
7 * Copyright (C) 2011 Google Inc. All rights reserved. 7 * Copyright (C) 2011 Google Inc. All rights reserved.
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "core/frame/csp/ContentSecurityPolicy.h" 45 #include "core/frame/csp/ContentSecurityPolicy.h"
46 #include "core/html/imports/LinkImport.h" 46 #include "core/html/imports/LinkImport.h"
47 #include "core/loader/FrameLoader.h" 47 #include "core/loader/FrameLoader.h"
48 #include "core/loader/FrameLoaderClient.h" 48 #include "core/loader/FrameLoaderClient.h"
49 #include "wtf/StdLibExtras.h" 49 #include "wtf/StdLibExtras.h"
50 50
51 namespace WebCore { 51 namespace WebCore {
52 52
53 using namespace HTMLNames; 53 using namespace HTMLNames;
54 54
55 template <typename CharacterType>
56 static void parseSizes(const CharacterType value, unsigned length, Vector<IntSiz e>& iconSizes)
Inactive 2014/03/14 20:36:18 const CharacterType* ?
michaelbai 2014/03/14 20:49:06 Done.
57 {
58 enum State {
59 ParseStart,
60 ParseWidth,
61 ParseHeight
62 };
63 int width = 0;
64 unsigned start = 0;
65 unsigned i = 0;
66 State state = ParseStart;
67 bool invalid = false;
68 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.
69 if (state == ParseWidth) {
70 if (value[i] == 'x' || value[i] == 'X') {
71 if (i == start) {
72 invalid = true;
73 break;
74 }
75 width = charactersToInt(value + start, i - start);
76 start = i + 1;
77 state = ParseHeight;
78 } else if (value[i] < '0' || value[i] > '9') {
79 invalid = true;
80 break;
81 }
82 } else if (state == ParseHeight) {
83 if (value[i] == ' ') {
84 if (i == start) {
85 invalid = true;
86 break;
87 }
88 int height = charactersToInt(value + start, i - start);
89 iconSizes.append(IntSize(width, height));
90 start = i + 1;
91 state = ParseStart;
92 } else if (value[i] < '0' || value[i] > '9') {
93 invalid = true;
94 break;
95 }
96 } else if (state == ParseStart) {
97 if (value[i] >= '0' && value[i] <= '9') {
98 start = i;
99 state = ParseWidth;
100 } else if (value[i] != ' ') {
101 invalid = true;
102 break;
103 }
104 }
105 ++i;
106 }
107 if (invalid || state == ParseWidth || (state == ParseHeight && start == i)) {
108 iconSizes.clear();
109 return;
110 }
111 if (state == ParseHeight && i > start) {
112 int height = charactersToInt(value + start, i - start);
113 iconSizes.append(IntSize(width, height));
114 }
115 }
116
55 static LinkEventSender& linkLoadEventSender() 117 static LinkEventSender& linkLoadEventSender()
56 { 118 {
57 DEFINE_STATIC_LOCAL(LinkEventSender, sharedLoadEventSender, (EventTypeNames: :load)); 119 DEFINE_STATIC_LOCAL(LinkEventSender, sharedLoadEventSender, (EventTypeNames: :load));
58 return sharedLoadEventSender; 120 return sharedLoadEventSender;
59 } 121 }
60 122
123 void HTMLLinkElement::parseSizesAttribute(const AtomicString& value, Vector<IntS ize>& iconSizes)
124 {
125 ASSERT(iconSizes.isEmpty());
126 if (value.isEmpty())
127 return;
128 if (value.is8Bit())
129 parseSizes(value.characters8(), value.length(), iconSizes);
130 else
131 parseSizes(value.characters16(), value.length(), iconSizes);
132 }
133
61 inline HTMLLinkElement::HTMLLinkElement(Document& document, bool createdByParser ) 134 inline HTMLLinkElement::HTMLLinkElement(Document& document, bool createdByParser )
62 : HTMLElement(linkTag, document) 135 : HTMLElement(linkTag, document)
63 , m_linkLoader(this) 136 , m_linkLoader(this)
64 , m_sizes(DOMSettableTokenList::create()) 137 , m_sizes(DOMSettableTokenList::create())
65 , m_createdByParser(createdByParser) 138 , m_createdByParser(createdByParser)
66 , m_isInShadowTree(false) 139 , m_isInShadowTree(false)
67 , m_beforeLoadRecurseCount(0) 140 , m_beforeLoadRecurseCount(0)
68 { 141 {
69 ScriptWrappable::init(this); 142 ScriptWrappable::init(this);
70 } 143 }
(...skipping 18 matching lines...) Expand all
89 if (name == relAttr) { 162 if (name == relAttr) {
90 m_relAttribute = LinkRelAttribute(value); 163 m_relAttribute = LinkRelAttribute(value);
91 process(); 164 process();
92 } else if (name == hrefAttr) { 165 } else if (name == hrefAttr) {
93 process(); 166 process();
94 } else if (name == typeAttr) { 167 } else if (name == typeAttr) {
95 m_type = value; 168 m_type = value;
96 process(); 169 process();
97 } else if (name == sizesAttr) { 170 } else if (name == sizesAttr) {
98 m_sizes->setValue(value); 171 m_sizes->setValue(value);
172 parseSizesAttribute(value, m_iconSizes);
99 process(); 173 process();
100 } else if (name == mediaAttr) { 174 } else if (name == mediaAttr) {
101 m_media = value.string().lower(); 175 m_media = value.string().lower();
102 process(); 176 process();
103 } else if (name == disabledAttr) { 177 } else if (name == disabledAttr) {
104 if (LinkStyle* link = linkStyle()) 178 if (LinkStyle* link = linkStyle())
105 link->setDisabledState(!value.isNull()); 179 link->setDisabledState(!value.isNull());
106 } else if (name == onbeforeloadAttr) 180 } else if (name == onbeforeloadAttr)
107 setAttributeEventListener(EventTypeNames::beforeload, createAttributeEve ntListener(this, name, value)); 181 setAttributeEventListener(EventTypeNames::beforeload, createAttributeEve ntListener(this, name, value));
108 else { 182 else {
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 const AtomicString& HTMLLinkElement::type() const 414 const AtomicString& HTMLLinkElement::type() const
341 { 415 {
342 return getAttribute(typeAttr); 416 return getAttribute(typeAttr);
343 } 417 }
344 418
345 IconType HTMLLinkElement::iconType() const 419 IconType HTMLLinkElement::iconType() const
346 { 420 {
347 return m_relAttribute.iconType(); 421 return m_relAttribute.iconType();
348 } 422 }
349 423
350 const AtomicString& HTMLLinkElement::iconSizes() const 424 const Vector<IntSize>& HTMLLinkElement::iconSizes() const
351 { 425 {
352 return m_sizes->toString(); 426 return m_iconSizes;
353 } 427 }
354 428
355 DOMSettableTokenList* HTMLLinkElement::sizes() const 429 DOMSettableTokenList* HTMLLinkElement::sizes() const
356 { 430 {
357 return m_sizes.get(); 431 return m_sizes.get();
358 } 432 }
359 433
360 PassOwnPtr<LinkStyle> LinkStyle::create(HTMLLinkElement* owner) 434 PassOwnPtr<LinkStyle> LinkStyle::create(HTMLLinkElement* owner)
361 { 435 {
362 return adoptPtr(new LinkStyle(owner)); 436 return adoptPtr(new LinkStyle(owner));
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 void LinkStyle::ownerRemoved() 700 void LinkStyle::ownerRemoved()
627 { 701 {
628 if (m_sheet) 702 if (m_sheet)
629 clearSheet(); 703 clearSheet();
630 704
631 if (styleSheetIsLoading()) 705 if (styleSheetIsLoading())
632 removePendingSheet(RemovePendingSheetNotifyLater); 706 removePendingSheet(RemovePendingSheetNotifyLater);
633 } 707 }
634 708
635 } // namespace WebCore 709 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698