Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 * (C) 2000 Stefan Schimanski (1Stein@gmx.de) | 4 * (C) 2000 Stefan Schimanski (1Stein@gmx.de) |
| 5 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. | 5 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. |
| 6 * | 6 * |
| 7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 m_shouldPreferPlugInsForImages(preferPlugInsForImagesOption == | 85 m_shouldPreferPlugInsForImages(preferPlugInsForImagesOption == |
| 86 ShouldPreferPlugInsForImages) {} | 86 ShouldPreferPlugInsForImages) {} |
| 87 | 87 |
| 88 HTMLPlugInElement::~HTMLPlugInElement() { | 88 HTMLPlugInElement::~HTMLPlugInElement() { |
| 89 DCHECK(!m_pluginWrapper); // cleared in detachLayoutTree() | 89 DCHECK(!m_pluginWrapper); // cleared in detachLayoutTree() |
| 90 DCHECK(!m_isDelayingLoadEvent); | 90 DCHECK(!m_isDelayingLoadEvent); |
| 91 } | 91 } |
| 92 | 92 |
| 93 DEFINE_TRACE(HTMLPlugInElement) { | 93 DEFINE_TRACE(HTMLPlugInElement) { |
| 94 visitor->trace(m_imageLoader); | 94 visitor->trace(m_imageLoader); |
| 95 visitor->trace(m_plugin); | |
| 95 visitor->trace(m_persistedPlugin); | 96 visitor->trace(m_persistedPlugin); |
| 96 HTMLFrameOwnerElement::trace(visitor); | 97 HTMLFrameOwnerElement::trace(visitor); |
| 97 } | 98 } |
| 98 | 99 |
| 99 // TODO(joelhockey): Move implementation of HTMLFrameOwnerElement | 100 void HTMLPlugInElement::setPlugin(PluginView* plugin) { |
| 100 // setWidget/releaseWidget/ownedWidget that relates to plugins to here and | 101 if (plugin == m_plugin) |
| 101 // remove inheritance from PluginView to FrameViewBase. | 102 return; |
| 102 void HTMLPlugInElement::setPlugin(PluginView* pluginView) { | 103 |
| 103 setWidget(pluginView); | 104 // Remove and dispose the old plugin if we had one. |
| 105 if (m_plugin) { | |
| 106 document().view()->removePlugin(m_plugin); | |
| 107 disposeWidgetSoon(m_plugin); | |
| 108 } | |
| 109 m_plugin = plugin; | |
| 110 | |
| 111 // TODO(joelhockey): I copied the rest of this method from | |
| 112 // HTMLFrameOwnerElement. I don't really know what it does. | |
| 113 // Are the layoutPartItem.isNull check and DCHECKs required? | |
| 114 LayoutPart* layoutPart = toLayoutPart(layoutObject()); | |
| 115 LayoutPartItem layoutPartItem = LayoutPartItem(layoutPart); | |
| 116 if (layoutPartItem.isNull()) | |
| 117 return; | |
| 118 | |
| 119 // Update layout and frame with new plugin. | |
| 120 if (m_plugin) { | |
| 121 layoutPartItem.updateOnWidgetChange(); | |
| 122 | |
| 123 DCHECK_EQ(document().view(), layoutPartItem.frameView()); | |
| 124 DCHECK(layoutPartItem.frameView()); | |
| 125 document().view()->addPlugin(plugin); | |
| 126 } | |
| 127 | |
| 128 // Apparently accessibility objects might have been modified if plugin | |
| 129 // was removed. | |
| 130 if (AXObjectCache* cache = document().existingAXObjectCache()) | |
| 131 cache->childrenChanged(layoutPart); | |
| 104 } | 132 } |
| 105 | 133 |
| 106 PluginView* HTMLPlugInElement::releasePlugin() { | 134 PluginView* HTMLPlugInElement::releasePlugin() { |
| 107 FrameViewBase* plugin = releaseWidget(); | 135 if (!m_plugin) |
| 108 return plugin && plugin->isPluginView() ? toPluginView(plugin) : nullptr; | 136 return nullptr; |
| 109 } | 137 document().view()->removePlugin(m_plugin); |
| 110 | 138 LayoutPart* layoutPart = toLayoutPart(layoutObject()); |
| 111 PluginView* HTMLPlugInElement::ownedPlugin() const { | 139 if (layoutPart) { |
| 112 FrameViewBase* plugin = ownedWidget(); | 140 if (AXObjectCache* cache = document().existingAXObjectCache()) |
| 113 return plugin && plugin->isPluginView() ? toPluginView(plugin) : nullptr; | 141 cache->childrenChanged(layoutPart); |
| 142 } | |
| 143 return m_plugin.release(); | |
| 114 } | 144 } |
| 115 | 145 |
| 116 void HTMLPlugInElement::setPersistedPlugin(PluginView* plugin) { | 146 void HTMLPlugInElement::setPersistedPlugin(PluginView* plugin) { |
| 117 if (m_persistedPlugin == plugin) | 147 if (m_persistedPlugin == plugin) |
| 118 return; | 148 return; |
| 119 if (m_persistedPlugin) { | 149 if (m_persistedPlugin) { |
| 120 m_persistedPlugin->hide(); | 150 m_persistedPlugin->hide(); |
| 121 disposeWidgetSoon(m_persistedPlugin.release()); | 151 disposeWidgetSoon(m_persistedPlugin.release()); |
| 122 } | 152 } |
| 123 m_persistedPlugin = plugin; | 153 m_persistedPlugin = plugin; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 146 // new frame and set it as the LayoutPart's FrameViewBase, causing what was | 176 // new frame and set it as the LayoutPart's FrameViewBase, causing what was |
| 147 // previously in the FrameViewBase to be torn down. | 177 // previously in the FrameViewBase to be torn down. |
| 148 return loadOrRedirectSubframe(completedURL, getNameAttribute(), true); | 178 return loadOrRedirectSubframe(completedURL, getNameAttribute(), true); |
| 149 } | 179 } |
| 150 | 180 |
| 151 return loadPlugin(completedURL, mimeType, paramNames, paramValues, | 181 return loadPlugin(completedURL, mimeType, paramNames, paramValues, |
| 152 useFallback, true); | 182 useFallback, true); |
| 153 } | 183 } |
| 154 | 184 |
| 155 bool HTMLPlugInElement::canProcessDrag() const { | 185 bool HTMLPlugInElement::canProcessDrag() const { |
| 156 return pluginWidget() && pluginWidget()->isPluginView() && | 186 return pluginWidget() && pluginWidget()->canProcessDrag(); |
| 157 toPluginView(pluginWidget())->canProcessDrag(); | |
| 158 } | 187 } |
| 159 | 188 |
| 160 bool HTMLPlugInElement::canStartSelection() const { | 189 bool HTMLPlugInElement::canStartSelection() const { |
| 161 return useFallbackContent() && Node::canStartSelection(); | 190 return useFallbackContent() && Node::canStartSelection(); |
| 162 } | 191 } |
| 163 | 192 |
| 164 bool HTMLPlugInElement::willRespondToMouseClickEvents() { | 193 bool HTMLPlugInElement::willRespondToMouseClickEvents() { |
| 165 if (isDisabledFormControl()) | 194 if (isDisabledFormControl()) |
| 166 return false; | 195 return false; |
| 167 LayoutObject* r = layoutObject(); | 196 LayoutObject* r = layoutObject(); |
| 168 return r && (r->isEmbeddedObject() || r->isLayoutPart()); | 197 return r && (r->isEmbeddedObject() || r->isLayoutPart()); |
| 169 } | 198 } |
| 170 | 199 |
| 171 void HTMLPlugInElement::removeAllEventListeners() { | 200 void HTMLPlugInElement::removeAllEventListeners() { |
| 172 HTMLFrameOwnerElement::removeAllEventListeners(); | 201 HTMLFrameOwnerElement::removeAllEventListeners(); |
| 173 if (LayoutPart* layoutObject = existingLayoutPart()) { | 202 if (m_plugin) { |
| 174 if (FrameViewBase* frameViewBase = layoutObject->frameViewBase()) | 203 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
| |
| 175 frameViewBase->eventListenersRemoved(); | |
| 176 } | 204 } |
| 177 } | 205 } |
| 178 | 206 |
| 179 void HTMLPlugInElement::didMoveToNewDocument(Document& oldDocument) { | 207 void HTMLPlugInElement::didMoveToNewDocument(Document& oldDocument) { |
| 180 if (m_imageLoader) | 208 if (m_imageLoader) |
| 181 m_imageLoader->elementDidMoveToNewDocument(); | 209 m_imageLoader->elementDidMoveToNewDocument(); |
| 182 HTMLFrameOwnerElement::didMoveToNewDocument(oldDocument); | 210 HTMLFrameOwnerElement::didMoveToNewDocument(oldDocument); |
| 183 } | 211 } |
| 184 | 212 |
| 185 void HTMLPlugInElement::attachLayoutTree(const AttachContext& context) { | 213 void HTMLPlugInElement::attachLayoutTree(const AttachContext& context) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 257 Vector<String> paramValues; | 285 Vector<String> paramValues; |
| 258 | 286 |
| 259 paramNames.push_back("type"); | 287 paramNames.push_back("type"); |
| 260 paramValues.push_back(m_serviceType); | 288 paramValues.push_back(m_serviceType); |
| 261 | 289 |
| 262 bool useFallback = false; | 290 bool useFallback = false; |
| 263 loadPlugin(url, m_serviceType, paramNames, paramValues, useFallback, false); | 291 loadPlugin(url, m_serviceType, paramNames, paramValues, useFallback, false); |
| 264 } | 292 } |
| 265 | 293 |
| 266 bool HTMLPlugInElement::shouldAccelerate() const { | 294 bool HTMLPlugInElement::shouldAccelerate() const { |
| 267 return ownedPlugin() && ownedPlugin()->platformLayer(); | 295 return m_plugin && m_plugin->platformLayer(); |
| 268 } | 296 } |
| 269 | 297 |
| 270 void HTMLPlugInElement::detachLayoutTree(const AttachContext& context) { | 298 void HTMLPlugInElement::detachLayoutTree(const AttachContext& context) { |
| 271 // Update the FrameViewBase the next time we attach (detaching destroys the | 299 // Update the FrameViewBase the next time we attach (detaching destroys the |
| 272 // plugin). | 300 // plugin). |
| 273 // FIXME: None of this "needsPluginUpdate" related code looks right. | 301 // FIXME: None of this "needsPluginUpdate" related code looks right. |
| 274 if (layoutObject() && !useFallbackContent()) | 302 if (layoutObject() && !useFallbackContent()) |
| 275 setNeedsPluginUpdate(true); | 303 setNeedsPluginUpdate(true); |
| 276 | 304 |
| 277 if (m_isDelayingLoadEvent) { | 305 if (m_isDelayingLoadEvent) { |
| 278 m_isDelayingLoadEvent = false; | 306 m_isDelayingLoadEvent = false; |
| 279 document().decrementLoadEventDelayCount(); | 307 document().decrementLoadEventDelayCount(); |
| 280 } | 308 } |
| 281 | 309 |
| 282 // Only try to persist a plugin we actually own. | 310 // Only try to persist a plugin we actually own. |
| 283 PluginView* plugin = ownedPlugin(); | 311 if (m_plugin && context.performingReattach) { |
| 284 if (plugin && context.performingReattach) { | |
| 285 setPersistedPlugin(releasePlugin()); | 312 setPersistedPlugin(releasePlugin()); |
| 286 } else { | 313 } else { |
| 287 // Clear the plugin; will trigger disposal of it with Oilpan. | 314 // Clear the plugin; will trigger disposal of it with Oilpan. |
| 288 setPlugin(nullptr); | 315 setPlugin(nullptr); |
| 289 } | 316 } |
| 290 | 317 |
| 291 resetInstance(); | 318 resetInstance(); |
| 292 | 319 |
| 293 HTMLFrameOwnerElement::detachLayoutTree(context); | 320 HTMLFrameOwnerElement::detachLayoutTree(context); |
| 294 } | 321 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 plugin = m_persistedPlugin.get(); | 367 plugin = m_persistedPlugin.get(); |
| 341 else | 368 else |
| 342 plugin = pluginWidget(); | 369 plugin = pluginWidget(); |
| 343 | 370 |
| 344 if (plugin) | 371 if (plugin) |
| 345 m_pluginWrapper = frame->script().createPluginWrapper(plugin); | 372 m_pluginWrapper = frame->script().createPluginWrapper(plugin); |
| 346 } | 373 } |
| 347 return m_pluginWrapper.get(); | 374 return m_pluginWrapper.get(); |
| 348 } | 375 } |
| 349 | 376 |
| 350 FrameViewBase* HTMLPlugInElement::pluginWidget() const { | 377 // TODO(joelhockey): Remove this and use m_plugin. |
| 378 // I can't see how calling layoutPartForJSBindings can change | |
| 379 // the previous Widget, or the new m_plugin. | |
| 380 PluginView* HTMLPlugInElement::pluginWidget() const { | |
| 351 if (LayoutPart* layoutPart = layoutPartForJSBindings()) | 381 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
| |
| 352 return layoutPart->frameViewBase(); | 382 return layoutPart->plugin(); |
| 353 return nullptr; | 383 return nullptr; |
| 354 } | 384 } |
| 355 | 385 |
| 386 PluginView* HTMLPlugInElement::plugin() const { | |
| 387 return m_plugin.get(); | |
| 388 } | |
| 389 | |
| 356 bool HTMLPlugInElement::isPresentationAttribute( | 390 bool HTMLPlugInElement::isPresentationAttribute( |
| 357 const QualifiedName& name) const { | 391 const QualifiedName& name) const { |
| 358 if (name == widthAttr || name == heightAttr || name == vspaceAttr || | 392 if (name == widthAttr || name == heightAttr || name == vspaceAttr || |
| 359 name == hspaceAttr || name == alignAttr) | 393 name == hspaceAttr || name == alignAttr) |
| 360 return true; | 394 return true; |
| 361 return HTMLFrameOwnerElement::isPresentationAttribute(name); | 395 return HTMLFrameOwnerElement::isPresentationAttribute(name); |
| 362 } | 396 } |
| 363 | 397 |
| 364 void HTMLPlugInElement::collectStyleForPresentationAttribute( | 398 void HTMLPlugInElement::collectStyleForPresentationAttribute( |
| 365 const QualifiedName& name, | 399 const QualifiedName& name, |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 395 // code in EventHandler; these code paths should be united. | 429 // code in EventHandler; these code paths should be united. |
| 396 | 430 |
| 397 LayoutObject* r = layoutObject(); | 431 LayoutObject* r = layoutObject(); |
| 398 if (!r || !r->isLayoutPart()) | 432 if (!r || !r->isLayoutPart()) |
| 399 return; | 433 return; |
| 400 if (r->isEmbeddedObject()) { | 434 if (r->isEmbeddedObject()) { |
| 401 if (LayoutEmbeddedItem(toLayoutEmbeddedObject(r)) | 435 if (LayoutEmbeddedItem(toLayoutEmbeddedObject(r)) |
| 402 .showsUnavailablePluginIndicator()) | 436 .showsUnavailablePluginIndicator()) |
| 403 return; | 437 return; |
| 404 } | 438 } |
| 405 FrameViewBase* frameViewBase = toLayoutPart(r)->frameViewBase(); | 439 if (!m_plugin) |
| 406 if (!frameViewBase) | |
| 407 return; | 440 return; |
| 408 frameViewBase->handleEvent(event); | 441 m_plugin->handleEvent(event); |
| 409 if (event->defaultHandled()) | 442 if (event->defaultHandled()) |
| 410 return; | 443 return; |
| 411 HTMLFrameOwnerElement::defaultEventHandler(event); | 444 HTMLFrameOwnerElement::defaultEventHandler(event); |
| 412 } | 445 } |
| 413 | 446 |
| 414 LayoutPart* HTMLPlugInElement::layoutPartForJSBindings() const { | 447 LayoutPart* HTMLPlugInElement::layoutPartForJSBindings() const { |
| 415 // Needs to load the plugin immediatedly because this function is called | 448 // Needs to load the plugin immediatedly because this function is called |
| 416 // when JavaScript code accesses the plugin. | 449 // when JavaScript code accesses the plugin. |
| 417 // FIXME: Check if dispatching events here is safe. | 450 // FIXME: Check if dispatching events here is safe. |
| 418 document().updateStyleAndLayoutIgnorePendingStylesheets( | 451 document().updateStyleAndLayoutIgnorePendingStylesheets( |
| 419 Document::RunPostLayoutTasksSynchronously); | 452 Document::RunPostLayoutTasksSynchronously); |
| 420 return existingLayoutPart(); | 453 return existingLayoutPart(); |
| 421 } | 454 } |
| 422 | 455 |
| 423 bool HTMLPlugInElement::isKeyboardFocusable() const { | 456 bool HTMLPlugInElement::isKeyboardFocusable() const { |
| 424 if (HTMLFrameOwnerElement::isKeyboardFocusable()) | 457 if (HTMLFrameOwnerElement::isKeyboardFocusable()) |
| 425 return true; | 458 return true; |
| 426 return document().isActive() && pluginWidget() && | 459 return document().isActive() && pluginWidget() && |
| 427 pluginWidget()->isPluginView() && | 460 pluginWidget()->supportsKeyboardFocus(); |
| 428 toPluginView(pluginWidget())->supportsKeyboardFocus(); | |
| 429 } | 461 } |
| 430 | 462 |
| 431 bool HTMLPlugInElement::hasCustomFocusLogic() const { | 463 bool HTMLPlugInElement::hasCustomFocusLogic() const { |
| 432 return !useFallbackContent(); | 464 return !useFallbackContent(); |
| 433 } | 465 } |
| 434 | 466 |
| 435 bool HTMLPlugInElement::isPluginElement() const { | 467 bool HTMLPlugInElement::isPluginElement() const { |
| 436 return true; | 468 return true; |
| 437 } | 469 } |
| 438 | 470 |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 658 | 690 |
| 659 void HTMLPlugInElement::lazyReattachIfNeeded() { | 691 void HTMLPlugInElement::lazyReattachIfNeeded() { |
| 660 if (!useFallbackContent() && needsPluginUpdate() && layoutObject() && | 692 if (!useFallbackContent() && needsPluginUpdate() && layoutObject() && |
| 661 !isImageType()) { | 693 !isImageType()) { |
| 662 lazyReattachIfAttached(); | 694 lazyReattachIfAttached(); |
| 663 setPersistedPlugin(nullptr); | 695 setPersistedPlugin(nullptr); |
| 664 } | 696 } |
| 665 } | 697 } |
| 666 | 698 |
| 667 } // namespace blink | 699 } // namespace blink |
| OLD | NEW |