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

Side by Side Diff: Source/core/css/FontFace.cpp

Issue 333163004: Remove explicit bounds check from CSSValueList::item (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: address comment Created 6 years, 6 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
« no previous file with comments | « Source/core/css/CSSValueList.idl ('k') | Source/core/css/StylePropertySerializer.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 } 312 }
313 return true; 313 return true;
314 } 314 }
315 315
316 bool FontFace::setFamilyValue(CSSValueList* familyList) 316 bool FontFace::setFamilyValue(CSSValueList* familyList)
317 { 317 {
318 // The font-family descriptor has to have exactly one family name. 318 // The font-family descriptor has to have exactly one family name.
319 if (familyList->length() != 1) 319 if (familyList->length() != 1)
320 return false; 320 return false;
321 321
322 CSSPrimitiveValue* familyValue = toCSSPrimitiveValue(familyList->itemWithout BoundsCheck(0)); 322 CSSPrimitiveValue* familyValue = toCSSPrimitiveValue(familyList->item(0));
323 AtomicString family; 323 AtomicString family;
324 if (familyValue->isString()) { 324 if (familyValue->isString()) {
325 family = AtomicString(familyValue->getStringValue()); 325 family = AtomicString(familyValue->getStringValue());
326 } else if (familyValue->isValueID()) { 326 } else if (familyValue->isValueID()) {
327 // We need to use the raw text for all the generic family types, since @ font-face is a way of actually 327 // We need to use the raw text for all the generic family types, since @ font-face is a way of actually
328 // defining what font to use for those types. 328 // defining what font to use for those types.
329 switch (familyValue->getValueID()) { 329 switch (familyValue->getValueID()) {
330 case CSSValueSerif: 330 case CSSValueSerif:
331 family = FontFamilyNames::webkit_serif; 331 family = FontFamilyNames::webkit_serif;
332 break; 332 break;
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 } else if (!fontVariant->isValueList()) { 508 } else if (!fontVariant->isValueList()) {
509 return 0; 509 return 0;
510 } 510 }
511 511
512 CSSValueList* variantList = toCSSValueList(fontVariant.get()); 512 CSSValueList* variantList = toCSSValueList(fontVariant.get());
513 unsigned numVariants = variantList->length(); 513 unsigned numVariants = variantList->length();
514 if (!numVariants) 514 if (!numVariants)
515 return 0; 515 return 0;
516 516
517 for (unsigned i = 0; i < numVariants; ++i) { 517 for (unsigned i = 0; i < numVariants; ++i) {
518 switch (toCSSPrimitiveValue(variantList->itemWithoutBoundsCheck(i))- >getValueID()) { 518 switch (toCSSPrimitiveValue(variantList->item(i))->getValueID()) {
519 case CSSValueNormal: 519 case CSSValueNormal:
520 variant = FontVariantNormal; 520 variant = FontVariantNormal;
521 break; 521 break;
522 case CSSValueSmallCaps: 522 case CSSValueSmallCaps:
523 variant = FontVariantSmallCaps; 523 variant = FontVariantSmallCaps;
524 break; 524 break;
525 default: 525 default:
526 break; 526 break;
527 } 527 }
528 } 528 }
529 } 529 }
530 530
531 return FontTraits(style, variant, weight, FontStretchNormal); 531 return FontTraits(style, variant, weight, FontStretchNormal);
532 } 532 }
533 533
534 static PassOwnPtrWillBeRawPtr<CSSFontFace> createCSSFontFace(FontFace* fontFace, CSSValue* unicodeRange) 534 static PassOwnPtrWillBeRawPtr<CSSFontFace> createCSSFontFace(FontFace* fontFace, CSSValue* unicodeRange)
535 { 535 {
536 Vector<CSSFontFace::UnicodeRange> ranges; 536 Vector<CSSFontFace::UnicodeRange> ranges;
537 if (CSSValueList* rangeList = toCSSValueList(unicodeRange)) { 537 if (CSSValueList* rangeList = toCSSValueList(unicodeRange)) {
538 unsigned numRanges = rangeList->length(); 538 unsigned numRanges = rangeList->length();
539 for (unsigned i = 0; i < numRanges; i++) { 539 for (unsigned i = 0; i < numRanges; i++) {
540 CSSUnicodeRangeValue* range = toCSSUnicodeRangeValue(rangeList->item WithoutBoundsCheck(i)); 540 CSSUnicodeRangeValue* range = toCSSUnicodeRangeValue(rangeList->item (i));
541 ranges.append(CSSFontFace::UnicodeRange(range->from(), range->to())) ; 541 ranges.append(CSSFontFace::UnicodeRange(range->from(), range->to())) ;
542 } 542 }
543 } 543 }
544 544
545 return adoptPtrWillBeNoop(new CSSFontFace(fontFace, ranges)); 545 return adoptPtrWillBeNoop(new CSSFontFace(fontFace, ranges));
546 } 546 }
547 547
548 void FontFace::initCSSFontFace(Document* document, PassRefPtrWillBeRawPtr<CSSVal ue> src) 548 void FontFace::initCSSFontFace(Document* document, PassRefPtrWillBeRawPtr<CSSVal ue> src)
549 { 549 {
550 m_cssFontFace = createCSSFontFace(this, m_unicodeRange.get()); 550 m_cssFontFace = createCSSFontFace(this, m_unicodeRange.get());
551 551
552 // Each item in the src property's list is a single CSSFontFaceSource. Put t hem all into a CSSFontFace. 552 // Each item in the src property's list is a single CSSFontFaceSource. Put t hem all into a CSSFontFace.
553 CSSValueList* srcList = toCSSValueList(src.get()); 553 CSSValueList* srcList = toCSSValueList(src.get());
554 int srcLength = srcList->length(); 554 int srcLength = srcList->length();
555 555
556 bool foundSVGFont = false; 556 bool foundSVGFont = false;
557 557
558 for (int i = 0; i < srcLength; i++) { 558 for (int i = 0; i < srcLength; i++) {
559 // An item in the list either specifies a string (local font name) or a URL (remote font to download). 559 // An item in the list either specifies a string (local font name) or a URL (remote font to download).
560 CSSFontFaceSrcValue* item = toCSSFontFaceSrcValue(srcList->itemWithoutBo undsCheck(i)); 560 CSSFontFaceSrcValue* item = toCSSFontFaceSrcValue(srcList->item(i));
561 OwnPtrWillBeRawPtr<CSSFontFaceSource> source = nullptr; 561 OwnPtrWillBeRawPtr<CSSFontFaceSource> source = nullptr;
562 562
563 #if ENABLE(SVG_FONTS) 563 #if ENABLE(SVG_FONTS)
564 foundSVGFont = item->isSVGFontFaceSrc() || item->svgFontFaceElement(); 564 foundSVGFont = item->isSVGFontFaceSrc() || item->svgFontFaceElement();
565 #endif 565 #endif
566 if (!item->isLocal()) { 566 if (!item->isLocal()) {
567 Settings* settings = document ? document->frame() ? document->frame( )->settings() : 0 : 0; 567 Settings* settings = document ? document->frame() ? document->frame( )->settings() : 0 : 0;
568 bool allowDownloading = foundSVGFont || (settings && settings->downl oadableBinaryFontsEnabled()); 568 bool allowDownloading = foundSVGFont || (settings && settings->downl oadableBinaryFontsEnabled());
569 if (allowDownloading && item->isSupportedFormat() && document) { 569 if (allowDownloading && item->isSupportedFormat() && document) {
570 FontResource* fetched = item->fetch(document); 570 FontResource* fetched = item->fetch(document);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 visitor->trace(m_cssFontFace); 630 visitor->trace(m_cssFontFace);
631 visitor->trace(m_callbacks); 631 visitor->trace(m_callbacks);
632 } 632 }
633 633
634 bool FontFace::hadBlankText() const 634 bool FontFace::hadBlankText() const
635 { 635 {
636 return m_cssFontFace->hadBlankText(); 636 return m_cssFontFace->hadBlankText();
637 } 637 }
638 638
639 } // namespace WebCore 639 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/css/CSSValueList.idl ('k') | Source/core/css/StylePropertySerializer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698