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

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLImageElement.cpp

Issue 2535383003: Collapse images disallowed by the Safe Browsing Subresource Filter. (Closed)
Patch Set: Initial draft. Created 4 years 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
OLDNEW
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 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights
5 * reserved. 5 * reserved.
6 * Copyright (C) 2010 Google Inc. All rights reserved. 6 * Copyright (C) 2010 Google Inc. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 }; 86 };
87 87
88 HTMLImageElement::HTMLImageElement(Document& document, 88 HTMLImageElement::HTMLImageElement(Document& document,
89 HTMLFormElement* form, 89 HTMLFormElement* form,
90 bool createdByParser) 90 bool createdByParser)
91 : HTMLElement(imgTag, document), 91 : HTMLElement(imgTag, document),
92 ActiveScriptWrappable(this), 92 ActiveScriptWrappable(this),
93 m_imageLoader(HTMLImageLoader::create(this)), 93 m_imageLoader(HTMLImageLoader::create(this)),
94 m_imageDevicePixelRatio(1.0f), 94 m_imageDevicePixelRatio(1.0f),
95 m_source(nullptr), 95 m_source(nullptr),
96 m_contentType(ContentType::Primary),
96 m_formWasSetByParser(false), 97 m_formWasSetByParser(false),
97 m_elementCreatedByParser(createdByParser), 98 m_elementCreatedByParser(createdByParser),
98 m_useFallbackContent(false),
99 m_isFallbackImage(false), 99 m_isFallbackImage(false),
100 m_referrerPolicy(ReferrerPolicyDefault) { 100 m_referrerPolicy(ReferrerPolicyDefault) {
101 setHasCustomStyleCallbacks(); 101 setHasCustomStyleCallbacks();
102 if (form && form->isConnected()) { 102 if (form && form->isConnected()) {
103 m_form = form; 103 m_form = form;
104 m_formWasSetByParser = true; 104 m_formWasSetByParser = true;
105 m_form->associate(*this); 105 m_form->associate(*this);
106 m_form->didAssociateByParser(); 106 m_form->didAssociateByParser();
107 } 107 }
108 } 108 }
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 document().devicePixelRatio(), sourceSize(*source), 332 document().devicePixelRatio(), sourceSize(*source),
333 source->fastGetAttribute(srcsetAttr), &document()); 333 source->fastGetAttribute(srcsetAttr), &document());
334 if (candidate.isEmpty()) 334 if (candidate.isEmpty())
335 continue; 335 continue;
336 m_source = source; 336 m_source = source;
337 return candidate; 337 return candidate;
338 } 338 }
339 return ImageCandidate(); 339 return ImageCandidate();
340 } 340 }
341 341
342 bool HTMLImageElement::layoutObjectIsNeeded(const ComputedStyle& style) {
343 return m_contentType != ContentType::Collapsed &&
344 HTMLElement::layoutObjectIsNeeded(style);
345 }
346
342 LayoutObject* HTMLImageElement::createLayoutObject(const ComputedStyle& style) { 347 LayoutObject* HTMLImageElement::createLayoutObject(const ComputedStyle& style) {
343 const ContentData* contentData = style.contentData(); 348 const ContentData* contentData = style.contentData();
344 if (contentData && contentData->isImage()) { 349 if (contentData && contentData->isImage()) {
345 const StyleImage* contentImage = toImageContentData(contentData)->image(); 350 const StyleImage* contentImage = toImageContentData(contentData)->image();
346 bool errorOccurred = contentImage && contentImage->cachedImage() && 351 bool errorOccurred = contentImage && contentImage->cachedImage() &&
347 contentImage->cachedImage()->errorOccurred(); 352 contentImage->cachedImage()->errorOccurred();
348 if (!errorOccurred) 353 if (!errorOccurred)
349 return LayoutObject::createObject(this, style); 354 return LayoutObject::createObject(this, style);
350 } 355 }
351 356
352 if (m_useFallbackContent) 357 if (m_contentType == ContentType::Fallback)
353 return new LayoutBlockFlow(this); 358 return new LayoutBlockFlow(this);
354 359
360 DCHECK_EQ(m_contentType, ContentType::Primary);
355 LayoutImage* image = new LayoutImage(this); 361 LayoutImage* image = new LayoutImage(this);
356 image->setImageResource(LayoutImageResource::create()); 362 image->setImageResource(LayoutImageResource::create());
357 image->setImageDevicePixelRatio(m_imageDevicePixelRatio); 363 image->setImageDevicePixelRatio(m_imageDevicePixelRatio);
358 return image; 364 return image;
359 } 365 }
360 366
361 void HTMLImageElement::attachLayoutTree(const AttachContext& context) { 367 void HTMLImageElement::attachLayoutTree(const AttachContext& context) {
362 HTMLElement::attachLayoutTree(context); 368 HTMLElement::attachLayoutTree(context);
363 369
364 if (layoutObject() && layoutObject()->isImage()) { 370 if (layoutObject() && layoutObject()->isImage()) {
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 // sufficient, because a deferred image does have pending activity, does not 800 // sufficient, because a deferred image does have pending activity, does not
795 // have a pending error, and does have a source URL, so if imageHasLoaded 801 // have a pending error, and does have a source URL, so if imageHasLoaded
796 // was correct, imageStillLoading would become wrong. 802 // was correct, imageStillLoading would become wrong.
797 // 803 //
798 // Instead of dealing with that, there's a separate check that the 804 // Instead of dealing with that, there's a separate check that the
799 // ImageResource has non-null image data associated with it, which isn't 805 // ImageResource has non-null image data associated with it, which isn't
800 // folded into imageHasLoaded above. 806 // folded into imageHasLoaded above.
801 if ((imageHasLoaded && imageHasImage) || imageStillLoading || imageIsDocument) 807 if ((imageHasLoaded && imageHasImage) || imageStillLoading || imageIsDocument)
802 ensurePrimaryContent(); 808 ensurePrimaryContent();
803 else 809 else
804 ensureFallbackContent(); 810 ensureCollapsedOrFallbackContent();
805 } 811 }
806 812
807 const KURL& HTMLImageElement::sourceURL() const { 813 const KURL& HTMLImageElement::sourceURL() const {
808 return cachedImage()->response().url(); 814 return cachedImage()->response().url();
809 } 815 }
810 816
811 void HTMLImageElement::didAddUserAgentShadowRoot(ShadowRoot&) { 817 void HTMLImageElement::didAddUserAgentShadowRoot(ShadowRoot&) {
812 HTMLImageFallbackHelper::createAltTextShadowTree(*this); 818 HTMLImageFallbackHelper::createAltTextShadowTree(*this);
813 } 819 }
814 820
815 void HTMLImageElement::ensureFallbackForGeneratedContent() { 821 void HTMLImageElement::ensureFallbackForGeneratedContent() {
816 setUseFallbackContent(); 822 setUseFallbackContent();
817 reattachFallbackContent(); 823 reattachContent();
818 } 824 }
819 825
820 void HTMLImageElement::ensureFallbackContent() { 826 void HTMLImageElement::ensureCollapsedOrFallbackContent() {
821 if (m_useFallbackContent || m_isFallbackImage) 827 if (imageLoader().image() &&
822 return; 828 imageLoader().image()->resourceError().shouldCollapseInitiator()) {
823 setUseFallbackContent(); 829 if (m_contentType != ContentType::Collapsed) {
824 reattachFallbackContent(); 830 m_contentType = ContentType::Collapsed;
831 reattachContent();
832 }
833 } else if (m_contentType != ContentType::Fallback) {
834 setUseFallbackContent();
835 reattachContent();
836 }
825 } 837 }
826 838
827 void HTMLImageElement::ensurePrimaryContent() { 839 void HTMLImageElement::ensurePrimaryContent() {
828 if (!m_useFallbackContent) 840 if (m_contentType == ContentType::Primary)
829 return; 841 return;
830 m_useFallbackContent = false; 842 m_contentType = ContentType::Primary;
831 reattachFallbackContent(); 843 reattachContent();
832 } 844 }
833 845
834 void HTMLImageElement::reattachFallbackContent() { 846 void HTMLImageElement::reattachContent() {
835 // This can happen inside of attachLayoutTree() in the middle of a recalcStyle 847 // This can happen inside of attachLayoutTree() in the middle of a recalcStyle
836 // so we need to reattach synchronously here. 848 // so we need to reattach synchronously here.
837 if (document().inStyleRecalc()) 849 if (document().inStyleRecalc())
838 reattachLayoutTree(); 850 reattachLayoutTree();
839 else 851 else
840 lazyReattachIfAttached(); 852 lazyReattachIfAttached();
841 } 853 }
842 854
843 PassRefPtr<ComputedStyle> HTMLImageElement::customStyleForLayoutObject() { 855 PassRefPtr<ComputedStyle> HTMLImageElement::customStyleForLayoutObject() {
844 RefPtr<ComputedStyle> newStyle = originalStyleForLayoutObject(); 856 if (m_contentType == ContentType::Primary ||
845 857 m_contentType == ContentType::Collapsed)
Mike West 2016/11/30 15:57:35 Nit: {} for multi-line conditionals.
engedy 2016/11/30 17:37:39 Done.
846 if (!m_useFallbackContent) 858 return originalStyleForLayoutObject();
847 return newStyle; 859 return HTMLImageFallbackHelper::customStyleForAltText(
848 860 *this, ComputedStyle::clone(*originalStyleForLayoutObject()));
849 RefPtr<ComputedStyle> style = ComputedStyle::clone(*newStyle);
850 return HTMLImageFallbackHelper::customStyleForAltText(*this, style);
851 } 861 }
852 862
853 void HTMLImageElement::setUseFallbackContent() { 863 void HTMLImageElement::setUseFallbackContent() {
854 m_useFallbackContent = true; 864 m_contentType = ContentType::Fallback;
855 if (document().inStyleRecalc()) 865 if (document().inStyleRecalc())
856 return; 866 return;
857 EventDispatchForbiddenScope::AllowUserAgentEvents allowEvents; 867 EventDispatchForbiddenScope::AllowUserAgentEvents allowEvents;
858 ensureUserAgentShadowRoot(); 868 ensureUserAgentShadowRoot();
859 } 869 }
860 870
861 bool HTMLImageElement::isOpaque() const { 871 bool HTMLImageElement::isOpaque() const {
862 Image* image = const_cast<HTMLImageElement*>(this)->imageContents(); 872 Image* image = const_cast<HTMLImageElement*>(this)->imageContents();
863 return image && image->currentFrameKnownToBeOpaque(); 873 return image && image->currentFrameKnownToBeOpaque();
864 } 874 }
(...skipping 20 matching lines...) Expand all
885 ImageResource* image = cachedImage(); 895 ImageResource* image = cachedImage();
886 if (!image) 896 if (!image)
887 return IntSize(); 897 return IntSize();
888 LayoutSize lSize = image->imageSize( 898 LayoutSize lSize = image->imageSize(
889 LayoutObject::shouldRespectImageOrientation(layoutObject()), 1.0f); 899 LayoutObject::shouldRespectImageOrientation(layoutObject()), 1.0f);
890 DCHECK(lSize.fraction().isZero()); 900 DCHECK(lSize.fraction().isZero());
891 return IntSize(lSize.width().toInt(), lSize.height().toInt()); 901 return IntSize(lSize.width().toInt(), lSize.height().toInt());
892 } 902 }
893 903
894 } // namespace blink 904 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698