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

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

Issue 1645313002: Don't apply the SandboxPlugins flag until we know a plugin will be used (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pluginIsLoadable returns Created 4 years, 10 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 20 matching lines...) Expand all
31 #include "core/dom/shadow/ShadowRoot.h" 31 #include "core/dom/shadow/ShadowRoot.h"
32 #include "core/events/Event.h" 32 #include "core/events/Event.h"
33 #include "core/frame/FrameView.h" 33 #include "core/frame/FrameView.h"
34 #include "core/frame/LocalFrame.h" 34 #include "core/frame/LocalFrame.h"
35 #include "core/frame/Settings.h" 35 #include "core/frame/Settings.h"
36 #include "core/frame/csp/ContentSecurityPolicy.h" 36 #include "core/frame/csp/ContentSecurityPolicy.h"
37 #include "core/html/HTMLContentElement.h" 37 #include "core/html/HTMLContentElement.h"
38 #include "core/html/HTMLImageLoader.h" 38 #include "core/html/HTMLImageLoader.h"
39 #include "core/html/PluginDocument.h" 39 #include "core/html/PluginDocument.h"
40 #include "core/input/EventHandler.h" 40 #include "core/input/EventHandler.h"
41 #include "core/inspector/ConsoleMessage.h"
41 #include "core/layout/LayoutBlockFlow.h" 42 #include "core/layout/LayoutBlockFlow.h"
42 #include "core/layout/LayoutEmbeddedObject.h" 43 #include "core/layout/LayoutEmbeddedObject.h"
43 #include "core/layout/LayoutImage.h" 44 #include "core/layout/LayoutImage.h"
44 #include "core/layout/LayoutPart.h" 45 #include "core/layout/LayoutPart.h"
45 #include "core/loader/FrameLoaderClient.h" 46 #include "core/loader/FrameLoaderClient.h"
46 #include "core/loader/MixedContentChecker.h" 47 #include "core/loader/MixedContentChecker.h"
47 #include "core/page/Page.h" 48 #include "core/page/Page.h"
48 #include "core/page/scrolling/ScrollingCoordinator.h" 49 #include "core/page/scrolling/ScrollingCoordinator.h"
49 #include "core/plugins/PluginView.h" 50 #include "core/plugins/PluginView.h"
50 #include "platform/Logging.h" 51 #include "platform/Logging.h"
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 468
468 bool HTMLPlugInElement::requestObject(const String& url, const String& mimeType, const Vector<String>& paramNames, const Vector<String>& paramValues) 469 bool HTMLPlugInElement::requestObject(const String& url, const String& mimeType, const Vector<String>& paramNames, const Vector<String>& paramValues)
469 { 470 {
470 if (url.isEmpty() && mimeType.isEmpty()) 471 if (url.isEmpty() && mimeType.isEmpty())
471 return false; 472 return false;
472 473
473 if (protocolIsJavaScript(url)) 474 if (protocolIsJavaScript(url))
474 return false; 475 return false;
475 476
476 KURL completedURL = url.isEmpty() ? KURL() : document().completeURL(url); 477 KURL completedURL = url.isEmpty() ? KURL() : document().completeURL(url);
477 if (!pluginIsLoadable(completedURL, mimeType)) 478 if (!objectIsLoadable(completedURL, mimeType))
478 return false; 479 return false;
479 480
480 bool useFallback; 481 bool useFallback;
481 if (shouldUsePlugin(completedURL, mimeType, hasFallbackContent(), useFallbac k)) 482 if (shouldUsePlugin(completedURL, mimeType, hasFallbackContent(), useFallbac k)) {
483 if (!pluginIsLoadable(completedURL, mimeType))
484 return false;
482 return loadPlugin(completedURL, mimeType, paramNames, paramValues, useFa llback, true); 485 return loadPlugin(completedURL, mimeType, paramNames, paramValues, useFa llback, true);
486 }
483 487
484 // If the plugin element already contains a subframe, 488 // If the plugin element already contains a subframe,
485 // loadOrRedirectSubframe will re-use it. Otherwise, it will create a new 489 // loadOrRedirectSubframe will re-use it. Otherwise, it will create a new
486 // frame and set it as the LayoutPart's widget, causing what was previously 490 // frame and set it as the LayoutPart's widget, causing what was previously
487 // in the widget to be torn down. 491 // in the widget to be torn down.
488 return loadOrRedirectSubframe(completedURL, getNameAttribute(), true); 492 return loadOrRedirectSubframe(completedURL, getNameAttribute(), true);
489 } 493 }
490 494
491 bool HTMLPlugInElement::loadPlugin(const KURL& url, const String& mimeType, cons t Vector<String>& paramNames, const Vector<String>& paramValues, bool useFallbac k, bool requireLayoutObject) 495 bool HTMLPlugInElement::loadPlugin(const KURL& url, const String& mimeType, cons t Vector<String>& paramNames, const Vector<String>& paramValues, bool useFallbac k, bool requireLayoutObject)
492 { 496 {
pdr. 2016/02/02 04:32:42 Can you assert both objectIsLoadable and pluginIsL
fs 2016/02/22 18:36:56 In the latest PS I've sunk the latter (or its rena
493 LocalFrame* frame = document().frame(); 497 LocalFrame* frame = document().frame();
494 498
495 if (!frame->loader().allowPlugins(AboutToInstantiatePlugin)) 499 if (!frame->loader().allowPlugins(AboutToInstantiatePlugin))
496 return false; 500 return false;
497 501
498 LayoutEmbeddedObject* layoutObject = layoutEmbeddedObject(); 502 LayoutEmbeddedObject* layoutObject = layoutEmbeddedObject();
499 // FIXME: This code should not depend on layoutObject! 503 // FIXME: This code should not depend on layoutObject!
500 if ((!layoutObject && requireLayoutObject) || useFallback) 504 if ((!layoutObject && requireLayoutObject) || useFallback)
501 return false; 505 return false;
502 506
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 } 538 }
535 539
536 bool HTMLPlugInElement::shouldUsePlugin(const KURL& url, const String& mimeType, bool hasFallback, bool& useFallback) 540 bool HTMLPlugInElement::shouldUsePlugin(const KURL& url, const String& mimeType, bool hasFallback, bool& useFallback)
537 { 541 {
538 // Allow other plugins to win over QuickTime because if the user has 542 // Allow other plugins to win over QuickTime because if the user has
539 // installed a plugin that can handle TIFF (which QuickTime can also 543 // installed a plugin that can handle TIFF (which QuickTime can also
540 // handle) they probably intended to override QT. 544 // handle) they probably intended to override QT.
541 if (document().frame()->page() && (mimeType == "image/tiff" || mimeType == " image/tif" || mimeType == "image/x-tiff")) { 545 if (document().frame()->page() && (mimeType == "image/tiff" || mimeType == " image/tif" || mimeType == "image/x-tiff")) {
542 const PluginData* pluginData = document().frame()->page()->pluginData(); 546 const PluginData* pluginData = document().frame()->page()->pluginData();
543 String pluginName = pluginData ? pluginData->pluginNameForMimeType(mimeT ype) : String(); 547 String pluginName = pluginData ? pluginData->pluginNameForMimeType(mimeT ype) : String();
544 if (!pluginName.isEmpty() && !pluginName.contains("QuickTime", TextCaseI nsensitive)) 548 if (!pluginName.isEmpty() && !pluginName.contains("QuickTime", TextCaseI nsensitive)) {
549 useFallback = false;
545 return true; 550 return true;
551 }
546 } 552 }
547 553
548 ObjectContentType objectType = document().frame()->loader().client()->object ContentType(url, mimeType, shouldPreferPlugInsForImages()); 554 ObjectContentType objectType = document().frame()->loader().client()->object ContentType(url, mimeType, shouldPreferPlugInsForImages());
549 // If an object's content can't be handled and it has no fallback, let 555 // If an object's content can't be handled and it has no fallback, let
550 // it be handled as a plugin to show the broken plugin icon. 556 // it be handled as a plugin to show the broken plugin icon.
551 useFallback = objectType == ObjectContentNone && hasFallback; 557 useFallback = objectType == ObjectContentNone && hasFallback;
552 return objectType == ObjectContentNone || objectType == ObjectContentNetscap ePlugin || objectType == ObjectContentOtherPlugin; 558 return objectType == ObjectContentNone || objectType == ObjectContentNetscap ePlugin || objectType == ObjectContentOtherPlugin;
553 559
554 } 560 }
555 561
556 void HTMLPlugInElement::dispatchErrorEvent() 562 void HTMLPlugInElement::dispatchErrorEvent()
557 { 563 {
558 if (document().isPluginDocument() && document().ownerElement()) 564 if (document().isPluginDocument() && document().ownerElement())
559 document().ownerElement()->dispatchEvent(Event::create(EventTypeNames::e rror)); 565 document().ownerElement()->dispatchEvent(Event::create(EventTypeNames::e rror));
560 else 566 else
561 dispatchEvent(Event::create(EventTypeNames::error)); 567 dispatchEvent(Event::create(EventTypeNames::error));
562 } 568 }
563 569
564 bool HTMLPlugInElement::pluginIsLoadable(const KURL& url, const String& mimeType ) 570 bool HTMLPlugInElement::objectIsLoadable(const KURL& url, const String& mimeType )
565 { 571 {
566 if (url.isEmpty() && mimeType.isEmpty()) 572 if (url.isEmpty() && mimeType.isEmpty())
567 return false; 573 return false;
568 574
569 LocalFrame* frame = document().frame(); 575 LocalFrame* frame = document().frame();
570 Settings* settings = frame->settings(); 576 Settings* settings = frame->settings();
571 if (!settings) 577 if (!settings)
572 return false; 578 return false;
573 579
574 if (MIMETypeRegistry::isJavaAppletMIMEType(mimeType)) 580 if (MIMETypeRegistry::isJavaAppletMIMEType(mimeType))
575 return false; 581 return false;
576 582
577 if (document().isSandboxed(SandboxPlugins))
578 return false;
579
580 if (!document().securityOrigin()->canDisplay(url)) { 583 if (!document().securityOrigin()->canDisplay(url)) {
581 FrameLoader::reportLocalLoadFailed(frame, url.string()); 584 FrameLoader::reportLocalLoadFailed(frame, url.string());
582 return false; 585 return false;
583 } 586 }
584 587
585 AtomicString declaredMimeType = document().isPluginDocument() && document(). ownerElement() ? 588 if (!document().contentSecurityPolicy()->allowObjectFromSource(url)) {
586 document().ownerElement()->fastGetAttribute(HTMLNames::typeAttr) :
587 fastGetAttribute(HTMLNames::typeAttr);
588 if (!document().contentSecurityPolicy()->allowObjectFromSource(url)
589 || !document().contentSecurityPolicy()->allowPluginTypeForDocument(docum ent(), mimeType, declaredMimeType, url)) {
590 layoutEmbeddedObject()->setPluginUnavailabilityReason(LayoutEmbeddedObje ct::PluginBlockedByContentSecurityPolicy); 589 layoutEmbeddedObject()->setPluginUnavailabilityReason(LayoutEmbeddedObje ct::PluginBlockedByContentSecurityPolicy);
591 return false; 590 return false;
592 } 591 }
593 592
594 return (!mimeType.isEmpty() && url.isEmpty()) || !MixedContentChecker::shoul dBlockFetch(frame, WebURLRequest::RequestContextObject, WebURLRequest::FrameType None, url); 593 return (!mimeType.isEmpty() && url.isEmpty()) || !MixedContentChecker::shoul dBlockFetch(frame, WebURLRequest::RequestContextObject, WebURLRequest::FrameType None, url);
595 } 594 }
596 595
596 bool HTMLPlugInElement::pluginIsLoadable(const KURL& url, const String& mimeType )
597 {
pdr. 2016/02/02 04:32:42 Can you add an assert here so future refactorings
fs 2016/02/22 18:36:56 Done.
598 if (document().isSandboxed(SandboxPlugins)) {
599 document().addConsoleMessage(ConsoleMessage::create(SecurityMessageSourc e, ErrorMessageLevel,
600 "Failed to load '" + url.elidedString() + "' as a plugin, because th e frame into which the plugin is loading is sandboxed."));
601 return false;
602 }
603
604 AtomicString declaredMimeType = document().isPluginDocument() && document(). ownerElement() ?
605 document().ownerElement()->fastGetAttribute(HTMLNames::typeAttr) :
606 fastGetAttribute(HTMLNames::typeAttr);
607 if (!document().contentSecurityPolicy()->allowPluginTypeForDocument(document (), mimeType, declaredMimeType, url)) {
608 layoutEmbeddedObject()->setPluginUnavailabilityReason(LayoutEmbeddedObje ct::PluginBlockedByContentSecurityPolicy);
609 return false;
610 }
611 return true;
612 }
613
597 void HTMLPlugInElement::didAddUserAgentShadowRoot(ShadowRoot&) 614 void HTMLPlugInElement::didAddUserAgentShadowRoot(ShadowRoot&)
598 { 615 {
599 userAgentShadowRoot()->appendChild(HTMLContentElement::create(document())); 616 userAgentShadowRoot()->appendChild(HTMLContentElement::create(document()));
600 } 617 }
601 618
602 void HTMLPlugInElement::willAddFirstAuthorShadowRoot() 619 void HTMLPlugInElement::willAddFirstAuthorShadowRoot()
603 { 620 {
604 lazyReattachIfAttached(); 621 lazyReattachIfAttached();
605 } 622 }
606 623
607 bool HTMLPlugInElement::hasFallbackContent() const 624 bool HTMLPlugInElement::hasFallbackContent() const
608 { 625 {
609 return false; 626 return false;
610 } 627 }
611 628
612 bool HTMLPlugInElement::useFallbackContent() const 629 bool HTMLPlugInElement::useFallbackContent() const
613 { 630 {
614 return openShadowRoot(); 631 return openShadowRoot();
615 } 632 }
616 633
617 void HTMLPlugInElement::lazyReattachIfNeeded() 634 void HTMLPlugInElement::lazyReattachIfNeeded()
618 { 635 {
619 if (!useFallbackContent() && needsWidgetUpdate() && layoutObject() && !isIma geType()) 636 if (!useFallbackContent() && needsWidgetUpdate() && layoutObject() && !isIma geType())
620 lazyReattachIfAttached(); 637 lazyReattachIfAttached();
621 } 638 }
622 639
623 } // namespace blink 640 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698