Bug 883968. Give <object>/<embed>/<applet> channels notification callbacks that can actually be used from script. r=johns

This commit is contained in:
Boris Zbarsky 2013-06-19 10:24:37 -04:00
parent 550087fc0d
commit 52641f95fc
5 changed files with 39 additions and 11 deletions

View File

@ -1061,8 +1061,40 @@ nsObjectLoadingContent::GetContentTypeForMIMEType(const nsACString& aMIMEType,
}
// nsIInterfaceRequestor
// We use a shim class to implement this so that JS consumers still
// see an interface requestor even though WebIDL bindings don't expose
// that stuff.
class ObjectInterfaceRequestorShim MOZ_FINAL : public nsIInterfaceRequestor,
public nsIChannelEventSink
{
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(ObjectInterfaceRequestorShim,
nsIInterfaceRequestor)
NS_DECL_NSIINTERFACEREQUESTOR
NS_FORWARD_NSICHANNELEVENTSINK(mContent->)
ObjectInterfaceRequestorShim(nsIChannelEventSink* aContent)
: mContent(aContent)
{}
protected:
nsRefPtr<nsIChannelEventSink> mContent;
};
NS_IMPL_CYCLE_COLLECTION_1(ObjectInterfaceRequestorShim, mContent)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ObjectInterfaceRequestorShim)
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
NS_INTERFACE_MAP_ENTRY(nsIChannelEventSink)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIInterfaceRequestor)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(ObjectInterfaceRequestorShim)
NS_IMPL_CYCLE_COLLECTING_RELEASE(ObjectInterfaceRequestorShim)
NS_IMETHODIMP
nsObjectLoadingContent::GetInterface(const nsIID & aIID, void **aResult)
ObjectInterfaceRequestorShim::GetInterface(const nsIID & aIID, void **aResult)
{
if (aIID.Equals(NS_GET_IID(nsIChannelEventSink))) {
nsIChannelEventSink* sink = this;
@ -2079,7 +2111,9 @@ nsObjectLoadingContent::OpenChannel()
channelPolicy->SetContentSecurityPolicy(csp);
channelPolicy->SetLoadType(nsIContentPolicy::TYPE_OBJECT);
}
rv = NS_NewChannel(getter_AddRefs(chan), mURI, nullptr, group, this,
nsRefPtr<ObjectInterfaceRequestorShim> shim =
new ObjectInterfaceRequestorShim(this);
rv = NS_NewChannel(getter_AddRefs(chan), mURI, nullptr, group, shim,
nsIChannel::LOAD_CALL_CONTENT_SNIFFERS |
nsIChannel::LOAD_CLASSIFY_URI,
channelPolicy);

View File

@ -16,7 +16,6 @@
#include "mozilla/Attributes.h"
#include "nsImageLoadingContent.h"
#include "nsIStreamListener.h"
#include "nsIInterfaceRequestor.h"
#include "nsIChannelEventSink.h"
#include "nsIObjectLoadingContent.h"
#include "nsIRunnable.h"
@ -36,7 +35,6 @@ class nsObjectLoadingContent : public nsImageLoadingContent
, public nsIStreamListener
, public nsIFrameLoaderOwner
, public nsIObjectLoadingContent
, public nsIInterfaceRequestor
, public nsIChannelEventSink
{
friend class AutoSetInstantiatingToFalse;
@ -100,7 +98,6 @@ class nsObjectLoadingContent : public nsImageLoadingContent
NS_DECL_NSISTREAMLISTENER
NS_DECL_NSIFRAMELOADEROWNER
NS_DECL_NSIOBJECTLOADINGCONTENT
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSICHANNELEVENTSINK
/**

View File

@ -80,7 +80,7 @@ NS_IMPL_RELEASE_INHERITED(HTMLObjectElement, Element)
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(HTMLObjectElement)
NS_HTML_CONTENT_INTERFACES(nsGenericHTMLFormElement)
NS_INTERFACE_TABLE_INHERITED11(HTMLObjectElement,
NS_INTERFACE_TABLE_INHERITED10(HTMLObjectElement,
nsIDOMHTMLObjectElement,
imgINotificationObserver,
nsIRequestObserver,
@ -89,7 +89,6 @@ NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(HTMLObjectElement)
nsIObjectLoadingContent,
nsIImageLoadingContent,
imgIOnloadBlocker,
nsIInterfaceRequestor,
nsIChannelEventSink,
nsIConstraintValidation)
NS_INTERFACE_TABLE_TO_MAP_SEGUE

View File

@ -93,7 +93,7 @@ NS_IMPL_RELEASE_INHERITED(HTMLSharedObjectElement, Element)
NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(HTMLSharedObjectElement)
NS_HTML_CONTENT_INTERFACES_AMBIGUOUS(nsGenericHTMLElement,
nsIDOMHTMLAppletElement)
NS_INTERFACE_TABLE_INHERITED9(HTMLSharedObjectElement,
NS_INTERFACE_TABLE_INHERITED8(HTMLSharedObjectElement,
nsIRequestObserver,
nsIStreamListener,
nsIFrameLoaderOwner,
@ -101,7 +101,6 @@ NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(HTMLSharedObjectElement)
imgINotificationObserver,
nsIImageLoadingContent,
imgIOnloadBlocker,
nsIInterfaceRequestor,
nsIChannelEventSink)
NS_INTERFACE_TABLE_TO_MAP_SEGUE
NS_INTERFACE_MAP_ENTRY_IF_TAG(nsIDOMHTMLAppletElement, applet)

View File

@ -72,8 +72,7 @@ function HTML_TAG(aTagName, aImplClass) {
const objectIfaces = [
"imgINotificationObserver", "nsIRequestObserver", "nsIStreamListener",
"nsIFrameLoaderOwner", "nsIObjectLoadingContent", "nsIInterfaceRequestor",
"nsIChannelEventSink"
"nsIFrameLoaderOwner", "nsIObjectLoadingContent", "nsIChannelEventSink"
];
var objectIfaces2 = [];