| 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 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserv
ed. | 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserv
ed. |
| 5 * Copyright (C) 2010 Google Inc. All rights reserved. | 5 * Copyright (C) 2010 Google 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 #include "core/html/parser/HTMLSrcsetParser.h" | 44 #include "core/html/parser/HTMLSrcsetParser.h" |
| 45 #include "core/inspector/ConsoleMessage.h" | 45 #include "core/inspector/ConsoleMessage.h" |
| 46 #include "core/layout/LayoutBlockFlow.h" | 46 #include "core/layout/LayoutBlockFlow.h" |
| 47 #include "core/layout/LayoutImage.h" | 47 #include "core/layout/LayoutImage.h" |
| 48 #include "core/page/Page.h" | 48 #include "core/page/Page.h" |
| 49 #include "core/style/ContentData.h" | 49 #include "core/style/ContentData.h" |
| 50 #include "platform/ContentType.h" | 50 #include "platform/ContentType.h" |
| 51 #include "platform/EventDispatchForbiddenScope.h" | 51 #include "platform/EventDispatchForbiddenScope.h" |
| 52 #include "platform/MIMETypeRegistry.h" | 52 #include "platform/MIMETypeRegistry.h" |
| 53 #include "platform/RuntimeEnabledFeatures.h" | 53 #include "platform/RuntimeEnabledFeatures.h" |
| 54 #include "platform/weborigin/SecurityPolicy.h" |
| 54 | 55 |
| 55 namespace blink { | 56 namespace blink { |
| 56 | 57 |
| 57 using namespace HTMLNames; | 58 using namespace HTMLNames; |
| 58 | 59 |
| 59 class HTMLImageElement::ViewportChangeListener final : public MediaQueryListList
ener { | 60 class HTMLImageElement::ViewportChangeListener final : public MediaQueryListList
ener { |
| 60 public: | 61 public: |
| 61 static RefPtrWillBeRawPtr<ViewportChangeListener> create(HTMLImageElement* e
lement) | 62 static RefPtrWillBeRawPtr<ViewportChangeListener> create(HTMLImageElement* e
lement) |
| 62 { | 63 { |
| 63 return adoptRefWillBeNoop(new ViewportChangeListener(element)); | 64 return adoptRefWillBeNoop(new ViewportChangeListener(element)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 84 | 85 |
| 85 HTMLImageElement::HTMLImageElement(Document& document, HTMLFormElement* form, bo
ol createdByParser) | 86 HTMLImageElement::HTMLImageElement(Document& document, HTMLFormElement* form, bo
ol createdByParser) |
| 86 : HTMLElement(imgTag, document) | 87 : HTMLElement(imgTag, document) |
| 87 , m_imageLoader(HTMLImageLoader::create(this)) | 88 , m_imageLoader(HTMLImageLoader::create(this)) |
| 88 , m_imageDevicePixelRatio(1.0f) | 89 , m_imageDevicePixelRatio(1.0f) |
| 89 , m_formWasSetByParser(false) | 90 , m_formWasSetByParser(false) |
| 90 , m_elementCreatedByParser(createdByParser) | 91 , m_elementCreatedByParser(createdByParser) |
| 91 , m_intrinsicSizingViewportDependant(false) | 92 , m_intrinsicSizingViewportDependant(false) |
| 92 , m_useFallbackContent(false) | 93 , m_useFallbackContent(false) |
| 93 , m_isFallbackImage(false) | 94 , m_isFallbackImage(false) |
| 95 , m_referrerPolicy(ReferrerPolicyDefault) |
| 94 { | 96 { |
| 95 setHasCustomStyleCallbacks(); | 97 setHasCustomStyleCallbacks(); |
| 96 if (form && form->inDocument()) { | 98 if (form && form->inDocument()) { |
| 97 #if ENABLE(OILPAN) | 99 #if ENABLE(OILPAN) |
| 98 m_form = form; | 100 m_form = form; |
| 99 #else | 101 #else |
| 100 m_form = form->createWeakPtr(); | 102 m_form = form->createWeakPtr(); |
| 101 #endif | 103 #endif |
| 102 m_formWasSetByParser = true; | 104 m_formWasSetByParser = true; |
| 103 m_form->associate(*this); | 105 m_form->associate(*this); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 if (userAgentShadowRoot()) { | 263 if (userAgentShadowRoot()) { |
| 262 Element* text = userAgentShadowRoot()->getElementById("alttext"); | 264 Element* text = userAgentShadowRoot()->getElementById("alttext"); |
| 263 String value = altText(); | 265 String value = altText(); |
| 264 if (text && text->textContent() != value) | 266 if (text && text->textContent() != value) |
| 265 text->setTextContent(altText()); | 267 text->setTextContent(altText()); |
| 266 } | 268 } |
| 267 } else if (name == srcAttr || name == srcsetAttr || name == sizesAttr) { | 269 } else if (name == srcAttr || name == srcsetAttr || name == sizesAttr) { |
| 268 selectSourceURL(ImageLoader::UpdateIgnorePreviousError); | 270 selectSourceURL(ImageLoader::UpdateIgnorePreviousError); |
| 269 } else if (name == usemapAttr) { | 271 } else if (name == usemapAttr) { |
| 270 setIsLink(!value.isNull()); | 272 setIsLink(!value.isNull()); |
| 273 } else if (name == referrerpolicyAttr) { |
| 274 m_referrerPolicy = ReferrerPolicyDefault; |
| 275 if (!value.isNull()) |
| 276 SecurityPolicy::referrerPolicyFromString(value, &m_referrerPolicy); |
| 271 } else { | 277 } else { |
| 272 HTMLElement::parseAttribute(name, value); | 278 HTMLElement::parseAttribute(name, value); |
| 273 } | 279 } |
| 274 } | 280 } |
| 275 | 281 |
| 276 String HTMLImageElement::altText() const | 282 String HTMLImageElement::altText() const |
| 277 { | 283 { |
| 278 // lets figure out the alt text.. magic stuff | 284 // lets figure out the alt text.. magic stuff |
| 279 // http://www.w3.org/TR/1998/REC-html40-19980424/appendix/notes.html#altgen | 285 // http://www.w3.org/TR/1998/REC-html40-19980424/appendix/notes.html#altgen |
| 280 // also heavily discussed by Hixie on bugzilla | 286 // also heavily discussed by Hixie on bugzilla |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 ImageCandidate candidate = findBestFitImageFromPictureParent(); | 384 ImageCandidate candidate = findBestFitImageFromPictureParent(); |
| 379 if (!candidate.isEmpty()) { | 385 if (!candidate.isEmpty()) { |
| 380 setBestFitURLAndDPRFromImageCandidate(candidate); | 386 setBestFitURLAndDPRFromImageCandidate(candidate); |
| 381 imageWasModified = true; | 387 imageWasModified = true; |
| 382 } | 388 } |
| 383 } | 389 } |
| 384 | 390 |
| 385 // If we have been inserted from a layoutObject-less document, | 391 // If we have been inserted from a layoutObject-less document, |
| 386 // our loader may have not fetched the image, so do it now. | 392 // our loader may have not fetched the image, so do it now. |
| 387 if ((insertionPoint->inDocument() && !imageLoader().image()) || imageWasModi
fied) | 393 if ((insertionPoint->inDocument() && !imageLoader().image()) || imageWasModi
fied) |
| 388 imageLoader().updateFromElement(ImageLoader::UpdateNormal); | 394 imageLoader().updateFromElement(ImageLoader::UpdateNormal, m_referrerPol
icy); |
| 389 | 395 |
| 390 return HTMLElement::insertedInto(insertionPoint); | 396 return HTMLElement::insertedInto(insertionPoint); |
| 391 } | 397 } |
| 392 | 398 |
| 393 void HTMLImageElement::removedFrom(ContainerNode* insertionPoint) | 399 void HTMLImageElement::removedFrom(ContainerNode* insertionPoint) |
| 394 { | 400 { |
| 395 if (!m_form || NodeTraversal::highestAncestorOrSelf(*m_form.get()) != NodeTr
aversal::highestAncestorOrSelf(*this)) | 401 if (!m_form || NodeTraversal::highestAncestorOrSelf(*m_form.get()) != NodeTr
aversal::highestAncestorOrSelf(*this)) |
| 396 resetFormOwner(); | 402 resetFormOwner(); |
| 397 if (m_listener) | 403 if (m_listener) |
| 398 document().mediaQueryMatcher().removeViewportListener(m_listener); | 404 document().mediaQueryMatcher().removeViewportListener(m_listener); |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 { | 659 { |
| 654 float value; | 660 float value; |
| 655 // We don't care here if the sizes attribute exists, so we ignore the return
value. | 661 // We don't care here if the sizes attribute exists, so we ignore the return
value. |
| 656 // If it doesn't exist, we just return the default. | 662 // If it doesn't exist, we just return the default. |
| 657 sourceSizeValue(element, document(), value); | 663 sourceSizeValue(element, document(), value); |
| 658 return value; | 664 return value; |
| 659 } | 665 } |
| 660 | 666 |
| 661 void HTMLImageElement::forceReload() const | 667 void HTMLImageElement::forceReload() const |
| 662 { | 668 { |
| 663 imageLoader().updateFromElement(ImageLoader::UpdateForcedReload); | 669 imageLoader().updateFromElement(ImageLoader::UpdateForcedReload, m_referrerP
olicy); |
| 664 } | 670 } |
| 665 | 671 |
| 666 void HTMLImageElement::selectSourceURL(ImageLoader::UpdateFromElementBehavior be
havior) | 672 void HTMLImageElement::selectSourceURL(ImageLoader::UpdateFromElementBehavior be
havior) |
| 667 { | 673 { |
| 668 if (!document().isActive()) | 674 if (!document().isActive()) |
| 669 return; | 675 return; |
| 670 | 676 |
| 671 bool foundURL = false; | 677 bool foundURL = false; |
| 672 ImageCandidate candidate = findBestFitImageFromPictureParent(); | 678 ImageCandidate candidate = findBestFitImageFromPictureParent(); |
| 673 if (!candidate.isEmpty()) { | 679 if (!candidate.isEmpty()) { |
| 674 setBestFitURLAndDPRFromImageCandidate(candidate); | 680 setBestFitURLAndDPRFromImageCandidate(candidate); |
| 675 foundURL = true; | 681 foundURL = true; |
| 676 } | 682 } |
| 677 | 683 |
| 678 if (!foundURL) { | 684 if (!foundURL) { |
| 679 candidate = bestFitSourceForImageAttributes(document().devicePixelRatio(
), sourceSize(*this), fastGetAttribute(srcAttr), fastGetAttribute(srcsetAttr), &
document()); | 685 candidate = bestFitSourceForImageAttributes(document().devicePixelRatio(
), sourceSize(*this), fastGetAttribute(srcAttr), fastGetAttribute(srcsetAttr), &
document()); |
| 680 setBestFitURLAndDPRFromImageCandidate(candidate); | 686 setBestFitURLAndDPRFromImageCandidate(candidate); |
| 681 } | 687 } |
| 682 if (m_intrinsicSizingViewportDependant && !m_listener) { | 688 if (m_intrinsicSizingViewportDependant && !m_listener) { |
| 683 m_listener = ViewportChangeListener::create(this); | 689 m_listener = ViewportChangeListener::create(this); |
| 684 document().mediaQueryMatcher().addViewportListener(m_listener); | 690 document().mediaQueryMatcher().addViewportListener(m_listener); |
| 685 } | 691 } |
| 686 imageLoader().updateFromElement(behavior); | 692 imageLoader().updateFromElement(behavior, m_referrerPolicy); |
| 687 | 693 |
| 688 if (imageLoader().image() || (imageLoader().hasPendingActivity() && !imageSo
urceURL().isEmpty())) | 694 if (imageLoader().image() || (imageLoader().hasPendingActivity() && !imageSo
urceURL().isEmpty())) |
| 689 ensurePrimaryContent(); | 695 ensurePrimaryContent(); |
| 690 else | 696 else |
| 691 ensureFallbackContent(); | 697 ensureFallbackContent(); |
| 692 } | 698 } |
| 693 | 699 |
| 694 const KURL& HTMLImageElement::sourceURL() const | 700 const KURL& HTMLImageElement::sourceURL() const |
| 695 { | 701 { |
| 696 return cachedImage()->response().url(); | 702 return cachedImage()->response().url(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 ensureUserAgentShadowRoot(); | 759 ensureUserAgentShadowRoot(); |
| 754 } | 760 } |
| 755 | 761 |
| 756 bool HTMLImageElement::isOpaque() const | 762 bool HTMLImageElement::isOpaque() const |
| 757 { | 763 { |
| 758 Image* image = const_cast<HTMLImageElement*>(this)->imageContents(); | 764 Image* image = const_cast<HTMLImageElement*>(this)->imageContents(); |
| 759 return image && image->currentFrameKnownToBeOpaque(); | 765 return image && image->currentFrameKnownToBeOpaque(); |
| 760 } | 766 } |
| 761 | 767 |
| 762 } | 768 } |
| OLD | NEW |