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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 ImageCandidate candidate = findBestFitImageFromPictureParent(); | 388 ImageCandidate candidate = findBestFitImageFromPictureParent(); |
383 if (!candidate.isEmpty()) { | 389 if (!candidate.isEmpty()) { |
384 setBestFitURLAndDPRFromImageCandidate(candidate); | 390 setBestFitURLAndDPRFromImageCandidate(candidate); |
385 imageWasModified = true; | 391 imageWasModified = true; |
386 } | 392 } |
387 } | 393 } |
388 | 394 |
389 // If we have been inserted from a layoutObject-less document, | 395 // If we have been inserted from a layoutObject-less document, |
390 // our loader may have not fetched the image, so do it now. | 396 // our loader may have not fetched the image, so do it now. |
391 if ((insertionPoint->inDocument() && !imageLoader().image()) || imageWasModi
fied) | 397 if ((insertionPoint->inDocument() && !imageLoader().image()) || imageWasModi
fied) |
392 imageLoader().updateFromElement(ImageLoader::UpdateNormal); | 398 imageLoader().updateFromElement(ImageLoader::UpdateNormal, m_referrerPol
icy); |
393 | 399 |
394 return HTMLElement::insertedInto(insertionPoint); | 400 return HTMLElement::insertedInto(insertionPoint); |
395 } | 401 } |
396 | 402 |
397 void HTMLImageElement::removedFrom(ContainerNode* insertionPoint) | 403 void HTMLImageElement::removedFrom(ContainerNode* insertionPoint) |
398 { | 404 { |
399 if (!m_form || NodeTraversal::highestAncestorOrSelf(*m_form.get()) != NodeTr
aversal::highestAncestorOrSelf(*this)) | 405 if (!m_form || NodeTraversal::highestAncestorOrSelf(*m_form.get()) != NodeTr
aversal::highestAncestorOrSelf(*this)) |
400 resetFormOwner(); | 406 resetFormOwner(); |
401 if (m_listener) | 407 if (m_listener) |
402 document().mediaQueryMatcher().removeViewportListener(m_listener); | 408 document().mediaQueryMatcher().removeViewportListener(m_listener); |
(...skipping 250 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 |