Fixing bug 233307. deCOMtaminating nsIScript* and related interfaces. r+sr=bryner@brianryner.com.

This commit is contained in:
jst%mozilla.jstenback.com 2004-02-09 22:48:53 +00:00
Родитель 48abfb9563
Коммит 8b6dc1c3ca
116 изменённых файлов: 1255 добавлений и 2094 удалений

Просмотреть файл

@ -99,13 +99,10 @@ JSValIDToString(JSContext *cx, const jsval idval)
return NS_REINTERPRET_CAST(PRUnichar*, JS_GetStringChars(str)); return NS_REINTERPRET_CAST(PRUnichar*, JS_GetStringChars(str));
} }
already_AddRefed<nsIScriptContext> static nsIScriptContext *
GetScriptContext(JSContext *cx) GetScriptContext(JSContext *cx)
{ {
nsIScriptContext *scriptContext; return GetScriptContextFromJSContext(cx);
GetScriptContextFromJSContext(cx, &scriptContext);
return scriptContext;
} }
// Helper class to get stuff from the ClassInfo and not waste extra time with // Helper class to get stuff from the ClassInfo and not waste extra time with
@ -1428,16 +1425,18 @@ nsScriptSecurityManager::GetRootDocShell(JSContext *cx, nsIDocShell **result)
{ {
nsresult rv; nsresult rv;
*result = nsnull; *result = nsnull;
nsCOMPtr<nsIDocShell> docshell; nsIScriptContext *scriptContext = GetScriptContext(cx);
nsCOMPtr<nsIScriptContext> scriptContext = GetScriptContext(cx); if (!scriptContext)
if (!scriptContext) return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
nsCOMPtr<nsIScriptGlobalObject> globalObject;
scriptContext->GetGlobalObject(getter_AddRefs(globalObject)); nsIScriptGlobalObject *globalObject = scriptContext->GetGlobalObject();
if (!globalObject) return NS_ERROR_FAILURE; if (!globalObject)
rv = globalObject->GetDocShell(getter_AddRefs(docshell)); return NS_ERROR_FAILURE;
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIDocShellTreeItem> docshellTreeItem(do_QueryInterface(docshell, &rv)); nsCOMPtr<nsIDocShellTreeItem> docshellTreeItem =
do_QueryInterface(globalObject->GetDocShell(), &rv);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIDocShellTreeItem> rootItem; nsCOMPtr<nsIDocShellTreeItem> rootItem;
rv = docshellTreeItem->GetRootTreeItem(getter_AddRefs(rootItem)); rv = docshellTreeItem->GetRootTreeItem(getter_AddRefs(rootItem));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
@ -1479,15 +1478,13 @@ nsScriptSecurityManager::CanExecuteScripts(JSContext* cx,
} }
//-- See if the current window allows JS execution //-- See if the current window allows JS execution
nsCOMPtr<nsIScriptContext> scriptContext = GetScriptContext(cx); nsIScriptContext *scriptContext = GetScriptContext(cx);
if (!scriptContext) return NS_ERROR_FAILURE; if (!scriptContext) return NS_ERROR_FAILURE;
nsCOMPtr<nsIScriptGlobalObject> globalObject; nsIScriptGlobalObject *globalObject = scriptContext->GetGlobalObject();
scriptContext->GetGlobalObject(getter_AddRefs(globalObject));
if (!globalObject) return NS_ERROR_FAILURE; if (!globalObject) return NS_ERROR_FAILURE;
nsresult rv; nsresult rv;
nsCOMPtr<nsIDocShell> docshell; nsCOMPtr<nsIDocShell> docshell = globalObject->GetDocShell();
globalObject->GetDocShell(getter_AddRefs(docshell));
nsCOMPtr<nsIDocShellTreeItem> globalObjTreeItem = do_QueryInterface(docshell); nsCOMPtr<nsIDocShellTreeItem> globalObjTreeItem = do_QueryInterface(docshell);
if (globalObjTreeItem) if (globalObjTreeItem)
{ {
@ -1731,16 +1728,15 @@ nsScriptSecurityManager::GetPrincipalFromContext(JSContext *cx,
{ {
*result = nsnull; *result = nsnull;
nsCOMPtr<nsIScriptContext> scriptContext = GetScriptContext(cx); nsIScriptContext *scriptContext = GetScriptContext(cx);
if (!scriptContext) if (!scriptContext)
{ {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
nsCOMPtr<nsIScriptGlobalObject> global; nsCOMPtr<nsIScriptObjectPrincipal> globalData =
scriptContext->GetGlobalObject(getter_AddRefs(global)); do_QueryInterface(scriptContext->GetGlobalObject());
nsCOMPtr<nsIScriptObjectPrincipal> globalData(do_QueryInterface(global));
if (globalData) if (globalData)
globalData->GetPrincipal(result); globalData->GetPrincipal(result);
@ -1852,14 +1848,13 @@ nsScriptSecurityManager::GetPrincipalAndFrame(JSContext *cx,
// and return the innermost frame for annotations. // and return the innermost frame for annotations.
if (cx) if (cx)
{ {
nsCOMPtr<nsIScriptContext> scriptContext = GetScriptContext(cx); nsIScriptContext *scriptContext = GetScriptContext(cx);
if (scriptContext) if (scriptContext)
{ {
nsCOMPtr<nsIScriptGlobalObject> global; nsCOMPtr<nsIScriptObjectPrincipal> globalData =
scriptContext->GetGlobalObject(getter_AddRefs(global)); do_QueryInterface(scriptContext->GetGlobalObject());
NS_ENSURE_TRUE(global, NS_ERROR_FAILURE);
nsCOMPtr<nsIScriptObjectPrincipal> globalData(do_QueryInterface(global));
NS_ENSURE_TRUE(globalData, NS_ERROR_FAILURE); NS_ENSURE_TRUE(globalData, NS_ERROR_FAILURE);
globalData->GetPrincipal(result); globalData->GetPrincipal(result);
if (*result) if (*result)
{ {
@ -2060,13 +2055,11 @@ nsScriptSecurityManager::CheckConfirmDialog(JSContext* cx, nsIPrincipal* aPrinci
nsCOMPtr<nsIPrompt> prompter; nsCOMPtr<nsIPrompt> prompter;
if (cx) if (cx)
{ {
nsCOMPtr<nsIScriptContext> scriptContext = GetScriptContext(cx); nsIScriptContext *scriptContext = GetScriptContext(cx);
if (scriptContext) if (scriptContext)
{ {
nsCOMPtr<nsIScriptGlobalObject> globalObject; nsCOMPtr<nsIDOMWindowInternal> domWin =
scriptContext->GetGlobalObject(getter_AddRefs(globalObject)); do_QueryInterface(scriptContext->GetGlobalObject());
NS_ASSERTION(globalObject, "script context has no global object");
nsCOMPtr<nsIDOMWindowInternal> domWin(do_QueryInterface(globalObject));
if (domWin) if (domWin)
domWin->GetPrompter(getter_AddRefs(prompter)); domWin->GetPrompter(getter_AddRefs(prompter));
} }

Просмотреть файл

@ -172,19 +172,15 @@ public:
// These are copied from nsJSUtils.h // These are copied from nsJSUtils.h
static nsresult GetStaticScriptGlobal(JSContext* aContext, static nsIScriptGlobalObject *GetStaticScriptGlobal(JSContext* aContext,
JSObject* aObj, JSObject* aObj);
nsIScriptGlobalObject** aNativeGlobal);
static nsresult GetStaticScriptContext(JSContext* aContext, static nsIScriptContext *GetStaticScriptContext(JSContext* aContext,
JSObject* aObj, JSObject* aObj);
nsIScriptContext** aScriptContext);
static nsresult GetDynamicScriptGlobal(JSContext *aContext, static nsIScriptGlobalObject *GetDynamicScriptGlobal(JSContext *aContext);
nsIScriptGlobalObject** aNativeGlobal);
static nsresult GetDynamicScriptContext(JSContext *aContext, static nsIScriptContext *GetDynamicScriptContext(JSContext *aContext);
nsIScriptContext** aScriptContext);
static PRUint32 CopyNewlineNormalizedUnicodeTo(const nsAString& aSource, static PRUint32 CopyNewlineNormalizedUnicodeTo(const nsAString& aSource,
PRUint32 aSrcOffset, PRUint32 aSrcOffset,
@ -224,7 +220,7 @@ public:
* *
* @param aDocShell The docshell or null if no JS context * @param aDocShell The docshell or null if no JS context
*/ */
static void GetDocShellFromCaller(nsIDocShell** aDocShell); static nsIDocShell *GetDocShellFromCaller();
/** /**
* Get the document through the JS context that's currently on the stack. * Get the document through the JS context that's currently on the stack.
@ -232,7 +228,7 @@ public:
* *
* @param aDocument The document or null if no JS context * @param aDocument The document or null if no JS context
*/ */
static void GetDocumentFromCaller(nsIDOMDocument** aDocument); static nsIDOMDocument *GetDocumentFromCaller();
// Check if a node is in the document prolog, i.e. before the document // Check if a node is in the document prolog, i.e. before the document
// element. // element.

Просмотреть файл

@ -664,8 +664,11 @@ nsAttrAndChildArray::AddAttrSlot()
return PR_FALSE; return PR_FALSE;
} }
void** offset = mImpl->mBuffer + slotCount * ATTRSIZE; void** offset = mImpl->mBuffer + slotCount * ATTRSIZE;
if (childCount > 0) {
memmove(&ATTRS(mImpl)[slotCount + 1], &ATTRS(mImpl)[slotCount], memmove(&ATTRS(mImpl)[slotCount + 1], &ATTRS(mImpl)[slotCount],
childCount * sizeof(nsIContent*)); childCount * sizeof(nsIContent*));
}
SetAttrSlotCount(slotCount + 1); SetAttrSlotCount(slotCount + 1);
offset[0] = nsnull; offset[0] = nsnull;

Просмотреть файл

@ -158,21 +158,18 @@ nsContentUtils::GetParserServiceWeakRef()
} }
// static // static
nsresult nsIScriptGlobalObject *
nsContentUtils::GetStaticScriptGlobal(JSContext* aContext, JSObject* aObj, nsContentUtils::GetStaticScriptGlobal(JSContext* aContext, JSObject* aObj)
nsIScriptGlobalObject** aNativeGlobal)
{ {
if (!sXPConnect) { if (!sXPConnect) {
*aNativeGlobal = nsnull; return nsnull;
return NS_OK;
} }
JSObject* parent; JSObject* parent;
JSObject* glob = aObj; // starting point for search JSObject* glob = aObj; // starting point for search
if (!glob) if (!glob)
return NS_ERROR_FAILURE; return nsnull;
while (nsnull != (parent = JS_GetParent(aContext, glob))) { while (nsnull != (parent = JS_GetParent(aContext, glob))) {
glob = parent; glob = parent;
@ -180,54 +177,47 @@ nsContentUtils::GetStaticScriptGlobal(JSContext* aContext, JSObject* aObj,
nsCOMPtr<nsIXPConnectWrappedNative> wrapped_native; nsCOMPtr<nsIXPConnectWrappedNative> wrapped_native;
nsresult rv =
sXPConnect->GetWrappedNativeOfJSObject(aContext, glob, sXPConnect->GetWrappedNativeOfJSObject(aContext, glob,
getter_AddRefs(wrapped_native)); getter_AddRefs(wrapped_native));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_TRUE(wrapped_native, nsnull);
nsCOMPtr<nsISupports> native; nsCOMPtr<nsISupports> native;
rv = wrapped_native->GetNative(getter_AddRefs(native)); wrapped_native->GetNative(getter_AddRefs(native));
NS_ENSURE_SUCCESS(rv, rv);
return CallQueryInterface(native, aNativeGlobal); nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(native));
// This will return a pointer to something that's about to be
// released, but that's ok here.
return sgo;
} }
//static //static
nsresult nsIScriptContext *
nsContentUtils::GetStaticScriptContext(JSContext* aContext, nsContentUtils::GetStaticScriptContext(JSContext* aContext,
JSObject* aObj, JSObject* aObj)
nsIScriptContext** aScriptContext)
{ {
nsCOMPtr<nsIScriptGlobalObject> nativeGlobal; nsIScriptGlobalObject *nativeGlobal = GetStaticScriptGlobal(aContext, aObj);
GetStaticScriptGlobal(aContext, aObj, getter_AddRefs(nativeGlobal));
if (!nativeGlobal) if (!nativeGlobal)
return NS_ERROR_FAILURE; return nsnull;
nsIScriptContext* scriptContext = nsnull; return nativeGlobal->GetContext();
nativeGlobal->GetContext(&scriptContext);
*aScriptContext = scriptContext;
return scriptContext ? NS_OK : NS_ERROR_FAILURE;
} }
//static //static
nsresult nsIScriptGlobalObject *
nsContentUtils::GetDynamicScriptGlobal(JSContext* aContext, nsContentUtils::GetDynamicScriptGlobal(JSContext* aContext)
nsIScriptGlobalObject** aNativeGlobal)
{ {
nsCOMPtr<nsIScriptContext> scriptCX; nsIScriptContext *scriptCX = GetDynamicScriptContext(aContext);
GetDynamicScriptContext(aContext, getter_AddRefs(scriptCX));
if (!scriptCX) { if (!scriptCX) {
*aNativeGlobal = nsnull; return nsnull;
return NS_ERROR_FAILURE;
} }
return scriptCX->GetGlobalObject(aNativeGlobal); return scriptCX->GetGlobalObject();
} }
//static //static
nsresult nsIScriptContext *
nsContentUtils::GetDynamicScriptContext(JSContext *aContext, nsContentUtils::GetDynamicScriptContext(JSContext *aContext)
nsIScriptContext** aScriptContext)
{ {
return GetScriptContextFromJSContext(aContext, aScriptContext); return GetScriptContextFromJSContext(aContext);
} }
template <class OutputIterator> template <class OutputIterator>
@ -746,31 +736,26 @@ nsContentUtils::doReparentContentWrapper(nsIContent *aChild,
return rv; return rv;
} }
static static JSContext *
nsresult GetContextFromDocument(nsIDocument *aDocument, JSContext **cx) GetContextFromDocument(nsIDocument *aDocument)
{ {
*cx = nsnull;
nsIScriptGlobalObject *sgo = aDocument->GetScriptGlobalObject(); nsIScriptGlobalObject *sgo = aDocument->GetScriptGlobalObject();
if (!sgo) { if (!sgo) {
// No script global, no context. // No script global, no context.
return NS_OK; return nsnull;
} }
nsCOMPtr<nsIScriptContext> scx; nsIScriptContext *scx = sgo->GetContext();
sgo->GetContext(getter_AddRefs(scx));
if (!scx) { if (!scx) {
// No context left in the old scope... // No context left in the old scope...
return NS_OK; return nsnull;
} }
*cx = (JSContext *)scx->GetNativeContext(); return (JSContext *)scx->GetNativeContext();
return NS_OK;
} }
// static // static
@ -813,9 +798,7 @@ nsContentUtils::ReparentContentWrapper(nsIContent *aContent,
new_parent = aNewParent; new_parent = aNewParent;
} }
JSContext *cx = nsnull; JSContext *cx = GetContextFromDocument(old_doc);
GetContextFromDocument(old_doc, &cx);
if (!cx) { if (!cx) {
// No JSContext left in the old scope, can't find the old wrapper // No JSContext left in the old scope, can't find the old wrapper
@ -857,49 +840,51 @@ nsContentUtils::ReparentContentWrapper(nsIContent *aContent,
obj); obj);
} }
void nsIDocShell *
nsContentUtils::GetDocShellFromCaller(nsIDocShell** aDocShell) nsContentUtils::GetDocShellFromCaller()
{ {
*aDocShell = nsnull;
if (!sThreadJSContextStack) { if (!sThreadJSContextStack) {
return; return nsnull;
} }
JSContext *cx = nsnull; JSContext *cx = nsnull;
sThreadJSContextStack->Peek(&cx); sThreadJSContextStack->Peek(&cx);
if (cx) { if (cx) {
nsCOMPtr<nsIScriptGlobalObject> sgo; nsIScriptGlobalObject *sgo = GetDynamicScriptGlobal(cx);
GetDynamicScriptGlobal(cx, getter_AddRefs(sgo));
if (sgo) { if (sgo) {
sgo->GetDocShell(aDocShell); return sgo->GetDocShell();
} }
} }
return nsnull;
} }
void nsIDOMDocument *
nsContentUtils::GetDocumentFromCaller(nsIDOMDocument** aDocument) nsContentUtils::GetDocumentFromCaller()
{ {
*aDocument = nsnull;
if (!sThreadJSContextStack) { if (!sThreadJSContextStack) {
return; return nsnull;
} }
JSContext *cx = nsnull; JSContext *cx = nsnull;
sThreadJSContextStack->Peek(&cx); sThreadJSContextStack->Peek(&cx);
nsCOMPtr<nsIDOMDocument> doc;
if (cx) { if (cx) {
nsCOMPtr<nsIScriptGlobalObject> sgo; nsIScriptGlobalObject *sgo = GetDynamicScriptGlobal(cx);
GetDynamicScriptGlobal(cx, getter_AddRefs(sgo));
nsCOMPtr<nsIDOMWindowInternal> win(do_QueryInterface(sgo)); nsCOMPtr<nsIDOMWindowInternal> win(do_QueryInterface(sgo));
if (!win) { if (win) {
return; win->GetDocument(getter_AddRefs(doc));
}
} }
win->GetDocument(aDocument); // This will return a pointer to something we're about to release,
} // but that's ok here.
return doc;
} }
PRBool PRBool
@ -1635,7 +1620,7 @@ nsCxPusher::Push(nsISupports *aCurrentTarget)
JSContext *cx = nsnull; JSContext *cx = nsnull;
if (sgo) { if (sgo) {
sgo->GetContext(getter_AddRefs(mScx)); mScx = sgo->GetContext();
if (mScx) { if (mScx) {
cx = (JSContext *)mScx->GetNativeContext(); cx = (JSContext *)mScx->GetNativeContext();

Просмотреть файл

@ -368,8 +368,7 @@ nsDOMImplementation::CreateDocument(const nsAString& aNamespaceURI,
nsresult rv = NS_NewDOMDocument(aReturn, aNamespaceURI, aQualifiedName, nsresult rv = NS_NewDOMDocument(aReturn, aNamespaceURI, aQualifiedName,
aDoctype, mBaseURI); aDoctype, mBaseURI);
nsCOMPtr<nsIDocShell> docShell; nsIDocShell *docShell = nsContentUtils::GetDocShellFromCaller();
nsContentUtils::GetDocShellFromCaller(getter_AddRefs(docShell));
if (docShell) { if (docShell) {
nsCOMPtr<nsIPresContext> presContext; nsCOMPtr<nsIPresContext> presContext;
docShell->GetPresContext(getter_AddRefs(presContext)); docShell->GetPresContext(getter_AddRefs(presContext));
@ -1757,11 +1756,8 @@ nsDocument::EndLoad()
nsCOMPtr<nsIDOMEventTarget> target_frame; nsCOMPtr<nsIDOMEventTarget> target_frame;
if (mScriptGlobalObject) { if (mScriptGlobalObject) {
nsCOMPtr<nsIDocShell> docShell;
mScriptGlobalObject->GetDocShell(getter_AddRefs(docShell));
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem = nsCOMPtr<nsIDocShellTreeItem> docShellAsItem =
do_QueryInterface(docShell); do_QueryInterface(mScriptGlobalObject->GetDocShell());
if (docShellAsItem) { if (docShellAsItem) {
docShellAsItem->GetSameTypeParent(getter_AddRefs(docShellParent)); docShellAsItem->GetSameTypeParent(getter_AddRefs(docShellParent));
@ -3788,10 +3784,8 @@ nsDocument::FlushPendingNotifications(PRBool aFlushReflows,
// that uses mParentDocument, but mParentDocument is never set in // that uses mParentDocument, but mParentDocument is never set in
// the current code! // the current code!
nsCOMPtr<nsIDocShell> docShell; nsCOMPtr<nsIDocShellTreeItem> docShellAsItem =
mScriptGlobalObject->GetDocShell(getter_AddRefs(docShell)); do_QueryInterface(mScriptGlobalObject->GetDocShell());
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(docShell));
if (docShellAsItem) { if (docShellAsItem) {
nsCOMPtr<nsIDocShellTreeItem> docShellParent; nsCOMPtr<nsIDocShellTreeItem> docShellParent;
@ -3923,8 +3917,7 @@ nsDocument::IsScriptEnabled()
nsIScriptGlobalObject* globalObject = GetScriptGlobalObject(); nsIScriptGlobalObject* globalObject = GetScriptGlobalObject();
NS_ENSURE_TRUE(globalObject, PR_TRUE); NS_ENSURE_TRUE(globalObject, PR_TRUE);
nsCOMPtr<nsIScriptContext> scriptContext; nsIScriptContext *scriptContext = globalObject->GetContext();
globalObject->GetContext(getter_AddRefs(scriptContext));
NS_ENSURE_TRUE(scriptContext, PR_TRUE); NS_ENSURE_TRUE(scriptContext, PR_TRUE);
JSContext* cx = (JSContext *) scriptContext->GetNativeContext(); JSContext* cx = (JSContext *) scriptContext->GetNativeContext();

Просмотреть файл

@ -2588,9 +2588,7 @@ isSelfOrAncestor(nsIContent *aNode, nsIContent *aChild)
/* /*
* If aChild doesn't have children it can't be our ancestor * If aChild doesn't have children it can't be our ancestor
*/ */
PRUint32 childCount = aChild->GetChildCount(); if (aChild->GetChildCount() == 0) {
if (childCount == 0) {
return PR_FALSE; return PR_FALSE;
} }
@ -3137,62 +3135,37 @@ nsresult
nsGenericElement::AddScriptEventListener(nsIAtom* aAttribute, nsGenericElement::AddScriptEventListener(nsIAtom* aAttribute,
const nsAString& aValue) const nsAString& aValue)
{ {
nsresult ret = NS_OK; nsresult rv = NS_OK;
nsCOMPtr<nsIScriptContext> context; nsISupports *target = NS_STATIC_CAST(nsIContent *, this);
nsCOMPtr<nsIScriptGlobalObject> global; PRBool defer = PR_TRUE;
JSContext* cx = nsnull;
// Try to get context from doc nsCOMPtr<nsIEventListenerManager> manager;
if (mDocument) {
if ((global = mDocument->GetScriptGlobalObject())) {
NS_ENSURE_SUCCESS(global->GetContext(getter_AddRefs(context)), NS_ERROR_FAILURE);
}
}
if (!context) {
// Get JSContext from stack.
nsCOMPtr<nsIThreadJSContextStack> stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1"));
NS_ENSURE_TRUE(stack, NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(stack->Peek(&cx), NS_ERROR_FAILURE);
if (!cx) {
stack->GetSafeJSContext(&cx);
NS_ENSURE_TRUE(cx, NS_ERROR_FAILURE);
}
nsContentUtils::GetDynamicScriptContext(cx, getter_AddRefs(context));
NS_ENSURE_TRUE(context, NS_ERROR_FAILURE);
}
// Attributes on the body and frameset tags get set on the global object // Attributes on the body and frameset tags get set on the global object
if (mNodeInfo->Equals(nsHTMLAtoms::body) || if (mNodeInfo->Equals(nsHTMLAtoms::body) ||
mNodeInfo->Equals(nsHTMLAtoms::frameset)) { mNodeInfo->Equals(nsHTMLAtoms::frameset)) {
if (!global && cx) { nsIScriptGlobalObject *sgo;
nsContentUtils::GetDynamicScriptGlobal(cx, getter_AddRefs(global));
NS_ENSURE_TRUE(global, NS_ERROR_FAILURE); // If we have a document, and it has a script global, add the
} // event listener on the global. If not, proceed as normal.
nsCOMPtr<nsIDOMEventReceiver> receiver(do_QueryInterface(global)); if (mDocument && (sgo = mDocument->GetScriptGlobalObject())) {
nsCOMPtr<nsIDOMEventReceiver> receiver(do_QueryInterface(sgo));
NS_ENSURE_TRUE(receiver, NS_ERROR_FAILURE); NS_ENSURE_TRUE(receiver, NS_ERROR_FAILURE);
nsCOMPtr<nsIEventListenerManager> manager;
receiver->GetListenerManager(getter_AddRefs(manager)); receiver->GetListenerManager(getter_AddRefs(manager));
if (manager) { target = sgo;
ret = manager->AddScriptEventListener(context, global, aAttribute, defer = PR_FALSE;
aValue, PR_FALSE);
} }
} else { } else {
nsCOMPtr<nsIEventListenerManager> manager;
GetListenerManager(getter_AddRefs(manager)); GetListenerManager(getter_AddRefs(manager));
}
if (manager) { if (manager) {
ret = manager->AddScriptEventListener(context, this, aAttribute, aValue, rv = manager->AddScriptEventListener(target, aAttribute, aValue, defer);
PR_TRUE);
}
} }
return ret; return rv;
} }

Просмотреть файл

@ -1708,9 +1708,7 @@ nsPrintEngine::IsThereARangeSelection(nsIDOMWindow* aDOMWin)
nsCOMPtr<nsIPresShell> presShell; nsCOMPtr<nsIPresShell> presShell;
if (aDOMWin) { if (aDOMWin) {
nsCOMPtr<nsIScriptGlobalObject> scriptObj(do_QueryInterface(aDOMWin)); nsCOMPtr<nsIScriptGlobalObject> scriptObj(do_QueryInterface(aDOMWin));
nsCOMPtr<nsIDocShell> docShell; scriptObj->GetDocShell()->GetPresShell(getter_AddRefs(presShell));
scriptObj->GetDocShell(getter_AddRefs(docShell));
docShell->GetPresShell(getter_AddRefs(presShell));
} }
// check here to see if there is a range selection // check here to see if there is a range selection
@ -4002,10 +4000,9 @@ nsPrintEngine::IsWindowsInOurSubTree(nsIDOMWindow * aDOMWindow)
// now check to make sure it is in "our" tree of webshells // now check to make sure it is in "our" tree of webshells
nsCOMPtr<nsIScriptGlobalObject> scriptObj(do_QueryInterface(aDOMWindow)); nsCOMPtr<nsIScriptGlobalObject> scriptObj(do_QueryInterface(aDOMWindow));
if (scriptObj) { if (scriptObj) {
nsCOMPtr<nsIDocShell> docShell; nsCOMPtr<nsIDocShellTreeItem> docShellAsItem =
scriptObj->GetDocShell(getter_AddRefs(docShell)); do_QueryInterface(scriptObj->GetDocShell());
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(docShell));
if (docShellAsItem) { if (docShellAsItem) {
// get this DocViewer webshell // get this DocViewer webshell
nsCOMPtr<nsIWebShell> thisDVWebShell(do_QueryInterface(mContainer)); nsCOMPtr<nsIWebShell> thisDVWebShell(do_QueryInterface(mContainer));
@ -4440,9 +4437,8 @@ nsPrintEngine::TurnScriptingOn(PRBool aDoTurnOn)
// get the script global object // get the script global object
nsIScriptGlobalObject *scriptGlobalObj = mDocument->GetScriptGlobalObject(); nsIScriptGlobalObject *scriptGlobalObj = mDocument->GetScriptGlobalObject();
NS_ASSERTION(scriptGlobalObj, "Can't get nsIScriptGlobalObject"); NS_ASSERTION(scriptGlobalObj, "Can't get nsIScriptGlobalObject");
nsCOMPtr<nsIScriptContext> scx; nsIScriptContext *scx = scriptGlobalObj->GetContext();
nsresult rv = scriptGlobalObj->GetContext(getter_AddRefs(scx)); NS_ASSERTION(scx, "Can't get nsIScriptContext");
NS_ASSERTION(NS_SUCCEEDED(rv) && scx, "Can't get nsIScriptContext");
scx->SetScriptsEnabled(aDoTurnOn, PR_TRUE); scx->SetScriptsEnabled(aDoTurnOn, PR_TRUE);
} }

Просмотреть файл

@ -2490,20 +2490,19 @@ nsRange::CreateContextualFragment(const nsAString& aFragment,
if (NS_SUCCEEDED(result) && if (NS_SUCCEEDED(result) &&
(!subjectPrin || sysPrin.get() == subjectPrin.get())) { (!subjectPrin || sysPrin.get() == subjectPrin.get())) {
nsIScriptGlobalObject *globalObj = document->GetScriptGlobalObject(); nsIScriptGlobalObject *globalObj = document->GetScriptGlobalObject();
nsCOMPtr<nsIScriptContext> scriptContext;
if (globalObj) {
result = globalObj->GetContext(getter_AddRefs(scriptContext));
}
JSContext* cx = nsnull; JSContext* cx = nsnull;
if (NS_SUCCEEDED(result) && scriptContext) {
if (globalObj) {
nsIScriptContext *scriptContext = globalObj->GetContext();
if (scriptContext) {
cx = (JSContext*)scriptContext->GetNativeContext(); cx = (JSContext*)scriptContext->GetNativeContext();
} }
}
if(cx) { if (cx) {
ContextStack = do_GetService("@mozilla.org/js/xpc/ContextStack;1", &result); ContextStack = do_GetService("@mozilla.org/js/xpc/ContextStack;1");
if(NS_SUCCEEDED(result)) { if (ContextStack) {
result = ContextStack->Push(cx); result = ContextStack->Push(cx);
} }
} }

Просмотреть файл

@ -363,16 +363,13 @@ nsScriptLoader::ProcessScriptElement(nsIDOMHTMLScriptElement *aElement,
nsIScriptGlobalObject *globalObject = mDocument->GetScriptGlobalObject(); nsIScriptGlobalObject *globalObject = mDocument->GetScriptGlobalObject();
if (globalObject) if (globalObject)
{ {
nsCOMPtr<nsIScriptContext> context; nsIScriptContext *context = globalObject->GetContext();
if (NS_SUCCEEDED(globalObject->GetContext(getter_AddRefs(context)))
&& context) {
PRBool scriptsEnabled = PR_TRUE;
context->GetScriptsEnabled(&scriptsEnabled);
// If scripts aren't enabled in the current context, there's no // If scripts aren't enabled in the current context, there's no
// point in going on. // point in going on.
if (!scriptsEnabled) { if (context && !context->GetScriptsEnabled()) {
return FireErrorNotification(NS_ERROR_NOT_AVAILABLE, aElement, aObserver); return FireErrorNotification(NS_ERROR_NOT_AVAILABLE, aElement,
} aObserver);
} }
} }
@ -476,12 +473,7 @@ nsScriptLoader::ProcessScriptElement(nsIDOMHTMLScriptElement *aElement,
nsCOMPtr<nsILoadGroup> loadGroup = mDocument->GetDocumentLoadGroup(); nsCOMPtr<nsILoadGroup> loadGroup = mDocument->GetDocumentLoadGroup();
nsCOMPtr<nsIStreamLoader> loader; nsCOMPtr<nsIStreamLoader> loader;
nsCOMPtr<nsIDocShell> docshell; nsIDocShell *docshell = globalObject->GetDocShell();
rv = globalObject->GetDocShell(getter_AddRefs(docshell));
if (NS_FAILED(rv)) {
mPendingRequests.RemoveObject(request);
return FireErrorNotification(rv, aElement, aObserver);
}
nsCOMPtr<nsIInterfaceRequestor> prompter(do_QueryInterface(docshell)); nsCOMPtr<nsIInterfaceRequestor> prompter(do_QueryInterface(docshell));
@ -636,9 +628,8 @@ nsScriptLoader::EvaluateScript(nsScriptLoadRequest* aRequest,
nsIScriptGlobalObject *globalObject = mDocument->GetScriptGlobalObject(); nsIScriptGlobalObject *globalObject = mDocument->GetScriptGlobalObject();
NS_ENSURE_TRUE(globalObject, NS_ERROR_FAILURE); NS_ENSURE_TRUE(globalObject, NS_ERROR_FAILURE);
nsCOMPtr<nsIScriptContext> context; nsIScriptContext *context = globalObject->GetContext();
rv = globalObject->GetContext(getter_AddRefs(context)); if (!context) {
if (NS_FAILED(rv) || !context) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }

Просмотреть файл

@ -99,8 +99,7 @@ public:
* name aName and function body aFunc. * name aName and function body aFunc.
* @param an event listener * @param an event listener
*/ */
NS_IMETHOD AddScriptEventListener(nsIScriptContext*aContext, NS_IMETHOD AddScriptEventListener(nsISupports *aObject,
nsISupports *aObject,
nsIAtom *aName, nsIAtom *aName,
const nsAString& aFunc, const nsAString& aFunc,
PRBool aDeferCompilation) = 0; PRBool aDeferCompilation) = 0;

Просмотреть файл

@ -59,7 +59,6 @@
#include "nsIEventStateManager.h" #include "nsIEventStateManager.h"
#include "nsPIDOMWindow.h" #include "nsPIDOMWindow.h"
#include "nsIPrivateDOMEvent.h" #include "nsIPrivateDOMEvent.h"
#include "nsIScriptEventListener.h"
#include "nsIJSEventListener.h" #include "nsIJSEventListener.h"
#include "prmem.h" #include "prmem.h"
#include "nsIScriptGlobalObject.h" #include "nsIScriptGlobalObject.h"
@ -680,32 +679,15 @@ nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener,
PRBool found = PR_FALSE; PRBool found = PR_FALSE;
nsListenerStruct* ls; nsListenerStruct* ls;
nsresult rv;
nsCOMPtr<nsIScriptEventListener> sel = do_QueryInterface(aListener, &rv);
for (int i=0; i<listeners->Count(); i++) { for (int i=0; i<listeners->Count(); i++) {
ls = (nsListenerStruct*)listeners->ElementAt(i); ls = (nsListenerStruct*)listeners->ElementAt(i);
if (ls->mListener == aListener && ls->mFlags == aFlags && ls->mGroupFlags == group) { if (ls->mListener == aListener && ls->mFlags == aFlags &&
ls->mGroupFlags == group) {
ls->mSubType |= aSubType; ls->mSubType |= aSubType;
found = PR_TRUE; found = PR_TRUE;
break; break;
} }
else if (sel) {
//Listener is an nsIScriptEventListener so we need to use its CheckIfEqual
//method to verify equality.
nsCOMPtr<nsIScriptEventListener> regSel = do_QueryInterface(ls->mListener, &rv);
if (NS_SUCCEEDED(rv) && regSel) {
PRBool equal;
if (NS_SUCCEEDED(regSel->CheckIfEqual(sel, &equal)) && equal) {
if (ls->mFlags & aFlags && ls->mSubType & aSubType) {
found = PR_TRUE;
break;
}
}
}
}
} }
if (!found) { if (!found) {
@ -740,8 +722,6 @@ nsEventListenerManager::RemoveEventListener(nsIDOMEventListener *aListener,
} }
nsListenerStruct* ls; nsListenerStruct* ls;
nsresult rv;
nsCOMPtr<nsIScriptEventListener> sel = do_QueryInterface(aListener, &rv);
PRBool listenerRemoved = PR_FALSE; PRBool listenerRemoved = PR_FALSE;
for (int i=0; i<listeners->Count(); i++) { for (int i=0; i<listeners->Count(); i++) {
@ -756,32 +736,18 @@ nsEventListenerManager::RemoveEventListener(nsIDOMEventListener *aListener,
} }
break; break;
} }
else if (sel) {
//Listener is an nsIScriptEventListener so we need to use its CheckIfEqual
//method to verify equality.
nsCOMPtr<nsIScriptEventListener> regSel = do_QueryInterface(ls->mListener, &rv);
if (NS_SUCCEEDED(rv) && regSel) {
PRBool equal;
if (NS_SUCCEEDED(regSel->CheckIfEqual(sel, &equal)) && equal) {
if (ls->mFlags & aFlags && ls->mSubType & aSubType) {
NS_RELEASE(ls->mListener);
listeners->RemoveElement((void*)ls);
PR_DELETE(ls);
listenerRemoved = PR_TRUE;
break; // otherwise we'd need to adjust loop count...
}
}
}
}
} }
return NS_OK; return NS_OK;
} }
nsresult nsEventListenerManager::AddEventListenerByIID(nsIDOMEventListener *aListener, nsresult
const nsIID& aIID, PRInt32 aFlags) nsEventListenerManager::AddEventListenerByIID(nsIDOMEventListener *aListener,
const nsIID& aIID,
PRInt32 aFlags)
{ {
AddEventListener(aListener, GetTypeForIID(aIID), NS_EVENT_BITS_NONE, nsnull, aFlags, nsnull); AddEventListener(aListener, GetTypeForIID(aIID), NS_EVENT_BITS_NONE, nsnull,
aFlags, nsnull);
return NS_OK; return NS_OK;
} }
@ -790,11 +756,15 @@ nsEventListenerManager::RemoveEventListenerByIID(nsIDOMEventListener *aListener,
const nsIID& aIID, const nsIID& aIID,
PRInt32 aFlags) PRInt32 aFlags)
{ {
RemoveEventListener(aListener, GetTypeForIID(aIID), NS_EVENT_BITS_NONE, nsnull, aFlags, nsnull); RemoveEventListener(aListener, GetTypeForIID(aIID), NS_EVENT_BITS_NONE,
nsnull, aFlags, nsnull);
return NS_OK; return NS_OK;
} }
nsresult nsEventListenerManager::GetIdentifiersForType(nsIAtom* aType, EventArrayType* aArrayType, PRInt32* aFlags) nsresult
nsEventListenerManager::GetIdentifiersForType(nsIAtom* aType,
EventArrayType* aArrayType,
PRInt32* aFlags)
{ {
if (aType == nsLayoutAtoms::onmousedown) { if (aType == nsLayoutAtoms::onmousedown) {
*aArrayType = eEventArrayType_Mouse; *aArrayType = eEventArrayType_Mouse;
@ -1107,18 +1077,62 @@ nsEventListenerManager::SetJSEventListener(nsIScriptContext *aContext,
} }
NS_IMETHODIMP NS_IMETHODIMP
nsEventListenerManager::AddScriptEventListener(nsIScriptContext* aContext, nsEventListenerManager::AddScriptEventListener(nsISupports *aObject,
nsISupports *aObject,
nsIAtom *aName, nsIAtom *aName,
const nsAString& aBody, const nsAString& aBody,
PRBool aDeferCompilation) PRBool aDeferCompilation)
{ {
nsIScriptContext *context = nsnull;
JSContext* cx = nsnull;
nsCOMPtr<nsIContent> content(do_QueryInterface(aObject));
if (content) {
// Try to get context from doc
nsIDocument *doc = content->GetDocument();
nsIScriptGlobalObject *global;
if (doc && (global = doc->GetScriptGlobalObject())) {
context = global->GetContext();
}
} else {
nsCOMPtr<nsIDocument> doc(do_QueryInterface(aObject));
nsCOMPtr<nsIScriptGlobalObject> global;
if (doc) {
global = doc->GetScriptGlobalObject();
} else {
global = do_QueryInterface(aObject);
}
if (global) {
context = global->GetContext();
}
}
if (!context) {
// Get JSContext from stack.
nsCOMPtr<nsIThreadJSContextStack> stack =
do_GetService("@mozilla.org/js/xpc/ContextStack;1");
NS_ENSURE_TRUE(stack, NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(stack->Peek(&cx), NS_ERROR_FAILURE);
if (!cx) {
stack->GetSafeJSContext(&cx);
NS_ENSURE_TRUE(cx, NS_ERROR_FAILURE);
}
context = nsContentUtils::GetDynamicScriptContext(cx);
NS_ENSURE_TRUE(context, NS_ERROR_FAILURE);
}
nsresult rv; nsresult rv;
if (!aDeferCompilation) { if (!aDeferCompilation) {
nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID())); nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID()));
JSContext *cx = (JSContext *)aContext->GetNativeContext(); JSContext *cx = (JSContext *)context->GetNativeContext();
nsCOMPtr<nsIXPConnectJSObjectHolder> holder; nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
@ -1140,7 +1154,7 @@ nsEventListenerManager::AddScriptEventListener(nsIScriptContext* aContext,
if (handlerOwner) { if (handlerOwner) {
rv = handlerOwner->GetCompiledEventHandler(aName, &handler); rv = handlerOwner->GetCompiledEventHandler(aName, &handler);
if (NS_SUCCEEDED(rv) && handler) { if (NS_SUCCEEDED(rv) && handler) {
rv = aContext->BindCompiledEventHandler(scriptObject, aName, handler); rv = context->BindCompiledEventHandler(scriptObject, aName, handler);
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return rv; return rv;
done = PR_TRUE; done = PR_TRUE;
@ -1151,11 +1165,11 @@ nsEventListenerManager::AddScriptEventListener(nsIScriptContext* aContext,
if (handlerOwner) { if (handlerOwner) {
// Always let the handler owner compile the event handler, as // Always let the handler owner compile the event handler, as
// it may want to use a special context or scope object. // it may want to use a special context or scope object.
rv = handlerOwner->CompileEventHandler(aContext, scriptObject, aName, rv = handlerOwner->CompileEventHandler(context, scriptObject, aName,
aBody, nsnull, 0, &handler); aBody, nsnull, 0, &handler);
} }
else { else {
rv = aContext->CompileEventHandler(scriptObject, aName, aBody, rv = context->CompileEventHandler(scriptObject, aName, aBody,
nsnull, 0, nsnull, 0,
(handlerOwner != nsnull), (handlerOwner != nsnull),
&handler); &handler);
@ -1164,7 +1178,7 @@ nsEventListenerManager::AddScriptEventListener(nsIScriptContext* aContext,
} }
} }
return SetJSEventListener(aContext, aObject, aName, aDeferCompilation); return SetJSEventListener(context, aObject, aName, aDeferCompilation);
} }
nsresult nsresult
@ -1392,19 +1406,14 @@ nsEventListenerManager::HandleEventSubType(nsListenerStruct* aListenerStruct,
nsCOMPtr<nsIJSEventListener> jslistener = do_QueryInterface(aListenerStruct->mListener); nsCOMPtr<nsIJSEventListener> jslistener = do_QueryInterface(aListenerStruct->mListener);
if (jslistener) { if (jslistener) {
nsCOMPtr<nsISupports> target;
nsCOMPtr<nsIScriptContext> scriptCX;
result = jslistener->GetEventTarget(getter_AddRefs(scriptCX),
getter_AddRefs(target));
if (NS_SUCCEEDED(result)) {
nsAutoString eventString; nsAutoString eventString;
if (NS_SUCCEEDED(aDOMEvent->GetType(eventString))) { if (NS_SUCCEEDED(aDOMEvent->GetType(eventString))) {
nsCOMPtr<nsIAtom> atom = do_GetAtom(NS_LITERAL_STRING("on") + eventString); nsCOMPtr<nsIAtom> atom = do_GetAtom(NS_LITERAL_STRING("on") + eventString);
result = CompileEventHandlerInternal(scriptCX, target, atom, result = CompileEventHandlerInternal(jslistener->GetEventContext(),
aListenerStruct, aSubType); jslistener->GetEventTarget(),
} atom, aListenerStruct,
aSubType);
} }
} }
} }

Просмотреть файл

@ -123,8 +123,7 @@ public:
const nsAString& type, const nsAString& type,
PRInt32 aFlags, PRInt32 aFlags,
nsIDOMEventGroup* aEvtGroup); nsIDOMEventGroup* aEvtGroup);
NS_IMETHOD AddScriptEventListener(nsIScriptContext *aContext, NS_IMETHOD AddScriptEventListener(nsISupports *aObject,
nsISupports *aObject,
nsIAtom *aName, nsIAtom *aName,
const nsAString& aFunc, const nsAString& aFunc,
PRBool aDeferCompilation); PRBool aDeferCompilation);

Просмотреть файл

@ -865,17 +865,17 @@ nsGenericHTMLElement::SetInnerHTML(const nsAString& aInnerHTML)
nsCOMPtr<nsIDocument> doc = GetOwnerDocument(); nsCOMPtr<nsIDocument> doc = GetOwnerDocument();
nsCOMPtr<nsIScriptContext> scx; nsIScriptContext *scx = nsnull;
PRBool scripts_enabled = PR_FALSE; PRBool scripts_enabled = PR_FALSE;
if (doc) { if (doc) {
nsIScriptGlobalObject *sgo = doc->GetScriptGlobalObject(); nsIScriptGlobalObject *sgo = doc->GetScriptGlobalObject();
if (sgo) { if (sgo) {
sgo->GetContext(getter_AddRefs(scx)); scx = sgo->GetContext();
if (scx) { if (scx) {
scx->GetScriptsEnabled(&scripts_enabled); scripts_enabled = scx->GetScriptsEnabled();
} }
} }
} }

Просмотреть файл

@ -170,10 +170,8 @@ NS_NewHTMLImageElement(nsIHTMLContent** aInstancePtrResult,
nsresult rv; nsresult rv;
nsCOMPtr<nsINodeInfo> nodeInfo(aNodeInfo); nsCOMPtr<nsINodeInfo> nodeInfo(aNodeInfo);
if (!nodeInfo) { if (!nodeInfo) {
nsCOMPtr<nsIDOMDocument> dom_doc; nsCOMPtr<nsIDocument> doc =
nsContentUtils::GetDocumentFromCaller(getter_AddRefs(dom_doc)); do_QueryInterface(nsContentUtils::GetDocumentFromCaller());
nsCOMPtr<nsIDocument> doc(do_QueryInterface(dom_doc));
NS_ENSURE_TRUE(doc, NS_ERROR_UNEXPECTED); NS_ENSURE_TRUE(doc, NS_ERROR_UNEXPECTED);
nsINodeInfoManager *nodeInfoManager = doc->GetNodeInfoManager(); nsINodeInfoManager *nodeInfoManager = doc->GetNodeInfoManager();
@ -454,7 +452,6 @@ NS_IMETHODIMP
nsHTMLImageElement::SetHeight(PRInt32 aHeight) nsHTMLImageElement::SetHeight(PRInt32 aHeight)
{ {
nsAutoString val; nsAutoString val;
val.AppendInt(aHeight); val.AppendInt(aHeight);
return nsGenericHTMLLeafElement::SetAttr(kNameSpaceID_None, return nsGenericHTMLLeafElement::SetAttr(kNameSpaceID_None,
@ -474,7 +471,6 @@ NS_IMETHODIMP
nsHTMLImageElement::SetWidth(PRInt32 aWidth) nsHTMLImageElement::SetWidth(PRInt32 aWidth)
{ {
nsAutoString val; nsAutoString val;
val.AppendInt(aWidth); val.AppendInt(aWidth);
return nsGenericHTMLLeafElement::SetAttr(kNameSpaceID_None, return nsGenericHTMLLeafElement::SetAttr(kNameSpaceID_None,

Просмотреть файл

@ -163,10 +163,8 @@ NS_NewHTMLOptionElement(nsIHTMLContent** aInstancePtrResult,
nsresult rv; nsresult rv;
nsCOMPtr<nsINodeInfo> nodeInfo(aNodeInfo); nsCOMPtr<nsINodeInfo> nodeInfo(aNodeInfo);
if (!nodeInfo) { if (!nodeInfo) {
nsCOMPtr<nsIDOMDocument> dom_doc; nsCOMPtr<nsIDocument> doc =
nsContentUtils::GetDocumentFromCaller(getter_AddRefs(dom_doc)); do_QueryInterface(nsContentUtils::GetDocumentFromCaller());
nsCOMPtr<nsIDocument> doc(do_QueryInterface(dom_doc));
NS_ENSURE_TRUE(doc, NS_ERROR_UNEXPECTED); NS_ENSURE_TRUE(doc, NS_ERROR_UNEXPECTED);
nsINodeInfoManager *nodeInfoManager = doc->GetNodeInfoManager(); nsINodeInfoManager *nodeInfoManager = doc->GetNodeInfoManager();

Просмотреть файл

@ -207,16 +207,15 @@ nsHTMLScriptEventHandler::Invoke(nsISupports *aTargetObject,
// Get the script context... // Get the script context...
nsCOMPtr<nsIDOMDocument> domdoc; nsCOMPtr<nsIDOMDocument> domdoc;
nsCOMPtr<nsIScriptContext> scriptContext; nsIScriptContext *scriptContext = nsnull;
nsCOMPtr<nsIScriptGlobalObject> sgo;
mOuter->GetOwnerDocument(getter_AddRefs(domdoc)); mOuter->GetOwnerDocument(getter_AddRefs(domdoc));
nsCOMPtr<nsIDocument> doc(do_QueryInterface(domdoc)); nsCOMPtr<nsIDocument> doc(do_QueryInterface(domdoc));
if (doc) { if (doc) {
sgo = doc->GetScriptGlobalObject(); nsIScriptGlobalObject *sgo = doc->GetScriptGlobalObject();
if (sgo) { if (sgo) {
sgo->GetContext(getter_AddRefs(scriptContext)); scriptContext = sgo->GetContext();
} }
} }
// Fail if is no script context is available... // Fail if is no script context is available...
@ -280,7 +279,7 @@ nsHTMLScriptEventHandler::Invoke(nsISupports *aTargetObject,
// Compile the event handler script... // Compile the event handler script...
void* funcObject = nsnull; void* funcObject = nsnull;
nsCString funcName(NS_LITERAL_CSTRING("anonymous")); NS_NAMED_LITERAL_CSTRING(funcName, "anonymous");
rv = scriptContext->CompileFunction(scriptObject, rv = scriptContext->CompileFunction(scriptObject,
funcName, // method name funcName, // method name

Просмотреть файл

@ -2093,8 +2093,7 @@ IsScriptEnabled(nsIDocument *aDoc, nsIDocShell *aContainer)
NS_ENSURE_TRUE(globalObject, PR_TRUE); NS_ENSURE_TRUE(globalObject, PR_TRUE);
} }
nsCOMPtr<nsIScriptContext> scriptContext; nsIScriptContext *scriptContext = globalObject->GetContext();
globalObject->GetContext(getter_AddRefs(scriptContext));
NS_ENSURE_TRUE(scriptContext, PR_TRUE); NS_ENSURE_TRUE(scriptContext, PR_TRUE);
JSContext* cx = (JSContext *) scriptContext->GetNativeContext(); JSContext* cx = (JSContext *) scriptContext->GetNativeContext();

Просмотреть файл

@ -999,8 +999,7 @@ nsHTMLDocument::EndLoad()
stack->Peek(&cx); stack->Peek(&cx);
if (cx) { if (cx) {
nsCOMPtr<nsIScriptContext> scx; nsIScriptContext *scx = nsContentUtils::GetDynamicScriptContext(cx);
nsContentUtils::GetDynamicScriptContext(cx, getter_AddRefs(scx));
if (scx) { if (scx) {
// The load of the document was terminated while we're // The load of the document was terminated while we're
@ -2158,8 +2157,7 @@ nsHTMLDocument::GetSourceDocumentURI(nsIURI** sourceURI)
*sourceURI = nsnull; *sourceURI = nsnull;
// XXX This will fail on non-DOM contexts :( // XXX This will fail on non-DOM contexts :(
nsCOMPtr<nsIDOMDocument> domDoc; nsIDOMDocument *domDoc = nsContentUtils::GetDocumentFromCaller();
nsContentUtils::GetDocumentFromCaller(getter_AddRefs(domDoc));
nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDoc)); nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDoc));
if (!doc) { if (!doc) {
@ -3717,8 +3715,7 @@ nsHTMLDocument::SetDesignMode(const nsAString & aDesignMode)
if (!mScriptGlobalObject) if (!mScriptGlobalObject)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
nsCOMPtr<nsIDocShell> docshell; nsIDocShell *docshell = mScriptGlobalObject->GetDocShell();
mScriptGlobalObject->GetDocShell(getter_AddRefs(docshell));
if (!docshell) if (!docshell)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -3788,8 +3785,7 @@ nsHTMLDocument::GetMidasCommandManager(nsICommandManager** aCmdMgr)
if (!mScriptGlobalObject) if (!mScriptGlobalObject)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
nsCOMPtr<nsIDocShell> docshell; nsIDocShell *docshell = mScriptGlobalObject->GetDocShell();
mScriptGlobalObject->GetDocShell(getter_AddRefs(docshell));
if (!docshell) if (!docshell)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;

Просмотреть файл

@ -1143,8 +1143,7 @@ nsBindingManager::GetBindingImplementation(nsIContent* aContent, REFNSIID aIID,
if (!global) if (!global)
return NS_NOINTERFACE; return NS_NOINTERFACE;
nsCOMPtr<nsIScriptContext> context; nsIScriptContext *context = global->GetContext();
global->GetContext(getter_AddRefs(context));
if (!context) if (!context)
return NS_NOINTERFACE; return NS_NOINTERFACE;
@ -1157,7 +1156,6 @@ nsBindingManager::GetBindingImplementation(nsIContent* aContent, REFNSIID aIID,
return NS_NOINTERFACE; return NS_NOINTERFACE;
nsCOMPtr<nsIXPConnectWrappedNative> wrapper; nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
xpConnect->GetWrappedNativeOfNativeObject(jscontext, xpConnect->GetWrappedNativeOfNativeObject(jscontext,
JS_GetGlobalObject(jscontext), JS_GetGlobalObject(jscontext),
aContent, aContent,

Просмотреть файл

@ -958,8 +958,7 @@ nsXBLBinding::ChangeDocument(nsIDocument* aOldDocument, nsIDocument* aNewDocumen
if (interfaceElement) { if (interfaceElement) {
nsIScriptGlobalObject *global = aOldDocument->GetScriptGlobalObject(); nsIScriptGlobalObject *global = aOldDocument->GetScriptGlobalObject();
if (global) { if (global) {
nsCOMPtr<nsIScriptContext> context; nsIScriptContext *context = global->GetContext();
global->GetContext(getter_AddRefs(context));
if (context) { if (context) {
JSContext *jscontext = (JSContext *)context->GetNativeContext(); JSContext *jscontext = (JSContext *)context->GetNativeContext();
@ -1313,32 +1312,16 @@ nsXBLBinding::AddScriptEventListener(nsIContent* aElement, nsIAtom* aName,
nsCOMPtr<nsIAtom> eventName = do_GetAtom(eventStr); nsCOMPtr<nsIAtom> eventName = do_GetAtom(eventStr);
nsresult rv; nsresult rv;
nsCOMPtr<nsIDocument> document = aElement->GetDocument();
if (!document)
return NS_OK;
nsCOMPtr<nsIDOMEventReceiver> receiver(do_QueryInterface(aElement)); nsCOMPtr<nsIDOMEventReceiver> receiver(do_QueryInterface(aElement));
if (!receiver) if (!receiver)
return NS_OK; return NS_OK;
nsIScriptGlobalObject *global = document->GetScriptGlobalObject();
// This can happen normally as part of teardown code.
if (!global)
return NS_OK;
nsCOMPtr<nsIScriptContext> context;
rv = global->GetContext(getter_AddRefs(context));
if (NS_FAILED(rv)) return rv;
if (!context) return NS_OK;
nsCOMPtr<nsIEventListenerManager> manager; nsCOMPtr<nsIEventListenerManager> manager;
rv = receiver->GetListenerManager(getter_AddRefs(manager)); rv = receiver->GetListenerManager(getter_AddRefs(manager));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
rv = manager->AddScriptEventListener(context, receiver, eventName, rv = manager->AddScriptEventListener(receiver, eventName, aValue, PR_FALSE);
aValue, PR_FALSE);
return rv; return rv;
} }

Просмотреть файл

@ -64,24 +64,24 @@ public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
// nsIScriptGlobalObject methods // nsIScriptGlobalObject methods
NS_IMETHOD SetContext(nsIScriptContext *aContext); virtual void SetContext(nsIScriptContext *aContext);
NS_IMETHOD GetContext(nsIScriptContext **aContext); virtual nsIScriptContext *GetContext();
NS_IMETHOD SetNewDocument(nsIDOMDocument *aDocument, virtual nsresult SetNewDocument(nsIDOMDocument *aDocument,
PRBool aRemoveEventListeners, PRBool aRemoveEventListeners,
PRBool aClearScope); PRBool aClearScope);
NS_IMETHOD SetDocShell(nsIDocShell *aDocShell); virtual void SetDocShell(nsIDocShell *aDocShell);
NS_IMETHOD GetDocShell(nsIDocShell **aDocShell); virtual nsIDocShell *GetDocShell();
NS_IMETHOD SetOpenerWindow(nsIDOMWindowInternal *aOpener); virtual void SetOpenerWindow(nsIDOMWindowInternal *aOpener);
NS_IMETHOD SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner); virtual void SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner);
NS_IMETHOD GetGlobalObjectOwner(nsIScriptGlobalObjectOwner** aOwner); virtual nsIScriptGlobalObjectOwner *GetGlobalObjectOwner();
NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext, virtual nsresult HandleDOMEvent(nsIPresContext* aPresContext,
nsEvent* aEvent, nsEvent* aEvent,
nsIDOMEvent** aDOMEvent, nsIDOMEvent** aDOMEvent,
PRUint32 aFlags, PRUint32 aFlags,
nsEventStatus* aEventStatus); nsEventStatus* aEventStatus);
NS_IMETHOD_(JSObject *) GetGlobalJSObject(); virtual JSObject *GetGlobalJSObject();
NS_IMETHOD OnFinalize(JSObject *aObject); virtual void OnFinalize(JSObject *aObject);
NS_IMETHOD SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts); virtual void SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts);
// nsIScriptObjectPrincipal methods // nsIScriptObjectPrincipal methods
NS_IMETHOD GetPrincipal(nsIPrincipal** aPrincipal); NS_IMETHOD GetPrincipal(nsIPrincipal** aPrincipal);
@ -174,7 +174,7 @@ XBL_ProtoErrorReporter(JSContext *cx,
// nsIScriptGlobalObject methods // nsIScriptGlobalObject methods
// //
NS_IMETHODIMP void
nsXBLDocGlobalObject::SetContext(nsIScriptContext *aContext) nsXBLDocGlobalObject::SetContext(nsIScriptContext *aContext)
{ {
mScriptContext = aContext; mScriptContext = aContext;
@ -182,29 +182,28 @@ nsXBLDocGlobalObject::SetContext(nsIScriptContext *aContext)
JSContext* cx = (JSContext *)mScriptContext->GetNativeContext(); JSContext* cx = (JSContext *)mScriptContext->GetNativeContext();
JS_SetErrorReporter(cx, XBL_ProtoErrorReporter); JS_SetErrorReporter(cx, XBL_ProtoErrorReporter);
} }
return NS_OK;
} }
NS_IMETHODIMP nsIScriptContext *
nsXBLDocGlobalObject::GetContext(nsIScriptContext **aContext) nsXBLDocGlobalObject::GetContext()
{ {
// This whole fragile mess is predicated on the fact that // This whole fragile mess is predicated on the fact that
// GetContext() will be called before GetScriptObject() is. // GetContext() will be called before GetScriptObject() is.
if (! mScriptContext) { if (! mScriptContext) {
nsCOMPtr<nsIDOMScriptObjectFactory> factory = do_GetService(kDOMScriptObjectFactoryCID); nsCOMPtr<nsIDOMScriptObjectFactory> factory = do_GetService(kDOMScriptObjectFactoryCID);
NS_ENSURE_TRUE(factory, NS_ERROR_FAILURE); NS_ENSURE_TRUE(factory, nsnull);
nsresult rv = factory->NewScriptContext(nsnull, getter_AddRefs(mScriptContext)); nsresult rv = factory->NewScriptContext(nsnull, getter_AddRefs(mScriptContext));
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return rv; return nsnull;
JSContext *cx = (JSContext *)mScriptContext->GetNativeContext(); JSContext *cx = (JSContext *)mScriptContext->GetNativeContext();
JS_SetErrorReporter(cx, XBL_ProtoErrorReporter); JS_SetErrorReporter(cx, XBL_ProtoErrorReporter);
mJSObject = ::JS_NewObject(cx, &gSharedGlobalClass, nsnull, nsnull); mJSObject = ::JS_NewObject(cx, &gSharedGlobalClass, nsnull, nsnull);
if (!mJSObject) if (!mJSObject)
return NS_ERROR_OUT_OF_MEMORY; return nsnull;
::JS_SetGlobalObject(cx, mJSObject); ::JS_SetGlobalObject(cx, mJSObject);
@ -214,13 +213,11 @@ nsXBLDocGlobalObject::GetContext(nsIScriptContext **aContext)
NS_ADDREF(this); NS_ADDREF(this);
} }
*aContext = mScriptContext; return mScriptContext;
NS_IF_ADDREF(*aContext);
return NS_OK;
} }
NS_IMETHODIMP nsresult
nsXBLDocGlobalObject::SetNewDocument(nsIDOMDocument *aDocument, nsXBLDocGlobalObject::SetNewDocument(nsIDOMDocument *aDocument,
PRBool aRemoveEventListeners, PRBool aRemoveEventListeners,
PRBool aClearScope) PRBool aClearScope)
@ -230,48 +227,43 @@ nsXBLDocGlobalObject::SetNewDocument(nsIDOMDocument *aDocument,
} }
NS_IMETHODIMP void
nsXBLDocGlobalObject::SetDocShell(nsIDocShell *aDocShell) nsXBLDocGlobalObject::SetDocShell(nsIDocShell *aDocShell)
{ {
NS_NOTREACHED("waaah!"); NS_NOTREACHED("waaah!");
return NS_ERROR_UNEXPECTED;
} }
NS_IMETHODIMP nsIDocShell *
nsXBLDocGlobalObject::GetDocShell(nsIDocShell **aDocShell) nsXBLDocGlobalObject::GetDocShell()
{ {
NS_WARNING("waaah!"); NS_WARNING("waaah!");
return NS_ERROR_UNEXPECTED; return nsnull;
} }
NS_IMETHODIMP void
nsXBLDocGlobalObject::SetOpenerWindow(nsIDOMWindowInternal *aOpener) nsXBLDocGlobalObject::SetOpenerWindow(nsIDOMWindowInternal *aOpener)
{ {
NS_NOTREACHED("waaah!"); NS_NOTREACHED("waaah!");
return NS_ERROR_UNEXPECTED;
} }
NS_IMETHODIMP void
nsXBLDocGlobalObject::SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner) nsXBLDocGlobalObject::SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner)
{ {
mGlobalObjectOwner = aOwner; // weak reference mGlobalObjectOwner = aOwner; // weak reference
return NS_OK;
} }
NS_IMETHODIMP nsIScriptGlobalObjectOwner *
nsXBLDocGlobalObject::GetGlobalObjectOwner(nsIScriptGlobalObjectOwner** aOwner) nsXBLDocGlobalObject::GetGlobalObjectOwner()
{ {
*aOwner = mGlobalObjectOwner; return mGlobalObjectOwner;
NS_IF_ADDREF(*aOwner);
return NS_OK;
} }
NS_IMETHODIMP nsresult
nsXBLDocGlobalObject::HandleDOMEvent(nsIPresContext* aPresContext, nsXBLDocGlobalObject::HandleDOMEvent(nsIPresContext* aPresContext,
nsEvent* aEvent, nsEvent* aEvent,
nsIDOMEvent** aDOMEvent, nsIDOMEvent** aDOMEvent,
@ -282,7 +274,7 @@ nsXBLDocGlobalObject::HandleDOMEvent(nsIPresContext* aPresContext,
return NS_ERROR_UNEXPECTED; return NS_ERROR_UNEXPECTED;
} }
NS_IMETHODIMP_(JSObject *) JSObject *
nsXBLDocGlobalObject::GetGlobalJSObject() nsXBLDocGlobalObject::GetGlobalJSObject()
{ {
// The prototype document has its own special secret script object // The prototype document has its own special secret script object
@ -299,22 +291,18 @@ nsXBLDocGlobalObject::GetGlobalJSObject()
return ::JS_GetGlobalObject(cx); return ::JS_GetGlobalObject(cx);
} }
NS_IMETHODIMP void
nsXBLDocGlobalObject::OnFinalize(JSObject *aObject) nsXBLDocGlobalObject::OnFinalize(JSObject *aObject)
{ {
NS_ASSERTION(aObject == mJSObject, "Wrong object finalized!"); NS_ASSERTION(aObject == mJSObject, "Wrong object finalized!");
mJSObject = nsnull; mJSObject = nsnull;
return NS_OK;
} }
NS_IMETHODIMP void
nsXBLDocGlobalObject::SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts) nsXBLDocGlobalObject::SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts)
{ {
// We don't care... // We don't care...
return NS_OK;
} }

Просмотреть файл

@ -62,10 +62,7 @@ nsXBLProtoImpl::InstallImplementation(nsXBLPrototypeBinding* aBinding, nsIConten
nsIScriptGlobalObject *global = document->GetScriptGlobalObject(); nsIScriptGlobalObject *global = document->GetScriptGlobalObject();
if (!global) return NS_OK; if (!global) return NS_OK;
nsCOMPtr<nsIScriptContext> context; nsIScriptContext *context = global->GetContext();
nsresult rv = global->GetContext(getter_AddRefs(context));
NS_ENSURE_SUCCESS(rv, rv);
if (!context) return NS_OK; if (!context) return NS_OK;
// InitTarget objects gives us back the JS object that represents the bound element and the // InitTarget objects gives us back the JS object that represents the bound element and the
@ -74,7 +71,8 @@ nsXBLProtoImpl::InstallImplementation(nsXBLPrototypeBinding* aBinding, nsIConten
// not been built already. // not been built already.
void * targetScriptObject = nsnull; void * targetScriptObject = nsnull;
void * targetClassObject = nsnull; void * targetClassObject = nsnull;
rv = InitTargetObjects(aBinding, context, aBoundElement, &targetScriptObject, &targetClassObject); nsresult rv = InitTargetObjects(aBinding, context, aBoundElement,
&targetScriptObject, &targetClassObject);
NS_ENSURE_SUCCESS(rv, rv); // kick out if we were unable to properly intialize our target objects NS_ENSURE_SUCCESS(rv, rv); // kick out if we were unable to properly intialize our target objects
// Walk our member list and install each one in turn. // Walk our member list and install each one in turn.
@ -153,8 +151,7 @@ nsXBLProtoImpl::CompilePrototypeMembers(nsXBLPrototypeBinding* aBinding)
nsCOMPtr<nsIScriptGlobalObject> globalObject; nsCOMPtr<nsIScriptGlobalObject> globalObject;
globalOwner->GetScriptGlobalObject(getter_AddRefs(globalObject)); globalOwner->GetScriptGlobalObject(getter_AddRefs(globalObject));
nsCOMPtr<nsIScriptContext> context; nsIScriptContext *context = globalObject->GetContext();
globalObject->GetContext(getter_AddRefs(context));
void* classObject; void* classObject;
JSObject* scopeObject = globalObject->GetGlobalJSObject(); JSObject* scopeObject = globalObject->GetGlobalJSObject();

Просмотреть файл

@ -395,8 +395,7 @@ nsXBLPrototypeHandler::ExecuteHandler(nsIDOMEventReceiver* aReceiver,
if (!boundGlobal) if (!boundGlobal)
return NS_OK; return NS_OK;
nsCOMPtr<nsIScriptContext> boundContext; nsIScriptContext *boundContext = boundGlobal->GetContext();
boundGlobal->GetContext(getter_AddRefs(boundContext));
if (!boundContext) return NS_OK; if (!boundContext) return NS_OK;
JSObject* scriptObject = nsnull; JSObject* scriptObject = nsnull;

Просмотреть файл

@ -248,8 +248,7 @@ nsXBLWindowHandler :: IsEditor()
return PR_FALSE; return PR_FALSE;
nsCOMPtr<nsIScriptGlobalObject> obj(do_QueryInterface(focusedWindow)); nsCOMPtr<nsIScriptGlobalObject> obj(do_QueryInterface(focusedWindow));
nsCOMPtr<nsIDocShell> docShell; nsIDocShell *docShell = obj->GetDocShell();
obj->GetDocShell(getter_AddRefs(docShell));
nsCOMPtr<nsIPresShell> presShell; nsCOMPtr<nsIPresShell> presShell;
if (docShell) if (docShell)
docShell->GetPresShell(getter_AddRefs(presShell)); docShell->GetPresShell(getter_AddRefs(presShell));

Просмотреть файл

@ -340,9 +340,9 @@ nsXMLDocument::GetLoadGroup(nsILoadGroup **aLoadGroup)
*aLoadGroup = nsnull; *aLoadGroup = nsnull;
if (mScriptContext) { if (mScriptContext) {
nsCOMPtr<nsIScriptGlobalObject> global; nsCOMPtr<nsIDOMWindow> window =
mScriptContext->GetGlobalObject(getter_AddRefs(global)); do_QueryInterface(mScriptContext->GetGlobalObject());
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(global);
if (window) { if (window) {
nsCOMPtr<nsIDOMDocument> domdoc; nsCOMPtr<nsIDOMDocument> domdoc;
window->GetDocument(getter_AddRefs(domdoc)); window->GetDocument(getter_AddRefs(domdoc));
@ -381,15 +381,14 @@ nsXMLDocument::Load(const nsAString& aUrl, PRBool *aReturn)
mPrincipal = principal; mPrincipal = principal;
mListenerManager = elm; mListenerManager = elm;
nsCOMPtr<nsIScriptContext> callingContext; nsIScriptContext *callingContext = nsnull;
nsCOMPtr<nsIJSContextStack> stack = nsCOMPtr<nsIJSContextStack> stack =
do_GetService("@mozilla.org/js/xpc/ContextStack;1"); do_GetService("@mozilla.org/js/xpc/ContextStack;1");
if (stack) { if (stack) {
JSContext *cx; JSContext *cx;
if (NS_SUCCEEDED(stack->Peek(&cx)) && cx) { if (NS_SUCCEEDED(stack->Peek(&cx)) && cx) {
nsContentUtils::GetDynamicScriptContext(cx, callingContext = nsContentUtils::GetDynamicScriptContext(cx);
getter_AddRefs(callingContext));
} }
} }
@ -397,10 +396,8 @@ nsXMLDocument::Load(const nsAString& aUrl, PRBool *aReturn)
nsCAutoString charset; nsCAutoString charset;
if (callingContext) { if (callingContext) {
nsCOMPtr<nsIScriptGlobalObject> sgo; nsCOMPtr<nsIDOMWindow> window =
callingContext->GetGlobalObject(getter_AddRefs(sgo)); do_QueryInterface(callingContext->GetGlobalObject());
nsCOMPtr<nsIDOMWindow> window(do_QueryInterface(sgo));
if (window) { if (window) {
nsCOMPtr<nsIDOMDocument> dom_doc; nsCOMPtr<nsIDOMDocument> dom_doc;

Просмотреть файл

@ -301,6 +301,13 @@ static EventHandlerMapEntry kEventHandlerMap[] = {
static PRBool static PRBool
IsEventHandler(nsIAtom* aName) IsEventHandler(nsIAtom* aName)
{ {
const char* name;
aName->GetUTF8String(&name);
if (name[0] != 'o' || name[1] != 'n') {
return PR_FALSE;
}
EventHandlerMapEntry* entry = kEventHandlerMap; EventHandlerMapEntry* entry = kEventHandlerMap;
while (entry->mAttributeAtom) { while (entry->mAttributeAtom) {
if (entry->mAttributeAtom == aName) { if (entry->mAttributeAtom == aName) {
@ -1380,63 +1387,51 @@ nsXULElement::GetLazyState(LazyState aFlag, PRBool& aResult)
NS_IMETHODIMP NS_IMETHODIMP
nsXULElement::AddScriptEventListener(nsIAtom* aName, nsXULElement::AddScriptEventListener(nsIAtom* aName, const nsAString& aValue)
const nsAString& aValue)
{ {
if (! mDocument) if (! mDocument)
return NS_OK; // XXX return NS_OK; // XXX
nsresult rv; nsresult rv;
nsCOMPtr<nsIScriptContext> context;
nsIScriptGlobalObject *global = mDocument->GetScriptGlobalObject();
// This can happen normally as part of teardown code. nsISupports *target = NS_STATIC_CAST(nsIContent *, this);
if (! global) PRBool defer = PR_TRUE;
return NS_OK;
rv = global->GetContext(getter_AddRefs(context)); nsCOMPtr<nsIEventListenerManager> manager;
if (NS_FAILED(rv)) return rv;
if (!context) return NS_OK;
nsIContent *root = mDocument->GetRootContent(); nsIContent *root = mDocument->GetRootContent();
nsCOMPtr<nsIContent> content(do_QueryInterface(NS_STATIC_CAST(nsIStyledContent*, this))); nsCOMPtr<nsIContent> content(do_QueryInterface(NS_STATIC_CAST(nsIStyledContent*, this)));
if ((!root || root == content) && !NodeInfo()->Equals(nsXULAtoms::overlay)) { if ((!root || root == content) && !NodeInfo()->Equals(nsXULAtoms::overlay)) {
nsIScriptGlobalObject *global = mDocument->GetScriptGlobalObject();
nsCOMPtr<nsIDOMEventReceiver> receiver = do_QueryInterface(global); nsCOMPtr<nsIDOMEventReceiver> receiver = do_QueryInterface(global);
if (! receiver) if (! receiver)
return NS_ERROR_UNEXPECTED; return NS_ERROR_UNEXPECTED;
nsCOMPtr<nsIEventListenerManager> manager;
rv = receiver->GetListenerManager(getter_AddRefs(manager)); rv = receiver->GetListenerManager(getter_AddRefs(manager));
if (NS_FAILED(rv)) return rv;
rv = manager->AddScriptEventListener(context, global, aName, target = global;
aValue, PR_FALSE); defer = PR_FALSE;
} }
else { else {
nsCOMPtr<nsIEventListenerManager> manager;
rv = GetListenerManager(getter_AddRefs(manager)); rv = GetListenerManager(getter_AddRefs(manager));
if (NS_FAILED(rv)) return rv;
rv = manager->AddScriptEventListener(context,
NS_STATIC_CAST(nsIContent *,
this),
aName, aValue, PR_TRUE);
} }
return rv; if (NS_FAILED(rv)) return rv;
return manager->AddScriptEventListener(target, aName, aValue, defer);
} }
nsresult nsresult
nsXULElement::GetListenerManager(nsIEventListenerManager** aResult) nsXULElement::GetListenerManager(nsIEventListenerManager** aResult)
{ {
if (!mListenerManager) { if (!mListenerManager) {
nsresult rv; nsresult rv =
mListenerManager = do_CreateInstance(kEventListenerManagerCID, &rv); NS_NewEventListenerManager(getter_AddRefs(mListenerManager));
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return rv; return rv;
mListenerManager->SetListenerTarget(NS_STATIC_CAST(nsIStyledContent*, this)); mListenerManager->SetListenerTarget(NS_STATIC_CAST(nsIContent*, this));
} }
*aResult = mListenerManager; *aResult = mListenerManager;
@ -1448,7 +1443,7 @@ nsXULElement::GetListenerManager(nsIEventListenerManager** aResult)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// nsIScriptEventHandlerOwner interface // nsIScriptEventHandlerOwner interface
NS_IMETHODIMP nsresult
nsXULElement::GetCompiledEventHandler(nsIAtom *aName, void** aHandler) nsXULElement::GetCompiledEventHandler(nsIAtom *aName, void** aHandler)
{ {
XUL_PROTOTYPE_ATTRIBUTE_METER(gNumCacheTests); XUL_PROTOTYPE_ATTRIBUTE_METER(gNumCacheTests);
@ -1467,7 +1462,7 @@ nsXULElement::GetCompiledEventHandler(nsIAtom *aName, void** aHandler)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP nsresult
nsXULElement::CompileEventHandler(nsIScriptContext* aContext, nsXULElement::CompileEventHandler(nsIScriptContext* aContext,
void* aTarget, void* aTarget,
nsIAtom *aName, nsIAtom *aName,
@ -1481,7 +1476,7 @@ nsXULElement::CompileEventHandler(nsIScriptContext* aContext,
XUL_PROTOTYPE_ATTRIBUTE_METER(gNumCacheSets); XUL_PROTOTYPE_ATTRIBUTE_METER(gNumCacheSets);
nsCOMPtr<nsIScriptContext> context; nsIScriptContext *context;
if (mPrototype) { if (mPrototype) {
// It'll be shared among the instances of the prototype. // It'll be shared among the instances of the prototype.
// Use null for the scope object when precompiling shared // Use null for the scope object when precompiling shared
@ -1509,8 +1504,7 @@ nsXULElement::CompileEventHandler(nsIScriptContext* aContext,
globalOwner->GetScriptGlobalObject(getter_AddRefs(global)); globalOwner->GetScriptGlobalObject(getter_AddRefs(global));
NS_ENSURE_TRUE(global, NS_ERROR_UNEXPECTED); NS_ENSURE_TRUE(global, NS_ERROR_UNEXPECTED);
rv = global->GetContext(getter_AddRefs(context)); context = global->GetContext();
NS_ENSURE_SUCCESS(rv, rv);
} }
else { else {
// We don't have a prototype; do a one-off compile. // We don't have a prototype; do a one-off compile.
@ -1528,6 +1522,8 @@ nsXULElement::CompileEventHandler(nsIScriptContext* aContext,
if (! scopeObject) { if (! scopeObject) {
// If it's a shared handler, we need to bind the shared // If it's a shared handler, we need to bind the shared
// function object to the real target. // function object to the real target.
// XXX: Shouldn't this use context and not aContext?
rv = aContext->BindCompiledEventHandler(aTarget, aName, *aHandler); rv = aContext->BindCompiledEventHandler(aTarget, aName, *aHandler);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
} }
@ -4934,19 +4930,18 @@ nsXULPrototypeScript::Compile(const PRUnichar* aText,
nsresult rv; nsresult rv;
// Use the prototype document's special context // Use the prototype document's special context
nsCOMPtr<nsIScriptContext> context; nsIScriptContext *context = nsnull;
{ {
nsCOMPtr<nsIScriptGlobalObject> global;
nsCOMPtr<nsIScriptGlobalObjectOwner> globalOwner nsCOMPtr<nsIScriptGlobalObjectOwner> globalOwner
= do_QueryInterface(aPrototypeDocument); = do_QueryInterface(aPrototypeDocument);
nsCOMPtr<nsIScriptGlobalObject> global;
globalOwner->GetScriptGlobalObject(getter_AddRefs(global)); globalOwner->GetScriptGlobalObject(getter_AddRefs(global));
NS_ASSERTION(global != nsnull, "prototype doc has no script global"); NS_ASSERTION(global != nsnull, "prototype doc has no script global");
if (! global) if (! global)
return NS_ERROR_UNEXPECTED; return NS_ERROR_UNEXPECTED;
rv = global->GetContext(getter_AddRefs(context)); context = global->GetContext();
if (NS_FAILED(rv)) return rv;
NS_ASSERTION(context != nsnull, "no context for script global"); NS_ASSERTION(context != nsnull, "no context for script global");
if (! context) if (! context)

Просмотреть файл

@ -539,14 +539,14 @@ public:
NS_DECL_NSIDOMXULELEMENT NS_DECL_NSIDOMXULELEMENT
// nsIScriptEventHandlerOwner // nsIScriptEventHandlerOwner
NS_IMETHOD CompileEventHandler(nsIScriptContext* aContext, nsresult CompileEventHandler(nsIScriptContext* aContext,
void* aTarget, void* aTarget,
nsIAtom *aName, nsIAtom *aName,
const nsAString& aBody, const nsAString& aBody,
const char* aURL, const char* aURL,
PRUint32 aLineNo, PRUint32 aLineNo,
void** aHandler); void** aHandler);
NS_IMETHOD GetCompiledEventHandler(nsIAtom *aName, void** aHandler); nsresult GetCompiledEventHandler(nsIAtom *aName, void** aHandler);
// nsIChromeEventHandler // nsIChromeEventHandler
NS_DECL_NSICHROMEEVENTHANDLER NS_DECL_NSICHROMEEVENTHANDLER

Просмотреть файл

@ -554,13 +554,10 @@ XULPopupListenerImpl::LaunchPopup(PRInt32 aClientX, PRInt32 aClientY)
return NS_OK; return NS_OK;
// We have some popup content. Obtain our window. // We have some popup content. Obtain our window.
nsCOMPtr<nsIScriptContext> context; nsCOMPtr<nsIDOMWindowInternal> domWindow =
nsCOMPtr<nsIScriptGlobalObject> global = document->GetScriptGlobalObject(); do_QueryInterface(document->GetScriptGlobalObject());
if (global) {
if ((NS_OK == global->GetContext(getter_AddRefs(context))) && context) { if (domWindow) {
// Get the DOM window
nsCOMPtr<nsIDOMWindowInternal> domWindow = do_QueryInterface(global);
if (domWindow != nsnull) {
// Find out if we're anchored. // Find out if we're anchored.
mPopupContent = popupContent.get(); mPopupContent = popupContent.get();
@ -585,8 +582,6 @@ XULPopupListenerImpl::LaunchPopup(PRInt32 aClientX, PRInt32 aClientY)
type.get(), anchorAlignment.get(), type.get(), anchorAlignment.get(),
popupAlignment.get()); popupAlignment.get());
} }
}
}
return NS_OK; return NS_OK;
} }

Просмотреть файл

@ -1446,8 +1446,7 @@ XULContentSinkImpl::OpenScript(const PRUnichar** aAttributes,
if (doc) { if (doc) {
nsIScriptGlobalObject* globalObject = doc->GetScriptGlobalObject(); nsIScriptGlobalObject* globalObject = doc->GetScriptGlobalObject();
if (globalObject) { if (globalObject) {
nsCOMPtr<nsIScriptContext> scriptContext; nsIScriptContext *scriptContext = globalObject->GetContext();
globalObject->GetContext(getter_AddRefs(scriptContext));
if (scriptContext) if (scriptContext)
script->DeserializeOutOfLine(nsnull, scriptContext); script->DeserializeOutOfLine(nsnull, scriptContext);
} }

Просмотреть файл

@ -3252,8 +3252,7 @@ nsXULDocument::OnStreamComplete(nsIStreamLoader* aLoader,
NS_ASSERTION(global != nsnull, "master prototype w/o global?!"); NS_ASSERTION(global != nsnull, "master prototype w/o global?!");
if (global) { if (global) {
nsCOMPtr<nsIScriptContext> scriptContext; nsIScriptContext *scriptContext = global->GetContext();
global->GetContext(getter_AddRefs(scriptContext));
if (scriptContext) if (scriptContext)
scriptProto->SerializeOutOfLine(nsnull, scriptContext); scriptProto->SerializeOutOfLine(nsnull, scriptContext);
} }
@ -3303,19 +3302,14 @@ nsXULDocument::ExecuteScript(JSObject* aScriptObject)
return NS_ERROR_NULL_POINTER; return NS_ERROR_NULL_POINTER;
// Execute the precompiled script with the given version // Execute the precompiled script with the given version
nsresult rv; nsresult rv = NS_ERROR_UNEXPECTED;
NS_ASSERTION(mScriptGlobalObject != nsnull, "no script global object"); NS_ASSERTION(mScriptGlobalObject != nsnull, "no script global object");
if (! mScriptGlobalObject)
return NS_ERROR_UNEXPECTED;
nsCOMPtr<nsIScriptContext> context;
rv = mScriptGlobalObject->GetContext(getter_AddRefs(context));
if (NS_FAILED(rv)) return rv;
if (! context) return NS_ERROR_UNEXPECTED;
nsIScriptContext *context;
if (mScriptGlobalObject && (context = mScriptGlobalObject->GetContext()))
rv = context->ExecuteScript(aScriptObject, nsnull, nsnull, nsnull); rv = context->ExecuteScript(aScriptObject, nsnull, nsnull, nsnull);
return rv; return rv;
} }

Просмотреть файл

@ -85,24 +85,24 @@ public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
// nsIScriptGlobalObject methods // nsIScriptGlobalObject methods
NS_IMETHOD SetContext(nsIScriptContext *aContext); virtual void SetContext(nsIScriptContext *aContext);
NS_IMETHOD GetContext(nsIScriptContext **aContext); virtual nsIScriptContext *GetContext();
NS_IMETHOD SetNewDocument(nsIDOMDocument *aDocument, virtual nsresult SetNewDocument(nsIDOMDocument *aDocument,
PRBool aRemoveEventListeners, PRBool aRemoveEventListeners,
PRBool aClearScope); PRBool aClearScope);
NS_IMETHOD SetDocShell(nsIDocShell *aDocShell); virtual void SetDocShell(nsIDocShell *aDocShell);
NS_IMETHOD GetDocShell(nsIDocShell **aDocShell); virtual nsIDocShell *GetDocShell();
NS_IMETHOD SetOpenerWindow(nsIDOMWindowInternal *aOpener); virtual void SetOpenerWindow(nsIDOMWindowInternal *aOpener);
NS_IMETHOD SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner); virtual void SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner);
NS_IMETHOD GetGlobalObjectOwner(nsIScriptGlobalObjectOwner** aOwner); virtual nsIScriptGlobalObjectOwner *GetGlobalObjectOwner();
NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext, virtual nsresult HandleDOMEvent(nsIPresContext* aPresContext,
nsEvent* aEvent, nsEvent* aEvent,
nsIDOMEvent** aDOMEvent, nsIDOMEvent** aDOMEvent,
PRUint32 aFlags, PRUint32 aFlags,
nsEventStatus* aEventStatus); nsEventStatus* aEventStatus);
NS_IMETHOD_(JSObject *) GetGlobalJSObject(); virtual JSObject *GetGlobalJSObject();
NS_IMETHOD OnFinalize(JSObject *aObject); virtual void OnFinalize(JSObject *aObject);
NS_IMETHOD SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts); virtual void SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts);
// nsIScriptObjectPrincipal methods // nsIScriptObjectPrincipal methods
NS_IMETHOD GetPrincipal(nsIPrincipal** aPrincipal); NS_IMETHOD GetPrincipal(nsIPrincipal** aPrincipal);
@ -406,8 +406,7 @@ nsXULPrototypeDocument::Read(nsIObjectInputStream* aStream)
if (! mRoot) if (! mRoot)
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
nsCOMPtr<nsIScriptContext> scriptContext; nsIScriptContext *scriptContext = mGlobalObject->GetContext();
rv |= mGlobalObject->GetContext(getter_AddRefs(scriptContext));
NS_ASSERTION(scriptContext != nsnull, NS_ASSERTION(scriptContext != nsnull,
"no prototype script context!"); "no prototype script context!");
@ -501,8 +500,7 @@ nsXULPrototypeDocument::Write(nsIObjectOutputStream* aStream)
nsCOMPtr<nsIScriptGlobalObject> globalObject; nsCOMPtr<nsIScriptGlobalObject> globalObject;
rv |= GetScriptGlobalObject(getter_AddRefs(globalObject)); rv |= GetScriptGlobalObject(getter_AddRefs(globalObject));
nsCOMPtr<nsIScriptContext> scriptContext; nsIScriptContext *scriptContext = globalObject->GetContext();
rv |= globalObject->GetContext(getter_AddRefs(scriptContext));
if (mRoot) if (mRoot)
rv |= mRoot->Serialize(aStream, scriptContext, &nodeInfos); rv |= mRoot->Serialize(aStream, scriptContext, &nodeInfos);
@ -791,34 +789,33 @@ NS_INTERFACE_MAP_END
// nsIScriptGlobalObject methods // nsIScriptGlobalObject methods
// //
NS_IMETHODIMP void
nsXULPDGlobalObject::SetContext(nsIScriptContext *aContext) nsXULPDGlobalObject::SetContext(nsIScriptContext *aContext)
{ {
mScriptContext = aContext; mScriptContext = aContext;
return NS_OK;
} }
NS_IMETHODIMP nsIScriptContext *
nsXULPDGlobalObject::GetContext(nsIScriptContext **aContext) nsXULPDGlobalObject::GetContext()
{ {
// This whole fragile mess is predicated on the fact that // This whole fragile mess is predicated on the fact that
// GetContext() will be called before GetScriptObject() is. // GetContext() will be called before GetScriptObject() is.
if (! mScriptContext) { if (! mScriptContext) {
nsCOMPtr<nsIDOMScriptObjectFactory> factory = nsCOMPtr<nsIDOMScriptObjectFactory> factory =
do_GetService(kDOMScriptObjectFactoryCID); do_GetService(kDOMScriptObjectFactoryCID);
NS_ENSURE_TRUE(factory, NS_ERROR_FAILURE); NS_ENSURE_TRUE(factory, nsnull);
nsresult rv = nsresult rv =
factory->NewScriptContext(nsnull, getter_AddRefs(mScriptContext)); factory->NewScriptContext(nsnull, getter_AddRefs(mScriptContext));
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return rv; return nsnull;
JSContext *cx = (JSContext *)mScriptContext->GetNativeContext(); JSContext *cx = (JSContext *)mScriptContext->GetNativeContext();
mJSObject = ::JS_NewObject(cx, &gSharedGlobalClass, nsnull, nsnull); mJSObject = ::JS_NewObject(cx, &gSharedGlobalClass, nsnull, nsnull);
if (!mJSObject) if (!mJSObject)
return NS_ERROR_OUT_OF_MEMORY; return nsnull;
::JS_SetGlobalObject(cx, mJSObject); ::JS_SetGlobalObject(cx, mJSObject);
@ -828,13 +825,11 @@ nsXULPDGlobalObject::GetContext(nsIScriptContext **aContext)
NS_ADDREF(this); NS_ADDREF(this);
} }
*aContext = mScriptContext; return mScriptContext;
NS_IF_ADDREF(*aContext);
return NS_OK;
} }
NS_IMETHODIMP nsresult
nsXULPDGlobalObject::SetNewDocument(nsIDOMDocument *aDocument, nsXULPDGlobalObject::SetNewDocument(nsIDOMDocument *aDocument,
PRBool aRemoveEventListeners, PRBool aRemoveEventListeners,
PRBool aClearScope) PRBool aClearScope)
@ -844,48 +839,44 @@ nsXULPDGlobalObject::SetNewDocument(nsIDOMDocument *aDocument,
} }
NS_IMETHODIMP void
nsXULPDGlobalObject::SetDocShell(nsIDocShell *aDocShell) nsXULPDGlobalObject::SetDocShell(nsIDocShell *aDocShell)
{ {
NS_NOTREACHED("waaah!"); NS_NOTREACHED("waaah!");
return NS_ERROR_UNEXPECTED;
} }
NS_IMETHODIMP nsIDocShell *
nsXULPDGlobalObject::GetDocShell(nsIDocShell **aDocShell) nsXULPDGlobalObject::GetDocShell()
{ {
NS_WARNING("waaah!"); NS_WARNING("waaah!");
return NS_ERROR_UNEXPECTED;
return nsnull;
} }
NS_IMETHODIMP void
nsXULPDGlobalObject::SetOpenerWindow(nsIDOMWindowInternal *aOpener) nsXULPDGlobalObject::SetOpenerWindow(nsIDOMWindowInternal *aOpener)
{ {
NS_NOTREACHED("waaah!"); NS_NOTREACHED("waaah!");
return NS_ERROR_UNEXPECTED;
} }
NS_IMETHODIMP void
nsXULPDGlobalObject::SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner) nsXULPDGlobalObject::SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner)
{ {
mGlobalObjectOwner = aOwner; // weak reference mGlobalObjectOwner = aOwner; // weak reference
return NS_OK;
} }
NS_IMETHODIMP nsIScriptGlobalObjectOwner *
nsXULPDGlobalObject::GetGlobalObjectOwner(nsIScriptGlobalObjectOwner** aOwner) nsXULPDGlobalObject::GetGlobalObjectOwner()
{ {
*aOwner = mGlobalObjectOwner; return mGlobalObjectOwner;
NS_IF_ADDREF(*aOwner);
return NS_OK;
} }
NS_IMETHODIMP nsresult
nsXULPDGlobalObject::HandleDOMEvent(nsIPresContext* aPresContext, nsXULPDGlobalObject::HandleDOMEvent(nsIPresContext* aPresContext,
nsEvent* aEvent, nsEvent* aEvent,
nsIDOMEvent** aDOMEvent, nsIDOMEvent** aDOMEvent,
@ -896,7 +887,7 @@ nsXULPDGlobalObject::HandleDOMEvent(nsIPresContext* aPresContext,
return NS_ERROR_UNEXPECTED; return NS_ERROR_UNEXPECTED;
} }
NS_IMETHODIMP_(JSObject *) JSObject *
nsXULPDGlobalObject::GetGlobalJSObject() nsXULPDGlobalObject::GetGlobalJSObject()
{ {
// The prototype document has its own special secret script object // The prototype document has its own special secret script object
@ -913,22 +904,18 @@ nsXULPDGlobalObject::GetGlobalJSObject()
return ::JS_GetGlobalObject(cx); return ::JS_GetGlobalObject(cx);
} }
NS_IMETHODIMP void
nsXULPDGlobalObject::OnFinalize(JSObject *aObject) nsXULPDGlobalObject::OnFinalize(JSObject *aObject)
{ {
NS_ASSERTION(aObject == mJSObject, "Wrong object finalized!"); NS_ASSERTION(aObject == mJSObject, "Wrong object finalized!");
mJSObject = nsnull; mJSObject = nsnull;
return NS_OK;
} }
NS_IMETHODIMP void
nsXULPDGlobalObject::SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts) nsXULPDGlobalObject::SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts)
{ {
// We don't care... // We don't care...
return NS_OK;
} }

Просмотреть файл

@ -790,8 +790,7 @@ nsXULTemplateBuilder::InitHTMLTemplateRoot()
if (! global) if (! global)
return NS_ERROR_UNEXPECTED; return NS_ERROR_UNEXPECTED;
nsCOMPtr<nsIScriptContext> context; nsIScriptContext *context = global->GetContext();
global->GetContext(getter_AddRefs(context));
if (! context) if (! context)
return NS_ERROR_UNEXPECTED; return NS_ERROR_UNEXPECTED;

Просмотреть файл

@ -1096,10 +1096,12 @@ nsresult nsDocShell::FindTarget(const PRUnichar *aWindowTarget,
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
// This will AddRef() aResult... // This will AddRef() aResult...
rv = sgo->GetDocShell(aResult); *aResult = sgo->GetDocShell();
// If all went well, indicate that a new window has been created. // If all went well, indicate that a new window has been created.
if (*aResult) { if (*aResult) {
NS_ADDREF(*aResult);
*aIsNewWindow = PR_TRUE; *aIsNewWindow = PR_TRUE;
// if we just open a new window for this link, charset from current docshell // if we just open a new window for this link, charset from current docshell

Просмотреть файл

@ -41,7 +41,6 @@ EXPORTS=nsIScriptContext.h \
nsIScriptObjectOwner.h \ nsIScriptObjectOwner.h \
nsIScriptObjectPrincipal.h \ nsIScriptObjectPrincipal.h \
nsIScriptGlobalObject.h \ nsIScriptGlobalObject.h \
nsIScriptEventListener.h \
nsIDOMScriptObjectFactory.h \ nsIDOMScriptObjectFactory.h \
nsDOMCID.h \ nsDOMCID.h \
nsIScriptExternalNameSet.h \ nsIScriptExternalNameSet.h \

Просмотреть файл

@ -42,12 +42,6 @@
#include "nsIDOMEventTarget.h" #include "nsIDOMEventTarget.h"
class nsIDOMEventListener; class nsIDOMEventListener;
class nsIDOMMouseListener;
class nsIDOMMouseMotionListener;
class nsIDOMKeyListener;
class nsIDOMFocusListener;
class nsIDOMLoadListener;
class nsIDOMDragListener;
class nsIEventListenerManager; class nsIEventListenerManager;
class nsIDOMEvent; class nsIDOMEvent;
class nsIDOMEventGroup; class nsIDOMEventGroup;

Просмотреть файл

@ -39,9 +39,8 @@
#ifndef nsIJSEventListener_h__ #ifndef nsIJSEventListener_h__
#define nsIJSEventListener_h__ #define nsIJSEventListener_h__
#include "nsISupports.h" #include "nsIScriptContext.h"
class nsIScriptContext;
class nsIScriptObjectOwner; class nsIScriptObjectOwner;
class nsIDOMEventListener; class nsIDOMEventListener;
class nsIAtom; class nsIAtom;
@ -52,13 +51,42 @@ class nsIAtom;
// Implemented by JS event listeners. Used to retrieve the // Implemented by JS event listeners. Used to retrieve the
// JSObject corresponding to the event target. // JSObject corresponding to the event target.
class nsIJSEventListener : public nsISupports { class nsIJSEventListener : public nsISupports
{
public: public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IJSEVENTLISTENER_IID) NS_DEFINE_STATIC_IID_ACCESSOR(NS_IJSEVENTLISTENER_IID)
NS_IMETHOD GetEventTarget(nsIScriptContext** aContext, nsIJSEventListener(nsIScriptContext *aContext, nsISupports *aTarget)
nsISupports** aTarget) = 0; : mContext(aContext), mTarget(aTarget)
NS_IMETHOD SetEventName(nsIAtom* aName) = 0; {
// mTarget is a weak reference. We are guaranteed because of the
// ownership model that the target will be freed (and the
// references dropped) before either the context or the owner goes
// away.
NS_IF_ADDREF(mContext);
}
nsIScriptContext *GetEventContext()
{
return mContext;
}
nsISupports *GetEventTarget()
{
return mTarget;
}
virtual void SetEventName(nsIAtom* aName) = 0;
protected:
~nsIJSEventListener()
{
NS_IF_RELEASE(mContext);
}
nsIScriptContext *mContext;
nsISupports *mTarget;
}; };
#endif // nsIJSEventListener_h__ #endif // nsIJSEventListener_h__

Просмотреть файл

@ -65,7 +65,8 @@ typedef void (*nsScriptTerminationFunc)(nsISupports* aRef);
* should be removed in a short time. Ideally this interface will be * should be removed in a short time. Ideally this interface will be
* language neutral</I> * language neutral</I>
*/ */
class nsIScriptContext : public nsISupports { class nsIScriptContext : public nsISupports
{
public: public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISCRIPTCONTEXT_IID) NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISCRIPTCONTEXT_IID)
@ -86,7 +87,7 @@ public:
* @return NS_OK if the script was valid and got executed * @return NS_OK if the script was valid and got executed
* *
**/ **/
NS_IMETHOD EvaluateString(const nsAString& aScript, virtual nsresult EvaluateString(const nsAString& aScript,
void *aScopeObject, void *aScopeObject,
nsIPrincipal *aPrincipal, nsIPrincipal *aPrincipal,
const char *aURL, const char *aURL,
@ -95,7 +96,7 @@ public:
nsAString& aRetValue, nsAString& aRetValue,
PRBool* aIsUndefined) = 0; PRBool* aIsUndefined) = 0;
NS_IMETHOD EvaluateStringWithValue(const nsAString& aScript, virtual nsresult EvaluateStringWithValue(const nsAString& aScript,
void *aScopeObject, void *aScopeObject,
nsIPrincipal *aPrincipal, nsIPrincipal *aPrincipal,
const char *aURL, const char *aURL,
@ -122,7 +123,7 @@ public:
* @return NS_OK if the script source was valid and got compiled * @return NS_OK if the script source was valid and got compiled
* *
**/ **/
NS_IMETHOD CompileScript(const PRUnichar* aText, virtual nsresult CompileScript(const PRUnichar* aText,
PRInt32 aTextLength, PRInt32 aTextLength,
void* aScopeObject, void* aScopeObject,
nsIPrincipal* aPrincipal, nsIPrincipal* aPrincipal,
@ -145,7 +146,7 @@ public:
* @return NS_OK if the script was valid and got executed * @return NS_OK if the script was valid and got executed
* *
*/ */
NS_IMETHOD ExecuteScript(void* aScriptObject, virtual nsresult ExecuteScript(void* aScriptObject,
void* aScopeObject, void* aScopeObject,
nsAString* aRetValue, nsAString* aRetValue,
PRBool* aIsUndefined) = 0; PRBool* aIsUndefined) = 0;
@ -174,7 +175,7 @@ public:
* *
* @return NS_OK if the function body was valid and got compiled * @return NS_OK if the function body was valid and got compiled
*/ */
NS_IMETHOD CompileEventHandler(void* aTarget, virtual nsresult CompileEventHandler(void* aTarget,
nsIAtom* aName, nsIAtom* aName,
const nsAString& aBody, const nsAString& aBody,
const char* aURL, const char* aURL,
@ -194,7 +195,7 @@ public:
* @param aBoolResult out parameter returning boolean function result, or * @param aBoolResult out parameter returning boolean function result, or
* true if the result was not boolean. * true if the result was not boolean.
**/ **/
NS_IMETHOD CallEventHandler(void* aTarget, void* aHandler, virtual nsresult CallEventHandler(void* aTarget, void* aHandler,
PRUint32 argc, void* argv, PRUint32 argc, void* argv,
PRBool* aBoolResult) = 0; PRBool* aBoolResult) = 0;
@ -214,11 +215,11 @@ public:
* CompileEventHandler * CompileEventHandler
* @return NS_OK if the function was successfully bound to the name * @return NS_OK if the function was successfully bound to the name
*/ */
NS_IMETHOD BindCompiledEventHandler(void* aTarget, virtual nsresult BindCompiledEventHandler(void* aTarget,
nsIAtom* aName, nsIAtom* aName,
void* aHandler) = 0; void* aHandler) = 0;
NS_IMETHOD CompileFunction(void* aTarget, virtual nsresult CompileFunction(void* aTarget,
const nsACString& aName, const nsACString& aName,
PRUint32 aArgCount, PRUint32 aArgCount,
const char** aArgArray, const char** aArgArray,
@ -234,19 +235,19 @@ public:
* be a context specific to a particular scripting language. * be a context specific to a particular scripting language.
* *
**/ **/
NS_IMETHOD SetDefaultLanguageVersion(const char* aVersion) = 0; virtual void SetDefaultLanguageVersion(const char* aVersion) = 0;
/** /**
* Return the global object. * Return the global object.
* *
**/ **/
NS_IMETHOD GetGlobalObject(nsIScriptGlobalObject** aGlobalObject) = 0; virtual nsIScriptGlobalObject *GetGlobalObject() = 0;
/** /**
* Return the native script context * Return the native script context
* *
**/ **/
NS_IMETHOD_(void*) GetNativeContext() = 0; virtual void *GetNativeContext() = 0;
/** /**
* Init this context. * Init this context.
@ -256,16 +257,16 @@ public:
* @return NS_OK if context initialization was successful * @return NS_OK if context initialization was successful
* *
**/ **/
NS_IMETHOD InitContext(nsIScriptGlobalObject *aGlobalObject) = 0; virtual nsresult InitContext(nsIScriptGlobalObject *aGlobalObject) = 0;
/** /**
* Check to see if context is as yet intialized. Used to prevent * Check to see if context is as yet intialized. Used to prevent
* reentrancy issues during the initialization process. * reentrancy issues during the initialization process.
* *
* @return NS_OK if initialized, NS_ERROR_NOT_INITIALIZED if not * @return PR_TRUE if initialized, PR_FALSE if not
* *
*/ */
NS_IMETHOD IsContextInitialized() = 0; virtual PRBool IsContextInitialized() = 0;
/** /**
* For garbage collected systems, do a synchronous collection pass. * For garbage collected systems, do a synchronous collection pass.
@ -273,13 +274,7 @@ public:
* *
* @return NS_OK if the method is successful * @return NS_OK if the method is successful
*/ */
NS_IMETHOD GC() = 0; virtual void GC() = 0;
/**
* Get the security manager for this context.
* @return NS_OK if the method is successful
*/
NS_IMETHOD GetSecurityManager(nsIScriptSecurityManager** aInstancePtr) = 0;
/** /**
* Inform the context that a script was evaluated. * Inform the context that a script was evaluated.
@ -293,7 +288,7 @@ public:
* calls to the termination function. * calls to the termination function.
* @return NS_OK if the method is successful * @return NS_OK if the method is successful
*/ */
NS_IMETHOD ScriptEvaluated(PRBool aTerminated) = 0; virtual void ScriptEvaluated(PRBool aTerminated) = 0;
/** /**
* Let the script context know who its owner is. * Let the script context know who its owner is.
@ -301,7 +296,7 @@ public:
* will be told when the owner goes away. * will be told when the owner goes away.
* @return NS_OK if the method is successful * @return NS_OK if the method is successful
*/ */
NS_IMETHOD SetOwner(nsIScriptContextOwner* owner) = 0; virtual void SetOwner(nsIScriptContextOwner* owner) = 0;
/** /**
* Get the script context of the owner. The method * Get the script context of the owner. The method
@ -309,7 +304,7 @@ public:
* XPCOM rules, even though the internal reference itself * XPCOM rules, even though the internal reference itself
* is a "weak" reference. * is a "weak" reference.
*/ */
NS_IMETHOD GetOwner(nsIScriptContextOwner** owner) = 0; virtual nsIScriptContextOwner *GetOwner() = 0;
/** /**
* Called to specify a function that should be called when the current * Called to specify a function that should be called when the current
@ -317,47 +312,42 @@ public:
* of script state needs to be happen, but should be deferred till * of script state needs to be happen, but should be deferred till
* the end of script evaluation. * the end of script evaluation.
*/ */
NS_IMETHOD SetTerminationFunction(nsScriptTerminationFunc aFunc, virtual void SetTerminationFunction(nsScriptTerminationFunc aFunc,
nsISupports* aRef) = 0; nsISupports* aRef) = 0;
/** /**
* Called to disable/enable script execution in this context. * Called to disable/enable script execution in this context.
*/ */
NS_IMETHOD GetScriptsEnabled(PRBool *aEnabled) = 0; virtual PRBool GetScriptsEnabled() = 0;
NS_IMETHOD SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts) = 0; virtual void SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts) = 0;
/** /**
* Called to set/get information if the script context is * Called to set/get information if the script context is
* currently processing a script tag * currently processing a script tag
*/ */
NS_IMETHOD GetProcessingScriptTag(PRBool * aResult) =0; virtual PRBool GetProcessingScriptTag() = 0;
NS_IMETHOD SetProcessingScriptTag(PRBool aResult) =0; virtual void SetProcessingScriptTag(PRBool aResult) = 0;
/** /**
* Tell the context whether or not to GC when destroyed. * Tell the context whether or not to GC when destroyed.
*/ */
NS_IMETHOD SetGCOnDestruction(PRBool aGCOnDestruction) = 0; virtual void SetGCOnDestruction(PRBool aGCOnDestruction) = 0;
}; };
inline nsresult inline nsIScriptContext *
GetScriptContextFromJSContext(JSContext *cx, nsIScriptContext **result) GetScriptContextFromJSContext(JSContext *cx)
{ {
*result = nsnull;
if (!(::JS_GetOptions(cx) & JSOPTION_PRIVATE_IS_NSISUPPORTS)) { if (!(::JS_GetOptions(cx) & JSOPTION_PRIVATE_IS_NSISUPPORTS)) {
return NS_ERROR_INVALID_ARG; return nsnull;
} }
nsresult rv = NS_OK; nsCOMPtr<nsIScriptContext> scx =
do_QueryInterface(NS_STATIC_CAST(nsISupports *,
::JS_GetContextPrivate(cx)));
nsISupports *supports = // This will return a pointer to something that's about to be
NS_STATIC_CAST(nsISupports *, ::JS_GetContextPrivate(cx)); // released, but that's ok here.
return scx;
if (supports) {
rv = CallQueryInterface(supports, result);
}
return rv;
} }
#endif // nsIScriptContext_h__ #endif // nsIScriptContext_h__

Просмотреть файл

@ -1,4 +1,4 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* *
* The contents of this file are subject to the Mozilla Public * The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file * License Version 1.1 (the "License"); you may not use this file
@ -61,7 +61,6 @@ interface nsIScriptContextOwner : nsISupports
/** /**
* Error notification method. Informs the owner that an error * Error notification method. Informs the owner that an error
* occurred while a script was being evaluted. * occurred while a script was being evaluted.
*
*/ */
void reportScriptError(in string aErrorString, in string aFileName, void reportScriptError(in string aErrorString, in string aFileName,
in long aLineNo, in string aLineBuf); in long aLineNo, in string aLineBuf);

Просмотреть файл

@ -60,18 +60,19 @@ struct JSObject;
* per-window global state. * per-window global state.
*/ */
class nsIScriptGlobalObject : public nsISupports { class nsIScriptGlobalObject : public nsISupports
{
public: public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISCRIPTGLOBALOBJECT_IID) NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISCRIPTGLOBALOBJECT_IID)
NS_IMETHOD SetContext(nsIScriptContext *aContext) = 0; virtual void SetContext(nsIScriptContext *aContext) = 0;
NS_IMETHOD GetContext(nsIScriptContext **aContext) = 0; virtual nsIScriptContext *GetContext() = 0;
NS_IMETHOD SetNewDocument(nsIDOMDocument *aDocument, virtual nsresult SetNewDocument(nsIDOMDocument *aDocument,
PRBool aRemoveEventListeners, PRBool aRemoveEventListeners,
PRBool aClearScope) = 0; PRBool aClearScope) = 0;
NS_IMETHOD SetDocShell(nsIDocShell *aDocShell) = 0; virtual void SetDocShell(nsIDocShell *aDocShell) = 0;
NS_IMETHOD GetDocShell(nsIDocShell **aDocShell) = 0; virtual nsIDocShell *GetDocShell() = 0;
NS_IMETHOD SetOpenerWindow(nsIDOMWindowInternal *aOpener)=0; virtual void SetOpenerWindow(nsIDOMWindowInternal *aOpener)=0;
/** /**
* Let the script global object know who its owner is. * Let the script global object know who its owner is.
@ -79,7 +80,7 @@ public:
* will be told when the owner goes away. * will be told when the owner goes away.
* @return NS_OK if the method is successful * @return NS_OK if the method is successful
*/ */
NS_IMETHOD SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner) = 0; virtual void SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner) = 0;
/** /**
* Get the owner of the script global object. The method * Get the owner of the script global object. The method
@ -87,26 +88,26 @@ public:
* XPCOM rules, even though the internal reference itself * XPCOM rules, even though the internal reference itself
* is a "weak" reference. * is a "weak" reference.
*/ */
NS_IMETHOD GetGlobalObjectOwner(nsIScriptGlobalObjectOwner** aOwner) = 0; virtual nsIScriptGlobalObjectOwner *GetGlobalObjectOwner() = 0;
NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext, virtual nsresult HandleDOMEvent(nsIPresContext* aPresContext,
nsEvent* aEvent, nsEvent* aEvent,
nsIDOMEvent** aDOMEvent, nsIDOMEvent** aDOMEvent,
PRUint32 aFlags, PRUint32 aFlags,
nsEventStatus* aEventStatus)=0; nsEventStatus* aEventStatus)=0;
NS_IMETHOD_(JSObject *) GetGlobalJSObject() = 0; virtual JSObject *GetGlobalJSObject() = 0;
/** /**
* Called when the global JSObject is finalized * Called when the global JSObject is finalized
*/ */
NS_IMETHOD OnFinalize(JSObject *aJSObject) = 0; virtual void OnFinalize(JSObject *aJSObject) = 0;
/** /**
* Called when scripts are enabled/disabled. * Called when scripts are enabled/disabled.
*/ */
NS_IMETHOD SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts) = 0; virtual void SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts) = 0;
}; };
#endif #endif

Просмотреть файл

@ -116,7 +116,7 @@ public:
* @param aLineNo the starting line number of the script for error messages * @param aLineNo the starting line number of the script for error messages
* @param aHandler the compiled, bound handler object * @param aHandler the compiled, bound handler object
*/ */
NS_IMETHOD CompileEventHandler(nsIScriptContext* aContext, virtual nsresult CompileEventHandler(nsIScriptContext* aContext,
void* aTarget, void* aTarget,
nsIAtom *aName, nsIAtom *aName,
const nsAString& aBody, const nsAString& aBody,
@ -131,7 +131,8 @@ public:
* @param aName the name of the event handler to retrieve * @param aName the name of the event handler to retrieve
* @param aHandler the compiled event handler * @param aHandler the compiled event handler
*/ */
NS_IMETHOD GetCompiledEventHandler(nsIAtom *aName, void** aHandler) = 0; virtual nsresult GetCompiledEventHandler(nsIAtom *aName,
void** aHandler) = 0;
}; };
#endif // nsIScriptObjectOwner_h__ #endif // nsIScriptObjectOwner_h__

Просмотреть файл

@ -278,14 +278,13 @@ ScrollbarsPropImpl::~ScrollbarsPropImpl()
NS_IMETHODIMP NS_IMETHODIMP
ScrollbarsPropImpl::GetVisible(PRBool *aVisible) ScrollbarsPropImpl::GetVisible(PRBool *aVisible)
{ {
NS_ENSURE_ARG_POINTER(aVisible);
*aVisible = PR_TRUE; // one assumes *aVisible = PR_TRUE; // one assumes
nsCOMPtr<nsIDOMWindow> domwin(do_QueryReferent(mDOMWindowWeakref)); nsCOMPtr<nsIDOMWindow> domwin(do_QueryReferent(mDOMWindowWeakref));
if (domwin) { // dom window not deleted if (domwin) { // dom window not deleted
nsCOMPtr<nsIDocShell> docshell; nsCOMPtr<nsIScrollable> scroller =
mDOMWindow->GetDocShell(getter_AddRefs(docshell)); do_QueryInterface(mDOMWindow->GetDocShell());
nsCOMPtr<nsIScrollable> scroller(do_QueryInterface(docshell));
if (scroller) { if (scroller) {
PRInt32 prefValue = aVisible ? NS_STYLE_OVERFLOW_AUTO : PRInt32 prefValue = aVisible ? NS_STYLE_OVERFLOW_AUTO :
NS_STYLE_OVERFLOW_HIDDEN; NS_STYLE_OVERFLOW_HIDDEN;
@ -315,9 +314,9 @@ ScrollbarsPropImpl::SetVisible(PRBool aVisible)
nsCOMPtr<nsIDOMWindow> domwin(do_QueryReferent(mDOMWindowWeakref)); nsCOMPtr<nsIDOMWindow> domwin(do_QueryReferent(mDOMWindowWeakref));
if (domwin) { // dom window must still exist. use away. if (domwin) { // dom window must still exist. use away.
nsCOMPtr<nsIDocShell> docshell; nsCOMPtr<nsIScrollable> scroller =
mDOMWindow->GetDocShell(getter_AddRefs(docshell)); do_QueryInterface(mDOMWindow->GetDocShell());
nsCOMPtr<nsIScrollable> scroller(do_QueryInterface(docshell));
if (scroller) { if (scroller) {
PRInt32 prefValue = aVisible ? NS_STYLE_OVERFLOW_AUTO : PRInt32 prefValue = aVisible ? NS_STYLE_OVERFLOW_AUTO :
NS_STYLE_OVERFLOW_HIDDEN; NS_STYLE_OVERFLOW_HIDDEN;

Просмотреть файл

@ -2965,8 +2965,7 @@ needsSecurityCheck(JSContext *cx, nsIXPConnectWrappedNative *wrapper)
return PR_TRUE; return PR_TRUE;
} }
nsCOMPtr<nsIScriptContext> otherScriptContext; nsIScriptContext *otherScriptContext = sgo->GetContext();
sgo->GetContext(getter_AddRefs(otherScriptContext));
if (!otherScriptContext) { if (!otherScriptContext) {
return PR_TRUE; return PR_TRUE;
@ -3055,10 +3054,9 @@ nsDOMClassInfo::doCheckPropertyAccess(JSContext *cx, JSObject *obj, jsval id,
} }
} }
nsCOMPtr<nsIScriptContext> scx; nsIScriptContext *scx = sgo->GetContext();
sgo->GetContext(getter_AddRefs(scx));
if (!scx || NS_FAILED(scx->IsContextInitialized())) { if (!scx || !scx->IsContextInitialized()) {
return NS_OK; return NS_OK;
} }
@ -3224,11 +3222,7 @@ nsWindowSH::SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
nsresult rv = window->GetLocation(getter_AddRefs(location)); nsresult rv = window->GetLocation(getter_AddRefs(location));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
nsDependentString href(NS_REINTERPRET_CAST(PRUnichar *, rv = location->SetHref(nsDependentJSString(val));
::JS_GetStringChars(val)),
::JS_GetStringLength(val));
rv = location->SetHref(href);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
return WrapNative(cx, obj, location, NS_GET_IID(nsIDOMLocation), vp); return WrapNative(cx, obj, location, NS_GET_IID(nsIDOMLocation), vp);
@ -3331,9 +3325,7 @@ BaseStubConstructor(const nsGlobalNameStruct *name_struct, JSContext *cx,
nsCOMPtr<nsIScriptObjectOwner> owner(do_QueryInterface(native)); nsCOMPtr<nsIScriptObjectOwner> owner(do_QueryInterface(native));
if (owner) { if (owner) {
nsCOMPtr<nsIScriptContext> context; nsIScriptContext *context = nsJSUtils::GetStaticScriptContext(cx, obj);
nsJSUtils::GetStaticScriptContext(cx, obj, getter_AddRefs(context));
if (!context) { if (!context) {
nsDOMClassInfo::ThrowJSException(cx, NS_ERROR_UNEXPECTED); nsDOMClassInfo::ThrowJSException(cx, NS_ERROR_UNEXPECTED);
@ -3711,9 +3703,7 @@ nsWindowSH::GlobalResolve(nsISupports *native, JSContext *cx, JSObject *obj,
NS_ENSURE_TRUE(gNameSpaceManager, NS_ERROR_NOT_INITIALIZED); NS_ENSURE_TRUE(gNameSpaceManager, NS_ERROR_NOT_INITIALIZED);
nsDependentString name(NS_REINTERPRET_CAST(const PRUnichar*, nsDependentJSString name(str);
::JS_GetStringChars(str)),
::JS_GetStringLength(str));
const nsGlobalNameStruct *name_struct = nsnull; const nsGlobalNameStruct *name_struct = nsnull;
const PRUnichar *class_name = nsnull; const PRUnichar *class_name = nsnull;
@ -4015,8 +4005,7 @@ nsWindowSH::GlobalResolve(nsISupports *native, JSContext *cx, JSObject *obj,
nsCOMPtr<nsIScriptObjectOwner> owner(do_QueryInterface(native)); nsCOMPtr<nsIScriptObjectOwner> owner(do_QueryInterface(native));
if (owner) { if (owner) {
nsCOMPtr<nsIScriptContext> context; nsIScriptContext *context = nsJSUtils::GetStaticScriptContext(cx, obj);
nsJSUtils::GetStaticScriptContext(cx, obj, getter_AddRefs(context));
NS_ENSURE_TRUE(context, NS_ERROR_UNEXPECTED); NS_ENSURE_TRUE(context, NS_ERROR_UNEXPECTED);
JSObject *prop_obj = nsnull; JSObject *prop_obj = nsnull;
@ -4048,9 +4037,7 @@ nsWindowSH::GlobalResolve(nsISupports *native, JSContext *cx, JSObject *obj,
nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(native)); nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(native));
NS_ENSURE_TRUE(sgo, NS_ERROR_UNEXPECTED); NS_ENSURE_TRUE(sgo, NS_ERROR_UNEXPECTED);
nsCOMPtr<nsIScriptContext> context; nsIScriptContext *context = sgo->GetContext();
sgo->GetContext(getter_AddRefs(context));
NS_ENSURE_TRUE(context, NS_ERROR_UNEXPECTED); NS_ENSURE_TRUE(context, NS_ERROR_UNEXPECTED);
rv = nameset->InitializeNameSet(context); rv = nameset->InitializeNameSet(context);
@ -4092,17 +4079,15 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject **objp, PRBool *_retval) JSObject **objp, PRBool *_retval)
{ {
if (JSVAL_IS_STRING(id)) { if (JSVAL_IS_STRING(id)) {
JSString *str = JSVAL_TO_STRING(id);
nsCOMPtr<nsISupports> native; nsCOMPtr<nsISupports> native;
wrapper->GetNative(getter_AddRefs(native)); wrapper->GetNative(getter_AddRefs(native));
nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(native)); nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(native));
NS_ENSURE_TRUE(sgo, NS_ERROR_UNEXPECTED); NS_ENSURE_TRUE(sgo, NS_ERROR_UNEXPECTED);
nsCOMPtr<nsIScriptContext> my_context; nsIScriptContext *my_context = sgo->GetContext();
sgo->GetContext(getter_AddRefs(my_context));
if (!my_context || NS_FAILED(my_context->IsContextInitialized())) { if (!my_context || !my_context->IsContextInitialized()) {
// The context is not yet initialized so there's nothing we can do // The context is not yet initialized so there's nothing we can do
// here yet. // here yet.
@ -4148,10 +4133,9 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
// method on an interface that would let us just call into the // method on an interface that would let us just call into the
// window code directly... // window code directly...
nsCOMPtr<nsIDocShell> docShell; JSString *str = JSVAL_TO_STRING(id);
sgo->GetDocShell(getter_AddRefs(docShell));
nsCOMPtr<nsIDocShellTreeNode> dsn(do_QueryInterface(docShell)); nsCOMPtr<nsIDocShellTreeNode> dsn(do_QueryInterface(sgo->GetDocShell()));
PRInt32 count = 0; PRInt32 count = 0;
@ -4404,7 +4388,9 @@ nsWindowSH::Finalize(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(native)); nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(native));
NS_ENSURE_TRUE(sgo, NS_ERROR_UNEXPECTED); NS_ENSURE_TRUE(sgo, NS_ERROR_UNEXPECTED);
return sgo->OnFinalize(obj); sgo->OnFinalize(obj);
return NS_OK;
} }
@ -4645,10 +4631,8 @@ nsEventReceiverSH::RegisterCompileHandler(nsIXPConnectWrappedNative *wrapper,
return NS_OK; return NS_OK;
} }
nsCOMPtr<nsIScriptContext> script_cx; nsIScriptContext *script_cx = nsJSUtils::GetStaticScriptContext(cx, obj);
nsresult rv = nsJSUtils::GetStaticScriptContext(cx, obj, NS_ENSURE_TRUE(script_cx, NS_ERROR_UNEXPECTED);
getter_AddRefs(script_cx));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsISupports> native; nsCOMPtr<nsISupports> native;
wrapper->GetNative(getter_AddRefs(native)); wrapper->GetNative(getter_AddRefs(native));
@ -4662,13 +4646,11 @@ nsEventReceiverSH::RegisterCompileHandler(nsIXPConnectWrappedNative *wrapper,
receiver->GetListenerManager(getter_AddRefs(manager)); receiver->GetListenerManager(getter_AddRefs(manager));
NS_ENSURE_TRUE(manager, NS_ERROR_UNEXPECTED); NS_ENSURE_TRUE(manager, NS_ERROR_UNEXPECTED);
JSString *str = JSVAL_TO_STRING(id); nsCOMPtr<nsIAtom> atom(do_GetAtom(nsDependentJSString(id)));
const PRUnichar *ustr = NS_REINTERPRET_CAST(const PRUnichar *,
::JS_GetStringChars(str));
nsCOMPtr<nsIAtom> atom(do_GetAtom(ustr));
NS_ENSURE_TRUE(atom, NS_ERROR_OUT_OF_MEMORY); NS_ENSURE_TRUE(atom, NS_ERROR_OUT_OF_MEMORY);
nsresult rv;
if (compile) { if (compile) {
rv = manager->CompileScriptEventListener(script_cx, native, atom, rv = manager->CompileScriptEventListener(script_cx, native, atom,
did_compile); did_compile);
@ -4936,13 +4918,8 @@ nsNamedArraySH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
wrapper->GetNative(getter_AddRefs(native)); wrapper->GetNative(getter_AddRefs(native));
nsCOMPtr<nsISupports> item; nsCOMPtr<nsISupports> item;
nsresult rv = GetNamedItem(native, nsDependentJSString(id),
JSString *str = JSVAL_TO_STRING(id); getter_AddRefs(item));
nsDependentString name(NS_REINTERPRET_CAST(const PRUnichar *,
::JS_GetStringChars(str)),
::JS_GetStringLength(str));
nsresult rv = GetNamedItem(native, name, getter_AddRefs(item));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
if (item) { if (item) {
@ -5300,11 +5277,7 @@ nsDocumentSH::SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSString *val = ::JS_ValueToString(cx, *vp); JSString *val = ::JS_ValueToString(cx, *vp);
NS_ENSURE_TRUE(val, NS_ERROR_UNEXPECTED); NS_ENSURE_TRUE(val, NS_ERROR_UNEXPECTED);
nsDependentString href(NS_REINTERPRET_CAST(const PRUnichar *, nsresult rv = location->SetHref(nsDependentJSString(val));
::JS_GetStringChars(val)),
::JS_GetStringLength(val));
nsresult rv = location->SetHref(href);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
return WrapNative(cx, obj, location, NS_GET_IID(nsIDOMLocation), vp); return WrapNative(cx, obj, location, NS_GET_IID(nsIDOMLocation), vp);
@ -5343,12 +5316,9 @@ nsHTMLDocumentSH::ResolveImpl(JSContext *cx,
// should map to <input name="1">. Thus we can't use // should map to <input name="1">. Thus we can't use
// JSVAL_TO_STRING() here. // JSVAL_TO_STRING() here.
JSString *str = JS_ValueToString(cx, id); JSString *str = JS_ValueToString(cx, id);
NS_ENSURE_TRUE(str, NS_ERROR_UNEXPECTED);
const nsDependentString name(NS_REINTERPRET_CAST(const PRUnichar *, return doc->ResolveName(nsDependentJSString(str), nsnull, result);
::JS_GetStringChars(str)),
::JS_GetStringLength(str));
return doc->ResolveName(name, nsnull, result);
} }
// static // static
@ -5533,9 +5503,7 @@ nsHTMLFormElementSH::FindNamedItem(nsIForm *aForm, JSString *str,
{ {
*aResult = nsnull; *aResult = nsnull;
nsDependentString name(NS_REINTERPRET_CAST(const PRUnichar *, nsDependentJSString name(str);
::JS_GetStringChars(str)),
::JS_GetStringLength(str));
aForm->ResolveName(name, aResult); aForm->ResolveName(name, aResult);

Просмотреть файл

@ -136,9 +136,7 @@ nsFocusController::SetFocusedWindow(nsIDOMWindowInternal* aWindow)
if (aWindow && (mCurrentWindow != aWindow)) { if (aWindow && (mCurrentWindow != aWindow)) {
nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(aWindow); nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(aWindow);
if (sgo) { if (sgo) {
nsCOMPtr<nsIDocShell> docShell; nsCOMPtr<nsIBaseWindow> basewin = do_QueryInterface(sgo->GetDocShell());
sgo->GetDocShell(getter_AddRefs(docShell));
nsCOMPtr<nsIBaseWindow> basewin = do_QueryInterface(docShell);
if (basewin) if (basewin)
basewin->SetFocus(); basewin->SetFocus();
} }
@ -513,11 +511,11 @@ nsFocusController::UpdateWWActiveWindow()
// This gets the toplevel DOMWindow // This gets the toplevel DOMWindow
nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(mCurrentWindow); nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(mCurrentWindow);
nsCOMPtr<nsIDocShell> docShell;
sgo->GetDocShell(getter_AddRefs(docShell));
if (!docShell) return;
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(docShell)); nsCOMPtr<nsIDocShellTreeItem> docShellAsItem =
do_QueryInterface(sgo->GetDocShell());
if (!docShellAsItem) return;
nsCOMPtr<nsIDocShellTreeItem> rootItem; nsCOMPtr<nsIDocShellTreeItem> rootItem;
docShellAsItem->GetRootTreeItem(getter_AddRefs(rootItem)); docShellAsItem->GetRootTreeItem(getter_AddRefs(rootItem));
NS_ASSERTION(rootItem, "Invalid docshell tree - no root!"); NS_ASSERTION(rootItem, "Invalid docshell tree - no root!");

Просмотреть файл

@ -390,7 +390,7 @@ NS_IMPL_RELEASE(GlobalWindowImpl)
// GlobalWindowImpl::nsIScriptGlobalObject // GlobalWindowImpl::nsIScriptGlobalObject
//***************************************************************************** //*****************************************************************************
NS_IMETHODIMP void
GlobalWindowImpl::SetContext(nsIScriptContext* aContext) GlobalWindowImpl::SetContext(nsIScriptContext* aContext)
{ {
// if setting the context to null, then we won't get to clean up the // if setting the context to null, then we won't get to clean up the
@ -406,10 +406,7 @@ GlobalWindowImpl::SetContext(nsIScriptContext* aContext)
mContext = aContext; mContext = aContext;
if (mContext) { if (mContext) {
nsCOMPtr<nsIDOMWindowInternal> parent; if (GetParentInternal()) {
GetParentInternal(getter_AddRefs(parent));
if (parent) {
// This window is a [i]frame, don't bother GC'ing when the // This window is a [i]frame, don't bother GC'ing when the
// frame's context is destroyed since a GC will happen when the // frame's context is destroyed since a GC will happen when the
// frameset or host document is destroyed anyway. // frameset or host document is destroyed anyway.
@ -417,16 +414,12 @@ GlobalWindowImpl::SetContext(nsIScriptContext* aContext)
mContext->SetGCOnDestruction(PR_FALSE); mContext->SetGCOnDestruction(PR_FALSE);
} }
} }
return NS_OK;
} }
NS_IMETHODIMP nsIScriptContext *
GlobalWindowImpl::GetContext(nsIScriptContext ** aContext) GlobalWindowImpl::GetContext()
{ {
NS_IF_ADDREF(*aContext = mContext); return mContext;
return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -436,7 +429,7 @@ GlobalWindowImpl::SetOpenerScriptURL(nsIURI* aURI)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP nsresult
GlobalWindowImpl::SetNewDocument(nsIDOMDocument* aDocument, GlobalWindowImpl::SetNewDocument(nsIDOMDocument* aDocument,
PRBool aRemoveEventListeners, PRBool aRemoveEventListeners,
PRBool aClearScopeHint) PRBool aClearScopeHint)
@ -671,11 +664,11 @@ GlobalWindowImpl::SetNewDocument(nsIDOMDocument* aDocument,
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP void
GlobalWindowImpl::SetDocShell(nsIDocShell* aDocShell) GlobalWindowImpl::SetDocShell(nsIDocShell* aDocShell)
{ {
if (aDocShell == mDocShell) if (aDocShell == mDocShell)
return NS_OK; return;
// SetDocShell(nsnull) means the window is being torn down. Drop our // SetDocShell(nsnull) means the window is being torn down. Drop our
// reference to the script context, allowing it to be deleted // reference to the script context, allowing it to be deleted
@ -755,43 +748,33 @@ GlobalWindowImpl::SetDocShell(nsIDocShell* aDocShell)
else NS_NewWindowRoot(this, getter_AddRefs(mChromeEventHandler)); else NS_NewWindowRoot(this, getter_AddRefs(mChromeEventHandler));
} }
} }
return NS_OK;
} }
NS_IMETHODIMP nsIDocShell *
GlobalWindowImpl::GetDocShell(nsIDocShell ** aDocShell) GlobalWindowImpl::GetDocShell()
{ {
NS_IF_ADDREF(*aDocShell = mDocShell); return mDocShell;
return NS_OK;
} }
NS_IMETHODIMP void
GlobalWindowImpl::SetOpenerWindow(nsIDOMWindowInternal* aOpener) GlobalWindowImpl::SetOpenerWindow(nsIDOMWindowInternal* aOpener)
{ {
mOpener = aOpener; mOpener = aOpener;
return NS_OK;
} }
NS_IMETHODIMP void
GlobalWindowImpl::SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner) GlobalWindowImpl::SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner)
{ {
mGlobalObjectOwner = aOwner; // Note this is supposed to be a weak ref. mGlobalObjectOwner = aOwner; // Note this is supposed to be a weak ref.
return NS_OK;
} }
NS_IMETHODIMP nsIScriptGlobalObjectOwner *
GlobalWindowImpl::GetGlobalObjectOwner(nsIScriptGlobalObjectOwner ** aOwner) GlobalWindowImpl::GetGlobalObjectOwner()
{ {
NS_ENSURE_ARG_POINTER(aOwner); return mGlobalObjectOwner;
NS_IF_ADDREF(*aOwner = mGlobalObjectOwner);
return NS_OK;
} }
NS_IMETHODIMP nsresult
GlobalWindowImpl::HandleDOMEvent(nsIPresContext* aPresContext, GlobalWindowImpl::HandleDOMEvent(nsIPresContext* aPresContext,
nsEvent* aEvent, nsEvent* aEvent,
nsIDOMEvent** aDOMEvent, nsIDOMEvent** aDOMEvent,
@ -929,9 +912,6 @@ GlobalWindowImpl::HandleDOMEvent(nsIPresContext* aPresContext,
if (aEvent->message == NS_PAGE_LOAD) { if (aEvent->message == NS_PAGE_LOAD) {
nsCOMPtr<nsIContent> content(do_QueryInterface(mFrameElement)); nsCOMPtr<nsIContent> content(do_QueryInterface(mFrameElement));
nsCOMPtr<nsIDOMWindowInternal> parent;
GetParentInternal(getter_AddRefs(parent));
nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(mDocShell)); nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(mDocShell));
PRInt32 itemType = nsIDocShellTreeItem::typeChrome; PRInt32 itemType = nsIDocShellTreeItem::typeChrome;
@ -940,7 +920,8 @@ GlobalWindowImpl::HandleDOMEvent(nsIPresContext* aPresContext,
treeItem->GetItemType(&itemType); treeItem->GetItemType(&itemType);
} }
if (content && parent && itemType != nsIDocShellTreeItem::typeChrome) { if (content && GetParentInternal() &&
itemType != nsIDocShellTreeItem::typeChrome) {
// If we're not in chrome, or at a chrome boundary, fire the // If we're not in chrome, or at a chrome boundary, fire the
// onload event for the frame element. // onload event for the frame element.
@ -987,7 +968,7 @@ GlobalWindowImpl::GetGlobalJSObject()
return mJSObject; return mJSObject;
} }
NS_IMETHODIMP void
GlobalWindowImpl::OnFinalize(JSObject *aJSObject) GlobalWindowImpl::OnFinalize(JSObject *aJSObject)
{ {
if (aJSObject == mJSObject) { if (aJSObject == mJSObject) {
@ -997,11 +978,9 @@ GlobalWindowImpl::OnFinalize(JSObject *aJSObject)
} else { } else {
NS_WARNING("Weird, we're finalized with a null mJSObject?"); NS_WARNING("Weird, we're finalized with a null mJSObject?");
} }
return NS_OK;
} }
NS_IMETHODIMP void
GlobalWindowImpl::SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts) GlobalWindowImpl::SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts)
{ {
if (aEnabled && aFireTimeouts) { if (aEnabled && aFireTimeouts) {
@ -1010,8 +989,6 @@ GlobalWindowImpl::SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts)
RunTimeout(nsnull); RunTimeout(nsnull);
} }
return NS_OK;
} }
@ -1049,17 +1026,13 @@ GlobalWindowImpl::GetPrincipal(nsIPrincipal** result)
// loading a frameset that has a <frame src="javascript:xxx">, in // loading a frameset that has a <frame src="javascript:xxx">, in
// that case the global window is used in JS before we've loaded // that case the global window is used in JS before we've loaded
// a document into the window. // a document into the window.
nsCOMPtr<nsIDOMWindowInternal> parent;
GetParentInternal(getter_AddRefs(parent)); nsCOMPtr<nsIScriptObjectPrincipal> objPrincipal =
do_QueryInterface(GetParentInternal());
if (parent) {
nsCOMPtr<nsIScriptObjectPrincipal> objPrincipal(do_QueryInterface(parent));
if (objPrincipal) { if (objPrincipal) {
return objPrincipal->GetPrincipal(result); return objPrincipal->GetPrincipal(result);
} }
}
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
@ -1475,9 +1448,9 @@ GlobalWindowImpl::GetOpener(nsIDOMWindowInternal** aOpener)
// So, we look in the opener's root docshell to see if it's a mail window. // So, we look in the opener's root docshell to see if it's a mail window.
nsCOMPtr<nsIScriptGlobalObject> openerSGO(do_QueryInterface(mOpener)); nsCOMPtr<nsIScriptGlobalObject> openerSGO(do_QueryInterface(mOpener));
if (openerSGO) { if (openerSGO) {
nsCOMPtr<nsIDocShell> openerDocShell; nsCOMPtr<nsIDocShellTreeItem> docShellAsItem =
openerSGO->GetDocShell(getter_AddRefs(openerDocShell)); do_QueryInterface(openerSGO->GetDocShell());
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(openerDocShell));
if (docShellAsItem) { if (docShellAsItem) {
nsCOMPtr<nsIDocShellTreeItem> openerRootItem; nsCOMPtr<nsIDocShellTreeItem> openerRootItem;
docShellAsItem->GetRootTreeItem(getter_AddRefs(openerRootItem)); docShellAsItem->GetRootTreeItem(getter_AddRefs(openerRootItem));
@ -2094,9 +2067,7 @@ NS_IMETHODIMP GlobalWindowImpl::SetFullScreen(PRBool aFullScreen)
// SetFullScreen needs to be called on the root window, so get that // SetFullScreen needs to be called on the root window, so get that
// via the DocShell tree, and if we are not already the root, // via the DocShell tree, and if we are not already the root,
// call SetFullScreen on that window instead. // call SetFullScreen on that window instead.
nsCOMPtr<nsIDocShell> docShell; nsCOMPtr<nsIDocShellTreeItem> treeItem = do_QueryInterface(mDocShell);
GetDocShell(getter_AddRefs(docShell));
nsCOMPtr<nsIDocShellTreeItem> treeItem = do_QueryInterface(docShell);
nsCOMPtr<nsIDocShellTreeItem> rootItem; nsCOMPtr<nsIDocShellTreeItem> rootItem;
treeItem->GetRootTreeItem(getter_AddRefs(rootItem)); treeItem->GetRootTreeItem(getter_AddRefs(rootItem));
nsCOMPtr<nsIDOMWindowInternal> window = do_GetInterface(rootItem); nsCOMPtr<nsIDOMWindowInternal> window = do_GetInterface(rootItem);
@ -3282,12 +3253,9 @@ GlobalWindowImpl::FireAbuseEvents(PRBool aBlocked, PRBool aWindow,
JSContext *cx = nsnull; JSContext *cx = nsnull;
stack->Peek(&cx); stack->Peek(&cx);
if (cx) { if (cx) {
nsCOMPtr<nsIScriptContext> currentCX; nsIScriptContext *currentCX = nsJSUtils::GetDynamicScriptContext(cx);
nsJSUtils::GetDynamicScriptContext(cx, getter_AddRefs(currentCX));
if (currentCX) { if (currentCX) {
nsCOMPtr<nsIScriptGlobalObject> gobj; contextWindow = do_QueryInterface(currentCX->GetGlobalObject());
currentCX->GetGlobalObject(getter_AddRefs(gobj));
contextWindow = do_QueryInterface(gobj);
} }
} }
} }
@ -3654,13 +3622,13 @@ GlobalWindowImpl::Close()
} }
if (cx) { if (cx) {
nsCOMPtr<nsIScriptContext> currentCX; nsIScriptContext *currentCX = nsJSUtils::GetDynamicScriptContext(cx);
nsJSUtils::GetDynamicScriptContext(cx, getter_AddRefs(currentCX));
if (currentCX && currentCX == mContext) { if (currentCX && currentCX == mContext) {
return currentCX->SetTerminationFunction(CloseWindow, currentCX->SetTerminationFunction(CloseWindow,
NS_STATIC_CAST(nsIDOMWindow *, NS_STATIC_CAST(nsIDOMWindow *,
this)); this));
return NS_OK;
} }
} }
@ -3710,10 +3678,7 @@ GlobalWindowImpl::GetFrameElement(nsIDOMElement** aFrameElement)
{ {
*aFrameElement = nsnull; *aFrameElement = nsnull;
nsCOMPtr<nsIDocShell> docShell; nsCOMPtr<nsIDocShellTreeItem> docShellTI(do_QueryInterface(mDocShell));
GetDocShell(getter_AddRefs(docShell));
nsCOMPtr<nsIDocShellTreeItem> docShellTI(do_QueryInterface(docShell));
if (!docShellTI) { if (!docShellTI) {
return NS_OK; return NS_OK;
@ -4361,11 +4326,11 @@ GlobalWindowImpl::GetPrivateRoot(nsIDOMWindowInternal ** aParent)
GetTop(getter_AddRefs(parent)); GetTop(getter_AddRefs(parent));
nsCOMPtr<nsIScriptGlobalObject> parentTop = do_QueryInterface(parent); nsCOMPtr<nsIScriptGlobalObject> parentTop = do_QueryInterface(parent);
nsCOMPtr<nsIDocShell> docShell;
NS_ASSERTION(parentTop, "cannot get parentTop"); NS_ASSERTION(parentTop, "cannot get parentTop");
if(parentTop == nsnull) if(parentTop == nsnull)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
parentTop->GetDocShell(getter_AddRefs(docShell));
nsIDocShell *docShell = parentTop->GetDocShell();
// Get the chrome event handler from the doc shell, since we only // Get the chrome event handler from the doc shell, since we only
// want to deal with XUL chrome handlers and not the new kind of // want to deal with XUL chrome handlers and not the new kind of
@ -4719,19 +4684,22 @@ GlobalWindowImpl::GetInterface(const nsIID & aIID, void **aSink)
// GlobalWindowImpl: Window Control Functions // GlobalWindowImpl: Window Control Functions
//***************************************************************************** //*****************************************************************************
void nsIDOMWindowInternal *
GlobalWindowImpl::GetParentInternal(nsIDOMWindowInternal **aParent) GlobalWindowImpl::GetParentInternal()
{ {
*aParent = nsnull; nsIDOMWindowInternal *parentInternal = nsnull;
nsCOMPtr<nsIDOMWindow> parent; nsCOMPtr<nsIDOMWindow> parent;
GetParent(getter_AddRefs(parent)); GetParent(getter_AddRefs(parent));
if (parent && parent != NS_STATIC_CAST(nsIDOMWindow *, this)) { if (parent && parent != NS_STATIC_CAST(nsIDOMWindow *, this)) {
CallQueryInterface(parent, aParent); nsCOMPtr<nsIDOMWindowInternal> tmp(do_QueryInterface(parent));
NS_ASSERTION(*aParent, "Huh, parent not an nsIDOMWindowInternal?"); NS_ASSERTION(parent, "Huh, parent not an nsIDOMWindowInternal?");
parentInternal = tmp;
} }
return parentInternal;
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -5032,10 +5000,7 @@ GlobalWindowImpl::RunTimeout(nsTimeoutImpl *aTimeout)
return; return;
} }
PRBool scripts_enabled = PR_TRUE; if (!mContext->GetScriptsEnabled()) {
mContext->GetScriptsEnabled(&scripts_enabled);
if (!scripts_enabled) {
// Scripts were enabled once in this window (unless aTimeout == // Scripts were enabled once in this window (unless aTimeout ==
// nsnull) but now scripts are disabled (we might be in // nsnull) but now scripts are disabled (we might be in
// print-preview, for instance), this means we shouldn't run any // print-preview, for instance), this means we shouldn't run any
@ -5313,11 +5278,11 @@ nsTimeoutImpl::Release(nsIScriptContext *aContext)
return; return;
if (mExpr || mFunObj) { if (mExpr || mFunObj) {
nsCOMPtr<nsIScriptContext> scx(aContext); nsIScriptContext *scx = aContext;
JSRuntime *rt = nsnull; JSRuntime *rt = nsnull;
if (!scx && mWindow) { if (!scx && mWindow) {
mWindow->GetContext(getter_AddRefs(scx)); scx = mWindow->GetContext();
} }
if (scx) { if (scx) {
@ -5643,13 +5608,12 @@ GlobalWindowImpl::SecurityCheckURL(const char *aURL)
nsIURI* baseURI = nsnull; nsIURI* baseURI = nsnull;
nsCOMPtr<nsIURI> uriToLoad; nsCOMPtr<nsIURI> uriToLoad;
nsCOMPtr<nsIScriptContext> scriptcx; nsIScriptContext *scriptcx = nsJSUtils::GetDynamicScriptContext(cx);
nsJSUtils::GetDynamicScriptContext(cx, getter_AddRefs(scriptcx));
if (scriptcx) { if (scriptcx) {
nsCOMPtr<nsIScriptGlobalObject> gobj; nsCOMPtr<nsIDOMWindow> caller =
scriptcx->GetGlobalObject(getter_AddRefs(gobj)); do_QueryInterface(scriptcx->GetGlobalObject());
nsCOMPtr<nsIDOMWindow> caller(do_QueryInterface(gobj));
if (caller) { if (caller) {
nsCOMPtr<nsIDOMDocument> callerDOMdoc; nsCOMPtr<nsIDOMDocument> callerDOMdoc;
caller->GetDocument(getter_AddRefs(callerDOMdoc)); caller->GetDocument(getter_AddRefs(callerDOMdoc));

Просмотреть файл

@ -130,22 +130,23 @@ public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
// nsIScriptGlobalObject // nsIScriptGlobalObject
NS_IMETHOD SetContext(nsIScriptContext *aContext); virtual void SetContext(nsIScriptContext *aContext);
NS_IMETHOD GetContext(nsIScriptContext **aContext); virtual nsIScriptContext *GetContext();
NS_IMETHOD SetNewDocument(nsIDOMDocument *aDocument, virtual nsresult SetNewDocument(nsIDOMDocument *aDocument,
PRBool aRemoveEventListeners, PRBool aRemoveEventListeners,
PRBool aClearScopeHint); PRBool aClearScopeHint);
NS_IMETHOD SetDocShell(nsIDocShell* aDocShell); virtual void SetDocShell(nsIDocShell* aDocShell);
NS_IMETHOD GetDocShell(nsIDocShell** aDocShell); virtual nsIDocShell *GetDocShell();
NS_IMETHOD SetOpenerWindow(nsIDOMWindowInternal *aOpener); virtual void SetOpenerWindow(nsIDOMWindowInternal *aOpener);
NS_IMETHOD SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner); virtual void SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner);
NS_IMETHOD GetGlobalObjectOwner(nsIScriptGlobalObjectOwner** aOwner); virtual nsIScriptGlobalObjectOwner *GetGlobalObjectOwner();
NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent, virtual nsresult HandleDOMEvent(nsIPresContext* aPresContext,
nsIDOMEvent** aDOMEvent, PRUint32 aFlags, nsEvent* aEvent, nsIDOMEvent** aDOMEvent,
PRUint32 aFlags,
nsEventStatus* aEventStatus); nsEventStatus* aEventStatus);
NS_IMETHOD_(JSObject *) GetGlobalJSObject(); virtual JSObject *GetGlobalJSObject();
NS_IMETHOD OnFinalize(JSObject *aJSObject); virtual void OnFinalize(JSObject *aJSObject);
NS_IMETHOD SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts); virtual void SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts);
// nsIScriptObjectPrincipal // nsIScriptObjectPrincipal
NS_IMETHOD GetPrincipal(nsIPrincipal **prin); NS_IMETHOD GetPrincipal(nsIPrincipal **prin);
@ -219,7 +220,7 @@ protected:
void ClearControllers(); void ClearControllers();
// Get the parent, returns null if this is a toplevel window // Get the parent, returns null if this is a toplevel window
void GetParentInternal(nsIDOMWindowInternal **parent); nsIDOMWindowInternal *GetParentInternal();
// Window Control Functions // Window Control Functions
NS_IMETHOD OpenInternal(const nsAString& aUrl, NS_IMETHOD OpenInternal(const nsAString& aUrl,
@ -488,7 +489,7 @@ public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
NS_IMETHOD_(void) SetDocShell(nsIDocShell *aDocShell); void SetDocShell(nsIDocShell *aDocShell);
// nsIDOMLocation // nsIDOMLocation
NS_DECL_NSIDOMLOCATION NS_DECL_NSIDOMLOCATION

Просмотреть файл

@ -206,8 +206,7 @@ nsSelectionCommandsBase::GetPresShellFromWindow(nsIDOMWindow *aWindow, nsIPresSh
nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(aWindow)); nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(aWindow));
NS_ENSURE_TRUE(sgo, NS_ERROR_FAILURE); NS_ENSURE_TRUE(sgo, NS_ERROR_FAILURE);
nsCOMPtr<nsIDocShell> docShell; nsIDocShell *docShell = sgo->GetDocShell();
sgo->GetDocShell(getter_AddRefs(docShell));
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE); NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
return docShell->GetPresShell(aPresShell); return docShell->GetPresShell(aPresShell);
@ -478,8 +477,7 @@ nsClipboardBaseCommand::GetContentViewerEditFromContext(nsISupports *aContext,
nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(window)); nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(window));
NS_ENSURE_TRUE(sgo, NS_ERROR_FAILURE); NS_ENSURE_TRUE(sgo, NS_ERROR_FAILURE);
nsCOMPtr<nsIDocShell> docShell; nsIDocShell *docShell = sgo->GetDocShell();
sgo->GetDocShell(getter_AddRefs(docShell));
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE); NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
nsCOMPtr<nsIContentViewer> viewer; nsCOMPtr<nsIContentViewer> viewer;
@ -834,9 +832,7 @@ nsClipboardDragDropHookCommand::DoCommandParams(const char *aCommandName,
nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(window); nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(window);
NS_ENSURE_TRUE(sgo, NS_ERROR_FAILURE); NS_ENSURE_TRUE(sgo, NS_ERROR_FAILURE);
nsCOMPtr<nsIDocShell> docShell; nsIDocShell *docShell = sgo->GetDocShell();
sgo->GetDocShell(getter_AddRefs(docShell));
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
nsCOMPtr<nsIClipboardDragDropHookList> obj = do_GetInterface(docShell); nsCOMPtr<nsIClipboardDragDropHookList> obj = do_GetInterface(docShell);
if (!obj) return NS_ERROR_INVALID_ARG; if (!obj) return NS_ERROR_INVALID_ARG;

Просмотреть файл

@ -141,14 +141,13 @@ NS_ScriptErrorReporter(JSContext *cx,
const char *message, const char *message,
JSErrorReport *report) JSErrorReport *report)
{ {
nsCOMPtr<nsIScriptContext> context; // XXX this means we are not going to get error reports on non DOM contexts
nsIScriptContext *context = nsJSUtils::GetDynamicScriptContext(cx);
nsEventStatus status = nsEventStatus_eIgnore; nsEventStatus status = nsEventStatus_eIgnore;
// XXX this means we are not going to get error reports on non DOM contexts
nsJSUtils::GetDynamicScriptContext(cx, getter_AddRefs(context));
if (context) { if (context) {
nsCOMPtr<nsIScriptGlobalObject> globalObject; nsIScriptGlobalObject *globalObject = context->GetGlobalObject();
context->GetGlobalObject(getter_AddRefs(globalObject));
if (globalObject) { if (globalObject) {
nsAutoString fileName, msg; nsAutoString fileName, msg;
@ -168,12 +167,8 @@ NS_ScriptErrorReporter(JSContext *cx,
msg.AssignWithConversion(message); msg.AssignWithConversion(message);
} }
nsCOMPtr<nsIDocShell> docShell;
nsCOMPtr<nsIScriptGlobalObjectOwner> owner;
globalObject->GetGlobalObjectOwner(getter_AddRefs(owner));
if (owner) {
// First, notify the DOM that we have a script error. // First, notify the DOM that we have a script error.
globalObject->GetDocShell(getter_AddRefs(docShell)); nsIDocShell *docShell = globalObject->GetDocShell();
if (docShell && !JSREPORT_IS_WARNING(report->flags)) { if (docShell && !JSREPORT_IS_WARNING(report->flags)) {
static PRInt32 errorDepth; // Recursion prevention static PRInt32 errorDepth; // Recursion prevention
++errorDepth; ++errorDepth;
@ -196,7 +191,6 @@ NS_ScriptErrorReporter(JSContext *cx,
--errorDepth; --errorDepth;
} }
}
if (status != nsEventStatus_eConsumeNoDefault) { if (status != nsEventStatus_eConsumeNoDefault) {
// Make an nsIScriptError and populate it with information from // Make an nsIScriptError and populate it with information from
@ -236,6 +230,8 @@ NS_ScriptErrorReporter(JSContext *cx,
} }
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
nsIScriptGlobalObjectOwner *owner =
globalObject->GetGlobalObjectOwner();
if (owner) { if (owner) {
owner->ReportScriptError(errorObject); owner->ReportScriptError(errorObject);
} else { } else {
@ -308,12 +304,8 @@ static JSBool
ChangeCase(JSContext *cx, JSString *src, jsval *rval, ChangeCase(JSContext *cx, JSString *src, jsval *rval,
void(* changeCaseFnc)(const nsAString&, nsAString&)) void(* changeCaseFnc)(const nsAString&, nsAString&))
{ {
nsDependentString str(NS_REINTERPRET_CAST(const PRUnichar *,
::JS_GetStringChars(src)),
::JS_GetStringLength(src));
nsAutoString result; nsAutoString result;
changeCaseFnc(str, result); changeCaseFnc(nsDependentJSString(src), result);
JSString *ucstr = JS_NewUCStringCopyN(cx, (jschar*)result.get(), result.Length()); JSString *ucstr = JS_NewUCStringCopyN(cx, (jschar*)result.get(), result.Length());
if (!ucstr) { if (!ucstr) {
@ -367,15 +359,10 @@ LocaleCompare(JSContext *cx, JSString *src1, JSString *src2, jsval *rval)
} }
} }
nsDependentString str1(NS_REINTERPRET_CAST(const PRUnichar *,
::JS_GetStringChars(src1)),
::JS_GetStringLength(src1));
nsDependentString str2(NS_REINTERPRET_CAST(const PRUnichar *,
::JS_GetStringChars(src2)),
::JS_GetStringLength(src2));
PRInt32 result; PRInt32 result;
rv = gCollation->CompareString(kCollationStrengthDefault, str1, str2, rv = gCollation->CompareString(kCollationStrengthDefault,
nsDependentJSString(src1),
nsDependentJSString(src2),
&result); &result);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
@ -433,12 +420,10 @@ nsJSContext::DOMBranchCallback(JSContext *cx, JSScript *script)
// If we get here we're most likely executing an infinite loop in JS, // If we get here we're most likely executing an infinite loop in JS,
// we'll tell the user about this and we'll give the user the option // we'll tell the user about this and we'll give the user the option
// of stopping the execution of the script. // of stopping the execution of the script.
nsCOMPtr<nsIScriptGlobalObject> global; nsIScriptGlobalObject *global = ctx->GetGlobalObject();
ctx->GetGlobalObject(getter_AddRefs(global));
NS_ENSURE_TRUE(global, JS_TRUE); NS_ENSURE_TRUE(global, JS_TRUE);
nsCOMPtr<nsIDocShell> docShell; nsIDocShell *docShell = global->GetDocShell();
global->GetDocShell(getter_AddRefs(docShell));
NS_ENSURE_TRUE(docShell, JS_TRUE); NS_ENSURE_TRUE(docShell, JS_TRUE);
nsCOMPtr<nsIInterfaceRequestor> ireq(do_QueryInterface(docShell)); nsCOMPtr<nsIInterfaceRequestor> ireq(do_QueryInterface(docShell));
@ -622,7 +607,7 @@ NS_IMPL_ADDREF(nsJSContext)
NS_IMPL_RELEASE(nsJSContext) NS_IMPL_RELEASE(nsJSContext)
NS_IMETHODIMP nsresult
nsJSContext::EvaluateStringWithValue(const nsAString& aScript, nsJSContext::EvaluateStringWithValue(const nsAString& aScript,
void *aScopeObject, void *aScopeObject,
nsIPrincipal *aPrincipal, nsIPrincipal *aPrincipal,
@ -655,11 +640,11 @@ nsJSContext::EvaluateStringWithValue(const nsAString& aScript,
aPrincipal->GetJSPrincipals(mContext, &jsprin); aPrincipal->GetJSPrincipals(mContext, &jsprin);
} }
else { else {
nsCOMPtr<nsIScriptGlobalObject> global; nsIScriptGlobalObject *global = GetGlobalObject();
GetGlobalObject(getter_AddRefs(global));
if (!global) if (!global)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
nsCOMPtr<nsIScriptObjectPrincipal> objPrincipal = do_QueryInterface(global, &rv); nsCOMPtr<nsIScriptObjectPrincipal> objPrincipal =
do_QueryInterface(global, &rv);
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
rv = objPrincipal->GetPrincipal(getter_AddRefs(principal)); rv = objPrincipal->GetPrincipal(getter_AddRefs(principal));
@ -670,10 +655,8 @@ nsJSContext::EvaluateStringWithValue(const nsAString& aScript,
// From here on, we must JSPRINCIPALS_DROP(jsprin) before returning... // From here on, we must JSPRINCIPALS_DROP(jsprin) before returning...
PRBool ok = PR_FALSE; PRBool ok = PR_FALSE;
nsCOMPtr<nsIScriptSecurityManager> securityManager;
rv = GetSecurityManager(getter_AddRefs(securityManager)); rv = sSecurityManager->CanExecuteScripts(mContext, principal, &ok);
if (NS_SUCCEEDED(rv))
rv = securityManager->CanExecuteScripts(mContext, principal, &ok);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
JSPRINCIPALS_DROP(mContext, jsprin); JSPRINCIPALS_DROP(mContext, jsprin);
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -805,7 +788,7 @@ JSValueToAString(JSContext *cx, jsval val, nsAString *result,
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP nsresult
nsJSContext::EvaluateString(const nsAString& aScript, nsJSContext::EvaluateString(const nsAString& aScript,
void *aScopeObject, void *aScopeObject,
nsIPrincipal *aPrincipal, nsIPrincipal *aPrincipal,
@ -834,8 +817,7 @@ nsJSContext::EvaluateString(const nsAString& aScript,
aPrincipal->GetJSPrincipals(mContext, &jsprin); aPrincipal->GetJSPrincipals(mContext, &jsprin);
} }
else { else {
nsCOMPtr<nsIScriptGlobalObject> global; nsIScriptGlobalObject *global = GetGlobalObject();
GetGlobalObject(getter_AddRefs(global));
if (!global) if (!global)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
nsCOMPtr<nsIScriptObjectPrincipal> objPrincipal = do_QueryInterface(global, &rv); nsCOMPtr<nsIScriptObjectPrincipal> objPrincipal = do_QueryInterface(global, &rv);
@ -849,10 +831,8 @@ nsJSContext::EvaluateString(const nsAString& aScript,
// From here on, we must JSPRINCIPALS_DROP(jsprin) before returning... // From here on, we must JSPRINCIPALS_DROP(jsprin) before returning...
PRBool ok = PR_FALSE; PRBool ok = PR_FALSE;
nsCOMPtr<nsIScriptSecurityManager> securityManager;
rv = GetSecurityManager(getter_AddRefs(securityManager)); rv = sSecurityManager->CanExecuteScripts(mContext, principal, &ok);
if (NS_SUCCEEDED(rv))
rv = securityManager->CanExecuteScripts(mContext, principal, &ok);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
JSPRINCIPALS_DROP(mContext, jsprin); JSPRINCIPALS_DROP(mContext, jsprin);
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -937,7 +917,7 @@ nsJSContext::EvaluateString(const nsAString& aScript,
return rv; return rv;
} }
NS_IMETHODIMP nsresult
nsJSContext::CompileScript(const PRUnichar* aText, nsJSContext::CompileScript(const PRUnichar* aText,
PRInt32 aTextLength, PRInt32 aTextLength,
void *aScopeObject, void *aScopeObject,
@ -958,10 +938,8 @@ nsJSContext::CompileScript(const PRUnichar* aText,
// From here on, we must JSPRINCIPALS_DROP(jsprin) before returning... // From here on, we must JSPRINCIPALS_DROP(jsprin) before returning...
PRBool ok = PR_FALSE; PRBool ok = PR_FALSE;
nsCOMPtr<nsIScriptSecurityManager> securityManager;
rv = GetSecurityManager(getter_AddRefs(securityManager)); rv = sSecurityManager->CanExecuteScripts(mContext, aPrincipal, &ok);
if (NS_SUCCEEDED(rv))
rv = securityManager->CanExecuteScripts(mContext, aPrincipal, &ok);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
JSPRINCIPALS_DROP(mContext, jsprin); JSPRINCIPALS_DROP(mContext, jsprin);
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -1008,7 +986,7 @@ nsJSContext::CompileScript(const PRUnichar* aText,
return rv; return rv;
} }
NS_IMETHODIMP nsresult
nsJSContext::ExecuteScript(void* aScriptObject, nsJSContext::ExecuteScript(void* aScriptObject,
void *aScopeObject, void *aScopeObject,
nsAString* aRetValue, nsAString* aRetValue,
@ -1106,7 +1084,7 @@ AtomToEventHandlerName(nsIAtom *aName)
return name; return name;
} }
NS_IMETHODIMP nsresult
nsJSContext::CompileEventHandler(void *aTarget, nsIAtom *aName, nsJSContext::CompileEventHandler(void *aTarget, nsIAtom *aName,
const nsAString& aBody, const nsAString& aBody,
const char *aURL, PRUint32 aLineNo, const char *aURL, PRUint32 aLineNo,
@ -1165,7 +1143,7 @@ nsJSContext::CompileEventHandler(void *aTarget, nsIAtom *aName,
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP nsresult
nsJSContext::CompileFunction(void* aTarget, nsJSContext::CompileFunction(void* aTarget,
const nsACString& aName, const nsACString& aName,
PRUint32 aArgCount, PRUint32 aArgCount,
@ -1178,8 +1156,7 @@ nsJSContext::CompileFunction(void* aTarget,
{ {
JSPrincipals *jsprin = nsnull; JSPrincipals *jsprin = nsnull;
nsCOMPtr<nsIScriptGlobalObject> global; nsIScriptGlobalObject *global = GetGlobalObject();
GetGlobalObject(getter_AddRefs(global));
if (global) { if (global) {
// XXXbe why the two-step QI? speed up via a new GetGlobalObjectData func? // XXXbe why the two-step QI? speed up via a new GetGlobalObjectData func?
nsCOMPtr<nsIScriptObjectPrincipal> globalData = do_QueryInterface(global); nsCOMPtr<nsIScriptObjectPrincipal> globalData = do_QueryInterface(global);
@ -1217,7 +1194,7 @@ nsJSContext::CompileFunction(void* aTarget,
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP nsresult
nsJSContext::CallEventHandler(void *aTarget, void *aHandler, PRUint32 argc, nsJSContext::CallEventHandler(void *aTarget, void *aHandler, PRUint32 argc,
void *argv, PRBool *aBoolResult) void *argv, PRBool *aBoolResult)
{ {
@ -1230,10 +1207,6 @@ nsJSContext::CallEventHandler(void *aTarget, void *aHandler, PRUint32 argc,
// This one's a lot easier than EvaluateString because we don't have to // This one's a lot easier than EvaluateString because we don't have to
// hassle with principals: they're already compiled into the JS function. // hassle with principals: they're already compiled into the JS function.
nsresult rv; nsresult rv;
nsCOMPtr<nsIScriptSecurityManager> securityManager;
rv = GetSecurityManager(getter_AddRefs(securityManager));
if (NS_FAILED(rv))
return NS_ERROR_FAILURE;
nsCOMPtr<nsIJSContextStack> stack = nsCOMPtr<nsIJSContextStack> stack =
do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv); do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv);
@ -1250,7 +1223,7 @@ nsJSContext::CallEventHandler(void *aTarget, void *aHandler, PRUint32 argc,
mTerminationFunc = nsnull; mTerminationFunc = nsnull;
// check if the event handler can be run on the object in question // check if the event handler can be run on the object in question
rv = securityManager->CheckFunctionAccess(mContext, aHandler, aTarget); rv = sSecurityManager->CheckFunctionAccess(mContext, aHandler, aTarget);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
jsval val; jsval val;
@ -1277,7 +1250,7 @@ nsJSContext::CallEventHandler(void *aTarget, void *aHandler, PRUint32 argc,
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP nsresult
nsJSContext::BindCompiledEventHandler(void *aTarget, nsIAtom *aName, nsJSContext::BindCompiledEventHandler(void *aTarget, nsIAtom *aName,
void *aHandler) void *aHandler)
{ {
@ -1301,22 +1274,20 @@ nsJSContext::BindCompiledEventHandler(void *aTarget, nsIAtom *aName,
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP void
nsJSContext::SetDefaultLanguageVersion(const char* aVersion) nsJSContext::SetDefaultLanguageVersion(const char* aVersion)
{ {
(void) ::JS_SetVersion(mContext, ::JS_StringToVersion(aVersion)); ::JS_SetVersion(mContext, ::JS_StringToVersion(aVersion));
return NS_OK;
} }
NS_IMETHODIMP nsIScriptGlobalObject *
nsJSContext::GetGlobalObject(nsIScriptGlobalObject** aGlobalObject) nsJSContext::GetGlobalObject()
{ {
JSObject *global = ::JS_GetGlobalObject(mContext); JSObject *global = ::JS_GetGlobalObject(mContext);
*aGlobalObject = nsnull;
if (!global) { if (!global) {
NS_WARNING("Context has no global."); NS_WARNING("Context has no global.");
return NS_OK; return nsnull;
} }
JSClass *c = JS_GET_CLASS(mContext, global); JSClass *c = JS_GET_CLASS(mContext, global);
@ -1324,42 +1295,44 @@ nsJSContext::GetGlobalObject(nsIScriptGlobalObject** aGlobalObject)
if (!c || ((~c->flags) & (JSCLASS_HAS_PRIVATE | if (!c || ((~c->flags) & (JSCLASS_HAS_PRIVATE |
JSCLASS_PRIVATE_IS_NSISUPPORTS))) { JSCLASS_PRIVATE_IS_NSISUPPORTS))) {
NS_WARNING("Global is not an nsISupports."); NS_WARNING("Global is not an nsISupports.");
return NS_OK; return nsnull;
} }
nsCOMPtr<nsISupports> native = nsCOMPtr<nsIScriptGlobalObject> sgo;
nsISupports *priv =
(nsISupports *)::JS_GetPrivate(mContext, global); (nsISupports *)::JS_GetPrivate(mContext, global);
nsCOMPtr<nsIXPConnectWrappedNative> wrapped_native = nsCOMPtr<nsIXPConnectWrappedNative> wrapped_native =
do_QueryInterface(native); do_QueryInterface(priv);
if (wrapped_native) { if (wrapped_native) {
// The global object is a XPConnect wrapped native, the native in // The global object is a XPConnect wrapped native, the native in
// the wrapper might be the nsIScriptGlobalObject // the wrapper might be the nsIScriptGlobalObject
nsCOMPtr<nsISupports> native;
wrapped_native->GetNative(getter_AddRefs(native)); wrapped_native->GetNative(getter_AddRefs(native));
NS_WARN_IF_FALSE(native,
"XPConnect wrapped native doesn't wrap anything.");
sgo = do_QueryInterface(native);
} else {
sgo = do_QueryInterface(priv);
} }
if (!native) { // This'll return a pointer to something we're about to release, but
NS_WARNING("XPConnect wrapped native doesn't wrap anything."); // that's ok, the JS object will hold it alive long enough.
return NS_OK; return sgo;
}
// We have private data (either directly from ::JS_GetPrivate() or
// through wrapped_native->GetNative()), check if it's a
// nsIScriptGlobalObject
return CallQueryInterface(native, aGlobalObject);
} }
NS_IMETHODIMP_(void*) void *
nsJSContext::GetNativeContext() nsJSContext::GetNativeContext()
{ {
return (void *)mContext; return mContext;
} }
NS_IMETHODIMP nsresult
nsJSContext::InitContext(nsIScriptGlobalObject *aGlobalObject) nsJSContext::InitContext(nsIScriptGlobalObject *aGlobalObject)
{ {
if (!mContext) if (!mContext)
@ -1685,21 +1658,19 @@ nsJSContext::InitClasses()
return rv; return rv;
} }
NS_IMETHODIMP PRBool
nsJSContext::IsContextInitialized() nsJSContext::IsContextInitialized()
{ {
return (mIsInitialized) ? NS_OK : NS_ERROR_NOT_INITIALIZED; return mIsInitialized;
} }
NS_IMETHODIMP void
nsJSContext::GC() nsJSContext::GC()
{ {
FireGCTimer(); FireGCTimer();
return NS_OK;
} }
NS_IMETHODIMP void
nsJSContext::ScriptEvaluated(PRBool aTerminated) nsJSContext::ScriptEvaluated(PRBool aTerminated)
{ {
if (aTerminated && mTerminationFunc) { if (aTerminated && mTerminationFunc) {
@ -1716,102 +1687,73 @@ nsJSContext::ScriptEvaluated(PRBool aTerminated)
} }
mBranchCallbackCount = 0; mBranchCallbackCount = 0;
return NS_OK;
} }
NS_IMETHODIMP void
nsJSContext::GetSecurityManager(nsIScriptSecurityManager **aInstancePtr)
{
*aInstancePtr = sSecurityManager;
if (!sSecurityManager) {
return NS_ERROR_NOT_AVAILABLE;
}
NS_ADDREF(*aInstancePtr);
return NS_OK;
}
NS_IMETHODIMP
nsJSContext::SetOwner(nsIScriptContextOwner* owner) nsJSContext::SetOwner(nsIScriptContextOwner* owner)
{ {
// The owner should not be addrefed!! We'll be told // The owner should not be addrefed!! We'll be told
// when the owner goes away. // when the owner goes away.
mOwner = owner; mOwner = owner;
return NS_OK;
} }
NS_IMETHODIMP nsIScriptContextOwner *
nsJSContext::GetOwner(nsIScriptContextOwner** owner) nsJSContext::GetOwner()
{ {
*owner = mOwner; return mOwner;
NS_IF_ADDREF(*owner);
return NS_OK;
} }
NS_IMETHODIMP void
nsJSContext::SetTerminationFunction(nsScriptTerminationFunc aFunc, nsJSContext::SetTerminationFunction(nsScriptTerminationFunc aFunc,
nsISupports* aRef) nsISupports* aRef)
{ {
mTerminationFunc = aFunc; mTerminationFunc = aFunc;
mTerminationFuncArg = aRef; mTerminationFuncArg = aRef;
return NS_OK;
} }
NS_IMETHODIMP PRBool
nsJSContext::GetScriptsEnabled(PRBool *aEnabled) nsJSContext::GetScriptsEnabled()
{ {
*aEnabled = mScriptsEnabled; return mScriptsEnabled;
return NS_OK;
} }
NS_IMETHODIMP void
nsJSContext::SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts) nsJSContext::SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts)
{ {
mScriptsEnabled = aEnabled; mScriptsEnabled = aEnabled;
nsCOMPtr<nsIScriptGlobalObject> global; nsIScriptGlobalObject *global = GetGlobalObject();
GetGlobalObject(getter_AddRefs(global));
if (global) { if (global) {
global->SetScriptsEnabled(aEnabled, aFireTimeouts); global->SetScriptsEnabled(aEnabled, aFireTimeouts);
} }
return NS_OK;
} }
NS_IMETHODIMP PRBool
nsJSContext::GetProcessingScriptTag(PRBool * aResult) nsJSContext::GetProcessingScriptTag()
{ {
*aResult = mProcessingScriptTag; return mProcessingScriptTag;
return NS_OK;
} }
NS_IMETHODIMP void
nsJSContext::SetProcessingScriptTag(PRBool aFlag) nsJSContext::SetProcessingScriptTag(PRBool aFlag)
{ {
mProcessingScriptTag = aFlag; mProcessingScriptTag = aFlag;
return NS_OK;
} }
NS_IMETHODIMP void
nsJSContext::SetGCOnDestruction(PRBool aGCOnDestruction) nsJSContext::SetGCOnDestruction(PRBool aGCOnDestruction)
{ {
mGCOnDestruction = aGCOnDestruction; mGCOnDestruction = aGCOnDestruction;
return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsJSContext::ScriptExecuted() nsJSContext::ScriptExecuted()
{ {
return ScriptEvaluated(PR_FALSE); ScriptEvaluated(PR_FALSE);
return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -1870,7 +1812,8 @@ DOMGCCallback(JSContext *cx, JSGCStatus status)
} }
// static // static
nsresult nsJSEnvironment::Init() nsresult
nsJSEnvironment::Init()
{ {
static PRBool isInitialized; static PRBool isInitialized;
@ -1990,8 +1933,7 @@ NS_CreateScriptContext(nsIScriptGlobalObject *aGlobal,
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
if (aGlobal) { if (aGlobal) {
rv = aGlobal->SetContext(scriptContext); aGlobal->SetContext(scriptContext);
NS_ENSURE_SUCCESS(rv, rv);
} }
*aContext = scriptContext; *aContext = scriptContext;

Просмотреть файл

@ -58,7 +58,7 @@ public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
NS_IMETHOD EvaluateString(const nsAString& aScript, virtual nsresult EvaluateString(const nsAString& aScript,
void *aScopeObject, void *aScopeObject,
nsIPrincipal *principal, nsIPrincipal *principal,
const char *aURL, const char *aURL,
@ -66,7 +66,7 @@ public:
const char* aVersion, const char* aVersion,
nsAString& aRetValue, nsAString& aRetValue,
PRBool* aIsUndefined); PRBool* aIsUndefined);
NS_IMETHOD EvaluateStringWithValue(const nsAString& aScript, virtual nsresult EvaluateStringWithValue(const nsAString& aScript,
void *aScopeObject, void *aScopeObject,
nsIPrincipal *aPrincipal, nsIPrincipal *aPrincipal,
const char *aURL, const char *aURL,
@ -75,7 +75,7 @@ public:
void* aRetValue, void* aRetValue,
PRBool* aIsUndefined); PRBool* aIsUndefined);
NS_IMETHOD CompileScript(const PRUnichar* aText, virtual nsresult CompileScript(const PRUnichar* aText,
PRInt32 aTextLength, PRInt32 aTextLength,
void *aScopeObject, void *aScopeObject,
nsIPrincipal *principal, nsIPrincipal *principal,
@ -83,24 +83,24 @@ public:
PRUint32 aLineNo, PRUint32 aLineNo,
const char* aVersion, const char* aVersion,
void** aScriptObject); void** aScriptObject);
NS_IMETHOD ExecuteScript(void* aScriptObject, virtual nsresult ExecuteScript(void* aScriptObject,
void *aScopeObject, void *aScopeObject,
nsAString* aRetValue, nsAString* aRetValue,
PRBool* aIsUndefined); PRBool* aIsUndefined);
NS_IMETHOD CompileEventHandler(void *aTarget, virtual nsresult CompileEventHandler(void *aTarget,
nsIAtom *aName, nsIAtom *aName,
const nsAString& aBody, const nsAString& aBody,
const char *aURL, const char *aURL,
PRUint32 aLineNo, PRUint32 aLineNo,
PRBool aShared, PRBool aShared,
void** aHandler); void** aHandler);
NS_IMETHOD CallEventHandler(void *aTarget, void *aHandler, virtual nsresult CallEventHandler(void *aTarget, void *aHandler,
PRUint32 argc, void *argv, PRUint32 argc, void *argv,
PRBool *aBoolResult); PRBool *aBoolResult);
NS_IMETHOD BindCompiledEventHandler(void *aTarget, virtual nsresult BindCompiledEventHandler(void *aTarget,
nsIAtom *aName, nsIAtom *aName,
void *aHandler); void *aHandler);
NS_IMETHOD CompileFunction(void* aTarget, virtual nsresult CompileFunction(void* aTarget,
const nsACString& aName, const nsACString& aName,
PRUint32 aArgCount, PRUint32 aArgCount,
const char** aArgArray, const char** aArgArray,
@ -110,26 +110,25 @@ public:
PRBool aShared, PRBool aShared,
void** aFunctionObject); void** aFunctionObject);
NS_IMETHOD SetDefaultLanguageVersion(const char* aVersion); virtual void SetDefaultLanguageVersion(const char* aVersion);
NS_IMETHOD GetGlobalObject(nsIScriptGlobalObject** aGlobalObject); virtual nsIScriptGlobalObject *GetGlobalObject();
NS_IMETHOD_(void *) GetNativeContext(); virtual void *GetNativeContext();
NS_IMETHOD InitContext(nsIScriptGlobalObject *aGlobalObject); virtual nsresult InitContext(nsIScriptGlobalObject *aGlobalObject);
NS_IMETHOD IsContextInitialized(); virtual PRBool IsContextInitialized();
NS_IMETHOD GC(); virtual void GC();
NS_IMETHOD GetSecurityManager(nsIScriptSecurityManager** aInstancePtr);
NS_IMETHOD ScriptEvaluated(PRBool aTerminated); virtual void ScriptEvaluated(PRBool aTerminated);
NS_IMETHOD SetOwner(nsIScriptContextOwner* owner); virtual void SetOwner(nsIScriptContextOwner* owner);
NS_IMETHOD GetOwner(nsIScriptContextOwner** owner); virtual nsIScriptContextOwner *GetOwner();
NS_IMETHOD SetTerminationFunction(nsScriptTerminationFunc aFunc, virtual void SetTerminationFunction(nsScriptTerminationFunc aFunc,
nsISupports* aRef); nsISupports* aRef);
NS_IMETHOD GetScriptsEnabled(PRBool *aEnabled); virtual PRBool GetScriptsEnabled();
NS_IMETHOD SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts); virtual void SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts);
NS_IMETHOD GetProcessingScriptTag(PRBool * aResult); virtual PRBool GetProcessingScriptTag();
NS_IMETHOD SetProcessingScriptTag(PRBool aResult); virtual void SetProcessingScriptTag(PRBool aResult);
NS_IMETHOD SetGCOnDestruction(PRBool aGCOnDestruction); virtual void SetGCOnDestruction(PRBool aGCOnDestruction);
NS_DECL_NSIXPCSCRIPTNOTIFY NS_DECL_NSIXPCSCRIPTNOTIFY

Просмотреть файл

@ -91,9 +91,8 @@ nsJSUtils::GetCallingLocation(JSContext* aContext, const char* *aFilename,
return JS_FALSE; return JS_FALSE;
} }
void jsval
nsJSUtils::ConvertStringToJSVal(const nsString& aProp, JSContext* aContext, nsJSUtils::ConvertStringToJSVal(const nsString& aProp, JSContext* aContext)
jsval* aReturn)
{ {
JSString *jsstring = JSString *jsstring =
::JS_NewUCStringCopyN(aContext, NS_REINTERPRET_CAST(const jschar*, ::JS_NewUCStringCopyN(aContext, NS_REINTERPRET_CAST(const jschar*,
@ -101,7 +100,7 @@ nsJSUtils::ConvertStringToJSVal(const nsString& aProp, JSContext* aContext,
aProp.Length()); aProp.Length());
// set the return value // set the return value
*aReturn = STRING_TO_JSVAL(jsstring); return STRING_TO_JSVAL(jsstring);
} }
PRBool PRBool
@ -162,9 +161,8 @@ nsJSUtils::ConvertJSValToUint32(PRUint32* aProp, JSContext* aContext,
return JS_TRUE; return JS_TRUE;
} }
nsresult nsIScriptGlobalObject *
nsJSUtils::GetStaticScriptGlobal(JSContext* aContext, JSObject* aObj, nsJSUtils::GetStaticScriptGlobal(JSContext* aContext, JSObject* aObj)
nsIScriptGlobalObject** aNativeGlobal)
{ {
nsISupports* supports; nsISupports* supports;
JSClass* clazz; JSClass* clazz;
@ -172,7 +170,7 @@ nsJSUtils::GetStaticScriptGlobal(JSContext* aContext, JSObject* aObj,
JSObject* glob = aObj; // starting point for search JSObject* glob = aObj; // starting point for search
if (!glob) if (!glob)
return NS_ERROR_FAILURE; return nsnull;
while ((parent = ::JS_GetParent(aContext, glob))) while ((parent = ::JS_GetParent(aContext, glob)))
glob = parent; glob = parent;
@ -183,47 +181,44 @@ nsJSUtils::GetStaticScriptGlobal(JSContext* aContext, JSObject* aObj,
!(clazz->flags & JSCLASS_HAS_PRIVATE) || !(clazz->flags & JSCLASS_HAS_PRIVATE) ||
!(clazz->flags & JSCLASS_PRIVATE_IS_NSISUPPORTS) || !(clazz->flags & JSCLASS_PRIVATE_IS_NSISUPPORTS) ||
!(supports = (nsISupports*)::JS_GetPrivate(aContext, glob))) { !(supports = (nsISupports*)::JS_GetPrivate(aContext, glob))) {
return NS_ERROR_FAILURE; return nsnull;
} }
nsCOMPtr<nsIXPConnectWrappedNative> wrapper(do_QueryInterface(supports)); nsCOMPtr<nsIXPConnectWrappedNative> wrapper(do_QueryInterface(supports));
NS_ENSURE_TRUE(wrapper, NS_ERROR_UNEXPECTED); NS_ENSURE_TRUE(wrapper, nsnull);
nsCOMPtr<nsISupports> native; nsCOMPtr<nsISupports> native;
wrapper->GetNative(getter_AddRefs(native)); wrapper->GetNative(getter_AddRefs(native));
return CallQueryInterface(native, aNativeGlobal); nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(native));
// We're returning a pointer to something that's about to be
// released, but that's ok here.
return sgo;
} }
nsresult nsIScriptContext *
nsJSUtils::GetStaticScriptContext(JSContext* aContext, JSObject* aObj, nsJSUtils::GetStaticScriptContext(JSContext* aContext, JSObject* aObj)
nsIScriptContext** aScriptContext)
{ {
nsCOMPtr<nsIScriptGlobalObject> nativeGlobal; nsIScriptGlobalObject *nativeGlobal = GetStaticScriptGlobal(aContext, aObj);
GetStaticScriptGlobal(aContext, aObj, getter_AddRefs(nativeGlobal));
if (!nativeGlobal) if (!nativeGlobal)
return NS_ERROR_FAILURE; return nsnull;
nsIScriptContext* scriptContext = nsnull;
nativeGlobal->GetContext(&scriptContext); return nativeGlobal->GetContext();
*aScriptContext = scriptContext;
return scriptContext ? NS_OK : NS_ERROR_FAILURE;
} }
nsresult nsIScriptGlobalObject *
nsJSUtils::GetDynamicScriptGlobal(JSContext* aContext, nsJSUtils::GetDynamicScriptGlobal(JSContext* aContext)
nsIScriptGlobalObject** aNativeGlobal)
{ {
nsCOMPtr<nsIScriptContext> scriptCX; nsIScriptContext *scriptCX = GetDynamicScriptContext(aContext);
GetDynamicScriptContext(aContext, getter_AddRefs(scriptCX));
if (!scriptCX) if (!scriptCX)
return NS_ERROR_FAILURE; return nsnull;
return scriptCX->GetGlobalObject(aNativeGlobal); return scriptCX->GetGlobalObject();
} }
nsresult nsIScriptContext *
nsJSUtils::GetDynamicScriptContext(JSContext *aContext, nsJSUtils::GetDynamicScriptContext(JSContext *aContext)
nsIScriptContext** aScriptContext)
{ {
return GetScriptContextFromJSContext(aContext, aScriptContext); return GetScriptContextFromJSContext(aContext);
} }

Просмотреть файл

@ -53,15 +53,15 @@
class nsIDOMEventListener; class nsIDOMEventListener;
class nsIScriptContext; class nsIScriptContext;
class nsIScriptGlobalObject; class nsIScriptGlobalObject;
class nsIScriptSecurityManager;
class nsJSUtils { class nsJSUtils
{
public: public:
static JSBool GetCallingLocation(JSContext* aContext, const char* *aFilename, static JSBool GetCallingLocation(JSContext* aContext, const char* *aFilename,
PRUint32 *aLineno); PRUint32 *aLineno);
static void ConvertStringToJSVal(const nsString& aProp, JSContext* aContext, static jsval ConvertStringToJSVal(const nsString& aProp,
jsval* aReturn); JSContext* aContext);
static PRBool ConvertJSValToXPCObject(nsISupports** aSupports, REFNSIID aIID, static PRBool ConvertJSValToXPCObject(nsISupports** aSupports, REFNSIID aIID,
JSContext* aContext, jsval aValue); JSContext* aContext, jsval aValue);
@ -72,17 +72,35 @@ public:
static PRBool ConvertJSValToUint32(PRUint32* aProp, JSContext* aContext, static PRBool ConvertJSValToUint32(PRUint32* aProp, JSContext* aContext,
jsval aValue); jsval aValue);
static nsresult GetStaticScriptGlobal(JSContext* aContext, JSObject* aObj, static nsIScriptGlobalObject *GetStaticScriptGlobal(JSContext* aContext,
nsIScriptGlobalObject** aGlobal); JSObject* aObj);
static nsresult GetStaticScriptContext(JSContext* aContext, JSObject* aObj, static nsIScriptContext *GetStaticScriptContext(JSContext* aContext,
nsIScriptContext** aScriptContext); JSObject* aObj);
static nsresult GetDynamicScriptGlobal(JSContext *aContext, static nsIScriptGlobalObject *GetDynamicScriptGlobal(JSContext *aContext);
nsIScriptGlobalObject** aGlobal);
static nsresult GetDynamicScriptContext(JSContext *aContext, static nsIScriptContext *GetDynamicScriptContext(JSContext *aContext);
nsIScriptContext** aScriptContext); };
class nsDependentJSString : public nsDependentString
{
public:
explicit nsDependentJSString(jsval v)
: nsDependentString((PRUnichar *)::JS_GetStringChars(JSVAL_TO_STRING(v)),
::JS_GetStringLength(JSVAL_TO_STRING(v)))
{
}
explicit nsDependentJSString(JSString *str)
: nsDependentString(::JS_GetStringChars(str), ::JS_GetStringLength(str))
{
}
~nsDependentJSString()
{
}
}; };
#endif /* nsJSUtils_h__ */ #endif /* nsJSUtils_h__ */

Просмотреть файл

@ -69,7 +69,8 @@
#include "nsIProtocolHandler.h" #include "nsIProtocolHandler.h"
#include "nsReadableUtils.h" #include "nsReadableUtils.h"
static nsresult GetDocumentCharacterSetForURI(const nsAString& aHref, nsACString& aCharset) static nsresult
GetDocumentCharacterSetForURI(const nsAString& aHref, nsACString& aCharset)
{ {
aCharset.Truncate(); aCharset.Truncate();
@ -83,11 +84,8 @@ static nsresult GetDocumentCharacterSetForURI(const nsAString& aHref, nsACString
rv = stack->Peek(&cx); rv = stack->Peek(&cx);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIScriptGlobalObject> nativeGlob; nsCOMPtr<nsIDOMWindow> window =
nsJSUtils::GetDynamicScriptGlobal(cx, getter_AddRefs(nativeGlob)); do_QueryInterface(nsJSUtils::GetDynamicScriptGlobal(cx));
NS_ENSURE_TRUE(nativeGlob, NS_ERROR_FAILURE);
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(nativeGlob);
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE); NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
nsCOMPtr<nsIDOMDocument> domDoc; nsCOMPtr<nsIDOMDocument> domDoc;
@ -125,7 +123,8 @@ NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(LocationImpl) NS_IMPL_ADDREF(LocationImpl)
NS_IMPL_RELEASE(LocationImpl) NS_IMPL_RELEASE(LocationImpl)
NS_IMETHODIMP_(void) LocationImpl::SetDocShell(nsIDocShell *aDocShell) void
LocationImpl::SetDocShell(nsIDocShell *aDocShell)
{ {
mDocShell = aDocShell; // Weak Reference mDocShell = aDocShell; // Weak Reference
} }
@ -573,11 +572,11 @@ LocationImpl::SetHrefWithBase(const nsAString& aHref,
result = stack->Peek(&cx); result = stack->Peek(&cx);
if (cx) { if (cx) {
nsCOMPtr<nsIScriptContext> scriptContext; nsIScriptContext *scriptContext =
nsJSUtils::GetDynamicScriptContext(cx, getter_AddRefs(scriptContext)); nsJSUtils::GetDynamicScriptContext(cx);
if (scriptContext) { if (scriptContext) {
scriptContext->GetProcessingScriptTag(&inScriptTag); inScriptTag = scriptContext->GetProcessingScriptTag();
} }
} //cx } //cx
} // stack } // stack
@ -907,10 +906,8 @@ LocationImpl::GetSourceDocument(JSContext* cx, nsIDocument** aDocument)
// that we can get the url of the caller. // that we can get the url of the caller.
// XXX This will fail on non-DOM contexts :( // XXX This will fail on non-DOM contexts :(
nsCOMPtr<nsIScriptGlobalObject> nativeGlob; nsCOMPtr<nsIDOMWindow> window =
nsJSUtils::GetDynamicScriptGlobal(cx, getter_AddRefs(nativeGlob)); do_QueryInterface(nsJSUtils::GetDynamicScriptGlobal(cx), &rv);
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(nativeGlob, &rv);
if (window) { if (window) {
nsCOMPtr<nsIDOMDocument> domDoc; nsCOMPtr<nsIDOMDocument> domDoc;

Просмотреть файл

@ -1,388 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
*
* This Original Code has been modified by IBM Corporation.
* Modifications made by IBM described herein are
* Copyright (c) International Business Machines
* Corporation, 2000
*
* Modifications to Mozilla code or documentation
* identified per MPL Section 3.3
*
* Date Modified by Description of modification
* 03/27/2000 IBM Corp. Added PR_CALLBACK for Optlink
* use in OS2
*/
#include "nscore.h"
#include "nsIGenericFactory.h"
#include "nsJSEnvironment.h"
#include "nsIScriptGlobalObject.h"
#include "nsDOMCID.h"
#include "nsIDOMScriptObjectFactory.h"
#include "nsIScriptEventListener.h"
#include "nsIJSEventListener.h"
#include "nsIScriptContext.h"
#include "nsDOMClassInfo.h"
#include "nsGlobalWindow.h"
#include "nsIObserverService.h"
#include "nsIJSContextStack.h"
#include "nsIExceptionService.h"
#ifdef MOZ_XUL
#include "nsIXULPrototypeCache.h"
#endif
#include "nsCRT.h"
#include "nsIController.h"
#include "nsIControllerContext.h"
#include "nsIControllerCommandTable.h"
#include "nsGlobalWindowCommands.h"
#include "nsScriptNameSpaceManager.h"
#include "nsDOMException.h"
#include "nsJSProtocolHandler.h"
#define NS_WINDOWCOMMANDTABLE_CID \
{ /* 0DE2FBFA-6B7F-11D7-BBBA-0003938A9D96 */ \
0x0DE2FBFA, 0x6B7F, 0x11D7, {0xBB, 0xBA, 0x00, 0x03, 0x93, 0x8A, 0x9D, 0x96} }
static NS_DEFINE_CID(kWindowCommandTableCID, NS_WINDOWCOMMANDTABLE_CID);
extern nsresult NS_CreateScriptContext(nsIScriptGlobalObject *aGlobal,
nsIScriptContext **aContext);
extern nsresult NS_NewJSEventListener(nsIDOMEventListener **aInstancePtrResult,
nsIScriptContext *aContext,
nsISupports *aObject);
extern nsresult NS_NewScriptGlobalObject(PRBool aIsChrome,
nsIScriptGlobalObject **aGlobal);
extern nsresult NS_NewDOMException(nsresult aResult,
nsIException* aDefaultException,
nsIException** aException);
extern nsresult NS_NewRangeException(nsresult aResult,
nsIException* aDefaultException,
nsIException** aException);
//////////////////////////////////////////////////////////////////////
class nsDOMSOFactory : public nsIDOMScriptObjectFactory,
public nsIObserver,
public nsIExceptionProvider
{
public:
nsDOMSOFactory();
virtual ~nsDOMSOFactory();
NS_DECL_ISUPPORTS
// nsIObserver
NS_DECL_NSIOBSERVER
// nsIExceptionProvider
NS_DECL_NSIEXCEPTIONPROVIDER
NS_IMETHOD NewScriptContext(nsIScriptGlobalObject *aGlobal,
nsIScriptContext **aContext);
NS_IMETHOD NewJSEventListener(nsIScriptContext *aContext,
nsISupports* aObject,
nsIDOMEventListener ** aInstancePtrResult);
NS_IMETHOD NewScriptGlobalObject(PRBool aIsChrome,
nsIScriptGlobalObject **aGlobal);
NS_IMETHOD_(nsISupports *)GetClassInfoInstance(nsDOMClassInfoID aID);
NS_IMETHOD_(nsISupports *)GetExternalClassInfoInstance(const nsAString& aName);
NS_IMETHOD RegisterDOMClassInfo(const char *aName,
nsDOMClassInfoExternalConstructorFnc aConstructorFptr,
const nsIID *aProtoChainInterface,
const nsIID **aInterfaces,
PRUint32 aScriptableFlags,
PRBool aHasClassInterface,
const nsCID *aConstructorCID);
};
nsDOMSOFactory::nsDOMSOFactory()
{
nsCOMPtr<nsIObserverService> observerService =
do_GetService("@mozilla.org/observer-service;1");
if (observerService) {
observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE);
}
nsCOMPtr<nsIExceptionService> xs =
do_GetService(NS_EXCEPTIONSERVICE_CONTRACTID);
if (xs) {
xs->RegisterExceptionProvider(this, NS_ERROR_MODULE_DOM);
xs->RegisterExceptionProvider(this, NS_ERROR_MODULE_DOM_RANGE);
}
}
nsDOMSOFactory::~nsDOMSOFactory()
{
}
NS_INTERFACE_MAP_BEGIN(nsDOMSOFactory)
NS_INTERFACE_MAP_ENTRY(nsIDOMScriptObjectFactory)
NS_INTERFACE_MAP_ENTRY(nsIObserver)
NS_INTERFACE_MAP_ENTRY(nsIExceptionProvider)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMScriptObjectFactory)
NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(nsDOMSOFactory)
NS_IMPL_RELEASE(nsDOMSOFactory)
NS_IMETHODIMP
nsDOMSOFactory::NewScriptContext(nsIScriptGlobalObject *aGlobal,
nsIScriptContext **aContext)
{
return NS_CreateScriptContext(aGlobal, aContext);
}
NS_IMETHODIMP
nsDOMSOFactory::NewJSEventListener(nsIScriptContext *aContext,
nsISupports *aObject,
nsIDOMEventListener **aInstancePtrResult)
{
return NS_NewJSEventListener(aInstancePtrResult, aContext, aObject);
}
NS_IMETHODIMP
nsDOMSOFactory::NewScriptGlobalObject(PRBool aIsChrome,
nsIScriptGlobalObject **aGlobal)
{
return NS_NewScriptGlobalObject(aIsChrome, aGlobal);
}
NS_IMETHODIMP_(nsISupports *)
nsDOMSOFactory::GetClassInfoInstance(nsDOMClassInfoID aID)
{
return nsDOMClassInfo::GetClassInfoInstance(aID);
}
NS_IMETHODIMP_(nsISupports *)
nsDOMSOFactory::GetExternalClassInfoInstance(const nsAString& aName)
{
extern nsScriptNameSpaceManager *gNameSpaceManager;
NS_ENSURE_TRUE(gNameSpaceManager, nsnull);
const nsGlobalNameStruct *globalStruct;
gNameSpaceManager->LookupName(aName, &globalStruct);
if (globalStruct) {
if (globalStruct->mType == nsGlobalNameStruct::eTypeExternalClassInfoCreator) {
nsresult rv;
nsCOMPtr<nsIDOMCIExtension> creator(do_CreateInstance(globalStruct->mCID, &rv));
NS_ENSURE_SUCCESS(rv, nsnull);
rv = creator->RegisterDOMCI(NS_ConvertUCS2toUTF8(aName).get(), this);
NS_ENSURE_SUCCESS(rv, nsnull);
rv = gNameSpaceManager->LookupName(aName, &globalStruct);
NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && globalStruct, nsnull);
NS_ASSERTION(globalStruct->mType == nsGlobalNameStruct::eTypeExternalClassInfo,
"The classinfo data for this class didn't get registered.");
}
if (globalStruct->mType == nsGlobalNameStruct::eTypeExternalClassInfo) {
return nsDOMClassInfo::GetClassInfoInstance(globalStruct->mData);
}
}
return nsnull;
}
NS_IMETHODIMP
nsDOMSOFactory::Observe(nsISupports *aSubject,
const char *aTopic,
const PRUnichar *someData)
{
if (!nsCRT::strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
#ifdef MOZ_XUL
// Flush the XUL cache since it holds JS roots, and we're about to
// start the final GC.
nsCOMPtr<nsIXULPrototypeCache> cache =
do_GetService("@mozilla.org/xul/xul-prototype-cache;1");
if (cache)
cache->Flush();
#endif
nsCOMPtr<nsIThreadJSContextStack> stack =
do_GetService("@mozilla.org/js/xpc/ContextStack;1");
if (stack) {
JSContext *cx = nsnull;
stack->GetSafeJSContext(&cx);
if (cx) {
// Do one final GC to clean things up before shutdown.
::JS_GC(cx);
}
}
GlobalWindowImpl::ShutDown();
nsDOMClassInfo::ShutDown();
nsJSEnvironment::ShutDown();
nsCOMPtr<nsIExceptionService> xs =
do_GetService(NS_EXCEPTIONSERVICE_CONTRACTID);
if (xs) {
xs->UnregisterExceptionProvider(this, NS_ERROR_MODULE_DOM);
}
}
return NS_OK;
}
NS_IMETHODIMP
nsDOMSOFactory::GetException(nsresult result, nsIException *aDefaultException,
nsIException **_retval)
{
if (NS_ERROR_GET_MODULE(result) == NS_ERROR_MODULE_DOM_RANGE) {
return NS_NewRangeException(result, aDefaultException, _retval);
}
return NS_NewDOMException(result, aDefaultException, _retval);
}
NS_IMETHODIMP
nsDOMSOFactory::RegisterDOMClassInfo(const char *aName,
nsDOMClassInfoExternalConstructorFnc aConstructorFptr,
const nsIID *aProtoChainInterface,
const nsIID **aInterfaces,
PRUint32 aScriptableFlags,
PRBool aHasClassInterface,
const nsCID *aConstructorCID)
{
extern nsScriptNameSpaceManager *gNameSpaceManager;
NS_ENSURE_TRUE(gNameSpaceManager, NS_ERROR_NOT_INITIALIZED);
return gNameSpaceManager->RegisterDOMCIData(aName,
aConstructorFptr,
aProtoChainInterface,
aInterfaces,
aScriptableFlags,
aHasClassInterface,
aConstructorCID);
}
//////////////////////////////////////////////////////////////////////
static NS_METHOD
CreateWindowCommandTableConstructor(nsISupports *aOuter,
REFNSIID aIID, void **aResult)
{
nsresult rv;
nsCOMPtr<nsIControllerCommandTable> commandTable =
do_CreateInstance(NS_CONTROLLERCOMMANDTABLE_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
rv = nsWindowCommandRegistration::RegisterWindowCommands(commandTable);
if (NS_FAILED(rv)) return rv;
return commandTable->QueryInterface(aIID, aResult);
}
static NS_METHOD
CreateWindowControllerWithSingletonCommandTable(nsISupports *aOuter,
REFNSIID aIID, void **aResult)
{
nsresult rv;
nsCOMPtr<nsIController> controller =
do_CreateInstance("@mozilla.org/embedcomp/base-command-controller;1", &rv);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIControllerCommandTable> windowCommandTable = do_GetService(kWindowCommandTableCID, &rv);
if (NS_FAILED(rv)) return rv;
// this is a singleton; make it immutable
windowCommandTable->MakeImmutable();
nsCOMPtr<nsIControllerContext> controllerContext = do_QueryInterface(controller, &rv);
if (NS_FAILED(rv)) return rv;
controllerContext->Init(windowCommandTable);
if (NS_FAILED(rv)) return rv;
return controller->QueryInterface(aIID, aResult);
}
//////////////////////////////////////////////////////////////////////
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDOMSOFactory)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBaseDOMException)
static const nsModuleComponentInfo gDOMModuleInfo[] = {
{ "Script Object Factory",
NS_DOM_SCRIPT_OBJECT_FACTORY_CID,
nsnull,
nsDOMSOFactoryConstructor
},
{ "Base DOM Exception",
NS_BASE_DOM_EXCEPTION_CID,
nsnull,
nsBaseDOMExceptionConstructor
},
{ "JavaScript Protocol Handler",
NS_JSPROTOCOLHANDLER_CID,
NS_JSPROTOCOLHANDLER_CONTRACTID,
nsJSProtocolHandler::Create },
{ "Window Command Table",
NS_WINDOWCOMMANDTABLE_CID,
"",
CreateWindowCommandTableConstructor
},
{ "Window Command Controller",
NS_WINDOWCONTROLLER_CID,
NS_WINDOWCONTROLLER_CONTRACTID,
CreateWindowControllerWithSingletonCommandTable
},
};
void PR_CALLBACK
DOMModuleDestructor(nsIModule *self)
{
GlobalWindowImpl::ShutDown();
nsDOMClassInfo::ShutDown();
}
NS_IMPL_NSGETMODULE_WITH_DTOR(DOM_components, gDOMModuleInfo,
DOMModuleDestructor)

Просмотреть файл

@ -37,7 +37,7 @@
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
#include "nsJSEventListener.h" #include "nsJSEventListener.h"
#include "nsString.h" #include "nsString.h"
#include "nsIScriptEventListener.h" #include "nsReadableUtils.h"
#include "nsIServiceManager.h" #include "nsIServiceManager.h"
#include "nsIJSContextStack.h" #include "nsIJSContextStack.h"
#include "nsIScriptSecurityManager.h" #include "nsIScriptSecurityManager.h"
@ -52,14 +52,8 @@
*/ */
nsJSEventListener::nsJSEventListener(nsIScriptContext *aContext, nsJSEventListener::nsJSEventListener(nsIScriptContext *aContext,
nsISupports *aObject) nsISupports *aObject)
: nsIJSEventListener(aContext, aObject)
{ {
// mObject is a weak reference. We are guaranteed
// because of the ownership model that this object will be
// freed (and the references dropped) before either the context
// or the owner goes away.
mContext = aContext;
mObject = aObject;
mReturnResult = nsReturnResult_eNotSet; mReturnResult = nsReturnResult_eNotSet;
} }
@ -79,13 +73,14 @@ NS_IMPL_RELEASE(nsJSEventListener)
//static nsString onPrefix = "on"; //static nsString onPrefix = "on";
nsresult nsJSEventListener::SetEventName(nsIAtom* aName) void
nsJSEventListener::SetEventName(nsIAtom* aName)
{ {
mEventName = aName; mEventName = aName;
return NS_OK;
} }
nsresult nsJSEventListener::HandleEvent(nsIDOMEvent* aEvent) nsresult
nsJSEventListener::HandleEvent(nsIDOMEvent* aEvent)
{ {
jsval funval; jsval funval;
jsval arg; jsval arg;
@ -122,7 +117,7 @@ nsresult nsJSEventListener::HandleEvent(nsIDOMEvent* aEvent)
// root // root
nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper; nsCOMPtr<nsIXPConnectJSObjectHolder> wrapper;
rv = xpc->WrapNative(cx, ::JS_GetGlobalObject(cx), mObject, rv = xpc->WrapNative(cx, ::JS_GetGlobalObject(cx), mTarget,
NS_GET_IID(nsISupports), getter_AddRefs(wrapper)); NS_GET_IID(nsISupports), getter_AddRefs(wrapper));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
@ -193,22 +188,6 @@ nsresult nsJSEventListener::HandleEvent(nsIDOMEvent* aEvent)
return rv; return rv;
} }
NS_IMETHODIMP
nsJSEventListener::GetEventTarget(nsIScriptContext**aContext,
nsISupports** aTarget)
{
NS_ENSURE_ARG_POINTER(aContext);
NS_ENSURE_ARG_POINTER(aTarget);
*aContext = mContext;
NS_ADDREF(*aContext);
*aTarget = mObject;
NS_ADDREF(*aTarget);
return NS_OK;
}
/* /*
* Factory functions * Factory functions
*/ */

Просмотреть файл

@ -40,7 +40,6 @@
#define nsJSEventListener_h__ #define nsJSEventListener_h__
#include "nsIDOMKeyEvent.h" #include "nsIDOMKeyEvent.h"
#include "nsIScriptEventListener.h"
#include "nsIJSEventListener.h" #include "nsIJSEventListener.h"
#include "nsIDOMMouseListener.h" #include "nsIDOMMouseListener.h"
#include "jsapi.h" #include "jsapi.h"
@ -58,18 +57,13 @@ public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
//nsIDOMEventListener interface // nsIDOMEventListener interface
NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent); NS_DECL_NSIDOMEVENTLISTENER
//nsIJSEventListener interface // nsIJSEventListener interface
NS_IMETHOD GetEventTarget(nsIScriptContext** aContext, virtual void SetEventName(nsIAtom* aName);
nsISupports** aTarget);
NS_IMETHOD SetEventName(nsIAtom* aName);
protected: protected:
nsCOMPtr<nsIScriptContext> mContext;
nsISupports* mObject;
nsCOMPtr<nsIAtom> mEventName; nsCOMPtr<nsIAtom> mEventName;
enum nsReturnResult { enum nsReturnResult {

Просмотреть файл

@ -184,12 +184,9 @@ nsresult nsJSThunk::EvaluateScript(nsIChannel *aChannel)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
nsCOMPtr<nsIScriptContext> scriptContext; nsIScriptContext *scriptContext = global->GetContext();
rv = global->GetContext(getter_AddRefs(scriptContext)); if (!scriptContext)
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
return rv;
if (!scriptContext) return NS_ERROR_FAILURE;
// Unescape the script // Unescape the script
NS_UnescapeURL(script); NS_UnescapeURL(script);

Просмотреть файл

@ -233,9 +233,7 @@ nsComposerCommandsUpdater::Init(nsIDOMWindow* aDOMWindow)
nsCOMPtr<nsIScriptGlobalObject> scriptObject(do_QueryInterface(aDOMWindow)); nsCOMPtr<nsIScriptGlobalObject> scriptObject(do_QueryInterface(aDOMWindow));
if (scriptObject) if (scriptObject)
{ {
nsCOMPtr<nsIDocShell> docShell; mDocShell = scriptObject->GetDocShell();
scriptObject->GetDocShell(getter_AddRefs(docShell));
mDocShell = docShell.get();
} }
return NS_OK; return NS_OK;
} }

Просмотреть файл

@ -126,9 +126,8 @@ NS_IMPL_ISUPPORTS4(nsEditingSession, nsIEditingSession, nsIWebProgressListener,
NS_IMETHODIMP NS_IMETHODIMP
nsEditingSession::Init(nsIDOMWindow *aWindow) nsEditingSession::Init(nsIDOMWindow *aWindow)
{ {
nsCOMPtr<nsIDocShell> docShell; nsIDocShell *docShell = GetDocShellFromWindow(aWindow);
nsresult rv = GetDocShellFromWindow(aWindow, getter_AddRefs(docShell)); if (!docShell) return NS_ERROR_FAILURE;
if (NS_FAILED(rv)) return rv;
mEditingShell = do_GetWeakReference(docShell); mEditingShell = do_GetWeakReference(docShell);
if (!mEditingShell) return NS_ERROR_NO_INTERFACE; if (!mEditingShell) return NS_ERROR_NO_INTERFACE;
@ -157,11 +156,10 @@ nsEditingSession::MakeWindowEditable(nsIDOMWindow *aWindow,
mWindowToBeEdited = do_GetWeakReference(aWindow); mWindowToBeEdited = do_GetWeakReference(aWindow);
// disable plugins // disable plugins
nsCOMPtr<nsIDocShell> docShell; nsIDocShell *docShell = GetDocShellFromWindow(aWindow);
nsresult rv = GetDocShellFromWindow(aWindow, getter_AddRefs(docShell)); if (!docShell) return NS_ERROR_FAILURE;
if (NS_FAILED(rv)) return rv;
rv = docShell->SetAllowPlugins(PR_FALSE); nsresult rv = docShell->SetAllowPlugins(PR_FALSE);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
// register as a content listener, so that we can fend off URL // register as a content listener, so that we can fend off URL
@ -173,12 +171,10 @@ nsEditingSession::MakeWindowEditable(nsIDOMWindow *aWindow,
nsCOMPtr<nsIScriptGlobalObject> sgo (do_QueryInterface(aWindow)); nsCOMPtr<nsIScriptGlobalObject> sgo (do_QueryInterface(aWindow));
if (sgo) if (sgo)
{ {
nsCOMPtr<nsIScriptContext> scriptContext; nsIScriptContext *scriptContext = sgo->GetContext();
sgo->GetContext(getter_AddRefs(scriptContext));
if (scriptContext) if (scriptContext)
{ {
rv = scriptContext->SetScriptsEnabled(PR_FALSE, PR_TRUE); scriptContext->SetScriptsEnabled(PR_FALSE, PR_TRUE);
if (NS_FAILED(rv)) return rv;
} }
} }
@ -392,9 +388,8 @@ nsEditingSession::SetupEditorOnWindow(nsIDOMWindow *aWindow)
// Create editor and do other things // Create editor and do other things
// only if we haven't found some error above, // only if we haven't found some error above,
nsCOMPtr<nsIDocShell> docShell; nsIDocShell *docShell = GetDocShellFromWindow(aWindow);
rv = GetDocShellFromWindow(aWindow, getter_AddRefs(docShell)); if (!docShell) return NS_ERROR_FAILURE;
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIPresShell> presShell; nsCOMPtr<nsIPresShell> presShell;
rv = docShell->GetPresShell(getter_AddRefs(presShell)); rv = docShell->GetPresShell(getter_AddRefs(presShell));
@ -763,9 +758,8 @@ nsEditingSession::OnLocationChange(nsIWebProgress *aWebProgress,
// Notify the location-changed observer that // Notify the location-changed observer that
// the document URL has changed // the document URL has changed
nsCOMPtr<nsIDocShell> docShell; nsIDocShell *docShell = GetDocShellFromWindow(domWindow);
rv = GetDocShellFromWindow(domWindow, getter_AddRefs(docShell)); if (!docShell) return NS_ERROR_FAILURE;
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsICommandManager> commandManager = do_GetInterface(docShell); nsCOMPtr<nsICommandManager> commandManager = do_GetInterface(docShell);
nsCOMPtr<nsPICommandUpdater> commandUpdater = nsCOMPtr<nsPICommandUpdater> commandUpdater =
@ -978,9 +972,8 @@ nsEditingSession::EndDocumentLoad(nsIWebProgress *aWebProgress,
mEditorStatus = eEditorErrorFileNotFound; mEditorStatus = eEditorErrorFileNotFound;
} }
nsCOMPtr<nsIDocShell> docShell; nsIDocShell *docShell = GetDocShellFromWindow(domWindow);
nsresult rv = GetDocShellFromWindow(domWindow, getter_AddRefs(docShell)); if (!docShell) return NS_ERROR_FAILURE; // better error handling?
if (NS_FAILED(rv)) return rv; // better error handling?
// cancel refresh from meta tags // cancel refresh from meta tags
// we need to make sure that all pages in editor (whether editable or not) // we need to make sure that all pages in editor (whether editable or not)
@ -991,6 +984,8 @@ nsEditingSession::EndDocumentLoad(nsIWebProgress *aWebProgress,
nsCOMPtr<nsIEditorDocShell> editorDocShell = do_QueryInterface(docShell); nsCOMPtr<nsIEditorDocShell> editorDocShell = do_QueryInterface(docShell);
nsresult rv = NS_OK;
// did someone set the flag to make this shell editable? // did someone set the flag to make this shell editable?
if (aIsToBeMadeEditable && mCanCreateEditor && editorDocShell) if (aIsToBeMadeEditable && mCanCreateEditor && editorDocShell)
{ {
@ -1089,9 +1084,8 @@ nsEditingSession::EndPageLoad(nsIWebProgress *aWebProgress,
nsCOMPtr<nsIDOMWindow> domWindow; nsCOMPtr<nsIDOMWindow> domWindow;
nsresult rv = aWebProgress->GetDOMWindow(getter_AddRefs(domWindow)); nsresult rv = aWebProgress->GetDOMWindow(getter_AddRefs(domWindow));
nsCOMPtr<nsIDocShell> docShell; nsIDocShell *docShell = GetDocShellFromWindow(domWindow);
rv = GetDocShellFromWindow(domWindow, getter_AddRefs(docShell)); if (!docShell) return NS_ERROR_FAILURE;
if (NS_FAILED(rv)) return rv;
// cancel refresh from meta tags // cancel refresh from meta tags
// we need to make sure that all pages in editor (whether editable or not) // we need to make sure that all pages in editor (whether editable or not)
@ -1117,20 +1111,16 @@ nsEditingSession::EndPageLoad(nsIWebProgress *aWebProgress,
GetDocShellFromWindow GetDocShellFromWindow
Utility method. This will always return an error if no docShell Utility method. This will always return nsnull if no docShell is found.
is returned.
----------------------------------------------------------------------------*/ ----------------------------------------------------------------------------*/
nsresult nsIDocShell *
nsEditingSession::GetDocShellFromWindow(nsIDOMWindow *aWindow, nsEditingSession::GetDocShellFromWindow(nsIDOMWindow *aWindow)
nsIDocShell** outDocShell)
{ {
nsCOMPtr<nsIScriptGlobalObject> scriptGO = do_QueryInterface(aWindow); nsCOMPtr<nsIScriptGlobalObject> scriptGO = do_QueryInterface(aWindow);
if (!scriptGO) return NS_ERROR_FAILURE; if (!scriptGO)
return nsnull;
nsresult rv = scriptGO->GetDocShell(outDocShell); return scriptGO->GetDocShell();
if (NS_FAILED(rv)) return rv;
if (!*outDocShell) return NS_ERROR_FAILURE;
return NS_OK;
} }
/*--------------------------------------------------------------------------- /*---------------------------------------------------------------------------
@ -1144,9 +1134,8 @@ nsresult
nsEditingSession::GetEditorDocShellFromWindow(nsIDOMWindow *aWindow, nsEditingSession::GetEditorDocShellFromWindow(nsIDOMWindow *aWindow,
nsIEditorDocShell** outDocShell) nsIEditorDocShell** outDocShell)
{ {
nsCOMPtr<nsIDocShell> docShell; nsIDocShell *docShell = GetDocShellFromWindow(aWindow);
nsresult rv = GetDocShellFromWindow(aWindow, getter_AddRefs(docShell)); if (!docShell) return NS_ERROR_FAILURE;
if (NS_FAILED(rv)) return rv;
return docShell->QueryInterface(NS_GET_IID(nsIEditorDocShell), return docShell->QueryInterface(NS_GET_IID(nsIEditorDocShell),
(void **)outDocShell); (void **)outDocShell);

Просмотреть файл

@ -98,8 +98,7 @@ public:
protected: protected:
nsresult GetDocShellFromWindow(nsIDOMWindow *aWindow, nsIDocShell * GetDocShellFromWindow(nsIDOMWindow *aWindow);
nsIDocShell** outDocShell);
nsresult GetEditorDocShellFromWindow(nsIDOMWindow *aWindow, nsresult GetEditorDocShellFromWindow(nsIDOMWindow *aWindow,
nsIEditorDocShell** outDocShell); nsIEditorDocShell** outDocShell);

Просмотреть файл

@ -438,16 +438,14 @@ GetPluginsContext(PluginInstanceData *pData)
nsCOMPtr<nsIDOMWindow> window; nsCOMPtr<nsIDOMWindow> window;
NPN_GetValue(pData->pPluginInstance, NPNVDOMWindow, NPN_GetValue(pData->pPluginInstance, NPNVDOMWindow,
NS_STATIC_CAST(nsIDOMWindow **, getter_AddRefs(window))); NS_STATIC_CAST(nsIDOMWindow **, getter_AddRefs(window)));
if (!window)
return nsnull;
nsCOMPtr<nsIScriptGlobalObject> globalObject(do_QueryInterface(window)); nsCOMPtr<nsIScriptGlobalObject> globalObject(do_QueryInterface(window));
if (!globalObject) if (!globalObject)
return nsnull; return nsnull;
nsCOMPtr<nsIScriptContext> scriptContext; nsIScriptContext *scriptContext = globalObject->GetContext();
if (NS_FAILED(globalObject->GetContext(getter_AddRefs(scriptContext))) ||
!scriptContext) if (!scriptContext)
return nsnull; return nsnull;
return NS_REINTERPRET_CAST(JSContext*, scriptContext->GetNativeContext()); return NS_REINTERPRET_CAST(JSContext*, scriptContext->GetNativeContext());

Просмотреть файл

@ -165,7 +165,6 @@ nsresult
PrefObserver::Subscribe() PrefObserver::Subscribe()
{ {
NS_ENSURE_TRUE(mPrefBranch, NS_ERROR_FAILURE); NS_ENSURE_TRUE(mPrefBranch, NS_ERROR_FAILURE);
nsresult rv;
mPrefBranch->AddObserver(kProxyPref, this, PR_TRUE); mPrefBranch->AddObserver(kProxyPref, this, PR_TRUE);
mPrefBranch->AddObserver(kUserAgentPref, this, PR_TRUE); mPrefBranch->AddObserver(kUserAgentPref, this, PR_TRUE);
@ -180,7 +179,6 @@ nsresult
PrefObserver::Unsubscribe() PrefObserver::Unsubscribe()
{ {
NS_ENSURE_TRUE(mPrefBranch, NS_ERROR_FAILURE); NS_ENSURE_TRUE(mPrefBranch, NS_ERROR_FAILURE);
nsresult rv;
mPrefBranch->RemoveObserver(kProxyPref, this); mPrefBranch->RemoveObserver(kProxyPref, this);
mPrefBranch->RemoveObserver(kUserAgentPref, this); mPrefBranch->RemoveObserver(kUserAgentPref, this);

Просмотреть файл

@ -819,9 +819,8 @@ END_COM_MAP()
if (!globalObject) if (!globalObject)
return E_UNEXPECTED; return E_UNEXPECTED;
nsCOMPtr<nsIScriptContext> scriptContext; nsIScriptContext *scriptContext = globalObject->GetContext();
if (NS_FAILED(globalObject->GetContext(getter_AddRefs(scriptContext))) || if (!scriptContext)
!scriptContext)
return E_UNEXPECTED; return E_UNEXPECTED;
nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDocument)); nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDocument));

Просмотреть файл

@ -52,12 +52,10 @@ nsresult nsCommandHandler::GetCommandHandler(nsICommandHandler **aCommandHandler
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
nsCOMPtr<nsIDocShell> docShell;
globalObj->GetDocShell(getter_AddRefs(docShell));
// Get the document tree owner // Get the document tree owner
nsCOMPtr<nsIDocShellTreeItem> docShellAsTreeItem(do_QueryInterface(docShell)); nsCOMPtr<nsIDocShellTreeItem> docShellAsTreeItem =
do_QueryInterface(globalObj->GetDocShell());
nsIDocShellTreeOwner *treeOwner = nsnull; nsIDocShellTreeOwner *treeOwner = nsnull;
docShellAsTreeItem->GetTreeOwner(&treeOwner); docShellAsTreeItem->GetTreeOwner(&treeOwner);

Просмотреть файл

@ -97,7 +97,7 @@ GetEventReceiver ( nsWebBrowser* inBrowser, nsIDOMEventReceiver** outEventRcvr )
NS_ENSURE_TRUE(chromeHandler, NS_ERROR_FAILURE); NS_ENSURE_TRUE(chromeHandler, NS_ERROR_FAILURE);
nsCOMPtr<nsIDOMEventReceiver> rcvr = do_QueryInterface(chromeHandler); nsCOMPtr<nsIDOMEventReceiver> rcvr = do_QueryInterface(chromeHandler);
*outEventRcvr = rcvr.get(); *outEventRcvr = rcvr;
NS_IF_ADDREF(*outEventRcvr); NS_IF_ADDREF(*outEventRcvr);
return NS_OK; return NS_OK;
@ -243,14 +243,14 @@ nsDocShellTreeOwner::FindItemWithName(const PRUnichar* aName,
nsCOMPtr<nsIDocShellTreeOwner> reqAsTreeOwner(do_QueryInterface(aRequestor)); nsCOMPtr<nsIDocShellTreeOwner> reqAsTreeOwner(do_QueryInterface(aRequestor));
if(mTreeOwner) { if(mTreeOwner) {
if (mTreeOwner != reqAsTreeOwner.get()) if (mTreeOwner != reqAsTreeOwner)
return mTreeOwner->FindItemWithName(aName, mWebBrowser->mDocShellAsItem.get(), return mTreeOwner->FindItemWithName(aName, mWebBrowser->mDocShellAsItem,
aFoundItem); aFoundItem);
return NS_OK; return NS_OK;
} }
// finally, failing everything else, search all windows, if we're not already // finally, failing everything else, search all windows, if we're not already
if (mWebBrowser->mDocShellAsItem.get() != aRequestor) if (mWebBrowser->mDocShellAsItem != aRequestor)
return FindItemWithNameAcrossWindows(aName, aFoundItem); return FindItemWithNameAcrossWindows(aName, aFoundItem);
return NS_OK; // failed return NS_OK; // failed
@ -284,11 +284,9 @@ nsDocShellTreeOwner::FindChildWithName(const PRUnichar *aName, PRBool aRecurse,
if (frame) { if (frame) {
nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(frame)); nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(frame));
if (sgo) { if (sgo) {
nsCOMPtr<nsIDocShell> docshell; nsCOMPtr<nsIDocShellTreeItem> item =
sgo->GetDocShell(getter_AddRefs(docshell)); do_QueryInterface(sgo->GetDocShell());
if (docshell) { if (item && item != aRequestor) {
nsCOMPtr<nsIDocShellTreeItem> item(do_QueryInterface(docshell));
if (item && item.get() != aRequestor) {
rv = item->FindItemWithName(aName, mWebBrowser->mDocShellAsItem, aFoundItem); rv = item->FindItemWithName(aName, mWebBrowser->mDocShellAsItem, aFoundItem);
if (NS_FAILED(rv) || *aFoundItem) if (NS_FAILED(rv) || *aFoundItem)
break; break;
@ -296,7 +294,6 @@ nsDocShellTreeOwner::FindChildWithName(const PRUnichar *aName, PRBool aRecurse,
} }
} }
} }
}
return rv; return rv;
} }
@ -326,10 +323,8 @@ nsDocShellTreeOwner::FindItemWithNameAcrossWindows(const PRUnichar* aName,
// it's a DOM Window. cut straight to the ScriptGlobalObject. // it's a DOM Window. cut straight to the ScriptGlobalObject.
nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(nextSupWindow)); nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(nextSupWindow));
if (sgo) { if (sgo) {
nsCOMPtr<nsIDocShell> docshell; nsCOMPtr<nsIDocShellTreeItem> item =
sgo->GetDocShell(getter_AddRefs(docshell)); do_QueryInterface(sgo->GetDocShell());
if (docshell) {
nsCOMPtr<nsIDocShellTreeItem> item(do_QueryInterface(docshell));
if (item) { if (item) {
rv = item->FindItemWithName(aName, item, aFoundItem); rv = item->FindItemWithName(aName, item, aFoundItem);
if (NS_FAILED(rv) || *aFoundItem) if (NS_FAILED(rv) || *aFoundItem)
@ -337,7 +332,6 @@ nsDocShellTreeOwner::FindItemWithNameAcrossWindows(const PRUnichar* aName,
} }
} }
} }
}
} while(1); } while(1);
return rv; return rv;
@ -422,7 +416,7 @@ nsDocShellTreeOwner::GetPrimaryContentShell(nsIDocShellTreeItem** aShell)
if(mTreeOwner) if(mTreeOwner)
return mTreeOwner->GetPrimaryContentShell(aShell); return mTreeOwner->GetPrimaryContentShell(aShell);
*aShell = (mPrimaryContentShell ? mPrimaryContentShell : mWebBrowser->mDocShellAsItem.get()); *aShell = (mPrimaryContentShell ? mPrimaryContentShell : mWebBrowser->mDocShellAsItem);
NS_IF_ADDREF(*aShell); NS_IF_ADDREF(*aShell);
return NS_OK; return NS_OK;
@ -437,7 +431,7 @@ nsDocShellTreeOwner::SizeShellTo(nsIDocShellTreeItem* aShellItem,
if(mTreeOwner) if(mTreeOwner)
return mTreeOwner->SizeShellTo(aShellItem, aCX, aCY); return mTreeOwner->SizeShellTo(aShellItem, aCX, aCY);
if(aShellItem == mWebBrowser->mDocShellAsItem.get()) if(aShellItem == mWebBrowser->mDocShellAsItem)
return mWebBrowserChrome->SizeBrowserTo(aCX, aCY); return mWebBrowserChrome->SizeBrowserTo(aCX, aCY);
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(aShellItem)); nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(aShellItem));

Просмотреть файл

@ -49,8 +49,7 @@ nsWebBrowserContentPolicy::ShouldLoad(PRInt32 contentType,
if (!scriptGlobal) if (!scriptGlobal)
return NS_OK; return NS_OK;
nsCOMPtr<nsIDocShell> shell; nsIDocShell *shell = scriptGlobal->GetDocShell();
scriptGlobal->GetDocShell(getter_AddRefs(shell));
/* We're going to dereference shell, so make sure it isn't null */ /* We're going to dereference shell, so make sure it isn't null */
if (!shell) if (!shell)
return NS_OK; return NS_OK;

Просмотреть файл

@ -144,9 +144,8 @@ NS_IMETHODIMP nsWebBrowserFind::FindNext(PRBool *outDidFind)
if (!mSearchSubFrames && !mSearchParentFrames) if (!mSearchSubFrames && !mSearchParentFrames)
return NS_OK; return NS_OK;
nsCOMPtr<nsIDocShell> rootDocShell; nsIDocShell *rootDocShell = GetDocShellFromWindow(rootFrame);
rv = GetDocShellFromWindow(rootFrame, getter_AddRefs(rootDocShell)); if (!rootDocShell) return NS_ERROR_FAILURE;
if (NS_FAILED(rv)) return rv;
PRInt32 enumDirection; PRInt32 enumDirection;
if (mFindBackwards) if (mFindBackwards)
@ -160,10 +159,8 @@ NS_IMETHODIMP nsWebBrowserFind::FindNext(PRBool *outDidFind)
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
// remember where we started // remember where we started
nsCOMPtr<nsIDocShell> startingShell; nsCOMPtr<nsIDocShellTreeItem> startingItem =
rv = GetDocShellFromWindow(searchFrame, getter_AddRefs(startingShell)); do_QueryInterface(GetDocShellFromWindow(searchFrame), &rv);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIDocShellTreeItem> startingItem = do_QueryInterface(startingShell, &rv);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIDocShellTreeItem> curItem; nsCOMPtr<nsIDocShellTreeItem> curItem;
@ -619,8 +616,7 @@ NS_IMETHODIMP nsWebBrowserFind::SetSearchParentFrames(PRBool aSearchParentFrames
void nsWebBrowserFind::MoveFocusToCaret(nsIDOMWindow *aWindow) void nsWebBrowserFind::MoveFocusToCaret(nsIDOMWindow *aWindow)
{ {
nsCOMPtr<nsIDocShell> docShell; nsIDocShell *docShell = GetDocShellFromWindow(aWindow);
GetDocShellFromWindow(aWindow, getter_AddRefs(docShell));
if (!docShell) if (!docShell)
return; return;
nsCOMPtr<nsIPresShell> presShell; nsCOMPtr<nsIPresShell> presShell;
@ -683,9 +679,7 @@ nsresult nsWebBrowserFind::SearchInFrame(nsIDOMWindow* aWindow,
nsCOMPtr<nsIDOMWindow> searchFrame = do_QueryReferent(mCurrentSearchFrame); nsCOMPtr<nsIDOMWindow> searchFrame = do_QueryReferent(mCurrentSearchFrame);
// Get the selection controller -- we'd better do this every time, // Get the selection controller -- we'd better do this every time,
// since the doc might have changed since the last time. // since the doc might have changed since the last time.
nsCOMPtr<nsIDocShell> docShell; nsIDocShell *docShell = GetDocShellFromWindow(aWindow);
rv = GetDocShellFromWindow(aWindow, getter_AddRefs(docShell));
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_ARG_POINTER(docShell); NS_ENSURE_ARG_POINTER(docShell);
nsCOMPtr<nsIPresShell> presShell; nsCOMPtr<nsIPresShell> presShell;
@ -797,18 +791,15 @@ nsresult nsWebBrowserFind::OnFind(nsIDOMWindow *aFoundWindow)
GetDocShellFromWindow GetDocShellFromWindow
Utility method. This will always return an error if no docShell Utility method. This will always return nsnull if no docShell
is returned. Oh why isn't there a better way to do this? is returned. Oh why isn't there a better way to do this?
----------------------------------------------------------------------------*/ ----------------------------------------------------------------------------*/
nsresult nsIDocShell *
nsWebBrowserFind::GetDocShellFromWindow(nsIDOMWindow *inWindow, nsIDocShell** outDocShell) nsWebBrowserFind::GetDocShellFromWindow(nsIDOMWindow *inWindow)
{ {
nsCOMPtr<nsIScriptGlobalObject> scriptGO(do_QueryInterface(inWindow)); nsCOMPtr<nsIScriptGlobalObject> scriptGO(do_QueryInterface(inWindow));
if (!scriptGO) return NS_ERROR_FAILURE; if (!scriptGO) return nsnull;
nsresult rv = scriptGO->GetDocShell(outDocShell); return scriptGO->GetDocShell();
if (NS_FAILED(rv)) return rv;
if (!*outDocShell) return NS_ERROR_FAILURE;
return NS_OK;
} }

Просмотреть файл

@ -82,7 +82,7 @@ protected:
nsresult OnFind(nsIDOMWindow *aFoundWindow); nsresult OnFind(nsIDOMWindow *aFoundWindow);
nsresult GetDocShellFromWindow(nsIDOMWindow *inWindow, nsIDocShell** outDocShell); nsIDocShell *GetDocShellFromWindow(nsIDOMWindow *inWindow);
void SetSelectionAndScroll(nsIDOMRange* aRange, void SetSelectionAndScroll(nsIDOMRange* aRange,
nsISelectionController* aSelCon); nsISelectionController* aSelCon);

Просмотреть файл

@ -141,12 +141,9 @@ nsPrintingPromptService::GetHWNDForDOMWindow(nsIDOMWindow *aWindow)
// Now we might be the Browser so check this path // Now we might be the Browser so check this path
nsCOMPtr<nsIScriptGlobalObject> scriptGlobal(do_QueryInterface(aWindow)); nsCOMPtr<nsIScriptGlobalObject> scriptGlobal(do_QueryInterface(aWindow));
nsCOMPtr<nsIDocShell> docShell;
scriptGlobal->GetDocShell(getter_AddRefs(docShell));
if (!docShell) return nsnull;
nsCOMPtr<nsIDocShellTreeItem> treeItem; nsCOMPtr<nsIDocShellTreeItem> treeItem =
treeItem = do_QueryInterface(docShell); do_QueryInterface(scriptGlobal->GetDocShell());
if (!treeItem) return nsnull; if (!treeItem) return nsnull;
nsCOMPtr<nsIDocShellTreeOwner> treeOwner; nsCOMPtr<nsIDocShellTreeOwner> treeOwner;

Просмотреть файл

@ -46,10 +46,8 @@
#include "nsWWJSUtils.h" #include "nsWWJSUtils.h"
#include "nsIXPConnect.h" #include "nsIXPConnect.h"
nsresult nsIScriptGlobalObject *
nsWWJSUtils::nsGetStaticScriptGlobal(JSContext* aContext, nsWWJSUtils::GetStaticScriptGlobal(JSContext* aContext, JSObject* aObj)
JSObject* aObj,
nsIScriptGlobalObject** aNativeGlobal)
{ {
nsISupports* supports; nsISupports* supports;
JSClass* clazz; JSClass* clazz;
@ -57,7 +55,7 @@ nsWWJSUtils::nsGetStaticScriptGlobal(JSContext* aContext,
JSObject* glob = aObj; // starting point for search JSObject* glob = aObj; // starting point for search
if (!glob) if (!glob)
return NS_ERROR_FAILURE; return nsnull;
while (nsnull != (parent = JS_GetParent(aContext, glob))) while (nsnull != (parent = JS_GetParent(aContext, glob)))
glob = parent; glob = parent;
@ -72,37 +70,35 @@ nsWWJSUtils::nsGetStaticScriptGlobal(JSContext* aContext,
!(clazz->flags & JSCLASS_HAS_PRIVATE) || !(clazz->flags & JSCLASS_HAS_PRIVATE) ||
!(clazz->flags & JSCLASS_PRIVATE_IS_NSISUPPORTS) || !(clazz->flags & JSCLASS_PRIVATE_IS_NSISUPPORTS) ||
!(supports = (nsISupports*) JS_GetPrivate(aContext, glob))) { !(supports = (nsISupports*) JS_GetPrivate(aContext, glob))) {
return NS_ERROR_FAILURE; return nsnull;
} }
nsCOMPtr<nsIXPConnectWrappedNative> wrapper(do_QueryInterface(supports)); nsCOMPtr<nsIXPConnectWrappedNative> wrapper(do_QueryInterface(supports));
NS_ENSURE_TRUE(wrapper, NS_ERROR_UNEXPECTED); NS_ENSURE_TRUE(wrapper, nsnull);
nsCOMPtr<nsISupports> native; nsCOMPtr<nsISupports> native;
wrapper->GetNative(getter_AddRefs(native)); wrapper->GetNative(getter_AddRefs(native));
return CallQueryInterface(native, aNativeGlobal); nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(native));
// This will return a pointer to something we're about to release,
// but that's ok here.
return sgo;
} }
nsresult nsIScriptContext *
nsWWJSUtils::nsGetDynamicScriptContext(JSContext *aContext, nsWWJSUtils::GetDynamicScriptContext(JSContext *aContext)
nsIScriptContext** aScriptContext)
{ {
return GetScriptContextFromJSContext(aContext, aScriptContext); return GetScriptContextFromJSContext(aContext);
} }
nsresult nsIScriptContext *
nsWWJSUtils::nsGetStaticScriptContext(JSContext* aContext, nsWWJSUtils::GetStaticScriptContext(JSContext* aContext,
JSObject* aObj, JSObject* aObj)
nsIScriptContext** aScriptContext)
{ {
nsCOMPtr<nsIScriptGlobalObject> nativeGlobal; nsIScriptGlobalObject *nativeGlobal = GetStaticScriptGlobal(aContext, aObj);
nsGetStaticScriptGlobal(aContext, aObj, getter_AddRefs(nativeGlobal));
if (!nativeGlobal) if (!nativeGlobal)
return NS_ERROR_FAILURE; return nsnull;
nsIScriptContext* scriptContext = nsnull; return nativeGlobal->GetContext();
nativeGlobal->GetContext(&scriptContext);
*aScriptContext = scriptContext;
return scriptContext ? NS_OK : NS_ERROR_FAILURE;
} }

Просмотреть файл

@ -51,19 +51,15 @@ class nsIScriptGlobalObject;
class nsWWJSUtils { class nsWWJSUtils {
public: public:
static nsresult nsGetStaticScriptGlobal(JSContext* aContext, static nsIScriptGlobalObject *GetStaticScriptGlobal(JSContext* aContext,
JSObject* aObj, JSObject* aObj);
nsIScriptGlobalObject** aNativeGlobal);
static nsresult nsGetStaticScriptContext(JSContext* aContext, static nsIScriptContext *GetStaticScriptContext(JSContext* aContext,
JSObject* aObj, JSObject* aObj);
nsIScriptContext** aScriptContext);
static nsresult nsGetDynamicScriptGlobal(JSContext *aContext, static nsIScriptGlobalObject *GetDynamicScriptGlobal(JSContext *aContext);
nsIScriptGlobalObject** aNativeGlobal);
static nsresult nsGetDynamicScriptContext(JSContext *aContext, static nsIScriptContext *GetDynamicScriptContext(JSContext *aContext);
nsIScriptContext** aScriptContext);
}; };
#endif /* nsWWJSUtils_h__ */ #endif /* nsWWJSUtils_h__ */

Просмотреть файл

@ -686,8 +686,7 @@ nsWindowWatcher::OpenWindowJS(nsIDOMWindow *aParent,
// want to continue in the face of errors. // want to continue in the face of errors.
nsCOMPtr<nsIScriptGlobalObject> parentSGO(do_QueryInterface(aParent)); nsCOMPtr<nsIScriptGlobalObject> parentSGO(do_QueryInterface(aParent));
if (parentSGO) { if (parentSGO) {
nsCOMPtr<nsIDocShell> parentDocshell; nsIDocShell *parentDocshell = parentSGO->GetDocShell();
parentSGO->GetDocShell(getter_AddRefs(parentDocshell));
// parentDocshell may be null if the parent got closed in the meantime // parentDocshell may be null if the parent got closed in the meantime
if (parentDocshell) { if (parentDocshell) {
nsCOMPtr<nsIContentViewer> parentContentViewer; nsCOMPtr<nsIContentViewer> parentContentViewer;
@ -708,13 +707,9 @@ nsWindowWatcher::OpenWindowJS(nsIDOMWindow *aParent,
} }
if (uriToLoad) { // get the script principal and pass it to docshell if (uriToLoad) { // get the script principal and pass it to docshell
JSContext *cx = GetJSContextFromCallStack();
// get the security manager // get the security manager
nsCOMPtr<nsIScriptSecurityManager> secMan;
JSContext *cx;
nsCOMPtr<nsIScriptContext> scriptCX;
cx = GetJSContextFromCallStack();
if (!cx) if (!cx)
cx = GetJSContextFromWindow(aParent); cx = GetJSContextFromWindow(aParent);
if (!cx) { if (!cx) {
@ -723,18 +718,15 @@ nsWindowWatcher::OpenWindowJS(nsIDOMWindow *aParent,
return rv; return rv;
cx = contextGuard.get(); cx = contextGuard.get();
} }
JSObject *scriptObject = GetWindowScriptObject(aParent ? aParent : *_retval);
nsWWJSUtils::nsGetStaticScriptContext(cx, scriptObject,
getter_AddRefs(scriptCX));
if (scriptCX &&
NS_FAILED(scriptCX->GetSecurityManager(getter_AddRefs(secMan))))
return NS_ERROR_FAILURE;
nsCOMPtr<nsIDocShellLoadInfo> loadInfo; nsCOMPtr<nsIDocShellLoadInfo> loadInfo;
newDocShell->CreateLoadInfo(getter_AddRefs(loadInfo)); newDocShell->CreateLoadInfo(getter_AddRefs(loadInfo));
NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE); NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE);
if (!uriToLoadIsChrome && secMan) { if (!uriToLoadIsChrome) {
nsCOMPtr<nsIScriptSecurityManager> secMan =
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID);
nsCOMPtr<nsIPrincipal> principal; nsCOMPtr<nsIPrincipal> principal;
if (NS_FAILED(secMan->GetSubjectPrincipal(getter_AddRefs(principal)))) if (NS_FAILED(secMan->GetSubjectPrincipal(getter_AddRefs(principal))))
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -754,10 +746,8 @@ nsWindowWatcher::OpenWindowJS(nsIDOMWindow *aParent,
// get its document, if any // get its document, if any
if (stack && NS_SUCCEEDED(stack->Peek(&ccx)) && ccx) { if (stack && NS_SUCCEEDED(stack->Peek(&ccx)) && ccx) {
nsIScriptGlobalObject *sgo =
nsCOMPtr<nsIScriptGlobalObject> sgo; nsWWJSUtils::GetStaticScriptGlobal(ccx, ::JS_GetGlobalObject(ccx));
nsWWJSUtils::nsGetStaticScriptGlobal(ccx, ::JS_GetGlobalObject(ccx),
getter_AddRefs(sgo));
nsCOMPtr<nsPIDOMWindow> w(do_QueryInterface(sgo)); nsCOMPtr<nsPIDOMWindow> w(do_QueryInterface(sgo));
if (w) { if (w) {
@ -1112,12 +1102,9 @@ nsWindowWatcher::URIfromURL(const char *aURL,
in nsGlobalWindow.cpp.) */ in nsGlobalWindow.cpp.) */
JSContext *cx = GetJSContextFromCallStack(); JSContext *cx = GetJSContextFromCallStack();
if (cx) { if (cx) {
nsCOMPtr<nsIScriptContext> scriptcx; nsIScriptContext *scriptcx = nsWWJSUtils::GetDynamicScriptContext(cx);
nsWWJSUtils::nsGetDynamicScriptContext(cx, getter_AddRefs(scriptcx));
if (scriptcx) { if (scriptcx) {
nsCOMPtr<nsIScriptGlobalObject> gobj; baseWindow = do_QueryInterface(scriptcx->GetGlobalObject());
scriptcx->GetGlobalObject(getter_AddRefs(gobj));
baseWindow = do_QueryInterface(gobj);
} }
} }
@ -1642,8 +1629,7 @@ nsWindowWatcher::AttachArguments(nsIDOMWindow *aWindow,
nsCOMPtr<nsIScriptGlobalObject> scriptGlobal(do_QueryInterface(aWindow)); nsCOMPtr<nsIScriptGlobalObject> scriptGlobal(do_QueryInterface(aWindow));
NS_ENSURE_TRUE(scriptGlobal, NS_ERROR_UNEXPECTED); NS_ENSURE_TRUE(scriptGlobal, NS_ERROR_UNEXPECTED);
nsCOMPtr<nsIScriptContext> scriptContext; nsIScriptContext *scriptContext = scriptGlobal->GetContext();
scriptGlobal->GetContext(getter_AddRefs(scriptContext));
if (scriptContext) { if (scriptContext) {
JSContext *cx; JSContext *cx;
cx = (JSContext *)scriptContext->GetNativeContext(); cx = (JSContext *)scriptContext->GetNativeContext();
@ -1981,8 +1967,7 @@ nsWindowWatcher::GetWindowTreeItem(nsIDOMWindow *inWindow,
nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(inWindow)); nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(inWindow));
if (sgo) { if (sgo) {
nsCOMPtr<nsIDocShell> docshell; nsIDocShell *docshell = sgo->GetDocShell();
sgo->GetDocShell(getter_AddRefs(docshell));
if (docshell) if (docshell)
CallQueryInterface(docshell, outTreeItem); CallQueryInterface(docshell, outTreeItem);
} }
@ -2020,8 +2005,7 @@ nsWindowWatcher::GetJSContextFromWindow(nsIDOMWindow *aWindow)
if (aWindow) { if (aWindow) {
nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(aWindow)); nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(aWindow));
if (sgo) { if (sgo) {
nsCOMPtr<nsIScriptContext> scx; nsIScriptContext *scx = sgo->GetContext();
sgo->GetContext(getter_AddRefs(scx));
if (scx) if (scx)
cx = (JSContext *) scx->GetNativeContext(); cx = (JSContext *) scx->GetNativeContext();
} }

Просмотреть файл

@ -71,10 +71,9 @@ GetRootDocShell(nsIDOMWindow *aWindow)
nsCOMPtr<nsIScriptGlobalObject> globalObj(do_QueryInterface(aWindow)); nsCOMPtr<nsIScriptGlobalObject> globalObj(do_QueryInterface(aWindow));
if (globalObj) { if (globalObj) {
nsCOMPtr<nsIDocShell> docShell; nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem =
globalObj->GetDocShell(getter_AddRefs(docShell)); do_QueryInterface(globalObj->GetDocShell());
nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem(do_QueryInterface(docShell));
if (docShellTreeItem) { if (docShellTreeItem) {
nsCOMPtr<nsIDocShellTreeItem> rootItem; nsCOMPtr<nsIDocShellTreeItem> rootItem;
docShellTreeItem->GetRootTreeItem(getter_AddRefs(rootItem)); docShellTreeItem->GetRootTreeItem(getter_AddRefs(rootItem));

Просмотреть файл

@ -83,11 +83,9 @@ nsIPresShell*
inLayoutUtils::GetPresShellFor(nsISupports* aThing) inLayoutUtils::GetPresShellFor(nsISupports* aThing)
{ {
nsCOMPtr<nsIScriptGlobalObject> so = do_QueryInterface(aThing); nsCOMPtr<nsIScriptGlobalObject> so = do_QueryInterface(aThing);
nsCOMPtr<nsIDocShell> docShell;
so->GetDocShell(getter_AddRefs(docShell));
nsCOMPtr<nsIPresShell> presShell; nsCOMPtr<nsIPresShell> presShell;
docShell->GetPresShell(getter_AddRefs(presShell)); so->GetDocShell()->GetPresShell(getter_AddRefs(presShell));
return presShell; return presShell;
} }

Просмотреть файл

@ -153,7 +153,7 @@ nsLayoutDebuggingTools::Init(nsIDOMWindow *aWin)
nsCOMPtr<nsIScriptGlobalObject> global = do_QueryInterface(aWin); nsCOMPtr<nsIScriptGlobalObject> global = do_QueryInterface(aWin);
if (!global) if (!global)
return NS_ERROR_UNEXPECTED; return NS_ERROR_UNEXPECTED;
global->GetDocShell(getter_AddRefs(mDocShell)); mDocShell = global->GetDocShell();
} }
mPrefs = do_GetService(NS_PREF_CONTRACTID); mPrefs = do_GetService(NS_PREF_CONTRACTID);

Просмотреть файл

@ -179,5 +179,8 @@ nsRegressionTester::GetDocShellFromWindow(nsIDOMWindow* inWindow, nsIDocShell**
nsCOMPtr<nsIScriptGlobalObject> scriptObj(do_QueryInterface(inWindow)); nsCOMPtr<nsIScriptGlobalObject> scriptObj(do_QueryInterface(inWindow));
if (!scriptObj) return NS_ERROR_FAILURE; if (!scriptObj) return NS_ERROR_FAILURE;
return scriptObj->GetDocShell(outShell); *outShell = scriptObj->GetDocShell();
NS_IF_ADDREF(*outShell);
return NS_OK;
} }

Просмотреть файл

@ -210,9 +210,8 @@ void txMozillaXMLOutput::endDocument()
nsCOMPtr<nsIDocument> doc = do_QueryInterface(mDocument); nsCOMPtr<nsIDocument> doc = do_QueryInterface(mDocument);
nsIScriptGlobalObject *sgo = doc->GetScriptGlobalObject(); nsIScriptGlobalObject *sgo = doc->GetScriptGlobalObject();
if (sgo) { if (sgo) {
nsCOMPtr<nsIDocShell> docShell; nsCOMPtr<nsIRefreshURI> refURI =
sgo->GetDocShell(getter_AddRefs(docShell)); do_QueryInterface(sgo->GetDocShell());
nsCOMPtr<nsIRefreshURI> refURI = do_QueryInterface(docShell);
if (refURI) { if (refURI) {
refURI->SetupRefreshURIFromHeader(doc->GetBaseURI(), refURI->SetupRefreshURIFromHeader(doc->GetBaseURI(),
mRefreshString); mRefreshString);

Просмотреть файл

@ -124,8 +124,7 @@ nsWalletlibService::WALLET_RequestToCapture(nsIDOMWindowInternal* aWin,
nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObject; nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObject;
scriptGlobalObject = do_QueryInterface(aWin); scriptGlobalObject = do_QueryInterface(aWin);
nsCOMPtr<nsIDocShell> docShell; nsIDocShell *docShell = scriptGlobalObject->GetDocShell();
scriptGlobalObject->GetDocShell(getter_AddRefs(docShell));
nsCOMPtr<nsIPresShell> presShell; nsCOMPtr<nsIPresShell> presShell;
if(docShell) if(docShell)
@ -152,8 +151,7 @@ nsWalletlibService::WALLET_Prefill(PRBool quick,
{ {
nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObject; nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObject;
scriptGlobalObject = do_QueryInterface(aWin); scriptGlobalObject = do_QueryInterface(aWin);
nsCOMPtr<nsIDocShell> docShell; nsIDocShell *docShell = scriptGlobalObject->GetDocShell();
scriptGlobalObject->GetDocShell(getter_AddRefs(docShell));
nsCOMPtr<nsIPresShell> presShell; nsCOMPtr<nsIPresShell> presShell;
if(docShell) if(docShell)

Просмотреть файл

@ -93,9 +93,9 @@ static void DOMWindowToTreeOwner(
return; // with webWindow unchanged -- its constructor gives it a null ptr return; // with webWindow unchanged -- its constructor gives it a null ptr
} }
nsCOMPtr<nsIScriptGlobalObject> globalScript(do_QueryInterface(DOMWindow)); nsCOMPtr<nsIScriptGlobalObject> globalScript(do_QueryInterface(DOMWindow));
nsCOMPtr<nsIDocShell> docShell; nsIDocShell *docShell = nsnull;
if (globalScript) { if (globalScript) {
globalScript->GetDocShell(getter_AddRefs(docShell)); docShell = globalScript->GetDocShell();
} }
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(docShell)); nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(docShell));
if(!docShellAsItem) if(!docShellAsItem)

Просмотреть файл

@ -469,13 +469,11 @@ nsDOMParser::ParseFromStream(nsIInputStream *stream,
rv = cc->GetJSContext(&cx); rv = cc->GetJSContext(&cx);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE; if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
nsCOMPtr<nsIScriptContext> scriptContext; nsIScriptContext *scriptContext = GetScriptContextFromJSContext(cx);
GetScriptContextFromJSContext(cx, getter_AddRefs(scriptContext));
if (scriptContext) { if (scriptContext) {
nsCOMPtr<nsIScriptGlobalObject> globalObject; nsCOMPtr<nsIDOMWindow> window =
scriptContext->GetGlobalObject(getter_AddRefs(globalObject)); do_QueryInterface(scriptContext->GetGlobalObject());
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(globalObject);
if (window) { if (window) {
nsCOMPtr<nsIDOMDocument> domdoc; nsCOMPtr<nsIDOMDocument> domdoc;
window->GetDocument(getter_AddRefs(domdoc)); window->GetDocument(getter_AddRefs(domdoc));

Просмотреть файл

@ -112,30 +112,24 @@ static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
XML_HTTP_REQUEST_SENT | \ XML_HTTP_REQUEST_SENT | \
XML_HTTP_REQUEST_STOPPED) XML_HTTP_REQUEST_STOPPED)
static void static nsIScriptContext *
GetCurrentContext(nsIScriptContext **aScriptContext) GetCurrentContext()
{ {
*aScriptContext = nsnull;
// Get JSContext from stack. // Get JSContext from stack.
nsCOMPtr<nsIJSContextStack> stack = nsCOMPtr<nsIJSContextStack> stack =
do_GetService("@mozilla.org/js/xpc/ContextStack;1"); do_GetService("@mozilla.org/js/xpc/ContextStack;1");
if (!stack) { if (!stack) {
return; return nsnull;
} }
JSContext *cx; JSContext *cx;
if (NS_FAILED(stack->Peek(&cx))) { if (NS_FAILED(stack->Peek(&cx)) || !cx) {
return; return nsnull;
} }
if (cx) { return GetScriptContextFromJSContext(cx);
GetScriptContextFromJSContext(cx, aScriptContext);
}
return;
} }
/** /**
@ -151,9 +145,8 @@ GetDocumentFromScriptContext(nsIScriptContext *aScriptContext)
if (!aScriptContext) if (!aScriptContext)
return nsnull; return nsnull;
nsCOMPtr<nsIScriptGlobalObject> global; nsCOMPtr<nsIDOMWindow> window =
aScriptContext->GetGlobalObject(getter_AddRefs(global)); do_QueryInterface(aScriptContext->GetGlobalObject());
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(global);
nsIDocument *doc = nsnull; nsIDocument *doc = nsnull;
if (window) { if (window) {
nsCOMPtr<nsIDOMDocument> domdoc; nsCOMPtr<nsIDOMDocument> domdoc;
@ -233,7 +226,7 @@ nsXMLHttpRequest::AddEventListener(const nsAString& type,
else { else {
return NS_ERROR_INVALID_ARG; return NS_ERROR_INVALID_ARG;
} }
GetCurrentContext(getter_AddRefs(mScriptContext)); mScriptContext = GetCurrentContext();
return NS_OK; return NS_OK;
} }
@ -290,7 +283,7 @@ nsXMLHttpRequest::SetOnreadystatechange(nsIOnReadystatechangeHandler * aOnreadys
{ {
mOnReadystatechangeListener = aOnreadystatechange; mOnReadystatechangeListener = aOnreadystatechange;
GetCurrentContext(getter_AddRefs(mScriptContext)); mScriptContext = GetCurrentContext();
return NS_OK; return NS_OK;
} }
@ -313,7 +306,7 @@ nsXMLHttpRequest::SetOnload(nsIDOMEventListener * aOnLoad)
{ {
mOnLoadListener = aOnLoad; mOnLoadListener = aOnLoad;
GetCurrentContext(getter_AddRefs(mScriptContext)); mScriptContext = GetCurrentContext();
return NS_OK; return NS_OK;
} }
@ -335,7 +328,7 @@ nsXMLHttpRequest::SetOnerror(nsIDOMEventListener * aOnerror)
{ {
mOnErrorListener = aOnerror; mOnErrorListener = aOnerror;
GetCurrentContext(getter_AddRefs(mScriptContext)); mScriptContext = GetCurrentContext();
return NS_OK; return NS_OK;
} }
@ -602,7 +595,7 @@ nsXMLHttpRequest::GetLoadGroup(nsILoadGroup **aLoadGroup)
*aLoadGroup = nsnull; *aLoadGroup = nsnull;
if (!mScriptContext) { if (!mScriptContext) {
GetCurrentContext(getter_AddRefs(mScriptContext)); mScriptContext = GetCurrentContext();
} }
nsCOMPtr<nsIDocument> doc = GetDocumentFromScriptContext(mScriptContext); nsCOMPtr<nsIDocument> doc = GetDocumentFromScriptContext(mScriptContext);
@ -620,7 +613,7 @@ nsXMLHttpRequest::GetBaseURI(nsIURI **aBaseURI)
*aBaseURI = nsnull; *aBaseURI = nsnull;
if (!mScriptContext) { if (!mScriptContext) {
GetCurrentContext(getter_AddRefs(mScriptContext)); mScriptContext = GetCurrentContext();
if (!mScriptContext) { if (!mScriptContext) {
return NS_OK; return NS_OK;
} }
@ -1321,7 +1314,7 @@ nsXMLHttpRequest::Send(nsIVariant *aBody)
if (!mScriptContext) { if (!mScriptContext) {
// We need a context to check if redirect (if any) is allowed // We need a context to check if redirect (if any) is allowed
GetCurrentContext(getter_AddRefs(mScriptContext)); mScriptContext = GetCurrentContext();
} }
// Hook us up to listen to redirects and the like // Hook us up to listen to redirects and the like

Просмотреть файл

@ -1606,7 +1606,9 @@ jsdContext::GetScriptsEnabled (PRBool *_rval)
if (!context) if (!context)
return NS_ERROR_NO_INTERFACE; return NS_ERROR_NO_INTERFACE;
return context->GetScriptsEnabled(_rval); *_rval = context->GetScriptsEnabled();
return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -1617,7 +1619,9 @@ jsdContext::SetScriptsEnabled (PRBool _rval)
if (!context) if (!context)
return NS_ERROR_NO_INTERFACE; return NS_ERROR_NO_INTERFACE;
return context->SetScriptsEnabled(_rval, PR_TRUE); context->SetScriptsEnabled(_rval, PR_TRUE);
return NS_OK;
} }
/* Stack Frames */ /* Stack Frames */

Просмотреть файл

@ -891,10 +891,10 @@ nsImageMap::UpdateAreas()
nsresult nsresult
nsImageMap::AddArea(nsIContent* aArea) nsImageMap::AddArea(nsIContent* aArea)
{ {
nsAutoString shape, coords, baseURL, noHref; nsAutoString shape, coords;
aArea->GetAttr(kNameSpaceID_None, nsHTMLAtoms::shape, shape); aArea->GetAttr(kNameSpaceID_None, nsHTMLAtoms::shape, shape);
aArea->GetAttr(kNameSpaceID_None, nsHTMLAtoms::coords, coords); aArea->GetAttr(kNameSpaceID_None, nsHTMLAtoms::coords, coords);
PRBool hasURL = (PRBool)(NS_CONTENT_ATTR_HAS_VALUE != aArea->GetAttr(kNameSpaceID_None, nsHTMLAtoms::nohref, noHref)); PRBool hasURL = !aArea->HasAttr(kNameSpaceID_None, nsHTMLAtoms::nohref);
//Add focus listener to track area focus changes //Add focus listener to track area focus changes
nsCOMPtr<nsIDOMEventReceiver> rec(do_QueryInterface(aArea)); nsCOMPtr<nsIDOMEventReceiver> rec(do_QueryInterface(aArea));

Просмотреть файл

@ -1920,8 +1920,7 @@ nsObjectFrame::NotifyContentObjectWrapper()
if (!sgo) if (!sgo)
return; return;
nsCOMPtr<nsIScriptContext> scx; nsIScriptContext *scx = sgo->GetContext();
sgo->GetContext(getter_AddRefs(scx));
if (!scx) if (!scx)
return; return;

Просмотреть файл

@ -891,10 +891,10 @@ nsImageMap::UpdateAreas()
nsresult nsresult
nsImageMap::AddArea(nsIContent* aArea) nsImageMap::AddArea(nsIContent* aArea)
{ {
nsAutoString shape, coords, baseURL, noHref; nsAutoString shape, coords;
aArea->GetAttr(kNameSpaceID_None, nsHTMLAtoms::shape, shape); aArea->GetAttr(kNameSpaceID_None, nsHTMLAtoms::shape, shape);
aArea->GetAttr(kNameSpaceID_None, nsHTMLAtoms::coords, coords); aArea->GetAttr(kNameSpaceID_None, nsHTMLAtoms::coords, coords);
PRBool hasURL = (PRBool)(NS_CONTENT_ATTR_HAS_VALUE != aArea->GetAttr(kNameSpaceID_None, nsHTMLAtoms::nohref, noHref)); PRBool hasURL = !aArea->HasAttr(kNameSpaceID_None, nsHTMLAtoms::nohref);
//Add focus listener to track area focus changes //Add focus listener to track area focus changes
nsCOMPtr<nsIDOMEventReceiver> rec(do_QueryInterface(aArea)); nsCOMPtr<nsIDOMEventReceiver> rec(do_QueryInterface(aArea));

Просмотреть файл

@ -1920,8 +1920,7 @@ nsObjectFrame::NotifyContentObjectWrapper()
if (!sgo) if (!sgo)
return; return;
nsCOMPtr<nsIScriptContext> scx; nsIScriptContext *scx = sgo->GetContext();
sgo->GetContext(getter_AddRefs(scx));
if (!scx) if (!scx)
return; return;

Просмотреть файл

@ -1708,9 +1708,7 @@ nsPrintEngine::IsThereARangeSelection(nsIDOMWindow* aDOMWin)
nsCOMPtr<nsIPresShell> presShell; nsCOMPtr<nsIPresShell> presShell;
if (aDOMWin) { if (aDOMWin) {
nsCOMPtr<nsIScriptGlobalObject> scriptObj(do_QueryInterface(aDOMWin)); nsCOMPtr<nsIScriptGlobalObject> scriptObj(do_QueryInterface(aDOMWin));
nsCOMPtr<nsIDocShell> docShell; scriptObj->GetDocShell()->GetPresShell(getter_AddRefs(presShell));
scriptObj->GetDocShell(getter_AddRefs(docShell));
docShell->GetPresShell(getter_AddRefs(presShell));
} }
// check here to see if there is a range selection // check here to see if there is a range selection
@ -4002,10 +4000,9 @@ nsPrintEngine::IsWindowsInOurSubTree(nsIDOMWindow * aDOMWindow)
// now check to make sure it is in "our" tree of webshells // now check to make sure it is in "our" tree of webshells
nsCOMPtr<nsIScriptGlobalObject> scriptObj(do_QueryInterface(aDOMWindow)); nsCOMPtr<nsIScriptGlobalObject> scriptObj(do_QueryInterface(aDOMWindow));
if (scriptObj) { if (scriptObj) {
nsCOMPtr<nsIDocShell> docShell; nsCOMPtr<nsIDocShellTreeItem> docShellAsItem =
scriptObj->GetDocShell(getter_AddRefs(docShell)); do_QueryInterface(scriptObj->GetDocShell());
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(docShell));
if (docShellAsItem) { if (docShellAsItem) {
// get this DocViewer webshell // get this DocViewer webshell
nsCOMPtr<nsIWebShell> thisDVWebShell(do_QueryInterface(mContainer)); nsCOMPtr<nsIWebShell> thisDVWebShell(do_QueryInterface(mContainer));
@ -4440,9 +4437,8 @@ nsPrintEngine::TurnScriptingOn(PRBool aDoTurnOn)
// get the script global object // get the script global object
nsIScriptGlobalObject *scriptGlobalObj = mDocument->GetScriptGlobalObject(); nsIScriptGlobalObject *scriptGlobalObj = mDocument->GetScriptGlobalObject();
NS_ASSERTION(scriptGlobalObj, "Can't get nsIScriptGlobalObject"); NS_ASSERTION(scriptGlobalObj, "Can't get nsIScriptGlobalObject");
nsCOMPtr<nsIScriptContext> scx; nsIScriptContext *scx = scriptGlobalObj->GetContext();
nsresult rv = scriptGlobalObj->GetContext(getter_AddRefs(scx)); NS_ASSERTION(scx, "Can't get nsIScriptContext");
NS_ASSERTION(NS_SUCCEEDED(rv) && scx, "Can't get nsIScriptContext");
scx->SetScriptsEnabled(aDoTurnOn, PR_TRUE); scx->SetScriptsEnabled(aDoTurnOn, PR_TRUE);
} }

Просмотреть файл

@ -157,10 +157,8 @@ nsResizerFrame::HandleEvent(nsIPresContext* aPresContext,
nsIScriptGlobalObject *scriptGlobalObject = document->GetScriptGlobalObject(); nsIScriptGlobalObject *scriptGlobalObject = document->GetScriptGlobalObject();
NS_ENSURE_TRUE(scriptGlobalObject, NS_ERROR_FAILURE); NS_ENSURE_TRUE(scriptGlobalObject, NS_ERROR_FAILURE);
nsCOMPtr<nsIDocShell> docShell; nsCOMPtr<nsIDocShellTreeItem> docShellAsItem =
scriptGlobalObject->GetDocShell(getter_AddRefs(docShell)); do_QueryInterface(scriptGlobalObject->GetDocShell());
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(docShell));
NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE); NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);
nsCOMPtr<nsIDocShellTreeOwner> treeOwner; nsCOMPtr<nsIDocShellTreeOwner> treeOwner;

Просмотреть файл

@ -566,8 +566,9 @@ nsXULTooltipListener::GetTooltipFor(nsIContent* aTarget, nsIContent** aTooltip)
} }
nsIScriptGlobalObject *global = document->GetScriptGlobalObject(); nsIScriptGlobalObject *global = document->GetScriptGlobalObject();
if (global) { if (global) {
nsCOMPtr<nsIScriptContext> context; nsIScriptContext *context = global->GetContext();
if (NS_SUCCEEDED(global->GetContext(getter_AddRefs(context))) && context) {
if (context) {
nsCOMPtr<nsIDOMWindowInternal> domWindow = do_QueryInterface(global); nsCOMPtr<nsIDOMWindowInternal> domWindow = do_QueryInterface(global);
if (!domWindow) if (!domWindow)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;

Просмотреть файл

@ -245,7 +245,6 @@ nsresult nsAddressBook::DoCommand(nsIRDFDataSource* db,
nsISupportsArray *srcArray, nsISupportsArray *srcArray,
nsISupportsArray *argumentArray) nsISupportsArray *argumentArray)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
nsCOMPtr<nsIRDFService> rdfService = do_GetService (NS_RDF_CONTRACTID "/rdf-service;1", &rv); nsCOMPtr<nsIRDFService> rdfService = do_GetService (NS_RDF_CONTRACTID "/rdf-service;1", &rv);
@ -259,7 +258,6 @@ nsresult nsAddressBook::DoCommand(nsIRDFDataSource* db,
} }
return rv; return rv;
} }
NS_IMETHODIMP nsAddressBook::SetDocShellWindow(nsIDOMWindowInternal *aWin) NS_IMETHODIMP nsAddressBook::SetDocShellWindow(nsIDOMWindowInternal *aWin)
@ -273,13 +271,11 @@ NS_IMETHODIMP nsAddressBook::SetDocShellWindow(nsIDOMWindowInternal *aWin)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
globalObj->GetDocShell(&mDocShell); // mDocShell is a weak reference
mDocShell = globalObj->GetDocShell();
if (!mDocShell) if (!mDocShell)
return NS_ERROR_NOT_INITIALIZED; return NS_ERROR_NOT_INITIALIZED;
// Make reference weak by releasing
mDocShell->Release();
return NS_OK; return NS_OK;
} }

Просмотреть файл

@ -371,8 +371,7 @@ nsMessenger::SetWindow(nsIDOMWindowInternal *aWin, nsIMsgWindow *aMsgWindow)
nsCOMPtr<nsIScriptGlobalObject> globalObj( do_QueryInterface(aWin) ); nsCOMPtr<nsIScriptGlobalObject> globalObj( do_QueryInterface(aWin) );
NS_ENSURE_TRUE(globalObj, NS_ERROR_FAILURE); NS_ENSURE_TRUE(globalObj, NS_ERROR_FAILURE);
nsCOMPtr<nsIDocShell> docShell; nsIDocShell *docShell = globalObj->GetDocShell();
globalObj->GetDocShell(getter_AddRefs(docShell));
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(docShell)); nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(docShell));
NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE); NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);

Просмотреть файл

@ -94,11 +94,9 @@ HWND hwndForDOMWindow( nsISupports *window )
nsCOMPtr<nsIScriptGlobalObject> ppScriptGlobalObj( do_QueryInterface(window) ); nsCOMPtr<nsIScriptGlobalObject> ppScriptGlobalObj( do_QueryInterface(window) );
if ( !ppScriptGlobalObj ) if ( !ppScriptGlobalObj )
return 0; return 0;
nsCOMPtr<nsIDocShell> ppDocShell;
ppScriptGlobalObj->GetDocShell( getter_AddRefs( ppDocShell ) );
if ( !ppDocShell ) return 0;
nsCOMPtr<nsIBaseWindow> ppBaseWindow( do_QueryInterface( ppDocShell ) ); nsCOMPtr<nsIBaseWindow> ppBaseWindow =
do_QueryInterface( ppScriptGlobalObj->GetDocShell() );
if (!ppBaseWindow) return 0; if (!ppBaseWindow) return 0;
nsCOMPtr<nsIWidget> ppWidget; nsCOMPtr<nsIWidget> ppWidget;

Просмотреть файл

@ -341,9 +341,8 @@ nsresult nsMsgMailSession::GetTopmostMsgWindow(nsIMsgWindow* *aMsgWindow)
nsCOMPtr<nsIScriptGlobalObject> globalObj = do_QueryInterface(topMostWindow, &rv); nsCOMPtr<nsIScriptGlobalObject> globalObj = do_QueryInterface(topMostWindow, &rv);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDocShell> topDocShell; // use this for the match // use this for the match
rv = globalObj->GetDocShell(getter_AddRefs(topDocShell)); nsIDocShell *topDocShell = globalObj->GetDocShell();
NS_ENSURE_SUCCESS(rv, rv);
// loop for the msgWindow array to find the match // loop for the msgWindow array to find the match
nsCOMPtr<nsIDocShell> docShell; nsCOMPtr<nsIDocShell> docShell;

Просмотреть файл

@ -249,10 +249,8 @@ nsMsgPrintEngine::SetWindow(nsIDOMWindowInternal *aWin)
nsCOMPtr<nsIScriptGlobalObject> globalObj( do_QueryInterface(aWin) ); nsCOMPtr<nsIScriptGlobalObject> globalObj( do_QueryInterface(aWin) );
NS_ENSURE_TRUE(globalObj, NS_ERROR_FAILURE); NS_ENSURE_TRUE(globalObj, NS_ERROR_FAILURE);
nsCOMPtr<nsIDocShell> docShell; nsCOMPtr<nsIDocShellTreeItem> docShellAsItem =
globalObj->GetDocShell(getter_AddRefs(docShell)); do_QueryInterface(globalObj->GetDocShell());
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(docShell));
NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE); NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);
nsCOMPtr<nsIDocShellTreeItem> rootAsItem; nsCOMPtr<nsIDocShellTreeItem> rootAsItem;
@ -291,12 +289,9 @@ nsMsgPrintEngine::ShowWindow(PRBool aShow)
nsCOMPtr <nsIScriptGlobalObject> globalScript = do_QueryInterface(mWindow, &rv); nsCOMPtr <nsIScriptGlobalObject> globalScript = do_QueryInterface(mWindow, &rv);
NS_ENSURE_SUCCESS(rv,rv); NS_ENSURE_SUCCESS(rv,rv);
nsCOMPtr <nsIDocShell> docShell;
rv = globalScript->GetDocShell(getter_AddRefs(docShell)); nsCOMPtr <nsIWebShell> webShell =
NS_ENSURE_SUCCESS(rv,rv); do_QueryInterface(globalScript->GetDocShell(), &rv);
nsCOMPtr <nsIWebShell> webShell = do_QueryInterface(docShell, &rv);
NS_ENSURE_SUCCESS(rv,rv); NS_ENSURE_SUCCESS(rv,rv);
nsCOMPtr <nsIWebShellContainer> webShellContainer; nsCOMPtr <nsIWebShellContainer> webShellContainer;
@ -307,7 +302,7 @@ nsMsgPrintEngine::ShowWindow(PRBool aShow)
nsCOMPtr <nsIWebShellWindow> webShellWindow = do_QueryInterface(webShellContainer, &rv); nsCOMPtr <nsIWebShellWindow> webShellWindow = do_QueryInterface(webShellContainer, &rv);
NS_ENSURE_SUCCESS(rv,rv); NS_ENSURE_SUCCESS(rv,rv);
nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(docShell, &rv)); nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(webShell, &rv));
NS_ENSURE_SUCCESS(rv,rv); NS_ENSURE_SUCCESS(rv,rv);
nsCOMPtr<nsIDocShellTreeOwner> treeOwner; nsCOMPtr<nsIDocShellTreeOwner> treeOwner;

Просмотреть файл

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK ***** /* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
* *
@ -199,7 +199,6 @@ NS_IMETHODIMP nsMsgWindow::GetStatusFeedback(nsIMsgStatusFeedback * *aStatusFeed
NS_IMETHODIMP nsMsgWindow::SetStatusFeedback(nsIMsgStatusFeedback * aStatusFeedback) NS_IMETHODIMP nsMsgWindow::SetStatusFeedback(nsIMsgStatusFeedback * aStatusFeedback)
{ {
nsCOMPtr<nsIDocShell> messageWindowDocShell; nsCOMPtr<nsIDocShell> messageWindowDocShell;
GetMessageWindowDocShell(getter_AddRefs(messageWindowDocShell)); GetMessageWindowDocShell(getter_AddRefs(messageWindowDocShell));
@ -353,9 +352,9 @@ NS_IMETHODIMP nsMsgWindow::SetDOMWindow(nsIDOMWindowInternal *aWindow)
nsresult rv = NS_OK; nsresult rv = NS_OK;
nsCOMPtr<nsIScriptGlobalObject> globalScript(do_QueryInterface(aWindow)); nsCOMPtr<nsIScriptGlobalObject> globalScript(do_QueryInterface(aWindow));
nsCOMPtr<nsIDocShell> docShell; nsIDocShell *docShell = nsnull;
if (globalScript) if (globalScript)
globalScript->GetDocShell(getter_AddRefs(docShell)); docShell = globalScript->GetDocShell();
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(docShell)); nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(docShell));

Просмотреть файл

@ -522,11 +522,9 @@ nsMsgCompose::ConvertAndLoadComposeWindow(nsString& aPrefix,
if (!aBuf.IsEmpty() && mailEditor) if (!aBuf.IsEmpty() && mailEditor)
{ {
// XXX see bug #206793 // XXX see bug #206793
nsCOMPtr<nsIDocShell> docshell; nsIDocShell *docshell = nsnull;
nsCOMPtr<nsIScriptGlobalObject> globalObj = do_QueryInterface(m_window); nsCOMPtr<nsIScriptGlobalObject> globalObj = do_QueryInterface(m_window);
if (globalObj) if (globalObj && (docshell = globalObj->GetDocShell()))
globalObj->GetDocShell(getter_AddRefs(docshell));
if (docshell)
docshell->SetAppType(nsIDocShell::APP_TYPE_MAIL); docshell->SetAppType(nsIDocShell::APP_TYPE_MAIL);
if (aHTMLEditor && !mCiteReference.IsEmpty()) if (aHTMLEditor && !mCiteReference.IsEmpty())
@ -710,13 +708,12 @@ nsMsgCompose::Initialize(nsIDOMWindowInternal *aWindow, nsIMsgComposeParams *par
if (aWindow) if (aWindow)
{ {
m_window = aWindow; m_window = aWindow;
nsCOMPtr<nsIDocShell> docshell;
nsCOMPtr<nsIScriptGlobalObject> globalObj(do_QueryInterface(aWindow)); nsCOMPtr<nsIScriptGlobalObject> globalObj(do_QueryInterface(aWindow));
if (!globalObj) if (!globalObj)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
globalObj->GetDocShell(getter_AddRefs(docshell)); nsCOMPtr<nsIDocShellTreeItem> treeItem =
nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(docshell)); do_QueryInterface(globalObj->GetDocShell());
nsCOMPtr<nsIDocShellTreeOwner> treeOwner; nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
rv = treeItem->GetTreeOwner(getter_AddRefs(treeOwner)); rv = treeItem->GetTreeOwner(getter_AddRefs(treeOwner));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
@ -1268,8 +1265,7 @@ NS_IMETHODIMP nsMsgCompose::CloseWindow(PRBool recycleIt)
nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(m_window)); nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(m_window));
if (sgo) if (sgo)
{ {
nsCOMPtr<nsIScriptContext> scriptContext; nsIScriptContext *scriptContext = sgo->GetContext();
sgo->GetContext(getter_AddRefs(scriptContext));
if (scriptContext) if (scriptContext)
scriptContext->GC(); scriptContext->GC();
} }
@ -1336,8 +1332,7 @@ NS_IMETHODIMP nsMsgCompose::InitEditor(nsIEditor* aEditor, nsIDOMWindow* aConten
nsCOMPtr<nsIScriptGlobalObject> globalObj = do_QueryInterface(m_window); nsCOMPtr<nsIScriptGlobalObject> globalObj = do_QueryInterface(m_window);
nsCOMPtr<nsIDocShell> docShell; nsIDocShell *docShell = globalObj->GetDocShell();
globalObj->GetDocShell(getter_AddRefs(docShell));
NS_ENSURE_TRUE(docShell, NS_ERROR_UNEXPECTED); NS_ENSURE_TRUE(docShell, NS_ERROR_UNEXPECTED);
nsCOMPtr<nsIContentViewer> childCV; nsCOMPtr<nsIContentViewer> childCV;
@ -2376,10 +2371,10 @@ QuotingOutputStreamListener::InsertToCompose(nsIEditor *aEditor,
nsCOMPtr<nsIDOMWindowInternal> domWindow; nsCOMPtr<nsIDOMWindowInternal> domWindow;
if (compose) if (compose)
compose->GetDomWindow(getter_AddRefs(domWindow)); compose->GetDomWindow(getter_AddRefs(domWindow));
nsCOMPtr<nsIDocShell> docshell; nsIDocShell *docshell = nsnull;
nsCOMPtr<nsIScriptGlobalObject> globalObj = do_QueryInterface(domWindow); nsCOMPtr<nsIScriptGlobalObject> globalObj = do_QueryInterface(domWindow);
if (globalObj) if (globalObj)
globalObj->GetDocShell(getter_AddRefs(docshell)); docshell = globalObj->GetDocShell();
if (docshell) if (docshell)
docshell->SetAppType(nsIDocShell::APP_TYPE_MAIL); docshell->SetAppType(nsIDocShell::APP_TYPE_MAIL);

Просмотреть файл

@ -304,10 +304,9 @@ void nsMsgComposeService::CloseWindow(nsIDOMWindowInternal *domWindow)
nsCOMPtr<nsIScriptGlobalObject> globalObj(do_QueryInterface(domWindow)); nsCOMPtr<nsIScriptGlobalObject> globalObj(do_QueryInterface(domWindow));
if (globalObj) if (globalObj)
{ {
globalObj->GetDocShell(getter_AddRefs(docshell)); nsCOMPtr<nsIDocShellTreeItem> treeItem =
if (docshell) do_QueryInterface(globalObj->GetDocShell());
{
nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(docshell));
if (treeItem) if (treeItem)
{ {
nsCOMPtr<nsIDocShellTreeOwner> treeOwner; nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
@ -322,7 +321,6 @@ void nsMsgComposeService::CloseWindow(nsIDOMWindowInternal *domWindow)
} }
} }
} }
}
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -690,11 +688,9 @@ HWND hwndForComposeDOMWindow( nsISupports *window )
nsCOMPtr<nsIScriptGlobalObject> ppScriptGlobalObj( do_QueryInterface(window) ); nsCOMPtr<nsIScriptGlobalObject> ppScriptGlobalObj( do_QueryInterface(window) );
if ( !ppScriptGlobalObj ) if ( !ppScriptGlobalObj )
return 0; return 0;
nsCOMPtr<nsIDocShell> ppDocShell;
ppScriptGlobalObj->GetDocShell( getter_AddRefs( ppDocShell ) );
if ( !ppDocShell ) return 0;
nsCOMPtr<nsIBaseWindow> ppBaseWindow( do_QueryInterface( ppDocShell ) ); nsCOMPtr<nsIBaseWindow> ppBaseWindow =
do_QueryInterface( ppScriptGlobalObj->GetDocShell() );
if (!ppBaseWindow) return 0; if (!ppBaseWindow) return 0;
nsCOMPtr<nsIWidget> ppWidget; nsCOMPtr<nsIWidget> ppWidget;
@ -889,10 +885,8 @@ nsresult nsMsgComposeService::ShowCachedComposeWindow(nsIDOMWindowInternal *aCom
nsCOMPtr <nsIScriptGlobalObject> globalScript = do_QueryInterface(aComposeWindow, &rv); nsCOMPtr <nsIScriptGlobalObject> globalScript = do_QueryInterface(aComposeWindow, &rv);
NS_ENSURE_SUCCESS(rv,rv); NS_ENSURE_SUCCESS(rv,rv);
nsCOMPtr <nsIDocShell> docShell;
rv = globalScript->GetDocShell(getter_AddRefs(docShell)); nsIDocShell *docShell = globalScript->GetDocShell();
NS_ENSURE_SUCCESS(rv,rv);
nsCOMPtr <nsIWebShell> webShell = do_QueryInterface(docShell, &rv); nsCOMPtr <nsIWebShell> webShell = do_QueryInterface(docShell, &rv);
NS_ENSURE_SUCCESS(rv,rv); NS_ENSURE_SUCCESS(rv,rv);

Просмотреть файл

@ -58,13 +58,12 @@
*/ */
static nsresult getScriptCodebase(JSContext* cx, nsIURI* *result) static nsresult getScriptCodebase(JSContext* cx, nsIURI* *result)
{ {
nsCOMPtr<nsIScriptContext> scriptContext; nsIScriptContext *scriptContext = GetScriptContextFromJSContext(cx);
GetScriptContextFromJSContext(cx, getter_AddRefs(scriptContext));
if (scriptContext) { if (scriptContext) {
nsCOMPtr<nsIScriptGlobalObject> scriptGlobal; nsCOMPtr<nsIScriptObjectPrincipal> scriptObjectPrincipal =
scriptContext->GetGlobalObject(getter_AddRefs(scriptGlobal)); do_QueryInterface(scriptContext->GetGlobalObject());
nsCOMPtr<nsIScriptObjectPrincipal> scriptObjectPrincipal = do_QueryInterface(scriptGlobal);
if (scriptObjectPrincipal) { if (scriptObjectPrincipal) {
nsCOMPtr<nsIPrincipal> principal; nsCOMPtr<nsIPrincipal> principal;
scriptObjectPrincipal->GetPrincipal(getter_AddRefs(principal)); scriptObjectPrincipal->GetPrincipal(getter_AddRefs(principal));

Просмотреть файл

@ -337,24 +337,22 @@ enter_js_from_java_impl(JNIEnv *jEnv, char **errp,
nsCOMPtr<nsISecurityContext> javaSecurityContext = do_QueryInterface(credentials); nsCOMPtr<nsISecurityContext> javaSecurityContext = do_QueryInterface(credentials);
if (javaSecurityContext) { if (javaSecurityContext) {
if (pJSCX) { if (pJSCX) {
nsCOMPtr<nsIScriptContext> scriptContext; nsIScriptContext *scriptContext =
GetScriptContextFromJSContext(pJSCX, GetScriptContextFromJSContext(pJSCX);
getter_AddRefs(scriptContext));
if (scriptContext) { if (scriptContext) {
nsCOMPtr<nsIScriptGlobalObject> global; nsIScriptGlobalObject *global =
scriptContext->GetGlobalObject(getter_AddRefs(global)); scriptContext->GetGlobalObject();
NS_ASSERTION(global, "script context has no global object"); NS_ASSERTION(global, "script context has no global object");
if (global) { nsCOMPtr<nsIScriptObjectPrincipal> globalData =
nsCOMPtr<nsIScriptObjectPrincipal> globalData = do_QueryInterface(global); do_QueryInterface(global);
if (globalData) { if (globalData) {
if (NS_FAILED(globalData->GetPrincipal(getter_AddRefs(principal)))) if (NS_FAILED(globalData->GetPrincipal(getter_AddRefs(principal))))
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
} }
} }
}
// What if !pJSCX? // What if !pJSCX?
@ -407,8 +405,7 @@ exit_js_impl(JNIEnv *jEnv, JSContext *cx)
// The main idea is to execute terminate function if have any; // The main idea is to execute terminate function if have any;
if (cx) if (cx)
{ {
nsCOMPtr<nsIScriptContext> scriptContext; nsIScriptContext *scriptContext = GetScriptContextFromJSContext(cx);
GetScriptContextFromJSContext(cx, getter_AddRefs(scriptContext));
if (scriptContext) if (scriptContext)
{ {

Просмотреть файл

@ -818,53 +818,39 @@ nsJVMManager::EnsurePrefCallbackRegistered(void)
nsresult nsresult
nsJVMManager::GetChrome(nsIWebBrowserChrome **theChrome) nsJVMManager::GetChrome(nsIWebBrowserChrome **theChrome)
{ {
NS_ENSURE_ARG_POINTER(theChrome); *theChrome = nsnull;
nsresult rv = NS_ERROR_FAILURE; nsresult rv;
nsCOMPtr<nsIWindowWatcher> windowWatcher; nsCOMPtr<nsIWindowWatcher> windowWatcher =
nsCOMPtr<nsIDOMWindow> domWindow;
nsCOMPtr<nsIDocShell> docShell;
nsCOMPtr<nsIScriptGlobalObject> scriptObject;
nsCOMPtr<nsIPresContext> presContext;
nsCOMPtr<nsIDocShellTreeItem> treeItem;
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
nsCOMPtr<nsISupports> cont;
nsCOMPtr<nsIWebBrowserChrome> chrome;
windowWatcher =
do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv); do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv);
if (!windowWatcher) { if (NS_FAILED(rv)) {
return rv; return rv;
} }
rv = windowWatcher->GetActiveWindow(getter_AddRefs(domWindow)); nsCOMPtr<nsIDOMWindow> domWindow;
if (!domWindow) { windowWatcher->GetActiveWindow(getter_AddRefs(domWindow));
return rv; nsCOMPtr<nsIScriptGlobalObject> scriptObject =
} do_QueryInterface(domWindow, &rv);
scriptObject = do_QueryInterface(domWindow, &rv);
if (!scriptObject) { if (!scriptObject) {
return rv; return rv;
} }
rv = scriptObject->GetDocShell(getter_AddRefs(docShell)); nsIDocShell *docShell = scriptObject->GetDocShell();
if (!docShell) { if (!docShell) {
return rv; return NS_OK;
} }
nsCOMPtr<nsIPresContext> presContext;
rv = docShell->GetPresContext(getter_AddRefs(presContext)); rv = docShell->GetPresContext(getter_AddRefs(presContext));
if (!presContext) { if (!presContext) {
return rv; return rv;
} }
cont = presContext->GetContainer(); nsCOMPtr<nsISupports> container(presContext->GetContainer());
if (!cont) { nsCOMPtr<nsIDocShellTreeItem> treeItem = do_QueryInterface(container, &rv);
return NS_OK;
}
treeItem = do_QueryInterface(cont, &rv);
if (!treeItem) { if (!treeItem) {
return rv; return rv;
} }
rv = treeItem->GetTreeOwner(getter_AddRefs(treeOwner)); nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
if (!treeOwner) { treeItem->GetTreeOwner(getter_AddRefs(treeOwner));
return rv;
} nsCOMPtr<nsIWebBrowserChrome> chrome = do_GetInterface(treeOwner, &rv);
chrome = do_GetInterface(treeOwner, &rv);
*theChrome = (nsIWebBrowserChrome *) chrome.get(); *theChrome = (nsIWebBrowserChrome *) chrome.get();
NS_IF_ADDREF(*theChrome); NS_IF_ADDREF(*theChrome);
return rv; return rv;

Просмотреть файл

@ -5642,10 +5642,7 @@ NS_IMETHODIMP nsPluginHostImpl::NewPluginURLStream(const nsString& aURL,
if (global) if (global)
{ {
nsCOMPtr<nsIScriptGlobalObjectOwner> owner; callbacks = do_QueryInterface(global->GetGlobalObjectOwner());
global->GetGlobalObjectOwner(getter_AddRefs(owner));
callbacks = do_QueryInterface(owner);
} }
} }

Просмотреть файл

@ -773,13 +773,10 @@ NS_IMETHODIMP nsPluginInstancePeerImpl::GetJSContext(JSContext* *outContext)
nsIScriptGlobalObject *global = document->GetScriptGlobalObject(); nsIScriptGlobalObject *global = document->GetScriptGlobalObject();
if (global) { if (global) {
nsCOMPtr<nsIScriptContext> context; nsIScriptContext *context = global->GetContext();
if (global->GetContext(getter_AddRefs(context)) == NS_OK) {
if (context) { if (context) {
*outContext = (JSContext*) context->GetNativeContext(); *outContext = (JSContext*) context->GetNativeContext();
rv = NS_OK;
}
} }
} }
} }

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше