Chromium Code Reviews| 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..dd6b2af547de8a1f56b97debe11f76ef5e15ec02 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. I don't really know what it does. |
| + // Are the layoutPartItem.isNull check and DCHECKs required? |
| + 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.get()->eventListenersRemoved(); |
|
dcheng
2017/03/23 07:21:42
Minor nit: no .get() is needed here
joelhockey
2017/03/27 06:42:21
Thanks. Do let me know when my code is not idioma
|
| } |
| } |
| @@ -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,19 @@ SharedPersistent<v8::Object>* HTMLPlugInElement::pluginWrapper() { |
| return m_pluginWrapper.get(); |
| } |
| -FrameViewBase* HTMLPlugInElement::pluginWidget() const { |
| +// TODO(joelhockey): Remove this and use m_plugin. |
| +// I can't see how calling layoutPartForJSBindings can change |
| +// the previous Widget, or the new m_plugin. |
| +PluginView* HTMLPlugInElement::pluginWidget() const { |
| if (LayoutPart* layoutPart = layoutPartForJSBindings()) |
|
dcheng
2017/03/23 07:21:42
This will synchronously trigger initialization of
joelhockey
2017/03/27 06:42:21
Ack. In another CL I might see if I can remove th
|
| - 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 +436,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 +457,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 { |