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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/html/HTMLImageElement.cpp
diff --git a/third_party/WebKit/Source/core/html/HTMLImageElement.cpp b/third_party/WebKit/Source/core/html/HTMLImageElement.cpp
index 01fc2ac62b9849ede2e4d98b0d73447fdedc8672..c61e179f1d3adf9b9eaab4ecbc4dd1e48ce3f33f 100644
--- a/third_party/WebKit/Source/core/html/HTMLImageElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLImageElement.cpp
@@ -93,9 +93,9 @@ HTMLImageElement::HTMLImageElement(Document& document,
m_imageLoader(HTMLImageLoader::create(this)),
m_imageDevicePixelRatio(1.0f),
m_source(nullptr),
+ m_contentType(ContentType::Primary),
m_formWasSetByParser(false),
m_elementCreatedByParser(createdByParser),
- m_useFallbackContent(false),
m_isFallbackImage(false),
m_referrerPolicy(ReferrerPolicyDefault) {
setHasCustomStyleCallbacks();
@@ -339,6 +339,11 @@ ImageCandidate HTMLImageElement::findBestFitImageFromPictureParent() {
return ImageCandidate();
}
+bool HTMLImageElement::layoutObjectIsNeeded(const ComputedStyle& style) {
+ return m_contentType != ContentType::Collapsed &&
+ HTMLElement::layoutObjectIsNeeded(style);
+}
+
LayoutObject* HTMLImageElement::createLayoutObject(const ComputedStyle& style) {
const ContentData* contentData = style.contentData();
if (contentData && contentData->isImage()) {
@@ -349,9 +354,10 @@ LayoutObject* HTMLImageElement::createLayoutObject(const ComputedStyle& style) {
return LayoutObject::createObject(this, style);
}
- if (m_useFallbackContent)
+ if (m_contentType == ContentType::Fallback)
return new LayoutBlockFlow(this);
+ DCHECK_EQ(m_contentType, ContentType::Primary);
LayoutImage* image = new LayoutImage(this);
image->setImageResource(LayoutImageResource::create());
image->setImageDevicePixelRatio(m_imageDevicePixelRatio);
@@ -801,7 +807,7 @@ void HTMLImageElement::selectSourceURL(
if ((imageHasLoaded && imageHasImage) || imageStillLoading || imageIsDocument)
ensurePrimaryContent();
else
- ensureFallbackContent();
+ ensureCollapsedOrFallbackContent();
}
const KURL& HTMLImageElement::sourceURL() const {
@@ -814,24 +820,30 @@ void HTMLImageElement::didAddUserAgentShadowRoot(ShadowRoot&) {
void HTMLImageElement::ensureFallbackForGeneratedContent() {
setUseFallbackContent();
- reattachFallbackContent();
+ reattachContent();
}
-void HTMLImageElement::ensureFallbackContent() {
- if (m_useFallbackContent || m_isFallbackImage)
- return;
- setUseFallbackContent();
- reattachFallbackContent();
+void HTMLImageElement::ensureCollapsedOrFallbackContent() {
+ if (imageLoader().image() &&
+ imageLoader().image()->resourceError().shouldCollapseInitiator()) {
+ if (m_contentType != ContentType::Collapsed) {
+ m_contentType = ContentType::Collapsed;
+ reattachContent();
+ }
+ } else if (m_contentType != ContentType::Fallback) {
+ setUseFallbackContent();
+ reattachContent();
+ }
}
void HTMLImageElement::ensurePrimaryContent() {
- if (!m_useFallbackContent)
+ if (m_contentType == ContentType::Primary)
return;
- m_useFallbackContent = false;
- reattachFallbackContent();
+ m_contentType = ContentType::Primary;
+ reattachContent();
}
-void HTMLImageElement::reattachFallbackContent() {
+void HTMLImageElement::reattachContent() {
// This can happen inside of attachLayoutTree() in the middle of a recalcStyle
// so we need to reattach synchronously here.
if (document().inStyleRecalc())
@@ -841,17 +853,15 @@ void HTMLImageElement::reattachFallbackContent() {
}
PassRefPtr<ComputedStyle> HTMLImageElement::customStyleForLayoutObject() {
- RefPtr<ComputedStyle> newStyle = originalStyleForLayoutObject();
-
- if (!m_useFallbackContent)
- return newStyle;
-
- RefPtr<ComputedStyle> style = ComputedStyle::clone(*newStyle);
- return HTMLImageFallbackHelper::customStyleForAltText(*this, style);
+ if (m_contentType == ContentType::Primary ||
+ 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.
+ return originalStyleForLayoutObject();
+ return HTMLImageFallbackHelper::customStyleForAltText(
+ *this, ComputedStyle::clone(*originalStyleForLayoutObject()));
}
void HTMLImageElement::setUseFallbackContent() {
- m_useFallbackContent = true;
+ m_contentType = ContentType::Fallback;
if (document().inStyleRecalc())
return;
EventDispatchForbiddenScope::AllowUserAgentEvents allowEvents;

Powered by Google App Engine
This is Rietveld 408576698