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. There may be parts that can be removed | |
113 // 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
| |
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->eventListenersRemoved(); |
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 // Maybe just pluginWrapper function should check if m_plugin is null, | |
379 // and call document().updateStyleAndLayoutIgnorePendingStylesheets as per | |
380 // layoutPartForJSBindings. | |
381 PluginView* HTMLPlugInElement::pluginWidget() const { | |
351 if (LayoutPart* layoutPart = layoutPartForJSBindings()) | 382 if (LayoutPart* layoutPart = layoutPartForJSBindings()) |
352 return layoutPart->frameViewBase(); | 383 return layoutPart->plugin(); |
353 return nullptr; | 384 return nullptr; |
354 } | 385 } |
355 | 386 |
387 PluginView* HTMLPlugInElement::plugin() const { | |
388 return m_plugin.get(); | |
389 } | |
390 | |
356 bool HTMLPlugInElement::isPresentationAttribute( | 391 bool HTMLPlugInElement::isPresentationAttribute( |
357 const QualifiedName& name) const { | 392 const QualifiedName& name) const { |
358 if (name == widthAttr || name == heightAttr || name == vspaceAttr || | 393 if (name == widthAttr || name == heightAttr || name == vspaceAttr || |
359 name == hspaceAttr || name == alignAttr) | 394 name == hspaceAttr || name == alignAttr) |
360 return true; | 395 return true; |
361 return HTMLFrameOwnerElement::isPresentationAttribute(name); | 396 return HTMLFrameOwnerElement::isPresentationAttribute(name); |
362 } | 397 } |
363 | 398 |
364 void HTMLPlugInElement::collectStyleForPresentationAttribute( | 399 void HTMLPlugInElement::collectStyleForPresentationAttribute( |
365 const QualifiedName& name, | 400 const QualifiedName& name, |
(...skipping 29 matching lines...) Expand all Loading... | |
395 // code in EventHandler; these code paths should be united. | 430 // code in EventHandler; these code paths should be united. |
396 | 431 |
397 LayoutObject* r = layoutObject(); | 432 LayoutObject* r = layoutObject(); |
398 if (!r || !r->isLayoutPart()) | 433 if (!r || !r->isLayoutPart()) |
399 return; | 434 return; |
400 if (r->isEmbeddedObject()) { | 435 if (r->isEmbeddedObject()) { |
401 if (LayoutEmbeddedItem(toLayoutEmbeddedObject(r)) | 436 if (LayoutEmbeddedItem(toLayoutEmbeddedObject(r)) |
402 .showsUnavailablePluginIndicator()) | 437 .showsUnavailablePluginIndicator()) |
403 return; | 438 return; |
404 } | 439 } |
405 FrameViewBase* frameViewBase = toLayoutPart(r)->frameViewBase(); | 440 if (!m_plugin) |
406 if (!frameViewBase) | |
407 return; | 441 return; |
408 frameViewBase->handleEvent(event); | 442 m_plugin->handleEvent(event); |
409 if (event->defaultHandled()) | 443 if (event->defaultHandled()) |
410 return; | 444 return; |
411 HTMLFrameOwnerElement::defaultEventHandler(event); | 445 HTMLFrameOwnerElement::defaultEventHandler(event); |
412 } | 446 } |
413 | 447 |
414 LayoutPart* HTMLPlugInElement::layoutPartForJSBindings() const { | 448 LayoutPart* HTMLPlugInElement::layoutPartForJSBindings() const { |
415 // Needs to load the plugin immediatedly because this function is called | 449 // Needs to load the plugin immediatedly because this function is called |
416 // when JavaScript code accesses the plugin. | 450 // when JavaScript code accesses the plugin. |
417 // FIXME: Check if dispatching events here is safe. | 451 // FIXME: Check if dispatching events here is safe. |
418 document().updateStyleAndLayoutIgnorePendingStylesheets( | 452 document().updateStyleAndLayoutIgnorePendingStylesheets( |
419 Document::RunPostLayoutTasksSynchronously); | 453 Document::RunPostLayoutTasksSynchronously); |
420 return existingLayoutPart(); | 454 return existingLayoutPart(); |
421 } | 455 } |
422 | 456 |
423 bool HTMLPlugInElement::isKeyboardFocusable() const { | 457 bool HTMLPlugInElement::isKeyboardFocusable() const { |
424 if (HTMLFrameOwnerElement::isKeyboardFocusable()) | 458 if (HTMLFrameOwnerElement::isKeyboardFocusable()) |
425 return true; | 459 return true; |
426 return document().isActive() && pluginWidget() && | 460 return document().isActive() && pluginWidget() && |
427 pluginWidget()->isPluginView() && | 461 pluginWidget()->supportsKeyboardFocus(); |
428 toPluginView(pluginWidget())->supportsKeyboardFocus(); | |
429 } | 462 } |
430 | 463 |
431 bool HTMLPlugInElement::hasCustomFocusLogic() const { | 464 bool HTMLPlugInElement::hasCustomFocusLogic() const { |
432 return !useFallbackContent(); | 465 return !useFallbackContent(); |
433 } | 466 } |
434 | 467 |
435 bool HTMLPlugInElement::isPluginElement() const { | 468 bool HTMLPlugInElement::isPluginElement() const { |
436 return true; | 469 return true; |
437 } | 470 } |
438 | 471 |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
658 | 691 |
659 void HTMLPlugInElement::lazyReattachIfNeeded() { | 692 void HTMLPlugInElement::lazyReattachIfNeeded() { |
660 if (!useFallbackContent() && needsPluginUpdate() && layoutObject() && | 693 if (!useFallbackContent() && needsPluginUpdate() && layoutObject() && |
661 !isImageType()) { | 694 !isImageType()) { |
662 lazyReattachIfAttached(); | 695 lazyReattachIfAttached(); |
663 setPersistedPlugin(nullptr); | 696 setPersistedPlugin(nullptr); |
664 } | 697 } |
665 } | 698 } |
666 | 699 |
667 } // namespace blink | 700 } // namespace blink |
OLD | NEW |