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 ReferrerPolicy parsedPolicy; | |
275 if (value.isNull() || !SecurityPolicy::referrerPolicyFromString(value, & parsedPolicy)) { | |
276 m_referrerPolicy = ReferrerPolicyDefault; | |
277 } else { | |
278 m_referrerPolicy = parsedPolicy; | |
279 } | |
Yoav Weiss
2015/08/18 21:09:21
We could replace the if{}else{} here similarly to
estark
2015/08/19 02:53:22
Done.
| |
271 } else { | 280 } else { |
272 HTMLElement::parseAttribute(name, value); | 281 HTMLElement::parseAttribute(name, value); |
273 } | 282 } |
274 } | 283 } |
275 | 284 |
276 String HTMLImageElement::altText() const | 285 String HTMLImageElement::altText() const |
277 { | 286 { |
278 // lets figure out the alt text.. magic stuff | 287 // lets figure out the alt text.. magic stuff |
279 // http://www.w3.org/TR/1998/REC-html40-19980424/appendix/notes.html#altgen | 288 // http://www.w3.org/TR/1998/REC-html40-19980424/appendix/notes.html#altgen |
280 // also heavily discussed by Hixie on bugzilla | 289 // also heavily discussed by Hixie on bugzilla |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
378 ImageCandidate candidate = findBestFitImageFromPictureParent(); | 387 ImageCandidate candidate = findBestFitImageFromPictureParent(); |
379 if (!candidate.isEmpty()) { | 388 if (!candidate.isEmpty()) { |
380 setBestFitURLAndDPRFromImageCandidate(candidate); | 389 setBestFitURLAndDPRFromImageCandidate(candidate); |
381 imageWasModified = true; | 390 imageWasModified = true; |
382 } | 391 } |
383 } | 392 } |
384 | 393 |
385 // If we have been inserted from a layoutObject-less document, | 394 // If we have been inserted from a layoutObject-less document, |
386 // our loader may have not fetched the image, so do it now. | 395 // our loader may have not fetched the image, so do it now. |
387 if ((insertionPoint->inDocument() && !imageLoader().image()) || imageWasModi fied) | 396 if ((insertionPoint->inDocument() && !imageLoader().image()) || imageWasModi fied) |
388 imageLoader().updateFromElement(ImageLoader::UpdateNormal); | 397 imageLoader().updateFromElement(ImageLoader::UpdateNormal, m_referrerPol icy); |
389 | 398 |
390 return HTMLElement::insertedInto(insertionPoint); | 399 return HTMLElement::insertedInto(insertionPoint); |
391 } | 400 } |
392 | 401 |
393 void HTMLImageElement::removedFrom(ContainerNode* insertionPoint) | 402 void HTMLImageElement::removedFrom(ContainerNode* insertionPoint) |
394 { | 403 { |
395 if (!m_form || NodeTraversal::highestAncestorOrSelf(*m_form.get()) != NodeTr aversal::highestAncestorOrSelf(*this)) | 404 if (!m_form || NodeTraversal::highestAncestorOrSelf(*m_form.get()) != NodeTr aversal::highestAncestorOrSelf(*this)) |
396 resetFormOwner(); | 405 resetFormOwner(); |
397 if (m_listener) | 406 if (m_listener) |
398 document().mediaQueryMatcher().removeViewportListener(m_listener); | 407 document().mediaQueryMatcher().removeViewportListener(m_listener); |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
653 { | 662 { |
654 float value; | 663 float value; |
655 // We don't care here if the sizes attribute exists, so we ignore the return value. | 664 // 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. | 665 // If it doesn't exist, we just return the default. |
657 sourceSizeValue(element, document(), value); | 666 sourceSizeValue(element, document(), value); |
658 return value; | 667 return value; |
659 } | 668 } |
660 | 669 |
661 void HTMLImageElement::forceReload() const | 670 void HTMLImageElement::forceReload() const |
662 { | 671 { |
663 imageLoader().updateFromElement(ImageLoader::UpdateForcedReload); | 672 imageLoader().updateFromElement(ImageLoader::UpdateForcedReload, m_referrerP olicy); |
664 } | 673 } |
665 | 674 |
666 void HTMLImageElement::selectSourceURL(ImageLoader::UpdateFromElementBehavior be havior) | 675 void HTMLImageElement::selectSourceURL(ImageLoader::UpdateFromElementBehavior be havior) |
667 { | 676 { |
668 if (!document().isActive()) | 677 if (!document().isActive()) |
669 return; | 678 return; |
670 | 679 |
671 bool foundURL = false; | 680 bool foundURL = false; |
672 ImageCandidate candidate = findBestFitImageFromPictureParent(); | 681 ImageCandidate candidate = findBestFitImageFromPictureParent(); |
673 if (!candidate.isEmpty()) { | 682 if (!candidate.isEmpty()) { |
674 setBestFitURLAndDPRFromImageCandidate(candidate); | 683 setBestFitURLAndDPRFromImageCandidate(candidate); |
675 foundURL = true; | 684 foundURL = true; |
676 } | 685 } |
677 | 686 |
678 if (!foundURL) { | 687 if (!foundURL) { |
679 candidate = bestFitSourceForImageAttributes(document().devicePixelRatio( ), sourceSize(*this), fastGetAttribute(srcAttr), fastGetAttribute(srcsetAttr), & document()); | 688 candidate = bestFitSourceForImageAttributes(document().devicePixelRatio( ), sourceSize(*this), fastGetAttribute(srcAttr), fastGetAttribute(srcsetAttr), & document()); |
680 setBestFitURLAndDPRFromImageCandidate(candidate); | 689 setBestFitURLAndDPRFromImageCandidate(candidate); |
681 } | 690 } |
682 if (m_intrinsicSizingViewportDependant && !m_listener) { | 691 if (m_intrinsicSizingViewportDependant && !m_listener) { |
683 m_listener = ViewportChangeListener::create(this); | 692 m_listener = ViewportChangeListener::create(this); |
684 document().mediaQueryMatcher().addViewportListener(m_listener); | 693 document().mediaQueryMatcher().addViewportListener(m_listener); |
685 } | 694 } |
686 imageLoader().updateFromElement(behavior); | 695 imageLoader().updateFromElement(behavior, m_referrerPolicy); |
687 | 696 |
688 if (imageLoader().image() || (imageLoader().hasPendingActivity() && !imageSo urceURL().isEmpty())) | 697 if (imageLoader().image() || (imageLoader().hasPendingActivity() && !imageSo urceURL().isEmpty())) |
689 ensurePrimaryContent(); | 698 ensurePrimaryContent(); |
690 else | 699 else |
691 ensureFallbackContent(); | 700 ensureFallbackContent(); |
692 } | 701 } |
693 | 702 |
694 const KURL& HTMLImageElement::sourceURL() const | 703 const KURL& HTMLImageElement::sourceURL() const |
695 { | 704 { |
696 return cachedImage()->response().url(); | 705 return cachedImage()->response().url(); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
753 ensureUserAgentShadowRoot(); | 762 ensureUserAgentShadowRoot(); |
754 } | 763 } |
755 | 764 |
756 bool HTMLImageElement::isOpaque() const | 765 bool HTMLImageElement::isOpaque() const |
757 { | 766 { |
758 Image* image = const_cast<HTMLImageElement*>(this)->imageContents(); | 767 Image* image = const_cast<HTMLImageElement*>(this)->imageContents(); |
759 return image && image->currentFrameKnownToBeOpaque(); | 768 return image && image->currentFrameKnownToBeOpaque(); |
760 } | 769 } |
761 | 770 |
762 } | 771 } |
OLD | NEW |