зеркало из https://github.com/mozilla/pjs.git
Fixing bug 233307. deCOMtaminating nsIScript* and related interfaces. r+sr=bryner@brianryner.com.
This commit is contained in:
Родитель
48abfb9563
Коммит
8b6dc1c3ca
|
@ -99,13 +99,10 @@ JSValIDToString(JSContext *cx, const jsval idval)
|
|||
return NS_REINTERPRET_CAST(PRUnichar*, JS_GetStringChars(str));
|
||||
}
|
||||
|
||||
already_AddRefed<nsIScriptContext>
|
||||
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<nsIDocShell> docshell;
|
||||
nsCOMPtr<nsIScriptContext> scriptContext = GetScriptContext(cx);
|
||||
if (!scriptContext) return NS_ERROR_FAILURE;
|
||||
nsCOMPtr<nsIScriptGlobalObject> 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<nsIDocShellTreeItem> 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<nsIDocShellTreeItem> docshellTreeItem =
|
||||
do_QueryInterface(globalObject->GetDocShell(), &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> 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<nsIScriptContext> scriptContext = GetScriptContext(cx);
|
||||
nsIScriptContext *scriptContext = GetScriptContext(cx);
|
||||
if (!scriptContext) return NS_ERROR_FAILURE;
|
||||
nsCOMPtr<nsIScriptGlobalObject> globalObject;
|
||||
scriptContext->GetGlobalObject(getter_AddRefs(globalObject));
|
||||
nsIScriptGlobalObject *globalObject = scriptContext->GetGlobalObject();
|
||||
if (!globalObject) return NS_ERROR_FAILURE;
|
||||
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIDocShell> docshell;
|
||||
globalObject->GetDocShell(getter_AddRefs(docshell));
|
||||
nsCOMPtr<nsIDocShell> docshell = globalObject->GetDocShell();
|
||||
nsCOMPtr<nsIDocShellTreeItem> globalObjTreeItem = do_QueryInterface(docshell);
|
||||
if (globalObjTreeItem)
|
||||
{
|
||||
|
@ -1731,16 +1728,15 @@ nsScriptSecurityManager::GetPrincipalFromContext(JSContext *cx,
|
|||
{
|
||||
*result = nsnull;
|
||||
|
||||
nsCOMPtr<nsIScriptContext> scriptContext = GetScriptContext(cx);
|
||||
nsIScriptContext *scriptContext = GetScriptContext(cx);
|
||||
|
||||
if (!scriptContext)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> global;
|
||||
scriptContext->GetGlobalObject(getter_AddRefs(global));
|
||||
nsCOMPtr<nsIScriptObjectPrincipal> globalData(do_QueryInterface(global));
|
||||
nsCOMPtr<nsIScriptObjectPrincipal> 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<nsIScriptContext> scriptContext = GetScriptContext(cx);
|
||||
nsIScriptContext *scriptContext = GetScriptContext(cx);
|
||||
if (scriptContext)
|
||||
{
|
||||
nsCOMPtr<nsIScriptGlobalObject> global;
|
||||
scriptContext->GetGlobalObject(getter_AddRefs(global));
|
||||
NS_ENSURE_TRUE(global, NS_ERROR_FAILURE);
|
||||
nsCOMPtr<nsIScriptObjectPrincipal> globalData(do_QueryInterface(global));
|
||||
nsCOMPtr<nsIScriptObjectPrincipal> 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<nsIPrompt> prompter;
|
||||
if (cx)
|
||||
{
|
||||
nsCOMPtr<nsIScriptContext> scriptContext = GetScriptContext(cx);
|
||||
nsIScriptContext *scriptContext = GetScriptContext(cx);
|
||||
if (scriptContext)
|
||||
{
|
||||
nsCOMPtr<nsIScriptGlobalObject> globalObject;
|
||||
scriptContext->GetGlobalObject(getter_AddRefs(globalObject));
|
||||
NS_ASSERTION(globalObject, "script context has no global object");
|
||||
nsCOMPtr<nsIDOMWindowInternal> domWin(do_QueryInterface(globalObject));
|
||||
nsCOMPtr<nsIDOMWindowInternal> domWin =
|
||||
do_QueryInterface(scriptContext->GetGlobalObject());
|
||||
if (domWin)
|
||||
domWin->GetPrompter(getter_AddRefs(prompter));
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<nsIXPConnectWrappedNative> 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<nsISupports> native;
|
||||
rv = wrapped_native->GetNative(getter_AddRefs(native));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
wrapped_native->GetNative(getter_AddRefs(native));
|
||||
|
||||
return CallQueryInterface(native, aNativeGlobal);
|
||||
nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(native));
|
||||
|
||||
// This will return a pointer to something that's about to be
|
||||
// released, but that's ok here.
|
||||
return sgo;
|
||||
}
|
||||
|
||||
//static
|
||||
nsresult
|
||||
nsIScriptContext *
|
||||
nsContentUtils::GetStaticScriptContext(JSContext* aContext,
|
||||
JSObject* aObj,
|
||||
nsIScriptContext** aScriptContext)
|
||||
JSObject* aObj)
|
||||
{
|
||||
nsCOMPtr<nsIScriptGlobalObject> 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<nsIScriptContext> 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 <class OutputIterator>
|
||||
|
@ -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<nsIScriptContext> 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<nsIScriptGlobalObject> 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<nsIDOMDocument> doc;
|
||||
|
||||
if (cx) {
|
||||
nsCOMPtr<nsIScriptGlobalObject> sgo;
|
||||
GetDynamicScriptGlobal(cx, getter_AddRefs(sgo));
|
||||
nsIScriptGlobalObject *sgo = GetDynamicScriptGlobal(cx);
|
||||
|
||||
nsCOMPtr<nsIDOMWindowInternal> 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();
|
||||
|
|
|
@ -368,8 +368,7 @@ nsDOMImplementation::CreateDocument(const nsAString& aNamespaceURI,
|
|||
nsresult rv = NS_NewDOMDocument(aReturn, aNamespaceURI, aQualifiedName,
|
||||
aDoctype, mBaseURI);
|
||||
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
nsContentUtils::GetDocShellFromCaller(getter_AddRefs(docShell));
|
||||
nsIDocShell *docShell = nsContentUtils::GetDocShellFromCaller();
|
||||
if (docShell) {
|
||||
nsCOMPtr<nsIPresContext> presContext;
|
||||
docShell->GetPresContext(getter_AddRefs(presContext));
|
||||
|
@ -1757,11 +1756,8 @@ nsDocument::EndLoad()
|
|||
nsCOMPtr<nsIDOMEventTarget> target_frame;
|
||||
|
||||
if (mScriptGlobalObject) {
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
mScriptGlobalObject->GetDocShell(getter_AddRefs(docShell));
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> 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<nsIDocShell> docShell;
|
||||
mScriptGlobalObject->GetDocShell(getter_AddRefs(docShell));
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(docShell));
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem =
|
||||
do_QueryInterface(mScriptGlobalObject->GetDocShell());
|
||||
|
||||
if (docShellAsItem) {
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellParent;
|
||||
|
@ -3923,8 +3917,7 @@ nsDocument::IsScriptEnabled()
|
|||
nsIScriptGlobalObject* globalObject = GetScriptGlobalObject();
|
||||
NS_ENSURE_TRUE(globalObject, PR_TRUE);
|
||||
|
||||
nsCOMPtr<nsIScriptContext> scriptContext;
|
||||
globalObject->GetContext(getter_AddRefs(scriptContext));
|
||||
nsIScriptContext *scriptContext = globalObject->GetContext();
|
||||
NS_ENSURE_TRUE(scriptContext, PR_TRUE);
|
||||
|
||||
JSContext* cx = (JSContext *) scriptContext->GetNativeContext();
|
||||
|
|
|
@ -2588,9 +2588,7 @@ isSelfOrAncestor(nsIContent *aNode, nsIContent *aChild)
|
|||
/*
|
||||
* If aChild doesn't have children it can't be our ancestor
|
||||
*/
|
||||
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<nsIScriptContext> context;
|
||||
nsCOMPtr<nsIScriptGlobalObject> 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<nsIThreadJSContextStack> stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1"));
|
||||
NS_ENSURE_TRUE(stack, NS_ERROR_FAILURE);
|
||||
NS_ENSURE_SUCCESS(stack->Peek(&cx), NS_ERROR_FAILURE);
|
||||
|
||||
if (!cx) {
|
||||
stack->GetSafeJSContext(&cx);
|
||||
NS_ENSURE_TRUE(cx, NS_ERROR_FAILURE);
|
||||
}
|
||||
|
||||
nsContentUtils::GetDynamicScriptContext(cx, getter_AddRefs(context));
|
||||
NS_ENSURE_TRUE(context, NS_ERROR_FAILURE);
|
||||
}
|
||||
nsCOMPtr<nsIEventListenerManager> 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<nsIDOMEventReceiver> 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<nsIDOMEventReceiver> receiver(do_QueryInterface(sgo));
|
||||
NS_ENSURE_TRUE(receiver, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIEventListenerManager> 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<nsIEventListenerManager> 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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1708,9 +1708,7 @@ nsPrintEngine::IsThereARangeSelection(nsIDOMWindow* aDOMWin)
|
|||
nsCOMPtr<nsIPresShell> presShell;
|
||||
if (aDOMWin) {
|
||||
nsCOMPtr<nsIScriptGlobalObject> scriptObj(do_QueryInterface(aDOMWin));
|
||||
nsCOMPtr<nsIDocShell> 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<nsIScriptGlobalObject> scriptObj(do_QueryInterface(aDOMWindow));
|
||||
if (scriptObj) {
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
scriptObj->GetDocShell(getter_AddRefs(docShell));
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem =
|
||||
do_QueryInterface(scriptObj->GetDocShell());
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(docShell));
|
||||
if (docShellAsItem) {
|
||||
// get this DocViewer webshell
|
||||
nsCOMPtr<nsIWebShell> 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<nsIScriptContext> 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -2490,20 +2490,19 @@ nsRange::CreateContextualFragment(const nsAString& aFragment,
|
|||
if (NS_SUCCEEDED(result) &&
|
||||
(!subjectPrin || sysPrin.get() == subjectPrin.get())) {
|
||||
nsIScriptGlobalObject *globalObj = document->GetScriptGlobalObject();
|
||||
|
||||
nsCOMPtr<nsIScriptContext> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -363,16 +363,13 @@ nsScriptLoader::ProcessScriptElement(nsIDOMHTMLScriptElement *aElement,
|
|||
nsIScriptGlobalObject *globalObject = mDocument->GetScriptGlobalObject();
|
||||
if (globalObject)
|
||||
{
|
||||
nsCOMPtr<nsIScriptContext> 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<nsILoadGroup> loadGroup = mDocument->GetDocumentLoadGroup();
|
||||
nsCOMPtr<nsIStreamLoader> loader;
|
||||
|
||||
nsCOMPtr<nsIDocShell> docshell;
|
||||
rv = globalObject->GetDocShell(getter_AddRefs(docshell));
|
||||
if (NS_FAILED(rv)) {
|
||||
mPendingRequests.RemoveObject(request);
|
||||
return FireErrorNotification(rv, aElement, aObserver);
|
||||
}
|
||||
nsIDocShell *docshell = globalObject->GetDocShell();
|
||||
|
||||
nsCOMPtr<nsIInterfaceRequestor> prompter(do_QueryInterface(docshell));
|
||||
|
||||
|
@ -636,9 +628,8 @@ nsScriptLoader::EvaluateScript(nsScriptLoadRequest* aRequest,
|
|||
nsIScriptGlobalObject *globalObject = mDocument->GetScriptGlobalObject();
|
||||
NS_ENSURE_TRUE(globalObject, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIScriptContext> context;
|
||||
rv = globalObject->GetContext(getter_AddRefs(context));
|
||||
if (NS_FAILED(rv) || !context) {
|
||||
nsIScriptContext *context = globalObject->GetContext();
|
||||
if (!context) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<nsIScriptEventListener> sel = do_QueryInterface(aListener, &rv);
|
||||
|
||||
|
||||
for (int i=0; i<listeners->Count(); 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<nsIScriptEventListener> regSel = do_QueryInterface(ls->mListener, &rv);
|
||||
if (NS_SUCCEEDED(rv) && regSel) {
|
||||
PRBool equal;
|
||||
if (NS_SUCCEEDED(regSel->CheckIfEqual(sel, &equal)) && equal) {
|
||||
if (ls->mFlags & aFlags && ls->mSubType & aSubType) {
|
||||
found = PR_TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
|
@ -740,8 +722,6 @@ nsEventListenerManager::RemoveEventListener(nsIDOMEventListener *aListener,
|
|||
}
|
||||
|
||||
nsListenerStruct* ls;
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIScriptEventListener> sel = do_QueryInterface(aListener, &rv);
|
||||
PRBool listenerRemoved = PR_FALSE;
|
||||
|
||||
for (int i=0; i<listeners->Count(); 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<nsIScriptEventListener> regSel = do_QueryInterface(ls->mListener, &rv);
|
||||
if (NS_SUCCEEDED(rv) && regSel) {
|
||||
PRBool equal;
|
||||
if (NS_SUCCEEDED(regSel->CheckIfEqual(sel, &equal)) && equal) {
|
||||
if (ls->mFlags & aFlags && ls->mSubType & aSubType) {
|
||||
NS_RELEASE(ls->mListener);
|
||||
listeners->RemoveElement((void*)ls);
|
||||
PR_DELETE(ls);
|
||||
listenerRemoved = PR_TRUE;
|
||||
break; // otherwise we'd need to adjust loop count...
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
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<nsIContent> content(do_QueryInterface(aObject));
|
||||
|
||||
if (content) {
|
||||
// Try to get context from doc
|
||||
nsIDocument *doc = content->GetDocument();
|
||||
nsIScriptGlobalObject *global;
|
||||
|
||||
if (doc && (global = doc->GetScriptGlobalObject())) {
|
||||
context = global->GetContext();
|
||||
}
|
||||
} else {
|
||||
nsCOMPtr<nsIDocument> doc(do_QueryInterface(aObject));
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> global;
|
||||
|
||||
if (doc) {
|
||||
global = doc->GetScriptGlobalObject();
|
||||
} else {
|
||||
global = do_QueryInterface(aObject);
|
||||
}
|
||||
|
||||
if (global) {
|
||||
context = global->GetContext();
|
||||
}
|
||||
}
|
||||
|
||||
if (!context) {
|
||||
// Get JSContext from stack.
|
||||
nsCOMPtr<nsIThreadJSContextStack> stack =
|
||||
do_GetService("@mozilla.org/js/xpc/ContextStack;1");
|
||||
NS_ENSURE_TRUE(stack, NS_ERROR_FAILURE);
|
||||
NS_ENSURE_SUCCESS(stack->Peek(&cx), NS_ERROR_FAILURE);
|
||||
|
||||
if (!cx) {
|
||||
stack->GetSafeJSContext(&cx);
|
||||
NS_ENSURE_TRUE(cx, NS_ERROR_FAILURE);
|
||||
}
|
||||
|
||||
context = nsContentUtils::GetDynamicScriptContext(cx);
|
||||
NS_ENSURE_TRUE(context, NS_ERROR_FAILURE);
|
||||
}
|
||||
|
||||
nsresult rv;
|
||||
|
||||
if (!aDeferCompilation) {
|
||||
nsCOMPtr<nsIXPConnect> xpc(do_GetService(nsIXPConnect::GetCID()));
|
||||
|
||||
JSContext *cx = (JSContext *)aContext->GetNativeContext();
|
||||
JSContext *cx = (JSContext *)context->GetNativeContext();
|
||||
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> 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<nsIJSEventListener> jslistener = do_QueryInterface(aListenerStruct->mListener);
|
||||
if (jslistener) {
|
||||
nsCOMPtr<nsISupports> target;
|
||||
nsCOMPtr<nsIScriptContext> scriptCX;
|
||||
result = jslistener->GetEventTarget(getter_AddRefs(scriptCX),
|
||||
getter_AddRefs(target));
|
||||
nsAutoString eventString;
|
||||
if (NS_SUCCEEDED(aDOMEvent->GetType(eventString))) {
|
||||
nsCOMPtr<nsIAtom> atom = do_GetAtom(NS_LITERAL_STRING("on") + eventString);
|
||||
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
nsAutoString eventString;
|
||||
if (NS_SUCCEEDED(aDOMEvent->GetType(eventString))) {
|
||||
nsCOMPtr<nsIAtom> atom = do_GetAtom(NS_LITERAL_STRING("on") + eventString);
|
||||
|
||||
result = CompileEventHandlerInternal(scriptCX, target, atom,
|
||||
aListenerStruct, aSubType);
|
||||
}
|
||||
result = CompileEventHandlerInternal(jslistener->GetEventContext(),
|
||||
jslistener->GetEventTarget(),
|
||||
atom, aListenerStruct,
|
||||
aSubType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -865,17 +865,17 @@ nsGenericHTMLElement::SetInnerHTML(const nsAString& aInnerHTML)
|
|||
|
||||
nsCOMPtr<nsIDocument> doc = GetOwnerDocument();
|
||||
|
||||
nsCOMPtr<nsIScriptContext> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -170,10 +170,8 @@ NS_NewHTMLImageElement(nsIHTMLContent** aInstancePtrResult,
|
|||
nsresult rv;
|
||||
nsCOMPtr<nsINodeInfo> nodeInfo(aNodeInfo);
|
||||
if (!nodeInfo) {
|
||||
nsCOMPtr<nsIDOMDocument> dom_doc;
|
||||
nsContentUtils::GetDocumentFromCaller(getter_AddRefs(dom_doc));
|
||||
|
||||
nsCOMPtr<nsIDocument> doc(do_QueryInterface(dom_doc));
|
||||
nsCOMPtr<nsIDocument> 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,
|
||||
|
|
|
@ -163,10 +163,8 @@ NS_NewHTMLOptionElement(nsIHTMLContent** aInstancePtrResult,
|
|||
nsresult rv;
|
||||
nsCOMPtr<nsINodeInfo> nodeInfo(aNodeInfo);
|
||||
if (!nodeInfo) {
|
||||
nsCOMPtr<nsIDOMDocument> dom_doc;
|
||||
nsContentUtils::GetDocumentFromCaller(getter_AddRefs(dom_doc));
|
||||
|
||||
nsCOMPtr<nsIDocument> doc(do_QueryInterface(dom_doc));
|
||||
nsCOMPtr<nsIDocument> doc =
|
||||
do_QueryInterface(nsContentUtils::GetDocumentFromCaller());
|
||||
NS_ENSURE_TRUE(doc, NS_ERROR_UNEXPECTED);
|
||||
|
||||
nsINodeInfoManager *nodeInfoManager = doc->GetNodeInfoManager();
|
||||
|
|
|
@ -207,16 +207,15 @@ nsHTMLScriptEventHandler::Invoke(nsISupports *aTargetObject,
|
|||
|
||||
// Get the script context...
|
||||
nsCOMPtr<nsIDOMDocument> domdoc;
|
||||
nsCOMPtr<nsIScriptContext> scriptContext;
|
||||
nsCOMPtr<nsIScriptGlobalObject> sgo;
|
||||
nsIScriptContext *scriptContext = nsnull;
|
||||
|
||||
mOuter->GetOwnerDocument(getter_AddRefs(domdoc));
|
||||
|
||||
nsCOMPtr<nsIDocument> 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
|
||||
|
|
|
@ -2093,8 +2093,7 @@ IsScriptEnabled(nsIDocument *aDoc, nsIDocShell *aContainer)
|
|||
NS_ENSURE_TRUE(globalObject, PR_TRUE);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIScriptContext> scriptContext;
|
||||
globalObject->GetContext(getter_AddRefs(scriptContext));
|
||||
nsIScriptContext *scriptContext = globalObject->GetContext();
|
||||
NS_ENSURE_TRUE(scriptContext, PR_TRUE);
|
||||
|
||||
JSContext* cx = (JSContext *) scriptContext->GetNativeContext();
|
||||
|
|
|
@ -999,8 +999,7 @@ nsHTMLDocument::EndLoad()
|
|||
stack->Peek(&cx);
|
||||
|
||||
if (cx) {
|
||||
nsCOMPtr<nsIScriptContext> 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<nsIDOMDocument> domDoc;
|
||||
nsContentUtils::GetDocumentFromCaller(getter_AddRefs(domDoc));
|
||||
nsIDOMDocument *domDoc = nsContentUtils::GetDocumentFromCaller();
|
||||
|
||||
nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDoc));
|
||||
if (!doc) {
|
||||
|
@ -3717,8 +3715,7 @@ nsHTMLDocument::SetDesignMode(const nsAString & aDesignMode)
|
|||
if (!mScriptGlobalObject)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIDocShell> 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<nsIDocShell> docshell;
|
||||
mScriptGlobalObject->GetDocShell(getter_AddRefs(docshell));
|
||||
nsIDocShell *docshell = mScriptGlobalObject->GetDocShell();
|
||||
if (!docshell)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
|
|
|
@ -1143,8 +1143,7 @@ nsBindingManager::GetBindingImplementation(nsIContent* aContent, REFNSIID aIID,
|
|||
if (!global)
|
||||
return NS_NOINTERFACE;
|
||||
|
||||
nsCOMPtr<nsIScriptContext> 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<nsIXPConnectWrappedNative> wrapper;
|
||||
|
||||
xpConnect->GetWrappedNativeOfNativeObject(jscontext,
|
||||
JS_GetGlobalObject(jscontext),
|
||||
aContent,
|
||||
|
|
|
@ -958,8 +958,7 @@ nsXBLBinding::ChangeDocument(nsIDocument* aOldDocument, nsIDocument* aNewDocumen
|
|||
if (interfaceElement) {
|
||||
nsIScriptGlobalObject *global = aOldDocument->GetScriptGlobalObject();
|
||||
if (global) {
|
||||
nsCOMPtr<nsIScriptContext> 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<nsIAtom> eventName = do_GetAtom(eventStr);
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIDocument> document = aElement->GetDocument();
|
||||
if (!document)
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIDOMEventReceiver> 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<nsIScriptContext> context;
|
||||
rv = global->GetContext(getter_AddRefs(context));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (!context) return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIEventListenerManager> 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;
|
||||
}
|
||||
|
|
|
@ -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<nsIDOMScriptObjectFactory> factory = do_GetService(kDOMScriptObjectFactoryCID);
|
||||
NS_ENSURE_TRUE(factory, NS_ERROR_FAILURE);
|
||||
NS_ENSURE_TRUE(factory, nsnull);
|
||||
|
||||
nsresult rv = factory->NewScriptContext(nsnull, getter_AddRefs(mScriptContext));
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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; };
|
||||
|
||||
|
|
|
@ -62,10 +62,7 @@ nsXBLProtoImpl::InstallImplementation(nsXBLPrototypeBinding* aBinding, nsIConten
|
|||
nsIScriptGlobalObject *global = document->GetScriptGlobalObject();
|
||||
if (!global) return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIScriptContext> 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<nsIScriptGlobalObject> globalObject;
|
||||
globalOwner->GetScriptGlobalObject(getter_AddRefs(globalObject));
|
||||
|
||||
nsCOMPtr<nsIScriptContext> context;
|
||||
globalObject->GetContext(getter_AddRefs(context));
|
||||
|
||||
nsIScriptContext *context = globalObject->GetContext();
|
||||
|
||||
void* classObject;
|
||||
JSObject* scopeObject = globalObject->GetGlobalJSObject();
|
||||
nsresult rv = aBinding->InitClass(mClassName, context, scopeObject, &classObject);
|
||||
|
|
|
@ -395,8 +395,7 @@ nsXBLPrototypeHandler::ExecuteHandler(nsIDOMEventReceiver* aReceiver,
|
|||
if (!boundGlobal)
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIScriptContext> boundContext;
|
||||
boundGlobal->GetContext(getter_AddRefs(boundContext));
|
||||
nsIScriptContext *boundContext = boundGlobal->GetContext();
|
||||
if (!boundContext) return NS_OK;
|
||||
|
||||
JSObject* scriptObject = nsnull;
|
||||
|
|
|
@ -248,8 +248,7 @@ nsXBLWindowHandler :: IsEditor()
|
|||
return PR_FALSE;
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> obj(do_QueryInterface(focusedWindow));
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
obj->GetDocShell(getter_AddRefs(docShell));
|
||||
nsIDocShell *docShell = obj->GetDocShell();
|
||||
nsCOMPtr<nsIPresShell> presShell;
|
||||
if (docShell)
|
||||
docShell->GetPresShell(getter_AddRefs(presShell));
|
||||
|
|
|
@ -340,9 +340,9 @@ nsXMLDocument::GetLoadGroup(nsILoadGroup **aLoadGroup)
|
|||
*aLoadGroup = nsnull;
|
||||
|
||||
if (mScriptContext) {
|
||||
nsCOMPtr<nsIScriptGlobalObject> global;
|
||||
mScriptContext->GetGlobalObject(getter_AddRefs(global));
|
||||
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(global);
|
||||
nsCOMPtr<nsIDOMWindow> window =
|
||||
do_QueryInterface(mScriptContext->GetGlobalObject());
|
||||
|
||||
if (window) {
|
||||
nsCOMPtr<nsIDOMDocument> domdoc;
|
||||
window->GetDocument(getter_AddRefs(domdoc));
|
||||
|
@ -381,15 +381,14 @@ nsXMLDocument::Load(const nsAString& aUrl, PRBool *aReturn)
|
|||
mPrincipal = principal;
|
||||
mListenerManager = elm;
|
||||
|
||||
nsCOMPtr<nsIScriptContext> callingContext;
|
||||
nsIScriptContext *callingContext = nsnull;
|
||||
|
||||
nsCOMPtr<nsIJSContextStack> 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<nsIScriptGlobalObject> sgo;
|
||||
callingContext->GetGlobalObject(getter_AddRefs(sgo));
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> window(do_QueryInterface(sgo));
|
||||
nsCOMPtr<nsIDOMWindow> window =
|
||||
do_QueryInterface(callingContext->GetGlobalObject());
|
||||
|
||||
if (window) {
|
||||
nsCOMPtr<nsIDOMDocument> dom_doc;
|
||||
|
|
|
@ -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<nsIScriptContext> 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<nsIEventListenerManager> manager;
|
||||
|
||||
nsIContent *root = mDocument->GetRootContent();
|
||||
nsCOMPtr<nsIContent> content(do_QueryInterface(NS_STATIC_CAST(nsIStyledContent*, this)));
|
||||
if ((!root || root == content) && !NodeInfo()->Equals(nsXULAtoms::overlay)) {
|
||||
nsIScriptGlobalObject *global = mDocument->GetScriptGlobalObject();
|
||||
|
||||
nsCOMPtr<nsIDOMEventReceiver> receiver = do_QueryInterface(global);
|
||||
if (! receiver)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
nsCOMPtr<nsIEventListenerManager> 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<nsIEventListenerManager> 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<nsIScriptContext> 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<nsIScriptContext> context;
|
||||
nsIScriptContext *context = nsnull;
|
||||
|
||||
{
|
||||
nsCOMPtr<nsIScriptGlobalObject> global;
|
||||
nsCOMPtr<nsIScriptGlobalObjectOwner> globalOwner
|
||||
= do_QueryInterface(aPrototypeDocument);
|
||||
nsCOMPtr<nsIScriptGlobalObject> 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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -554,38 +554,33 @@ XULPopupListenerImpl::LaunchPopup(PRInt32 aClientX, PRInt32 aClientY)
|
|||
return NS_OK;
|
||||
|
||||
// We have some popup content. Obtain our window.
|
||||
nsCOMPtr<nsIScriptContext> context;
|
||||
nsCOMPtr<nsIScriptGlobalObject> global = document->GetScriptGlobalObject();
|
||||
if (global) {
|
||||
if ((NS_OK == global->GetContext(getter_AddRefs(context))) && context) {
|
||||
// Get the DOM window
|
||||
nsCOMPtr<nsIDOMWindowInternal> domWindow = do_QueryInterface(global);
|
||||
if (domWindow != nsnull) {
|
||||
// Find out if we're anchored.
|
||||
mPopupContent = popupContent.get();
|
||||
nsCOMPtr<nsIDOMWindowInternal> 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<nsIBoxObject> popupBox;
|
||||
nsCOMPtr<nsIDOMXULElement> xulPopupElt(do_QueryInterface(mPopupContent));
|
||||
xulPopupElt->GetBoxObject(getter_AddRefs(popupBox));
|
||||
nsCOMPtr<nsIPopupBoxObject> 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<nsIBoxObject> popupBox;
|
||||
nsCOMPtr<nsIDOMXULElement> xulPopupElt(do_QueryInterface(mPopupContent));
|
||||
xulPopupElt->GetBoxObject(getter_AddRefs(popupBox));
|
||||
nsCOMPtr<nsIPopupBoxObject> popupBoxObject(do_QueryInterface(popupBox));
|
||||
if (popupBoxObject)
|
||||
popupBoxObject->ShowPopup(mElement, mPopupContent, xPos, yPos,
|
||||
type.get(), anchorAlignment.get(),
|
||||
popupAlignment.get());
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
|
|
@ -1446,8 +1446,7 @@ XULContentSinkImpl::OpenScript(const PRUnichar** aAttributes,
|
|||
if (doc) {
|
||||
nsIScriptGlobalObject* globalObject = doc->GetScriptGlobalObject();
|
||||
if (globalObject) {
|
||||
nsCOMPtr<nsIScriptContext> scriptContext;
|
||||
globalObject->GetContext(getter_AddRefs(scriptContext));
|
||||
nsIScriptContext *scriptContext = globalObject->GetContext();
|
||||
if (scriptContext)
|
||||
script->DeserializeOutOfLine(nsnull, scriptContext);
|
||||
}
|
||||
|
|
|
@ -3252,8 +3252,7 @@ nsXULDocument::OnStreamComplete(nsIStreamLoader* aLoader,
|
|||
|
||||
NS_ASSERTION(global != nsnull, "master prototype w/o global?!");
|
||||
if (global) {
|
||||
nsCOMPtr<nsIScriptContext> 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<nsIScriptContext> 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<nsIScriptContext> 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<nsIScriptGlobalObject> globalObject;
|
||||
rv |= GetScriptGlobalObject(getter_AddRefs(globalObject));
|
||||
|
||||
nsCOMPtr<nsIScriptContext> 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<nsIDOMScriptObjectFactory> factory =
|
||||
do_GetService(kDOMScriptObjectFactoryCID);
|
||||
NS_ENSURE_TRUE(factory, NS_ERROR_FAILURE);
|
||||
NS_ENSURE_TRUE(factory, nsnull);
|
||||
|
||||
nsresult rv =
|
||||
factory->NewScriptContext(nsnull, getter_AddRefs(mScriptContext));
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -790,8 +790,7 @@ nsXULTemplateBuilder::InitHTMLTemplateRoot()
|
|||
if (! global)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
nsCOMPtr<nsIScriptContext> context;
|
||||
global->GetContext(getter_AddRefs(context));
|
||||
nsIScriptContext *context = global->GetContext();
|
||||
if (! context)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -41,7 +41,6 @@ EXPORTS=nsIScriptContext.h \
|
|||
nsIScriptObjectOwner.h \
|
||||
nsIScriptObjectPrincipal.h \
|
||||
nsIScriptGlobalObject.h \
|
||||
nsIScriptEventListener.h \
|
||||
nsIDOMScriptObjectFactory.h \
|
||||
nsDOMCID.h \
|
||||
nsIScriptExternalNameSet.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;
|
||||
|
|
|
@ -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__
|
||||
|
|
|
@ -65,7 +65,8 @@ typedef void (*nsScriptTerminationFunc)(nsISupports* aRef);
|
|||
* should be removed in a short time. Ideally this interface will be
|
||||
* language neutral</I>
|
||||
*/
|
||||
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<nsIScriptContext> 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__
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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__
|
||||
|
|
|
@ -278,14 +278,13 @@ ScrollbarsPropImpl::~ScrollbarsPropImpl()
|
|||
NS_IMETHODIMP
|
||||
ScrollbarsPropImpl::GetVisible(PRBool *aVisible)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aVisible);
|
||||
*aVisible = PR_TRUE; // one assumes
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> domwin(do_QueryReferent(mDOMWindowWeakref));
|
||||
if (domwin) { // dom window not deleted
|
||||
nsCOMPtr<nsIDocShell> docshell;
|
||||
mDOMWindow->GetDocShell(getter_AddRefs(docshell));
|
||||
nsCOMPtr<nsIScrollable> scroller(do_QueryInterface(docshell));
|
||||
nsCOMPtr<nsIScrollable> 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<nsIDOMWindow> domwin(do_QueryReferent(mDOMWindowWeakref));
|
||||
if (domwin) { // dom window must still exist. use away.
|
||||
nsCOMPtr<nsIDocShell> docshell;
|
||||
mDOMWindow->GetDocShell(getter_AddRefs(docshell));
|
||||
nsCOMPtr<nsIScrollable> scroller(do_QueryInterface(docshell));
|
||||
nsCOMPtr<nsIScrollable> scroller =
|
||||
do_QueryInterface(mDOMWindow->GetDocShell());
|
||||
|
||||
if (scroller) {
|
||||
PRInt32 prefValue = aVisible ? NS_STYLE_OVERFLOW_AUTO :
|
||||
NS_STYLE_OVERFLOW_HIDDEN;
|
||||
|
|
|
@ -2965,8 +2965,7 @@ needsSecurityCheck(JSContext *cx, nsIXPConnectWrappedNative *wrapper)
|
|||
return PR_TRUE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIScriptContext> 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<nsIScriptContext> 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<nsIScriptObjectOwner> owner(do_QueryInterface(native));
|
||||
if (owner) {
|
||||
nsCOMPtr<nsIScriptContext> 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<nsIScriptObjectOwner> owner(do_QueryInterface(native));
|
||||
if (owner) {
|
||||
nsCOMPtr<nsIScriptContext> 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<nsIScriptGlobalObject> sgo(do_QueryInterface(native));
|
||||
NS_ENSURE_TRUE(sgo, NS_ERROR_UNEXPECTED);
|
||||
|
||||
nsCOMPtr<nsIScriptContext> 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<nsISupports> native;
|
||||
wrapper->GetNative(getter_AddRefs(native));
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(native));
|
||||
NS_ENSURE_TRUE(sgo, NS_ERROR_UNEXPECTED);
|
||||
|
||||
nsCOMPtr<nsIScriptContext> 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<nsIDocShell> docShell;
|
||||
sgo->GetDocShell(getter_AddRefs(docShell));
|
||||
JSString *str = JSVAL_TO_STRING(id);
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeNode> dsn(do_QueryInterface(docShell));
|
||||
nsCOMPtr<nsIDocShellTreeNode> dsn(do_QueryInterface(sgo->GetDocShell()));
|
||||
|
||||
PRInt32 count = 0;
|
||||
|
||||
|
@ -4404,7 +4388,9 @@ nsWindowSH::Finalize(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
|||
nsCOMPtr<nsIScriptGlobalObject> 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<nsIScriptContext> 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<nsISupports> 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<nsIAtom> atom(do_GetAtom(ustr));
|
||||
nsCOMPtr<nsIAtom> 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<nsISupports> 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 <input name="1">. 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);
|
||||
|
||||
|
|
|
@ -136,9 +136,7 @@ nsFocusController::SetFocusedWindow(nsIDOMWindowInternal* aWindow)
|
|||
if (aWindow && (mCurrentWindow != aWindow)) {
|
||||
nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(aWindow);
|
||||
if (sgo) {
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
sgo->GetDocShell(getter_AddRefs(docShell));
|
||||
nsCOMPtr<nsIBaseWindow> basewin = do_QueryInterface(docShell);
|
||||
nsCOMPtr<nsIBaseWindow> basewin = do_QueryInterface(sgo->GetDocShell());
|
||||
if (basewin)
|
||||
basewin->SetFocus();
|
||||
}
|
||||
|
@ -513,11 +511,11 @@ nsFocusController::UpdateWWActiveWindow()
|
|||
|
||||
// This gets the toplevel DOMWindow
|
||||
nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(mCurrentWindow);
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
sgo->GetDocShell(getter_AddRefs(docShell));
|
||||
if (!docShell) return;
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(docShell));
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem =
|
||||
do_QueryInterface(sgo->GetDocShell());
|
||||
if (!docShellAsItem) return;
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> rootItem;
|
||||
docShellAsItem->GetRootTreeItem(getter_AddRefs(rootItem));
|
||||
NS_ASSERTION(rootItem, "Invalid docshell tree - no root!");
|
||||
|
|
|
@ -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<nsIDOMWindowInternal> 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<nsIContent> content(do_QueryInterface(mFrameElement));
|
||||
|
||||
nsCOMPtr<nsIDOMWindowInternal> parent;
|
||||
GetParentInternal(getter_AddRefs(parent));
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> 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 <frame src="javascript:xxx">, in
|
||||
// that case the global window is used in JS before we've loaded
|
||||
// a document into the window.
|
||||
nsCOMPtr<nsIDOMWindowInternal> parent;
|
||||
|
||||
GetParentInternal(getter_AddRefs(parent));
|
||||
nsCOMPtr<nsIScriptObjectPrincipal> objPrincipal =
|
||||
do_QueryInterface(GetParentInternal());
|
||||
|
||||
if (parent) {
|
||||
nsCOMPtr<nsIScriptObjectPrincipal> objPrincipal(do_QueryInterface(parent));
|
||||
|
||||
if (objPrincipal) {
|
||||
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<nsIScriptGlobalObject> openerSGO(do_QueryInterface(mOpener));
|
||||
if (openerSGO) {
|
||||
nsCOMPtr<nsIDocShell> openerDocShell;
|
||||
openerSGO->GetDocShell(getter_AddRefs(openerDocShell));
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(openerDocShell));
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem =
|
||||
do_QueryInterface(openerSGO->GetDocShell());
|
||||
|
||||
if (docShellAsItem) {
|
||||
nsCOMPtr<nsIDocShellTreeItem> 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<nsIDocShell> docShell;
|
||||
GetDocShell(getter_AddRefs(docShell));
|
||||
nsCOMPtr<nsIDocShellTreeItem> treeItem = do_QueryInterface(docShell);
|
||||
nsCOMPtr<nsIDocShellTreeItem> treeItem = do_QueryInterface(mDocShell);
|
||||
nsCOMPtr<nsIDocShellTreeItem> rootItem;
|
||||
treeItem->GetRootTreeItem(getter_AddRefs(rootItem));
|
||||
nsCOMPtr<nsIDOMWindowInternal> window = do_GetInterface(rootItem);
|
||||
|
@ -3282,12 +3253,9 @@ GlobalWindowImpl::FireAbuseEvents(PRBool aBlocked, PRBool aWindow,
|
|||
JSContext *cx = nsnull;
|
||||
stack->Peek(&cx);
|
||||
if (cx) {
|
||||
nsCOMPtr<nsIScriptContext> currentCX;
|
||||
nsJSUtils::GetDynamicScriptContext(cx, getter_AddRefs(currentCX));
|
||||
nsIScriptContext *currentCX = nsJSUtils::GetDynamicScriptContext(cx);
|
||||
if (currentCX) {
|
||||
nsCOMPtr<nsIScriptGlobalObject> gobj;
|
||||
currentCX->GetGlobalObject(getter_AddRefs(gobj));
|
||||
contextWindow = do_QueryInterface(gobj);
|
||||
contextWindow = do_QueryInterface(currentCX->GetGlobalObject());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3654,13 +3622,13 @@ GlobalWindowImpl::Close()
|
|||
}
|
||||
|
||||
if (cx) {
|
||||
nsCOMPtr<nsIScriptContext> 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<nsIDocShell> docShell;
|
||||
GetDocShell(getter_AddRefs(docShell));
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellTI(do_QueryInterface(docShell));
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellTI(do_QueryInterface(mDocShell));
|
||||
|
||||
if (!docShellTI) {
|
||||
return NS_OK;
|
||||
|
@ -4361,11 +4326,11 @@ GlobalWindowImpl::GetPrivateRoot(nsIDOMWindowInternal ** aParent)
|
|||
GetTop(getter_AddRefs(parent));
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> parentTop = do_QueryInterface(parent);
|
||||
nsCOMPtr<nsIDocShell> 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<nsIDOMWindow> 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<nsIDOMWindowInternal> 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<nsIScriptContext> 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<nsIURI> uriToLoad;
|
||||
|
||||
nsCOMPtr<nsIScriptContext> scriptcx;
|
||||
nsJSUtils::GetDynamicScriptContext(cx, getter_AddRefs(scriptcx));
|
||||
nsIScriptContext *scriptcx = nsJSUtils::GetDynamicScriptContext(cx);
|
||||
|
||||
if (scriptcx) {
|
||||
nsCOMPtr<nsIScriptGlobalObject> gobj;
|
||||
scriptcx->GetGlobalObject(getter_AddRefs(gobj));
|
||||
nsCOMPtr<nsIDOMWindow> caller(do_QueryInterface(gobj));
|
||||
nsCOMPtr<nsIDOMWindow> caller =
|
||||
do_QueryInterface(scriptcx->GetGlobalObject());
|
||||
|
||||
if (caller) {
|
||||
nsCOMPtr<nsIDOMDocument> callerDOMdoc;
|
||||
caller->GetDocument(getter_AddRefs(callerDOMdoc));
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -206,8 +206,7 @@ nsSelectionCommandsBase::GetPresShellFromWindow(nsIDOMWindow *aWindow, nsIPresSh
|
|||
nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(aWindow));
|
||||
NS_ENSURE_TRUE(sgo, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIDocShell> 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<nsIScriptGlobalObject> sgo(do_QueryInterface(window));
|
||||
NS_ENSURE_TRUE(sgo, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
sgo->GetDocShell(getter_AddRefs(docShell));
|
||||
nsIDocShell *docShell = sgo->GetDocShell();
|
||||
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIContentViewer> viewer;
|
||||
|
@ -834,9 +832,7 @@ nsClipboardDragDropHookCommand::DoCommandParams(const char *aCommandName,
|
|||
nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(window);
|
||||
NS_ENSURE_TRUE(sgo, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
sgo->GetDocShell(getter_AddRefs(docShell));
|
||||
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
|
||||
nsIDocShell *docShell = sgo->GetDocShell();
|
||||
|
||||
nsCOMPtr<nsIClipboardDragDropHookList> obj = do_GetInterface(docShell);
|
||||
if (!obj) return NS_ERROR_INVALID_ARG;
|
||||
|
|
|
@ -141,14 +141,13 @@ NS_ScriptErrorReporter(JSContext *cx,
|
|||
const char *message,
|
||||
JSErrorReport *report)
|
||||
{
|
||||
nsCOMPtr<nsIScriptContext> context;
|
||||
// XXX this means we are not going to get error reports on non DOM contexts
|
||||
nsIScriptContext *context = nsJSUtils::GetDynamicScriptContext(cx);
|
||||
|
||||
nsEventStatus status = nsEventStatus_eIgnore;
|
||||
|
||||
// XXX this means we are not going to get error reports on non DOM contexts
|
||||
nsJSUtils::GetDynamicScriptContext(cx, getter_AddRefs(context));
|
||||
if (context) {
|
||||
nsCOMPtr<nsIScriptGlobalObject> 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<nsIDocShell> docShell;
|
||||
nsCOMPtr<nsIScriptGlobalObjectOwner> 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<nsIPresContext> presContext;
|
||||
docShell->GetPresContext(getter_AddRefs(presContext));
|
||||
nsCOMPtr<nsIPresContext> 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<nsIScriptGlobalObject> global;
|
||||
ctx->GetGlobalObject(getter_AddRefs(global));
|
||||
nsIScriptGlobalObject *global = ctx->GetGlobalObject();
|
||||
NS_ENSURE_TRUE(global, JS_TRUE);
|
||||
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
global->GetDocShell(getter_AddRefs(docShell));
|
||||
nsIDocShell *docShell = global->GetDocShell();
|
||||
NS_ENSURE_TRUE(docShell, JS_TRUE);
|
||||
|
||||
nsCOMPtr<nsIInterfaceRequestor> 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<nsIScriptGlobalObject> global;
|
||||
GetGlobalObject(getter_AddRefs(global));
|
||||
nsIScriptGlobalObject *global = GetGlobalObject();
|
||||
if (!global)
|
||||
return NS_ERROR_FAILURE;
|
||||
nsCOMPtr<nsIScriptObjectPrincipal> objPrincipal = do_QueryInterface(global, &rv);
|
||||
nsCOMPtr<nsIScriptObjectPrincipal> 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<nsIScriptSecurityManager> 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<nsIScriptGlobalObject> global;
|
||||
GetGlobalObject(getter_AddRefs(global));
|
||||
nsIScriptGlobalObject *global = GetGlobalObject();
|
||||
if (!global)
|
||||
return NS_ERROR_FAILURE;
|
||||
nsCOMPtr<nsIScriptObjectPrincipal> objPrincipal = do_QueryInterface(global, &rv);
|
||||
|
@ -849,10 +831,8 @@ nsJSContext::EvaluateString(const nsAString& aScript,
|
|||
// From here on, we must JSPRINCIPALS_DROP(jsprin) before returning...
|
||||
|
||||
PRBool ok = PR_FALSE;
|
||||
nsCOMPtr<nsIScriptSecurityManager> 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<nsIScriptSecurityManager> 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<nsIScriptGlobalObject> global;
|
||||
GetGlobalObject(getter_AddRefs(global));
|
||||
nsIScriptGlobalObject *global = GetGlobalObject();
|
||||
if (global) {
|
||||
// XXXbe why the two-step QI? speed up via a new GetGlobalObjectData func?
|
||||
nsCOMPtr<nsIScriptObjectPrincipal> 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<nsIScriptSecurityManager> securityManager;
|
||||
rv = GetSecurityManager(getter_AddRefs(securityManager));
|
||||
if (NS_FAILED(rv))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIJSContextStack> 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<nsISupports> native =
|
||||
nsCOMPtr<nsIScriptGlobalObject> sgo;
|
||||
nsISupports *priv =
|
||||
(nsISupports *)::JS_GetPrivate(mContext, global);
|
||||
|
||||
nsCOMPtr<nsIXPConnectWrappedNative> 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<nsISupports> 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<nsIScriptGlobalObject> 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;
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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<nsIXPConnectWrappedNative> wrapper(do_QueryInterface(supports));
|
||||
NS_ENSURE_TRUE(wrapper, NS_ERROR_UNEXPECTED);
|
||||
NS_ENSURE_TRUE(wrapper, nsnull);
|
||||
|
||||
nsCOMPtr<nsISupports> native;
|
||||
wrapper->GetNative(getter_AddRefs(native));
|
||||
|
||||
return CallQueryInterface(native, aNativeGlobal);
|
||||
nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(native));
|
||||
|
||||
// We're returning a pointer to something that's about to be
|
||||
// released, but that's ok here.
|
||||
return sgo;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJSUtils::GetStaticScriptContext(JSContext* aContext, JSObject* aObj,
|
||||
nsIScriptContext** aScriptContext)
|
||||
nsIScriptContext *
|
||||
nsJSUtils::GetStaticScriptContext(JSContext* aContext, JSObject* aObj)
|
||||
{
|
||||
nsCOMPtr<nsIScriptGlobalObject> 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<nsIScriptContext> 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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__ */
|
||||
|
|
|
@ -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<nsIScriptGlobalObject> nativeGlob;
|
||||
nsJSUtils::GetDynamicScriptGlobal(cx, getter_AddRefs(nativeGlob));
|
||||
NS_ENSURE_TRUE(nativeGlob, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(nativeGlob);
|
||||
nsCOMPtr<nsIDOMWindow> window =
|
||||
do_QueryInterface(nsJSUtils::GetDynamicScriptGlobal(cx));
|
||||
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> 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<nsIScriptContext> 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<nsIScriptGlobalObject> nativeGlob;
|
||||
nsJSUtils::GetDynamicScriptGlobal(cx, getter_AddRefs(nativeGlob));
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(nativeGlob, &rv);
|
||||
nsCOMPtr<nsIDOMWindow> window =
|
||||
do_QueryInterface(nsJSUtils::GetDynamicScriptGlobal(cx), &rv);
|
||||
|
||||
if (window) {
|
||||
nsCOMPtr<nsIDOMDocument> domDoc;
|
||||
|
|
|
@ -1,388 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*
|
||||
* This Original Code has been modified by IBM Corporation.
|
||||
* Modifications made by IBM described herein are
|
||||
* Copyright (c) International Business Machines
|
||||
* Corporation, 2000
|
||||
*
|
||||
* Modifications to Mozilla code or documentation
|
||||
* identified per MPL Section 3.3
|
||||
*
|
||||
* Date Modified by Description of modification
|
||||
* 03/27/2000 IBM Corp. Added PR_CALLBACK for Optlink
|
||||
* use in OS2
|
||||
*/
|
||||
#include "nscore.h"
|
||||
#include "nsIGenericFactory.h"
|
||||
|
||||
#include "nsJSEnvironment.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsDOMCID.h"
|
||||
#include "nsIDOMScriptObjectFactory.h"
|
||||
#include "nsIScriptEventListener.h"
|
||||
#include "nsIJSEventListener.h"
|
||||
#include "nsIScriptContext.h"
|
||||
#include "nsDOMClassInfo.h"
|
||||
#include "nsGlobalWindow.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsIJSContextStack.h"
|
||||
#include "nsIExceptionService.h"
|
||||
#ifdef MOZ_XUL
|
||||
#include "nsIXULPrototypeCache.h"
|
||||
#endif
|
||||
#include "nsCRT.h"
|
||||
|
||||
#include "nsIController.h"
|
||||
#include "nsIControllerContext.h"
|
||||
#include "nsIControllerCommandTable.h"
|
||||
#include "nsGlobalWindowCommands.h"
|
||||
|
||||
#include "nsScriptNameSpaceManager.h"
|
||||
#include "nsDOMException.h"
|
||||
|
||||
#include "nsJSProtocolHandler.h"
|
||||
|
||||
|
||||
#define NS_WINDOWCOMMANDTABLE_CID \
|
||||
{ /* 0DE2FBFA-6B7F-11D7-BBBA-0003938A9D96 */ \
|
||||
0x0DE2FBFA, 0x6B7F, 0x11D7, {0xBB, 0xBA, 0x00, 0x03, 0x93, 0x8A, 0x9D, 0x96} }
|
||||
|
||||
static NS_DEFINE_CID(kWindowCommandTableCID, NS_WINDOWCOMMANDTABLE_CID);
|
||||
|
||||
|
||||
extern nsresult NS_CreateScriptContext(nsIScriptGlobalObject *aGlobal,
|
||||
nsIScriptContext **aContext);
|
||||
|
||||
extern nsresult NS_NewJSEventListener(nsIDOMEventListener **aInstancePtrResult,
|
||||
nsIScriptContext *aContext,
|
||||
nsISupports *aObject);
|
||||
|
||||
extern nsresult NS_NewScriptGlobalObject(PRBool aIsChrome,
|
||||
nsIScriptGlobalObject **aGlobal);
|
||||
|
||||
extern nsresult NS_NewDOMException(nsresult aResult,
|
||||
nsIException* aDefaultException,
|
||||
nsIException** aException);
|
||||
|
||||
extern nsresult NS_NewRangeException(nsresult aResult,
|
||||
nsIException* aDefaultException,
|
||||
nsIException** aException);
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsDOMSOFactory : public nsIDOMScriptObjectFactory,
|
||||
public nsIObserver,
|
||||
public nsIExceptionProvider
|
||||
{
|
||||
public:
|
||||
nsDOMSOFactory();
|
||||
virtual ~nsDOMSOFactory();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIObserver
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
// nsIExceptionProvider
|
||||
NS_DECL_NSIEXCEPTIONPROVIDER
|
||||
|
||||
NS_IMETHOD NewScriptContext(nsIScriptGlobalObject *aGlobal,
|
||||
nsIScriptContext **aContext);
|
||||
|
||||
NS_IMETHOD NewJSEventListener(nsIScriptContext *aContext,
|
||||
nsISupports* aObject,
|
||||
nsIDOMEventListener ** aInstancePtrResult);
|
||||
|
||||
NS_IMETHOD NewScriptGlobalObject(PRBool aIsChrome,
|
||||
nsIScriptGlobalObject **aGlobal);
|
||||
|
||||
NS_IMETHOD_(nsISupports *)GetClassInfoInstance(nsDOMClassInfoID aID);
|
||||
NS_IMETHOD_(nsISupports *)GetExternalClassInfoInstance(const nsAString& aName);
|
||||
|
||||
NS_IMETHOD RegisterDOMClassInfo(const char *aName,
|
||||
nsDOMClassInfoExternalConstructorFnc aConstructorFptr,
|
||||
const nsIID *aProtoChainInterface,
|
||||
const nsIID **aInterfaces,
|
||||
PRUint32 aScriptableFlags,
|
||||
PRBool aHasClassInterface,
|
||||
const nsCID *aConstructorCID);
|
||||
};
|
||||
|
||||
nsDOMSOFactory::nsDOMSOFactory()
|
||||
{
|
||||
|
||||
nsCOMPtr<nsIObserverService> observerService =
|
||||
do_GetService("@mozilla.org/observer-service;1");
|
||||
|
||||
if (observerService) {
|
||||
observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIExceptionService> xs =
|
||||
do_GetService(NS_EXCEPTIONSERVICE_CONTRACTID);
|
||||
|
||||
if (xs) {
|
||||
xs->RegisterExceptionProvider(this, NS_ERROR_MODULE_DOM);
|
||||
xs->RegisterExceptionProvider(this, NS_ERROR_MODULE_DOM_RANGE);
|
||||
}
|
||||
}
|
||||
|
||||
nsDOMSOFactory::~nsDOMSOFactory()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(nsDOMSOFactory)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMScriptObjectFactory)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIObserver)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIExceptionProvider)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMScriptObjectFactory)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
|
||||
NS_IMPL_ADDREF(nsDOMSOFactory)
|
||||
NS_IMPL_RELEASE(nsDOMSOFactory)
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMSOFactory::NewScriptContext(nsIScriptGlobalObject *aGlobal,
|
||||
nsIScriptContext **aContext)
|
||||
{
|
||||
return NS_CreateScriptContext(aGlobal, aContext);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMSOFactory::NewJSEventListener(nsIScriptContext *aContext,
|
||||
nsISupports *aObject,
|
||||
nsIDOMEventListener **aInstancePtrResult)
|
||||
{
|
||||
return NS_NewJSEventListener(aInstancePtrResult, aContext, aObject);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMSOFactory::NewScriptGlobalObject(PRBool aIsChrome,
|
||||
nsIScriptGlobalObject **aGlobal)
|
||||
{
|
||||
return NS_NewScriptGlobalObject(aIsChrome, aGlobal);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(nsISupports *)
|
||||
nsDOMSOFactory::GetClassInfoInstance(nsDOMClassInfoID aID)
|
||||
{
|
||||
return nsDOMClassInfo::GetClassInfoInstance(aID);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(nsISupports *)
|
||||
nsDOMSOFactory::GetExternalClassInfoInstance(const nsAString& aName)
|
||||
{
|
||||
extern nsScriptNameSpaceManager *gNameSpaceManager;
|
||||
|
||||
NS_ENSURE_TRUE(gNameSpaceManager, nsnull);
|
||||
|
||||
const nsGlobalNameStruct *globalStruct;
|
||||
gNameSpaceManager->LookupName(aName, &globalStruct);
|
||||
if (globalStruct) {
|
||||
if (globalStruct->mType == nsGlobalNameStruct::eTypeExternalClassInfoCreator) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIDOMCIExtension> creator(do_CreateInstance(globalStruct->mCID, &rv));
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
||||
rv = creator->RegisterDOMCI(NS_ConvertUCS2toUTF8(aName).get(), this);
|
||||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
|
||||
rv = gNameSpaceManager->LookupName(aName, &globalStruct);
|
||||
NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && globalStruct, nsnull);
|
||||
|
||||
NS_ASSERTION(globalStruct->mType == nsGlobalNameStruct::eTypeExternalClassInfo,
|
||||
"The classinfo data for this class didn't get registered.");
|
||||
}
|
||||
if (globalStruct->mType == nsGlobalNameStruct::eTypeExternalClassInfo) {
|
||||
return nsDOMClassInfo::GetClassInfoInstance(globalStruct->mData);
|
||||
}
|
||||
}
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMSOFactory::Observe(nsISupports *aSubject,
|
||||
const char *aTopic,
|
||||
const PRUnichar *someData)
|
||||
{
|
||||
if (!nsCRT::strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
|
||||
#ifdef MOZ_XUL
|
||||
// Flush the XUL cache since it holds JS roots, and we're about to
|
||||
// start the final GC.
|
||||
nsCOMPtr<nsIXULPrototypeCache> cache =
|
||||
do_GetService("@mozilla.org/xul/xul-prototype-cache;1");
|
||||
|
||||
if (cache)
|
||||
cache->Flush();
|
||||
#endif
|
||||
|
||||
nsCOMPtr<nsIThreadJSContextStack> stack =
|
||||
do_GetService("@mozilla.org/js/xpc/ContextStack;1");
|
||||
|
||||
if (stack) {
|
||||
JSContext *cx = nsnull;
|
||||
|
||||
stack->GetSafeJSContext(&cx);
|
||||
|
||||
if (cx) {
|
||||
// Do one final GC to clean things up before shutdown.
|
||||
|
||||
::JS_GC(cx);
|
||||
}
|
||||
}
|
||||
|
||||
GlobalWindowImpl::ShutDown();
|
||||
nsDOMClassInfo::ShutDown();
|
||||
nsJSEnvironment::ShutDown();
|
||||
|
||||
nsCOMPtr<nsIExceptionService> xs =
|
||||
do_GetService(NS_EXCEPTIONSERVICE_CONTRACTID);
|
||||
|
||||
if (xs) {
|
||||
xs->UnregisterExceptionProvider(this, NS_ERROR_MODULE_DOM);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMSOFactory::GetException(nsresult result, nsIException *aDefaultException,
|
||||
nsIException **_retval)
|
||||
{
|
||||
if (NS_ERROR_GET_MODULE(result) == NS_ERROR_MODULE_DOM_RANGE) {
|
||||
return NS_NewRangeException(result, aDefaultException, _retval);
|
||||
}
|
||||
return NS_NewDOMException(result, aDefaultException, _retval);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMSOFactory::RegisterDOMClassInfo(const char *aName,
|
||||
nsDOMClassInfoExternalConstructorFnc aConstructorFptr,
|
||||
const nsIID *aProtoChainInterface,
|
||||
const nsIID **aInterfaces,
|
||||
PRUint32 aScriptableFlags,
|
||||
PRBool aHasClassInterface,
|
||||
const nsCID *aConstructorCID)
|
||||
{
|
||||
extern nsScriptNameSpaceManager *gNameSpaceManager;
|
||||
|
||||
NS_ENSURE_TRUE(gNameSpaceManager, NS_ERROR_NOT_INITIALIZED);
|
||||
|
||||
return gNameSpaceManager->RegisterDOMCIData(aName,
|
||||
aConstructorFptr,
|
||||
aProtoChainInterface,
|
||||
aInterfaces,
|
||||
aScriptableFlags,
|
||||
aHasClassInterface,
|
||||
aConstructorCID);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_METHOD
|
||||
CreateWindowCommandTableConstructor(nsISupports *aOuter,
|
||||
REFNSIID aIID, void **aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIControllerCommandTable> commandTable =
|
||||
do_CreateInstance(NS_CONTROLLERCOMMANDTABLE_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = nsWindowCommandRegistration::RegisterWindowCommands(commandTable);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return commandTable->QueryInterface(aIID, aResult);
|
||||
}
|
||||
|
||||
static NS_METHOD
|
||||
CreateWindowControllerWithSingletonCommandTable(nsISupports *aOuter,
|
||||
REFNSIID aIID, void **aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIController> controller =
|
||||
do_CreateInstance("@mozilla.org/embedcomp/base-command-controller;1", &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIControllerCommandTable> windowCommandTable = do_GetService(kWindowCommandTableCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// this is a singleton; make it immutable
|
||||
windowCommandTable->MakeImmutable();
|
||||
|
||||
nsCOMPtr<nsIControllerContext> controllerContext = do_QueryInterface(controller, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
controllerContext->Init(windowCommandTable);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return controller->QueryInterface(aIID, aResult);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDOMSOFactory)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBaseDOMException)
|
||||
|
||||
static const nsModuleComponentInfo gDOMModuleInfo[] = {
|
||||
{ "Script Object Factory",
|
||||
NS_DOM_SCRIPT_OBJECT_FACTORY_CID,
|
||||
nsnull,
|
||||
nsDOMSOFactoryConstructor
|
||||
},
|
||||
{ "Base DOM Exception",
|
||||
NS_BASE_DOM_EXCEPTION_CID,
|
||||
nsnull,
|
||||
nsBaseDOMExceptionConstructor
|
||||
},
|
||||
{ "JavaScript Protocol Handler",
|
||||
NS_JSPROTOCOLHANDLER_CID,
|
||||
NS_JSPROTOCOLHANDLER_CONTRACTID,
|
||||
nsJSProtocolHandler::Create },
|
||||
{ "Window Command Table",
|
||||
NS_WINDOWCOMMANDTABLE_CID,
|
||||
"",
|
||||
CreateWindowCommandTableConstructor
|
||||
},
|
||||
{ "Window Command Controller",
|
||||
NS_WINDOWCONTROLLER_CID,
|
||||
NS_WINDOWCONTROLLER_CONTRACTID,
|
||||
CreateWindowControllerWithSingletonCommandTable
|
||||
},
|
||||
};
|
||||
|
||||
void PR_CALLBACK
|
||||
DOMModuleDestructor(nsIModule *self)
|
||||
{
|
||||
GlobalWindowImpl::ShutDown();
|
||||
nsDOMClassInfo::ShutDown();
|
||||
}
|
||||
|
||||
NS_IMPL_NSGETMODULE_WITH_DTOR(DOM_components, gDOMModuleInfo,
|
||||
DOMModuleDestructor)
|
||||
|
||||
|
|
@ -37,7 +37,7 @@
|
|||
* ***** END LICENSE BLOCK ***** */
|
||||
#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<nsIXPConnectJSObjectHolder> wrapper;
|
||||
rv = xpc->WrapNative(cx, ::JS_GetGlobalObject(cx), mObject,
|
||||
rv = xpc->WrapNative(cx, ::JS_GetGlobalObject(cx), mTarget,
|
||||
NS_GET_IID(nsISupports), getter_AddRefs(wrapper));
|
||||
NS_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
|
||||
*/
|
||||
|
|
|
@ -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<nsIScriptContext> mContext;
|
||||
nsISupports* mObject;
|
||||
nsCOMPtr<nsIAtom> mEventName;
|
||||
|
||||
enum nsReturnResult {
|
||||
|
|
|
@ -184,12 +184,9 @@ nsresult nsJSThunk::EvaluateScript(nsIChannel *aChannel)
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIScriptContext> 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);
|
||||
|
|
|
@ -233,9 +233,7 @@ nsComposerCommandsUpdater::Init(nsIDOMWindow* aDOMWindow)
|
|||
nsCOMPtr<nsIScriptGlobalObject> scriptObject(do_QueryInterface(aDOMWindow));
|
||||
if (scriptObject)
|
||||
{
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
scriptObject->GetDocShell(getter_AddRefs(docShell));
|
||||
mDocShell = docShell.get();
|
||||
mDocShell = scriptObject->GetDocShell();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -126,9 +126,8 @@ NS_IMPL_ISUPPORTS4(nsEditingSession, nsIEditingSession, nsIWebProgressListener,
|
|||
NS_IMETHODIMP
|
||||
nsEditingSession::Init(nsIDOMWindow *aWindow)
|
||||
{
|
||||
nsCOMPtr<nsIDocShell> 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<nsIDocShell> 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<nsIScriptGlobalObject> sgo (do_QueryInterface(aWindow));
|
||||
if (sgo)
|
||||
{
|
||||
nsCOMPtr<nsIScriptContext> 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<nsIDocShell> docShell;
|
||||
rv = GetDocShellFromWindow(aWindow, getter_AddRefs(docShell));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsIDocShell *docShell = GetDocShellFromWindow(aWindow);
|
||||
if (!docShell) return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIPresShell> 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<nsIDocShell> docShell;
|
||||
rv = GetDocShellFromWindow(domWindow, getter_AddRefs(docShell));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsIDocShell *docShell = GetDocShellFromWindow(domWindow);
|
||||
if (!docShell) return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsICommandManager> commandManager = do_GetInterface(docShell);
|
||||
nsCOMPtr<nsPICommandUpdater> commandUpdater =
|
||||
|
@ -978,9 +972,8 @@ nsEditingSession::EndDocumentLoad(nsIWebProgress *aWebProgress,
|
|||
mEditorStatus = eEditorErrorFileNotFound;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocShell> 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<nsIEditorDocShell> 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<nsIDOMWindow> domWindow;
|
||||
nsresult rv = aWebProgress->GetDOMWindow(getter_AddRefs(domWindow));
|
||||
|
||||
nsCOMPtr<nsIDocShell> 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<nsIScriptGlobalObject> 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<nsIDocShell> 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);
|
||||
|
|
|
@ -98,8 +98,7 @@ public:
|
|||
|
||||
protected:
|
||||
|
||||
nsresult GetDocShellFromWindow(nsIDOMWindow *aWindow,
|
||||
nsIDocShell** outDocShell);
|
||||
nsIDocShell * GetDocShellFromWindow(nsIDOMWindow *aWindow);
|
||||
nsresult GetEditorDocShellFromWindow(nsIDOMWindow *aWindow,
|
||||
nsIEditorDocShell** outDocShell);
|
||||
|
||||
|
|
|
@ -438,16 +438,14 @@ GetPluginsContext(PluginInstanceData *pData)
|
|||
nsCOMPtr<nsIDOMWindow> window;
|
||||
NPN_GetValue(pData->pPluginInstance, NPNVDOMWindow,
|
||||
NS_STATIC_CAST(nsIDOMWindow **, getter_AddRefs(window)));
|
||||
if (!window)
|
||||
return nsnull;
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> globalObject(do_QueryInterface(window));
|
||||
if (!globalObject)
|
||||
return nsnull;
|
||||
|
||||
nsCOMPtr<nsIScriptContext> 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());
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -819,9 +819,8 @@ END_COM_MAP()
|
|||
if (!globalObject)
|
||||
return E_UNEXPECTED;
|
||||
|
||||
nsCOMPtr<nsIScriptContext> scriptContext;
|
||||
if (NS_FAILED(globalObject->GetContext(getter_AddRefs(scriptContext))) ||
|
||||
!scriptContext)
|
||||
nsIScriptContext *scriptContext = globalObject->GetContext();
|
||||
if (!scriptContext)
|
||||
return E_UNEXPECTED;
|
||||
|
||||
nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDocument));
|
||||
|
|
|
@ -52,12 +52,10 @@ nsresult nsCommandHandler::GetCommandHandler(nsICommandHandler **aCommandHandler
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
globalObj->GetDocShell(getter_AddRefs(docShell));
|
||||
|
||||
// Get the document tree owner
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellAsTreeItem(do_QueryInterface(docShell));
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellAsTreeItem =
|
||||
do_QueryInterface(globalObj->GetDocShell());
|
||||
nsIDocShellTreeOwner *treeOwner = nsnull;
|
||||
docShellAsTreeItem->GetTreeOwner(&treeOwner);
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ GetEventReceiver ( nsWebBrowser* inBrowser, nsIDOMEventReceiver** outEventRcvr )
|
|||
NS_ENSURE_TRUE(chromeHandler, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIDOMEventReceiver> 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<nsIDocShellTreeOwner> 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<nsIScriptGlobalObject> sgo(do_QueryInterface(frame));
|
||||
if (sgo) {
|
||||
nsCOMPtr<nsIDocShell> docshell;
|
||||
sgo->GetDocShell(getter_AddRefs(docshell));
|
||||
if (docshell) {
|
||||
nsCOMPtr<nsIDocShellTreeItem> item(do_QueryInterface(docshell));
|
||||
if (item && item.get() != aRequestor) {
|
||||
rv = item->FindItemWithName(aName, mWebBrowser->mDocShellAsItem, aFoundItem);
|
||||
if (NS_FAILED(rv) || *aFoundItem)
|
||||
break;
|
||||
}
|
||||
nsCOMPtr<nsIDocShellTreeItem> 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<nsIScriptGlobalObject> sgo(do_QueryInterface(nextSupWindow));
|
||||
if (sgo) {
|
||||
nsCOMPtr<nsIDocShell> docshell;
|
||||
sgo->GetDocShell(getter_AddRefs(docshell));
|
||||
if (docshell) {
|
||||
nsCOMPtr<nsIDocShellTreeItem> item(do_QueryInterface(docshell));
|
||||
if (item) {
|
||||
rv = item->FindItemWithName(aName, item, aFoundItem);
|
||||
if (NS_FAILED(rv) || *aFoundItem)
|
||||
break;
|
||||
}
|
||||
nsCOMPtr<nsIDocShellTreeItem> 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<nsIWebNavigation> webNav(do_QueryInterface(aShellItem));
|
||||
|
|
|
@ -49,8 +49,7 @@ nsWebBrowserContentPolicy::ShouldLoad(PRInt32 contentType,
|
|||
if (!scriptGlobal)
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIDocShell> 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;
|
||||
|
|
|
@ -144,9 +144,8 @@ NS_IMETHODIMP nsWebBrowserFind::FindNext(PRBool *outDidFind)
|
|||
if (!mSearchSubFrames && !mSearchParentFrames)
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIDocShell> 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<nsIDocShell> startingShell;
|
||||
rv = GetDocShellFromWindow(searchFrame, getter_AddRefs(startingShell));
|
||||
nsCOMPtr<nsIDocShellTreeItem> startingItem =
|
||||
do_QueryInterface(GetDocShellFromWindow(searchFrame), &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsCOMPtr<nsIDocShellTreeItem> startingItem = do_QueryInterface(startingShell, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> 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<nsIDocShell> docShell;
|
||||
GetDocShellFromWindow(aWindow, getter_AddRefs(docShell));
|
||||
nsIDocShell *docShell = GetDocShellFromWindow(aWindow);
|
||||
if (!docShell)
|
||||
return;
|
||||
nsCOMPtr<nsIPresShell> presShell;
|
||||
|
@ -683,9 +679,7 @@ nsresult nsWebBrowserFind::SearchInFrame(nsIDOMWindow* aWindow,
|
|||
nsCOMPtr<nsIDOMWindow> 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<nsIDocShell> docShell;
|
||||
rv = GetDocShellFromWindow(aWindow, getter_AddRefs(docShell));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsIDocShell *docShell = GetDocShellFromWindow(aWindow);
|
||||
NS_ENSURE_ARG_POINTER(docShell);
|
||||
|
||||
nsCOMPtr<nsIPresShell> 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<nsIScriptGlobalObject> 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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -141,12 +141,9 @@ nsPrintingPromptService::GetHWNDForDOMWindow(nsIDOMWindow *aWindow)
|
|||
|
||||
// Now we might be the Browser so check this path
|
||||
nsCOMPtr<nsIScriptGlobalObject> scriptGlobal(do_QueryInterface(aWindow));
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
scriptGlobal->GetDocShell(getter_AddRefs(docShell));
|
||||
if (!docShell) return nsnull;
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> treeItem;
|
||||
treeItem = do_QueryInterface(docShell);
|
||||
nsCOMPtr<nsIDocShellTreeItem> treeItem =
|
||||
do_QueryInterface(scriptGlobal->GetDocShell());
|
||||
if (!treeItem) return nsnull;
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
|
||||
|
|
|
@ -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<nsIXPConnectWrappedNative> wrapper(do_QueryInterface(supports));
|
||||
NS_ENSURE_TRUE(wrapper, NS_ERROR_UNEXPECTED);
|
||||
NS_ENSURE_TRUE(wrapper, nsnull);
|
||||
|
||||
nsCOMPtr<nsISupports> native;
|
||||
wrapper->GetNative(getter_AddRefs(native));
|
||||
|
||||
return CallQueryInterface(native, aNativeGlobal);
|
||||
nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(native));
|
||||
|
||||
// This will return a pointer to something we're about to release,
|
||||
// but that's ok here.
|
||||
return sgo;
|
||||
}
|
||||
|
||||
nsresult
|
||||
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<nsIScriptGlobalObject> 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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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__ */
|
||||
|
|
|
@ -686,8 +686,7 @@ nsWindowWatcher::OpenWindowJS(nsIDOMWindow *aParent,
|
|||
// want to continue in the face of errors.
|
||||
nsCOMPtr<nsIScriptGlobalObject> parentSGO(do_QueryInterface(aParent));
|
||||
if (parentSGO) {
|
||||
nsCOMPtr<nsIDocShell> 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<nsIContentViewer> 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<nsIScriptSecurityManager> secMan;
|
||||
JSContext *cx;
|
||||
nsCOMPtr<nsIScriptContext> 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<nsIDocShellLoadInfo> loadInfo;
|
||||
newDocShell->CreateLoadInfo(getter_AddRefs(loadInfo));
|
||||
NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE);
|
||||
|
||||
if (!uriToLoadIsChrome && secMan) {
|
||||
if (!uriToLoadIsChrome) {
|
||||
nsCOMPtr<nsIScriptSecurityManager> secMan =
|
||||
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID);
|
||||
|
||||
nsCOMPtr<nsIPrincipal> 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<nsIScriptGlobalObject> sgo;
|
||||
nsWWJSUtils::nsGetStaticScriptGlobal(ccx, ::JS_GetGlobalObject(ccx),
|
||||
getter_AddRefs(sgo));
|
||||
nsIScriptGlobalObject *sgo =
|
||||
nsWWJSUtils::GetStaticScriptGlobal(ccx, ::JS_GetGlobalObject(ccx));
|
||||
|
||||
nsCOMPtr<nsPIDOMWindow> w(do_QueryInterface(sgo));
|
||||
if (w) {
|
||||
|
@ -1112,12 +1102,9 @@ nsWindowWatcher::URIfromURL(const char *aURL,
|
|||
in nsGlobalWindow.cpp.) */
|
||||
JSContext *cx = GetJSContextFromCallStack();
|
||||
if (cx) {
|
||||
nsCOMPtr<nsIScriptContext> scriptcx;
|
||||
nsWWJSUtils::nsGetDynamicScriptContext(cx, getter_AddRefs(scriptcx));
|
||||
nsIScriptContext *scriptcx = nsWWJSUtils::GetDynamicScriptContext(cx);
|
||||
if (scriptcx) {
|
||||
nsCOMPtr<nsIScriptGlobalObject> gobj;
|
||||
scriptcx->GetGlobalObject(getter_AddRefs(gobj));
|
||||
baseWindow = do_QueryInterface(gobj);
|
||||
baseWindow = do_QueryInterface(scriptcx->GetGlobalObject());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1642,8 +1629,7 @@ nsWindowWatcher::AttachArguments(nsIDOMWindow *aWindow,
|
|||
nsCOMPtr<nsIScriptGlobalObject> scriptGlobal(do_QueryInterface(aWindow));
|
||||
NS_ENSURE_TRUE(scriptGlobal, NS_ERROR_UNEXPECTED);
|
||||
|
||||
nsCOMPtr<nsIScriptContext> 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<nsIScriptGlobalObject> sgo(do_QueryInterface(inWindow));
|
||||
if (sgo) {
|
||||
nsCOMPtr<nsIDocShell> 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<nsIScriptGlobalObject> sgo(do_QueryInterface(aWindow));
|
||||
if (sgo) {
|
||||
nsCOMPtr<nsIScriptContext> scx;
|
||||
sgo->GetContext(getter_AddRefs(scx));
|
||||
nsIScriptContext *scx = sgo->GetContext();
|
||||
if (scx)
|
||||
cx = (JSContext *) scx->GetNativeContext();
|
||||
}
|
||||
|
|
|
@ -71,10 +71,9 @@ GetRootDocShell(nsIDOMWindow *aWindow)
|
|||
|
||||
nsCOMPtr<nsIScriptGlobalObject> globalObj(do_QueryInterface(aWindow));
|
||||
if (globalObj) {
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
globalObj->GetDocShell(getter_AddRefs(docShell));
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem =
|
||||
do_QueryInterface(globalObj->GetDocShell());
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem(do_QueryInterface(docShell));
|
||||
if (docShellTreeItem) {
|
||||
nsCOMPtr<nsIDocShellTreeItem> rootItem;
|
||||
docShellTreeItem->GetRootTreeItem(getter_AddRefs(rootItem));
|
||||
|
|
|
@ -83,11 +83,9 @@ nsIPresShell*
|
|||
inLayoutUtils::GetPresShellFor(nsISupports* aThing)
|
||||
{
|
||||
nsCOMPtr<nsIScriptGlobalObject> so = do_QueryInterface(aThing);
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
so->GetDocShell(getter_AddRefs(docShell));
|
||||
|
||||
|
||||
nsCOMPtr<nsIPresShell> presShell;
|
||||
docShell->GetPresShell(getter_AddRefs(presShell));
|
||||
so->GetDocShell()->GetPresShell(getter_AddRefs(presShell));
|
||||
|
||||
return presShell;
|
||||
}
|
||||
|
|
|
@ -153,7 +153,7 @@ nsLayoutDebuggingTools::Init(nsIDOMWindow *aWin)
|
|||
nsCOMPtr<nsIScriptGlobalObject> global = do_QueryInterface(aWin);
|
||||
if (!global)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
global->GetDocShell(getter_AddRefs(mDocShell));
|
||||
mDocShell = global->GetDocShell();
|
||||
}
|
||||
|
||||
mPrefs = do_GetService(NS_PREF_CONTRACTID);
|
||||
|
|
|
@ -178,6 +178,9 @@ nsRegressionTester::GetDocShellFromWindow(nsIDOMWindow* inWindow, nsIDocShell**
|
|||
{
|
||||
nsCOMPtr<nsIScriptGlobalObject> scriptObj(do_QueryInterface(inWindow));
|
||||
if (!scriptObj) return NS_ERROR_FAILURE;
|
||||
|
||||
return scriptObj->GetDocShell(outShell);
|
||||
|
||||
*outShell = scriptObj->GetDocShell();
|
||||
NS_IF_ADDREF(*outShell);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -210,9 +210,8 @@ void txMozillaXMLOutput::endDocument()
|
|||
nsCOMPtr<nsIDocument> doc = do_QueryInterface(mDocument);
|
||||
nsIScriptGlobalObject *sgo = doc->GetScriptGlobalObject();
|
||||
if (sgo) {
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
sgo->GetDocShell(getter_AddRefs(docShell));
|
||||
nsCOMPtr<nsIRefreshURI> refURI = do_QueryInterface(docShell);
|
||||
nsCOMPtr<nsIRefreshURI> refURI =
|
||||
do_QueryInterface(sgo->GetDocShell());
|
||||
if (refURI) {
|
||||
refURI->SetupRefreshURIFromHeader(doc->GetBaseURI(),
|
||||
mRefreshString);
|
||||
|
|
|
@ -124,8 +124,7 @@ nsWalletlibService::WALLET_RequestToCapture(nsIDOMWindowInternal* aWin,
|
|||
|
||||
nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObject;
|
||||
scriptGlobalObject = do_QueryInterface(aWin);
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
scriptGlobalObject->GetDocShell(getter_AddRefs(docShell));
|
||||
nsIDocShell *docShell = scriptGlobalObject->GetDocShell();
|
||||
|
||||
nsCOMPtr<nsIPresShell> presShell;
|
||||
if(docShell)
|
||||
|
@ -152,8 +151,7 @@ nsWalletlibService::WALLET_Prefill(PRBool quick,
|
|||
{
|
||||
nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObject;
|
||||
scriptGlobalObject = do_QueryInterface(aWin);
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
scriptGlobalObject->GetDocShell(getter_AddRefs(docShell));
|
||||
nsIDocShell *docShell = scriptGlobalObject->GetDocShell();
|
||||
|
||||
nsCOMPtr<nsIPresShell> presShell;
|
||||
if(docShell)
|
||||
|
|
|
@ -93,9 +93,9 @@ static void DOMWindowToTreeOwner(
|
|||
return; // with webWindow unchanged -- its constructor gives it a null ptr
|
||||
}
|
||||
nsCOMPtr<nsIScriptGlobalObject> globalScript(do_QueryInterface(DOMWindow));
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
nsIDocShell *docShell = nsnull;
|
||||
if (globalScript) {
|
||||
globalScript->GetDocShell(getter_AddRefs(docShell));
|
||||
docShell = globalScript->GetDocShell();
|
||||
}
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(docShell));
|
||||
if(!docShellAsItem)
|
||||
|
|
|
@ -469,13 +469,11 @@ nsDOMParser::ParseFromStream(nsIInputStream *stream,
|
|||
rv = cc->GetJSContext(&cx);
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIScriptContext> scriptContext;
|
||||
GetScriptContextFromJSContext(cx, getter_AddRefs(scriptContext));
|
||||
nsIScriptContext *scriptContext = GetScriptContextFromJSContext(cx);
|
||||
if (scriptContext) {
|
||||
nsCOMPtr<nsIScriptGlobalObject> globalObject;
|
||||
scriptContext->GetGlobalObject(getter_AddRefs(globalObject));
|
||||
nsCOMPtr<nsIDOMWindow> window =
|
||||
do_QueryInterface(scriptContext->GetGlobalObject());
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(globalObject);
|
||||
if (window) {
|
||||
nsCOMPtr<nsIDOMDocument> domdoc;
|
||||
window->GetDocument(getter_AddRefs(domdoc));
|
||||
|
|
|
@ -112,30 +112,24 @@ static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
|||
XML_HTTP_REQUEST_SENT | \
|
||||
XML_HTTP_REQUEST_STOPPED)
|
||||
|
||||
static void
|
||||
GetCurrentContext(nsIScriptContext **aScriptContext)
|
||||
static nsIScriptContext *
|
||||
GetCurrentContext()
|
||||
{
|
||||
*aScriptContext = nsnull;
|
||||
|
||||
// Get JSContext from stack.
|
||||
nsCOMPtr<nsIJSContextStack> 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<nsIScriptGlobalObject> global;
|
||||
aScriptContext->GetGlobalObject(getter_AddRefs(global));
|
||||
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(global);
|
||||
nsCOMPtr<nsIDOMWindow> window =
|
||||
do_QueryInterface(aScriptContext->GetGlobalObject());
|
||||
nsIDocument *doc = nsnull;
|
||||
if (window) {
|
||||
nsCOMPtr<nsIDOMDocument> 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<nsIDocument> 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
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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<nsIDOMEventReceiver> rec(do_QueryInterface(aArea));
|
||||
|
|
|
@ -1920,8 +1920,7 @@ nsObjectFrame::NotifyContentObjectWrapper()
|
|||
if (!sgo)
|
||||
return;
|
||||
|
||||
nsCOMPtr<nsIScriptContext> scx;
|
||||
sgo->GetContext(getter_AddRefs(scx));
|
||||
nsIScriptContext *scx = sgo->GetContext();
|
||||
if (!scx)
|
||||
return;
|
||||
|
||||
|
|
|
@ -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<nsIDOMEventReceiver> rec(do_QueryInterface(aArea));
|
||||
|
|
|
@ -1920,8 +1920,7 @@ nsObjectFrame::NotifyContentObjectWrapper()
|
|||
if (!sgo)
|
||||
return;
|
||||
|
||||
nsCOMPtr<nsIScriptContext> scx;
|
||||
sgo->GetContext(getter_AddRefs(scx));
|
||||
nsIScriptContext *scx = sgo->GetContext();
|
||||
if (!scx)
|
||||
return;
|
||||
|
||||
|
|
|
@ -1708,9 +1708,7 @@ nsPrintEngine::IsThereARangeSelection(nsIDOMWindow* aDOMWin)
|
|||
nsCOMPtr<nsIPresShell> presShell;
|
||||
if (aDOMWin) {
|
||||
nsCOMPtr<nsIScriptGlobalObject> scriptObj(do_QueryInterface(aDOMWin));
|
||||
nsCOMPtr<nsIDocShell> 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<nsIScriptGlobalObject> scriptObj(do_QueryInterface(aDOMWindow));
|
||||
if (scriptObj) {
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
scriptObj->GetDocShell(getter_AddRefs(docShell));
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem =
|
||||
do_QueryInterface(scriptObj->GetDocShell());
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(docShell));
|
||||
if (docShellAsItem) {
|
||||
// get this DocViewer webshell
|
||||
nsCOMPtr<nsIWebShell> 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<nsIScriptContext> 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -157,10 +157,8 @@ nsResizerFrame::HandleEvent(nsIPresContext* aPresContext,
|
|||
nsIScriptGlobalObject *scriptGlobalObject = document->GetScriptGlobalObject();
|
||||
NS_ENSURE_TRUE(scriptGlobalObject, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
scriptGlobalObject->GetDocShell(getter_AddRefs(docShell));
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(docShell));
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem =
|
||||
do_QueryInterface(scriptGlobalObject->GetDocShell());
|
||||
NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
|
||||
|
|
|
@ -566,8 +566,9 @@ nsXULTooltipListener::GetTooltipFor(nsIContent* aTarget, nsIContent** aTooltip)
|
|||
}
|
||||
nsIScriptGlobalObject *global = document->GetScriptGlobalObject();
|
||||
if (global) {
|
||||
nsCOMPtr<nsIScriptContext> context;
|
||||
if (NS_SUCCEEDED(global->GetContext(getter_AddRefs(context))) && context) {
|
||||
nsIScriptContext *context = global->GetContext();
|
||||
|
||||
if (context) {
|
||||
nsCOMPtr<nsIDOMWindowInternal> domWindow = do_QueryInterface(global);
|
||||
if (!domWindow)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
|
|
@ -187,19 +187,19 @@ NS_IMETHODIMP nsAddressBook::NewAddressBook(nsIAbDirectoryProperties *aPropertie
|
|||
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIRDFService> rdfService = do_GetService (NS_RDF_CONTRACTID "/rdf-service;1", &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsIRDFService> rdfService = do_GetService (NS_RDF_CONTRACTID "/rdf-service;1", &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIRDFResource> parentResource;
|
||||
rv = rdfService->GetResource(NS_LITERAL_CSTRING(kAllDirectoryRoot),
|
||||
getter_AddRefs(parentResource));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsIRDFResource> parentResource;
|
||||
rv = rdfService->GetResource(NS_LITERAL_CSTRING(kAllDirectoryRoot),
|
||||
getter_AddRefs(parentResource));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIAbDirectory> parentDir = do_QueryInterface(parentResource, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIAbDirectory> 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<nsIRDFService> rdfService = do_GetService (NS_RDF_CONTRACTID "/rdf-service;1", &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIRDFService> rdfService = do_GetService (NS_RDF_CONTRACTID "/rdf-service;1", &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIRDFResource> commandResource;
|
||||
rv = rdfService->GetResource(command, getter_AddRefs(commandResource));
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
rv = db->DoCommand(srcArray, commandResource, argumentArray);
|
||||
}
|
||||
|
||||
return rv;
|
||||
nsCOMPtr<nsIRDFResource> 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<nsIScriptGlobalObject> globalObj( do_QueryInterface(aWin) );
|
||||
if (!globalObj) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
globalObj->GetDocShell(&mDocShell);
|
||||
if (!mDocShell)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
nsCOMPtr<nsIScriptGlobalObject> 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;
|
||||
|
|
|
@ -370,9 +370,8 @@ nsMessenger::SetWindow(nsIDOMWindowInternal *aWin, nsIMsgWindow *aMsgWindow)
|
|||
|
||||
nsCOMPtr<nsIScriptGlobalObject> globalObj( do_QueryInterface(aWin) );
|
||||
NS_ENSURE_TRUE(globalObj, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
globalObj->GetDocShell(getter_AddRefs(docShell));
|
||||
|
||||
nsIDocShell *docShell = globalObj->GetDocShell();
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(docShell));
|
||||
NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);
|
||||
|
||||
|
|
|
@ -94,11 +94,9 @@ HWND hwndForDOMWindow( nsISupports *window )
|
|||
nsCOMPtr<nsIScriptGlobalObject> ppScriptGlobalObj( do_QueryInterface(window) );
|
||||
if ( !ppScriptGlobalObj )
|
||||
return 0;
|
||||
nsCOMPtr<nsIDocShell> ppDocShell;
|
||||
ppScriptGlobalObj->GetDocShell( getter_AddRefs( ppDocShell ) );
|
||||
if ( !ppDocShell ) return 0;
|
||||
|
||||
nsCOMPtr<nsIBaseWindow> ppBaseWindow( do_QueryInterface( ppDocShell ) );
|
||||
nsCOMPtr<nsIBaseWindow> ppBaseWindow =
|
||||
do_QueryInterface( ppScriptGlobalObj->GetDocShell() );
|
||||
if (!ppBaseWindow) return 0;
|
||||
|
||||
nsCOMPtr<nsIWidget> 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);
|
||||
}
|
||||
|
|
|
@ -341,9 +341,8 @@ nsresult nsMsgMailSession::GetTopmostMsgWindow(nsIMsgWindow* *aMsgWindow)
|
|||
nsCOMPtr<nsIScriptGlobalObject> globalObj = do_QueryInterface(topMostWindow, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIDocShell> 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<nsIDocShell> docShell;
|
||||
|
|
|
@ -249,10 +249,8 @@ nsMsgPrintEngine::SetWindow(nsIDOMWindowInternal *aWin)
|
|||
nsCOMPtr<nsIScriptGlobalObject> globalObj( do_QueryInterface(aWin) );
|
||||
NS_ENSURE_TRUE(globalObj, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
globalObj->GetDocShell(getter_AddRefs(docShell));
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(docShell));
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem =
|
||||
do_QueryInterface(globalObj->GetDocShell());
|
||||
NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> rootAsItem;
|
||||
|
@ -291,12 +289,9 @@ nsMsgPrintEngine::ShowWindow(PRBool aShow)
|
|||
nsCOMPtr <nsIScriptGlobalObject> globalScript = do_QueryInterface(mWindow, &rv);
|
||||
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
nsCOMPtr <nsIDocShell> docShell;
|
||||
|
||||
rv = globalScript->GetDocShell(getter_AddRefs(docShell));
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
nsCOMPtr <nsIWebShell> webShell = do_QueryInterface(docShell, &rv);
|
||||
nsCOMPtr <nsIWebShell> webShell =
|
||||
do_QueryInterface(globalScript->GetDocShell(), &rv);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
nsCOMPtr <nsIWebShellContainer> webShellContainer;
|
||||
|
@ -307,7 +302,7 @@ nsMsgPrintEngine::ShowWindow(PRBool aShow)
|
|||
nsCOMPtr <nsIWebShellWindow> webShellWindow = do_QueryInterface(webShellContainer, &rv);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(docShell, &rv));
|
||||
nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(webShell, &rv));
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* 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<nsIDocShell> messageWindowDocShell;
|
||||
GetMessageWindowDocShell(getter_AddRefs(messageWindowDocShell));
|
||||
|
||||
|
@ -353,36 +352,36 @@ NS_IMETHODIMP nsMsgWindow::SetDOMWindow(nsIDOMWindowInternal *aWindow)
|
|||
nsresult rv = NS_OK;
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> globalScript(do_QueryInterface(aWindow));
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
nsIDocShell *docShell = nsnull;
|
||||
if (globalScript)
|
||||
globalScript->GetDocShell(getter_AddRefs(docShell));
|
||||
docShell = globalScript->GetDocShell();
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(docShell));
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(docShell));
|
||||
|
||||
if(docShellAsItem)
|
||||
{
|
||||
nsCOMPtr<nsIDocShellTreeItem> rootAsItem;
|
||||
docShellAsItem->GetSameTypeRootTreeItem(getter_AddRefs(rootAsItem));
|
||||
if(docShellAsItem)
|
||||
{
|
||||
nsCOMPtr<nsIDocShellTreeItem> rootAsItem;
|
||||
docShellAsItem->GetSameTypeRootTreeItem(getter_AddRefs(rootAsItem));
|
||||
|
||||
nsCOMPtr<nsIDocShell> rootAsShell(do_QueryInterface(rootAsItem));
|
||||
SetRootDocShell(rootAsShell);
|
||||
nsCOMPtr<nsIDocShell> rootAsShell(do_QueryInterface(rootAsItem));
|
||||
SetRootDocShell(rootAsShell);
|
||||
|
||||
// force ourselves to figure out the message pane
|
||||
nsCOMPtr<nsIDocShell> messageWindowDocShell;
|
||||
GetMessageWindowDocShell(getter_AddRefs(messageWindowDocShell));
|
||||
SetStatusFeedback(mStatusFeedback);
|
||||
}
|
||||
// force ourselves to figure out the message pane
|
||||
nsCOMPtr<nsIDocShell> messageWindowDocShell;
|
||||
GetMessageWindowDocShell(getter_AddRefs(messageWindowDocShell));
|
||||
SetStatusFeedback(mStatusFeedback);
|
||||
}
|
||||
|
||||
//Get nsIMsgWindowCommands object
|
||||
nsCOMPtr<nsISupports> xpConnectObj;
|
||||
nsCOMPtr<nsPIDOMWindow> piDOMWindow(do_QueryInterface(aWindow));
|
||||
if (piDOMWindow)
|
||||
{
|
||||
piDOMWindow->GetObjectProperty(NS_LITERAL_STRING("MsgWindowCommands").get(), getter_AddRefs(xpConnectObj));
|
||||
mMsgWindowCommands = do_QueryInterface(xpConnectObj);
|
||||
}
|
||||
nsCOMPtr<nsISupports> xpConnectObj;
|
||||
nsCOMPtr<nsPIDOMWindow> 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<nsIDocShell> rootShell(do_QueryReferent(mRootDocShellWeak));
|
||||
if (rootShell)
|
||||
{
|
||||
nsCOMPtr<nsIPrompt> dialog;
|
||||
dialog = do_GetInterface(rootShell, &rv);
|
||||
if (dialog)
|
||||
{
|
||||
*aPrompt = dialog;
|
||||
NS_ADDREF(*aPrompt);
|
||||
}
|
||||
return rv;
|
||||
nsCOMPtr<nsIPrompt> 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("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></head><body>").get());
|
||||
htmlStr.Append(body);
|
||||
htmlStr.Append(NS_LITERAL_STRING("</body></html>").get());
|
||||
nsString htmlStr;
|
||||
htmlStr.Append(NS_LITERAL_STRING("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></head><body>").get());
|
||||
htmlStr.Append(body);
|
||||
htmlStr.Append(NS_LITERAL_STRING("</body></html>").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 <nsIURI> uri = do_CreateInstance("@mozilla.org/network/simple-uri;1");
|
||||
if (!uri) return NS_ERROR_UNEXPECTED;
|
||||
nsCOMPtr <nsIURI> 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 <nsIDocShell> docShell;
|
||||
GetMessageWindowDocShell(getter_AddRefs(docShell));
|
||||
if (!docShell) return NS_ERROR_UNEXPECTED;
|
||||
nsCOMPtr <nsIDocShell> 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)
|
||||
|
|
|
@ -522,11 +522,9 @@ nsMsgCompose::ConvertAndLoadComposeWindow(nsString& aPrefix,
|
|||
if (!aBuf.IsEmpty() && mailEditor)
|
||||
{
|
||||
// XXX see bug #206793
|
||||
nsCOMPtr<nsIDocShell> docshell;
|
||||
nsIDocShell *docshell = nsnull;
|
||||
nsCOMPtr<nsIScriptGlobalObject> 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<nsIDocShell> docshell;
|
||||
nsCOMPtr<nsIScriptGlobalObject> globalObj(do_QueryInterface(aWindow));
|
||||
if (!globalObj)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
globalObj->GetDocShell(getter_AddRefs(docshell));
|
||||
nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(docshell));
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> treeItem =
|
||||
do_QueryInterface(globalObj->GetDocShell());
|
||||
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
|
||||
rv = treeItem->GetTreeOwner(getter_AddRefs(treeOwner));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
@ -1268,8 +1265,7 @@ NS_IMETHODIMP nsMsgCompose::CloseWindow(PRBool recycleIt)
|
|||
nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(m_window));
|
||||
if (sgo)
|
||||
{
|
||||
nsCOMPtr<nsIScriptContext> 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<nsIScriptGlobalObject> globalObj = do_QueryInterface(m_window);
|
||||
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
globalObj->GetDocShell(getter_AddRefs(docShell));
|
||||
nsIDocShell *docShell = globalObj->GetDocShell();
|
||||
NS_ENSURE_TRUE(docShell, NS_ERROR_UNEXPECTED);
|
||||
|
||||
nsCOMPtr<nsIContentViewer> childCV;
|
||||
|
@ -2376,10 +2371,10 @@ QuotingOutputStreamListener::InsertToCompose(nsIEditor *aEditor,
|
|||
nsCOMPtr<nsIDOMWindowInternal> domWindow;
|
||||
if (compose)
|
||||
compose->GetDomWindow(getter_AddRefs(domWindow));
|
||||
nsCOMPtr<nsIDocShell> docshell;
|
||||
nsIDocShell *docshell = nsnull;
|
||||
nsCOMPtr<nsIScriptGlobalObject> globalObj = do_QueryInterface(domWindow);
|
||||
if (globalObj)
|
||||
globalObj->GetDocShell(getter_AddRefs(docshell));
|
||||
docshell = globalObj->GetDocShell();
|
||||
if (docshell)
|
||||
docshell->SetAppType(nsIDocShell::APP_TYPE_MAIL);
|
||||
|
||||
|
|
|
@ -304,21 +304,19 @@ void nsMsgComposeService::CloseWindow(nsIDOMWindowInternal *domWindow)
|
|||
nsCOMPtr<nsIScriptGlobalObject> globalObj(do_QueryInterface(domWindow));
|
||||
if (globalObj)
|
||||
{
|
||||
globalObj->GetDocShell(getter_AddRefs(docshell));
|
||||
if (docshell)
|
||||
nsCOMPtr<nsIDocShellTreeItem> treeItem =
|
||||
do_QueryInterface(globalObj->GetDocShell());
|
||||
|
||||
if (treeItem)
|
||||
{
|
||||
nsCOMPtr<nsIDocShellTreeItem> treeItem(do_QueryInterface(docshell));
|
||||
if (treeItem)
|
||||
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
|
||||
treeItem->GetTreeOwner(getter_AddRefs(treeOwner));
|
||||
if (treeOwner)
|
||||
{
|
||||
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
|
||||
treeItem->GetTreeOwner(getter_AddRefs(treeOwner));
|
||||
if (treeOwner)
|
||||
{
|
||||
nsCOMPtr<nsIBaseWindow> baseWindow;
|
||||
baseWindow = do_QueryInterface(treeOwner);
|
||||
if (baseWindow)
|
||||
baseWindow->Destroy();
|
||||
}
|
||||
nsCOMPtr<nsIBaseWindow> baseWindow;
|
||||
baseWindow = do_QueryInterface(treeOwner);
|
||||
if (baseWindow)
|
||||
baseWindow->Destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -690,11 +688,9 @@ HWND hwndForComposeDOMWindow( nsISupports *window )
|
|||
nsCOMPtr<nsIScriptGlobalObject> ppScriptGlobalObj( do_QueryInterface(window) );
|
||||
if ( !ppScriptGlobalObj )
|
||||
return 0;
|
||||
nsCOMPtr<nsIDocShell> ppDocShell;
|
||||
ppScriptGlobalObj->GetDocShell( getter_AddRefs( ppDocShell ) );
|
||||
if ( !ppDocShell ) return 0;
|
||||
|
||||
nsCOMPtr<nsIBaseWindow> ppBaseWindow( do_QueryInterface( ppDocShell ) );
|
||||
|
||||
nsCOMPtr<nsIBaseWindow> ppBaseWindow =
|
||||
do_QueryInterface( ppScriptGlobalObj->GetDocShell() );
|
||||
if (!ppBaseWindow) return 0;
|
||||
|
||||
nsCOMPtr<nsIWidget> ppWidget;
|
||||
|
@ -889,10 +885,8 @@ nsresult nsMsgComposeService::ShowCachedComposeWindow(nsIDOMWindowInternal *aCom
|
|||
nsCOMPtr <nsIScriptGlobalObject> globalScript = do_QueryInterface(aComposeWindow, &rv);
|
||||
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
nsCOMPtr <nsIDocShell> docShell;
|
||||
|
||||
rv = globalScript->GetDocShell(getter_AddRefs(docShell));
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
nsIDocShell *docShell = globalScript->GetDocShell();
|
||||
|
||||
nsCOMPtr <nsIWebShell> webShell = do_QueryInterface(docShell, &rv);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
|
|
@ -58,13 +58,12 @@
|
|||
*/
|
||||
static nsresult getScriptCodebase(JSContext* cx, nsIURI* *result)
|
||||
{
|
||||
nsCOMPtr<nsIScriptContext> scriptContext;
|
||||
GetScriptContextFromJSContext(cx, getter_AddRefs(scriptContext));
|
||||
nsIScriptContext *scriptContext = GetScriptContextFromJSContext(cx);
|
||||
|
||||
if (scriptContext) {
|
||||
nsCOMPtr<nsIScriptGlobalObject> scriptGlobal;
|
||||
scriptContext->GetGlobalObject(getter_AddRefs(scriptGlobal));
|
||||
nsCOMPtr<nsIScriptObjectPrincipal> scriptObjectPrincipal = do_QueryInterface(scriptGlobal);
|
||||
nsCOMPtr<nsIScriptObjectPrincipal> scriptObjectPrincipal =
|
||||
do_QueryInterface(scriptContext->GetGlobalObject());
|
||||
|
||||
if (scriptObjectPrincipal) {
|
||||
nsCOMPtr<nsIPrincipal> principal;
|
||||
scriptObjectPrincipal->GetPrincipal(getter_AddRefs(principal));
|
||||
|
|
|
@ -337,21 +337,19 @@ enter_js_from_java_impl(JNIEnv *jEnv, char **errp,
|
|||
nsCOMPtr<nsISecurityContext> javaSecurityContext = do_QueryInterface(credentials);
|
||||
if (javaSecurityContext) {
|
||||
if (pJSCX) {
|
||||
nsCOMPtr<nsIScriptContext> scriptContext;
|
||||
GetScriptContextFromJSContext(pJSCX,
|
||||
getter_AddRefs(scriptContext));
|
||||
nsIScriptContext *scriptContext =
|
||||
GetScriptContextFromJSContext(pJSCX);
|
||||
|
||||
if (scriptContext) {
|
||||
nsCOMPtr<nsIScriptGlobalObject> global;
|
||||
scriptContext->GetGlobalObject(getter_AddRefs(global));
|
||||
nsIScriptGlobalObject *global =
|
||||
scriptContext->GetGlobalObject();
|
||||
NS_ASSERTION(global, "script context has no global object");
|
||||
|
||||
if (global) {
|
||||
nsCOMPtr<nsIScriptObjectPrincipal> globalData = do_QueryInterface(global);
|
||||
if (globalData) {
|
||||
if (NS_FAILED(globalData->GetPrincipal(getter_AddRefs(principal))))
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
nsCOMPtr<nsIScriptObjectPrincipal> 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<nsIScriptContext> scriptContext;
|
||||
GetScriptContextFromJSContext(cx, getter_AddRefs(scriptContext));
|
||||
nsIScriptContext *scriptContext = GetScriptContextFromJSContext(cx);
|
||||
|
||||
if (scriptContext)
|
||||
{
|
||||
|
|
|
@ -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<nsIWindowWatcher> windowWatcher;
|
||||
nsCOMPtr<nsIDOMWindow> domWindow;
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
nsCOMPtr<nsIScriptGlobalObject> scriptObject;
|
||||
nsCOMPtr<nsIPresContext> presContext;
|
||||
nsCOMPtr<nsIDocShellTreeItem> treeItem;
|
||||
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
|
||||
nsCOMPtr<nsISupports> cont;
|
||||
nsCOMPtr<nsIWebBrowserChrome> chrome;
|
||||
|
||||
windowWatcher =
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIWindowWatcher> 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<nsIDOMWindow> domWindow;
|
||||
windowWatcher->GetActiveWindow(getter_AddRefs(domWindow));
|
||||
nsCOMPtr<nsIScriptGlobalObject> 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<nsIPresContext> 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<nsISupports> container(presContext->GetContainer());
|
||||
nsCOMPtr<nsIDocShellTreeItem> 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<nsIDocShellTreeOwner> treeOwner;
|
||||
treeItem->GetTreeOwner(getter_AddRefs(treeOwner));
|
||||
|
||||
nsCOMPtr<nsIWebBrowserChrome> chrome = do_GetInterface(treeOwner, &rv);
|
||||
*theChrome = (nsIWebBrowserChrome *) chrome.get();
|
||||
NS_IF_ADDREF(*theChrome);
|
||||
return rv;
|
||||
|
|
|
@ -5642,10 +5642,7 @@ NS_IMETHODIMP nsPluginHostImpl::NewPluginURLStream(const nsString& aURL,
|
|||
|
||||
if (global)
|
||||
{
|
||||
nsCOMPtr<nsIScriptGlobalObjectOwner> owner;
|
||||
global->GetGlobalObjectOwner(getter_AddRefs(owner));
|
||||
|
||||
callbacks = do_QueryInterface(owner);
|
||||
callbacks = do_QueryInterface(global->GetGlobalObjectOwner());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
Ссылка в новой задаче