Index: third_party/WebKit/Source/core/html/HTMLPlugInElement.cpp |
diff --git a/third_party/WebKit/Source/core/html/HTMLPlugInElement.cpp b/third_party/WebKit/Source/core/html/HTMLPlugInElement.cpp |
index 9eb65ef0dbf4bb2bf62f5aafb4e2c845cc1624d4..14eb7088831b9db508f123bc84b9c4d3661f28b1 100644 |
--- a/third_party/WebKit/Source/core/html/HTMLPlugInElement.cpp |
+++ b/third_party/WebKit/Source/core/html/HTMLPlugInElement.cpp |
@@ -92,25 +92,55 @@ HTMLPlugInElement::~HTMLPlugInElement() { |
DEFINE_TRACE(HTMLPlugInElement) { |
visitor->trace(m_imageLoader); |
+ visitor->trace(m_plugin); |
visitor->trace(m_persistedPlugin); |
HTMLFrameOwnerElement::trace(visitor); |
} |
-// TODO(joelhockey): Move implementation of HTMLFrameOwnerElement |
-// setWidget/releaseWidget/ownedWidget that relates to plugins to here and |
-// remove inheritance from PluginView to FrameViewBase. |
-void HTMLPlugInElement::setPlugin(PluginView* pluginView) { |
- setWidget(pluginView); |
-} |
+void HTMLPlugInElement::setPlugin(PluginView* plugin) { |
+ if (plugin == m_plugin) |
+ return; |
-PluginView* HTMLPlugInElement::releasePlugin() { |
- FrameViewBase* plugin = releaseWidget(); |
- return plugin && plugin->isPluginView() ? toPluginView(plugin) : nullptr; |
+ // Remove and dispose the old plugin if we had one. |
+ if (m_plugin) { |
+ document().view()->removePlugin(m_plugin); |
+ disposeWidgetSoon(m_plugin); |
+ } |
+ m_plugin = plugin; |
+ |
+ // TODO(joelhockey): I copied the rest of this method from |
+ // HTMLFrameOwnerElement. There may be parts that can be removed |
+ // such as the layoutPartItem.isNull check and DCHECKs. |
dcheng
2017/04/04 07:20:12
I feel a bit uneasy about this code duplication. I
joelhockey
2017/04/04 23:39:05
My primary focus has bene to remove the common bas
|
+ LayoutPart* layoutPart = toLayoutPart(layoutObject()); |
+ LayoutPartItem layoutPartItem = LayoutPartItem(layoutPart); |
+ if (layoutPartItem.isNull()) |
+ return; |
+ |
+ // Update layout and frame with new plugin. |
+ if (m_plugin) { |
+ layoutPartItem.updateOnWidgetChange(); |
+ |
+ DCHECK_EQ(document().view(), layoutPartItem.frameView()); |
+ DCHECK(layoutPartItem.frameView()); |
+ document().view()->addPlugin(plugin); |
+ } |
+ |
+ // Apparently accessibility objects might have been modified if plugin |
+ // was removed. |
+ if (AXObjectCache* cache = document().existingAXObjectCache()) |
+ cache->childrenChanged(layoutPart); |
} |
-PluginView* HTMLPlugInElement::ownedPlugin() const { |
- FrameViewBase* plugin = ownedWidget(); |
- return plugin && plugin->isPluginView() ? toPluginView(plugin) : nullptr; |
+PluginView* HTMLPlugInElement::releasePlugin() { |
+ if (!m_plugin) |
+ return nullptr; |
+ document().view()->removePlugin(m_plugin); |
+ LayoutPart* layoutPart = toLayoutPart(layoutObject()); |
+ if (layoutPart) { |
+ if (AXObjectCache* cache = document().existingAXObjectCache()) |
+ cache->childrenChanged(layoutPart); |
+ } |
+ return m_plugin.release(); |
} |
void HTMLPlugInElement::setPersistedPlugin(PluginView* plugin) { |
@@ -153,8 +183,7 @@ bool HTMLPlugInElement::requestObjectInternal( |
} |
bool HTMLPlugInElement::canProcessDrag() const { |
- return pluginWidget() && pluginWidget()->isPluginView() && |
- toPluginView(pluginWidget())->canProcessDrag(); |
+ return pluginWidget() && pluginWidget()->canProcessDrag(); |
} |
bool HTMLPlugInElement::canStartSelection() const { |
@@ -170,9 +199,8 @@ bool HTMLPlugInElement::willRespondToMouseClickEvents() { |
void HTMLPlugInElement::removeAllEventListeners() { |
HTMLFrameOwnerElement::removeAllEventListeners(); |
- if (LayoutPart* layoutObject = existingLayoutPart()) { |
- if (FrameViewBase* frameViewBase = layoutObject->frameViewBase()) |
- frameViewBase->eventListenersRemoved(); |
+ if (m_plugin) { |
+ m_plugin->eventListenersRemoved(); |
} |
} |
@@ -264,7 +292,7 @@ void HTMLPlugInElement::createPluginWithoutLayoutObject() { |
} |
bool HTMLPlugInElement::shouldAccelerate() const { |
- return ownedPlugin() && ownedPlugin()->platformLayer(); |
+ return m_plugin && m_plugin->platformLayer(); |
} |
void HTMLPlugInElement::detachLayoutTree(const AttachContext& context) { |
@@ -280,8 +308,7 @@ void HTMLPlugInElement::detachLayoutTree(const AttachContext& context) { |
} |
// Only try to persist a plugin we actually own. |
- PluginView* plugin = ownedPlugin(); |
- if (plugin && context.performingReattach) { |
+ if (m_plugin && context.performingReattach) { |
setPersistedPlugin(releasePlugin()); |
} else { |
// Clear the plugin; will trigger disposal of it with Oilpan. |
@@ -347,12 +374,20 @@ SharedPersistent<v8::Object>* HTMLPlugInElement::pluginWrapper() { |
return m_pluginWrapper.get(); |
} |
-FrameViewBase* HTMLPlugInElement::pluginWidget() const { |
+// TODO(joelhockey): Remove this and use m_plugin. |
+// Maybe just pluginWrapper function should check if m_plugin is null, |
+// and call document().updateStyleAndLayoutIgnorePendingStylesheets as per |
+// layoutPartForJSBindings. |
+PluginView* HTMLPlugInElement::pluginWidget() const { |
if (LayoutPart* layoutPart = layoutPartForJSBindings()) |
- return layoutPart->frameViewBase(); |
+ return layoutPart->plugin(); |
return nullptr; |
} |
+PluginView* HTMLPlugInElement::plugin() const { |
+ return m_plugin.get(); |
+} |
+ |
bool HTMLPlugInElement::isPresentationAttribute( |
const QualifiedName& name) const { |
if (name == widthAttr || name == heightAttr || name == vspaceAttr || |
@@ -402,10 +437,9 @@ void HTMLPlugInElement::defaultEventHandler(Event* event) { |
.showsUnavailablePluginIndicator()) |
return; |
} |
- FrameViewBase* frameViewBase = toLayoutPart(r)->frameViewBase(); |
- if (!frameViewBase) |
+ if (!m_plugin) |
return; |
- frameViewBase->handleEvent(event); |
+ m_plugin->handleEvent(event); |
if (event->defaultHandled()) |
return; |
HTMLFrameOwnerElement::defaultEventHandler(event); |
@@ -424,8 +458,7 @@ bool HTMLPlugInElement::isKeyboardFocusable() const { |
if (HTMLFrameOwnerElement::isKeyboardFocusable()) |
return true; |
return document().isActive() && pluginWidget() && |
- pluginWidget()->isPluginView() && |
- toPluginView(pluginWidget())->supportsKeyboardFocus(); |
+ pluginWidget()->supportsKeyboardFocus(); |
} |
bool HTMLPlugInElement::hasCustomFocusLogic() const { |