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

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: merge origin/master Created 5 years, 3 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 // a LayoutEmbeddedObject or LayoutPart. 277 // a LayoutEmbeddedObject or LayoutPart.
282 if (useFallbackContent()) 278 if (useFallbackContent())
283 return LayoutObject::createObject(this, style); 279 return LayoutObject::createObject(this, style);
284 280
285 if (isImageType()) { 281 if (isImageType()) {
286 LayoutImage* image = new LayoutImage(this); 282 LayoutImage* image = new LayoutImage(this);
287 image->setImageResource(LayoutImageResource::create()); 283 image->setImageResource(LayoutImageResource::create());
288 return image; 284 return image;
289 } 285 }
290 286
291 if (usePlaceholderContent())
292 return new LayoutBlockFlow(this);
293 287
294 return new LayoutEmbeddedObject(this); 288 return new LayoutEmbeddedObject(this);
295 } 289 }
296 290
297 void HTMLPlugInElement::finishParsingChildren() 291 void HTMLPlugInElement::finishParsingChildren()
298 { 292 {
299 HTMLFrameOwnerElement::finishParsingChildren(); 293 HTMLFrameOwnerElement::finishParsingChildren();
300 if (useFallbackContent()) 294 if (useFallbackContent())
301 return; 295 return;
302 296
(...skipping 15 matching lines...) Expand all
318 312
319 // If the host dynamically turns off JavaScript (or Java) we will still 313 // If the host dynamically turns off JavaScript (or Java) we will still
320 // return the cached allocated Bindings::Instance. Not supporting this 314 // return the cached allocated Bindings::Instance. Not supporting this
321 // edge-case is OK. 315 // edge-case is OK.
322 if (!m_pluginWrapper) { 316 if (!m_pluginWrapper) {
323 Widget* plugin; 317 Widget* plugin;
324 318
325 if (m_persistedPluginWidget) 319 if (m_persistedPluginWidget)
326 plugin = m_persistedPluginWidget.get(); 320 plugin = m_persistedPluginWidget.get();
327 else 321 else
328 plugin = pluginWidgetForJSBindings(); 322 plugin = pluginWidget();
329 323
330 if (plugin) 324 if (plugin)
331 m_pluginWrapper = frame->script().createPluginWrapper(plugin); 325 m_pluginWrapper = frame->script().createPluginWrapper(plugin);
332 } 326 }
333 return m_pluginWrapper.get(); 327 return m_pluginWrapper.get();
334 } 328 }
335 329
336 Widget* HTMLPlugInElement::existingPluginWidget() const 330 Widget* HTMLPlugInElement::pluginWidget() const
337 {
338 if (LayoutPart* layoutPart = existingLayoutPart())
339 return layoutPart->widget();
340 return nullptr;
341 }
342
343 Widget* HTMLPlugInElement::pluginWidgetForJSBindings()
344 { 331 {
345 if (LayoutPart* layoutPart = layoutPartForJSBindings()) 332 if (LayoutPart* layoutPart = layoutPartForJSBindings())
346 return layoutPart->widget(); 333 return layoutPart->widget();
347 return nullptr; 334 return nullptr;
348 } 335 }
349 336
350 bool HTMLPlugInElement::isPresentationAttribute(const QualifiedName& name) const 337 bool HTMLPlugInElement::isPresentationAttribute(const QualifiedName& name) const
351 { 338 {
352 if (name == widthAttr || name == heightAttr || name == vspaceAttr || name == hspaceAttr || name == alignAttr) 339 if (name == widthAttr || name == heightAttr || name == vspaceAttr || name == hspaceAttr || name == alignAttr)
353 return true; 340 return true;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 { 392 {
406 // Needs to load the plugin immediatedly because this function is called 393 // Needs to load the plugin immediatedly because this function is called
407 // when JavaScript code accesses the plugin. 394 // when JavaScript code accesses the plugin.
408 // FIXME: Check if dispatching events here is safe. 395 // FIXME: Check if dispatching events here is safe.
409 document().updateLayoutIgnorePendingStylesheets(Document::RunPostLayoutTasks Synchronously); 396 document().updateLayoutIgnorePendingStylesheets(Document::RunPostLayoutTasks Synchronously);
410 return existingLayoutPart(); 397 return existingLayoutPart();
411 } 398 }
412 399
413 bool HTMLPlugInElement::isKeyboardFocusable() const 400 bool HTMLPlugInElement::isKeyboardFocusable() const
414 { 401 {
415 if (useFallbackContent() || usePlaceholderContent())
416 return HTMLElement::isKeyboardFocusable();
417
418 if (!document().isActive()) 402 if (!document().isActive())
419 return false; 403 return false;
420 404 return pluginWidget() && pluginWidget()->isPluginView() && toPluginView(plug inWidget())->supportsKeyboardFocus();
421 if (Widget* widget = existingPluginWidget())
422 return widget->isPluginView() && toPluginView(widget)->supportsKeyboardF ocus();
423
424 return false;
425 } 405 }
426 406
427 bool HTMLPlugInElement::hasCustomFocusLogic() const 407 bool HTMLPlugInElement::hasCustomFocusLogic() const
428 { 408 {
429 return !useFallbackContent() && !usePlaceholderContent(); 409 return !useFallbackContent();
430 } 410 }
431 411
432 bool HTMLPlugInElement::isPluginElement() const 412 bool HTMLPlugInElement::isPluginElement() const
433 { 413 {
434 return true; 414 return true;
435 } 415 }
436 416
437 bool HTMLPlugInElement::layoutObjectIsFocusable() const 417 bool HTMLPlugInElement::layoutObjectIsFocusable() const
438 { 418 {
439 if (HTMLFrameOwnerElement::supportsFocus() && HTMLFrameOwnerElement::layoutO bjectIsFocusable()) 419 if (HTMLFrameOwnerElement::supportsFocus() && HTMLFrameOwnerElement::layoutO bjectIsFocusable())
440 return true; 420 return true;
441 421
442 if (useFallbackContent() || !layoutObject() || !layoutObject()->isEmbeddedOb ject()) 422 if (useFallbackContent() || !layoutObject() || !layoutObject()->isEmbeddedOb ject())
443 return false; 423 return false;
444 return !toLayoutEmbeddedObject(layoutObject())->showsUnavailablePluginIndica tor(); 424 return !toLayoutEmbeddedObject(layoutObject())->showsUnavailablePluginIndica tor();
445 } 425 }
446 426
447 NPObject* HTMLPlugInElement::getNPObject() 427 NPObject* HTMLPlugInElement::getNPObject()
448 { 428 {
449 ASSERT(document().frame()); 429 ASSERT(document().frame());
450 if (!m_NPObject) 430 if (!m_NPObject)
451 m_NPObject = document().frame()->script().createScriptObjectForPluginEle ment(this); 431 m_NPObject = document().frame()->script().createScriptObjectForPluginEle ment(this);
452 return m_NPObject; 432 return m_NPObject;
453 } 433 }
454 434
455 void HTMLPlugInElement::setPluginFocus(bool focused) 435 void HTMLPlugInElement::setPluginFocus(bool focused)
456 { 436 {
457 Widget* focusedWidget = existingPluginWidget();
458 // NPAPI flash requires to receive messages when web contents focus changes. 437 // NPAPI flash requires to receive messages when web contents focus changes.
459 if (getNPObject() && focusedWidget) 438 if (getNPObject() && pluginWidget() && pluginWidget()->isPluginView())
460 focusedWidget->setFocus(focused, WebFocusTypeNone); 439 toPluginView(pluginWidget())->setFocus(focused, WebFocusTypeNone);
461 } 440 }
462 441
463 bool HTMLPlugInElement::isImageType() 442 bool HTMLPlugInElement::isImageType()
464 { 443 {
465 if (m_serviceType.isEmpty() && protocolIs(m_url, "data")) 444 if (m_serviceType.isEmpty() && protocolIs(m_url, "data"))
466 m_serviceType = mimeTypeFromDataURL(m_url); 445 m_serviceType = mimeTypeFromDataURL(m_url);
467 446
468 if (LocalFrame* frame = document().frame()) { 447 if (LocalFrame* frame = document().frame()) {
469 KURL completedURL = document().completeURL(m_url); 448 KURL completedURL = document().completeURL(m_url);
470 return frame->loader().client()->objectContentType(completedURL, m_servi ceType, shouldPreferPlugInsForImages()) == ObjectContentImage; 449 return frame->loader().client()->objectContentType(completedURL, m_servi ceType, shouldPreferPlugInsForImages()) == ObjectContentImage;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 515
537 LayoutEmbeddedObject* layoutObject = layoutEmbeddedObject(); 516 LayoutEmbeddedObject* layoutObject = layoutEmbeddedObject();
538 // FIXME: This code should not depend on layoutObject! 517 // FIXME: This code should not depend on layoutObject!
539 if ((!layoutObject && requireLayoutObject) || useFallback) 518 if ((!layoutObject && requireLayoutObject) || useFallback)
540 return false; 519 return false;
541 520
542 WTF_LOG(Plugins, "%p Plugin URL: %s", this, m_url.utf8().data()); 521 WTF_LOG(Plugins, "%p Plugin URL: %s", this, m_url.utf8().data());
543 WTF_LOG(Plugins, " Loaded URL: %s", url.string().utf8().data()); 522 WTF_LOG(Plugins, " Loaded URL: %s", url.string().utf8().data());
544 m_loadedUrl = url; 523 m_loadedUrl = url;
545 524
546 OwnPtrWillBeRawPtr<PluginPlaceholder> placeholder = nullptr;
547 RefPtrWillBeRawPtr<Widget> widget = m_persistedPluginWidget; 525 RefPtrWillBeRawPtr<Widget> widget = m_persistedPluginWidget;
548 if (!widget) { 526 if (!widget) {
549 bool loadManually = document().isPluginDocument() && !document().contain sPlugins(); 527 bool loadManually = document().isPluginDocument() && !document().contain sPlugins();
550 placeholder = frame->loader().client()->createPluginPlaceholder(document (), url, paramNames, paramValues, mimeType, loadManually); 528 FrameLoaderClient::DetachedPluginPolicy policy = requireLayoutObject ? F rameLoaderClient::FailOnDetachedPlugin : FrameLoaderClient::AllowDetachedPlugin;
551 if (!placeholder) { 529 widget = frame->loader().client()->createPlugin(this, url, paramNames, p aramValues, mimeType, loadManually, policy);
552 FrameLoaderClient::DetachedPluginPolicy policy = requireLayoutObject ? FrameLoaderClient::FailOnDetachedPlugin : FrameLoaderClient::AllowDetachedPlu gin;
553 widget = frame->loader().client()->createPlugin(this, url, paramName s, paramValues, mimeType, loadManually, policy);
554 }
555 } 530 }
556 531
557 if (!placeholder && !widget) { 532 if (!widget) {
558 if (layoutObject && !layoutObject->showsUnavailablePluginIndicator()) 533 if (layoutObject && !layoutObject->showsUnavailablePluginIndicator())
559 layoutObject->setPluginUnavailabilityReason(LayoutEmbeddedObject::Pl uginMissing); 534 layoutObject->setPluginUnavailabilityReason(LayoutEmbeddedObject::Pl uginMissing);
560 setPlaceholder(nullptr);
561 return false; 535 return false;
562 } 536 }
563 537
564 if (placeholder) {
565 setPlaceholder(placeholder.release());
566 return true;
567 }
568
569 if (layoutObject) { 538 if (layoutObject) {
570 setWidget(widget); 539 setWidget(widget);
571 setPersistedPluginWidget(nullptr); 540 setPersistedPluginWidget(nullptr);
572 } else { 541 } else {
573 setPersistedPluginWidget(widget.get()); 542 setPersistedPluginWidget(widget.get());
574 } 543 }
575 setPlaceholder(nullptr);
576 document().setContainsPlugins(); 544 document().setContainsPlugins();
577 // TODO(esprehn): WebPluginContainerImpl::setWebLayer also schedules a compo siting update, do we need both? 545 // TODO(esprehn): WebPluginContainerImpl::setWebLayer also schedules a compo siting update, do we need both?
578 setNeedsCompositingUpdate(); 546 setNeedsCompositingUpdate();
579 // Make sure any input event handlers introduced by the plugin are taken int o account. 547 // Make sure any input event handlers introduced by the plugin are taken int o account.
580 if (Page* page = document().frame()->page()) { 548 if (Page* page = document().frame()->page()) {
581 if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordina tor()) 549 if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordina tor())
582 scrollingCoordinator->notifyLayoutUpdated(); 550 scrollingCoordinator->notifyLayoutUpdated();
583 } 551 }
584 return true; 552 return true;
585 } 553 }
586 554
587 bool HTMLPlugInElement::shouldUsePlugin(const KURL& url, const String& mimeType, bool hasFallback, bool& useFallback) 555 bool HTMLPlugInElement::shouldUsePlugin(const KURL& url, const String& mimeType, bool hasFallback, bool& useFallback)
588 { 556 {
589 // Allow other plugins to win over QuickTime because if the user has 557 // Allow other plugins to win over QuickTime because if the user has
590 // installed a plugin that can handle TIFF (which QuickTime can also 558 // installed a plugin that can handle TIFF (which QuickTime can also
591 // handle) they probably intended to override QT. 559 // handle) they probably intended to override QT.
592 if (document().frame()->page() && (mimeType == "image/tiff" || mimeType == " image/tif" || mimeType == "image/x-tiff")) { 560 if (document().frame()->page() && (mimeType == "image/tiff" || mimeType == " image/tif" || mimeType == "image/x-tiff")) {
593 const PluginData* pluginData = document().frame()->page()->pluginData(); 561 const PluginData* pluginData = document().frame()->page()->pluginData();
594 String pluginName = pluginData ? pluginData->pluginNameForMimeType(mimeT ype) : String(); 562 String pluginName = pluginData ? pluginData->pluginNameForMimeType(mimeT ype) : String();
595 if (!pluginName.isEmpty() && !pluginName.contains("QuickTime", TextCaseI nsensitive)) 563 if (!pluginName.isEmpty() && !pluginName.contains("QuickTime", TextCaseI nsensitive))
596 return true; 564 return true;
597 } 565 }
598 566
599 ObjectContentType objectType = document().frame()->loader().client()->object ContentType(url, mimeType, shouldPreferPlugInsForImages()); 567 ObjectContentType objectType = document().frame()->loader().client()->object ContentType(url, mimeType, shouldPreferPlugInsForImages());
600 // If an object's content can't be handled and it has no fallback, let 568 // If an object's content can't be handled and it has no fallback, let
601 // it be handled as a plugin to show the broken plugin icon. 569 // it be handled as a plugin to show the broken plugin icon.
602 useFallback = objectType == ObjectContentNone && hasFallback; 570 useFallback = objectType == ObjectContentNone && hasFallback;
603 return objectType == ObjectContentNone || objectType == ObjectContentNetscap ePlugin || objectType == ObjectContentOtherPlugin; 571 return objectType == ObjectContentNone || objectType == ObjectContentNetscap ePlugin || objectType == ObjectContentOtherPlugin;
604 }
605 572
606 void HTMLPlugInElement::setPlaceholder(PassOwnPtrWillBeRawPtr<PluginPlaceholder> placeholder)
607 {
608 bool needsLazyReattach = (!placeholder) != (!m_placeholder);
609 if (placeholder) {
610 placeholder->loadIntoContainer(ensureUserAgentShadowRoot());
611 m_placeholder = placeholder;
612 } else {
613 ShadowRoot& shadowRoot = ensureUserAgentShadowRoot();
614 shadowRoot.removeChildren();
615 shadowRoot.appendChild(HTMLContentElement::create(document()));
616 m_placeholder.clear();
617 }
618 if (needsLazyReattach)
619 lazyReattachIfAttached();
620 } 573 }
621 574
622 void HTMLPlugInElement::dispatchErrorEvent() 575 void HTMLPlugInElement::dispatchErrorEvent()
623 { 576 {
624 if (document().isPluginDocument() && document().ownerElement()) 577 if (document().isPluginDocument() && document().ownerElement())
625 document().ownerElement()->dispatchEvent(Event::create(EventTypeNames::e rror)); 578 document().ownerElement()->dispatchEvent(Event::create(EventTypeNames::e rror));
626 else 579 else
627 dispatchEvent(Event::create(EventTypeNames::error)); 580 dispatchEvent(Event::create(EventTypeNames::error));
628 } 581 }
629 582
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 return false; 628 return false;
676 } 629 }
677 630
678 bool HTMLPlugInElement::useFallbackContent() const 631 bool HTMLPlugInElement::useFallbackContent() const
679 { 632 {
680 return openShadowRoot(); 633 return openShadowRoot();
681 } 634 }
682 635
683 void HTMLPlugInElement::lazyReattachIfNeeded() 636 void HTMLPlugInElement::lazyReattachIfNeeded()
684 { 637 {
685 if (!useFallbackContent() && !usePlaceholderContent() && needsWidgetUpdate() && layoutObject() && !isImageType()) 638 if (!useFallbackContent() && needsWidgetUpdate() && layoutObject() && !isIma geType())
686 lazyReattachIfAttached(); 639 lazyReattachIfAttached();
687 } 640 }
688 641
689 } 642 }
OLDNEW
« no previous file with comments | « Source/core/html/HTMLPlugInElement.h ('k') | Source/core/html/shadow/PluginPlaceholderElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698