| OLD | NEW |
| 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, 2010 Apple Inc. All rights reserved. | 5 * Copyright (C) 2003, 2010 Apple Inc. All rights reserved. |
| 6 * | 6 * |
| 7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '=' || | 53 return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '=' || |
| 54 c == ',' || c == '\0'; | 54 c == ',' || c == '\0'; |
| 55 } | 55 } |
| 56 | 56 |
| 57 void HTMLMetaElement::parseContentAttribute(const String& content, | 57 void HTMLMetaElement::parseContentAttribute(const String& content, |
| 58 void* data, | 58 void* data, |
| 59 Document* document, | 59 Document* document, |
| 60 bool viewportMetaZeroValuesQuirk) { | 60 bool viewportMetaZeroValuesQuirk) { |
| 61 bool hasInvalidSeparator = false; | 61 bool hasInvalidSeparator = false; |
| 62 | 62 |
| 63 // Tread lightly in this code -- it was specifically designed to mimic Win IE'
s parsing behavior. | 63 // Tread lightly in this code -- it was specifically designed to mimic Win |
| 64 // IE's parsing behavior. |
| 64 unsigned keyBegin, keyEnd; | 65 unsigned keyBegin, keyEnd; |
| 65 unsigned valueBegin, valueEnd; | 66 unsigned valueBegin, valueEnd; |
| 66 | 67 |
| 67 String buffer = content.lower(); | 68 String buffer = content.lower(); |
| 68 unsigned length = buffer.length(); | 69 unsigned length = buffer.length(); |
| 69 for (unsigned i = 0; i < length; /* no increment here */) { | 70 for (unsigned i = 0; i < length; /* no increment here */) { |
| 70 // skip to first non-separator, but don't skip past the end of the string | 71 // skip to first non-separator, but don't skip past the end of the string |
| 71 while (isSeparator(buffer[i])) { | 72 while (isSeparator(buffer[i])) { |
| 72 if (i >= length) | 73 if (i >= length) |
| 73 break; | 74 break; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 85 keyEnd = i; | 86 keyEnd = i; |
| 86 | 87 |
| 87 // skip to first '=', but don't skip past a ',' or the end of the string | 88 // skip to first '=', but don't skip past a ',' or the end of the string |
| 88 while (buffer[i] != '=') { | 89 while (buffer[i] != '=') { |
| 89 hasInvalidSeparator |= isInvalidSeparator(buffer[i]); | 90 hasInvalidSeparator |= isInvalidSeparator(buffer[i]); |
| 90 if (buffer[i] == ',' || i >= length) | 91 if (buffer[i] == ',' || i >= length) |
| 91 break; | 92 break; |
| 92 i++; | 93 i++; |
| 93 } | 94 } |
| 94 | 95 |
| 95 // skip to first non-separator, but don't skip past a ',' or the end of the
string | 96 // Skip to first non-separator, but don't skip past a ',' or the end of the |
| 97 // string. |
| 96 while (isSeparator(buffer[i])) { | 98 while (isSeparator(buffer[i])) { |
| 97 if (buffer[i] == ',' || i >= length) | 99 if (buffer[i] == ',' || i >= length) |
| 98 break; | 100 break; |
| 99 i++; | 101 i++; |
| 100 } | 102 } |
| 101 valueBegin = i; | 103 valueBegin = i; |
| 102 | 104 |
| 103 // skip to first separator | 105 // skip to first separator |
| 104 while (!isSeparator(buffer[i])) { | 106 while (!isSeparator(buffer[i])) { |
| 105 hasInvalidSeparator |= isInvalidSeparator(buffer[i]); | 107 hasInvalidSeparator |= isInvalidSeparator(buffer[i]); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 return clampedValue; | 236 return clampedValue; |
| 235 } | 237 } |
| 236 | 238 |
| 237 bool HTMLMetaElement::parseViewportValueAsUserZoom( | 239 bool HTMLMetaElement::parseViewportValueAsUserZoom( |
| 238 Document* document, | 240 Document* document, |
| 239 bool reportWarnings, | 241 bool reportWarnings, |
| 240 const String& keyString, | 242 const String& keyString, |
| 241 const String& valueString, | 243 const String& valueString, |
| 242 bool& computedValueMatchesParsedValue) { | 244 bool& computedValueMatchesParsedValue) { |
| 243 // yes and no are used as keywords. | 245 // yes and no are used as keywords. |
| 244 // Numbers >= 1, numbers <= -1, device-width and device-height are mapped to y
es. | 246 // Numbers >= 1, numbers <= -1, device-width and device-height are mapped to |
| 247 // yes. |
| 245 // Numbers in the range <-1, 1>, and unknown values, are mapped to no. | 248 // Numbers in the range <-1, 1>, and unknown values, are mapped to no. |
| 246 | 249 |
| 247 computedValueMatchesParsedValue = false; | 250 computedValueMatchesParsedValue = false; |
| 248 if (equalIgnoringCase(valueString, "yes")) { | 251 if (equalIgnoringCase(valueString, "yes")) { |
| 249 computedValueMatchesParsedValue = true; | 252 computedValueMatchesParsedValue = true; |
| 250 return true; | 253 return true; |
| 251 } | 254 } |
| 252 if (equalIgnoringCase(valueString, "no")) { | 255 if (equalIgnoringCase(valueString, "no")) { |
| 253 computedValueMatchesParsedValue = true; | 256 computedValueMatchesParsedValue = true; |
| 254 return false; | 257 return false; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 const String& replacement2) { | 381 const String& replacement2) { |
| 379 if (!document || !document->frame()) | 382 if (!document || !document->frame()) |
| 380 return; | 383 return; |
| 381 | 384 |
| 382 String message = viewportErrorMessageTemplate(errorCode); | 385 String message = viewportErrorMessageTemplate(errorCode); |
| 383 if (!replacement1.isNull()) | 386 if (!replacement1.isNull()) |
| 384 message.replace("%replacement1", replacement1); | 387 message.replace("%replacement1", replacement1); |
| 385 if (!replacement2.isNull()) | 388 if (!replacement2.isNull()) |
| 386 message.replace("%replacement2", replacement2); | 389 message.replace("%replacement2", replacement2); |
| 387 | 390 |
| 388 // FIXME: This message should be moved off the console once a solution to http
s://bugs.webkit.org/show_bug.cgi?id=103274 exists. | 391 // FIXME: This message should be moved off the console once a solution to |
| 392 // https://bugs.webkit.org/show_bug.cgi?id=103274 exists. |
| 389 document->addConsoleMessage(ConsoleMessage::create( | 393 document->addConsoleMessage(ConsoleMessage::create( |
| 390 RenderingMessageSource, viewportErrorMessageLevel(errorCode), message)); | 394 RenderingMessageSource, viewportErrorMessageLevel(errorCode), message)); |
| 391 } | 395 } |
| 392 | 396 |
| 393 void HTMLMetaElement::getViewportDescriptionFromContentAttribute( | 397 void HTMLMetaElement::getViewportDescriptionFromContentAttribute( |
| 394 const String& content, | 398 const String& content, |
| 395 ViewportDescription& description, | 399 ViewportDescription& description, |
| 396 Document* document, | 400 Document* document, |
| 397 bool viewportMetaZeroValuesQuirk) { | 401 bool viewportMetaZeroValuesQuirk) { |
| 398 parseContentAttribute(content, (void*)&description, document, | 402 parseContentAttribute(content, (void*)&description, document, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 if (!element->isConnected()) | 456 if (!element->isConnected()) |
| 453 return false; | 457 return false; |
| 454 | 458 |
| 455 return Traversal<HTMLHeadElement>::firstAncestor(*element); | 459 return Traversal<HTMLHeadElement>::firstAncestor(*element); |
| 456 } | 460 } |
| 457 | 461 |
| 458 void HTMLMetaElement::process() { | 462 void HTMLMetaElement::process() { |
| 459 if (!isConnected()) | 463 if (!isConnected()) |
| 460 return; | 464 return; |
| 461 | 465 |
| 462 // All below situations require a content attribute (which can be the empty st
ring). | 466 // All below situations require a content attribute (which can be the empty |
| 467 // string). |
| 463 const AtomicString& contentValue = fastGetAttribute(contentAttr); | 468 const AtomicString& contentValue = fastGetAttribute(contentAttr); |
| 464 if (contentValue.isNull()) | 469 if (contentValue.isNull()) |
| 465 return; | 470 return; |
| 466 | 471 |
| 467 const AtomicString& nameValue = fastGetAttribute(nameAttr); | 472 const AtomicString& nameValue = fastGetAttribute(nameAttr); |
| 468 if (!nameValue.isEmpty()) { | 473 if (!nameValue.isEmpty()) { |
| 469 if (equalIgnoringCase(nameValue, "viewport")) | 474 if (equalIgnoringCase(nameValue, "viewport")) |
| 470 processViewportContentAttribute(contentValue, | 475 processViewportContentAttribute(contentValue, |
| 471 ViewportDescription::ViewportMeta); | 476 ViewportDescription::ViewportMeta); |
| 472 else if (equalIgnoringCase(nameValue, "referrer")) | 477 else if (equalIgnoringCase(nameValue, "referrer")) |
| 473 document().parseAndSetReferrerPolicy(contentValue, | 478 document().parseAndSetReferrerPolicy(contentValue, |
| 474 true /* support legacy keywords */); | 479 true /* support legacy keywords */); |
| 475 else if (equalIgnoringCase(nameValue, "handheldfriendly") && | 480 else if (equalIgnoringCase(nameValue, "handheldfriendly") && |
| 476 equalIgnoringCase(contentValue, "true")) | 481 equalIgnoringCase(contentValue, "true")) |
| 477 processViewportContentAttribute( | 482 processViewportContentAttribute( |
| 478 "width=device-width", ViewportDescription::HandheldFriendlyMeta); | 483 "width=device-width", ViewportDescription::HandheldFriendlyMeta); |
| 479 else if (equalIgnoringCase(nameValue, "mobileoptimized")) | 484 else if (equalIgnoringCase(nameValue, "mobileoptimized")) |
| 480 processViewportContentAttribute("width=device-width, initial-scale=1", | 485 processViewportContentAttribute("width=device-width, initial-scale=1", |
| 481 ViewportDescription::MobileOptimizedMeta); | 486 ViewportDescription::MobileOptimizedMeta); |
| 482 else if (equalIgnoringCase(nameValue, "theme-color") && document().frame()) | 487 else if (equalIgnoringCase(nameValue, "theme-color") && document().frame()) |
| 483 document().frame()->loader().client()->dispatchDidChangeThemeColor(); | 488 document().frame()->loader().client()->dispatchDidChangeThemeColor(); |
| 484 } | 489 } |
| 485 | 490 |
| 486 // Get the document to process the tag, but only if we're actually part of DOM | 491 // Get the document to process the tag, but only if we're actually part of DOM |
| 487 // tree (changing a meta tag while it's not in the tree shouldn't have any eff
ect | 492 // tree (changing a meta tag while it's not in the tree shouldn't have any |
| 488 // on the document). | 493 // effect on the document). |
| 489 | 494 |
| 490 const AtomicString& httpEquivValue = fastGetAttribute(http_equivAttr); | 495 const AtomicString& httpEquivValue = fastGetAttribute(http_equivAttr); |
| 491 if (httpEquivValue.isEmpty()) | 496 if (httpEquivValue.isEmpty()) |
| 492 return; | 497 return; |
| 493 | 498 |
| 494 HttpEquiv::process(document(), httpEquivValue, contentValue, | 499 HttpEquiv::process(document(), httpEquivValue, contentValue, |
| 495 inDocumentHead(this)); | 500 inDocumentHead(this)); |
| 496 } | 501 } |
| 497 | 502 |
| 498 WTF::TextEncoding HTMLMetaElement::computeEncoding() const { | 503 WTF::TextEncoding HTMLMetaElement::computeEncoding() const { |
| 499 HTMLAttributeList attributeList; | 504 HTMLAttributeList attributeList; |
| 500 for (const Attribute& attr : attributes()) | 505 for (const Attribute& attr : attributes()) |
| 501 attributeList.append( | 506 attributeList.append( |
| 502 std::make_pair(attr.name().localName(), attr.value().getString())); | 507 std::make_pair(attr.name().localName(), attr.value().getString())); |
| 503 return encodingFromMetaAttributes(attributeList); | 508 return encodingFromMetaAttributes(attributeList); |
| 504 } | 509 } |
| 505 | 510 |
| 506 const AtomicString& HTMLMetaElement::content() const { | 511 const AtomicString& HTMLMetaElement::content() const { |
| 507 return getAttribute(contentAttr); | 512 return getAttribute(contentAttr); |
| 508 } | 513 } |
| 509 | 514 |
| 510 const AtomicString& HTMLMetaElement::httpEquiv() const { | 515 const AtomicString& HTMLMetaElement::httpEquiv() const { |
| 511 return getAttribute(http_equivAttr); | 516 return getAttribute(http_equivAttr); |
| 512 } | 517 } |
| 513 | 518 |
| 514 const AtomicString& HTMLMetaElement::name() const { | 519 const AtomicString& HTMLMetaElement::name() const { |
| 515 return getNameAttribute(); | 520 return getNameAttribute(); |
| 516 } | 521 } |
| 517 } | 522 } |
| OLD | NEW |