Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: Source/core/html/HTMLPlugInElement.cpp

Issue 1313763002: Blink Plugins: Remove Shadow DOM Plugin Placeholder (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 29 matching lines...) Expand all
40 #include "core/html/PluginDocument.h" 40 #include "core/html/PluginDocument.h"
41 #include "core/input/EventHandler.h" 41 #include "core/input/EventHandler.h"
42 #include "core/layout/LayoutBlockFlow.h" 42 #include "core/layout/LayoutBlockFlow.h"
43 #include "core/layout/LayoutEmbeddedObject.h" 43 #include "core/layout/LayoutEmbeddedObject.h"
44 #include "core/layout/LayoutImage.h" 44 #include "core/layout/LayoutImage.h"
45 #include "core/layout/LayoutPart.h" 45 #include "core/layout/LayoutPart.h"
46 #include "core/loader/FrameLoaderClient.h" 46 #include "core/loader/FrameLoaderClient.h"
47 #include "core/loader/MixedContentChecker.h" 47 #include "core/loader/MixedContentChecker.h"
48 #include "core/page/Page.h" 48 #include "core/page/Page.h"
49 #include "core/page/scrolling/ScrollingCoordinator.h" 49 #include "core/page/scrolling/ScrollingCoordinator.h"
50 #include "core/plugins/PluginPlaceholder.h"
51 #include "core/plugins/PluginView.h" 50 #include "core/plugins/PluginView.h"
52 #include "platform/Logging.h" 51 #include "platform/Logging.h"
53 #include "platform/MIMETypeFromURL.h" 52 #include "platform/MIMETypeFromURL.h"
54 #include "platform/MIMETypeRegistry.h" 53 #include "platform/MIMETypeRegistry.h"
55 #include "platform/Widget.h" 54 #include "platform/Widget.h"
56 #include "platform/plugins/PluginData.h" 55 #include "platform/plugins/PluginData.h"
57 #include "public/platform/WebURLRequest.h" 56 #include "public/platform/WebURLRequest.h"
58 57
59 namespace blink { 58 namespace blink {
60 59
(...skipping 19 matching lines...) Expand all
80 79
81 if (m_NPObject) { 80 if (m_NPObject) {
82 _NPN_ReleaseObject(m_NPObject); 81 _NPN_ReleaseObject(m_NPObject);
83 m_NPObject = 0; 82 m_NPObject = 0;
84 } 83 }
85 } 84 }
86 85
87 DEFINE_TRACE(HTMLPlugInElement) 86 DEFINE_TRACE(HTMLPlugInElement)
88 { 87 {
89 visitor->trace(m_imageLoader); 88 visitor->trace(m_imageLoader);
90 visitor->trace(m_placeholder);
91 visitor->trace(m_persistedPluginWidget); 89 visitor->trace(m_persistedPluginWidget);
92 HTMLFrameOwnerElement::trace(visitor); 90 HTMLFrameOwnerElement::trace(visitor);
93 } 91 }
94 92
95 #if ENABLE(OILPAN) 93 #if ENABLE(OILPAN)
96 void HTMLPlugInElement::disconnectContentFrame() 94 void HTMLPlugInElement::disconnectContentFrame()
97 { 95 {
98 if (m_persistedPluginWidget) { 96 if (m_persistedPluginWidget) {
99 m_persistedPluginWidget->dispose(); 97 m_persistedPluginWidget->dispose();
100 m_persistedPluginWidget = nullptr; 98 m_persistedPluginWidget = nullptr;
(...skipping 22 matching lines...) Expand all
123 LocalFrame* frame = toPluginView(widget)->pluginFrame(); 121 LocalFrame* frame = toPluginView(widget)->pluginFrame();
124 ASSERT(frame); 122 ASSERT(frame);
125 frame->registerPluginElement(this); 123 frame->registerPluginElement(this);
126 } 124 }
127 #endif 125 #endif
128 m_persistedPluginWidget = widget; 126 m_persistedPluginWidget = widget;
129 } 127 }
130 128
131 bool HTMLPlugInElement::canProcessDrag() const 129 bool HTMLPlugInElement::canProcessDrag() const
132 { 130 {
133 if (Widget* widget = existingPluginWidget()) 131 return pluginWidget() && pluginWidget()->isPluginView() && toPluginView(plug inWidget())->canProcessDrag();
134 return widget->isPluginView() && toPluginView(widget)->canProcessDrag();
135 return false;
136 } 132 }
137 133
138 bool HTMLPlugInElement::willRespondToMouseClickEvents() 134 bool HTMLPlugInElement::willRespondToMouseClickEvents()
139 { 135 {
140 if (isDisabledFormControl()) 136 if (isDisabledFormControl())
141 return false; 137 return false;
142 LayoutObject* r = layoutObject(); 138 LayoutObject* r = layoutObject();
143 return r && (r->isEmbeddedObject() || r->isLayoutPart()); 139 return r && (r->isEmbeddedObject() || r->isLayoutPart());
144 } 140 }
145 141
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 // a LayoutEmbeddedObject or LayoutPart. 259 // a LayoutEmbeddedObject or LayoutPart.
264 if (useFallbackContent()) 260 if (useFallbackContent())
265 return LayoutObject::createObject(this, style); 261 return LayoutObject::createObject(this, style);
266 262
267 if (isImageType()) { 263 if (isImageType()) {
268 LayoutImage* image = new LayoutImage(this); 264 LayoutImage* image = new LayoutImage(this);
269 image->setImageResource(LayoutImageResource::create()); 265 image->setImageResource(LayoutImageResource::create());
270 return image; 266 return image;
271 } 267 }
272 268
273 if (usePlaceholderContent())
274 return new LayoutBlockFlow(this);
275 269
276 return new LayoutEmbeddedObject(this); 270 return new LayoutEmbeddedObject(this);
277 } 271 }
278 272
279 void HTMLPlugInElement::finishParsingChildren() 273 void HTMLPlugInElement::finishParsingChildren()
280 { 274 {
281 HTMLFrameOwnerElement::finishParsingChildren(); 275 HTMLFrameOwnerElement::finishParsingChildren();
282 if (useFallbackContent()) 276 if (useFallbackContent())
283 return; 277 return;
284 278
(...skipping 15 matching lines...) Expand all
300 294
301 // If the host dynamically turns off JavaScript (or Java) we will still 295 // If the host dynamically turns off JavaScript (or Java) we will still
302 // return the cached allocated Bindings::Instance. Not supporting this 296 // return the cached allocated Bindings::Instance. Not supporting this
303 // edge-case is OK. 297 // edge-case is OK.
304 if (!m_pluginWrapper) { 298 if (!m_pluginWrapper) {
305 Widget* plugin; 299 Widget* plugin;
306 300
307 if (m_persistedPluginWidget) 301 if (m_persistedPluginWidget)
308 plugin = m_persistedPluginWidget.get(); 302 plugin = m_persistedPluginWidget.get();
309 else 303 else
310 plugin = pluginWidgetForJSBindings(); 304 plugin = pluginWidget();
311 305
312 if (plugin) 306 if (plugin)
313 m_pluginWrapper = frame->script().createPluginWrapper(plugin); 307 m_pluginWrapper = frame->script().createPluginWrapper(plugin);
314 } 308 }
315 return m_pluginWrapper.get(); 309 return m_pluginWrapper.get();
316 } 310 }
317 311
318 Widget* HTMLPlugInElement::existingPluginWidget() const 312 Widget* HTMLPlugInElement::pluginWidget() const
319 {
320 if (LayoutPart* layoutPart = existingLayoutPart())
321 return layoutPart->widget();
322 return nullptr;
323 }
324
325 Widget* HTMLPlugInElement::pluginWidgetForJSBindings()
326 { 313 {
327 if (LayoutPart* layoutPart = layoutPartForJSBindings()) 314 if (LayoutPart* layoutPart = layoutPartForJSBindings())
328 return layoutPart->widget(); 315 return layoutPart->widget();
329 return nullptr; 316 return nullptr;
330 } 317 }
331 318
332 bool HTMLPlugInElement::isPresentationAttribute(const QualifiedName& name) const 319 bool HTMLPlugInElement::isPresentationAttribute(const QualifiedName& name) const
333 { 320 {
334 if (name == widthAttr || name == heightAttr || name == vspaceAttr || name == hspaceAttr || name == alignAttr) 321 if (name == widthAttr || name == heightAttr || name == vspaceAttr || name == hspaceAttr || name == alignAttr)
335 return true; 322 return true;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 { 374 {
388 // Needs to load the plugin immediatedly because this function is called 375 // Needs to load the plugin immediatedly because this function is called
389 // when JavaScript code accesses the plugin. 376 // when JavaScript code accesses the plugin.
390 // FIXME: Check if dispatching events here is safe. 377 // FIXME: Check if dispatching events here is safe.
391 document().updateLayoutIgnorePendingStylesheets(Document::RunPostLayoutTasks Synchronously); 378 document().updateLayoutIgnorePendingStylesheets(Document::RunPostLayoutTasks Synchronously);
392 return existingLayoutPart(); 379 return existingLayoutPart();
393 } 380 }
394 381
395 bool HTMLPlugInElement::isKeyboardFocusable() const 382 bool HTMLPlugInElement::isKeyboardFocusable() const
396 { 383 {
397 if (useFallbackContent() || usePlaceholderContent())
398 return HTMLElement::isKeyboardFocusable();
399
400 if (!document().isActive()) 384 if (!document().isActive())
401 return false; 385 return false;
402 386 return pluginWidget() && pluginWidget()->isPluginView() && toPluginView(plug inWidget())->supportsKeyboardFocus();
403 if (Widget* widget = existingPluginWidget())
404 return widget->isPluginView() && toPluginView(widget)->supportsKeyboardF ocus();
405
406 return false;
407 } 387 }
408 388
409 bool HTMLPlugInElement::hasCustomFocusLogic() const 389 bool HTMLPlugInElement::hasCustomFocusLogic() const
410 { 390 {
411 return !useFallbackContent() && !usePlaceholderContent(); 391 return !useFallbackContent();
412 } 392 }
413 393
414 bool HTMLPlugInElement::isPluginElement() const 394 bool HTMLPlugInElement::isPluginElement() const
415 { 395 {
416 return true; 396 return true;
417 } 397 }
418 398
419 bool HTMLPlugInElement::layoutObjectIsFocusable() const 399 bool HTMLPlugInElement::layoutObjectIsFocusable() const
420 { 400 {
421 if (HTMLFrameOwnerElement::supportsFocus() && HTMLFrameOwnerElement::layoutO bjectIsFocusable()) 401 if (HTMLFrameOwnerElement::supportsFocus() && HTMLFrameOwnerElement::layoutO bjectIsFocusable())
422 return true; 402 return true;
423 403
424 if (useFallbackContent() || !layoutObject() || !layoutObject()->isEmbeddedOb ject()) 404 if (useFallbackContent() || !layoutObject() || !layoutObject()->isEmbeddedOb ject())
425 return false; 405 return false;
426 return !toLayoutEmbeddedObject(layoutObject())->showsUnavailablePluginIndica tor(); 406 return !toLayoutEmbeddedObject(layoutObject())->showsUnavailablePluginIndica tor();
427 } 407 }
428 408
429 NPObject* HTMLPlugInElement::getNPObject() 409 NPObject* HTMLPlugInElement::getNPObject()
430 { 410 {
431 ASSERT(document().frame()); 411 ASSERT(document().frame());
432 if (!m_NPObject) 412 if (!m_NPObject)
433 m_NPObject = document().frame()->script().createScriptObjectForPluginEle ment(this); 413 m_NPObject = document().frame()->script().createScriptObjectForPluginEle ment(this);
434 return m_NPObject; 414 return m_NPObject;
435 } 415 }
436 416
437 void HTMLPlugInElement::setPluginFocus(bool focused) 417 void HTMLPlugInElement::setPluginFocus(bool focused)
438 { 418 {
439 Widget* focusedWidget = existingPluginWidget();
440 // NPAPI flash requires to receive messages when web contents focus changes. 419 // NPAPI flash requires to receive messages when web contents focus changes.
441 if (getNPObject() && focusedWidget) 420 if (getNPObject() && pluginWidget() && pluginWidget()->isPluginView())
tommycli 2015/08/25 00:18:10 Extra scrutiny here: This was added by this patch
jbroman 2015/08/25 00:34:10 Do we even still support NPAPI Flash? I'd suspect
442 focusedWidget->setFocus(focused, WebFocusTypeNone); 421 toPluginView(pluginWidget())->setFocus(focused, WebFocusTypeNone);
443 } 422 }
444 423
445 bool HTMLPlugInElement::isImageType() 424 bool HTMLPlugInElement::isImageType()
446 { 425 {
447 if (m_serviceType.isEmpty() && protocolIs(m_url, "data")) 426 if (m_serviceType.isEmpty() && protocolIs(m_url, "data"))
448 m_serviceType = mimeTypeFromDataURL(m_url); 427 m_serviceType = mimeTypeFromDataURL(m_url);
449 428
450 if (LocalFrame* frame = document().frame()) { 429 if (LocalFrame* frame = document().frame()) {
451 KURL completedURL = document().completeURL(m_url); 430 KURL completedURL = document().completeURL(m_url);
452 return frame->loader().client()->objectContentType(completedURL, m_servi ceType, shouldPreferPlugInsForImages()) == ObjectContentImage; 431 return frame->loader().client()->objectContentType(completedURL, m_servi ceType, shouldPreferPlugInsForImages()) == ObjectContentImage;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 497
519 LayoutEmbeddedObject* layoutObject = layoutEmbeddedObject(); 498 LayoutEmbeddedObject* layoutObject = layoutEmbeddedObject();
520 // FIXME: This code should not depend on layoutObject! 499 // FIXME: This code should not depend on layoutObject!
521 if ((!layoutObject && requireLayoutObject) || useFallback) 500 if ((!layoutObject && requireLayoutObject) || useFallback)
522 return false; 501 return false;
523 502
524 WTF_LOG(Plugins, "%p Plugin URL: %s", this, m_url.utf8().data()); 503 WTF_LOG(Plugins, "%p Plugin URL: %s", this, m_url.utf8().data());
525 WTF_LOG(Plugins, " Loaded URL: %s", url.string().utf8().data()); 504 WTF_LOG(Plugins, " Loaded URL: %s", url.string().utf8().data());
526 m_loadedUrl = url; 505 m_loadedUrl = url;
527 506
528 OwnPtrWillBeRawPtr<PluginPlaceholder> placeholder = nullptr;
529 RefPtrWillBeRawPtr<Widget> widget = m_persistedPluginWidget; 507 RefPtrWillBeRawPtr<Widget> widget = m_persistedPluginWidget;
530 if (!widget) { 508 if (!widget) {
531 bool loadManually = document().isPluginDocument() && !document().contain sPlugins(); 509 bool loadManually = document().isPluginDocument() && !document().contain sPlugins();
532 placeholder = frame->loader().client()->createPluginPlaceholder(document (), url, paramNames, paramValues, mimeType, loadManually); 510 FrameLoaderClient::DetachedPluginPolicy policy = requireLayoutObject ? F rameLoaderClient::FailOnDetachedPlugin : FrameLoaderClient::AllowDetachedPlugin;
533 if (!placeholder) { 511 widget = frame->loader().client()->createPlugin(this, url, paramNames, p aramValues, mimeType, loadManually, policy);
534 FrameLoaderClient::DetachedPluginPolicy policy = requireLayoutObject ? FrameLoaderClient::FailOnDetachedPlugin : FrameLoaderClient::AllowDetachedPlu gin;
535 widget = frame->loader().client()->createPlugin(this, url, paramName s, paramValues, mimeType, loadManually, policy);
536 }
537 } 512 }
538 513
539 if (!placeholder && !widget) { 514 if (!widget) {
540 if (layoutObject && !layoutObject->showsUnavailablePluginIndicator()) 515 if (layoutObject && !layoutObject->showsUnavailablePluginIndicator())
541 layoutObject->setPluginUnavailabilityReason(LayoutEmbeddedObject::Pl uginMissing); 516 layoutObject->setPluginUnavailabilityReason(LayoutEmbeddedObject::Pl uginMissing);
542 setPlaceholder(nullptr);
543 return false; 517 return false;
544 } 518 }
545 519
546 if (placeholder) {
547 setPlaceholder(placeholder.release());
548 return true;
549 }
550
551 if (layoutObject) { 520 if (layoutObject) {
552 setWidget(widget); 521 setWidget(widget);
553 setPersistedPluginWidget(nullptr); 522 setPersistedPluginWidget(nullptr);
554 } else { 523 } else {
555 setPersistedPluginWidget(widget.get()); 524 setPersistedPluginWidget(widget.get());
556 } 525 }
557 setPlaceholder(nullptr);
558 document().setContainsPlugins(); 526 document().setContainsPlugins();
559 // TODO(esprehn): WebPluginContainerImpl::setWebLayer also schedules a compo siting update, do we need both? 527 // TODO(esprehn): WebPluginContainerImpl::setWebLayer also schedules a compo siting update, do we need both?
560 setNeedsCompositingUpdate(); 528 setNeedsCompositingUpdate();
561 // Make sure any input event handlers introduced by the plugin are taken int o account. 529 // Make sure any input event handlers introduced by the plugin are taken int o account.
562 if (Page* page = document().frame()->page()) { 530 if (Page* page = document().frame()->page()) {
563 if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordina tor()) 531 if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordina tor())
564 scrollingCoordinator->notifyLayoutUpdated(); 532 scrollingCoordinator->notifyLayoutUpdated();
565 } 533 }
566 return true; 534 return true;
567 } 535 }
568 536
569 bool HTMLPlugInElement::shouldUsePlugin(const KURL& url, const String& mimeType, bool hasFallback, bool& useFallback) 537 bool HTMLPlugInElement::shouldUsePlugin(const KURL& url, const String& mimeType, bool hasFallback, bool& useFallback)
570 { 538 {
571 // Allow other plugins to win over QuickTime because if the user has 539 // Allow other plugins to win over QuickTime because if the user has
572 // installed a plugin that can handle TIFF (which QuickTime can also 540 // installed a plugin that can handle TIFF (which QuickTime can also
573 // handle) they probably intended to override QT. 541 // handle) they probably intended to override QT.
574 if (document().frame()->page() && (mimeType == "image/tiff" || mimeType == " image/tif" || mimeType == "image/x-tiff")) { 542 if (document().frame()->page() && (mimeType == "image/tiff" || mimeType == " image/tif" || mimeType == "image/x-tiff")) {
575 const PluginData* pluginData = document().frame()->page()->pluginData(); 543 const PluginData* pluginData = document().frame()->page()->pluginData();
576 String pluginName = pluginData ? pluginData->pluginNameForMimeType(mimeT ype) : String(); 544 String pluginName = pluginData ? pluginData->pluginNameForMimeType(mimeT ype) : String();
577 if (!pluginName.isEmpty() && !pluginName.contains("QuickTime", TextCaseI nsensitive)) 545 if (!pluginName.isEmpty() && !pluginName.contains("QuickTime", TextCaseI nsensitive))
578 return true; 546 return true;
579 } 547 }
580 548
581 ObjectContentType objectType = document().frame()->loader().client()->object ContentType(url, mimeType, shouldPreferPlugInsForImages()); 549 ObjectContentType objectType = document().frame()->loader().client()->object ContentType(url, mimeType, shouldPreferPlugInsForImages());
582 // If an object's content can't be handled and it has no fallback, let 550 // If an object's content can't be handled and it has no fallback, let
583 // it be handled as a plugin to show the broken plugin icon. 551 // it be handled as a plugin to show the broken plugin icon.
584 useFallback = objectType == ObjectContentNone && hasFallback; 552 useFallback = objectType == ObjectContentNone && hasFallback;
585 return objectType == ObjectContentNone || objectType == ObjectContentNetscap ePlugin || objectType == ObjectContentOtherPlugin; 553 return objectType == ObjectContentNone || objectType == ObjectContentNetscap ePlugin || objectType == ObjectContentOtherPlugin;
586 }
587 554
588 void HTMLPlugInElement::setPlaceholder(PassOwnPtrWillBeRawPtr<PluginPlaceholder> placeholder)
589 {
590 bool needsLazyReattach = (!placeholder) != (!m_placeholder);
591 if (placeholder) {
592 placeholder->loadIntoContainer(ensureUserAgentShadowRoot());
593 m_placeholder = placeholder;
594 } else {
595 ShadowRoot& shadowRoot = ensureUserAgentShadowRoot();
596 shadowRoot.removeChildren();
597 shadowRoot.appendChild(HTMLContentElement::create(document()));
598 m_placeholder.clear();
599 }
600 if (needsLazyReattach)
601 lazyReattachIfAttached();
602 } 555 }
603 556
604 void HTMLPlugInElement::dispatchErrorEvent() 557 void HTMLPlugInElement::dispatchErrorEvent()
605 { 558 {
606 if (document().isPluginDocument() && document().ownerElement()) 559 if (document().isPluginDocument() && document().ownerElement())
607 document().ownerElement()->dispatchEvent(Event::create(EventTypeNames::e rror)); 560 document().ownerElement()->dispatchEvent(Event::create(EventTypeNames::e rror));
608 else 561 else
609 dispatchEvent(Event::create(EventTypeNames::error)); 562 dispatchEvent(Event::create(EventTypeNames::error));
610 } 563 }
611 564
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 return false; 610 return false;
658 } 611 }
659 612
660 bool HTMLPlugInElement::useFallbackContent() const 613 bool HTMLPlugInElement::useFallbackContent() const
661 { 614 {
662 return openShadowRoot(); 615 return openShadowRoot();
663 } 616 }
664 617
665 void HTMLPlugInElement::lazyReattachIfNeeded() 618 void HTMLPlugInElement::lazyReattachIfNeeded()
666 { 619 {
667 if (!useFallbackContent() && !usePlaceholderContent() && needsWidgetUpdate() && layoutObject() && !isImageType()) 620 if (!useFallbackContent() && needsWidgetUpdate() && layoutObject() && !isIma geType())
668 lazyReattachIfAttached(); 621 lazyReattachIfAttached();
669 } 622 }
670 623
671 } 624 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698