Commit dd8d1cce authored by Robert Flack's avatar Robert Flack Committed by Commit Bot

Declare that LayoutEmbeddedContent always wraps an HTMLFrameOwnerElement

LayoutEmbeddedContent is constructed for HTMLPluginElement,
HTMLFrameElement, HTMLPortalElement and HTMLIFrameElement. All of these
are of type HTMLFrameOwnerElement so the dynamic casts and type checks
are unnecessary. Unfortunately, since the LayoutEmbeddedContent object
can outlive the HTMLFrameOwnerElement, null checks are still necessary.

Bug: None
Change-Id: I33d3fc5654d73f92f10d302429dc3713592455a8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1866016Reviewed-by: default avatarMorten Stenshorne <mstensho@chromium.org>
Reviewed-by: default avatarYi Gu <yigu@chromium.org>
Commit-Queue: Robert Flack <flackr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706988}
parent 29fdb63f
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
namespace blink { namespace blink {
LayoutEmbeddedContent::LayoutEmbeddedContent(Element* element) LayoutEmbeddedContent::LayoutEmbeddedContent(HTMLFrameOwnerElement* element)
: LayoutReplaced(element), : LayoutReplaced(element),
// Reference counting is used to prevent the part from being destroyed // Reference counting is used to prevent the part from being destroyed
// while inside the EmbeddedContentView code, which might not be able to // while inside the EmbeddedContentView code, which might not be able to
...@@ -62,7 +62,7 @@ void LayoutEmbeddedContent::WillBeDestroyed() { ...@@ -62,7 +62,7 @@ void LayoutEmbeddedContent::WillBeDestroyed() {
cache->Remove(this); cache->Remove(this);
} }
if (auto* frame_owner = DynamicTo<HTMLFrameOwnerElement>(GetNode())) if (auto* frame_owner = GetFrameOwnerElement())
frame_owner->SetEmbeddedContentView(nullptr); frame_owner->SetEmbeddedContentView(nullptr);
LayoutReplaced::WillBeDestroyed(); LayoutReplaced::WillBeDestroyed();
...@@ -77,7 +77,7 @@ void LayoutEmbeddedContent::Destroy() { ...@@ -77,7 +77,7 @@ void LayoutEmbeddedContent::Destroy() {
// Release()). // Release()).
// //
// But, we've told the system we've destroyed the layoutObject, which happens // But, we've told the system we've destroyed the layoutObject, which happens
// when the DOM node is destroyed. So there is a good change the DOM node this // when the DOM node is destroyed. So there is a good chance the DOM node this
// object points too is invalid, so we have to clear the node so we make sure // object points too is invalid, so we have to clear the node so we make sure
// we don't access it in the future. // we don't access it in the future.
ClearNode(); ClearNode();
...@@ -100,8 +100,8 @@ WebPluginContainerImpl* LayoutEmbeddedContent::Plugin() const { ...@@ -100,8 +100,8 @@ WebPluginContainerImpl* LayoutEmbeddedContent::Plugin() const {
} }
EmbeddedContentView* LayoutEmbeddedContent::GetEmbeddedContentView() const { EmbeddedContentView* LayoutEmbeddedContent::GetEmbeddedContentView() const {
if (auto* frame_owner_element = DynamicTo<HTMLFrameOwnerElement>(GetNode())) if (auto* frame_owner = GetFrameOwnerElement())
return frame_owner_element->OwnedEmbeddedContentView(); return frame_owner->OwnedEmbeddedContentView();
return nullptr; return nullptr;
} }
...@@ -124,7 +124,7 @@ bool LayoutEmbeddedContent::RequiresAcceleratedCompositing() const { ...@@ -124,7 +124,7 @@ bool LayoutEmbeddedContent::RequiresAcceleratedCompositing() const {
if (plugin_view && plugin_view->CcLayer()) if (plugin_view && plugin_view->CcLayer())
return true; return true;
auto* element = DynamicTo<HTMLFrameOwnerElement>(GetNode()); auto* element = GetFrameOwnerElement();
if (!element) if (!element)
return false; return false;
...@@ -268,7 +268,7 @@ void LayoutEmbeddedContent::StyleDidChange(StyleDifference diff, ...@@ -268,7 +268,7 @@ void LayoutEmbeddedContent::StyleDidChange(StyleDifference diff,
return; return;
} }
auto* frame_owner = DynamicTo<HTMLFrameOwnerElement>(GetNode()); auto* frame_owner = GetFrameOwnerElement();
if (!frame_owner) if (!frame_owner)
return; return;
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#define THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_LAYOUT_EMBEDDED_CONTENT_H_ #define THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_LAYOUT_EMBEDDED_CONTENT_H_
#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/html/html_frame_owner_element.h"
#include "third_party/blink/renderer/core/layout/layout_replaced.h" #include "third_party/blink/renderer/core/layout/layout_replaced.h"
namespace blink { namespace blink {
...@@ -36,7 +37,7 @@ class WebPluginContainerImpl; ...@@ -36,7 +37,7 @@ class WebPluginContainerImpl;
// LayoutEmbeddedObject. // LayoutEmbeddedObject.
class CORE_EXPORT LayoutEmbeddedContent : public LayoutReplaced { class CORE_EXPORT LayoutEmbeddedContent : public LayoutReplaced {
public: public:
explicit LayoutEmbeddedContent(Element*); explicit LayoutEmbeddedContent(HTMLFrameOwnerElement*);
~LayoutEmbeddedContent() override; ~LayoutEmbeddedContent() override;
bool RequiresAcceleratedCompositing() const; bool RequiresAcceleratedCompositing() const;
...@@ -90,6 +91,10 @@ class CORE_EXPORT LayoutEmbeddedContent : public LayoutReplaced { ...@@ -90,6 +91,10 @@ class CORE_EXPORT LayoutEmbeddedContent : public LayoutReplaced {
const PhysicalOffset& accumulated_offset, const PhysicalOffset& accumulated_offset,
HitTestAction); HitTestAction);
HTMLFrameOwnerElement* GetFrameOwnerElement() const {
return To<HTMLFrameOwnerElement>(GetNode());
}
int ref_count_; int ref_count_;
}; };
......
...@@ -14,7 +14,7 @@ class LayoutEmbeddedContentTest : public RenderingTest {}; ...@@ -14,7 +14,7 @@ class LayoutEmbeddedContentTest : public RenderingTest {};
class OverriddenLayoutEmbeddedContent : public LayoutEmbeddedContent { class OverriddenLayoutEmbeddedContent : public LayoutEmbeddedContent {
public: public:
explicit OverriddenLayoutEmbeddedContent(Element* element) explicit OverriddenLayoutEmbeddedContent(HTMLFrameOwnerElement* element)
: LayoutEmbeddedContent(element) {} : LayoutEmbeddedContent(element) {}
const char* GetName() const override { const char* GetName() const override {
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
namespace blink { namespace blink {
LayoutEmbeddedObject::LayoutEmbeddedObject(Element* element) LayoutEmbeddedObject::LayoutEmbeddedObject(HTMLFrameOwnerElement* element)
: LayoutEmbeddedContent(element) { : LayoutEmbeddedContent(element) {
View()->GetFrameView()->SetIsVisuallyNonEmpty(); View()->GetFrameView()->SetIsVisuallyNonEmpty();
} }
......
...@@ -32,7 +32,7 @@ namespace blink { ...@@ -32,7 +32,7 @@ namespace blink {
// plugins. For example, <embed src="foo.html"> does not invoke a plugin. // plugins. For example, <embed src="foo.html"> does not invoke a plugin.
class LayoutEmbeddedObject final : public LayoutEmbeddedContent { class LayoutEmbeddedObject final : public LayoutEmbeddedContent {
public: public:
LayoutEmbeddedObject(Element*); LayoutEmbeddedObject(HTMLFrameOwnerElement*);
~LayoutEmbeddedObject() override; ~LayoutEmbeddedObject() override;
enum PluginAvailability { enum PluginAvailability {
......
...@@ -30,7 +30,8 @@ ...@@ -30,7 +30,8 @@
namespace blink { namespace blink {
LayoutIFrame::LayoutIFrame(Element* element) : LayoutEmbeddedContent(element) {} LayoutIFrame::LayoutIFrame(HTMLFrameOwnerElement* element)
: LayoutEmbeddedContent(element) {}
bool LayoutIFrame::ShouldComputeSizeAsReplaced() const { bool LayoutIFrame::ShouldComputeSizeAsReplaced() const {
return true; return true;
......
...@@ -32,7 +32,7 @@ namespace blink { ...@@ -32,7 +32,7 @@ namespace blink {
class LayoutIFrame final : public LayoutEmbeddedContent { class LayoutIFrame final : public LayoutEmbeddedContent {
public: public:
explicit LayoutIFrame(Element*); explicit LayoutIFrame(HTMLFrameOwnerElement*);
const char* GetName() const override { return "LayoutIFrame"; } const char* GetName() const override { return "LayoutIFrame"; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment