зеркало из https://github.com/mozilla/gecko-dev.git
Bug 403168, r=jonas, sr=jst, a=blocking1.9
This commit is contained in:
Родитель
42c91579a7
Коммит
7b08ddd398
|
@ -57,6 +57,8 @@
|
|||
#include "nsContentUtils.h"
|
||||
#include "nsDOMJSUtils.h"
|
||||
#include "nsDOMError.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
|
||||
// nsIDOMEventListener
|
||||
nsresult
|
||||
|
@ -426,7 +428,7 @@ GetInitArgs(JSContext *cx, PRUint32 argc, jsval *argv,
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMParser::Initialize(JSContext *cx, JSObject* obj,
|
||||
nsDOMParser::Initialize(nsISupports* aOwner, JSContext* cx, JSObject* obj,
|
||||
PRUint32 argc, jsval *argv)
|
||||
{
|
||||
AttemptedInitMarker marker(&mAttemptedInit);
|
||||
|
@ -463,9 +465,14 @@ nsDOMParser::Initialize(JSContext *cx, JSObject* obj,
|
|||
// Also note that |cx| matches what GetDocumentFromContext() would return,
|
||||
// while GetDocumentFromCaller() gives us the window that the DOMParser()
|
||||
// call was made on.
|
||||
|
||||
nsCOMPtr<nsIDocument> doc =
|
||||
do_QueryInterface(nsContentUtils::GetDocumentFromCaller());
|
||||
|
||||
nsCOMPtr<nsIDocument> doc;
|
||||
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aOwner);
|
||||
if (aOwner) {
|
||||
nsCOMPtr<nsIDOMDocument> domdoc = window->GetExtantDocument();
|
||||
doc = do_QueryInterface(domdoc);
|
||||
}
|
||||
|
||||
if (!doc) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
@ -474,9 +481,8 @@ nsDOMParser::Initialize(JSContext *cx, JSObject* obj,
|
|||
documentURI = doc->GetDocumentURI();
|
||||
}
|
||||
|
||||
nsIScriptContext* scriptContext = GetScriptContextFromJSContext(cx);
|
||||
return Init(prin, documentURI, baseURI,
|
||||
scriptContext ? scriptContext->GetGlobalObject() : nsnull);
|
||||
nsCOMPtr<nsIScriptGlobalObject> scriptglobal = do_QueryInterface(aOwner);
|
||||
return Init(prin, documentURI, baseURI, scriptglobal);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -74,7 +74,7 @@ public:
|
|||
NS_IMETHOD Error(nsIDOMEvent* aEvent);
|
||||
|
||||
// nsIJSNativeInitializer
|
||||
NS_IMETHOD Initialize(JSContext *cx, JSObject *obj,
|
||||
NS_IMETHOD Initialize(nsISupports* aOwner, JSContext* cx, JSObject* obj,
|
||||
PRUint32 argc, jsval *argv);
|
||||
|
||||
private:
|
||||
|
|
|
@ -2585,6 +2585,7 @@ nsDocument::GetScriptHandlingObject(PRBool& aHasHadScriptHandlingObject) const
|
|||
do_QueryReferent(mScriptObject);
|
||||
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(scriptHandlingObject);
|
||||
if (win) {
|
||||
NS_ASSERTION(win->IsInnerWindow(), "Should have inner window here!");
|
||||
nsPIDOMWindow* outer = win->GetOuterWindow();
|
||||
if (!outer || outer->GetCurrentInnerWindow() != win) {
|
||||
NS_WARNING("Wrong inner/outer window combination!");
|
||||
|
@ -2599,6 +2600,8 @@ nsDocument::SetScriptHandlingObject(nsIScriptGlobalObject* aScriptObject)
|
|||
NS_ASSERTION(!mScriptGlobalObject ||
|
||||
mScriptGlobalObject == aScriptObject,
|
||||
"Wrong script object!");
|
||||
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(aScriptObject);
|
||||
NS_ASSERTION(!win || win->IsInnerWindow(), "Should have inner window here!");
|
||||
mScriptObject = do_GetWeakReference(aScriptObject);
|
||||
if (aScriptObject) {
|
||||
mHasHadScriptHandlingObject = PR_TRUE;
|
||||
|
|
|
@ -89,6 +89,7 @@
|
|||
#include "nsIHTMLDocument.h"
|
||||
#include "nsWhitespaceTokenizer.h"
|
||||
#include "nsIMultiPartChannel.h"
|
||||
#include "nsIScriptObjectPrincipal.h"
|
||||
|
||||
#define LOAD_STR "load"
|
||||
#define ERROR_STR "error"
|
||||
|
@ -338,27 +339,6 @@ nsACProxyListener::GetInterface(const nsIID & aIID, void **aResult)
|
|||
return QueryInterface(aIID, aResult);
|
||||
}
|
||||
|
||||
|
||||
static nsIScriptContext *
|
||||
GetCurrentContext()
|
||||
{
|
||||
// Get JSContext from stack.
|
||||
nsCOMPtr<nsIJSContextStack> stack =
|
||||
do_GetService("@mozilla.org/js/xpc/ContextStack;1");
|
||||
|
||||
if (!stack) {
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
JSContext *cx;
|
||||
|
||||
if (NS_FAILED(stack->Peek(&cx)) || !cx) {
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
return GetScriptContextFromJSContext(cx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the nsIDocument given the script context. Will return nsnull on failure.
|
||||
*
|
||||
|
@ -412,6 +392,68 @@ nsXMLHttpRequest::~nsXMLHttpRequest()
|
|||
nsLayoutStatics::Release();
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsXMLHttpRequest::Init()
|
||||
{
|
||||
// Set the original mScriptContext and mPrincipal, if available.
|
||||
// Get JSContext from stack.
|
||||
nsCOMPtr<nsIJSContextStack> stack =
|
||||
do_GetService("@mozilla.org/js/xpc/ContextStack;1");
|
||||
|
||||
if (!stack) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
JSContext *cx;
|
||||
|
||||
if (NS_FAILED(stack->Peek(&cx)) || !cx) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIScriptContext* context = GetScriptContextFromJSContext(cx);
|
||||
if (!context) {
|
||||
return NS_OK;
|
||||
}
|
||||
nsIScriptSecurityManager *secMan = nsContentUtils::GetSecurityManager();
|
||||
nsCOMPtr<nsIPrincipal> subjectPrincipal;
|
||||
if (secMan) {
|
||||
secMan->GetSubjectPrincipal(getter_AddRefs(subjectPrincipal));
|
||||
}
|
||||
NS_ENSURE_STATE(subjectPrincipal);
|
||||
|
||||
mScriptContext = context;
|
||||
mPrincipal = subjectPrincipal;
|
||||
nsCOMPtr<nsPIDOMWindow> window =
|
||||
do_QueryInterface(context->GetGlobalObject());
|
||||
if (window) {
|
||||
mOwner = window->GetCurrentInnerWindow();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsXMLHttpRequest::Initialize(nsISupports* aOwner, JSContext* cx, JSObject* obj,
|
||||
PRUint32 argc, jsval *argv)
|
||||
{
|
||||
mOwner = do_QueryInterface(aOwner);
|
||||
if (!mOwner) {
|
||||
NS_WARNING("Unexpected nsIJSNativeInitializer owner");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// This XHR object is bound to a |window|,
|
||||
// so re-set principal and script context.
|
||||
nsCOMPtr<nsIScriptObjectPrincipal> scriptPrincipal = do_QueryInterface(aOwner);
|
||||
NS_ENSURE_STATE(scriptPrincipal);
|
||||
mPrincipal = scriptPrincipal->GetPrincipal();
|
||||
nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(aOwner);
|
||||
NS_ENSURE_STATE(sgo);
|
||||
mScriptContext = sgo->GetContext();
|
||||
NS_ENSURE_STATE(mScriptContext);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(nsXMLHttpRequest)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXMLHttpRequest)
|
||||
|
@ -436,6 +478,8 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsXMLHttpRequest)
|
|||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mChannelEventSink)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mProgressEventSink)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOwner)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
|
||||
|
@ -461,6 +505,8 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsXMLHttpRequest)
|
|||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mChannelEventSink)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mProgressEventSink)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOwner)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
|
||||
|
@ -477,6 +523,7 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsXMLHttpRequest)
|
|||
NS_INTERFACE_MAP_ENTRY(nsIProgressEventSink)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIJSNativeInitializer)
|
||||
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(XMLHttpRequest)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
|
@ -512,8 +559,6 @@ nsXMLHttpRequest::AddEventListener(const nsAString& type,
|
|||
|
||||
array->AppendObject(listener);
|
||||
|
||||
mScriptContext = GetCurrentContext();
|
||||
|
||||
#undef IMPL_ADD_LISTENER
|
||||
|
||||
return NS_OK;
|
||||
|
@ -578,9 +623,6 @@ NS_IMETHODIMP
|
|||
nsXMLHttpRequest::SetOnreadystatechange(nsIDOMEventListener * aOnreadystatechange)
|
||||
{
|
||||
mOnReadystatechangeListener = aOnreadystatechange;
|
||||
|
||||
mScriptContext = GetCurrentContext();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -600,9 +642,6 @@ NS_IMETHODIMP
|
|||
nsXMLHttpRequest::SetOnload(nsIDOMEventListener * aOnLoad)
|
||||
{
|
||||
mOnLoadListener = aOnLoad;
|
||||
|
||||
mScriptContext = GetCurrentContext();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -621,9 +660,6 @@ NS_IMETHODIMP
|
|||
nsXMLHttpRequest::SetOnerror(nsIDOMEventListener * aOnerror)
|
||||
{
|
||||
mOnErrorListener = aOnerror;
|
||||
|
||||
mScriptContext = GetCurrentContext();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -642,9 +678,6 @@ NS_IMETHODIMP
|
|||
nsXMLHttpRequest::SetOnprogress(nsIDOMEventListener * aOnprogress)
|
||||
{
|
||||
mOnProgressListener = aOnprogress;
|
||||
|
||||
mScriptContext = GetCurrentContext();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -663,9 +696,6 @@ NS_IMETHODIMP
|
|||
nsXMLHttpRequest::SetOnuploadprogress(nsIDOMEventListener * aOnuploadprogress)
|
||||
{
|
||||
mOnUploadProgressListener = aOnuploadprogress;
|
||||
|
||||
mScriptContext = GetCurrentContext();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -983,10 +1013,6 @@ nsXMLHttpRequest::GetLoadGroup(nsILoadGroup **aLoadGroup)
|
|||
NS_ENSURE_ARG_POINTER(aLoadGroup);
|
||||
*aLoadGroup = nsnull;
|
||||
|
||||
if (!mScriptContext) {
|
||||
mScriptContext = GetCurrentContext();
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocument> doc = GetDocumentFromScriptContext(mScriptContext);
|
||||
if (doc) {
|
||||
*aLoadGroup = doc->GetDocumentLoadGroup().get(); // already_AddRefed
|
||||
|
@ -999,10 +1025,7 @@ nsIURI *
|
|||
nsXMLHttpRequest::GetBaseURI()
|
||||
{
|
||||
if (!mScriptContext) {
|
||||
mScriptContext = GetCurrentContext();
|
||||
if (!mScriptContext) {
|
||||
return nsnull;
|
||||
}
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocument> doc = GetDocumentFromScriptContext(mScriptContext);
|
||||
|
@ -1067,6 +1090,10 @@ nsXMLHttpRequest::NotifyEventListeners(const nsCOMArray<nsIDOMEventListener>& aL
|
|||
nsCOMPtr<nsIJSContextStack> stack;
|
||||
JSContext *cx = nsnull;
|
||||
|
||||
if (NS_FAILED(CheckInnerWindowCorrectness())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mScriptContext) {
|
||||
stack = do_GetService("@mozilla.org/js/xpc/ContextStack;1");
|
||||
|
||||
|
@ -1209,20 +1236,6 @@ nsXMLHttpRequest::OpenRequest(const nsACString& method,
|
|||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
// Get the principal.
|
||||
// XXX This should be done at construction time.
|
||||
nsCOMPtr<nsIDocument> doc =
|
||||
do_QueryInterface(nsContentUtils::GetDocumentFromCaller());
|
||||
if (doc) {
|
||||
mPrincipal = doc->NodePrincipal();
|
||||
}
|
||||
else {
|
||||
nsIScriptSecurityManager *secMan = nsContentUtils::GetSecurityManager();
|
||||
if (secMan) {
|
||||
secMan->GetSubjectPrincipal(getter_AddRefs(mPrincipal));
|
||||
}
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
PRBool authp = PR_FALSE;
|
||||
|
@ -1262,11 +1275,13 @@ nsXMLHttpRequest::OpenRequest(const nsACString& method,
|
|||
|
||||
// mScriptContext should be initialized because of GetBaseURI() above.
|
||||
// Still need to consider the case that doc is nsnull however.
|
||||
doc = GetDocumentFromScriptContext(mScriptContext);
|
||||
rv = CheckInnerWindowCorrectness();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsIDocument> doc = GetDocumentFromScriptContext(mScriptContext);
|
||||
PRInt16 shouldLoad = nsIContentPolicy::ACCEPT;
|
||||
rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_XMLHTTPREQUEST,
|
||||
uri,
|
||||
(doc ? doc->NodePrincipal() : nsnull),
|
||||
mPrincipal,
|
||||
doc,
|
||||
EmptyCString(), //mime guess
|
||||
nsnull, //extra
|
||||
|
@ -1552,8 +1567,7 @@ nsXMLHttpRequest::OnStartRequest(nsIRequest *request, nsISupports *ctxt)
|
|||
|
||||
// Create an empty document from it
|
||||
const nsAString& emptyStr = EmptyString();
|
||||
nsIScriptGlobalObject* global = mScriptContext ?
|
||||
mScriptContext->GetGlobalObject() : nsnull;
|
||||
nsCOMPtr<nsIScriptGlobalObject> global = do_QueryInterface(mOwner);
|
||||
nsresult rv = nsContentUtils::CreateDocument(emptyStr, emptyStr, nsnull, uri,
|
||||
uri, mPrincipal, global,
|
||||
getter_AddRefs(mDocument));
|
||||
|
@ -1824,7 +1838,8 @@ nsXMLHttpRequest::SendAsBinary(const nsAString &aBody)
|
|||
NS_IMETHODIMP
|
||||
nsXMLHttpRequest::Send(nsIVariant *aBody)
|
||||
{
|
||||
nsresult rv;
|
||||
nsresult rv = CheckInnerWindowCorrectness();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Return error if we're already processing a request
|
||||
if (XML_HTTP_REQUEST_SENT & mState) {
|
||||
|
@ -2016,11 +2031,6 @@ nsXMLHttpRequest::Send(nsIVariant *aBody)
|
|||
mState |= XML_HTTP_REQUEST_SYNCLOOPING;
|
||||
}
|
||||
|
||||
if (!mScriptContext) {
|
||||
// We need a context to check if redirect (if any) is allowed
|
||||
mScriptContext = GetCurrentContext();
|
||||
}
|
||||
|
||||
rv = CheckChannelForCrossSiteRequest();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
|
|
|
@ -60,7 +60,8 @@
|
|||
#include "nsJSUtils.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
|
||||
#include "nsIJSNativeInitializer.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsIDOMLSProgressEvent.h"
|
||||
|
||||
class nsILoadGroup;
|
||||
|
@ -73,7 +74,8 @@ class nsXMLHttpRequest : public nsIXMLHttpRequest,
|
|||
public nsIChannelEventSink,
|
||||
public nsIProgressEventSink,
|
||||
public nsIInterfaceRequestor,
|
||||
public nsSupportsWeakReference
|
||||
public nsSupportsWeakReference,
|
||||
public nsIJSNativeInitializer
|
||||
{
|
||||
public:
|
||||
nsXMLHttpRequest();
|
||||
|
@ -115,6 +117,13 @@ public:
|
|||
// nsIInterfaceRequestor
|
||||
NS_DECL_NSIINTERFACEREQUESTOR
|
||||
|
||||
// nsIJSNativeInitializer
|
||||
NS_IMETHOD Initialize(nsISupports* aOwner, JSContext* cx, JSObject* obj,
|
||||
PRUint32 argc, jsval* argv);
|
||||
|
||||
// This is called by the factory constructor.
|
||||
nsresult Init();
|
||||
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsXMLHttpRequest, nsIXMLHttpRequest)
|
||||
|
||||
protected:
|
||||
|
@ -165,6 +174,18 @@ protected:
|
|||
*/
|
||||
nsresult CheckChannelForCrossSiteRequest();
|
||||
|
||||
nsresult CheckInnerWindowCorrectness()
|
||||
{
|
||||
if (mOwner) {
|
||||
NS_ASSERTION(mOwner->IsInnerWindow(), "Should have inner window here!\n");
|
||||
nsPIDOMWindow* outer = mOwner->GetOuterWindow();
|
||||
if (!outer || outer->GetCurrentInnerWindow() != mOwner) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISupports> mContext;
|
||||
nsCOMPtr<nsIPrincipal> mPrincipal;
|
||||
nsCOMPtr<nsIChannel> mChannel;
|
||||
|
@ -180,6 +201,7 @@ protected:
|
|||
nsCOMArray<nsIDOMEventListener> mReadystatechangeEventListeners;
|
||||
|
||||
nsCOMPtr<nsIScriptContext> mScriptContext;
|
||||
nsCOMPtr<nsPIDOMWindow> mOwner; // Inner window.
|
||||
|
||||
nsCOMPtr<nsIDOMEventListener> mOnLoadListener;
|
||||
nsCOMPtr<nsIDOMEventListener> mOnErrorListener;
|
||||
|
|
|
@ -108,8 +108,8 @@ public:
|
|||
NS_DECL_NSIDOMNSHTMLIMAGEELEMENT
|
||||
|
||||
// nsIJSNativeInitializer
|
||||
NS_IMETHOD Initialize(JSContext* aContext, JSObject *aObj,
|
||||
PRUint32 argc, jsval *argv);
|
||||
NS_IMETHOD Initialize(nsISupports* aOwner, JSContext* aContext,
|
||||
JSObject* aObj, PRUint32 argc, jsval* argv);
|
||||
|
||||
// nsIContent
|
||||
virtual PRBool ParseAttribute(PRInt32 aNamespaceID,
|
||||
|
@ -542,8 +542,8 @@ nsHTMLImageElement::IntrinsicState() const
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLImageElement::Initialize(JSContext* aContext, JSObject *aObj,
|
||||
PRUint32 argc, jsval *argv)
|
||||
nsHTMLImageElement::Initialize(nsISupports* aOwner, JSContext* aContext,
|
||||
JSObject *aObj, PRUint32 argc, jsval *argv)
|
||||
{
|
||||
if (argc <= 0) {
|
||||
// Nothing to do here if we don't get any arguments.
|
||||
|
|
|
@ -102,8 +102,8 @@ public:
|
|||
NS_IMETHOD SetText(const nsAString & aText);
|
||||
|
||||
// nsIJSNativeInitializer
|
||||
NS_IMETHOD Initialize(JSContext* aContext, JSObject *aObj,
|
||||
PRUint32 argc, jsval *argv);
|
||||
NS_IMETHOD Initialize(nsISupports* aOwner, JSContext* aContext,
|
||||
JSObject *aObj, PRUint32 argc, jsval *argv);
|
||||
|
||||
virtual nsChangeHint GetAttributeChangeHint(const nsIAtom* aAttribute,
|
||||
PRInt32 aModType) const;
|
||||
|
@ -455,7 +455,8 @@ nsHTMLOptionElement::GetSelect()
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLOptionElement::Initialize(JSContext* aContext,
|
||||
nsHTMLOptionElement::Initialize(nsISupports* aOwner,
|
||||
JSContext* aContext,
|
||||
JSObject *aObj,
|
||||
PRUint32 argc,
|
||||
jsval *argv)
|
||||
|
|
|
@ -1258,8 +1258,8 @@ txMozillaXSLTProcessor::ContentRemoved(nsIDocument* aDocument,
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
txMozillaXSLTProcessor::Initialize(JSContext* cx, JSObject* obj,
|
||||
PRUint32 argc, jsval* argv)
|
||||
txMozillaXSLTProcessor::Initialize(nsISupports* aOwner, JSContext* cx,
|
||||
JSObject* obj, PRUint32 argc, jsval* argv)
|
||||
{
|
||||
nsCOMPtr<nsIPrincipal> prin;
|
||||
nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
|
||||
|
|
|
@ -142,7 +142,7 @@ public:
|
|||
}
|
||||
|
||||
// nsIJSNativeInitializer
|
||||
NS_IMETHODIMP Initialize(JSContext *cx, JSObject *obj,
|
||||
NS_IMETHODIMP Initialize(nsISupports* aOwner, JSContext *cx, JSObject *obj,
|
||||
PRUint32 argc, jsval *argv);
|
||||
|
||||
static nsresult Startup();
|
||||
|
|
|
@ -42,8 +42,8 @@
|
|||
#include "jsapi.h"
|
||||
|
||||
#define NS_IJSNATIVEINITIALIZER_IID \
|
||||
{0xa6cf90f4, 0x15b3, 0x11d2, \
|
||||
{0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32}}
|
||||
{ 0x536c5ad2, 0x1275, 0x4706, \
|
||||
{ 0x99, 0xbd, 0x4a, 0xef, 0xb2, 0x4a, 0xb7, 0xf7 } }
|
||||
|
||||
/**
|
||||
* A JavaScript specific interface used to initialize new
|
||||
|
@ -57,10 +57,10 @@ public:
|
|||
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IJSNATIVEINITIALIZER_IID)
|
||||
|
||||
/**
|
||||
* Intialize a newly created native instance using the parameters
|
||||
* passed into the JavaScript constructor.
|
||||
* Initialize a newly created native instance using the owner of the
|
||||
* constructor and the parameters passed into the JavaScript constructor.
|
||||
*/
|
||||
NS_IMETHOD Initialize(JSContext *cx, JSObject *obj,
|
||||
NS_IMETHOD Initialize(nsISupports* aOwner, JSContext *cx, JSObject *obj,
|
||||
PRUint32 argc, jsval *argv) = 0;
|
||||
};
|
||||
|
||||
|
|
|
@ -4734,7 +4734,8 @@ FindConstructorContractID(PRInt32 aDOMClassInfoID)
|
|||
}
|
||||
|
||||
static nsresult
|
||||
BaseStubConstructor(const nsGlobalNameStruct *name_struct, JSContext *cx,
|
||||
BaseStubConstructor(nsIWeakReference* aWeakOwner,
|
||||
const nsGlobalNameStruct *name_struct, JSContext *cx,
|
||||
JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
nsresult rv;
|
||||
|
@ -4757,7 +4758,9 @@ BaseStubConstructor(const nsGlobalNameStruct *name_struct, JSContext *cx,
|
|||
|
||||
nsCOMPtr<nsIJSNativeInitializer> initializer(do_QueryInterface(native));
|
||||
if (initializer) {
|
||||
rv = initializer->Initialize(cx, obj, argc, argv);
|
||||
nsCOMPtr<nsISupports> owner = do_QueryReferent(aWeakOwner);
|
||||
NS_ENSURE_STATE(owner);
|
||||
rv = initializer->Initialize(owner, cx, obj, argc, argv);
|
||||
if (NS_FAILED(rv)) {
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
@ -4865,9 +4868,11 @@ class nsDOMConstructor : public nsIDOMDOMConstructor
|
|||
{
|
||||
public:
|
||||
nsDOMConstructor(const PRUnichar *aName,
|
||||
const nsGlobalNameStruct *aNameStruct)
|
||||
const nsGlobalNameStruct *aNameStruct,
|
||||
nsISupports* aOwner)
|
||||
: mClassName(aName),
|
||||
mConstructable(IsConstructable(aNameStruct))
|
||||
mConstructable(IsConstructable(aNameStruct)),
|
||||
mWeakOwner(do_GetWeakReference(aOwner))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -4946,8 +4951,9 @@ private:
|
|||
aNameStruct->mType == nsGlobalNameStruct::eTypeExternalConstructorAlias;
|
||||
}
|
||||
|
||||
const PRUnichar *mClassName;
|
||||
const PRUnichar* mClassName;
|
||||
const PRPackedBool mConstructable;
|
||||
nsWeakPtr mWeakOwner;
|
||||
};
|
||||
|
||||
NS_IMPL_ADDREF(nsDOMConstructor)
|
||||
|
@ -4994,7 +5000,7 @@ nsDOMConstructor::Construct(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
|||
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
||||
}
|
||||
|
||||
return BaseStubConstructor(name_struct, cx, obj, argc, argv, vp);
|
||||
return BaseStubConstructor(mWeakOwner, name_struct, cx, obj, argc, argv, vp);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -5200,7 +5206,8 @@ nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx,
|
|||
nsRefPtr<nsDOMConstructor> constructor =
|
||||
new nsDOMConstructor(reinterpret_cast<PRUnichar *>
|
||||
(::JS_GetStringChars(str)),
|
||||
name_struct);
|
||||
name_struct,
|
||||
static_cast<nsPIDOMWindow*>(aWin));
|
||||
if (!constructor) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -5262,7 +5269,8 @@ nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx,
|
|||
const PRUnichar *name = reinterpret_cast<PRUnichar *>
|
||||
(::JS_GetStringChars(str));
|
||||
nsRefPtr<nsDOMConstructor> constructor =
|
||||
new nsDOMConstructor(name, name_struct);
|
||||
new nsDOMConstructor(name, name_struct,
|
||||
static_cast<nsPIDOMWindow*>(aWin));
|
||||
if (!constructor) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -5483,7 +5491,8 @@ nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx,
|
|||
|
||||
if (name_struct->mType == nsGlobalNameStruct::eTypeExternalConstructor) {
|
||||
nsRefPtr<nsDOMConstructor> constructor =
|
||||
new nsDOMConstructor(class_name, name_struct);
|
||||
new nsDOMConstructor(class_name, name_struct,
|
||||
static_cast<nsPIDOMWindow*>(aWin));
|
||||
if (!constructor) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
|
|
@ -282,7 +282,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(txMozillaXSLTProcessor)
|
|||
NS_GENERIC_AGGREGATED_CONSTRUCTOR_INIT(nsXPathEvaluator, Init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(txNodeSetAdaptor, Init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDOMSerializer)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsXMLHttpRequest)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsXMLHttpRequest, Init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDOMParser)
|
||||
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsDOMStorageManager,
|
||||
nsDOMStorageManager::GetInstance)
|
||||
|
|
Загрузка…
Ссылка в новой задаче