diff --git a/caps/src/nsScriptSecurityManager.cpp b/caps/src/nsScriptSecurityManager.cpp index f897e43133c..059acc1aac2 100644 --- a/caps/src/nsScriptSecurityManager.cpp +++ b/caps/src/nsScriptSecurityManager.cpp @@ -99,13 +99,10 @@ JSValIDToString(JSContext *cx, const jsval idval) return NS_REINTERPRET_CAST(PRUnichar*, JS_GetStringChars(str)); } -already_AddRefed +static nsIScriptContext * GetScriptContext(JSContext *cx) { - nsIScriptContext *scriptContext; - GetScriptContextFromJSContext(cx, &scriptContext); - - return scriptContext; + return GetScriptContextFromJSContext(cx); } // 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; *result = nsnull; - nsCOMPtr docshell; - nsCOMPtr scriptContext = GetScriptContext(cx); - if (!scriptContext) return NS_ERROR_FAILURE; - nsCOMPtr globalObject; - scriptContext->GetGlobalObject(getter_AddRefs(globalObject)); - if (!globalObject) return NS_ERROR_FAILURE; - rv = globalObject->GetDocShell(getter_AddRefs(docshell)); - if (NS_FAILED(rv)) return rv; - nsCOMPtr docshellTreeItem(do_QueryInterface(docshell, &rv)); + nsIScriptContext *scriptContext = GetScriptContext(cx); + if (!scriptContext) + return NS_ERROR_FAILURE; + + nsIScriptGlobalObject *globalObject = scriptContext->GetGlobalObject(); + if (!globalObject) + return NS_ERROR_FAILURE; + + nsCOMPtr docshellTreeItem = + do_QueryInterface(globalObject->GetDocShell(), &rv); if (NS_FAILED(rv)) return rv; + nsCOMPtr rootItem; rv = docshellTreeItem->GetRootTreeItem(getter_AddRefs(rootItem)); if (NS_FAILED(rv)) return rv; @@ -1479,15 +1478,13 @@ nsScriptSecurityManager::CanExecuteScripts(JSContext* cx, } //-- See if the current window allows JS execution - nsCOMPtr scriptContext = GetScriptContext(cx); + nsIScriptContext *scriptContext = GetScriptContext(cx); if (!scriptContext) return NS_ERROR_FAILURE; - nsCOMPtr globalObject; - scriptContext->GetGlobalObject(getter_AddRefs(globalObject)); + nsIScriptGlobalObject *globalObject = scriptContext->GetGlobalObject(); if (!globalObject) return NS_ERROR_FAILURE; - + nsresult rv; - nsCOMPtr docshell; - globalObject->GetDocShell(getter_AddRefs(docshell)); + nsCOMPtr docshell = globalObject->GetDocShell(); nsCOMPtr globalObjTreeItem = do_QueryInterface(docshell); if (globalObjTreeItem) { @@ -1731,16 +1728,15 @@ nsScriptSecurityManager::GetPrincipalFromContext(JSContext *cx, { *result = nsnull; - nsCOMPtr scriptContext = GetScriptContext(cx); + nsIScriptContext *scriptContext = GetScriptContext(cx); if (!scriptContext) { return NS_ERROR_FAILURE; } - nsCOMPtr global; - scriptContext->GetGlobalObject(getter_AddRefs(global)); - nsCOMPtr globalData(do_QueryInterface(global)); + nsCOMPtr globalData = + do_QueryInterface(scriptContext->GetGlobalObject()); if (globalData) globalData->GetPrincipal(result); @@ -1852,14 +1848,13 @@ nsScriptSecurityManager::GetPrincipalAndFrame(JSContext *cx, // and return the innermost frame for annotations. if (cx) { - nsCOMPtr scriptContext = GetScriptContext(cx); + nsIScriptContext *scriptContext = GetScriptContext(cx); if (scriptContext) { - nsCOMPtr global; - scriptContext->GetGlobalObject(getter_AddRefs(global)); - NS_ENSURE_TRUE(global, NS_ERROR_FAILURE); - nsCOMPtr globalData(do_QueryInterface(global)); + nsCOMPtr globalData = + do_QueryInterface(scriptContext->GetGlobalObject()); NS_ENSURE_TRUE(globalData, NS_ERROR_FAILURE); + globalData->GetPrincipal(result); if (*result) { @@ -2060,13 +2055,11 @@ nsScriptSecurityManager::CheckConfirmDialog(JSContext* cx, nsIPrincipal* aPrinci nsCOMPtr prompter; if (cx) { - nsCOMPtr scriptContext = GetScriptContext(cx); + nsIScriptContext *scriptContext = GetScriptContext(cx); if (scriptContext) { - nsCOMPtr globalObject; - scriptContext->GetGlobalObject(getter_AddRefs(globalObject)); - NS_ASSERTION(globalObject, "script context has no global object"); - nsCOMPtr domWin(do_QueryInterface(globalObject)); + nsCOMPtr domWin = + do_QueryInterface(scriptContext->GetGlobalObject()); if (domWin) domWin->GetPrompter(getter_AddRefs(prompter)); } diff --git a/content/base/public/nsContentUtils.h b/content/base/public/nsContentUtils.h index 49f097e9066..cde08520200 100644 --- a/content/base/public/nsContentUtils.h +++ b/content/base/public/nsContentUtils.h @@ -172,19 +172,15 @@ public: // These are copied from nsJSUtils.h - static nsresult GetStaticScriptGlobal(JSContext* aContext, - JSObject* aObj, - nsIScriptGlobalObject** aNativeGlobal); + static nsIScriptGlobalObject *GetStaticScriptGlobal(JSContext* aContext, + JSObject* aObj); - static nsresult GetStaticScriptContext(JSContext* aContext, - JSObject* aObj, - nsIScriptContext** aScriptContext); + static nsIScriptContext *GetStaticScriptContext(JSContext* aContext, + JSObject* aObj); - static nsresult GetDynamicScriptGlobal(JSContext *aContext, - nsIScriptGlobalObject** aNativeGlobal); + static nsIScriptGlobalObject *GetDynamicScriptGlobal(JSContext *aContext); - static nsresult GetDynamicScriptContext(JSContext *aContext, - nsIScriptContext** aScriptContext); + static nsIScriptContext *GetDynamicScriptContext(JSContext *aContext); static PRUint32 CopyNewlineNormalizedUnicodeTo(const nsAString& aSource, PRUint32 aSrcOffset, @@ -224,7 +220,7 @@ public: * * @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. @@ -232,7 +228,7 @@ public: * * @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 // element. diff --git a/content/base/src/nsAttrAndChildArray.cpp b/content/base/src/nsAttrAndChildArray.cpp index 8a33a602723..826bb1fbce7 100644 --- a/content/base/src/nsAttrAndChildArray.cpp +++ b/content/base/src/nsAttrAndChildArray.cpp @@ -664,8 +664,11 @@ nsAttrAndChildArray::AddAttrSlot() return PR_FALSE; } void** offset = mImpl->mBuffer + slotCount * ATTRSIZE; - memmove(&ATTRS(mImpl)[slotCount + 1], &ATTRS(mImpl)[slotCount], - childCount * sizeof(nsIContent*)); + + if (childCount > 0) { + memmove(&ATTRS(mImpl)[slotCount + 1], &ATTRS(mImpl)[slotCount], + childCount * sizeof(nsIContent*)); + } SetAttrSlotCount(slotCount + 1); offset[0] = nsnull; diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index cd569afa7af..1a0a3e02208 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -158,21 +158,18 @@ nsContentUtils::GetParserServiceWeakRef() } // static -nsresult -nsContentUtils::GetStaticScriptGlobal(JSContext* aContext, JSObject* aObj, - nsIScriptGlobalObject** aNativeGlobal) +nsIScriptGlobalObject * +nsContentUtils::GetStaticScriptGlobal(JSContext* aContext, JSObject* aObj) { if (!sXPConnect) { - *aNativeGlobal = nsnull; - - return NS_OK; + return nsnull; } JSObject* parent; JSObject* glob = aObj; // starting point for search if (!glob) - return NS_ERROR_FAILURE; + return nsnull; while (nsnull != (parent = JS_GetParent(aContext, glob))) { glob = parent; @@ -180,54 +177,47 @@ nsContentUtils::GetStaticScriptGlobal(JSContext* aContext, JSObject* aObj, nsCOMPtr wrapped_native; - nsresult rv = - sXPConnect->GetWrappedNativeOfJSObject(aContext, glob, - getter_AddRefs(wrapped_native)); - NS_ENSURE_SUCCESS(rv, rv); + sXPConnect->GetWrappedNativeOfJSObject(aContext, glob, + getter_AddRefs(wrapped_native)); + NS_ENSURE_TRUE(wrapped_native, nsnull); nsCOMPtr native; - rv = wrapped_native->GetNative(getter_AddRefs(native)); - NS_ENSURE_SUCCESS(rv, rv); + wrapped_native->GetNative(getter_AddRefs(native)); - return CallQueryInterface(native, aNativeGlobal); + nsCOMPtr 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 -nsresult +nsIScriptContext * nsContentUtils::GetStaticScriptContext(JSContext* aContext, - JSObject* aObj, - nsIScriptContext** aScriptContext) + JSObject* aObj) { - nsCOMPtr nativeGlobal; - GetStaticScriptGlobal(aContext, aObj, getter_AddRefs(nativeGlobal)); + nsIScriptGlobalObject *nativeGlobal = GetStaticScriptGlobal(aContext, aObj); if (!nativeGlobal) - return NS_ERROR_FAILURE; - nsIScriptContext* scriptContext = nsnull; - nativeGlobal->GetContext(&scriptContext); - *aScriptContext = scriptContext; - return scriptContext ? NS_OK : NS_ERROR_FAILURE; + return nsnull; + return nativeGlobal->GetContext(); } //static -nsresult -nsContentUtils::GetDynamicScriptGlobal(JSContext* aContext, - nsIScriptGlobalObject** aNativeGlobal) +nsIScriptGlobalObject * +nsContentUtils::GetDynamicScriptGlobal(JSContext* aContext) { - nsCOMPtr scriptCX; - GetDynamicScriptContext(aContext, getter_AddRefs(scriptCX)); + nsIScriptContext *scriptCX = GetDynamicScriptContext(aContext); if (!scriptCX) { - *aNativeGlobal = nsnull; - return NS_ERROR_FAILURE; + return nsnull; } - return scriptCX->GetGlobalObject(aNativeGlobal); + return scriptCX->GetGlobalObject(); } //static -nsresult -nsContentUtils::GetDynamicScriptContext(JSContext *aContext, - nsIScriptContext** aScriptContext) +nsIScriptContext * +nsContentUtils::GetDynamicScriptContext(JSContext *aContext) { - return GetScriptContextFromJSContext(aContext, aScriptContext); + return GetScriptContextFromJSContext(aContext); } template @@ -746,31 +736,26 @@ nsContentUtils::doReparentContentWrapper(nsIContent *aChild, return rv; } -static -nsresult GetContextFromDocument(nsIDocument *aDocument, JSContext **cx) +static JSContext * +GetContextFromDocument(nsIDocument *aDocument) { - *cx = nsnull; - nsIScriptGlobalObject *sgo = aDocument->GetScriptGlobalObject(); if (!sgo) { // No script global, no context. - return NS_OK; + return nsnull; } - nsCOMPtr scx; - sgo->GetContext(getter_AddRefs(scx)); + nsIScriptContext *scx = sgo->GetContext(); if (!scx) { // No context left in the old scope... - return NS_OK; + return nsnull; } - *cx = (JSContext *)scx->GetNativeContext(); - - return NS_OK; + return (JSContext *)scx->GetNativeContext(); } // static @@ -813,9 +798,7 @@ nsContentUtils::ReparentContentWrapper(nsIContent *aContent, new_parent = aNewParent; } - JSContext *cx = nsnull; - - GetContextFromDocument(old_doc, &cx); + JSContext *cx = GetContextFromDocument(old_doc); if (!cx) { // No JSContext left in the old scope, can't find the old wrapper @@ -857,49 +840,51 @@ nsContentUtils::ReparentContentWrapper(nsIContent *aContent, obj); } -void -nsContentUtils::GetDocShellFromCaller(nsIDocShell** aDocShell) +nsIDocShell * +nsContentUtils::GetDocShellFromCaller() { - *aDocShell = nsnull; if (!sThreadJSContextStack) { - return; + return nsnull; } JSContext *cx = nsnull; sThreadJSContextStack->Peek(&cx); if (cx) { - nsCOMPtr sgo; - GetDynamicScriptGlobal(cx, getter_AddRefs(sgo)); + nsIScriptGlobalObject *sgo = GetDynamicScriptGlobal(cx); if (sgo) { - sgo->GetDocShell(aDocShell); + return sgo->GetDocShell(); } } + + return nsnull; } -void -nsContentUtils::GetDocumentFromCaller(nsIDOMDocument** aDocument) +nsIDOMDocument * +nsContentUtils::GetDocumentFromCaller() { - *aDocument = nsnull; if (!sThreadJSContextStack) { - return; + return nsnull; } JSContext *cx = nsnull; sThreadJSContextStack->Peek(&cx); + nsCOMPtr doc; + if (cx) { - nsCOMPtr sgo; - GetDynamicScriptGlobal(cx, getter_AddRefs(sgo)); + nsIScriptGlobalObject *sgo = GetDynamicScriptGlobal(cx); nsCOMPtr win(do_QueryInterface(sgo)); - if (!win) { - return; + if (win) { + 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 @@ -1635,7 +1620,7 @@ nsCxPusher::Push(nsISupports *aCurrentTarget) JSContext *cx = nsnull; if (sgo) { - sgo->GetContext(getter_AddRefs(mScx)); + mScx = sgo->GetContext(); if (mScx) { cx = (JSContext *)mScx->GetNativeContext(); diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index 0d5f6a55a87..3789f4a4f74 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -368,8 +368,7 @@ nsDOMImplementation::CreateDocument(const nsAString& aNamespaceURI, nsresult rv = NS_NewDOMDocument(aReturn, aNamespaceURI, aQualifiedName, aDoctype, mBaseURI); - nsCOMPtr docShell; - nsContentUtils::GetDocShellFromCaller(getter_AddRefs(docShell)); + nsIDocShell *docShell = nsContentUtils::GetDocShellFromCaller(); if (docShell) { nsCOMPtr presContext; docShell->GetPresContext(getter_AddRefs(presContext)); @@ -1757,11 +1756,8 @@ nsDocument::EndLoad() nsCOMPtr target_frame; if (mScriptGlobalObject) { - nsCOMPtr docShell; - mScriptGlobalObject->GetDocShell(getter_AddRefs(docShell)); - nsCOMPtr docShellAsItem = - do_QueryInterface(docShell); + do_QueryInterface(mScriptGlobalObject->GetDocShell()); if (docShellAsItem) { docShellAsItem->GetSameTypeParent(getter_AddRefs(docShellParent)); @@ -3788,10 +3784,8 @@ nsDocument::FlushPendingNotifications(PRBool aFlushReflows, // that uses mParentDocument, but mParentDocument is never set in // the current code! - nsCOMPtr docShell; - mScriptGlobalObject->GetDocShell(getter_AddRefs(docShell)); - - nsCOMPtr docShellAsItem(do_QueryInterface(docShell)); + nsCOMPtr docShellAsItem = + do_QueryInterface(mScriptGlobalObject->GetDocShell()); if (docShellAsItem) { nsCOMPtr docShellParent; @@ -3923,8 +3917,7 @@ nsDocument::IsScriptEnabled() nsIScriptGlobalObject* globalObject = GetScriptGlobalObject(); NS_ENSURE_TRUE(globalObject, PR_TRUE); - nsCOMPtr scriptContext; - globalObject->GetContext(getter_AddRefs(scriptContext)); + nsIScriptContext *scriptContext = globalObject->GetContext(); NS_ENSURE_TRUE(scriptContext, PR_TRUE); JSContext* cx = (JSContext *) scriptContext->GetNativeContext(); diff --git a/content/base/src/nsGenericElement.cpp b/content/base/src/nsGenericElement.cpp index 5a6e25c08a4..245851b4ac8 100644 --- a/content/base/src/nsGenericElement.cpp +++ b/content/base/src/nsGenericElement.cpp @@ -2588,9 +2588,7 @@ isSelfOrAncestor(nsIContent *aNode, nsIContent *aChild) /* * If aChild doesn't have children it can't be our ancestor */ - PRUint32 childCount = aChild->GetChildCount(); - - if (childCount == 0) { + if (aChild->GetChildCount() == 0) { return PR_FALSE; } @@ -3137,62 +3135,37 @@ nsresult nsGenericElement::AddScriptEventListener(nsIAtom* aAttribute, const nsAString& aValue) { - nsresult ret = NS_OK; - nsCOMPtr context; - nsCOMPtr global; - JSContext* cx = nsnull; + nsresult rv = NS_OK; + nsISupports *target = NS_STATIC_CAST(nsIContent *, this); + PRBool defer = PR_TRUE; - // Try to get context from doc - if (mDocument) { - if ((global = mDocument->GetScriptGlobalObject())) { - NS_ENSURE_SUCCESS(global->GetContext(getter_AddRefs(context)), NS_ERROR_FAILURE); - } - } - - if (!context) { - // Get JSContext from stack. - nsCOMPtr 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); - } + nsCOMPtr manager; // Attributes on the body and frameset tags get set on the global object if (mNodeInfo->Equals(nsHTMLAtoms::body) || mNodeInfo->Equals(nsHTMLAtoms::frameset)) { - if (!global && cx) { - nsContentUtils::GetDynamicScriptGlobal(cx, getter_AddRefs(global)); + nsIScriptGlobalObject *sgo; - NS_ENSURE_TRUE(global, NS_ERROR_FAILURE); - } - nsCOMPtr receiver(do_QueryInterface(global)); - NS_ENSURE_TRUE(receiver, 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. + if (mDocument && (sgo = mDocument->GetScriptGlobalObject())) { + nsCOMPtr receiver(do_QueryInterface(sgo)); + NS_ENSURE_TRUE(receiver, NS_ERROR_FAILURE); - nsCOMPtr manager; - receiver->GetListenerManager(getter_AddRefs(manager)); + receiver->GetListenerManager(getter_AddRefs(manager)); - if (manager) { - ret = manager->AddScriptEventListener(context, global, aAttribute, - aValue, PR_FALSE); + target = sgo; + defer = PR_FALSE; } } else { - nsCOMPtr manager; GetListenerManager(getter_AddRefs(manager)); - - if (manager) { - ret = manager->AddScriptEventListener(context, this, aAttribute, aValue, - PR_TRUE); - } } - return ret; + if (manager) { + rv = manager->AddScriptEventListener(target, aAttribute, aValue, defer); + } + + return rv; } diff --git a/content/base/src/nsPrintEngine.cpp b/content/base/src/nsPrintEngine.cpp index ac6131575fe..676f2c47fcc 100644 --- a/content/base/src/nsPrintEngine.cpp +++ b/content/base/src/nsPrintEngine.cpp @@ -1708,9 +1708,7 @@ nsPrintEngine::IsThereARangeSelection(nsIDOMWindow* aDOMWin) nsCOMPtr presShell; if (aDOMWin) { nsCOMPtr scriptObj(do_QueryInterface(aDOMWin)); - nsCOMPtr docShell; - scriptObj->GetDocShell(getter_AddRefs(docShell)); - docShell->GetPresShell(getter_AddRefs(presShell)); + scriptObj->GetDocShell()->GetPresShell(getter_AddRefs(presShell)); } // 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 nsCOMPtr scriptObj(do_QueryInterface(aDOMWindow)); if (scriptObj) { - nsCOMPtr docShell; - scriptObj->GetDocShell(getter_AddRefs(docShell)); + nsCOMPtr docShellAsItem = + do_QueryInterface(scriptObj->GetDocShell()); - nsCOMPtr docShellAsItem(do_QueryInterface(docShell)); if (docShellAsItem) { // get this DocViewer webshell nsCOMPtr thisDVWebShell(do_QueryInterface(mContainer)); @@ -4440,9 +4437,8 @@ nsPrintEngine::TurnScriptingOn(PRBool aDoTurnOn) // get the script global object nsIScriptGlobalObject *scriptGlobalObj = mDocument->GetScriptGlobalObject(); NS_ASSERTION(scriptGlobalObj, "Can't get nsIScriptGlobalObject"); - nsCOMPtr scx; - nsresult rv = scriptGlobalObj->GetContext(getter_AddRefs(scx)); - NS_ASSERTION(NS_SUCCEEDED(rv) && scx, "Can't get nsIScriptContext"); + nsIScriptContext *scx = scriptGlobalObj->GetContext(); + NS_ASSERTION(scx, "Can't get nsIScriptContext"); scx->SetScriptsEnabled(aDoTurnOn, PR_TRUE); } diff --git a/content/base/src/nsRange.cpp b/content/base/src/nsRange.cpp index caeb51585e1..e937563ad68 100644 --- a/content/base/src/nsRange.cpp +++ b/content/base/src/nsRange.cpp @@ -2490,20 +2490,19 @@ nsRange::CreateContextualFragment(const nsAString& aFragment, if (NS_SUCCEEDED(result) && (!subjectPrin || sysPrin.get() == subjectPrin.get())) { nsIScriptGlobalObject *globalObj = document->GetScriptGlobalObject(); - - nsCOMPtr scriptContext; - if (globalObj) { - result = globalObj->GetContext(getter_AddRefs(scriptContext)); - } - JSContext* cx = nsnull; - if (NS_SUCCEEDED(result) && scriptContext) { - cx = (JSContext*)scriptContext->GetNativeContext(); + + if (globalObj) { + nsIScriptContext *scriptContext = globalObj->GetContext(); + + if (scriptContext) { + cx = (JSContext*)scriptContext->GetNativeContext(); + } } - if(cx) { - ContextStack = do_GetService("@mozilla.org/js/xpc/ContextStack;1", &result); - if(NS_SUCCEEDED(result)) { + if (cx) { + ContextStack = do_GetService("@mozilla.org/js/xpc/ContextStack;1"); + if (ContextStack) { result = ContextStack->Push(cx); } } diff --git a/content/base/src/nsScriptLoader.cpp b/content/base/src/nsScriptLoader.cpp index 97be06c2924..12ecd4169a4 100644 --- a/content/base/src/nsScriptLoader.cpp +++ b/content/base/src/nsScriptLoader.cpp @@ -363,16 +363,13 @@ nsScriptLoader::ProcessScriptElement(nsIDOMHTMLScriptElement *aElement, nsIScriptGlobalObject *globalObject = mDocument->GetScriptGlobalObject(); if (globalObject) { - nsCOMPtr context; - 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 - // point in going on. - if (!scriptsEnabled) { - return FireErrorNotification(NS_ERROR_NOT_AVAILABLE, aElement, aObserver); - } + nsIScriptContext *context = globalObject->GetContext(); + + // If scripts aren't enabled in the current context, there's no + // point in going on. + if (context && !context->GetScriptsEnabled()) { + return FireErrorNotification(NS_ERROR_NOT_AVAILABLE, aElement, + aObserver); } } @@ -476,12 +473,7 @@ nsScriptLoader::ProcessScriptElement(nsIDOMHTMLScriptElement *aElement, nsCOMPtr loadGroup = mDocument->GetDocumentLoadGroup(); nsCOMPtr loader; - nsCOMPtr docshell; - rv = globalObject->GetDocShell(getter_AddRefs(docshell)); - if (NS_FAILED(rv)) { - mPendingRequests.RemoveObject(request); - return FireErrorNotification(rv, aElement, aObserver); - } + nsIDocShell *docshell = globalObject->GetDocShell(); nsCOMPtr prompter(do_QueryInterface(docshell)); @@ -636,9 +628,8 @@ nsScriptLoader::EvaluateScript(nsScriptLoadRequest* aRequest, nsIScriptGlobalObject *globalObject = mDocument->GetScriptGlobalObject(); NS_ENSURE_TRUE(globalObject, NS_ERROR_FAILURE); - nsCOMPtr context; - rv = globalObject->GetContext(getter_AddRefs(context)); - if (NS_FAILED(rv) || !context) { + nsIScriptContext *context = globalObject->GetContext(); + if (!context) { return NS_ERROR_FAILURE; } diff --git a/content/events/public/nsIEventListenerManager.h b/content/events/public/nsIEventListenerManager.h index bacc35721ea..7c10345d7ea 100644 --- a/content/events/public/nsIEventListenerManager.h +++ b/content/events/public/nsIEventListenerManager.h @@ -99,8 +99,7 @@ public: * name aName and function body aFunc. * @param an event listener */ - NS_IMETHOD AddScriptEventListener(nsIScriptContext*aContext, - nsISupports *aObject, + NS_IMETHOD AddScriptEventListener(nsISupports *aObject, nsIAtom *aName, const nsAString& aFunc, PRBool aDeferCompilation) = 0; diff --git a/content/events/src/nsEventListenerManager.cpp b/content/events/src/nsEventListenerManager.cpp index d11d1415a97..62e2da8f911 100644 --- a/content/events/src/nsEventListenerManager.cpp +++ b/content/events/src/nsEventListenerManager.cpp @@ -59,7 +59,6 @@ #include "nsIEventStateManager.h" #include "nsPIDOMWindow.h" #include "nsIPrivateDOMEvent.h" -#include "nsIScriptEventListener.h" #include "nsIJSEventListener.h" #include "prmem.h" #include "nsIScriptGlobalObject.h" @@ -680,32 +679,15 @@ nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener, PRBool found = PR_FALSE; nsListenerStruct* ls; - nsresult rv; - - nsCOMPtr sel = do_QueryInterface(aListener, &rv); - for (int i=0; iCount(); 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; found = PR_TRUE; break; } - else if (sel) { - //Listener is an nsIScriptEventListener so we need to use its CheckIfEqual - //method to verify equality. - nsCOMPtr 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) { @@ -740,8 +722,6 @@ nsEventListenerManager::RemoveEventListener(nsIDOMEventListener *aListener, } nsListenerStruct* ls; - nsresult rv; - nsCOMPtr sel = do_QueryInterface(aListener, &rv); PRBool listenerRemoved = PR_FALSE; for (int i=0; iCount(); i++) { @@ -756,32 +736,18 @@ nsEventListenerManager::RemoveEventListener(nsIDOMEventListener *aListener, } break; } - else if (sel) { - //Listener is an nsIScriptEventListener so we need to use its CheckIfEqual - //method to verify equality. - nsCOMPtr 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; } -nsresult nsEventListenerManager::AddEventListenerByIID(nsIDOMEventListener *aListener, - const nsIID& aIID, PRInt32 aFlags) +nsresult +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; } @@ -790,11 +756,15 @@ nsEventListenerManager::RemoveEventListenerByIID(nsIDOMEventListener *aListener, const nsIID& aIID, 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; } -nsresult nsEventListenerManager::GetIdentifiersForType(nsIAtom* aType, EventArrayType* aArrayType, PRInt32* aFlags) +nsresult +nsEventListenerManager::GetIdentifiersForType(nsIAtom* aType, + EventArrayType* aArrayType, + PRInt32* aFlags) { if (aType == nsLayoutAtoms::onmousedown) { *aArrayType = eEventArrayType_Mouse; @@ -1107,18 +1077,62 @@ nsEventListenerManager::SetJSEventListener(nsIScriptContext *aContext, } NS_IMETHODIMP -nsEventListenerManager::AddScriptEventListener(nsIScriptContext* aContext, - nsISupports *aObject, +nsEventListenerManager::AddScriptEventListener(nsISupports *aObject, nsIAtom *aName, const nsAString& aBody, PRBool aDeferCompilation) { + nsIScriptContext *context = nsnull; + JSContext* cx = nsnull; + + nsCOMPtr 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 doc(do_QueryInterface(aObject)); + + nsCOMPtr global; + + if (doc) { + global = doc->GetScriptGlobalObject(); + } else { + global = do_QueryInterface(aObject); + } + + if (global) { + context = global->GetContext(); + } + } + + if (!context) { + // Get JSContext from stack. + nsCOMPtr 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; if (!aDeferCompilation) { nsCOMPtr xpc(do_GetService(nsIXPConnect::GetCID())); - JSContext *cx = (JSContext *)aContext->GetNativeContext(); + JSContext *cx = (JSContext *)context->GetNativeContext(); nsCOMPtr holder; @@ -1140,7 +1154,7 @@ nsEventListenerManager::AddScriptEventListener(nsIScriptContext* aContext, if (handlerOwner) { rv = handlerOwner->GetCompiledEventHandler(aName, &handler); if (NS_SUCCEEDED(rv) && handler) { - rv = aContext->BindCompiledEventHandler(scriptObject, aName, handler); + rv = context->BindCompiledEventHandler(scriptObject, aName, handler); if (NS_FAILED(rv)) return rv; done = PR_TRUE; @@ -1151,20 +1165,20 @@ nsEventListenerManager::AddScriptEventListener(nsIScriptContext* aContext, if (handlerOwner) { // Always let the handler owner compile the event handler, as // 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); } else { - rv = aContext->CompileEventHandler(scriptObject, aName, aBody, - nsnull, 0, - (handlerOwner != nsnull), - &handler); + rv = context->CompileEventHandler(scriptObject, aName, aBody, + nsnull, 0, + (handlerOwner != nsnull), + &handler); } if (NS_FAILED(rv)) return rv; } } - return SetJSEventListener(aContext, aObject, aName, aDeferCompilation); + return SetJSEventListener(context, aObject, aName, aDeferCompilation); } nsresult @@ -1392,19 +1406,14 @@ nsEventListenerManager::HandleEventSubType(nsListenerStruct* aListenerStruct, nsCOMPtr jslistener = do_QueryInterface(aListenerStruct->mListener); if (jslistener) { - nsCOMPtr target; - nsCOMPtr scriptCX; - result = jslistener->GetEventTarget(getter_AddRefs(scriptCX), - getter_AddRefs(target)); + nsAutoString eventString; + if (NS_SUCCEEDED(aDOMEvent->GetType(eventString))) { + nsCOMPtr atom = do_GetAtom(NS_LITERAL_STRING("on") + eventString); - if (NS_SUCCEEDED(result)) { - nsAutoString eventString; - if (NS_SUCCEEDED(aDOMEvent->GetType(eventString))) { - nsCOMPtr atom = do_GetAtom(NS_LITERAL_STRING("on") + eventString); - - result = CompileEventHandlerInternal(scriptCX, target, atom, - aListenerStruct, aSubType); - } + result = CompileEventHandlerInternal(jslistener->GetEventContext(), + jslistener->GetEventTarget(), + atom, aListenerStruct, + aSubType); } } } diff --git a/content/events/src/nsEventListenerManager.h b/content/events/src/nsEventListenerManager.h index e2ff59b5ba6..470fb164dba 100644 --- a/content/events/src/nsEventListenerManager.h +++ b/content/events/src/nsEventListenerManager.h @@ -123,8 +123,7 @@ public: const nsAString& type, PRInt32 aFlags, nsIDOMEventGroup* aEvtGroup); - NS_IMETHOD AddScriptEventListener(nsIScriptContext *aContext, - nsISupports *aObject, + NS_IMETHOD AddScriptEventListener(nsISupports *aObject, nsIAtom *aName, const nsAString& aFunc, PRBool aDeferCompilation); diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp index 3536e8adab5..3b530490697 100644 --- a/content/html/content/src/nsGenericHTMLElement.cpp +++ b/content/html/content/src/nsGenericHTMLElement.cpp @@ -865,17 +865,17 @@ nsGenericHTMLElement::SetInnerHTML(const nsAString& aInnerHTML) nsCOMPtr doc = GetOwnerDocument(); - nsCOMPtr scx; + nsIScriptContext *scx = nsnull; PRBool scripts_enabled = PR_FALSE; if (doc) { nsIScriptGlobalObject *sgo = doc->GetScriptGlobalObject(); if (sgo) { - sgo->GetContext(getter_AddRefs(scx)); + scx = sgo->GetContext(); if (scx) { - scx->GetScriptsEnabled(&scripts_enabled); + scripts_enabled = scx->GetScriptsEnabled(); } } } diff --git a/content/html/content/src/nsHTMLImageElement.cpp b/content/html/content/src/nsHTMLImageElement.cpp index c9937106646..79cb93b5f71 100644 --- a/content/html/content/src/nsHTMLImageElement.cpp +++ b/content/html/content/src/nsHTMLImageElement.cpp @@ -170,10 +170,8 @@ NS_NewHTMLImageElement(nsIHTMLContent** aInstancePtrResult, nsresult rv; nsCOMPtr nodeInfo(aNodeInfo); if (!nodeInfo) { - nsCOMPtr dom_doc; - nsContentUtils::GetDocumentFromCaller(getter_AddRefs(dom_doc)); - - nsCOMPtr doc(do_QueryInterface(dom_doc)); + nsCOMPtr doc = + do_QueryInterface(nsContentUtils::GetDocumentFromCaller()); NS_ENSURE_TRUE(doc, NS_ERROR_UNEXPECTED); nsINodeInfoManager *nodeInfoManager = doc->GetNodeInfoManager(); @@ -454,7 +452,6 @@ NS_IMETHODIMP nsHTMLImageElement::SetHeight(PRInt32 aHeight) { nsAutoString val; - val.AppendInt(aHeight); return nsGenericHTMLLeafElement::SetAttr(kNameSpaceID_None, @@ -474,7 +471,6 @@ NS_IMETHODIMP nsHTMLImageElement::SetWidth(PRInt32 aWidth) { nsAutoString val; - val.AppendInt(aWidth); return nsGenericHTMLLeafElement::SetAttr(kNameSpaceID_None, diff --git a/content/html/content/src/nsHTMLOptionElement.cpp b/content/html/content/src/nsHTMLOptionElement.cpp index c2f90957538..af7e1922978 100644 --- a/content/html/content/src/nsHTMLOptionElement.cpp +++ b/content/html/content/src/nsHTMLOptionElement.cpp @@ -163,10 +163,8 @@ NS_NewHTMLOptionElement(nsIHTMLContent** aInstancePtrResult, nsresult rv; nsCOMPtr nodeInfo(aNodeInfo); if (!nodeInfo) { - nsCOMPtr dom_doc; - nsContentUtils::GetDocumentFromCaller(getter_AddRefs(dom_doc)); - - nsCOMPtr doc(do_QueryInterface(dom_doc)); + nsCOMPtr doc = + do_QueryInterface(nsContentUtils::GetDocumentFromCaller()); NS_ENSURE_TRUE(doc, NS_ERROR_UNEXPECTED); nsINodeInfoManager *nodeInfoManager = doc->GetNodeInfoManager(); diff --git a/content/html/content/src/nsHTMLScriptElement.cpp b/content/html/content/src/nsHTMLScriptElement.cpp index b556b82f165..1cf01cae41f 100644 --- a/content/html/content/src/nsHTMLScriptElement.cpp +++ b/content/html/content/src/nsHTMLScriptElement.cpp @@ -207,16 +207,15 @@ nsHTMLScriptEventHandler::Invoke(nsISupports *aTargetObject, // Get the script context... nsCOMPtr domdoc; - nsCOMPtr scriptContext; - nsCOMPtr sgo; + nsIScriptContext *scriptContext = nsnull; mOuter->GetOwnerDocument(getter_AddRefs(domdoc)); nsCOMPtr doc(do_QueryInterface(domdoc)); if (doc) { - sgo = doc->GetScriptGlobalObject(); + nsIScriptGlobalObject *sgo = doc->GetScriptGlobalObject(); if (sgo) { - sgo->GetContext(getter_AddRefs(scriptContext)); + scriptContext = sgo->GetContext(); } } // Fail if is no script context is available... @@ -280,7 +279,7 @@ nsHTMLScriptEventHandler::Invoke(nsISupports *aTargetObject, // Compile the event handler script... void* funcObject = nsnull; - nsCString funcName(NS_LITERAL_CSTRING("anonymous")); + NS_NAMED_LITERAL_CSTRING(funcName, "anonymous"); rv = scriptContext->CompileFunction(scriptObject, funcName, // method name diff --git a/content/html/document/src/nsHTMLContentSink.cpp b/content/html/document/src/nsHTMLContentSink.cpp index 455d3d4c7ee..c705031a445 100644 --- a/content/html/document/src/nsHTMLContentSink.cpp +++ b/content/html/document/src/nsHTMLContentSink.cpp @@ -2093,8 +2093,7 @@ IsScriptEnabled(nsIDocument *aDoc, nsIDocShell *aContainer) NS_ENSURE_TRUE(globalObject, PR_TRUE); } - nsCOMPtr scriptContext; - globalObject->GetContext(getter_AddRefs(scriptContext)); + nsIScriptContext *scriptContext = globalObject->GetContext(); NS_ENSURE_TRUE(scriptContext, PR_TRUE); JSContext* cx = (JSContext *) scriptContext->GetNativeContext(); diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index 710a8a590fb..65910cb67fb 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -999,8 +999,7 @@ nsHTMLDocument::EndLoad() stack->Peek(&cx); if (cx) { - nsCOMPtr scx; - nsContentUtils::GetDynamicScriptContext(cx, getter_AddRefs(scx)); + nsIScriptContext *scx = nsContentUtils::GetDynamicScriptContext(cx); if (scx) { // The load of the document was terminated while we're @@ -2158,8 +2157,7 @@ nsHTMLDocument::GetSourceDocumentURI(nsIURI** sourceURI) *sourceURI = nsnull; // XXX This will fail on non-DOM contexts :( - nsCOMPtr domDoc; - nsContentUtils::GetDocumentFromCaller(getter_AddRefs(domDoc)); + nsIDOMDocument *domDoc = nsContentUtils::GetDocumentFromCaller(); nsCOMPtr doc(do_QueryInterface(domDoc)); if (!doc) { @@ -3717,8 +3715,7 @@ nsHTMLDocument::SetDesignMode(const nsAString & aDesignMode) if (!mScriptGlobalObject) return NS_ERROR_FAILURE; - nsCOMPtr docshell; - mScriptGlobalObject->GetDocShell(getter_AddRefs(docshell)); + nsIDocShell *docshell = mScriptGlobalObject->GetDocShell(); if (!docshell) return NS_ERROR_FAILURE; @@ -3788,8 +3785,7 @@ nsHTMLDocument::GetMidasCommandManager(nsICommandManager** aCmdMgr) if (!mScriptGlobalObject) return NS_ERROR_FAILURE; - nsCOMPtr docshell; - mScriptGlobalObject->GetDocShell(getter_AddRefs(docshell)); + nsIDocShell *docshell = mScriptGlobalObject->GetDocShell(); if (!docshell) return NS_ERROR_FAILURE; diff --git a/content/xbl/src/nsBindingManager.cpp b/content/xbl/src/nsBindingManager.cpp index 634bedd89d4..c9356a53041 100644 --- a/content/xbl/src/nsBindingManager.cpp +++ b/content/xbl/src/nsBindingManager.cpp @@ -1143,8 +1143,7 @@ nsBindingManager::GetBindingImplementation(nsIContent* aContent, REFNSIID aIID, if (!global) return NS_NOINTERFACE; - nsCOMPtr context; - global->GetContext(getter_AddRefs(context)); + nsIScriptContext *context = global->GetContext(); if (!context) return NS_NOINTERFACE; @@ -1157,7 +1156,6 @@ nsBindingManager::GetBindingImplementation(nsIContent* aContent, REFNSIID aIID, return NS_NOINTERFACE; nsCOMPtr wrapper; - xpConnect->GetWrappedNativeOfNativeObject(jscontext, JS_GetGlobalObject(jscontext), aContent, diff --git a/content/xbl/src/nsXBLBinding.cpp b/content/xbl/src/nsXBLBinding.cpp index 4d497fbbc24..92071c671b2 100644 --- a/content/xbl/src/nsXBLBinding.cpp +++ b/content/xbl/src/nsXBLBinding.cpp @@ -958,8 +958,7 @@ nsXBLBinding::ChangeDocument(nsIDocument* aOldDocument, nsIDocument* aNewDocumen if (interfaceElement) { nsIScriptGlobalObject *global = aOldDocument->GetScriptGlobalObject(); if (global) { - nsCOMPtr context; - global->GetContext(getter_AddRefs(context)); + nsIScriptContext *context = global->GetContext(); if (context) { JSContext *jscontext = (JSContext *)context->GetNativeContext(); @@ -1313,32 +1312,16 @@ nsXBLBinding::AddScriptEventListener(nsIContent* aElement, nsIAtom* aName, nsCOMPtr eventName = do_GetAtom(eventStr); nsresult rv; - nsCOMPtr document = aElement->GetDocument(); - if (!document) - return NS_OK; nsCOMPtr receiver(do_QueryInterface(aElement)); if (!receiver) return NS_OK; - nsIScriptGlobalObject *global = document->GetScriptGlobalObject(); - - // This can happen normally as part of teardown code. - if (!global) - return NS_OK; - - nsCOMPtr context; - rv = global->GetContext(getter_AddRefs(context)); - if (NS_FAILED(rv)) return rv; - - if (!context) return NS_OK; - nsCOMPtr manager; rv = receiver->GetListenerManager(getter_AddRefs(manager)); if (NS_FAILED(rv)) return rv; - rv = manager->AddScriptEventListener(context, receiver, eventName, - aValue, PR_FALSE); + rv = manager->AddScriptEventListener(receiver, eventName, aValue, PR_FALSE); return rv; } diff --git a/content/xbl/src/nsXBLDocumentInfo.cpp b/content/xbl/src/nsXBLDocumentInfo.cpp index f529e00f1f8..552549fa041 100644 --- a/content/xbl/src/nsXBLDocumentInfo.cpp +++ b/content/xbl/src/nsXBLDocumentInfo.cpp @@ -64,24 +64,24 @@ public: NS_DECL_ISUPPORTS // nsIScriptGlobalObject methods - NS_IMETHOD SetContext(nsIScriptContext *aContext); - NS_IMETHOD GetContext(nsIScriptContext **aContext); - NS_IMETHOD SetNewDocument(nsIDOMDocument *aDocument, - PRBool aRemoveEventListeners, - PRBool aClearScope); - NS_IMETHOD SetDocShell(nsIDocShell *aDocShell); - NS_IMETHOD GetDocShell(nsIDocShell **aDocShell); - NS_IMETHOD SetOpenerWindow(nsIDOMWindowInternal *aOpener); - NS_IMETHOD SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner); - NS_IMETHOD GetGlobalObjectOwner(nsIScriptGlobalObjectOwner** aOwner); - NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext, - nsEvent* aEvent, - nsIDOMEvent** aDOMEvent, - PRUint32 aFlags, - nsEventStatus* aEventStatus); - NS_IMETHOD_(JSObject *) GetGlobalJSObject(); - NS_IMETHOD OnFinalize(JSObject *aObject); - NS_IMETHOD SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts); + virtual void SetContext(nsIScriptContext *aContext); + virtual nsIScriptContext *GetContext(); + virtual nsresult SetNewDocument(nsIDOMDocument *aDocument, + PRBool aRemoveEventListeners, + PRBool aClearScope); + virtual void SetDocShell(nsIDocShell *aDocShell); + virtual nsIDocShell *GetDocShell(); + virtual void SetOpenerWindow(nsIDOMWindowInternal *aOpener); + virtual void SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner); + virtual nsIScriptGlobalObjectOwner *GetGlobalObjectOwner(); + virtual nsresult HandleDOMEvent(nsIPresContext* aPresContext, + nsEvent* aEvent, + nsIDOMEvent** aDOMEvent, + PRUint32 aFlags, + nsEventStatus* aEventStatus); + virtual JSObject *GetGlobalJSObject(); + virtual void OnFinalize(JSObject *aObject); + virtual void SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts); // nsIScriptObjectPrincipal methods NS_IMETHOD GetPrincipal(nsIPrincipal** aPrincipal); @@ -174,7 +174,7 @@ XBL_ProtoErrorReporter(JSContext *cx, // nsIScriptGlobalObject methods // -NS_IMETHODIMP +void nsXBLDocGlobalObject::SetContext(nsIScriptContext *aContext) { mScriptContext = aContext; @@ -182,29 +182,28 @@ nsXBLDocGlobalObject::SetContext(nsIScriptContext *aContext) JSContext* cx = (JSContext *)mScriptContext->GetNativeContext(); JS_SetErrorReporter(cx, XBL_ProtoErrorReporter); } - return NS_OK; } -NS_IMETHODIMP -nsXBLDocGlobalObject::GetContext(nsIScriptContext **aContext) +nsIScriptContext * +nsXBLDocGlobalObject::GetContext() { // This whole fragile mess is predicated on the fact that // GetContext() will be called before GetScriptObject() is. if (! mScriptContext) { nsCOMPtr factory = do_GetService(kDOMScriptObjectFactoryCID); - NS_ENSURE_TRUE(factory, NS_ERROR_FAILURE); + NS_ENSURE_TRUE(factory, nsnull); nsresult rv = factory->NewScriptContext(nsnull, getter_AddRefs(mScriptContext)); if (NS_FAILED(rv)) - return rv; + return nsnull; JSContext *cx = (JSContext *)mScriptContext->GetNativeContext(); JS_SetErrorReporter(cx, XBL_ProtoErrorReporter); mJSObject = ::JS_NewObject(cx, &gSharedGlobalClass, nsnull, nsnull); if (!mJSObject) - return NS_ERROR_OUT_OF_MEMORY; + return nsnull; ::JS_SetGlobalObject(cx, mJSObject); @@ -214,13 +213,11 @@ nsXBLDocGlobalObject::GetContext(nsIScriptContext **aContext) NS_ADDREF(this); } - *aContext = mScriptContext; - NS_IF_ADDREF(*aContext); - return NS_OK; + return mScriptContext; } -NS_IMETHODIMP +nsresult nsXBLDocGlobalObject::SetNewDocument(nsIDOMDocument *aDocument, PRBool aRemoveEventListeners, PRBool aClearScope) @@ -230,48 +227,43 @@ nsXBLDocGlobalObject::SetNewDocument(nsIDOMDocument *aDocument, } -NS_IMETHODIMP +void nsXBLDocGlobalObject::SetDocShell(nsIDocShell *aDocShell) { NS_NOTREACHED("waaah!"); - return NS_ERROR_UNEXPECTED; } -NS_IMETHODIMP -nsXBLDocGlobalObject::GetDocShell(nsIDocShell **aDocShell) +nsIDocShell * +nsXBLDocGlobalObject::GetDocShell() { NS_WARNING("waaah!"); - return NS_ERROR_UNEXPECTED; + return nsnull; } -NS_IMETHODIMP +void nsXBLDocGlobalObject::SetOpenerWindow(nsIDOMWindowInternal *aOpener) { NS_NOTREACHED("waaah!"); - return NS_ERROR_UNEXPECTED; } -NS_IMETHODIMP +void nsXBLDocGlobalObject::SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner) { mGlobalObjectOwner = aOwner; // weak reference - return NS_OK; } -NS_IMETHODIMP -nsXBLDocGlobalObject::GetGlobalObjectOwner(nsIScriptGlobalObjectOwner** aOwner) +nsIScriptGlobalObjectOwner * +nsXBLDocGlobalObject::GetGlobalObjectOwner() { - *aOwner = mGlobalObjectOwner; - NS_IF_ADDREF(*aOwner); - return NS_OK; + return mGlobalObjectOwner; } -NS_IMETHODIMP +nsresult nsXBLDocGlobalObject::HandleDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent, nsIDOMEvent** aDOMEvent, @@ -282,7 +274,7 @@ nsXBLDocGlobalObject::HandleDOMEvent(nsIPresContext* aPresContext, return NS_ERROR_UNEXPECTED; } -NS_IMETHODIMP_(JSObject *) +JSObject * nsXBLDocGlobalObject::GetGlobalJSObject() { // The prototype document has its own special secret script object @@ -299,22 +291,18 @@ nsXBLDocGlobalObject::GetGlobalJSObject() return ::JS_GetGlobalObject(cx); } -NS_IMETHODIMP +void nsXBLDocGlobalObject::OnFinalize(JSObject *aObject) { NS_ASSERTION(aObject == mJSObject, "Wrong object finalized!"); mJSObject = nsnull; - - return NS_OK; } -NS_IMETHODIMP +void nsXBLDocGlobalObject::SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts) { // We don't care... - - return NS_OK; } diff --git a/content/xbl/src/nsXBLDocumentInfo.h b/content/xbl/src/nsXBLDocumentInfo.h index 87238e8b077..a2052493b43 100644 --- a/content/xbl/src/nsXBLDocumentInfo.h +++ b/content/xbl/src/nsXBLDocumentInfo.h @@ -47,12 +47,12 @@ class nsXBLDocumentInfo : public nsIXBLDocumentInfo, public nsIScriptGlobalObjec { public: NS_DECL_ISUPPORTS - + nsXBLDocumentInfo(nsIDocument* aDocument); virtual ~nsXBLDocumentInfo(); - + NS_IMETHOD GetDocument(nsIDocument** aResult) { NS_ADDREF(*aResult = mDocument); return NS_OK; }; - + NS_IMETHOD GetScriptAccess(PRBool* aResult) { *aResult = mScriptAccess; return NS_OK; }; NS_IMETHOD SetScriptAccess(PRBool aAccess) { mScriptAccess = aAccess; return NS_OK; }; diff --git a/content/xbl/src/nsXBLProtoImpl.cpp b/content/xbl/src/nsXBLProtoImpl.cpp index 7abbacf0c6f..342ebf234b8 100644 --- a/content/xbl/src/nsXBLProtoImpl.cpp +++ b/content/xbl/src/nsXBLProtoImpl.cpp @@ -62,10 +62,7 @@ nsXBLProtoImpl::InstallImplementation(nsXBLPrototypeBinding* aBinding, nsIConten nsIScriptGlobalObject *global = document->GetScriptGlobalObject(); if (!global) return NS_OK; - nsCOMPtr context; - nsresult rv = global->GetContext(getter_AddRefs(context)); - NS_ENSURE_SUCCESS(rv, rv); - + nsIScriptContext *context = global->GetContext(); if (!context) return NS_OK; // 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. void * targetScriptObject = 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 // Walk our member list and install each one in turn. @@ -153,9 +151,8 @@ nsXBLProtoImpl::CompilePrototypeMembers(nsXBLPrototypeBinding* aBinding) nsCOMPtr globalObject; globalOwner->GetScriptGlobalObject(getter_AddRefs(globalObject)); - nsCOMPtr context; - globalObject->GetContext(getter_AddRefs(context)); - + nsIScriptContext *context = globalObject->GetContext(); + void* classObject; JSObject* scopeObject = globalObject->GetGlobalJSObject(); nsresult rv = aBinding->InitClass(mClassName, context, scopeObject, &classObject); diff --git a/content/xbl/src/nsXBLPrototypeHandler.cpp b/content/xbl/src/nsXBLPrototypeHandler.cpp index bb4fdd92fe8..9ecdd0ffbe8 100644 --- a/content/xbl/src/nsXBLPrototypeHandler.cpp +++ b/content/xbl/src/nsXBLPrototypeHandler.cpp @@ -395,8 +395,7 @@ nsXBLPrototypeHandler::ExecuteHandler(nsIDOMEventReceiver* aReceiver, if (!boundGlobal) return NS_OK; - nsCOMPtr boundContext; - boundGlobal->GetContext(getter_AddRefs(boundContext)); + nsIScriptContext *boundContext = boundGlobal->GetContext(); if (!boundContext) return NS_OK; JSObject* scriptObject = nsnull; diff --git a/content/xbl/src/nsXBLWindowHandler.cpp b/content/xbl/src/nsXBLWindowHandler.cpp index 5cf26c331b7..7998a57f7f2 100644 --- a/content/xbl/src/nsXBLWindowHandler.cpp +++ b/content/xbl/src/nsXBLWindowHandler.cpp @@ -248,8 +248,7 @@ nsXBLWindowHandler :: IsEditor() return PR_FALSE; nsCOMPtr obj(do_QueryInterface(focusedWindow)); - nsCOMPtr docShell; - obj->GetDocShell(getter_AddRefs(docShell)); + nsIDocShell *docShell = obj->GetDocShell(); nsCOMPtr presShell; if (docShell) docShell->GetPresShell(getter_AddRefs(presShell)); diff --git a/content/xml/document/src/nsXMLDocument.cpp b/content/xml/document/src/nsXMLDocument.cpp index adb85453687..01c73b037e3 100644 --- a/content/xml/document/src/nsXMLDocument.cpp +++ b/content/xml/document/src/nsXMLDocument.cpp @@ -340,9 +340,9 @@ nsXMLDocument::GetLoadGroup(nsILoadGroup **aLoadGroup) *aLoadGroup = nsnull; if (mScriptContext) { - nsCOMPtr global; - mScriptContext->GetGlobalObject(getter_AddRefs(global)); - nsCOMPtr window = do_QueryInterface(global); + nsCOMPtr window = + do_QueryInterface(mScriptContext->GetGlobalObject()); + if (window) { nsCOMPtr domdoc; window->GetDocument(getter_AddRefs(domdoc)); @@ -381,15 +381,14 @@ nsXMLDocument::Load(const nsAString& aUrl, PRBool *aReturn) mPrincipal = principal; mListenerManager = elm; - nsCOMPtr callingContext; + nsIScriptContext *callingContext = nsnull; nsCOMPtr stack = do_GetService("@mozilla.org/js/xpc/ContextStack;1"); if (stack) { JSContext *cx; if (NS_SUCCEEDED(stack->Peek(&cx)) && cx) { - nsContentUtils::GetDynamicScriptContext(cx, - getter_AddRefs(callingContext)); + callingContext = nsContentUtils::GetDynamicScriptContext(cx); } } @@ -397,10 +396,8 @@ nsXMLDocument::Load(const nsAString& aUrl, PRBool *aReturn) nsCAutoString charset; if (callingContext) { - nsCOMPtr sgo; - callingContext->GetGlobalObject(getter_AddRefs(sgo)); - - nsCOMPtr window(do_QueryInterface(sgo)); + nsCOMPtr window = + do_QueryInterface(callingContext->GetGlobalObject()); if (window) { nsCOMPtr dom_doc; diff --git a/content/xul/content/src/nsXULElement.cpp b/content/xul/content/src/nsXULElement.cpp index b4087cf24bc..38ac0e93a62 100644 --- a/content/xul/content/src/nsXULElement.cpp +++ b/content/xul/content/src/nsXULElement.cpp @@ -301,6 +301,13 @@ static EventHandlerMapEntry kEventHandlerMap[] = { static PRBool IsEventHandler(nsIAtom* aName) { + const char* name; + aName->GetUTF8String(&name); + + if (name[0] != 'o' || name[1] != 'n') { + return PR_FALSE; + } + EventHandlerMapEntry* entry = kEventHandlerMap; while (entry->mAttributeAtom) { if (entry->mAttributeAtom == aName) { @@ -1380,63 +1387,51 @@ nsXULElement::GetLazyState(LazyState aFlag, PRBool& aResult) NS_IMETHODIMP -nsXULElement::AddScriptEventListener(nsIAtom* aName, - const nsAString& aValue) +nsXULElement::AddScriptEventListener(nsIAtom* aName, const nsAString& aValue) { if (! mDocument) return NS_OK; // XXX nsresult rv; - nsCOMPtr context; - nsIScriptGlobalObject *global = mDocument->GetScriptGlobalObject(); - // This can happen normally as part of teardown code. - if (! global) - return NS_OK; + nsISupports *target = NS_STATIC_CAST(nsIContent *, this); + PRBool defer = PR_TRUE; - rv = global->GetContext(getter_AddRefs(context)); - if (NS_FAILED(rv)) return rv; - - if (!context) return NS_OK; + nsCOMPtr manager; nsIContent *root = mDocument->GetRootContent(); nsCOMPtr content(do_QueryInterface(NS_STATIC_CAST(nsIStyledContent*, this))); if ((!root || root == content) && !NodeInfo()->Equals(nsXULAtoms::overlay)) { + nsIScriptGlobalObject *global = mDocument->GetScriptGlobalObject(); + nsCOMPtr receiver = do_QueryInterface(global); if (! receiver) return NS_ERROR_UNEXPECTED; - nsCOMPtr manager; rv = receiver->GetListenerManager(getter_AddRefs(manager)); - if (NS_FAILED(rv)) return rv; - rv = manager->AddScriptEventListener(context, global, aName, - aValue, PR_FALSE); + target = global; + defer = PR_FALSE; } else { - nsCOMPtr 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 nsXULElement::GetListenerManager(nsIEventListenerManager** aResult) { if (!mListenerManager) { - nsresult rv; - mListenerManager = do_CreateInstance(kEventListenerManagerCID, &rv); + nsresult rv = + NS_NewEventListenerManager(getter_AddRefs(mListenerManager)); if (NS_FAILED(rv)) return rv; - mListenerManager->SetListenerTarget(NS_STATIC_CAST(nsIStyledContent*, this)); + mListenerManager->SetListenerTarget(NS_STATIC_CAST(nsIContent*, this)); } *aResult = mListenerManager; @@ -1448,7 +1443,7 @@ nsXULElement::GetListenerManager(nsIEventListenerManager** aResult) //---------------------------------------------------------------------- // nsIScriptEventHandlerOwner interface -NS_IMETHODIMP +nsresult nsXULElement::GetCompiledEventHandler(nsIAtom *aName, void** aHandler) { XUL_PROTOTYPE_ATTRIBUTE_METER(gNumCacheTests); @@ -1467,7 +1462,7 @@ nsXULElement::GetCompiledEventHandler(nsIAtom *aName, void** aHandler) return NS_OK; } -NS_IMETHODIMP +nsresult nsXULElement::CompileEventHandler(nsIScriptContext* aContext, void* aTarget, nsIAtom *aName, @@ -1481,7 +1476,7 @@ nsXULElement::CompileEventHandler(nsIScriptContext* aContext, XUL_PROTOTYPE_ATTRIBUTE_METER(gNumCacheSets); - nsCOMPtr context; + nsIScriptContext *context; if (mPrototype) { // It'll be shared among the instances of the prototype. // Use null for the scope object when precompiling shared @@ -1509,8 +1504,7 @@ nsXULElement::CompileEventHandler(nsIScriptContext* aContext, globalOwner->GetScriptGlobalObject(getter_AddRefs(global)); NS_ENSURE_TRUE(global, NS_ERROR_UNEXPECTED); - rv = global->GetContext(getter_AddRefs(context)); - NS_ENSURE_SUCCESS(rv, rv); + context = global->GetContext(); } else { // We don't have a prototype; do a one-off compile. @@ -1528,6 +1522,8 @@ nsXULElement::CompileEventHandler(nsIScriptContext* aContext, if (! scopeObject) { // If it's a shared handler, we need to bind the shared // function object to the real target. + + // XXX: Shouldn't this use context and not aContext? rv = aContext->BindCompiledEventHandler(aTarget, aName, *aHandler); if (NS_FAILED(rv)) return rv; } @@ -4934,19 +4930,18 @@ nsXULPrototypeScript::Compile(const PRUnichar* aText, nsresult rv; // Use the prototype document's special context - nsCOMPtr context; + nsIScriptContext *context = nsnull; { - nsCOMPtr global; nsCOMPtr globalOwner = do_QueryInterface(aPrototypeDocument); + nsCOMPtr global; globalOwner->GetScriptGlobalObject(getter_AddRefs(global)); NS_ASSERTION(global != nsnull, "prototype doc has no script global"); if (! global) return NS_ERROR_UNEXPECTED; - rv = global->GetContext(getter_AddRefs(context)); - if (NS_FAILED(rv)) return rv; + context = global->GetContext(); NS_ASSERTION(context != nsnull, "no context for script global"); if (! context) diff --git a/content/xul/content/src/nsXULElement.h b/content/xul/content/src/nsXULElement.h index a20c89046db..4d2138f52d7 100644 --- a/content/xul/content/src/nsXULElement.h +++ b/content/xul/content/src/nsXULElement.h @@ -539,14 +539,14 @@ public: NS_DECL_NSIDOMXULELEMENT // nsIScriptEventHandlerOwner - NS_IMETHOD CompileEventHandler(nsIScriptContext* aContext, - void* aTarget, - nsIAtom *aName, - const nsAString& aBody, - const char* aURL, - PRUint32 aLineNo, - void** aHandler); - NS_IMETHOD GetCompiledEventHandler(nsIAtom *aName, void** aHandler); + nsresult CompileEventHandler(nsIScriptContext* aContext, + void* aTarget, + nsIAtom *aName, + const nsAString& aBody, + const char* aURL, + PRUint32 aLineNo, + void** aHandler); + nsresult GetCompiledEventHandler(nsIAtom *aName, void** aHandler); // nsIChromeEventHandler NS_DECL_NSICHROMEEVENTHANDLER diff --git a/content/xul/content/src/nsXULPopupListener.cpp b/content/xul/content/src/nsXULPopupListener.cpp index 13965f8383c..ad7826af621 100644 --- a/content/xul/content/src/nsXULPopupListener.cpp +++ b/content/xul/content/src/nsXULPopupListener.cpp @@ -554,38 +554,33 @@ XULPopupListenerImpl::LaunchPopup(PRInt32 aClientX, PRInt32 aClientY) return NS_OK; // We have some popup content. Obtain our window. - nsCOMPtr context; - nsCOMPtr global = document->GetScriptGlobalObject(); - if (global) { - if ((NS_OK == global->GetContext(getter_AddRefs(context))) && context) { - // Get the DOM window - nsCOMPtr domWindow = do_QueryInterface(global); - if (domWindow != nsnull) { - // Find out if we're anchored. - mPopupContent = popupContent.get(); + nsCOMPtr domWindow = + do_QueryInterface(document->GetScriptGlobalObject()); - nsAutoString anchorAlignment; - mPopupContent->GetAttribute(NS_LITERAL_STRING("popupanchor"), anchorAlignment); + if (domWindow) { + // Find out if we're anchored. + mPopupContent = popupContent.get(); - nsAutoString popupAlignment; - mPopupContent->GetAttribute(NS_LITERAL_STRING("popupalign"), popupAlignment); + nsAutoString anchorAlignment; + mPopupContent->GetAttribute(NS_LITERAL_STRING("popupanchor"), anchorAlignment); - PRInt32 xPos = aClientX, yPos = aClientY; - - ConvertPosition(mPopupContent, anchorAlignment, popupAlignment, yPos); - if (!anchorAlignment.IsEmpty() && !popupAlignment.IsEmpty()) - xPos = yPos = -1; + nsAutoString popupAlignment; + mPopupContent->GetAttribute(NS_LITERAL_STRING("popupalign"), popupAlignment); - nsCOMPtr popupBox; - nsCOMPtr xulPopupElt(do_QueryInterface(mPopupContent)); - xulPopupElt->GetBoxObject(getter_AddRefs(popupBox)); - nsCOMPtr popupBoxObject(do_QueryInterface(popupBox)); - if (popupBoxObject) - popupBoxObject->ShowPopup(mElement, mPopupContent, xPos, yPos, - type.get(), anchorAlignment.get(), - popupAlignment.get()); - } - } + PRInt32 xPos = aClientX, yPos = aClientY; + + ConvertPosition(mPopupContent, anchorAlignment, popupAlignment, yPos); + if (!anchorAlignment.IsEmpty() && !popupAlignment.IsEmpty()) + xPos = yPos = -1; + + nsCOMPtr popupBox; + nsCOMPtr xulPopupElt(do_QueryInterface(mPopupContent)); + xulPopupElt->GetBoxObject(getter_AddRefs(popupBox)); + nsCOMPtr popupBoxObject(do_QueryInterface(popupBox)); + if (popupBoxObject) + popupBoxObject->ShowPopup(mElement, mPopupContent, xPos, yPos, + type.get(), anchorAlignment.get(), + popupAlignment.get()); } return NS_OK; diff --git a/content/xul/document/src/nsXULContentSink.cpp b/content/xul/document/src/nsXULContentSink.cpp index af5ccc5fc5b..0581176a392 100644 --- a/content/xul/document/src/nsXULContentSink.cpp +++ b/content/xul/document/src/nsXULContentSink.cpp @@ -1446,8 +1446,7 @@ XULContentSinkImpl::OpenScript(const PRUnichar** aAttributes, if (doc) { nsIScriptGlobalObject* globalObject = doc->GetScriptGlobalObject(); if (globalObject) { - nsCOMPtr scriptContext; - globalObject->GetContext(getter_AddRefs(scriptContext)); + nsIScriptContext *scriptContext = globalObject->GetContext(); if (scriptContext) script->DeserializeOutOfLine(nsnull, scriptContext); } diff --git a/content/xul/document/src/nsXULDocument.cpp b/content/xul/document/src/nsXULDocument.cpp index a01afd0c200..74f609f97ba 100644 --- a/content/xul/document/src/nsXULDocument.cpp +++ b/content/xul/document/src/nsXULDocument.cpp @@ -3252,8 +3252,7 @@ nsXULDocument::OnStreamComplete(nsIStreamLoader* aLoader, NS_ASSERTION(global != nsnull, "master prototype w/o global?!"); if (global) { - nsCOMPtr scriptContext; - global->GetContext(getter_AddRefs(scriptContext)); + nsIScriptContext *scriptContext = global->GetContext(); if (scriptContext) scriptProto->SerializeOutOfLine(nsnull, scriptContext); } @@ -3303,19 +3302,14 @@ nsXULDocument::ExecuteScript(JSObject* aScriptObject) return NS_ERROR_NULL_POINTER; // Execute the precompiled script with the given version - nsresult rv; + nsresult rv = NS_ERROR_UNEXPECTED; NS_ASSERTION(mScriptGlobalObject != nsnull, "no script global object"); - if (! mScriptGlobalObject) - return NS_ERROR_UNEXPECTED; - nsCOMPtr context; - rv = mScriptGlobalObject->GetContext(getter_AddRefs(context)); - if (NS_FAILED(rv)) return rv; + nsIScriptContext *context; + if (mScriptGlobalObject && (context = mScriptGlobalObject->GetContext())) + rv = context->ExecuteScript(aScriptObject, nsnull, nsnull, nsnull); - if (! context) return NS_ERROR_UNEXPECTED; - - rv = context->ExecuteScript(aScriptObject, nsnull, nsnull, nsnull); return rv; } diff --git a/content/xul/document/src/nsXULPrototypeDocument.cpp b/content/xul/document/src/nsXULPrototypeDocument.cpp index 5d6b04690a8..43202f0ab7a 100644 --- a/content/xul/document/src/nsXULPrototypeDocument.cpp +++ b/content/xul/document/src/nsXULPrototypeDocument.cpp @@ -85,24 +85,24 @@ public: NS_DECL_ISUPPORTS // nsIScriptGlobalObject methods - NS_IMETHOD SetContext(nsIScriptContext *aContext); - NS_IMETHOD GetContext(nsIScriptContext **aContext); - NS_IMETHOD SetNewDocument(nsIDOMDocument *aDocument, - PRBool aRemoveEventListeners, - PRBool aClearScope); - NS_IMETHOD SetDocShell(nsIDocShell *aDocShell); - NS_IMETHOD GetDocShell(nsIDocShell **aDocShell); - NS_IMETHOD SetOpenerWindow(nsIDOMWindowInternal *aOpener); - NS_IMETHOD SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner); - NS_IMETHOD GetGlobalObjectOwner(nsIScriptGlobalObjectOwner** aOwner); - NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext, - nsEvent* aEvent, - nsIDOMEvent** aDOMEvent, - PRUint32 aFlags, - nsEventStatus* aEventStatus); - NS_IMETHOD_(JSObject *) GetGlobalJSObject(); - NS_IMETHOD OnFinalize(JSObject *aObject); - NS_IMETHOD SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts); + virtual void SetContext(nsIScriptContext *aContext); + virtual nsIScriptContext *GetContext(); + virtual nsresult SetNewDocument(nsIDOMDocument *aDocument, + PRBool aRemoveEventListeners, + PRBool aClearScope); + virtual void SetDocShell(nsIDocShell *aDocShell); + virtual nsIDocShell *GetDocShell(); + virtual void SetOpenerWindow(nsIDOMWindowInternal *aOpener); + virtual void SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner); + virtual nsIScriptGlobalObjectOwner *GetGlobalObjectOwner(); + virtual nsresult HandleDOMEvent(nsIPresContext* aPresContext, + nsEvent* aEvent, + nsIDOMEvent** aDOMEvent, + PRUint32 aFlags, + nsEventStatus* aEventStatus); + virtual JSObject *GetGlobalJSObject(); + virtual void OnFinalize(JSObject *aObject); + virtual void SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts); // nsIScriptObjectPrincipal methods NS_IMETHOD GetPrincipal(nsIPrincipal** aPrincipal); @@ -406,8 +406,7 @@ nsXULPrototypeDocument::Read(nsIObjectInputStream* aStream) if (! mRoot) return NS_ERROR_OUT_OF_MEMORY; - nsCOMPtr scriptContext; - rv |= mGlobalObject->GetContext(getter_AddRefs(scriptContext)); + nsIScriptContext *scriptContext = mGlobalObject->GetContext(); NS_ASSERTION(scriptContext != nsnull, "no prototype script context!"); @@ -500,10 +499,9 @@ nsXULPrototypeDocument::Write(nsIObjectOutputStream* aStream) // Now serialize the document contents nsCOMPtr globalObject; rv |= GetScriptGlobalObject(getter_AddRefs(globalObject)); - - nsCOMPtr scriptContext; - rv |= globalObject->GetContext(getter_AddRefs(scriptContext)); - + + nsIScriptContext *scriptContext = globalObject->GetContext(); + if (mRoot) rv |= mRoot->Serialize(aStream, scriptContext, &nodeInfos); @@ -791,34 +789,33 @@ NS_INTERFACE_MAP_END // nsIScriptGlobalObject methods // -NS_IMETHODIMP +void nsXULPDGlobalObject::SetContext(nsIScriptContext *aContext) { mScriptContext = aContext; - return NS_OK; } -NS_IMETHODIMP -nsXULPDGlobalObject::GetContext(nsIScriptContext **aContext) +nsIScriptContext * +nsXULPDGlobalObject::GetContext() { // This whole fragile mess is predicated on the fact that // GetContext() will be called before GetScriptObject() is. if (! mScriptContext) { nsCOMPtr factory = do_GetService(kDOMScriptObjectFactoryCID); - NS_ENSURE_TRUE(factory, NS_ERROR_FAILURE); + NS_ENSURE_TRUE(factory, nsnull); nsresult rv = factory->NewScriptContext(nsnull, getter_AddRefs(mScriptContext)); if (NS_FAILED(rv)) - return rv; + return nsnull; JSContext *cx = (JSContext *)mScriptContext->GetNativeContext(); mJSObject = ::JS_NewObject(cx, &gSharedGlobalClass, nsnull, nsnull); if (!mJSObject) - return NS_ERROR_OUT_OF_MEMORY; + return nsnull; ::JS_SetGlobalObject(cx, mJSObject); @@ -828,13 +825,11 @@ nsXULPDGlobalObject::GetContext(nsIScriptContext **aContext) NS_ADDREF(this); } - *aContext = mScriptContext; - NS_IF_ADDREF(*aContext); - return NS_OK; + return mScriptContext; } -NS_IMETHODIMP +nsresult nsXULPDGlobalObject::SetNewDocument(nsIDOMDocument *aDocument, PRBool aRemoveEventListeners, PRBool aClearScope) @@ -844,48 +839,44 @@ nsXULPDGlobalObject::SetNewDocument(nsIDOMDocument *aDocument, } -NS_IMETHODIMP +void nsXULPDGlobalObject::SetDocShell(nsIDocShell *aDocShell) { NS_NOTREACHED("waaah!"); - return NS_ERROR_UNEXPECTED; } -NS_IMETHODIMP -nsXULPDGlobalObject::GetDocShell(nsIDocShell **aDocShell) +nsIDocShell * +nsXULPDGlobalObject::GetDocShell() { NS_WARNING("waaah!"); - return NS_ERROR_UNEXPECTED; + + return nsnull; } -NS_IMETHODIMP +void nsXULPDGlobalObject::SetOpenerWindow(nsIDOMWindowInternal *aOpener) { NS_NOTREACHED("waaah!"); - return NS_ERROR_UNEXPECTED; } -NS_IMETHODIMP +void nsXULPDGlobalObject::SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner) { mGlobalObjectOwner = aOwner; // weak reference - return NS_OK; } -NS_IMETHODIMP -nsXULPDGlobalObject::GetGlobalObjectOwner(nsIScriptGlobalObjectOwner** aOwner) +nsIScriptGlobalObjectOwner * +nsXULPDGlobalObject::GetGlobalObjectOwner() { - *aOwner = mGlobalObjectOwner; - NS_IF_ADDREF(*aOwner); - return NS_OK; + return mGlobalObjectOwner; } -NS_IMETHODIMP +nsresult nsXULPDGlobalObject::HandleDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent, nsIDOMEvent** aDOMEvent, @@ -896,7 +887,7 @@ nsXULPDGlobalObject::HandleDOMEvent(nsIPresContext* aPresContext, return NS_ERROR_UNEXPECTED; } -NS_IMETHODIMP_(JSObject *) +JSObject * nsXULPDGlobalObject::GetGlobalJSObject() { // The prototype document has its own special secret script object @@ -913,22 +904,18 @@ nsXULPDGlobalObject::GetGlobalJSObject() return ::JS_GetGlobalObject(cx); } -NS_IMETHODIMP +void nsXULPDGlobalObject::OnFinalize(JSObject *aObject) { NS_ASSERTION(aObject == mJSObject, "Wrong object finalized!"); mJSObject = nsnull; - - return NS_OK; } -NS_IMETHODIMP +void nsXULPDGlobalObject::SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts) { // We don't care... - - return NS_OK; } diff --git a/content/xul/templates/src/nsXULTemplateBuilder.cpp b/content/xul/templates/src/nsXULTemplateBuilder.cpp index 8f3137522bd..d2b908ba33c 100644 --- a/content/xul/templates/src/nsXULTemplateBuilder.cpp +++ b/content/xul/templates/src/nsXULTemplateBuilder.cpp @@ -790,8 +790,7 @@ nsXULTemplateBuilder::InitHTMLTemplateRoot() if (! global) return NS_ERROR_UNEXPECTED; - nsCOMPtr context; - global->GetContext(getter_AddRefs(context)); + nsIScriptContext *context = global->GetContext(); if (! context) return NS_ERROR_UNEXPECTED; diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index d96188e976b..ffbfa3f0b3b 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -1096,10 +1096,12 @@ nsresult nsDocShell::FindTarget(const PRUnichar *aWindowTarget, if (NS_FAILED(rv)) return rv; // This will AddRef() aResult... - rv = sgo->GetDocShell(aResult); + *aResult = sgo->GetDocShell(); // If all went well, indicate that a new window has been created. if (*aResult) { + NS_ADDREF(*aResult); + *aIsNewWindow = PR_TRUE; // if we just open a new window for this link, charset from current docshell diff --git a/dom/public/Makefile.in b/dom/public/Makefile.in index af63a7bebe7..6bdda10879a 100644 --- a/dom/public/Makefile.in +++ b/dom/public/Makefile.in @@ -41,7 +41,6 @@ EXPORTS=nsIScriptContext.h \ nsIScriptObjectOwner.h \ nsIScriptObjectPrincipal.h \ nsIScriptGlobalObject.h \ - nsIScriptEventListener.h \ nsIDOMScriptObjectFactory.h \ nsDOMCID.h \ nsIScriptExternalNameSet.h \ diff --git a/dom/public/coreEvents/nsIDOMEventReceiver.h b/dom/public/coreEvents/nsIDOMEventReceiver.h index 6a6d0dc761e..dad2101aa5a 100644 --- a/dom/public/coreEvents/nsIDOMEventReceiver.h +++ b/dom/public/coreEvents/nsIDOMEventReceiver.h @@ -42,12 +42,6 @@ #include "nsIDOMEventTarget.h" class nsIDOMEventListener; -class nsIDOMMouseListener; -class nsIDOMMouseMotionListener; -class nsIDOMKeyListener; -class nsIDOMFocusListener; -class nsIDOMLoadListener; -class nsIDOMDragListener; class nsIEventListenerManager; class nsIDOMEvent; class nsIDOMEventGroup; diff --git a/dom/public/nsIJSEventListener.h b/dom/public/nsIJSEventListener.h index 3bdd16c1056..60ee6f7777c 100644 --- a/dom/public/nsIJSEventListener.h +++ b/dom/public/nsIJSEventListener.h @@ -39,9 +39,8 @@ #ifndef nsIJSEventListener_h__ #define nsIJSEventListener_h__ -#include "nsISupports.h" +#include "nsIScriptContext.h" -class nsIScriptContext; class nsIScriptObjectOwner; class nsIDOMEventListener; class nsIAtom; @@ -52,13 +51,42 @@ class nsIAtom; // Implemented by JS event listeners. Used to retrieve the // JSObject corresponding to the event target. -class nsIJSEventListener : public nsISupports { +class nsIJSEventListener : public nsISupports +{ public: NS_DEFINE_STATIC_IID_ACCESSOR(NS_IJSEVENTLISTENER_IID) - NS_IMETHOD GetEventTarget(nsIScriptContext** aContext, - nsISupports** aTarget) = 0; - NS_IMETHOD SetEventName(nsIAtom* aName) = 0; + nsIJSEventListener(nsIScriptContext *aContext, nsISupports *aTarget) + : mContext(aContext), mTarget(aTarget) + { + // 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__ diff --git a/dom/public/nsIScriptContext.h b/dom/public/nsIScriptContext.h index b171324c02d..e1cc306ea32 100644 --- a/dom/public/nsIScriptContext.h +++ b/dom/public/nsIScriptContext.h @@ -65,7 +65,8 @@ typedef void (*nsScriptTerminationFunc)(nsISupports* aRef); * should be removed in a short time. Ideally this interface will be * language neutral */ -class nsIScriptContext : public nsISupports { +class nsIScriptContext : public nsISupports +{ public: NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISCRIPTCONTEXT_IID) @@ -86,23 +87,23 @@ public: * @return NS_OK if the script was valid and got executed * **/ - NS_IMETHOD EvaluateString(const nsAString& aScript, - void *aScopeObject, - nsIPrincipal *aPrincipal, - const char *aURL, - PRUint32 aLineNo, - const char* aVersion, - nsAString& aRetValue, - PRBool* aIsUndefined) = 0; + virtual nsresult EvaluateString(const nsAString& aScript, + void *aScopeObject, + nsIPrincipal *aPrincipal, + const char *aURL, + PRUint32 aLineNo, + const char* aVersion, + nsAString& aRetValue, + PRBool* aIsUndefined) = 0; - NS_IMETHOD EvaluateStringWithValue(const nsAString& aScript, - void *aScopeObject, - nsIPrincipal *aPrincipal, - const char *aURL, - PRUint32 aLineNo, - const char* aVersion, - void* aRetValue, - PRBool* aIsUndefined) = 0; + virtual nsresult EvaluateStringWithValue(const nsAString& aScript, + void *aScopeObject, + nsIPrincipal *aPrincipal, + const char *aURL, + PRUint32 aLineNo, + const char* aVersion, + void* aRetValue, + PRBool* aIsUndefined) = 0; /** * Compile a script. @@ -122,14 +123,14 @@ public: * @return NS_OK if the script source was valid and got compiled * **/ - NS_IMETHOD CompileScript(const PRUnichar* aText, - PRInt32 aTextLength, - void* aScopeObject, - nsIPrincipal* aPrincipal, - const char* aURL, - PRUint32 aLineNo, - const char* aVersion, - void** aScriptObject) = 0; + virtual nsresult CompileScript(const PRUnichar* aText, + PRInt32 aTextLength, + void* aScopeObject, + nsIPrincipal* aPrincipal, + const char* aURL, + PRUint32 aLineNo, + const char* aVersion, + void** aScriptObject) = 0; /** * Execute a precompiled script object. @@ -145,10 +146,10 @@ public: * @return NS_OK if the script was valid and got executed * */ - NS_IMETHOD ExecuteScript(void* aScriptObject, - void* aScopeObject, - nsAString* aRetValue, - PRBool* aIsUndefined) = 0; + virtual nsresult ExecuteScript(void* aScriptObject, + void* aScopeObject, + nsAString* aRetValue, + PRBool* aIsUndefined) = 0; /** * Compile the event handler named by atom aName, with function body aBody @@ -174,13 +175,13 @@ public: * * @return NS_OK if the function body was valid and got compiled */ - NS_IMETHOD CompileEventHandler(void* aTarget, - nsIAtom* aName, - const nsAString& aBody, - const char* aURL, - PRUint32 aLineNo, - PRBool aShared, - void** aHandler) = 0; + virtual nsresult CompileEventHandler(void* aTarget, + nsIAtom* aName, + const nsAString& aBody, + const char* aURL, + PRUint32 aLineNo, + PRBool aShared, + void** aHandler) = 0; /** * Call the function object with given args and return its boolean result, @@ -194,9 +195,9 @@ public: * @param aBoolResult out parameter returning boolean function result, or * true if the result was not boolean. **/ - NS_IMETHOD CallEventHandler(void* aTarget, void* aHandler, - PRUint32 argc, void* argv, - PRBool* aBoolResult) = 0; + virtual nsresult CallEventHandler(void* aTarget, void* aHandler, + PRUint32 argc, void* argv, + PRBool* aBoolResult) = 0; /** * Bind an already-compiled event handler function to a name in the given @@ -214,19 +215,19 @@ public: * CompileEventHandler * @return NS_OK if the function was successfully bound to the name */ - NS_IMETHOD BindCompiledEventHandler(void* aTarget, - nsIAtom* aName, - void* aHandler) = 0; + virtual nsresult BindCompiledEventHandler(void* aTarget, + nsIAtom* aName, + void* aHandler) = 0; - NS_IMETHOD CompileFunction(void* aTarget, - const nsACString& aName, - PRUint32 aArgCount, - const char** aArgArray, - const nsAString& aBody, - const char* aURL, - PRUint32 aLineNo, - PRBool aShared, - void** aFunctionObject) = 0; + virtual nsresult CompileFunction(void* aTarget, + const nsACString& aName, + PRUint32 aArgCount, + const char** aArgArray, + const nsAString& aBody, + const char* aURL, + PRUint32 aLineNo, + PRBool aShared, + void** aFunctionObject) = 0; /** @@ -234,19 +235,19 @@ public: * 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. * **/ - NS_IMETHOD GetGlobalObject(nsIScriptGlobalObject** aGlobalObject) = 0; + virtual nsIScriptGlobalObject *GetGlobalObject() = 0; /** * Return the native script context * **/ - NS_IMETHOD_(void*) GetNativeContext() = 0; + virtual void *GetNativeContext() = 0; /** * Init this context. @@ -256,16 +257,16 @@ public: * @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 * 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. @@ -273,13 +274,7 @@ public: * * @return NS_OK if the method is successful */ - NS_IMETHOD GC() = 0; - - /** - * Get the security manager for this context. - * @return NS_OK if the method is successful - */ - NS_IMETHOD GetSecurityManager(nsIScriptSecurityManager** aInstancePtr) = 0; + virtual void GC() = 0; /** * Inform the context that a script was evaluated. @@ -293,7 +288,7 @@ public: * calls to the termination function. * @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. @@ -301,7 +296,7 @@ public: * will be told when the owner goes away. * @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 @@ -309,7 +304,7 @@ public: * XPCOM rules, even though the internal reference itself * 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 @@ -317,47 +312,42 @@ public: * of script state needs to be happen, but should be deferred till * the end of script evaluation. */ - NS_IMETHOD SetTerminationFunction(nsScriptTerminationFunc aFunc, - nsISupports* aRef) = 0; + virtual void SetTerminationFunction(nsScriptTerminationFunc aFunc, + nsISupports* aRef) = 0; /** * Called to disable/enable script execution in this context. */ - NS_IMETHOD GetScriptsEnabled(PRBool *aEnabled) = 0; - NS_IMETHOD SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts) = 0; + virtual PRBool GetScriptsEnabled() = 0; + virtual void SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts) = 0; /** * Called to set/get information if the script context is * currently processing a script tag */ - NS_IMETHOD GetProcessingScriptTag(PRBool * aResult) =0; - NS_IMETHOD SetProcessingScriptTag(PRBool aResult) =0; + virtual PRBool GetProcessingScriptTag() = 0; + virtual void SetProcessingScriptTag(PRBool aResult) = 0; /** * Tell the context whether or not to GC when destroyed. */ - NS_IMETHOD SetGCOnDestruction(PRBool aGCOnDestruction) = 0; + virtual void SetGCOnDestruction(PRBool aGCOnDestruction) = 0; }; -inline nsresult -GetScriptContextFromJSContext(JSContext *cx, nsIScriptContext **result) +inline nsIScriptContext * +GetScriptContextFromJSContext(JSContext *cx) { - *result = nsnull; - if (!(::JS_GetOptions(cx) & JSOPTION_PRIVATE_IS_NSISUPPORTS)) { - return NS_ERROR_INVALID_ARG; + return nsnull; } - nsresult rv = NS_OK; + nsCOMPtr scx = + do_QueryInterface(NS_STATIC_CAST(nsISupports *, + ::JS_GetContextPrivate(cx))); - nsISupports *supports = - NS_STATIC_CAST(nsISupports *, ::JS_GetContextPrivate(cx)); - - if (supports) { - rv = CallQueryInterface(supports, result); - } - - return rv; + // This will return a pointer to something that's about to be + // released, but that's ok here. + return scx; } #endif // nsIScriptContext_h__ diff --git a/dom/public/nsIScriptContextOwner.idl b/dom/public/nsIScriptContextOwner.idl index 471ed4ddaee..d2b806a6217 100644 --- a/dom/public/nsIScriptContextOwner.idl +++ b/dom/public/nsIScriptContextOwner.idl @@ -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 * License Version 1.1 (the "License"); you may not use this file @@ -61,8 +61,7 @@ interface nsIScriptContextOwner : nsISupports /** * Error notification method. Informs the owner that an error * occurred while a script was being evaluted. - * */ void reportScriptError(in string aErrorString, in string aFileName, - in long aLineNo, in string aLineBuf); + in long aLineNo, in string aLineBuf); }; diff --git a/dom/public/nsIScriptGlobalObject.h b/dom/public/nsIScriptGlobalObject.h index 61b4835362c..29ae5391c14 100644 --- a/dom/public/nsIScriptGlobalObject.h +++ b/dom/public/nsIScriptGlobalObject.h @@ -60,18 +60,19 @@ struct JSObject; * per-window global state. */ -class nsIScriptGlobalObject : public nsISupports { +class nsIScriptGlobalObject : public nsISupports +{ public: NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISCRIPTGLOBALOBJECT_IID) - NS_IMETHOD SetContext(nsIScriptContext *aContext) = 0; - NS_IMETHOD GetContext(nsIScriptContext **aContext) = 0; - NS_IMETHOD SetNewDocument(nsIDOMDocument *aDocument, + virtual void SetContext(nsIScriptContext *aContext) = 0; + virtual nsIScriptContext *GetContext() = 0; + virtual nsresult SetNewDocument(nsIDOMDocument *aDocument, PRBool aRemoveEventListeners, PRBool aClearScope) = 0; - NS_IMETHOD SetDocShell(nsIDocShell *aDocShell) = 0; - NS_IMETHOD GetDocShell(nsIDocShell **aDocShell) = 0; - NS_IMETHOD SetOpenerWindow(nsIDOMWindowInternal *aOpener)=0; + virtual void SetDocShell(nsIDocShell *aDocShell) = 0; + virtual nsIDocShell *GetDocShell() = 0; + virtual void SetOpenerWindow(nsIDOMWindowInternal *aOpener)=0; /** * Let the script global object know who its owner is. @@ -79,7 +80,7 @@ public: * will be told when the owner goes away. * @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 @@ -87,26 +88,26 @@ public: * XPCOM rules, even though the internal reference itself * is a "weak" reference. */ - NS_IMETHOD GetGlobalObjectOwner(nsIScriptGlobalObjectOwner** aOwner) = 0; + virtual nsIScriptGlobalObjectOwner *GetGlobalObjectOwner() = 0; - NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext, - nsEvent* aEvent, - nsIDOMEvent** aDOMEvent, - PRUint32 aFlags, - nsEventStatus* aEventStatus)=0; + virtual nsresult HandleDOMEvent(nsIPresContext* aPresContext, + nsEvent* aEvent, + nsIDOMEvent** aDOMEvent, + PRUint32 aFlags, + nsEventStatus* aEventStatus)=0; - NS_IMETHOD_(JSObject *) GetGlobalJSObject() = 0; + virtual JSObject *GetGlobalJSObject() = 0; /** * 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. */ - NS_IMETHOD SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts) = 0; + virtual void SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts) = 0; }; #endif diff --git a/dom/public/nsIScriptObjectOwner.h b/dom/public/nsIScriptObjectOwner.h index ace8e6f9747..603d9534457 100644 --- a/dom/public/nsIScriptObjectOwner.h +++ b/dom/public/nsIScriptObjectOwner.h @@ -116,13 +116,13 @@ public: * @param aLineNo the starting line number of the script for error messages * @param aHandler the compiled, bound handler object */ - NS_IMETHOD CompileEventHandler(nsIScriptContext* aContext, - void* aTarget, - nsIAtom *aName, - const nsAString& aBody, - const char* aURL, - PRUint32 aLineNo, - void** aHandler) = 0; + virtual nsresult CompileEventHandler(nsIScriptContext* aContext, + void* aTarget, + nsIAtom *aName, + const nsAString& aBody, + const char* aURL, + PRUint32 aLineNo, + void** aHandler) = 0; /** * Retrieve an already-compiled event handler that can be bound to a @@ -131,7 +131,8 @@ public: * @param aName the name of the event handler to retrieve * @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__ diff --git a/dom/src/base/nsBarProps.cpp b/dom/src/base/nsBarProps.cpp index 7d564c92d69..1e70798a492 100644 --- a/dom/src/base/nsBarProps.cpp +++ b/dom/src/base/nsBarProps.cpp @@ -278,14 +278,13 @@ ScrollbarsPropImpl::~ScrollbarsPropImpl() NS_IMETHODIMP ScrollbarsPropImpl::GetVisible(PRBool *aVisible) { - NS_ENSURE_ARG_POINTER(aVisible); *aVisible = PR_TRUE; // one assumes nsCOMPtr domwin(do_QueryReferent(mDOMWindowWeakref)); if (domwin) { // dom window not deleted - nsCOMPtr docshell; - mDOMWindow->GetDocShell(getter_AddRefs(docshell)); - nsCOMPtr scroller(do_QueryInterface(docshell)); + nsCOMPtr scroller = + do_QueryInterface(mDOMWindow->GetDocShell()); + if (scroller) { PRInt32 prefValue = aVisible ? NS_STYLE_OVERFLOW_AUTO : NS_STYLE_OVERFLOW_HIDDEN; @@ -315,9 +314,9 @@ ScrollbarsPropImpl::SetVisible(PRBool aVisible) nsCOMPtr domwin(do_QueryReferent(mDOMWindowWeakref)); if (domwin) { // dom window must still exist. use away. - nsCOMPtr docshell; - mDOMWindow->GetDocShell(getter_AddRefs(docshell)); - nsCOMPtr scroller(do_QueryInterface(docshell)); + nsCOMPtr scroller = + do_QueryInterface(mDOMWindow->GetDocShell()); + if (scroller) { PRInt32 prefValue = aVisible ? NS_STYLE_OVERFLOW_AUTO : NS_STYLE_OVERFLOW_HIDDEN; diff --git a/dom/src/base/nsDOMClassInfo.cpp b/dom/src/base/nsDOMClassInfo.cpp index c947cd2bc74..19f07181ca9 100644 --- a/dom/src/base/nsDOMClassInfo.cpp +++ b/dom/src/base/nsDOMClassInfo.cpp @@ -2965,8 +2965,7 @@ needsSecurityCheck(JSContext *cx, nsIXPConnectWrappedNative *wrapper) return PR_TRUE; } - nsCOMPtr otherScriptContext; - sgo->GetContext(getter_AddRefs(otherScriptContext)); + nsIScriptContext *otherScriptContext = sgo->GetContext(); if (!otherScriptContext) { return PR_TRUE; @@ -3055,10 +3054,9 @@ nsDOMClassInfo::doCheckPropertyAccess(JSContext *cx, JSObject *obj, jsval id, } } - nsCOMPtr scx; - sgo->GetContext(getter_AddRefs(scx)); + nsIScriptContext *scx = sgo->GetContext(); - if (!scx || NS_FAILED(scx->IsContextInitialized())) { + if (!scx || !scx->IsContextInitialized()) { return NS_OK; } @@ -3224,11 +3222,7 @@ nsWindowSH::SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx, nsresult rv = window->GetLocation(getter_AddRefs(location)); NS_ENSURE_SUCCESS(rv, rv); - nsDependentString href(NS_REINTERPRET_CAST(PRUnichar *, - ::JS_GetStringChars(val)), - ::JS_GetStringLength(val)); - - rv = location->SetHref(href); + rv = location->SetHref(nsDependentJSString(val)); NS_ENSURE_SUCCESS(rv, rv); return WrapNative(cx, obj, location, NS_GET_IID(nsIDOMLocation), vp); @@ -3331,9 +3325,7 @@ BaseStubConstructor(const nsGlobalNameStruct *name_struct, JSContext *cx, nsCOMPtr owner(do_QueryInterface(native)); if (owner) { - nsCOMPtr context; - - nsJSUtils::GetStaticScriptContext(cx, obj, getter_AddRefs(context)); + nsIScriptContext *context = nsJSUtils::GetStaticScriptContext(cx, obj); if (!context) { 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); - nsDependentString name(NS_REINTERPRET_CAST(const PRUnichar*, - ::JS_GetStringChars(str)), - ::JS_GetStringLength(str)); + nsDependentJSString name(str); const nsGlobalNameStruct *name_struct = nsnull; const PRUnichar *class_name = nsnull; @@ -4015,8 +4005,7 @@ nsWindowSH::GlobalResolve(nsISupports *native, JSContext *cx, JSObject *obj, nsCOMPtr owner(do_QueryInterface(native)); if (owner) { - nsCOMPtr context; - nsJSUtils::GetStaticScriptContext(cx, obj, getter_AddRefs(context)); + nsIScriptContext *context = nsJSUtils::GetStaticScriptContext(cx, obj); NS_ENSURE_TRUE(context, NS_ERROR_UNEXPECTED); JSObject *prop_obj = nsnull; @@ -4048,9 +4037,7 @@ nsWindowSH::GlobalResolve(nsISupports *native, JSContext *cx, JSObject *obj, nsCOMPtr sgo(do_QueryInterface(native)); NS_ENSURE_TRUE(sgo, NS_ERROR_UNEXPECTED); - nsCOMPtr context; - - sgo->GetContext(getter_AddRefs(context)); + nsIScriptContext *context = sgo->GetContext(); NS_ENSURE_TRUE(context, NS_ERROR_UNEXPECTED); rv = nameset->InitializeNameSet(context); @@ -4092,17 +4079,15 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx, JSObject **objp, PRBool *_retval) { if (JSVAL_IS_STRING(id)) { - JSString *str = JSVAL_TO_STRING(id); nsCOMPtr native; wrapper->GetNative(getter_AddRefs(native)); nsCOMPtr sgo(do_QueryInterface(native)); NS_ENSURE_TRUE(sgo, NS_ERROR_UNEXPECTED); - nsCOMPtr my_context; - sgo->GetContext(getter_AddRefs(my_context)); + nsIScriptContext *my_context = sgo->GetContext(); - 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 // here yet. @@ -4148,10 +4133,9 @@ nsWindowSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx, // method on an interface that would let us just call into the // window code directly... - nsCOMPtr docShell; - sgo->GetDocShell(getter_AddRefs(docShell)); + JSString *str = JSVAL_TO_STRING(id); - nsCOMPtr dsn(do_QueryInterface(docShell)); + nsCOMPtr dsn(do_QueryInterface(sgo->GetDocShell())); PRInt32 count = 0; @@ -4404,7 +4388,9 @@ nsWindowSH::Finalize(nsIXPConnectWrappedNative *wrapper, JSContext *cx, nsCOMPtr sgo(do_QueryInterface(native)); 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; } - nsCOMPtr script_cx; - nsresult rv = nsJSUtils::GetStaticScriptContext(cx, obj, - getter_AddRefs(script_cx)); - NS_ENSURE_SUCCESS(rv, rv); + nsIScriptContext *script_cx = nsJSUtils::GetStaticScriptContext(cx, obj); + NS_ENSURE_TRUE(script_cx, NS_ERROR_UNEXPECTED); nsCOMPtr native; wrapper->GetNative(getter_AddRefs(native)); @@ -4662,13 +4646,11 @@ nsEventReceiverSH::RegisterCompileHandler(nsIXPConnectWrappedNative *wrapper, receiver->GetListenerManager(getter_AddRefs(manager)); NS_ENSURE_TRUE(manager, NS_ERROR_UNEXPECTED); - JSString *str = JSVAL_TO_STRING(id); - const PRUnichar *ustr = NS_REINTERPRET_CAST(const PRUnichar *, - ::JS_GetStringChars(str)); - - nsCOMPtr atom(do_GetAtom(ustr)); + nsCOMPtr atom(do_GetAtom(nsDependentJSString(id))); NS_ENSURE_TRUE(atom, NS_ERROR_OUT_OF_MEMORY); + nsresult rv; + if (compile) { rv = manager->CompileScriptEventListener(script_cx, native, atom, did_compile); @@ -4936,13 +4918,8 @@ nsNamedArraySH::GetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx, wrapper->GetNative(getter_AddRefs(native)); nsCOMPtr item; - - JSString *str = JSVAL_TO_STRING(id); - nsDependentString name(NS_REINTERPRET_CAST(const PRUnichar *, - ::JS_GetStringChars(str)), - ::JS_GetStringLength(str)); - - nsresult rv = GetNamedItem(native, name, getter_AddRefs(item)); + nsresult rv = GetNamedItem(native, nsDependentJSString(id), + getter_AddRefs(item)); NS_ENSURE_SUCCESS(rv, rv); if (item) { @@ -5300,11 +5277,7 @@ nsDocumentSH::SetProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx, JSString *val = ::JS_ValueToString(cx, *vp); NS_ENSURE_TRUE(val, NS_ERROR_UNEXPECTED); - nsDependentString href(NS_REINTERPRET_CAST(const PRUnichar *, - ::JS_GetStringChars(val)), - ::JS_GetStringLength(val)); - - nsresult rv = location->SetHref(href); + nsresult rv = location->SetHref(nsDependentJSString(val)); NS_ENSURE_SUCCESS(rv, rv); return WrapNative(cx, obj, location, NS_GET_IID(nsIDOMLocation), vp); @@ -5343,12 +5316,9 @@ nsHTMLDocumentSH::ResolveImpl(JSContext *cx, // should map to . Thus we can't use // JSVAL_TO_STRING() here. JSString *str = JS_ValueToString(cx, id); + NS_ENSURE_TRUE(str, NS_ERROR_UNEXPECTED); - const nsDependentString name(NS_REINTERPRET_CAST(const PRUnichar *, - ::JS_GetStringChars(str)), - ::JS_GetStringLength(str)); - - return doc->ResolveName(name, nsnull, result); + return doc->ResolveName(nsDependentJSString(str), nsnull, result); } // static @@ -5533,9 +5503,7 @@ nsHTMLFormElementSH::FindNamedItem(nsIForm *aForm, JSString *str, { *aResult = nsnull; - nsDependentString name(NS_REINTERPRET_CAST(const PRUnichar *, - ::JS_GetStringChars(str)), - ::JS_GetStringLength(str)); + nsDependentJSString name(str); aForm->ResolveName(name, aResult); diff --git a/dom/src/base/nsFocusController.cpp b/dom/src/base/nsFocusController.cpp index f8ae3244201..63eb1e67b49 100644 --- a/dom/src/base/nsFocusController.cpp +++ b/dom/src/base/nsFocusController.cpp @@ -136,9 +136,7 @@ nsFocusController::SetFocusedWindow(nsIDOMWindowInternal* aWindow) if (aWindow && (mCurrentWindow != aWindow)) { nsCOMPtr sgo = do_QueryInterface(aWindow); if (sgo) { - nsCOMPtr docShell; - sgo->GetDocShell(getter_AddRefs(docShell)); - nsCOMPtr basewin = do_QueryInterface(docShell); + nsCOMPtr basewin = do_QueryInterface(sgo->GetDocShell()); if (basewin) basewin->SetFocus(); } @@ -513,11 +511,11 @@ nsFocusController::UpdateWWActiveWindow() // This gets the toplevel DOMWindow nsCOMPtr sgo = do_QueryInterface(mCurrentWindow); - nsCOMPtr docShell; - sgo->GetDocShell(getter_AddRefs(docShell)); - if (!docShell) return; - nsCOMPtr docShellAsItem(do_QueryInterface(docShell)); + nsCOMPtr docShellAsItem = + do_QueryInterface(sgo->GetDocShell()); + if (!docShellAsItem) return; + nsCOMPtr rootItem; docShellAsItem->GetRootTreeItem(getter_AddRefs(rootItem)); NS_ASSERTION(rootItem, "Invalid docshell tree - no root!"); diff --git a/dom/src/base/nsGlobalWindow.cpp b/dom/src/base/nsGlobalWindow.cpp index 8f5f87c2e83..cacd2940404 100644 --- a/dom/src/base/nsGlobalWindow.cpp +++ b/dom/src/base/nsGlobalWindow.cpp @@ -390,7 +390,7 @@ NS_IMPL_RELEASE(GlobalWindowImpl) // GlobalWindowImpl::nsIScriptGlobalObject //***************************************************************************** -NS_IMETHODIMP +void GlobalWindowImpl::SetContext(nsIScriptContext* aContext) { // 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; if (mContext) { - nsCOMPtr parent; - GetParentInternal(getter_AddRefs(parent)); - - if (parent) { + if (GetParentInternal()) { // 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 // frameset or host document is destroyed anyway. @@ -417,16 +414,12 @@ GlobalWindowImpl::SetContext(nsIScriptContext* aContext) mContext->SetGCOnDestruction(PR_FALSE); } } - - return NS_OK; } -NS_IMETHODIMP -GlobalWindowImpl::GetContext(nsIScriptContext ** aContext) +nsIScriptContext * +GlobalWindowImpl::GetContext() { - NS_IF_ADDREF(*aContext = mContext); - - return NS_OK; + return mContext; } NS_IMETHODIMP @@ -436,7 +429,7 @@ GlobalWindowImpl::SetOpenerScriptURL(nsIURI* aURI) return NS_OK; } -NS_IMETHODIMP +nsresult GlobalWindowImpl::SetNewDocument(nsIDOMDocument* aDocument, PRBool aRemoveEventListeners, PRBool aClearScopeHint) @@ -671,11 +664,11 @@ GlobalWindowImpl::SetNewDocument(nsIDOMDocument* aDocument, return NS_OK; } -NS_IMETHODIMP +void GlobalWindowImpl::SetDocShell(nsIDocShell* aDocShell) { if (aDocShell == mDocShell) - return NS_OK; + return; // SetDocShell(nsnull) means the window is being torn down. Drop our // 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)); } } - - return NS_OK; } -NS_IMETHODIMP -GlobalWindowImpl::GetDocShell(nsIDocShell ** aDocShell) +nsIDocShell * +GlobalWindowImpl::GetDocShell() { - NS_IF_ADDREF(*aDocShell = mDocShell); - - return NS_OK; + return mDocShell; } -NS_IMETHODIMP +void GlobalWindowImpl::SetOpenerWindow(nsIDOMWindowInternal* aOpener) { mOpener = aOpener; - return NS_OK; } -NS_IMETHODIMP +void GlobalWindowImpl::SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner) { mGlobalObjectOwner = aOwner; // Note this is supposed to be a weak ref. - return NS_OK; } -NS_IMETHODIMP -GlobalWindowImpl::GetGlobalObjectOwner(nsIScriptGlobalObjectOwner ** aOwner) +nsIScriptGlobalObjectOwner * +GlobalWindowImpl::GetGlobalObjectOwner() { - NS_ENSURE_ARG_POINTER(aOwner); - - NS_IF_ADDREF(*aOwner = mGlobalObjectOwner); - - return NS_OK; + return mGlobalObjectOwner; } -NS_IMETHODIMP +nsresult GlobalWindowImpl::HandleDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent, nsIDOMEvent** aDOMEvent, @@ -929,9 +912,6 @@ GlobalWindowImpl::HandleDOMEvent(nsIPresContext* aPresContext, if (aEvent->message == NS_PAGE_LOAD) { nsCOMPtr content(do_QueryInterface(mFrameElement)); - nsCOMPtr parent; - GetParentInternal(getter_AddRefs(parent)); - nsCOMPtr treeItem(do_QueryInterface(mDocShell)); PRInt32 itemType = nsIDocShellTreeItem::typeChrome; @@ -940,7 +920,8 @@ GlobalWindowImpl::HandleDOMEvent(nsIPresContext* aPresContext, 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 // onload event for the frame element. @@ -987,7 +968,7 @@ GlobalWindowImpl::GetGlobalJSObject() return mJSObject; } -NS_IMETHODIMP +void GlobalWindowImpl::OnFinalize(JSObject *aJSObject) { if (aJSObject == mJSObject) { @@ -997,11 +978,9 @@ GlobalWindowImpl::OnFinalize(JSObject *aJSObject) } else { NS_WARNING("Weird, we're finalized with a null mJSObject?"); } - - return NS_OK; } -NS_IMETHODIMP +void GlobalWindowImpl::SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts) { if (aEnabled && aFireTimeouts) { @@ -1010,8 +989,6 @@ GlobalWindowImpl::SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts) RunTimeout(nsnull); } - - return NS_OK; } @@ -1049,16 +1026,12 @@ GlobalWindowImpl::GetPrincipal(nsIPrincipal** result) // loading a frameset that has a , in // that case the global window is used in JS before we've loaded // a document into the window. - nsCOMPtr parent; - GetParentInternal(getter_AddRefs(parent)); + nsCOMPtr objPrincipal = + do_QueryInterface(GetParentInternal()); - if (parent) { - nsCOMPtr objPrincipal(do_QueryInterface(parent)); - - if (objPrincipal) { - return objPrincipal->GetPrincipal(result); - } + if (objPrincipal) { + return objPrincipal->GetPrincipal(result); } 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. nsCOMPtr openerSGO(do_QueryInterface(mOpener)); if (openerSGO) { - nsCOMPtr openerDocShell; - openerSGO->GetDocShell(getter_AddRefs(openerDocShell)); - nsCOMPtr docShellAsItem(do_QueryInterface(openerDocShell)); + nsCOMPtr docShellAsItem = + do_QueryInterface(openerSGO->GetDocShell()); + if (docShellAsItem) { nsCOMPtr 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 // via the DocShell tree, and if we are not already the root, // call SetFullScreen on that window instead. - nsCOMPtr docShell; - GetDocShell(getter_AddRefs(docShell)); - nsCOMPtr treeItem = do_QueryInterface(docShell); + nsCOMPtr treeItem = do_QueryInterface(mDocShell); nsCOMPtr rootItem; treeItem->GetRootTreeItem(getter_AddRefs(rootItem)); nsCOMPtr window = do_GetInterface(rootItem); @@ -3282,12 +3253,9 @@ GlobalWindowImpl::FireAbuseEvents(PRBool aBlocked, PRBool aWindow, JSContext *cx = nsnull; stack->Peek(&cx); if (cx) { - nsCOMPtr currentCX; - nsJSUtils::GetDynamicScriptContext(cx, getter_AddRefs(currentCX)); + nsIScriptContext *currentCX = nsJSUtils::GetDynamicScriptContext(cx); if (currentCX) { - nsCOMPtr gobj; - currentCX->GetGlobalObject(getter_AddRefs(gobj)); - contextWindow = do_QueryInterface(gobj); + contextWindow = do_QueryInterface(currentCX->GetGlobalObject()); } } } @@ -3654,13 +3622,13 @@ GlobalWindowImpl::Close() } if (cx) { - nsCOMPtr currentCX; - nsJSUtils::GetDynamicScriptContext(cx, getter_AddRefs(currentCX)); + nsIScriptContext *currentCX = nsJSUtils::GetDynamicScriptContext(cx); if (currentCX && currentCX == mContext) { - return currentCX->SetTerminationFunction(CloseWindow, - NS_STATIC_CAST(nsIDOMWindow *, - this)); + currentCX->SetTerminationFunction(CloseWindow, + NS_STATIC_CAST(nsIDOMWindow *, + this)); + return NS_OK; } } @@ -3710,10 +3678,7 @@ GlobalWindowImpl::GetFrameElement(nsIDOMElement** aFrameElement) { *aFrameElement = nsnull; - nsCOMPtr docShell; - GetDocShell(getter_AddRefs(docShell)); - - nsCOMPtr docShellTI(do_QueryInterface(docShell)); + nsCOMPtr docShellTI(do_QueryInterface(mDocShell)); if (!docShellTI) { return NS_OK; @@ -4361,11 +4326,11 @@ GlobalWindowImpl::GetPrivateRoot(nsIDOMWindowInternal ** aParent) GetTop(getter_AddRefs(parent)); nsCOMPtr parentTop = do_QueryInterface(parent); - nsCOMPtr docShell; NS_ASSERTION(parentTop, "cannot get parentTop"); if(parentTop == nsnull) 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 // 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 //***************************************************************************** -void -GlobalWindowImpl::GetParentInternal(nsIDOMWindowInternal **aParent) +nsIDOMWindowInternal * +GlobalWindowImpl::GetParentInternal() { - *aParent = nsnull; + nsIDOMWindowInternal *parentInternal = nsnull; nsCOMPtr parent; - GetParent(getter_AddRefs(parent)); if (parent && parent != NS_STATIC_CAST(nsIDOMWindow *, this)) { - CallQueryInterface(parent, aParent); - NS_ASSERTION(*aParent, "Huh, parent not an nsIDOMWindowInternal?"); + nsCOMPtr tmp(do_QueryInterface(parent)); + NS_ASSERTION(parent, "Huh, parent not an nsIDOMWindowInternal?"); + + parentInternal = tmp; } + + return parentInternal; } NS_IMETHODIMP @@ -5032,10 +5000,7 @@ GlobalWindowImpl::RunTimeout(nsTimeoutImpl *aTimeout) return; } - PRBool scripts_enabled = PR_TRUE; - mContext->GetScriptsEnabled(&scripts_enabled); - - if (!scripts_enabled) { + if (!mContext->GetScriptsEnabled()) { // Scripts were enabled once in this window (unless aTimeout == // nsnull) but now scripts are disabled (we might be in // print-preview, for instance), this means we shouldn't run any @@ -5313,11 +5278,11 @@ nsTimeoutImpl::Release(nsIScriptContext *aContext) return; if (mExpr || mFunObj) { - nsCOMPtr scx(aContext); + nsIScriptContext *scx = aContext; JSRuntime *rt = nsnull; if (!scx && mWindow) { - mWindow->GetContext(getter_AddRefs(scx)); + scx = mWindow->GetContext(); } if (scx) { @@ -5643,13 +5608,12 @@ GlobalWindowImpl::SecurityCheckURL(const char *aURL) nsIURI* baseURI = nsnull; nsCOMPtr uriToLoad; - nsCOMPtr scriptcx; - nsJSUtils::GetDynamicScriptContext(cx, getter_AddRefs(scriptcx)); + nsIScriptContext *scriptcx = nsJSUtils::GetDynamicScriptContext(cx); if (scriptcx) { - nsCOMPtr gobj; - scriptcx->GetGlobalObject(getter_AddRefs(gobj)); - nsCOMPtr caller(do_QueryInterface(gobj)); + nsCOMPtr caller = + do_QueryInterface(scriptcx->GetGlobalObject()); + if (caller) { nsCOMPtr callerDOMdoc; caller->GetDocument(getter_AddRefs(callerDOMdoc)); diff --git a/dom/src/base/nsGlobalWindow.h b/dom/src/base/nsGlobalWindow.h index f9939f022a8..68c160c93d0 100644 --- a/dom/src/base/nsGlobalWindow.h +++ b/dom/src/base/nsGlobalWindow.h @@ -130,22 +130,23 @@ public: NS_DECL_ISUPPORTS // nsIScriptGlobalObject - NS_IMETHOD SetContext(nsIScriptContext *aContext); - NS_IMETHOD GetContext(nsIScriptContext **aContext); - NS_IMETHOD SetNewDocument(nsIDOMDocument *aDocument, - PRBool aRemoveEventListeners, - PRBool aClearScopeHint); - NS_IMETHOD SetDocShell(nsIDocShell* aDocShell); - NS_IMETHOD GetDocShell(nsIDocShell** aDocShell); - NS_IMETHOD SetOpenerWindow(nsIDOMWindowInternal *aOpener); - NS_IMETHOD SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner); - NS_IMETHOD GetGlobalObjectOwner(nsIScriptGlobalObjectOwner** aOwner); - NS_IMETHOD HandleDOMEvent(nsIPresContext* aPresContext, nsEvent* aEvent, - nsIDOMEvent** aDOMEvent, PRUint32 aFlags, - nsEventStatus* aEventStatus); - NS_IMETHOD_(JSObject *) GetGlobalJSObject(); - NS_IMETHOD OnFinalize(JSObject *aJSObject); - NS_IMETHOD SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts); + virtual void SetContext(nsIScriptContext *aContext); + virtual nsIScriptContext *GetContext(); + virtual nsresult SetNewDocument(nsIDOMDocument *aDocument, + PRBool aRemoveEventListeners, + PRBool aClearScopeHint); + virtual void SetDocShell(nsIDocShell* aDocShell); + virtual nsIDocShell *GetDocShell(); + virtual void SetOpenerWindow(nsIDOMWindowInternal *aOpener); + virtual void SetGlobalObjectOwner(nsIScriptGlobalObjectOwner* aOwner); + virtual nsIScriptGlobalObjectOwner *GetGlobalObjectOwner(); + virtual nsresult HandleDOMEvent(nsIPresContext* aPresContext, + nsEvent* aEvent, nsIDOMEvent** aDOMEvent, + PRUint32 aFlags, + nsEventStatus* aEventStatus); + virtual JSObject *GetGlobalJSObject(); + virtual void OnFinalize(JSObject *aJSObject); + virtual void SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts); // nsIScriptObjectPrincipal NS_IMETHOD GetPrincipal(nsIPrincipal **prin); @@ -219,7 +220,7 @@ protected: void ClearControllers(); // Get the parent, returns null if this is a toplevel window - void GetParentInternal(nsIDOMWindowInternal **parent); + nsIDOMWindowInternal *GetParentInternal(); // Window Control Functions NS_IMETHOD OpenInternal(const nsAString& aUrl, @@ -488,7 +489,7 @@ public: NS_DECL_ISUPPORTS - NS_IMETHOD_(void) SetDocShell(nsIDocShell *aDocShell); + void SetDocShell(nsIDocShell *aDocShell); // nsIDOMLocation NS_DECL_NSIDOMLOCATION diff --git a/dom/src/base/nsGlobalWindowCommands.cpp b/dom/src/base/nsGlobalWindowCommands.cpp index 2f482650b04..92187a8412d 100644 --- a/dom/src/base/nsGlobalWindowCommands.cpp +++ b/dom/src/base/nsGlobalWindowCommands.cpp @@ -206,8 +206,7 @@ nsSelectionCommandsBase::GetPresShellFromWindow(nsIDOMWindow *aWindow, nsIPresSh nsCOMPtr sgo(do_QueryInterface(aWindow)); NS_ENSURE_TRUE(sgo, NS_ERROR_FAILURE); - nsCOMPtr docShell; - sgo->GetDocShell(getter_AddRefs(docShell)); + nsIDocShell *docShell = sgo->GetDocShell(); NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE); return docShell->GetPresShell(aPresShell); @@ -478,8 +477,7 @@ nsClipboardBaseCommand::GetContentViewerEditFromContext(nsISupports *aContext, nsCOMPtr sgo(do_QueryInterface(window)); NS_ENSURE_TRUE(sgo, NS_ERROR_FAILURE); - nsCOMPtr docShell; - sgo->GetDocShell(getter_AddRefs(docShell)); + nsIDocShell *docShell = sgo->GetDocShell(); NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE); nsCOMPtr viewer; @@ -834,9 +832,7 @@ nsClipboardDragDropHookCommand::DoCommandParams(const char *aCommandName, nsCOMPtr sgo = do_QueryInterface(window); NS_ENSURE_TRUE(sgo, NS_ERROR_FAILURE); - nsCOMPtr docShell; - sgo->GetDocShell(getter_AddRefs(docShell)); - NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE); + nsIDocShell *docShell = sgo->GetDocShell(); nsCOMPtr obj = do_GetInterface(docShell); if (!obj) return NS_ERROR_INVALID_ARG; diff --git a/dom/src/base/nsJSEnvironment.cpp b/dom/src/base/nsJSEnvironment.cpp index df056a99a70..90e655ddffd 100644 --- a/dom/src/base/nsJSEnvironment.cpp +++ b/dom/src/base/nsJSEnvironment.cpp @@ -141,14 +141,13 @@ NS_ScriptErrorReporter(JSContext *cx, const char *message, JSErrorReport *report) { - nsCOMPtr 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; - // XXX this means we are not going to get error reports on non DOM contexts - nsJSUtils::GetDynamicScriptContext(cx, getter_AddRefs(context)); if (context) { - nsCOMPtr globalObject; - context->GetGlobalObject(getter_AddRefs(globalObject)); + nsIScriptGlobalObject *globalObject = context->GetGlobalObject(); if (globalObject) { nsAutoString fileName, msg; @@ -168,34 +167,29 @@ NS_ScriptErrorReporter(JSContext *cx, msg.AssignWithConversion(message); } - nsCOMPtr docShell; - nsCOMPtr owner; - globalObject->GetGlobalObjectOwner(getter_AddRefs(owner)); - if (owner) { - // First, notify the DOM that we have a script error. - globalObject->GetDocShell(getter_AddRefs(docShell)); - if (docShell && !JSREPORT_IS_WARNING(report->flags)) { - static PRInt32 errorDepth; // Recursion prevention - ++errorDepth; + // First, notify the DOM that we have a script error. + nsIDocShell *docShell = globalObject->GetDocShell(); + if (docShell && !JSREPORT_IS_WARNING(report->flags)) { + static PRInt32 errorDepth; // Recursion prevention + ++errorDepth; - nsCOMPtr presContext; - docShell->GetPresContext(getter_AddRefs(presContext)); + nsCOMPtr presContext; + docShell->GetPresContext(getter_AddRefs(presContext)); - if (presContext && errorDepth < 2) { - nsScriptErrorEvent errorevent(NS_SCRIPT_ERROR); + if (presContext && errorDepth < 2) { + nsScriptErrorEvent errorevent(NS_SCRIPT_ERROR); - errorevent.fileName = fileName.get(); - errorevent.errorMsg = msg.get(); - errorevent.lineNr = report ? report->lineno : 0; + errorevent.fileName = fileName.get(); + errorevent.errorMsg = msg.get(); + errorevent.lineNr = report ? report->lineno : 0; - // HandleDOMEvent() must be synchronous for the recursion block - // (errorDepth) to work. - globalObject->HandleDOMEvent(presContext, &errorevent, nsnull, - NS_EVENT_FLAG_INIT, &status); - } - - --errorDepth; + // HandleDOMEvent() must be synchronous for the recursion block + // (errorDepth) to work. + globalObject->HandleDOMEvent(presContext, &errorevent, nsnull, + NS_EVENT_FLAG_INIT, &status); } + + --errorDepth; } if (status != nsEventStatus_eConsumeNoDefault) { @@ -236,6 +230,8 @@ NS_ScriptErrorReporter(JSContext *cx, } if (NS_SUCCEEDED(rv)) { + nsIScriptGlobalObjectOwner *owner = + globalObject->GetGlobalObjectOwner(); if (owner) { owner->ReportScriptError(errorObject); } else { @@ -308,12 +304,8 @@ static JSBool ChangeCase(JSContext *cx, JSString *src, jsval *rval, void(* changeCaseFnc)(const nsAString&, nsAString&)) { - nsDependentString str(NS_REINTERPRET_CAST(const PRUnichar *, - ::JS_GetStringChars(src)), - ::JS_GetStringLength(src)); - nsAutoString result; - changeCaseFnc(str, result); + changeCaseFnc(nsDependentJSString(src), result); JSString *ucstr = JS_NewUCStringCopyN(cx, (jschar*)result.get(), result.Length()); 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; - rv = gCollation->CompareString(kCollationStrengthDefault, str1, str2, + rv = gCollation->CompareString(kCollationStrengthDefault, + nsDependentJSString(src1), + nsDependentJSString(src2), &result); 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, // we'll tell the user about this and we'll give the user the option // of stopping the execution of the script. - nsCOMPtr global; - ctx->GetGlobalObject(getter_AddRefs(global)); + nsIScriptGlobalObject *global = ctx->GetGlobalObject(); NS_ENSURE_TRUE(global, JS_TRUE); - nsCOMPtr docShell; - global->GetDocShell(getter_AddRefs(docShell)); + nsIDocShell *docShell = global->GetDocShell(); NS_ENSURE_TRUE(docShell, JS_TRUE); nsCOMPtr ireq(do_QueryInterface(docShell)); @@ -622,7 +607,7 @@ NS_IMPL_ADDREF(nsJSContext) NS_IMPL_RELEASE(nsJSContext) -NS_IMETHODIMP +nsresult nsJSContext::EvaluateStringWithValue(const nsAString& aScript, void *aScopeObject, nsIPrincipal *aPrincipal, @@ -655,11 +640,11 @@ nsJSContext::EvaluateStringWithValue(const nsAString& aScript, aPrincipal->GetJSPrincipals(mContext, &jsprin); } else { - nsCOMPtr global; - GetGlobalObject(getter_AddRefs(global)); + nsIScriptGlobalObject *global = GetGlobalObject(); if (!global) return NS_ERROR_FAILURE; - nsCOMPtr objPrincipal = do_QueryInterface(global, &rv); + nsCOMPtr objPrincipal = + do_QueryInterface(global, &rv); if (NS_FAILED(rv)) return NS_ERROR_FAILURE; 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... PRBool ok = PR_FALSE; - nsCOMPtr securityManager; - rv = GetSecurityManager(getter_AddRefs(securityManager)); - if (NS_SUCCEEDED(rv)) - rv = securityManager->CanExecuteScripts(mContext, principal, &ok); + + rv = sSecurityManager->CanExecuteScripts(mContext, principal, &ok); if (NS_FAILED(rv)) { JSPRINCIPALS_DROP(mContext, jsprin); return NS_ERROR_FAILURE; @@ -805,7 +788,7 @@ JSValueToAString(JSContext *cx, jsval val, nsAString *result, return NS_OK; } -NS_IMETHODIMP +nsresult nsJSContext::EvaluateString(const nsAString& aScript, void *aScopeObject, nsIPrincipal *aPrincipal, @@ -834,8 +817,7 @@ nsJSContext::EvaluateString(const nsAString& aScript, aPrincipal->GetJSPrincipals(mContext, &jsprin); } else { - nsCOMPtr global; - GetGlobalObject(getter_AddRefs(global)); + nsIScriptGlobalObject *global = GetGlobalObject(); if (!global) return NS_ERROR_FAILURE; nsCOMPtr objPrincipal = do_QueryInterface(global, &rv); @@ -849,10 +831,8 @@ nsJSContext::EvaluateString(const nsAString& aScript, // From here on, we must JSPRINCIPALS_DROP(jsprin) before returning... PRBool ok = PR_FALSE; - nsCOMPtr securityManager; - rv = GetSecurityManager(getter_AddRefs(securityManager)); - if (NS_SUCCEEDED(rv)) - rv = securityManager->CanExecuteScripts(mContext, principal, &ok); + + rv = sSecurityManager->CanExecuteScripts(mContext, principal, &ok); if (NS_FAILED(rv)) { JSPRINCIPALS_DROP(mContext, jsprin); return NS_ERROR_FAILURE; @@ -937,7 +917,7 @@ nsJSContext::EvaluateString(const nsAString& aScript, return rv; } -NS_IMETHODIMP +nsresult nsJSContext::CompileScript(const PRUnichar* aText, PRInt32 aTextLength, void *aScopeObject, @@ -958,10 +938,8 @@ nsJSContext::CompileScript(const PRUnichar* aText, // From here on, we must JSPRINCIPALS_DROP(jsprin) before returning... PRBool ok = PR_FALSE; - nsCOMPtr securityManager; - rv = GetSecurityManager(getter_AddRefs(securityManager)); - if (NS_SUCCEEDED(rv)) - rv = securityManager->CanExecuteScripts(mContext, aPrincipal, &ok); + + rv = sSecurityManager->CanExecuteScripts(mContext, aPrincipal, &ok); if (NS_FAILED(rv)) { JSPRINCIPALS_DROP(mContext, jsprin); return NS_ERROR_FAILURE; @@ -1008,7 +986,7 @@ nsJSContext::CompileScript(const PRUnichar* aText, return rv; } -NS_IMETHODIMP +nsresult nsJSContext::ExecuteScript(void* aScriptObject, void *aScopeObject, nsAString* aRetValue, @@ -1106,7 +1084,7 @@ AtomToEventHandlerName(nsIAtom *aName) return name; } -NS_IMETHODIMP +nsresult nsJSContext::CompileEventHandler(void *aTarget, nsIAtom *aName, const nsAString& aBody, const char *aURL, PRUint32 aLineNo, @@ -1165,7 +1143,7 @@ nsJSContext::CompileEventHandler(void *aTarget, nsIAtom *aName, return NS_OK; } -NS_IMETHODIMP +nsresult nsJSContext::CompileFunction(void* aTarget, const nsACString& aName, PRUint32 aArgCount, @@ -1178,8 +1156,7 @@ nsJSContext::CompileFunction(void* aTarget, { JSPrincipals *jsprin = nsnull; - nsCOMPtr global; - GetGlobalObject(getter_AddRefs(global)); + nsIScriptGlobalObject *global = GetGlobalObject(); if (global) { // XXXbe why the two-step QI? speed up via a new GetGlobalObjectData func? nsCOMPtr globalData = do_QueryInterface(global); @@ -1217,7 +1194,7 @@ nsJSContext::CompileFunction(void* aTarget, return NS_OK; } -NS_IMETHODIMP +nsresult nsJSContext::CallEventHandler(void *aTarget, void *aHandler, PRUint32 argc, 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 // hassle with principals: they're already compiled into the JS function. nsresult rv; - nsCOMPtr securityManager; - rv = GetSecurityManager(getter_AddRefs(securityManager)); - if (NS_FAILED(rv)) - return NS_ERROR_FAILURE; nsCOMPtr stack = do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv); @@ -1250,7 +1223,7 @@ nsJSContext::CallEventHandler(void *aTarget, void *aHandler, PRUint32 argc, mTerminationFunc = nsnull; // 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)) { jsval val; @@ -1277,7 +1250,7 @@ nsJSContext::CallEventHandler(void *aTarget, void *aHandler, PRUint32 argc, return NS_OK; } -NS_IMETHODIMP +nsresult nsJSContext::BindCompiledEventHandler(void *aTarget, nsIAtom *aName, void *aHandler) { @@ -1301,22 +1274,20 @@ nsJSContext::BindCompiledEventHandler(void *aTarget, nsIAtom *aName, return NS_OK; } -NS_IMETHODIMP +void nsJSContext::SetDefaultLanguageVersion(const char* aVersion) { - (void) ::JS_SetVersion(mContext, ::JS_StringToVersion(aVersion)); - return NS_OK; + ::JS_SetVersion(mContext, ::JS_StringToVersion(aVersion)); } -NS_IMETHODIMP -nsJSContext::GetGlobalObject(nsIScriptGlobalObject** aGlobalObject) +nsIScriptGlobalObject * +nsJSContext::GetGlobalObject() { JSObject *global = ::JS_GetGlobalObject(mContext); - *aGlobalObject = nsnull; if (!global) { NS_WARNING("Context has no global."); - return NS_OK; + return nsnull; } JSClass *c = JS_GET_CLASS(mContext, global); @@ -1324,42 +1295,44 @@ nsJSContext::GetGlobalObject(nsIScriptGlobalObject** aGlobalObject) if (!c || ((~c->flags) & (JSCLASS_HAS_PRIVATE | JSCLASS_PRIVATE_IS_NSISUPPORTS))) { NS_WARNING("Global is not an nsISupports."); - return NS_OK; + return nsnull; } - nsCOMPtr native = + nsCOMPtr sgo; + nsISupports *priv = (nsISupports *)::JS_GetPrivate(mContext, global); nsCOMPtr wrapped_native = - do_QueryInterface(native); + do_QueryInterface(priv); if (wrapped_native) { // The global object is a XPConnect wrapped native, the native in // the wrapper might be the nsIScriptGlobalObject + nsCOMPtr 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) { - NS_WARNING("XPConnect wrapped native doesn't wrap anything."); - return NS_OK; - } - - // We have private data (either directly from ::JS_GetPrivate() or - // through wrapped_native->GetNative()), check if it's a - // nsIScriptGlobalObject - - return CallQueryInterface(native, aGlobalObject); + // This'll return a pointer to something we're about to release, but + // that's ok, the JS object will hold it alive long enough. + return sgo; } -NS_IMETHODIMP_(void*) +void * nsJSContext::GetNativeContext() { - return (void *)mContext; + return mContext; } -NS_IMETHODIMP +nsresult nsJSContext::InitContext(nsIScriptGlobalObject *aGlobalObject) { if (!mContext) @@ -1685,21 +1658,19 @@ nsJSContext::InitClasses() return rv; } -NS_IMETHODIMP +PRBool nsJSContext::IsContextInitialized() { - return (mIsInitialized) ? NS_OK : NS_ERROR_NOT_INITIALIZED; + return mIsInitialized; } -NS_IMETHODIMP +void nsJSContext::GC() { FireGCTimer(); - - return NS_OK; } -NS_IMETHODIMP +void nsJSContext::ScriptEvaluated(PRBool aTerminated) { if (aTerminated && mTerminationFunc) { @@ -1716,102 +1687,73 @@ nsJSContext::ScriptEvaluated(PRBool aTerminated) } mBranchCallbackCount = 0; - - return NS_OK; } -NS_IMETHODIMP -nsJSContext::GetSecurityManager(nsIScriptSecurityManager **aInstancePtr) -{ - *aInstancePtr = sSecurityManager; - - if (!sSecurityManager) { - return NS_ERROR_NOT_AVAILABLE; - } - - NS_ADDREF(*aInstancePtr); - - return NS_OK; -} - -NS_IMETHODIMP +void nsJSContext::SetOwner(nsIScriptContextOwner* owner) { // The owner should not be addrefed!! We'll be told // when the owner goes away. mOwner = owner; - - return NS_OK; } -NS_IMETHODIMP -nsJSContext::GetOwner(nsIScriptContextOwner** owner) +nsIScriptContextOwner * +nsJSContext::GetOwner() { - *owner = mOwner; - NS_IF_ADDREF(*owner); - - return NS_OK; + return mOwner; } -NS_IMETHODIMP +void nsJSContext::SetTerminationFunction(nsScriptTerminationFunc aFunc, nsISupports* aRef) { mTerminationFunc = aFunc; mTerminationFuncArg = aRef; - - return NS_OK; } -NS_IMETHODIMP -nsJSContext::GetScriptsEnabled(PRBool *aEnabled) +PRBool +nsJSContext::GetScriptsEnabled() { - *aEnabled = mScriptsEnabled; - return NS_OK; + return mScriptsEnabled; } -NS_IMETHODIMP +void nsJSContext::SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts) { mScriptsEnabled = aEnabled; - nsCOMPtr global; - GetGlobalObject(getter_AddRefs(global)); + nsIScriptGlobalObject *global = GetGlobalObject(); if (global) { global->SetScriptsEnabled(aEnabled, aFireTimeouts); } - - return NS_OK; } -NS_IMETHODIMP -nsJSContext::GetProcessingScriptTag(PRBool * aResult) +PRBool +nsJSContext::GetProcessingScriptTag() { - *aResult = mProcessingScriptTag; - return NS_OK; + return mProcessingScriptTag; } -NS_IMETHODIMP +void nsJSContext::SetProcessingScriptTag(PRBool aFlag) { mProcessingScriptTag = aFlag; - return NS_OK; } -NS_IMETHODIMP +void nsJSContext::SetGCOnDestruction(PRBool aGCOnDestruction) { mGCOnDestruction = aGCOnDestruction; - - return NS_OK; } NS_IMETHODIMP nsJSContext::ScriptExecuted() { - return ScriptEvaluated(PR_FALSE); + ScriptEvaluated(PR_FALSE); + + return NS_OK; } NS_IMETHODIMP @@ -1870,7 +1812,8 @@ DOMGCCallback(JSContext *cx, JSGCStatus status) } // static -nsresult nsJSEnvironment::Init() +nsresult +nsJSEnvironment::Init() { static PRBool isInitialized; @@ -1990,8 +1933,7 @@ NS_CreateScriptContext(nsIScriptGlobalObject *aGlobal, NS_ENSURE_SUCCESS(rv, rv); if (aGlobal) { - rv = aGlobal->SetContext(scriptContext); - NS_ENSURE_SUCCESS(rv, rv); + aGlobal->SetContext(scriptContext); } *aContext = scriptContext; diff --git a/dom/src/base/nsJSEnvironment.h b/dom/src/base/nsJSEnvironment.h index 630bfc4bfcd..4da268e1590 100644 --- a/dom/src/base/nsJSEnvironment.h +++ b/dom/src/base/nsJSEnvironment.h @@ -58,7 +58,7 @@ public: NS_DECL_ISUPPORTS - NS_IMETHOD EvaluateString(const nsAString& aScript, + virtual nsresult EvaluateString(const nsAString& aScript, void *aScopeObject, nsIPrincipal *principal, const char *aURL, @@ -66,7 +66,7 @@ public: const char* aVersion, nsAString& aRetValue, PRBool* aIsUndefined); - NS_IMETHOD EvaluateStringWithValue(const nsAString& aScript, + virtual nsresult EvaluateStringWithValue(const nsAString& aScript, void *aScopeObject, nsIPrincipal *aPrincipal, const char *aURL, @@ -75,7 +75,7 @@ public: void* aRetValue, PRBool* aIsUndefined); - NS_IMETHOD CompileScript(const PRUnichar* aText, + virtual nsresult CompileScript(const PRUnichar* aText, PRInt32 aTextLength, void *aScopeObject, nsIPrincipal *principal, @@ -83,24 +83,24 @@ public: PRUint32 aLineNo, const char* aVersion, void** aScriptObject); - NS_IMETHOD ExecuteScript(void* aScriptObject, + virtual nsresult ExecuteScript(void* aScriptObject, void *aScopeObject, nsAString* aRetValue, PRBool* aIsUndefined); - NS_IMETHOD CompileEventHandler(void *aTarget, + virtual nsresult CompileEventHandler(void *aTarget, nsIAtom *aName, const nsAString& aBody, const char *aURL, PRUint32 aLineNo, PRBool aShared, void** aHandler); - NS_IMETHOD CallEventHandler(void *aTarget, void *aHandler, - PRUint32 argc, void *argv, + virtual nsresult CallEventHandler(void *aTarget, void *aHandler, + PRUint32 argc, void *argv, PRBool *aBoolResult); - NS_IMETHOD BindCompiledEventHandler(void *aTarget, + virtual nsresult BindCompiledEventHandler(void *aTarget, nsIAtom *aName, void *aHandler); - NS_IMETHOD CompileFunction(void* aTarget, + virtual nsresult CompileFunction(void* aTarget, const nsACString& aName, PRUint32 aArgCount, const char** aArgArray, @@ -110,26 +110,25 @@ public: PRBool aShared, void** aFunctionObject); - NS_IMETHOD SetDefaultLanguageVersion(const char* aVersion); - NS_IMETHOD GetGlobalObject(nsIScriptGlobalObject** aGlobalObject); - NS_IMETHOD_(void *) GetNativeContext(); - NS_IMETHOD InitContext(nsIScriptGlobalObject *aGlobalObject); - NS_IMETHOD IsContextInitialized(); - NS_IMETHOD GC(); - NS_IMETHOD GetSecurityManager(nsIScriptSecurityManager** aInstancePtr); + virtual void SetDefaultLanguageVersion(const char* aVersion); + virtual nsIScriptGlobalObject *GetGlobalObject(); + virtual void *GetNativeContext(); + virtual nsresult InitContext(nsIScriptGlobalObject *aGlobalObject); + virtual PRBool IsContextInitialized(); + virtual void GC(); - NS_IMETHOD ScriptEvaluated(PRBool aTerminated); - NS_IMETHOD SetOwner(nsIScriptContextOwner* owner); - NS_IMETHOD GetOwner(nsIScriptContextOwner** owner); - NS_IMETHOD SetTerminationFunction(nsScriptTerminationFunc aFunc, - nsISupports* aRef); - NS_IMETHOD GetScriptsEnabled(PRBool *aEnabled); - NS_IMETHOD SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts); + virtual void ScriptEvaluated(PRBool aTerminated); + virtual void SetOwner(nsIScriptContextOwner* owner); + virtual nsIScriptContextOwner *GetOwner(); + virtual void SetTerminationFunction(nsScriptTerminationFunc aFunc, + nsISupports* aRef); + virtual PRBool GetScriptsEnabled(); + virtual void SetScriptsEnabled(PRBool aEnabled, PRBool aFireTimeouts); - NS_IMETHOD GetProcessingScriptTag(PRBool * aResult); - NS_IMETHOD SetProcessingScriptTag(PRBool aResult); + virtual PRBool GetProcessingScriptTag(); + virtual void SetProcessingScriptTag(PRBool aResult); - NS_IMETHOD SetGCOnDestruction(PRBool aGCOnDestruction); + virtual void SetGCOnDestruction(PRBool aGCOnDestruction); NS_DECL_NSIXPCSCRIPTNOTIFY diff --git a/dom/src/base/nsJSUtils.cpp b/dom/src/base/nsJSUtils.cpp index be57b79a9ef..618686b4bfd 100644 --- a/dom/src/base/nsJSUtils.cpp +++ b/dom/src/base/nsJSUtils.cpp @@ -91,9 +91,8 @@ nsJSUtils::GetCallingLocation(JSContext* aContext, const char* *aFilename, return JS_FALSE; } -void -nsJSUtils::ConvertStringToJSVal(const nsString& aProp, JSContext* aContext, - jsval* aReturn) +jsval +nsJSUtils::ConvertStringToJSVal(const nsString& aProp, JSContext* aContext) { JSString *jsstring = ::JS_NewUCStringCopyN(aContext, NS_REINTERPRET_CAST(const jschar*, @@ -101,7 +100,7 @@ nsJSUtils::ConvertStringToJSVal(const nsString& aProp, JSContext* aContext, aProp.Length()); // set the return value - *aReturn = STRING_TO_JSVAL(jsstring); + return STRING_TO_JSVAL(jsstring); } PRBool @@ -162,9 +161,8 @@ nsJSUtils::ConvertJSValToUint32(PRUint32* aProp, JSContext* aContext, return JS_TRUE; } -nsresult -nsJSUtils::GetStaticScriptGlobal(JSContext* aContext, JSObject* aObj, - nsIScriptGlobalObject** aNativeGlobal) +nsIScriptGlobalObject * +nsJSUtils::GetStaticScriptGlobal(JSContext* aContext, JSObject* aObj) { nsISupports* supports; JSClass* clazz; @@ -172,7 +170,7 @@ nsJSUtils::GetStaticScriptGlobal(JSContext* aContext, JSObject* aObj, JSObject* glob = aObj; // starting point for search if (!glob) - return NS_ERROR_FAILURE; + return nsnull; while ((parent = ::JS_GetParent(aContext, glob))) glob = parent; @@ -183,47 +181,44 @@ nsJSUtils::GetStaticScriptGlobal(JSContext* aContext, JSObject* aObj, !(clazz->flags & JSCLASS_HAS_PRIVATE) || !(clazz->flags & JSCLASS_PRIVATE_IS_NSISUPPORTS) || !(supports = (nsISupports*)::JS_GetPrivate(aContext, glob))) { - return NS_ERROR_FAILURE; + return nsnull; } nsCOMPtr wrapper(do_QueryInterface(supports)); - NS_ENSURE_TRUE(wrapper, NS_ERROR_UNEXPECTED); + NS_ENSURE_TRUE(wrapper, nsnull); nsCOMPtr native; wrapper->GetNative(getter_AddRefs(native)); - return CallQueryInterface(native, aNativeGlobal); + nsCOMPtr 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 -nsJSUtils::GetStaticScriptContext(JSContext* aContext, JSObject* aObj, - nsIScriptContext** aScriptContext) +nsIScriptContext * +nsJSUtils::GetStaticScriptContext(JSContext* aContext, JSObject* aObj) { - nsCOMPtr nativeGlobal; - GetStaticScriptGlobal(aContext, aObj, getter_AddRefs(nativeGlobal)); + nsIScriptGlobalObject *nativeGlobal = GetStaticScriptGlobal(aContext, aObj); if (!nativeGlobal) - return NS_ERROR_FAILURE; - nsIScriptContext* scriptContext = nsnull; - nativeGlobal->GetContext(&scriptContext); - *aScriptContext = scriptContext; - return scriptContext ? NS_OK : NS_ERROR_FAILURE; + return nsnull; + + return nativeGlobal->GetContext(); } -nsresult -nsJSUtils::GetDynamicScriptGlobal(JSContext* aContext, - nsIScriptGlobalObject** aNativeGlobal) +nsIScriptGlobalObject * +nsJSUtils::GetDynamicScriptGlobal(JSContext* aContext) { - nsCOMPtr scriptCX; - GetDynamicScriptContext(aContext, getter_AddRefs(scriptCX)); + nsIScriptContext *scriptCX = GetDynamicScriptContext(aContext); if (!scriptCX) - return NS_ERROR_FAILURE; - return scriptCX->GetGlobalObject(aNativeGlobal); + return nsnull; + return scriptCX->GetGlobalObject(); } -nsresult -nsJSUtils::GetDynamicScriptContext(JSContext *aContext, - nsIScriptContext** aScriptContext) +nsIScriptContext * +nsJSUtils::GetDynamicScriptContext(JSContext *aContext) { - return GetScriptContextFromJSContext(aContext, aScriptContext); + return GetScriptContextFromJSContext(aContext); } diff --git a/dom/src/base/nsJSUtils.h b/dom/src/base/nsJSUtils.h index bc6387a42aa..a24b118411e 100644 --- a/dom/src/base/nsJSUtils.h +++ b/dom/src/base/nsJSUtils.h @@ -53,15 +53,15 @@ class nsIDOMEventListener; class nsIScriptContext; class nsIScriptGlobalObject; -class nsIScriptSecurityManager; -class nsJSUtils { +class nsJSUtils +{ public: static JSBool GetCallingLocation(JSContext* aContext, const char* *aFilename, PRUint32 *aLineno); - static void ConvertStringToJSVal(const nsString& aProp, JSContext* aContext, - jsval* aReturn); + static jsval ConvertStringToJSVal(const nsString& aProp, + JSContext* aContext); static PRBool ConvertJSValToXPCObject(nsISupports** aSupports, REFNSIID aIID, JSContext* aContext, jsval aValue); @@ -72,17 +72,35 @@ public: static PRBool ConvertJSValToUint32(PRUint32* aProp, JSContext* aContext, jsval aValue); - static nsresult GetStaticScriptGlobal(JSContext* aContext, JSObject* aObj, - nsIScriptGlobalObject** aGlobal); + static nsIScriptGlobalObject *GetStaticScriptGlobal(JSContext* aContext, + JSObject* aObj); - static nsresult GetStaticScriptContext(JSContext* aContext, JSObject* aObj, - nsIScriptContext** aScriptContext); + static nsIScriptContext *GetStaticScriptContext(JSContext* aContext, + JSObject* aObj); - static nsresult GetDynamicScriptGlobal(JSContext *aContext, - nsIScriptGlobalObject** aGlobal); + static nsIScriptGlobalObject *GetDynamicScriptGlobal(JSContext *aContext); - static nsresult GetDynamicScriptContext(JSContext *aContext, - nsIScriptContext** aScriptContext); + static nsIScriptContext *GetDynamicScriptContext(JSContext *aContext); +}; + + +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__ */ diff --git a/dom/src/base/nsLocation.cpp b/dom/src/base/nsLocation.cpp index f7d85739745..057a07e53b0 100644 --- a/dom/src/base/nsLocation.cpp +++ b/dom/src/base/nsLocation.cpp @@ -69,7 +69,8 @@ #include "nsIProtocolHandler.h" #include "nsReadableUtils.h" -static nsresult GetDocumentCharacterSetForURI(const nsAString& aHref, nsACString& aCharset) +static nsresult +GetDocumentCharacterSetForURI(const nsAString& aHref, nsACString& aCharset) { aCharset.Truncate(); @@ -83,11 +84,8 @@ static nsresult GetDocumentCharacterSetForURI(const nsAString& aHref, nsACString rv = stack->Peek(&cx); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr nativeGlob; - nsJSUtils::GetDynamicScriptGlobal(cx, getter_AddRefs(nativeGlob)); - NS_ENSURE_TRUE(nativeGlob, NS_ERROR_FAILURE); - - nsCOMPtr window = do_QueryInterface(nativeGlob); + nsCOMPtr window = + do_QueryInterface(nsJSUtils::GetDynamicScriptGlobal(cx)); NS_ENSURE_TRUE(window, NS_ERROR_FAILURE); nsCOMPtr domDoc; @@ -125,7 +123,8 @@ NS_INTERFACE_MAP_END NS_IMPL_ADDREF(LocationImpl) NS_IMPL_RELEASE(LocationImpl) -NS_IMETHODIMP_(void) LocationImpl::SetDocShell(nsIDocShell *aDocShell) +void +LocationImpl::SetDocShell(nsIDocShell *aDocShell) { mDocShell = aDocShell; // Weak Reference } @@ -573,11 +572,11 @@ LocationImpl::SetHrefWithBase(const nsAString& aHref, result = stack->Peek(&cx); if (cx) { - nsCOMPtr scriptContext; - nsJSUtils::GetDynamicScriptContext(cx, getter_AddRefs(scriptContext)); + nsIScriptContext *scriptContext = + nsJSUtils::GetDynamicScriptContext(cx); if (scriptContext) { - scriptContext->GetProcessingScriptTag(&inScriptTag); + inScriptTag = scriptContext->GetProcessingScriptTag(); } } //cx } // stack @@ -907,10 +906,8 @@ LocationImpl::GetSourceDocument(JSContext* cx, nsIDocument** aDocument) // that we can get the url of the caller. // XXX This will fail on non-DOM contexts :( - nsCOMPtr nativeGlob; - nsJSUtils::GetDynamicScriptGlobal(cx, getter_AddRefs(nativeGlob)); - - nsCOMPtr window = do_QueryInterface(nativeGlob, &rv); + nsCOMPtr window = + do_QueryInterface(nsJSUtils::GetDynamicScriptGlobal(cx), &rv); if (window) { nsCOMPtr domDoc; diff --git a/dom/src/build/nsDOMFactory.cpp b/dom/src/build/nsDOMFactory.cpp index 490d5a50d26..e69de29bb2d 100644 --- a/dom/src/build/nsDOMFactory.cpp +++ b/dom/src/build/nsDOMFactory.cpp @@ -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 observerService = - do_GetService("@mozilla.org/observer-service;1"); - - if (observerService) { - observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE); - } - - nsCOMPtr 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 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 cache = - do_GetService("@mozilla.org/xul/xul-prototype-cache;1"); - - if (cache) - cache->Flush(); -#endif - - nsCOMPtr 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 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 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 controller = - do_CreateInstance("@mozilla.org/embedcomp/base-command-controller;1", &rv); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr windowCommandTable = do_GetService(kWindowCommandTableCID, &rv); - if (NS_FAILED(rv)) return rv; - - // this is a singleton; make it immutable - windowCommandTable->MakeImmutable(); - - nsCOMPtr 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) - - diff --git a/dom/src/events/nsJSEventListener.cpp b/dom/src/events/nsJSEventListener.cpp index 5ab40a040ed..c44a16a6ab1 100644 --- a/dom/src/events/nsJSEventListener.cpp +++ b/dom/src/events/nsJSEventListener.cpp @@ -37,7 +37,7 @@ * ***** END LICENSE BLOCK ***** */ #include "nsJSEventListener.h" #include "nsString.h" -#include "nsIScriptEventListener.h" +#include "nsReadableUtils.h" #include "nsIServiceManager.h" #include "nsIJSContextStack.h" #include "nsIScriptSecurityManager.h" @@ -51,15 +51,9 @@ * nsJSEventListener implementation */ 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; } @@ -79,13 +73,14 @@ NS_IMPL_RELEASE(nsJSEventListener) //static nsString onPrefix = "on"; -nsresult nsJSEventListener::SetEventName(nsIAtom* aName) +void +nsJSEventListener::SetEventName(nsIAtom* aName) { mEventName = aName; - return NS_OK; } -nsresult nsJSEventListener::HandleEvent(nsIDOMEvent* aEvent) +nsresult +nsJSEventListener::HandleEvent(nsIDOMEvent* aEvent) { jsval funval; jsval arg; @@ -122,7 +117,7 @@ nsresult nsJSEventListener::HandleEvent(nsIDOMEvent* aEvent) // root nsCOMPtr 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_ENSURE_SUCCESS(rv, rv); @@ -193,22 +188,6 @@ nsresult nsJSEventListener::HandleEvent(nsIDOMEvent* aEvent) 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 */ diff --git a/dom/src/events/nsJSEventListener.h b/dom/src/events/nsJSEventListener.h index 654533418f6..f3872ba6641 100644 --- a/dom/src/events/nsJSEventListener.h +++ b/dom/src/events/nsJSEventListener.h @@ -40,7 +40,6 @@ #define nsJSEventListener_h__ #include "nsIDOMKeyEvent.h" -#include "nsIScriptEventListener.h" #include "nsIJSEventListener.h" #include "nsIDOMMouseListener.h" #include "jsapi.h" @@ -58,18 +57,13 @@ public: NS_DECL_ISUPPORTS - //nsIDOMEventListener interface - NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent); + // nsIDOMEventListener interface + NS_DECL_NSIDOMEVENTLISTENER - //nsIJSEventListener interface - NS_IMETHOD GetEventTarget(nsIScriptContext** aContext, - nsISupports** aTarget); - - NS_IMETHOD SetEventName(nsIAtom* aName); + // nsIJSEventListener interface + virtual void SetEventName(nsIAtom* aName); protected: - nsCOMPtr mContext; - nsISupports* mObject; nsCOMPtr mEventName; enum nsReturnResult { diff --git a/dom/src/jsurl/nsJSProtocolHandler.cpp b/dom/src/jsurl/nsJSProtocolHandler.cpp index ee01b0f18f5..8f38cb33907 100644 --- a/dom/src/jsurl/nsJSProtocolHandler.cpp +++ b/dom/src/jsurl/nsJSProtocolHandler.cpp @@ -184,12 +184,9 @@ nsresult nsJSThunk::EvaluateScript(nsIChannel *aChannel) return NS_ERROR_FAILURE; } - nsCOMPtr scriptContext; - rv = global->GetContext(getter_AddRefs(scriptContext)); - if (NS_FAILED(rv)) - return rv; - - if (!scriptContext) return NS_ERROR_FAILURE; + nsIScriptContext *scriptContext = global->GetContext(); + if (!scriptContext) + return NS_ERROR_FAILURE; // Unescape the script NS_UnescapeURL(script); diff --git a/editor/composer/src/nsComposerCommandsUpdater.cpp b/editor/composer/src/nsComposerCommandsUpdater.cpp index 71780355d97..38c3b574eb7 100644 --- a/editor/composer/src/nsComposerCommandsUpdater.cpp +++ b/editor/composer/src/nsComposerCommandsUpdater.cpp @@ -233,9 +233,7 @@ nsComposerCommandsUpdater::Init(nsIDOMWindow* aDOMWindow) nsCOMPtr scriptObject(do_QueryInterface(aDOMWindow)); if (scriptObject) { - nsCOMPtr docShell; - scriptObject->GetDocShell(getter_AddRefs(docShell)); - mDocShell = docShell.get(); + mDocShell = scriptObject->GetDocShell(); } return NS_OK; } diff --git a/editor/composer/src/nsEditingSession.cpp b/editor/composer/src/nsEditingSession.cpp index e2c1f6a80ed..dcaa8ba28a9 100644 --- a/editor/composer/src/nsEditingSession.cpp +++ b/editor/composer/src/nsEditingSession.cpp @@ -126,9 +126,8 @@ NS_IMPL_ISUPPORTS4(nsEditingSession, nsIEditingSession, nsIWebProgressListener, NS_IMETHODIMP nsEditingSession::Init(nsIDOMWindow *aWindow) { - nsCOMPtr docShell; - nsresult rv = GetDocShellFromWindow(aWindow, getter_AddRefs(docShell)); - if (NS_FAILED(rv)) return rv; + nsIDocShell *docShell = GetDocShellFromWindow(aWindow); + if (!docShell) return NS_ERROR_FAILURE; mEditingShell = do_GetWeakReference(docShell); if (!mEditingShell) return NS_ERROR_NO_INTERFACE; @@ -157,11 +156,10 @@ nsEditingSession::MakeWindowEditable(nsIDOMWindow *aWindow, mWindowToBeEdited = do_GetWeakReference(aWindow); // disable plugins - nsCOMPtr docShell; - nsresult rv = GetDocShellFromWindow(aWindow, getter_AddRefs(docShell)); - if (NS_FAILED(rv)) return rv; + nsIDocShell *docShell = GetDocShellFromWindow(aWindow); + if (!docShell) return NS_ERROR_FAILURE; - rv = docShell->SetAllowPlugins(PR_FALSE); + nsresult rv = docShell->SetAllowPlugins(PR_FALSE); if (NS_FAILED(rv)) return rv; // register as a content listener, so that we can fend off URL @@ -173,12 +171,10 @@ nsEditingSession::MakeWindowEditable(nsIDOMWindow *aWindow, nsCOMPtr sgo (do_QueryInterface(aWindow)); if (sgo) { - nsCOMPtr scriptContext; - sgo->GetContext(getter_AddRefs(scriptContext)); + nsIScriptContext *scriptContext = sgo->GetContext(); if (scriptContext) { - rv = scriptContext->SetScriptsEnabled(PR_FALSE, PR_TRUE); - if (NS_FAILED(rv)) return rv; + scriptContext->SetScriptsEnabled(PR_FALSE, PR_TRUE); } } @@ -392,9 +388,8 @@ nsEditingSession::SetupEditorOnWindow(nsIDOMWindow *aWindow) // Create editor and do other things // only if we haven't found some error above, - nsCOMPtr docShell; - rv = GetDocShellFromWindow(aWindow, getter_AddRefs(docShell)); - if (NS_FAILED(rv)) return rv; + nsIDocShell *docShell = GetDocShellFromWindow(aWindow); + if (!docShell) return NS_ERROR_FAILURE; nsCOMPtr presShell; rv = docShell->GetPresShell(getter_AddRefs(presShell)); @@ -763,9 +758,8 @@ nsEditingSession::OnLocationChange(nsIWebProgress *aWebProgress, // Notify the location-changed observer that // the document URL has changed - nsCOMPtr docShell; - rv = GetDocShellFromWindow(domWindow, getter_AddRefs(docShell)); - if (NS_FAILED(rv)) return rv; + nsIDocShell *docShell = GetDocShellFromWindow(domWindow); + if (!docShell) return NS_ERROR_FAILURE; nsCOMPtr commandManager = do_GetInterface(docShell); nsCOMPtr commandUpdater = @@ -978,9 +972,8 @@ nsEditingSession::EndDocumentLoad(nsIWebProgress *aWebProgress, mEditorStatus = eEditorErrorFileNotFound; } - nsCOMPtr docShell; - nsresult rv = GetDocShellFromWindow(domWindow, getter_AddRefs(docShell)); - if (NS_FAILED(rv)) return rv; // better error handling? + nsIDocShell *docShell = GetDocShellFromWindow(domWindow); + if (!docShell) return NS_ERROR_FAILURE; // better error handling? // cancel refresh from meta tags // we need to make sure that all pages in editor (whether editable or not) @@ -991,6 +984,8 @@ nsEditingSession::EndDocumentLoad(nsIWebProgress *aWebProgress, nsCOMPtr editorDocShell = do_QueryInterface(docShell); + nsresult rv = NS_OK; + // did someone set the flag to make this shell editable? if (aIsToBeMadeEditable && mCanCreateEditor && editorDocShell) { @@ -1089,9 +1084,8 @@ nsEditingSession::EndPageLoad(nsIWebProgress *aWebProgress, nsCOMPtr domWindow; nsresult rv = aWebProgress->GetDOMWindow(getter_AddRefs(domWindow)); - nsCOMPtr docShell; - rv = GetDocShellFromWindow(domWindow, getter_AddRefs(docShell)); - if (NS_FAILED(rv)) return rv; + nsIDocShell *docShell = GetDocShellFromWindow(domWindow); + if (!docShell) return NS_ERROR_FAILURE; // cancel refresh from meta tags // we need to make sure that all pages in editor (whether editable or not) @@ -1117,20 +1111,16 @@ nsEditingSession::EndPageLoad(nsIWebProgress *aWebProgress, GetDocShellFromWindow - Utility method. This will always return an error if no docShell - is returned. + Utility method. This will always return nsnull if no docShell is found. ----------------------------------------------------------------------------*/ -nsresult -nsEditingSession::GetDocShellFromWindow(nsIDOMWindow *aWindow, - nsIDocShell** outDocShell) +nsIDocShell * +nsEditingSession::GetDocShellFromWindow(nsIDOMWindow *aWindow) { nsCOMPtr scriptGO = do_QueryInterface(aWindow); - if (!scriptGO) return NS_ERROR_FAILURE; + if (!scriptGO) + return nsnull; - nsresult rv = scriptGO->GetDocShell(outDocShell); - if (NS_FAILED(rv)) return rv; - if (!*outDocShell) return NS_ERROR_FAILURE; - return NS_OK; + return scriptGO->GetDocShell(); } /*--------------------------------------------------------------------------- @@ -1144,9 +1134,8 @@ nsresult nsEditingSession::GetEditorDocShellFromWindow(nsIDOMWindow *aWindow, nsIEditorDocShell** outDocShell) { - nsCOMPtr docShell; - nsresult rv = GetDocShellFromWindow(aWindow, getter_AddRefs(docShell)); - if (NS_FAILED(rv)) return rv; + nsIDocShell *docShell = GetDocShellFromWindow(aWindow); + if (!docShell) return NS_ERROR_FAILURE; return docShell->QueryInterface(NS_GET_IID(nsIEditorDocShell), (void **)outDocShell); diff --git a/editor/composer/src/nsEditingSession.h b/editor/composer/src/nsEditingSession.h index d687b8ceda1..1ab7ebc952c 100644 --- a/editor/composer/src/nsEditingSession.h +++ b/editor/composer/src/nsEditingSession.h @@ -98,8 +98,7 @@ public: protected: - nsresult GetDocShellFromWindow(nsIDOMWindow *aWindow, - nsIDocShell** outDocShell); + nsIDocShell * GetDocShellFromWindow(nsIDOMWindow *aWindow); nsresult GetEditorDocShellFromWindow(nsIDOMWindow *aWindow, nsIEditorDocShell** outDocShell); diff --git a/embedding/browser/activex/src/plugin/LegacyPlugin.cpp b/embedding/browser/activex/src/plugin/LegacyPlugin.cpp index 72d67e93f3e..f72bcab3497 100644 --- a/embedding/browser/activex/src/plugin/LegacyPlugin.cpp +++ b/embedding/browser/activex/src/plugin/LegacyPlugin.cpp @@ -438,16 +438,14 @@ GetPluginsContext(PluginInstanceData *pData) nsCOMPtr window; NPN_GetValue(pData->pPluginInstance, NPNVDOMWindow, NS_STATIC_CAST(nsIDOMWindow **, getter_AddRefs(window))); - if (!window) - return nsnull; nsCOMPtr globalObject(do_QueryInterface(window)); if (!globalObject) return nsnull; - nsCOMPtr scriptContext; - if (NS_FAILED(globalObject->GetContext(getter_AddRefs(scriptContext))) || - !scriptContext) + nsIScriptContext *scriptContext = globalObject->GetContext(); + + if (!scriptContext) return nsnull; return NS_REINTERPRET_CAST(JSContext*, scriptContext->GetNativeContext()); diff --git a/embedding/browser/activex/src/plugin/PrefObserver.cpp b/embedding/browser/activex/src/plugin/PrefObserver.cpp index 4d92344bef3..482f5c8668d 100644 --- a/embedding/browser/activex/src/plugin/PrefObserver.cpp +++ b/embedding/browser/activex/src/plugin/PrefObserver.cpp @@ -165,7 +165,6 @@ nsresult PrefObserver::Subscribe() { NS_ENSURE_TRUE(mPrefBranch, NS_ERROR_FAILURE); - nsresult rv; mPrefBranch->AddObserver(kProxyPref, this, PR_TRUE); mPrefBranch->AddObserver(kUserAgentPref, this, PR_TRUE); @@ -180,7 +179,6 @@ nsresult PrefObserver::Unsubscribe() { NS_ENSURE_TRUE(mPrefBranch, NS_ERROR_FAILURE); - nsresult rv; mPrefBranch->RemoveObserver(kProxyPref, this); mPrefBranch->RemoveObserver(kUserAgentPref, this); diff --git a/embedding/browser/activex/src/plugin/XPCDocument.cpp b/embedding/browser/activex/src/plugin/XPCDocument.cpp index d1bdbdd8760..abeae2535a4 100644 --- a/embedding/browser/activex/src/plugin/XPCDocument.cpp +++ b/embedding/browser/activex/src/plugin/XPCDocument.cpp @@ -819,9 +819,8 @@ END_COM_MAP() if (!globalObject) return E_UNEXPECTED; - nsCOMPtr scriptContext; - if (NS_FAILED(globalObject->GetContext(getter_AddRefs(scriptContext))) || - !scriptContext) + nsIScriptContext *scriptContext = globalObject->GetContext(); + if (!scriptContext) return E_UNEXPECTED; nsCOMPtr doc(do_QueryInterface(domDocument)); diff --git a/embedding/browser/webBrowser/nsCommandHandler.cpp b/embedding/browser/webBrowser/nsCommandHandler.cpp index 594d0d680ec..64500a2a8ff 100644 --- a/embedding/browser/webBrowser/nsCommandHandler.cpp +++ b/embedding/browser/webBrowser/nsCommandHandler.cpp @@ -52,12 +52,10 @@ nsresult nsCommandHandler::GetCommandHandler(nsICommandHandler **aCommandHandler return NS_ERROR_FAILURE; } - nsCOMPtr docShell; - globalObj->GetDocShell(getter_AddRefs(docShell)); - // Get the document tree owner - nsCOMPtr docShellAsTreeItem(do_QueryInterface(docShell)); + nsCOMPtr docShellAsTreeItem = + do_QueryInterface(globalObj->GetDocShell()); nsIDocShellTreeOwner *treeOwner = nsnull; docShellAsTreeItem->GetTreeOwner(&treeOwner); diff --git a/embedding/browser/webBrowser/nsDocShellTreeOwner.cpp b/embedding/browser/webBrowser/nsDocShellTreeOwner.cpp index 15eea2826c3..c2e8212ab0b 100644 --- a/embedding/browser/webBrowser/nsDocShellTreeOwner.cpp +++ b/embedding/browser/webBrowser/nsDocShellTreeOwner.cpp @@ -97,7 +97,7 @@ GetEventReceiver ( nsWebBrowser* inBrowser, nsIDOMEventReceiver** outEventRcvr ) NS_ENSURE_TRUE(chromeHandler, NS_ERROR_FAILURE); nsCOMPtr rcvr = do_QueryInterface(chromeHandler); - *outEventRcvr = rcvr.get(); + *outEventRcvr = rcvr; NS_IF_ADDREF(*outEventRcvr); return NS_OK; @@ -243,14 +243,14 @@ nsDocShellTreeOwner::FindItemWithName(const PRUnichar* aName, nsCOMPtr reqAsTreeOwner(do_QueryInterface(aRequestor)); if(mTreeOwner) { - if (mTreeOwner != reqAsTreeOwner.get()) - return mTreeOwner->FindItemWithName(aName, mWebBrowser->mDocShellAsItem.get(), + if (mTreeOwner != reqAsTreeOwner) + return mTreeOwner->FindItemWithName(aName, mWebBrowser->mDocShellAsItem, aFoundItem); return NS_OK; } // 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 NS_OK; // failed @@ -284,15 +284,12 @@ nsDocShellTreeOwner::FindChildWithName(const PRUnichar *aName, PRBool aRecurse, if (frame) { nsCOMPtr sgo(do_QueryInterface(frame)); if (sgo) { - nsCOMPtr docshell; - sgo->GetDocShell(getter_AddRefs(docshell)); - if (docshell) { - nsCOMPtr item(do_QueryInterface(docshell)); - if (item && item.get() != aRequestor) { - rv = item->FindItemWithName(aName, mWebBrowser->mDocShellAsItem, aFoundItem); - if (NS_FAILED(rv) || *aFoundItem) - break; - } + nsCOMPtr item = + do_QueryInterface(sgo->GetDocShell()); + if (item && item != aRequestor) { + rv = item->FindItemWithName(aName, mWebBrowser->mDocShellAsItem, aFoundItem); + if (NS_FAILED(rv) || *aFoundItem) + break; } } } @@ -326,15 +323,12 @@ nsDocShellTreeOwner::FindItemWithNameAcrossWindows(const PRUnichar* aName, // it's a DOM Window. cut straight to the ScriptGlobalObject. nsCOMPtr sgo(do_QueryInterface(nextSupWindow)); if (sgo) { - nsCOMPtr docshell; - sgo->GetDocShell(getter_AddRefs(docshell)); - if (docshell) { - nsCOMPtr item(do_QueryInterface(docshell)); - if (item) { - rv = item->FindItemWithName(aName, item, aFoundItem); - if (NS_FAILED(rv) || *aFoundItem) - break; - } + nsCOMPtr item = + do_QueryInterface(sgo->GetDocShell()); + if (item) { + rv = item->FindItemWithName(aName, item, aFoundItem); + if (NS_FAILED(rv) || *aFoundItem) + break; } } } @@ -422,7 +416,7 @@ nsDocShellTreeOwner::GetPrimaryContentShell(nsIDocShellTreeItem** aShell) if(mTreeOwner) return mTreeOwner->GetPrimaryContentShell(aShell); - *aShell = (mPrimaryContentShell ? mPrimaryContentShell : mWebBrowser->mDocShellAsItem.get()); + *aShell = (mPrimaryContentShell ? mPrimaryContentShell : mWebBrowser->mDocShellAsItem); NS_IF_ADDREF(*aShell); return NS_OK; @@ -437,7 +431,7 @@ nsDocShellTreeOwner::SizeShellTo(nsIDocShellTreeItem* aShellItem, if(mTreeOwner) return mTreeOwner->SizeShellTo(aShellItem, aCX, aCY); - if(aShellItem == mWebBrowser->mDocShellAsItem.get()) + if(aShellItem == mWebBrowser->mDocShellAsItem) return mWebBrowserChrome->SizeBrowserTo(aCX, aCY); nsCOMPtr webNav(do_QueryInterface(aShellItem)); diff --git a/embedding/browser/webBrowser/nsWebBrowserContentPolicy.cpp b/embedding/browser/webBrowser/nsWebBrowserContentPolicy.cpp index 9063ad954ef..a2880c67c34 100644 --- a/embedding/browser/webBrowser/nsWebBrowserContentPolicy.cpp +++ b/embedding/browser/webBrowser/nsWebBrowserContentPolicy.cpp @@ -49,8 +49,7 @@ nsWebBrowserContentPolicy::ShouldLoad(PRInt32 contentType, if (!scriptGlobal) return NS_OK; - nsCOMPtr shell; - scriptGlobal->GetDocShell(getter_AddRefs(shell)); + nsIDocShell *shell = scriptGlobal->GetDocShell(); /* We're going to dereference shell, so make sure it isn't null */ if (!shell) return NS_OK; diff --git a/embedding/components/find/src/nsWebBrowserFind.cpp b/embedding/components/find/src/nsWebBrowserFind.cpp index 158feb1091b..98eedbf41a0 100644 --- a/embedding/components/find/src/nsWebBrowserFind.cpp +++ b/embedding/components/find/src/nsWebBrowserFind.cpp @@ -144,9 +144,8 @@ NS_IMETHODIMP nsWebBrowserFind::FindNext(PRBool *outDidFind) if (!mSearchSubFrames && !mSearchParentFrames) return NS_OK; - nsCOMPtr rootDocShell; - rv = GetDocShellFromWindow(rootFrame, getter_AddRefs(rootDocShell)); - if (NS_FAILED(rv)) return rv; + nsIDocShell *rootDocShell = GetDocShellFromWindow(rootFrame); + if (!rootDocShell) return NS_ERROR_FAILURE; PRInt32 enumDirection; if (mFindBackwards) @@ -160,12 +159,10 @@ NS_IMETHODIMP nsWebBrowserFind::FindNext(PRBool *outDidFind) if (NS_FAILED(rv)) return rv; // remember where we started - nsCOMPtr startingShell; - rv = GetDocShellFromWindow(searchFrame, getter_AddRefs(startingShell)); + nsCOMPtr startingItem = + do_QueryInterface(GetDocShellFromWindow(searchFrame), &rv); if (NS_FAILED(rv)) return rv; - nsCOMPtr startingItem = do_QueryInterface(startingShell, &rv); - if (NS_FAILED(rv)) return rv; - + nsCOMPtr curItem; // XXX We should avoid searching in frameset documents here. @@ -619,8 +616,7 @@ NS_IMETHODIMP nsWebBrowserFind::SetSearchParentFrames(PRBool aSearchParentFrames void nsWebBrowserFind::MoveFocusToCaret(nsIDOMWindow *aWindow) { - nsCOMPtr docShell; - GetDocShellFromWindow(aWindow, getter_AddRefs(docShell)); + nsIDocShell *docShell = GetDocShellFromWindow(aWindow); if (!docShell) return; nsCOMPtr presShell; @@ -683,9 +679,7 @@ nsresult nsWebBrowserFind::SearchInFrame(nsIDOMWindow* aWindow, nsCOMPtr searchFrame = do_QueryReferent(mCurrentSearchFrame); // Get the selection controller -- we'd better do this every time, // since the doc might have changed since the last time. - nsCOMPtr docShell; - rv = GetDocShellFromWindow(aWindow, getter_AddRefs(docShell)); - NS_ENSURE_SUCCESS(rv, rv); + nsIDocShell *docShell = GetDocShellFromWindow(aWindow); NS_ENSURE_ARG_POINTER(docShell); nsCOMPtr presShell; @@ -797,18 +791,15 @@ nsresult nsWebBrowserFind::OnFind(nsIDOMWindow *aFoundWindow) 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? ----------------------------------------------------------------------------*/ -nsresult -nsWebBrowserFind::GetDocShellFromWindow(nsIDOMWindow *inWindow, nsIDocShell** outDocShell) +nsIDocShell * +nsWebBrowserFind::GetDocShellFromWindow(nsIDOMWindow *inWindow) { nsCOMPtr scriptGO(do_QueryInterface(inWindow)); - if (!scriptGO) return NS_ERROR_FAILURE; + if (!scriptGO) return nsnull; - nsresult rv = scriptGO->GetDocShell(outDocShell); - if (NS_FAILED(rv)) return rv; - if (!*outDocShell) return NS_ERROR_FAILURE; - return NS_OK; + return scriptGO->GetDocShell(); } diff --git a/embedding/components/find/src/nsWebBrowserFind.h b/embedding/components/find/src/nsWebBrowserFind.h index 4306a95c6fb..2869f524b6c 100644 --- a/embedding/components/find/src/nsWebBrowserFind.h +++ b/embedding/components/find/src/nsWebBrowserFind.h @@ -82,7 +82,7 @@ protected: nsresult OnFind(nsIDOMWindow *aFoundWindow); - nsresult GetDocShellFromWindow(nsIDOMWindow *inWindow, nsIDocShell** outDocShell); + nsIDocShell *GetDocShellFromWindow(nsIDOMWindow *inWindow); void SetSelectionAndScroll(nsIDOMRange* aRange, nsISelectionController* aSelCon); diff --git a/embedding/components/printingui/src/win/nsPrintingPromptService.cpp b/embedding/components/printingui/src/win/nsPrintingPromptService.cpp index 18e91bd97a4..bfcdd6364f9 100644 --- a/embedding/components/printingui/src/win/nsPrintingPromptService.cpp +++ b/embedding/components/printingui/src/win/nsPrintingPromptService.cpp @@ -141,12 +141,9 @@ nsPrintingPromptService::GetHWNDForDOMWindow(nsIDOMWindow *aWindow) // Now we might be the Browser so check this path nsCOMPtr scriptGlobal(do_QueryInterface(aWindow)); - nsCOMPtr docShell; - scriptGlobal->GetDocShell(getter_AddRefs(docShell)); - if (!docShell) return nsnull; - nsCOMPtr treeItem; - treeItem = do_QueryInterface(docShell); + nsCOMPtr treeItem = + do_QueryInterface(scriptGlobal->GetDocShell()); if (!treeItem) return nsnull; nsCOMPtr treeOwner; diff --git a/embedding/components/windowwatcher/src/nsWWJSUtils.cpp b/embedding/components/windowwatcher/src/nsWWJSUtils.cpp index 6773fac3345..488ee7ff8b2 100644 --- a/embedding/components/windowwatcher/src/nsWWJSUtils.cpp +++ b/embedding/components/windowwatcher/src/nsWWJSUtils.cpp @@ -46,10 +46,8 @@ #include "nsWWJSUtils.h" #include "nsIXPConnect.h" -nsresult -nsWWJSUtils::nsGetStaticScriptGlobal(JSContext* aContext, - JSObject* aObj, - nsIScriptGlobalObject** aNativeGlobal) +nsIScriptGlobalObject * +nsWWJSUtils::GetStaticScriptGlobal(JSContext* aContext, JSObject* aObj) { nsISupports* supports; JSClass* clazz; @@ -57,7 +55,7 @@ nsWWJSUtils::nsGetStaticScriptGlobal(JSContext* aContext, JSObject* glob = aObj; // starting point for search if (!glob) - return NS_ERROR_FAILURE; + return nsnull; while (nsnull != (parent = JS_GetParent(aContext, glob))) glob = parent; @@ -72,37 +70,35 @@ nsWWJSUtils::nsGetStaticScriptGlobal(JSContext* aContext, !(clazz->flags & JSCLASS_HAS_PRIVATE) || !(clazz->flags & JSCLASS_PRIVATE_IS_NSISUPPORTS) || !(supports = (nsISupports*) JS_GetPrivate(aContext, glob))) { - return NS_ERROR_FAILURE; + return nsnull; } nsCOMPtr wrapper(do_QueryInterface(supports)); - NS_ENSURE_TRUE(wrapper, NS_ERROR_UNEXPECTED); + NS_ENSURE_TRUE(wrapper, nsnull); nsCOMPtr native; wrapper->GetNative(getter_AddRefs(native)); - return CallQueryInterface(native, aNativeGlobal); + nsCOMPtr sgo(do_QueryInterface(native)); + + // This will return a pointer to something we're about to release, + // but that's ok here. + return sgo; } -nsresult -nsWWJSUtils::nsGetDynamicScriptContext(JSContext *aContext, - nsIScriptContext** aScriptContext) +nsIScriptContext * +nsWWJSUtils::GetDynamicScriptContext(JSContext *aContext) { - return GetScriptContextFromJSContext(aContext, aScriptContext); + return GetScriptContextFromJSContext(aContext); } -nsresult -nsWWJSUtils::nsGetStaticScriptContext(JSContext* aContext, - JSObject* aObj, - nsIScriptContext** aScriptContext) +nsIScriptContext * +nsWWJSUtils::GetStaticScriptContext(JSContext* aContext, + JSObject* aObj) { - nsCOMPtr nativeGlobal; - nsGetStaticScriptGlobal(aContext, aObj, getter_AddRefs(nativeGlobal)); + nsIScriptGlobalObject *nativeGlobal = GetStaticScriptGlobal(aContext, aObj); if (!nativeGlobal) - return NS_ERROR_FAILURE; - nsIScriptContext* scriptContext = nsnull; - nativeGlobal->GetContext(&scriptContext); - *aScriptContext = scriptContext; - return scriptContext ? NS_OK : NS_ERROR_FAILURE; + return nsnull; + return nativeGlobal->GetContext(); } diff --git a/embedding/components/windowwatcher/src/nsWWJSUtils.h b/embedding/components/windowwatcher/src/nsWWJSUtils.h index e10c157b564..9e5122a81f9 100644 --- a/embedding/components/windowwatcher/src/nsWWJSUtils.h +++ b/embedding/components/windowwatcher/src/nsWWJSUtils.h @@ -51,19 +51,15 @@ class nsIScriptGlobalObject; class nsWWJSUtils { public: - static nsresult nsGetStaticScriptGlobal(JSContext* aContext, - JSObject* aObj, - nsIScriptGlobalObject** aNativeGlobal); + static nsIScriptGlobalObject *GetStaticScriptGlobal(JSContext* aContext, + JSObject* aObj); - static nsresult nsGetStaticScriptContext(JSContext* aContext, - JSObject* aObj, - nsIScriptContext** aScriptContext); + static nsIScriptContext *GetStaticScriptContext(JSContext* aContext, + JSObject* aObj); - static nsresult nsGetDynamicScriptGlobal(JSContext *aContext, - nsIScriptGlobalObject** aNativeGlobal); + static nsIScriptGlobalObject *GetDynamicScriptGlobal(JSContext *aContext); - static nsresult nsGetDynamicScriptContext(JSContext *aContext, - nsIScriptContext** aScriptContext); + static nsIScriptContext *GetDynamicScriptContext(JSContext *aContext); }; #endif /* nsWWJSUtils_h__ */ diff --git a/embedding/components/windowwatcher/src/nsWindowWatcher.cpp b/embedding/components/windowwatcher/src/nsWindowWatcher.cpp index 7266024c57b..b092a720cec 100644 --- a/embedding/components/windowwatcher/src/nsWindowWatcher.cpp +++ b/embedding/components/windowwatcher/src/nsWindowWatcher.cpp @@ -686,8 +686,7 @@ nsWindowWatcher::OpenWindowJS(nsIDOMWindow *aParent, // want to continue in the face of errors. nsCOMPtr parentSGO(do_QueryInterface(aParent)); if (parentSGO) { - nsCOMPtr parentDocshell; - parentSGO->GetDocShell(getter_AddRefs(parentDocshell)); + nsIDocShell *parentDocshell = parentSGO->GetDocShell(); // parentDocshell may be null if the parent got closed in the meantime if (parentDocshell) { nsCOMPtr parentContentViewer; @@ -708,13 +707,9 @@ nsWindowWatcher::OpenWindowJS(nsIDOMWindow *aParent, } if (uriToLoad) { // get the script principal and pass it to docshell + JSContext *cx = GetJSContextFromCallStack(); // get the security manager - nsCOMPtr secMan; - JSContext *cx; - nsCOMPtr scriptCX; - - cx = GetJSContextFromCallStack(); if (!cx) cx = GetJSContextFromWindow(aParent); if (!cx) { @@ -723,18 +718,15 @@ nsWindowWatcher::OpenWindowJS(nsIDOMWindow *aParent, return rv; 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 loadInfo; newDocShell->CreateLoadInfo(getter_AddRefs(loadInfo)); NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE); - if (!uriToLoadIsChrome && secMan) { + if (!uriToLoadIsChrome) { + nsCOMPtr secMan = + do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID); + nsCOMPtr principal; if (NS_FAILED(secMan->GetSubjectPrincipal(getter_AddRefs(principal)))) return NS_ERROR_FAILURE; @@ -754,10 +746,8 @@ nsWindowWatcher::OpenWindowJS(nsIDOMWindow *aParent, // get its document, if any if (stack && NS_SUCCEEDED(stack->Peek(&ccx)) && ccx) { - - nsCOMPtr sgo; - nsWWJSUtils::nsGetStaticScriptGlobal(ccx, ::JS_GetGlobalObject(ccx), - getter_AddRefs(sgo)); + nsIScriptGlobalObject *sgo = + nsWWJSUtils::GetStaticScriptGlobal(ccx, ::JS_GetGlobalObject(ccx)); nsCOMPtr w(do_QueryInterface(sgo)); if (w) { @@ -1112,12 +1102,9 @@ nsWindowWatcher::URIfromURL(const char *aURL, in nsGlobalWindow.cpp.) */ JSContext *cx = GetJSContextFromCallStack(); if (cx) { - nsCOMPtr scriptcx; - nsWWJSUtils::nsGetDynamicScriptContext(cx, getter_AddRefs(scriptcx)); + nsIScriptContext *scriptcx = nsWWJSUtils::GetDynamicScriptContext(cx); if (scriptcx) { - nsCOMPtr gobj; - scriptcx->GetGlobalObject(getter_AddRefs(gobj)); - baseWindow = do_QueryInterface(gobj); + baseWindow = do_QueryInterface(scriptcx->GetGlobalObject()); } } @@ -1642,8 +1629,7 @@ nsWindowWatcher::AttachArguments(nsIDOMWindow *aWindow, nsCOMPtr scriptGlobal(do_QueryInterface(aWindow)); NS_ENSURE_TRUE(scriptGlobal, NS_ERROR_UNEXPECTED); - nsCOMPtr scriptContext; - scriptGlobal->GetContext(getter_AddRefs(scriptContext)); + nsIScriptContext *scriptContext = scriptGlobal->GetContext(); if (scriptContext) { JSContext *cx; cx = (JSContext *)scriptContext->GetNativeContext(); @@ -1981,8 +1967,7 @@ nsWindowWatcher::GetWindowTreeItem(nsIDOMWindow *inWindow, nsCOMPtr sgo(do_QueryInterface(inWindow)); if (sgo) { - nsCOMPtr docshell; - sgo->GetDocShell(getter_AddRefs(docshell)); + nsIDocShell *docshell = sgo->GetDocShell(); if (docshell) CallQueryInterface(docshell, outTreeItem); } @@ -2020,8 +2005,7 @@ nsWindowWatcher::GetJSContextFromWindow(nsIDOMWindow *aWindow) if (aWindow) { nsCOMPtr sgo(do_QueryInterface(aWindow)); if (sgo) { - nsCOMPtr scx; - sgo->GetContext(getter_AddRefs(scx)); + nsIScriptContext *scx = sgo->GetContext(); if (scx) cx = (JSContext *) scx->GetNativeContext(); } diff --git a/extensions/cookie/nsImgManager.cpp b/extensions/cookie/nsImgManager.cpp index 810179221e3..c97176ec226 100644 --- a/extensions/cookie/nsImgManager.cpp +++ b/extensions/cookie/nsImgManager.cpp @@ -71,10 +71,9 @@ GetRootDocShell(nsIDOMWindow *aWindow) nsCOMPtr globalObj(do_QueryInterface(aWindow)); if (globalObj) { - nsCOMPtr docShell; - globalObj->GetDocShell(getter_AddRefs(docShell)); + nsCOMPtr docShellTreeItem = + do_QueryInterface(globalObj->GetDocShell()); - nsCOMPtr docShellTreeItem(do_QueryInterface(docShell)); if (docShellTreeItem) { nsCOMPtr rootItem; docShellTreeItem->GetRootTreeItem(getter_AddRefs(rootItem)); diff --git a/extensions/inspector/base/src/inLayoutUtils.cpp b/extensions/inspector/base/src/inLayoutUtils.cpp index fdc970761e3..9010352ce10 100644 --- a/extensions/inspector/base/src/inLayoutUtils.cpp +++ b/extensions/inspector/base/src/inLayoutUtils.cpp @@ -83,11 +83,9 @@ nsIPresShell* inLayoutUtils::GetPresShellFor(nsISupports* aThing) { nsCOMPtr so = do_QueryInterface(aThing); - nsCOMPtr docShell; - so->GetDocShell(getter_AddRefs(docShell)); - + nsCOMPtr presShell; - docShell->GetPresShell(getter_AddRefs(presShell)); + so->GetDocShell()->GetPresShell(getter_AddRefs(presShell)); return presShell; } diff --git a/extensions/layout-debug/src/nsLayoutDebuggingTools.cpp b/extensions/layout-debug/src/nsLayoutDebuggingTools.cpp index 2e38e57fea9..3393b23e885 100644 --- a/extensions/layout-debug/src/nsLayoutDebuggingTools.cpp +++ b/extensions/layout-debug/src/nsLayoutDebuggingTools.cpp @@ -153,7 +153,7 @@ nsLayoutDebuggingTools::Init(nsIDOMWindow *aWin) nsCOMPtr global = do_QueryInterface(aWin); if (!global) return NS_ERROR_UNEXPECTED; - global->GetDocShell(getter_AddRefs(mDocShell)); + mDocShell = global->GetDocShell(); } mPrefs = do_GetService(NS_PREF_CONTRACTID); diff --git a/extensions/layout-debug/src/nsRegressionTester.cpp b/extensions/layout-debug/src/nsRegressionTester.cpp index 5d97a9712a0..e4506b242b4 100644 --- a/extensions/layout-debug/src/nsRegressionTester.cpp +++ b/extensions/layout-debug/src/nsRegressionTester.cpp @@ -178,6 +178,9 @@ nsRegressionTester::GetDocShellFromWindow(nsIDOMWindow* inWindow, nsIDocShell** { nsCOMPtr scriptObj(do_QueryInterface(inWindow)); if (!scriptObj) return NS_ERROR_FAILURE; - - return scriptObj->GetDocShell(outShell); + + *outShell = scriptObj->GetDocShell(); + NS_IF_ADDREF(*outShell); + + return NS_OK; } diff --git a/extensions/transformiix/source/xslt/txMozillaXMLOutput.cpp b/extensions/transformiix/source/xslt/txMozillaXMLOutput.cpp index 480d61e1b41..7a011d62675 100644 --- a/extensions/transformiix/source/xslt/txMozillaXMLOutput.cpp +++ b/extensions/transformiix/source/xslt/txMozillaXMLOutput.cpp @@ -210,9 +210,8 @@ void txMozillaXMLOutput::endDocument() nsCOMPtr doc = do_QueryInterface(mDocument); nsIScriptGlobalObject *sgo = doc->GetScriptGlobalObject(); if (sgo) { - nsCOMPtr docShell; - sgo->GetDocShell(getter_AddRefs(docShell)); - nsCOMPtr refURI = do_QueryInterface(docShell); + nsCOMPtr refURI = + do_QueryInterface(sgo->GetDocShell()); if (refURI) { refURI->SetupRefreshURIFromHeader(doc->GetBaseURI(), mRefreshString); diff --git a/extensions/wallet/src/nsWalletService.cpp b/extensions/wallet/src/nsWalletService.cpp index f0e2aafd544..68f470e91c1 100644 --- a/extensions/wallet/src/nsWalletService.cpp +++ b/extensions/wallet/src/nsWalletService.cpp @@ -124,8 +124,7 @@ nsWalletlibService::WALLET_RequestToCapture(nsIDOMWindowInternal* aWin, nsCOMPtr scriptGlobalObject; scriptGlobalObject = do_QueryInterface(aWin); - nsCOMPtr docShell; - scriptGlobalObject->GetDocShell(getter_AddRefs(docShell)); + nsIDocShell *docShell = scriptGlobalObject->GetDocShell(); nsCOMPtr presShell; if(docShell) @@ -152,8 +151,7 @@ nsWalletlibService::WALLET_Prefill(PRBool quick, { nsCOMPtr scriptGlobalObject; scriptGlobalObject = do_QueryInterface(aWin); - nsCOMPtr docShell; - scriptGlobalObject->GetDocShell(getter_AddRefs(docShell)); + nsIDocShell *docShell = scriptGlobalObject->GetDocShell(); nsCOMPtr presShell; if(docShell) diff --git a/extensions/wallet/walletpreview/nsWalletPreview.cpp b/extensions/wallet/walletpreview/nsWalletPreview.cpp index 82d47f4bb33..63f150fe5f7 100644 --- a/extensions/wallet/walletpreview/nsWalletPreview.cpp +++ b/extensions/wallet/walletpreview/nsWalletPreview.cpp @@ -93,9 +93,9 @@ static void DOMWindowToTreeOwner( return; // with webWindow unchanged -- its constructor gives it a null ptr } nsCOMPtr globalScript(do_QueryInterface(DOMWindow)); - nsCOMPtr docShell; + nsIDocShell *docShell = nsnull; if (globalScript) { - globalScript->GetDocShell(getter_AddRefs(docShell)); + docShell = globalScript->GetDocShell(); } nsCOMPtr docShellAsItem(do_QueryInterface(docShell)); if(!docShellAsItem) diff --git a/extensions/xmlextras/base/src/nsDOMParser.cpp b/extensions/xmlextras/base/src/nsDOMParser.cpp index 98e28c2f9ad..2a65fcea6a5 100644 --- a/extensions/xmlextras/base/src/nsDOMParser.cpp +++ b/extensions/xmlextras/base/src/nsDOMParser.cpp @@ -469,13 +469,11 @@ nsDOMParser::ParseFromStream(nsIInputStream *stream, rv = cc->GetJSContext(&cx); if (NS_FAILED(rv)) return NS_ERROR_FAILURE; - nsCOMPtr scriptContext; - GetScriptContextFromJSContext(cx, getter_AddRefs(scriptContext)); + nsIScriptContext *scriptContext = GetScriptContextFromJSContext(cx); if (scriptContext) { - nsCOMPtr globalObject; - scriptContext->GetGlobalObject(getter_AddRefs(globalObject)); + nsCOMPtr window = + do_QueryInterface(scriptContext->GetGlobalObject()); - nsCOMPtr window = do_QueryInterface(globalObject); if (window) { nsCOMPtr domdoc; window->GetDocument(getter_AddRefs(domdoc)); diff --git a/extensions/xmlextras/base/src/nsXMLHttpRequest.cpp b/extensions/xmlextras/base/src/nsXMLHttpRequest.cpp index 830b97b6986..a0c2361dd8b 100644 --- a/extensions/xmlextras/base/src/nsXMLHttpRequest.cpp +++ b/extensions/xmlextras/base/src/nsXMLHttpRequest.cpp @@ -112,30 +112,24 @@ static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); XML_HTTP_REQUEST_SENT | \ XML_HTTP_REQUEST_STOPPED) -static void -GetCurrentContext(nsIScriptContext **aScriptContext) +static nsIScriptContext * +GetCurrentContext() { - *aScriptContext = nsnull; - // Get JSContext from stack. nsCOMPtr stack = do_GetService("@mozilla.org/js/xpc/ContextStack;1"); if (!stack) { - return; + return nsnull; } JSContext *cx; - if (NS_FAILED(stack->Peek(&cx))) { - return; + if (NS_FAILED(stack->Peek(&cx)) || !cx) { + return nsnull; } - if (cx) { - GetScriptContextFromJSContext(cx, aScriptContext); - } - - return; + return GetScriptContextFromJSContext(cx); } /** @@ -151,9 +145,8 @@ GetDocumentFromScriptContext(nsIScriptContext *aScriptContext) if (!aScriptContext) return nsnull; - nsCOMPtr global; - aScriptContext->GetGlobalObject(getter_AddRefs(global)); - nsCOMPtr window = do_QueryInterface(global); + nsCOMPtr window = + do_QueryInterface(aScriptContext->GetGlobalObject()); nsIDocument *doc = nsnull; if (window) { nsCOMPtr domdoc; @@ -233,7 +226,7 @@ nsXMLHttpRequest::AddEventListener(const nsAString& type, else { return NS_ERROR_INVALID_ARG; } - GetCurrentContext(getter_AddRefs(mScriptContext)); + mScriptContext = GetCurrentContext(); return NS_OK; } @@ -290,7 +283,7 @@ nsXMLHttpRequest::SetOnreadystatechange(nsIOnReadystatechangeHandler * aOnreadys { mOnReadystatechangeListener = aOnreadystatechange; - GetCurrentContext(getter_AddRefs(mScriptContext)); + mScriptContext = GetCurrentContext(); return NS_OK; } @@ -313,7 +306,7 @@ nsXMLHttpRequest::SetOnload(nsIDOMEventListener * aOnLoad) { mOnLoadListener = aOnLoad; - GetCurrentContext(getter_AddRefs(mScriptContext)); + mScriptContext = GetCurrentContext(); return NS_OK; } @@ -335,7 +328,7 @@ nsXMLHttpRequest::SetOnerror(nsIDOMEventListener * aOnerror) { mOnErrorListener = aOnerror; - GetCurrentContext(getter_AddRefs(mScriptContext)); + mScriptContext = GetCurrentContext(); return NS_OK; } @@ -602,7 +595,7 @@ nsXMLHttpRequest::GetLoadGroup(nsILoadGroup **aLoadGroup) *aLoadGroup = nsnull; if (!mScriptContext) { - GetCurrentContext(getter_AddRefs(mScriptContext)); + mScriptContext = GetCurrentContext(); } nsCOMPtr doc = GetDocumentFromScriptContext(mScriptContext); @@ -620,7 +613,7 @@ nsXMLHttpRequest::GetBaseURI(nsIURI **aBaseURI) *aBaseURI = nsnull; if (!mScriptContext) { - GetCurrentContext(getter_AddRefs(mScriptContext)); + mScriptContext = GetCurrentContext(); if (!mScriptContext) { return NS_OK; } @@ -1321,7 +1314,7 @@ nsXMLHttpRequest::Send(nsIVariant *aBody) if (!mScriptContext) { // 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 diff --git a/js/jsd/jsd_xpc.cpp b/js/jsd/jsd_xpc.cpp index fb1afaf17f0..7348351b154 100644 --- a/js/jsd/jsd_xpc.cpp +++ b/js/jsd/jsd_xpc.cpp @@ -1606,7 +1606,9 @@ jsdContext::GetScriptsEnabled (PRBool *_rval) if (!context) return NS_ERROR_NO_INTERFACE; - return context->GetScriptsEnabled(_rval); + *_rval = context->GetScriptsEnabled(); + + return NS_OK; } NS_IMETHODIMP @@ -1617,7 +1619,9 @@ jsdContext::SetScriptsEnabled (PRBool _rval) if (!context) return NS_ERROR_NO_INTERFACE; - return context->SetScriptsEnabled(_rval, PR_TRUE); + context->SetScriptsEnabled(_rval, PR_TRUE); + + return NS_OK; } /* Stack Frames */ diff --git a/layout/generic/nsImageMap.cpp b/layout/generic/nsImageMap.cpp index 076a918d188..33aa852041e 100644 --- a/layout/generic/nsImageMap.cpp +++ b/layout/generic/nsImageMap.cpp @@ -891,10 +891,10 @@ nsImageMap::UpdateAreas() nsresult nsImageMap::AddArea(nsIContent* aArea) { - nsAutoString shape, coords, baseURL, noHref; + nsAutoString shape, coords; aArea->GetAttr(kNameSpaceID_None, nsHTMLAtoms::shape, shape); 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 nsCOMPtr rec(do_QueryInterface(aArea)); diff --git a/layout/generic/nsObjectFrame.cpp b/layout/generic/nsObjectFrame.cpp index c86c323d4c6..70056946ef5 100644 --- a/layout/generic/nsObjectFrame.cpp +++ b/layout/generic/nsObjectFrame.cpp @@ -1920,8 +1920,7 @@ nsObjectFrame::NotifyContentObjectWrapper() if (!sgo) return; - nsCOMPtr scx; - sgo->GetContext(getter_AddRefs(scx)); + nsIScriptContext *scx = sgo->GetContext(); if (!scx) return; diff --git a/layout/html/base/src/nsImageMap.cpp b/layout/html/base/src/nsImageMap.cpp index 076a918d188..33aa852041e 100644 --- a/layout/html/base/src/nsImageMap.cpp +++ b/layout/html/base/src/nsImageMap.cpp @@ -891,10 +891,10 @@ nsImageMap::UpdateAreas() nsresult nsImageMap::AddArea(nsIContent* aArea) { - nsAutoString shape, coords, baseURL, noHref; + nsAutoString shape, coords; aArea->GetAttr(kNameSpaceID_None, nsHTMLAtoms::shape, shape); 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 nsCOMPtr rec(do_QueryInterface(aArea)); diff --git a/layout/html/base/src/nsObjectFrame.cpp b/layout/html/base/src/nsObjectFrame.cpp index c86c323d4c6..70056946ef5 100644 --- a/layout/html/base/src/nsObjectFrame.cpp +++ b/layout/html/base/src/nsObjectFrame.cpp @@ -1920,8 +1920,7 @@ nsObjectFrame::NotifyContentObjectWrapper() if (!sgo) return; - nsCOMPtr scx; - sgo->GetContext(getter_AddRefs(scx)); + nsIScriptContext *scx = sgo->GetContext(); if (!scx) return; diff --git a/layout/printing/nsPrintEngine.cpp b/layout/printing/nsPrintEngine.cpp index ac6131575fe..676f2c47fcc 100644 --- a/layout/printing/nsPrintEngine.cpp +++ b/layout/printing/nsPrintEngine.cpp @@ -1708,9 +1708,7 @@ nsPrintEngine::IsThereARangeSelection(nsIDOMWindow* aDOMWin) nsCOMPtr presShell; if (aDOMWin) { nsCOMPtr scriptObj(do_QueryInterface(aDOMWin)); - nsCOMPtr docShell; - scriptObj->GetDocShell(getter_AddRefs(docShell)); - docShell->GetPresShell(getter_AddRefs(presShell)); + scriptObj->GetDocShell()->GetPresShell(getter_AddRefs(presShell)); } // 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 nsCOMPtr scriptObj(do_QueryInterface(aDOMWindow)); if (scriptObj) { - nsCOMPtr docShell; - scriptObj->GetDocShell(getter_AddRefs(docShell)); + nsCOMPtr docShellAsItem = + do_QueryInterface(scriptObj->GetDocShell()); - nsCOMPtr docShellAsItem(do_QueryInterface(docShell)); if (docShellAsItem) { // get this DocViewer webshell nsCOMPtr thisDVWebShell(do_QueryInterface(mContainer)); @@ -4440,9 +4437,8 @@ nsPrintEngine::TurnScriptingOn(PRBool aDoTurnOn) // get the script global object nsIScriptGlobalObject *scriptGlobalObj = mDocument->GetScriptGlobalObject(); NS_ASSERTION(scriptGlobalObj, "Can't get nsIScriptGlobalObject"); - nsCOMPtr scx; - nsresult rv = scriptGlobalObj->GetContext(getter_AddRefs(scx)); - NS_ASSERTION(NS_SUCCEEDED(rv) && scx, "Can't get nsIScriptContext"); + nsIScriptContext *scx = scriptGlobalObj->GetContext(); + NS_ASSERTION(scx, "Can't get nsIScriptContext"); scx->SetScriptsEnabled(aDoTurnOn, PR_TRUE); } diff --git a/layout/xul/base/src/nsResizerFrame.cpp b/layout/xul/base/src/nsResizerFrame.cpp index 2b1a7b65c4e..26993ead977 100644 --- a/layout/xul/base/src/nsResizerFrame.cpp +++ b/layout/xul/base/src/nsResizerFrame.cpp @@ -157,10 +157,8 @@ nsResizerFrame::HandleEvent(nsIPresContext* aPresContext, nsIScriptGlobalObject *scriptGlobalObject = document->GetScriptGlobalObject(); NS_ENSURE_TRUE(scriptGlobalObject, NS_ERROR_FAILURE); - nsCOMPtr docShell; - scriptGlobalObject->GetDocShell(getter_AddRefs(docShell)); - - nsCOMPtr docShellAsItem(do_QueryInterface(docShell)); + nsCOMPtr docShellAsItem = + do_QueryInterface(scriptGlobalObject->GetDocShell()); NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE); nsCOMPtr treeOwner; diff --git a/layout/xul/base/src/nsXULTooltipListener.cpp b/layout/xul/base/src/nsXULTooltipListener.cpp index 435bca26f5d..78e322ca5bd 100644 --- a/layout/xul/base/src/nsXULTooltipListener.cpp +++ b/layout/xul/base/src/nsXULTooltipListener.cpp @@ -566,8 +566,9 @@ nsXULTooltipListener::GetTooltipFor(nsIContent* aTarget, nsIContent** aTooltip) } nsIScriptGlobalObject *global = document->GetScriptGlobalObject(); if (global) { - nsCOMPtr context; - if (NS_SUCCEEDED(global->GetContext(getter_AddRefs(context))) && context) { + nsIScriptContext *context = global->GetContext(); + + if (context) { nsCOMPtr domWindow = do_QueryInterface(global); if (!domWindow) return NS_ERROR_FAILURE; diff --git a/mailnews/addrbook/src/nsAddressBook.cpp b/mailnews/addrbook/src/nsAddressBook.cpp index 0517f6b92ae..d23f9c04ac7 100644 --- a/mailnews/addrbook/src/nsAddressBook.cpp +++ b/mailnews/addrbook/src/nsAddressBook.cpp @@ -187,19 +187,19 @@ NS_IMETHODIMP nsAddressBook::NewAddressBook(nsIAbDirectoryProperties *aPropertie nsresult rv; - nsCOMPtr rdfService = do_GetService (NS_RDF_CONTRACTID "/rdf-service;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr rdfService = do_GetService (NS_RDF_CONTRACTID "/rdf-service;1", &rv); + NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr parentResource; - rv = rdfService->GetResource(NS_LITERAL_CSTRING(kAllDirectoryRoot), - getter_AddRefs(parentResource)); - NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr parentResource; + rv = rdfService->GetResource(NS_LITERAL_CSTRING(kAllDirectoryRoot), + getter_AddRefs(parentResource)); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr parentDir = do_QueryInterface(parentResource, &rv); + NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr parentDir = do_QueryInterface(parentResource, &rv); - NS_ENSURE_SUCCESS(rv, rv); - rv = parentDir->CreateNewDirectory(aProperties); - return rv; + return rv; } NS_IMETHODIMP nsAddressBook::ModifyAddressBook @@ -245,42 +245,38 @@ nsresult nsAddressBook::DoCommand(nsIRDFDataSource* db, nsISupportsArray *srcArray, nsISupportsArray *argumentArray) { + nsresult rv = NS_OK; - nsresult rv = NS_OK; + nsCOMPtr rdfService = do_GetService (NS_RDF_CONTRACTID "/rdf-service;1", &rv); + NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr rdfService = do_GetService (NS_RDF_CONTRACTID "/rdf-service;1", &rv); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr commandResource; - rv = rdfService->GetResource(command, getter_AddRefs(commandResource)); - if(NS_SUCCEEDED(rv)) - { - rv = db->DoCommand(srcArray, commandResource, argumentArray); - } - - return rv; + nsCOMPtr commandResource; + rv = rdfService->GetResource(command, getter_AddRefs(commandResource)); + if(NS_SUCCEEDED(rv)) + { + rv = db->DoCommand(srcArray, commandResource, argumentArray); + } + return rv; } NS_IMETHODIMP nsAddressBook::SetDocShellWindow(nsIDOMWindowInternal *aWin) { - NS_PRECONDITION(aWin != nsnull, "null ptr"); - if (!aWin) - return NS_ERROR_NULL_POINTER; + NS_PRECONDITION(aWin != nsnull, "null ptr"); + if (!aWin) + return NS_ERROR_NULL_POINTER; - nsCOMPtr globalObj( do_QueryInterface(aWin) ); - if (!globalObj) { - return NS_ERROR_FAILURE; - } - - globalObj->GetDocShell(&mDocShell); - if (!mDocShell) - return NS_ERROR_NOT_INITIALIZED; + nsCOMPtr globalObj( do_QueryInterface(aWin) ); + if (!globalObj) { + return NS_ERROR_FAILURE; + } - // Make reference weak by releasing - mDocShell->Release(); - - return NS_OK; + // mDocShell is a weak reference + mDocShell = globalObj->GetDocShell(); + if (!mDocShell) + return NS_ERROR_NOT_INITIALIZED; + + return NS_OK; } NS_IMETHODIMP nsAddressBook::GetAbDatabaseFromURI(const char *aURI, nsIAddrDatabase **aDB) @@ -427,9 +423,9 @@ public: AddressBookParser::AddressBookParser(nsIFileSpec * fileSpec, PRBool migrating, nsIAddrDatabase *db, PRBool bStoreLocAsHome, PRBool bImportingComm4x) { - mFileSpec = fileSpec; - mDbUri = nsnull; - mMigrating = migrating; + mFileSpec = fileSpec; + mDbUri = nsnull; + mMigrating = migrating; mDatabase = db; if (mDatabase) mDeleteDB = PR_FALSE; diff --git a/mailnews/base/src/nsMessenger.cpp b/mailnews/base/src/nsMessenger.cpp index 6eb225284d7..a80457e6bb5 100644 --- a/mailnews/base/src/nsMessenger.cpp +++ b/mailnews/base/src/nsMessenger.cpp @@ -370,9 +370,8 @@ nsMessenger::SetWindow(nsIDOMWindowInternal *aWin, nsIMsgWindow *aMsgWindow) nsCOMPtr globalObj( do_QueryInterface(aWin) ); NS_ENSURE_TRUE(globalObj, NS_ERROR_FAILURE); - - nsCOMPtr docShell; - globalObj->GetDocShell(getter_AddRefs(docShell)); + + nsIDocShell *docShell = globalObj->GetDocShell(); nsCOMPtr docShellAsItem(do_QueryInterface(docShell)); NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE); diff --git a/mailnews/base/src/nsMessengerWinIntegration.cpp b/mailnews/base/src/nsMessengerWinIntegration.cpp index 394a13d79f0..42ce332f213 100644 --- a/mailnews/base/src/nsMessengerWinIntegration.cpp +++ b/mailnews/base/src/nsMessengerWinIntegration.cpp @@ -94,11 +94,9 @@ HWND hwndForDOMWindow( nsISupports *window ) nsCOMPtr ppScriptGlobalObj( do_QueryInterface(window) ); if ( !ppScriptGlobalObj ) return 0; - nsCOMPtr ppDocShell; - ppScriptGlobalObj->GetDocShell( getter_AddRefs( ppDocShell ) ); - if ( !ppDocShell ) return 0; - nsCOMPtr ppBaseWindow( do_QueryInterface( ppDocShell ) ); + nsCOMPtr ppBaseWindow = + do_QueryInterface( ppScriptGlobalObj->GetDocShell() ); if (!ppBaseWindow) return 0; nsCOMPtr ppWidget; @@ -580,7 +578,7 @@ void nsMessengerWinIntegration::FillToolTipInfo() folder = do_QueryReferent(weakReference); if (folder) { - folder->GetPrettiestName(getter_Copies(accountName)); + folder->GetPrettiestName(getter_Copies(accountName)); numNewMessages = 0; folder->GetNumNewMessages(PR_TRUE, &numNewMessages); @@ -611,8 +609,8 @@ void nsMessengerWinIntegration::FillToolTipInfo() if (maxTooltipSize >= toolTipText.Length() + accountName.Length() + finalText.Length() + 2) { if (index > 0) - toolTipText.Append(NS_LITERAL_STRING("\n").get()); - toolTipText.Append(accountName); + toolTipText.Append(NS_LITERAL_STRING("\n").get()); + toolTipText.Append(accountName); toolTipText.Append(NS_LITERAL_STRING(" ")); toolTipText.Append(finalText); } diff --git a/mailnews/base/src/nsMsgMailSession.cpp b/mailnews/base/src/nsMsgMailSession.cpp index 42c5d47b5a3..f751c7a7cd4 100644 --- a/mailnews/base/src/nsMsgMailSession.cpp +++ b/mailnews/base/src/nsMsgMailSession.cpp @@ -341,9 +341,8 @@ nsresult nsMsgMailSession::GetTopmostMsgWindow(nsIMsgWindow* *aMsgWindow) nsCOMPtr globalObj = do_QueryInterface(topMostWindow, &rv); NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr topDocShell; // use this for the match - rv = globalObj->GetDocShell(getter_AddRefs(topDocShell)); - NS_ENSURE_SUCCESS(rv, rv); + // use this for the match + nsIDocShell *topDocShell = globalObj->GetDocShell(); // loop for the msgWindow array to find the match nsCOMPtr docShell; diff --git a/mailnews/base/src/nsMsgPrintEngine.cpp b/mailnews/base/src/nsMsgPrintEngine.cpp index 823142947fe..a308c282f71 100644 --- a/mailnews/base/src/nsMsgPrintEngine.cpp +++ b/mailnews/base/src/nsMsgPrintEngine.cpp @@ -249,10 +249,8 @@ nsMsgPrintEngine::SetWindow(nsIDOMWindowInternal *aWin) nsCOMPtr globalObj( do_QueryInterface(aWin) ); NS_ENSURE_TRUE(globalObj, NS_ERROR_FAILURE); - nsCOMPtr docShell; - globalObj->GetDocShell(getter_AddRefs(docShell)); - - nsCOMPtr docShellAsItem(do_QueryInterface(docShell)); + nsCOMPtr docShellAsItem = + do_QueryInterface(globalObj->GetDocShell()); NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE); nsCOMPtr rootAsItem; @@ -291,12 +289,9 @@ nsMsgPrintEngine::ShowWindow(PRBool aShow) nsCOMPtr globalScript = do_QueryInterface(mWindow, &rv); NS_ENSURE_SUCCESS(rv,rv); - nsCOMPtr docShell; - rv = globalScript->GetDocShell(getter_AddRefs(docShell)); - NS_ENSURE_SUCCESS(rv,rv); - - nsCOMPtr webShell = do_QueryInterface(docShell, &rv); + nsCOMPtr webShell = + do_QueryInterface(globalScript->GetDocShell(), &rv); NS_ENSURE_SUCCESS(rv,rv); nsCOMPtr webShellContainer; @@ -307,7 +302,7 @@ nsMsgPrintEngine::ShowWindow(PRBool aShow) nsCOMPtr webShellWindow = do_QueryInterface(webShellContainer, &rv); NS_ENSURE_SUCCESS(rv,rv); - nsCOMPtr treeItem(do_QueryInterface(docShell, &rv)); + nsCOMPtr treeItem(do_QueryInterface(webShell, &rv)); NS_ENSURE_SUCCESS(rv,rv); nsCOMPtr treeOwner; diff --git a/mailnews/base/src/nsMsgWindow.cpp b/mailnews/base/src/nsMsgWindow.cpp index 0aeefd4224d..3a5070e1c9d 100644 --- a/mailnews/base/src/nsMsgWindow.cpp +++ b/mailnews/base/src/nsMsgWindow.cpp @@ -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 ***** * Version: NPL 1.1/GPL 2.0/LGPL 2.1 * @@ -107,13 +107,13 @@ nsresult nsMsgWindow::Init() if (NS_SUCCEEDED(rv)) { - rv = compMgr->CreateInstance(kTransactionManagerCID, nsnull, - NS_GET_IID(nsITransactionManager), - getter_AddRefs(mTransactionManager)); - if (NS_SUCCEEDED(rv)) - mTransactionManager->SetMaxTransactionCount(-1); + rv = compMgr->CreateInstance(kTransactionManagerCID, nsnull, + NS_GET_IID(nsITransactionManager), + getter_AddRefs(mTransactionManager)); + if (NS_SUCCEEDED(rv)) + mTransactionManager->SetMaxTransactionCount(-1); } - + return rv; } @@ -199,7 +199,6 @@ NS_IMETHODIMP nsMsgWindow::GetStatusFeedback(nsIMsgStatusFeedback * *aStatusFeed NS_IMETHODIMP nsMsgWindow::SetStatusFeedback(nsIMsgStatusFeedback * aStatusFeedback) { - nsCOMPtr messageWindowDocShell; GetMessageWindowDocShell(getter_AddRefs(messageWindowDocShell)); @@ -353,36 +352,36 @@ NS_IMETHODIMP nsMsgWindow::SetDOMWindow(nsIDOMWindowInternal *aWindow) nsresult rv = NS_OK; nsCOMPtr globalScript(do_QueryInterface(aWindow)); - nsCOMPtr docShell; + nsIDocShell *docShell = nsnull; if (globalScript) - globalScript->GetDocShell(getter_AddRefs(docShell)); + docShell = globalScript->GetDocShell(); - nsCOMPtr docShellAsItem(do_QueryInterface(docShell)); + nsCOMPtr docShellAsItem(do_QueryInterface(docShell)); - if(docShellAsItem) - { - nsCOMPtr rootAsItem; - docShellAsItem->GetSameTypeRootTreeItem(getter_AddRefs(rootAsItem)); + if(docShellAsItem) + { + nsCOMPtr rootAsItem; + docShellAsItem->GetSameTypeRootTreeItem(getter_AddRefs(rootAsItem)); - nsCOMPtr rootAsShell(do_QueryInterface(rootAsItem)); - SetRootDocShell(rootAsShell); + nsCOMPtr rootAsShell(do_QueryInterface(rootAsItem)); + SetRootDocShell(rootAsShell); - // force ourselves to figure out the message pane - nsCOMPtr messageWindowDocShell; - GetMessageWindowDocShell(getter_AddRefs(messageWindowDocShell)); - SetStatusFeedback(mStatusFeedback); - } + // force ourselves to figure out the message pane + nsCOMPtr messageWindowDocShell; + GetMessageWindowDocShell(getter_AddRefs(messageWindowDocShell)); + SetStatusFeedback(mStatusFeedback); + } //Get nsIMsgWindowCommands object - nsCOMPtr xpConnectObj; - nsCOMPtr piDOMWindow(do_QueryInterface(aWindow)); - if (piDOMWindow) - { - piDOMWindow->GetObjectProperty(NS_LITERAL_STRING("MsgWindowCommands").get(), getter_AddRefs(xpConnectObj)); - mMsgWindowCommands = do_QueryInterface(xpConnectObj); - } + nsCOMPtr xpConnectObj; + nsCOMPtr piDOMWindow(do_QueryInterface(aWindow)); + if (piDOMWindow) + { + piDOMWindow->GetObjectProperty(NS_LITERAL_STRING("MsgWindowCommands").get(), getter_AddRefs(xpConnectObj)); + mMsgWindowCommands = do_QueryInterface(xpConnectObj); + } - return rv; + return rv; } NS_IMETHODIMP nsMsgWindow::StopUrls() @@ -512,56 +511,56 @@ NS_IMETHODIMP nsMsgWindow::GetPromptDialog(nsIPrompt **aPrompt) nsCOMPtr rootShell(do_QueryReferent(mRootDocShellWeak)); if (rootShell) { - nsCOMPtr dialog; - dialog = do_GetInterface(rootShell, &rv); - if (dialog) - { - *aPrompt = dialog; - NS_ADDREF(*aPrompt); - } - return rv; + nsCOMPtr dialog; + dialog = do_GetInterface(rootShell, &rv); + if (dialog) + { + *aPrompt = dialog; + NS_ADDREF(*aPrompt); + } + return rv; } else - return NS_ERROR_NULL_POINTER; + return NS_ERROR_NULL_POINTER; } NS_IMETHODIMP nsMsgWindow::DisplayHTMLInMessagePane(const PRUnichar *title, const PRUnichar *body) { - nsresult rv; + nsresult rv; - if (mMsgPaneController) - mMsgPaneController->ClearMsgPane(); + if (mMsgPaneController) + mMsgPaneController->ClearMsgPane(); - nsString htmlStr; - htmlStr.Append(NS_LITERAL_STRING("").get()); - htmlStr.Append(body); - htmlStr.Append(NS_LITERAL_STRING("").get()); + nsString htmlStr; + htmlStr.Append(NS_LITERAL_STRING("").get()); + htmlStr.Append(body); + htmlStr.Append(NS_LITERAL_STRING("").get()); - char *encodedHtml = PL_Base64Encode(NS_ConvertUCS2toUTF8(htmlStr).get(), 0, nsnull); - if (!encodedHtml) - return NS_ERROR_OUT_OF_MEMORY; + char *encodedHtml = PL_Base64Encode(NS_ConvertUCS2toUTF8(htmlStr).get(), 0, nsnull); + if (!encodedHtml) + return NS_ERROR_OUT_OF_MEMORY; - nsCString dataSpec; - dataSpec = "data:text/html;base64,"; - dataSpec += encodedHtml; + nsCString dataSpec; + dataSpec = "data:text/html;base64,"; + dataSpec += encodedHtml; - PR_FREEIF(encodedHtml); + PR_FREEIF(encodedHtml); - nsCOMPtr uri = do_CreateInstance("@mozilla.org/network/simple-uri;1"); - if (!uri) return NS_ERROR_UNEXPECTED; + nsCOMPtr uri = do_CreateInstance("@mozilla.org/network/simple-uri;1"); + if (!uri) return NS_ERROR_UNEXPECTED; - rv = uri->SetSpec(dataSpec); - NS_ENSURE_SUCCESS(rv,rv); + rv = uri->SetSpec(dataSpec); + NS_ENSURE_SUCCESS(rv,rv); - nsCOMPtr docShell; - GetMessageWindowDocShell(getter_AddRefs(docShell)); - if (!docShell) return NS_ERROR_UNEXPECTED; + nsCOMPtr docShell; + GetMessageWindowDocShell(getter_AddRefs(docShell)); + if (!docShell) return NS_ERROR_UNEXPECTED; - rv = docShell->LoadURI(uri,nsnull,nsIWebNavigation::LOAD_FLAGS_NONE, PR_FALSE); - NS_ENSURE_SUCCESS(rv,rv); + rv = docShell->LoadURI(uri,nsnull,nsIWebNavigation::LOAD_FLAGS_NONE, PR_FALSE); + NS_ENSURE_SUCCESS(rv,rv); - return NS_OK; + return NS_OK; } NS_IMPL_GETSET(nsMsgWindow, Stopped, PRBool, m_stopped) diff --git a/mailnews/compose/src/nsMsgCompose.cpp b/mailnews/compose/src/nsMsgCompose.cpp index 53a96661042..c26a6c48932 100644 --- a/mailnews/compose/src/nsMsgCompose.cpp +++ b/mailnews/compose/src/nsMsgCompose.cpp @@ -522,11 +522,9 @@ nsMsgCompose::ConvertAndLoadComposeWindow(nsString& aPrefix, if (!aBuf.IsEmpty() && mailEditor) { // XXX see bug #206793 - nsCOMPtr docshell; + nsIDocShell *docshell = nsnull; nsCOMPtr globalObj = do_QueryInterface(m_window); - if (globalObj) - globalObj->GetDocShell(getter_AddRefs(docshell)); - if (docshell) + if (globalObj && (docshell = globalObj->GetDocShell())) docshell->SetAppType(nsIDocShell::APP_TYPE_MAIL); if (aHTMLEditor && !mCiteReference.IsEmpty()) @@ -710,13 +708,12 @@ nsMsgCompose::Initialize(nsIDOMWindowInternal *aWindow, nsIMsgComposeParams *par if (aWindow) { m_window = aWindow; - nsCOMPtr docshell; nsCOMPtr globalObj(do_QueryInterface(aWindow)); if (!globalObj) return NS_ERROR_FAILURE; - - globalObj->GetDocShell(getter_AddRefs(docshell)); - nsCOMPtr treeItem(do_QueryInterface(docshell)); + + nsCOMPtr treeItem = + do_QueryInterface(globalObj->GetDocShell()); nsCOMPtr treeOwner; rv = treeItem->GetTreeOwner(getter_AddRefs(treeOwner)); if (NS_FAILED(rv)) return rv; @@ -1268,8 +1265,7 @@ NS_IMETHODIMP nsMsgCompose::CloseWindow(PRBool recycleIt) nsCOMPtr sgo(do_QueryInterface(m_window)); if (sgo) { - nsCOMPtr scriptContext; - sgo->GetContext(getter_AddRefs(scriptContext)); + nsIScriptContext *scriptContext = sgo->GetContext(); if (scriptContext) scriptContext->GC(); } @@ -1336,8 +1332,7 @@ NS_IMETHODIMP nsMsgCompose::InitEditor(nsIEditor* aEditor, nsIDOMWindow* aConten nsCOMPtr globalObj = do_QueryInterface(m_window); - nsCOMPtr docShell; - globalObj->GetDocShell(getter_AddRefs(docShell)); + nsIDocShell *docShell = globalObj->GetDocShell(); NS_ENSURE_TRUE(docShell, NS_ERROR_UNEXPECTED); nsCOMPtr childCV; @@ -2376,10 +2371,10 @@ QuotingOutputStreamListener::InsertToCompose(nsIEditor *aEditor, nsCOMPtr domWindow; if (compose) compose->GetDomWindow(getter_AddRefs(domWindow)); - nsCOMPtr docshell; + nsIDocShell *docshell = nsnull; nsCOMPtr globalObj = do_QueryInterface(domWindow); if (globalObj) - globalObj->GetDocShell(getter_AddRefs(docshell)); + docshell = globalObj->GetDocShell(); if (docshell) docshell->SetAppType(nsIDocShell::APP_TYPE_MAIL); diff --git a/mailnews/compose/src/nsMsgComposeService.cpp b/mailnews/compose/src/nsMsgComposeService.cpp index af713f83123..b75dd1cf340 100644 --- a/mailnews/compose/src/nsMsgComposeService.cpp +++ b/mailnews/compose/src/nsMsgComposeService.cpp @@ -304,21 +304,19 @@ void nsMsgComposeService::CloseWindow(nsIDOMWindowInternal *domWindow) nsCOMPtr globalObj(do_QueryInterface(domWindow)); if (globalObj) { - globalObj->GetDocShell(getter_AddRefs(docshell)); - if (docshell) + nsCOMPtr treeItem = + do_QueryInterface(globalObj->GetDocShell()); + + if (treeItem) { - nsCOMPtr treeItem(do_QueryInterface(docshell)); - if (treeItem) + nsCOMPtr treeOwner; + treeItem->GetTreeOwner(getter_AddRefs(treeOwner)); + if (treeOwner) { - nsCOMPtr treeOwner; - treeItem->GetTreeOwner(getter_AddRefs(treeOwner)); - if (treeOwner) - { - nsCOMPtr baseWindow; - baseWindow = do_QueryInterface(treeOwner); - if (baseWindow) - baseWindow->Destroy(); - } + nsCOMPtr baseWindow; + baseWindow = do_QueryInterface(treeOwner); + if (baseWindow) + baseWindow->Destroy(); } } } @@ -690,11 +688,9 @@ HWND hwndForComposeDOMWindow( nsISupports *window ) nsCOMPtr ppScriptGlobalObj( do_QueryInterface(window) ); if ( !ppScriptGlobalObj ) return 0; - nsCOMPtr ppDocShell; - ppScriptGlobalObj->GetDocShell( getter_AddRefs( ppDocShell ) ); - if ( !ppDocShell ) return 0; - - nsCOMPtr ppBaseWindow( do_QueryInterface( ppDocShell ) ); + + nsCOMPtr ppBaseWindow = + do_QueryInterface( ppScriptGlobalObj->GetDocShell() ); if (!ppBaseWindow) return 0; nsCOMPtr ppWidget; @@ -889,10 +885,8 @@ nsresult nsMsgComposeService::ShowCachedComposeWindow(nsIDOMWindowInternal *aCom nsCOMPtr globalScript = do_QueryInterface(aComposeWindow, &rv); NS_ENSURE_SUCCESS(rv,rv); - nsCOMPtr docShell; - rv = globalScript->GetDocShell(getter_AddRefs(docShell)); - NS_ENSURE_SUCCESS(rv,rv); + nsIDocShell *docShell = globalScript->GetDocShell(); nsCOMPtr webShell = do_QueryInterface(docShell, &rv); NS_ENSURE_SUCCESS(rv,rv); diff --git a/modules/oji/src/ProxyClassLoader.cpp b/modules/oji/src/ProxyClassLoader.cpp index a3909eb4f10..00f6e134f00 100644 --- a/modules/oji/src/ProxyClassLoader.cpp +++ b/modules/oji/src/ProxyClassLoader.cpp @@ -58,13 +58,12 @@ */ static nsresult getScriptCodebase(JSContext* cx, nsIURI* *result) { - nsCOMPtr scriptContext; - GetScriptContextFromJSContext(cx, getter_AddRefs(scriptContext)); + nsIScriptContext *scriptContext = GetScriptContextFromJSContext(cx); if (scriptContext) { - nsCOMPtr scriptGlobal; - scriptContext->GetGlobalObject(getter_AddRefs(scriptGlobal)); - nsCOMPtr scriptObjectPrincipal = do_QueryInterface(scriptGlobal); + nsCOMPtr scriptObjectPrincipal = + do_QueryInterface(scriptContext->GetGlobalObject()); + if (scriptObjectPrincipal) { nsCOMPtr principal; scriptObjectPrincipal->GetPrincipal(getter_AddRefs(principal)); diff --git a/modules/oji/src/lcglue.cpp b/modules/oji/src/lcglue.cpp index e6f8a43d88e..7d73b0a3f79 100644 --- a/modules/oji/src/lcglue.cpp +++ b/modules/oji/src/lcglue.cpp @@ -337,21 +337,19 @@ enter_js_from_java_impl(JNIEnv *jEnv, char **errp, nsCOMPtr javaSecurityContext = do_QueryInterface(credentials); if (javaSecurityContext) { if (pJSCX) { - nsCOMPtr scriptContext; - GetScriptContextFromJSContext(pJSCX, - getter_AddRefs(scriptContext)); + nsIScriptContext *scriptContext = + GetScriptContextFromJSContext(pJSCX); if (scriptContext) { - nsCOMPtr global; - scriptContext->GetGlobalObject(getter_AddRefs(global)); + nsIScriptGlobalObject *global = + scriptContext->GetGlobalObject(); NS_ASSERTION(global, "script context has no global object"); - if (global) { - nsCOMPtr globalData = do_QueryInterface(global); - if (globalData) { - if (NS_FAILED(globalData->GetPrincipal(getter_AddRefs(principal)))) - return NS_ERROR_FAILURE; - } + nsCOMPtr globalData = + do_QueryInterface(global); + if (globalData) { + if (NS_FAILED(globalData->GetPrincipal(getter_AddRefs(principal)))) + return NS_ERROR_FAILURE; } } } @@ -407,8 +405,7 @@ exit_js_impl(JNIEnv *jEnv, JSContext *cx) // The main idea is to execute terminate function if have any; if (cx) { - nsCOMPtr scriptContext; - GetScriptContextFromJSContext(cx, getter_AddRefs(scriptContext)); + nsIScriptContext *scriptContext = GetScriptContextFromJSContext(cx); if (scriptContext) { diff --git a/modules/oji/src/nsJVMManager.cpp b/modules/oji/src/nsJVMManager.cpp index 0327a541108..261c37bde8b 100644 --- a/modules/oji/src/nsJVMManager.cpp +++ b/modules/oji/src/nsJVMManager.cpp @@ -818,53 +818,39 @@ nsJVMManager::EnsurePrefCallbackRegistered(void) nsresult nsJVMManager::GetChrome(nsIWebBrowserChrome **theChrome) { - NS_ENSURE_ARG_POINTER(theChrome); + *theChrome = nsnull; - nsresult rv = NS_ERROR_FAILURE; - nsCOMPtr windowWatcher; - nsCOMPtr domWindow; - nsCOMPtr docShell; - nsCOMPtr scriptObject; - nsCOMPtr presContext; - nsCOMPtr treeItem; - nsCOMPtr treeOwner; - nsCOMPtr cont; - nsCOMPtr chrome; - - windowWatcher = + nsresult rv; + nsCOMPtr windowWatcher = do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv); - if (!windowWatcher) { + if (NS_FAILED(rv)) { return rv; } - rv = windowWatcher->GetActiveWindow(getter_AddRefs(domWindow)); - if (!domWindow) { - return rv; - } - scriptObject = do_QueryInterface(domWindow, &rv); + nsCOMPtr domWindow; + windowWatcher->GetActiveWindow(getter_AddRefs(domWindow)); + nsCOMPtr scriptObject = + do_QueryInterface(domWindow, &rv); if (!scriptObject) { return rv; } - rv = scriptObject->GetDocShell(getter_AddRefs(docShell)); + nsIDocShell *docShell = scriptObject->GetDocShell(); if (!docShell) { - return rv; + return NS_OK; } + nsCOMPtr presContext; rv = docShell->GetPresContext(getter_AddRefs(presContext)); if (!presContext) { return rv; } - cont = presContext->GetContainer(); - if (!cont) { - return NS_OK; - } - treeItem = do_QueryInterface(cont, &rv); + nsCOMPtr container(presContext->GetContainer()); + nsCOMPtr treeItem = do_QueryInterface(container, &rv); if (!treeItem) { return rv; } - rv = treeItem->GetTreeOwner(getter_AddRefs(treeOwner)); - if (!treeOwner) { - return rv; - } - chrome = do_GetInterface(treeOwner, &rv); + nsCOMPtr treeOwner; + treeItem->GetTreeOwner(getter_AddRefs(treeOwner)); + + nsCOMPtr chrome = do_GetInterface(treeOwner, &rv); *theChrome = (nsIWebBrowserChrome *) chrome.get(); NS_IF_ADDREF(*theChrome); return rv; diff --git a/modules/plugin/base/src/nsPluginHostImpl.cpp b/modules/plugin/base/src/nsPluginHostImpl.cpp index 642b8873cd9..515148ced00 100644 --- a/modules/plugin/base/src/nsPluginHostImpl.cpp +++ b/modules/plugin/base/src/nsPluginHostImpl.cpp @@ -5642,10 +5642,7 @@ NS_IMETHODIMP nsPluginHostImpl::NewPluginURLStream(const nsString& aURL, if (global) { - nsCOMPtr owner; - global->GetGlobalObjectOwner(getter_AddRefs(owner)); - - callbacks = do_QueryInterface(owner); + callbacks = do_QueryInterface(global->GetGlobalObjectOwner()); } } diff --git a/modules/plugin/base/src/nsPluginInstancePeer.cpp b/modules/plugin/base/src/nsPluginInstancePeer.cpp index 091baa44a29..8fa04becf57 100644 --- a/modules/plugin/base/src/nsPluginInstancePeer.cpp +++ b/modules/plugin/base/src/nsPluginInstancePeer.cpp @@ -773,13 +773,10 @@ NS_IMETHODIMP nsPluginInstancePeerImpl::GetJSContext(JSContext* *outContext) nsIScriptGlobalObject *global = document->GetScriptGlobalObject(); if (global) { - nsCOMPtr context; + nsIScriptContext *context = global->GetContext(); - if (global->GetContext(getter_AddRefs(context)) == NS_OK) { - if (context) { - *outContext = (JSContext*) context->GetNativeContext(); - rv = NS_OK; - } + if (context) { + *outContext = (JSContext*) context->GetNativeContext(); } } } diff --git a/netwerk/base/public/nsILoadGroup.idl b/netwerk/base/public/nsILoadGroup.idl index 595fa58cca4..a10593b63fa 100644 --- a/netwerk/base/public/nsILoadGroup.idl +++ b/netwerk/base/public/nsILoadGroup.idl @@ -96,7 +96,7 @@ interface nsILoadGroup : nsIRequest * Returns the count of "active" requests (ie. requests without the * LOAD_BACKGROUND bit set). */ - readonly attribute unsigned long activeCount; + readonly attribute unsigned long activeCount; /** * Notification callbacks for the load group. diff --git a/profile/pref-migrator/src/nsPrefMigration.cpp b/profile/pref-migrator/src/nsPrefMigration.cpp index 197400926ee..c4b259106b7 100644 --- a/profile/pref-migrator/src/nsPrefMigration.cpp +++ b/profile/pref-migrator/src/nsPrefMigration.cpp @@ -444,11 +444,9 @@ nsPrefMigration::WindowCloseCallback() nsresult rv; nsCOMPtr scriptGO(do_QueryInterface(mPMProgressWindow)); if (!scriptGO) return NS_ERROR_FAILURE; - - nsCOMPtr docShell; - rv = scriptGO->GetDocShell(getter_AddRefs(docShell)); - if (!docShell) return NS_ERROR_FAILURE; - nsCOMPtr treeItem(do_QueryInterface(docShell)); + + nsCOMPtr treeItem = + do_QueryInterface(scriptGO->GetDocShell()); if (!treeItem) return NS_ERROR_FAILURE; nsCOMPtr treeOwner; treeItem->GetTreeOwner(getter_AddRefs(treeOwner)); diff --git a/security/manager/boot/src/nsSecureBrowserUIImpl.cpp b/security/manager/boot/src/nsSecureBrowserUIImpl.cpp index e63bb05756a..58a41791406 100644 --- a/security/manager/boot/src/nsSecureBrowserUIImpl.cpp +++ b/security/manager/boot/src/nsSecureBrowserUIImpl.cpp @@ -193,11 +193,7 @@ nsSecureBrowserUIImpl::Init(nsIDOMWindow *window) nsCOMPtr sgo(do_QueryInterface(mWindow)); if (!sgo) return NS_ERROR_FAILURE; - nsCOMPtr docShell; - sgo->GetDocShell(getter_AddRefs(docShell)); - if (!docShell) return NS_ERROR_FAILURE; - - nsCOMPtr wp(do_GetInterface(docShell)); + nsCOMPtr wp(do_GetInterface(sgo->GetDocShell())); if (!wp) return NS_ERROR_FAILURE; /* end GetWebProgress */ diff --git a/security/manager/ssl/src/nsCrypto.cpp b/security/manager/ssl/src/nsCrypto.cpp index a0b451cfdef..f0a3f34d791 100644 --- a/security/manager/ssl/src/nsCrypto.cpp +++ b/security/manager/ssl/src/nsCrypto.cpp @@ -374,15 +374,12 @@ nsCrypto::GetScriptPrincipal(JSContext *cx) if (principal) return principal; - nsCOMPtr scriptContext; - GetScriptContextFromJSContext(cx, getter_AddRefs(scriptContext)); + nsIScriptContext *scriptContext = GetScriptContextFromJSContext(cx); if (scriptContext) { - nsCOMPtr global; - scriptContext->GetGlobalObject(getter_AddRefs(global)); - NS_ENSURE_TRUE(global, nsnull); - nsCOMPtr globalData = do_QueryInterface(global); + nsCOMPtr globalData = + do_QueryInterface(scriptContext->GetGlobalObject()); NS_ENSURE_TRUE(globalData, nsnull); globalData->GetPrincipal(&principal); } diff --git a/webshell/tests/viewer/nsViewerApp.cpp b/webshell/tests/viewer/nsViewerApp.cpp index 232f2150474..9b6df1c5faa 100644 --- a/webshell/tests/viewer/nsViewerApp.cpp +++ b/webshell/tests/viewer/nsViewerApp.cpp @@ -1558,10 +1558,10 @@ static void ShowConsole(nsBrowserWindow* aWindow) MAKEINTRESOURCE(ACCELERATOR_TABLE)); } - nsIScriptContext *context = nsnull; nsCOMPtr scriptGlobal(do_GetInterface(aWindow->mDocShell)); - if (scriptGlobal) { - if ((NS_OK == scriptGlobal->GetContext(&context)) && context) { + if (scriptGlobal) { + nsIScriptContext *context; + if ((context = scriptGlobal->GetContext())) { // create the console gConsole = JSConsole::CreateConsole(); diff --git a/widget/src/xpwidgets/nsBaseFilePicker.cpp b/widget/src/xpwidgets/nsBaseFilePicker.cpp index ebfeaf66e25..9eb05b51516 100644 --- a/widget/src/xpwidgets/nsBaseFilePicker.cpp +++ b/widget/src/xpwidgets/nsBaseFilePicker.cpp @@ -65,8 +65,7 @@ NS_IMETHODIMP nsBaseFilePicker::DOMWindowToWidget(nsIDOMWindowInternal *dw, nsIW nsCOMPtr sgo = do_QueryInterface(dw); if (sgo) { - nsCOMPtr docShell; - sgo->GetDocShell(getter_AddRefs(docShell)); + nsIDocShell *docShell = sgo->GetDocShell(); if (docShell) { diff --git a/xpcom/ds/nsAtomTable.cpp b/xpcom/ds/nsAtomTable.cpp index 40d437dce01..8f8472ac4fd 100644 --- a/xpcom/ds/nsAtomTable.cpp +++ b/xpcom/ds/nsAtomTable.cpp @@ -388,7 +388,7 @@ AtomImpl::EqualsUTF8(const nsACString& aString, PRBool* aResult) NS_IMETHODIMP AtomImpl::Equals(const nsAString& aString, PRBool* aResult) { - *aResult = NS_ConvertUCS2toUTF8(aString).Equals(mString); + *aResult = NS_ConvertUTF16toUTF8(aString).Equals(mString); return NS_OK; } diff --git a/xpfe/appshell/src/nsAppShellService.cpp b/xpfe/appshell/src/nsAppShellService.cpp index 53193493c63..0b49f4126ef 100644 --- a/xpfe/appshell/src/nsAppShellService.cpp +++ b/xpfe/appshell/src/nsAppShellService.cpp @@ -911,8 +911,7 @@ nsAppShellService::GetHiddenWindowAndJSContext(nsIDOMWindowInternal **aWindow, if (!sgo) { rv = NS_ERROR_FAILURE; break; } // 4. Get script context from that. - nsCOMPtr scriptContext; - sgo->GetContext( getter_AddRefs( scriptContext ) ); + nsIScriptContext *scriptContext = sgo->GetContext(); if (!scriptContext) { rv = NS_ERROR_FAILURE; break; } // 5. Get JSContext from the script context. diff --git a/xpfe/bootstrap/nsNativeAppSupportOS2.cpp b/xpfe/bootstrap/nsNativeAppSupportOS2.cpp index 63465910370..9a047f3ace2 100644 --- a/xpfe/bootstrap/nsNativeAppSupportOS2.cpp +++ b/xpfe/bootstrap/nsNativeAppSupportOS2.cpp @@ -1565,19 +1565,14 @@ nsNativeAppSupportOS2::HandleDDENotification( ULONG idInst, // DDEML instanc // Escape any double-quotes. escapeQuotes( url ); - // Now for the title; first, get the "window" JS object. + // Now for the title; first, get the "window" script global object. nsCOMPtr scrGlobalObj( do_QueryInterface( internalContent ) ); if ( !scrGlobalObj ) { break; } - // Then the doc shell... - nsCOMPtr docShell; - scrGlobalObj->GetDocShell( getter_AddRefs( docShell ) ); - if ( !docShell ) { - break; - } - // And from that the base window... - nsCOMPtr baseWindow( do_QueryInterface( docShell ) ); + // Then from its doc shell get the base window... + nsCOMPtr baseWindow = + do_QueryInterface( scrGlobalObj->GetDocShell() ); if ( !baseWindow ) { break; } @@ -2184,12 +2179,9 @@ HWND hwndForDOMWindow( nsISupports *window ) { if ( !ppScriptGlobalObj ) { return 0; } - nsCOMPtr ppDocShell; - ppScriptGlobalObj->GetDocShell( getter_AddRefs( ppDocShell ) ); - if ( !ppDocShell ) { - return 0; - } - nsCOMPtr ppBaseWindow( do_QueryInterface( ppDocShell ) ); + + nsCOMPtr ppBaseWindow = + do_QueryInterface( ppScriptGlobalObj->GetDocShell() ); if ( !ppBaseWindow ) { return 0; } diff --git a/xpfe/bootstrap/nsNativeAppSupportWin.cpp b/xpfe/bootstrap/nsNativeAppSupportWin.cpp index 5c8b2d80b32..a411f47ead6 100644 --- a/xpfe/bootstrap/nsNativeAppSupportWin.cpp +++ b/xpfe/bootstrap/nsNativeAppSupportWin.cpp @@ -1471,19 +1471,14 @@ nsNativeAppSupportWin::HandleDDENotification( UINT uType, // transaction t // Escape any double-quotes. escapeQuotes( url ); - // Now for the title; first, get the "window" JS object. + // Now for the title; first, get the "window" script global object. nsCOMPtr scrGlobalObj( do_QueryInterface( internalContent ) ); if ( !scrGlobalObj ) { break; } - // Then the doc shell... - nsCOMPtr docShell; - scrGlobalObj->GetDocShell( getter_AddRefs( docShell ) ); - if ( !docShell ) { - break; - } - // And from that the base window... - nsCOMPtr baseWindow( do_QueryInterface( docShell ) ); + // Then from its doc shell get the base window... + nsCOMPtr baseWindow = + do_QueryInterface( scrGlobalObj->GetDocShell() ); if ( !baseWindow ) { break; } @@ -2165,12 +2160,9 @@ HWND hwndForDOMWindow( nsISupports *window ) { if ( !ppScriptGlobalObj ) { return 0; } - nsCOMPtr ppDocShell; - ppScriptGlobalObj->GetDocShell( getter_AddRefs( ppDocShell ) ); - if ( !ppDocShell ) { - return 0; - } - nsCOMPtr ppBaseWindow( do_QueryInterface( ppDocShell ) ); + + nsCOMPtr ppBaseWindow = + do_QueryInterface( ppScriptGlobalObj->GetDocShell() ); if ( !ppBaseWindow ) { return 0; } diff --git a/xpfe/browser/src/nsBrowserInstance.cpp b/xpfe/browser/src/nsBrowserInstance.cpp index 336a40e4bed..af336a3ec16 100644 --- a/xpfe/browser/src/nsBrowserInstance.cpp +++ b/xpfe/browser/src/nsBrowserInstance.cpp @@ -424,8 +424,7 @@ nsBrowserInstance::ReinitializeContentVariables() nsCOMPtr globalObj(do_QueryInterface(contentWindow)); if (globalObj) { - nsCOMPtr docShell; - globalObj->GetDocShell(getter_AddRefs(docShell)); + nsIDocShell *docShell = globalObj->GetDocShell(); mContentAreaDocShellWeak = do_GetWeakReference(docShell); // Weak reference @@ -587,9 +586,9 @@ nsBrowserInstance::SetWebShellWindow(nsIDOMWindowInternal* aWin) } if (APP_DEBUG) { - nsCOMPtr docShell; - globalObj->GetDocShell(getter_AddRefs(docShell)); - nsCOMPtr docShellAsItem(do_QueryInterface(docShell)); + nsCOMPtr docShellAsItem = + do_QueryInterface(globalObj->GetDocShell()); + if (docShellAsItem) { // inform our top level webshell that we are its parent URI content listener... nsXPIDLString name; diff --git a/xpfe/components/directory/nsDirectoryViewer.cpp b/xpfe/components/directory/nsDirectoryViewer.cpp index 00c71b9eed9..9c89d105a65 100644 --- a/xpfe/components/directory/nsDirectoryViewer.cpp +++ b/xpfe/components/directory/nsDirectoryViewer.cpp @@ -185,9 +185,8 @@ nsHTTPIndex::OnFTPControlLog(PRBool server, const char *msg) nsCOMPtr scriptGlobal(do_GetInterface(mRequestor)); NS_ENSURE_TRUE(scriptGlobal, NS_OK); - nsCOMPtr context; - nsresult rv = scriptGlobal->GetContext(getter_AddRefs(context)); - NS_ENSURE_SUCCESS(rv, NS_OK); + nsIScriptContext *context = scriptGlobal->GetContext(); + NS_ENSURE_TRUE(context, NS_OK); JSContext* jscontext = NS_REINTERPRET_CAST(JSContext*, context->GetNativeContext()); @@ -263,8 +262,7 @@ nsHTTPIndex::OnStartRequest(nsIRequest *request, nsISupports* aContext) nsCOMPtr scriptGlobal(do_GetInterface(mRequestor)); NS_ENSURE_TRUE(scriptGlobal, NS_ERROR_FAILURE); - nsCOMPtr context; - rv = scriptGlobal->GetContext(getter_AddRefs(context)); + nsIScriptContext *context = scriptGlobal->GetContext(); NS_ENSURE_TRUE(context, NS_ERROR_FAILURE); JSContext* jscontext = NS_REINTERPRET_CAST(JSContext*, diff --git a/xpfe/components/urlwidget/nsUrlWidget.cpp b/xpfe/components/urlwidget/nsUrlWidget.cpp index 714e246f384..ab04427d4a3 100644 --- a/xpfe/components/urlwidget/nsUrlWidget.cpp +++ b/xpfe/components/urlwidget/nsUrlWidget.cpp @@ -79,13 +79,10 @@ nsUrlWidget::SetURLToHiddenControl( char const *aURL, nsIDOMWindowInternal *pare { return NS_ERROR_FAILURE; } - nsCOMPtr ppDocShell; - ppScriptGlobalObj->GetDocShell(getter_AddRefs(ppDocShell)); - if (!ppDocShell) - { - return NS_ERROR_FAILURE; - } - nsCOMPtr ppBaseWindow(do_QueryInterface(ppDocShell)); + + nsCOMPtr ppBaseWindow = + do_QueryInterface(ppScriptGlobalObj->GetDocShell()); + if (ppBaseWindow) { nsCOMPtr ppWidget; diff --git a/xpinstall/src/nsInstallTrigger.cpp b/xpinstall/src/nsInstallTrigger.cpp index 1aca7c302d6..681703174bf 100644 --- a/xpinstall/src/nsInstallTrigger.cpp +++ b/xpinstall/src/nsInstallTrigger.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* ***** BEGIN LICENSE BLOCK ***** * Version: NPL 1.1/GPL 2.0/LGPL 2.1 * @@ -89,8 +89,7 @@ nsInstallTrigger::GetScriptObject(nsIScriptContext *aContext, void** aScriptObje if (nsnull == mScriptObject) { - nsIScriptGlobalObject *global = nsnull; - aContext->GetGlobalObject(&global); + nsIScriptGlobalObject *global = aContext->GetGlobalObject(); res = NS_NewScriptInstallTriggerGlobal( aContext, (nsISupports *)(nsIDOMInstallTriggerGlobal*)this, diff --git a/xpinstall/src/nsJSInstallTriggerGlobal.cpp b/xpinstall/src/nsJSInstallTriggerGlobal.cpp index 43001054d1e..a9bc1a2516d 100644 --- a/xpinstall/src/nsJSInstallTriggerGlobal.cpp +++ b/xpinstall/src/nsJSInstallTriggerGlobal.cpp @@ -237,15 +237,14 @@ InstallTriggerGlobalInstall(JSContext *cx, JSObject *obj, uintN argc, jsval *arg { PRBool result; - nsCOMPtr scriptContext; - GetScriptContextFromJSContext(cx, getter_AddRefs(scriptContext)); + nsIScriptContext *scriptContext = GetScriptContextFromJSContext(cx); if (scriptContext) { - nsCOMPtr globalObject; - scriptContext->GetGlobalObject(getter_AddRefs(globalObject)); + nsIScriptGlobalObject *globalObject = + scriptContext->GetGlobalObject(); if (globalObject) { - nativeThis->Install(globalObject, trigger,&result); + nativeThis->Install(globalObject, trigger, &result); *rval = BOOLEAN_TO_JSVAL(result); return JS_TRUE; } @@ -319,13 +318,12 @@ InstallTriggerGlobalInstallChrome(JSContext *cx, JSObject *obj, uintN argc, jsva if (item && item->IsRelativeURL()) item->mURL.Insert( baseURL, 0 ); - nsCOMPtr scriptContext; - GetScriptContextFromJSContext(cx, getter_AddRefs(scriptContext)); + nsIScriptContext *scriptContext = GetScriptContextFromJSContext(cx); if (scriptContext) { - nsCOMPtr globalObject; - scriptContext->GetGlobalObject(getter_AddRefs(globalObject)); + nsIScriptGlobalObject *globalObject = + scriptContext->GetGlobalObject(); if (globalObject) { nsresult rv = nativeThis->InstallChrome(globalObject, chromeType, item, &nativeRet); @@ -371,13 +369,12 @@ InstallTriggerGlobalStartSoftwareUpdate(JSContext *cx, JSObject *obj, uintN argc return JS_FALSE; } - nsCOMPtr scriptContext; - GetScriptContextFromJSContext(cx, getter_AddRefs(scriptContext)); + nsIScriptContext *scriptContext = GetScriptContextFromJSContext(cx); if (scriptContext) { - nsCOMPtr globalObject; - scriptContext->GetGlobalObject(getter_AddRefs(globalObject)); + nsIScriptGlobalObject *globalObject = + scriptContext->GetGlobalObject(); if (globalObject) { if(NS_OK != nativeThis->StartSoftwareUpdate(globalObject, b0, b1, &nativeRet)) @@ -682,8 +679,7 @@ NS_NewScriptInstallTriggerGlobal(nsIScriptContext *aContext, return NS_ERROR_FAILURE; } - result = aSupports->QueryInterface(NS_GET_IID(nsIDOMInstallTriggerGlobal), - (void **)&installTriggerGlobal); + result = CallQueryInterface(aSupports, &installTriggerGlobal); if (NS_OK != result) { return result; }