Landing fix for bug 239202, patch by trev@gtchat.de. Making nsIScriptGlobalObjectOwner not scriptable. r+sr=jst@mozilla.org

This commit is contained in:
jst%mozilla.jstenback.com 2004-07-16 17:03:10 +00:00
parent 910e44a7d5
commit 23b9aa362d
24 changed files with 72 additions and 172 deletions

View File

@ -57,7 +57,6 @@
#include "nsICSSStyleSheet.h"
#include "nsIFrame.h"
#include "nsIScriptGlobalObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsILinkHandler.h"
#include "nsIDOMDocument.h"

View File

@ -117,8 +117,6 @@ static const char kPrintingPromptService[] = "@mozilla.org/embedcomp/printingpro
#include "nsISupportsUtils.h"
#include "nsIFrame.h"
#include "nsIScriptContext.h"
#include "nsIScriptGlobalObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsILinkHandler.h"
#include "nsIDOMDocument.h"
#include "nsISelectionListener.h"

View File

@ -2027,7 +2027,7 @@ IsScriptEnabled(nsIDocument *aDoc, nsIDocShell *aContainer)
nsCOMPtr<nsIScriptGlobalObjectOwner> owner = do_GetInterface(aContainer);
NS_ENSURE_TRUE(owner, PR_TRUE);
owner->GetScriptGlobalObject(getter_AddRefs(globalObject));
globalObject = owner->GetScriptGlobalObject();
NS_ENSURE_TRUE(globalObject, PR_TRUE);
}

View File

@ -82,7 +82,6 @@
#include "nsIDOMScriptObjectFactory.h"
#include "nsIPrincipal.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptGlobalObjectOwner.h"
#include "nsIScriptObjectPrincipal.h"
#include "nsIConsoleService.h"
#include "nsIScriptError.h"

View File

@ -70,7 +70,6 @@
#include "nsXBLService.h"
#include "nsXBLInsertionPoint.h"
#include "nsIXPConnect.h"
#include "nsIScriptGlobalObjectOwner.h"
#include "nsIScriptContext.h"
#include "nsCRT.h"

View File

@ -40,6 +40,7 @@
#include "nsIDocument.h"
#include "nsXBLPrototypeBinding.h"
#include "nsIScriptObjectPrincipal.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptContext.h"
#include "nsIDOMScriptObjectFactory.h"
#include "jsapi.h"
@ -424,38 +425,20 @@ nsXBLDocumentInfo::FlushSkinStylesheets()
// nsIScriptGlobalObjectOwner methods
//
NS_IMETHODIMP
nsXBLDocumentInfo::GetScriptGlobalObject(nsIScriptGlobalObject** _result)
nsIScriptGlobalObject*
nsXBLDocumentInfo::GetScriptGlobalObject()
{
if (!mGlobalObject) {
mGlobalObject = new nsXBLDocGlobalObject();
if (!mGlobalObject) {
*_result = nsnull;
return NS_ERROR_OUT_OF_MEMORY;
}
if (!mGlobalObject)
return nsnull;
mGlobalObject->SetGlobalObjectOwner(this); // does not refcount
}
*_result = mGlobalObject;
NS_ADDREF(*_result);
return NS_OK;
}
NS_IMETHODIMP
nsXBLDocumentInfo::ReportScriptError(nsIScriptError *errorObject)
{
if (errorObject == nsnull)
return NS_ERROR_NULL_POINTER;
// Get the console service, where we're going to register the error.
nsCOMPtr<nsIConsoleService> consoleService (do_GetService("@mozilla.org/consoleservice;1"));
if (!consoleService)
return NS_ERROR_NOT_AVAILABLE;
return consoleService->LogMessage(errorObject);
return mGlobalObject;
}
nsresult NS_NewXBLDocumentInfo(nsIDocument* aDocument, nsIXBLDocumentInfo** aResult)
@ -470,4 +453,3 @@ nsresult NS_NewXBLDocumentInfo(nsIDocument* aDocument, nsIXBLDocumentInfo** aRes
NS_ADDREF(*aResult);
return NS_OK;
}

View File

@ -64,7 +64,7 @@ public:
NS_IMETHOD FlushSkinStylesheets();
// nsIScriptGlobalObjectOwner methods
NS_DECL_NSISCRIPTGLOBALOBJECTOWNER
virtual nsIScriptGlobalObject* GetScriptGlobalObject();
private:
nsCOMPtr<nsIDocument> mDocument;

View File

@ -145,8 +145,8 @@ nsXBLProtoImpl::CompilePrototypeMembers(nsXBLPrototypeBinding* aBinding)
// context.
nsCOMPtr<nsIScriptGlobalObjectOwner> globalOwner(
do_QueryInterface(aBinding->XBLDocumentInfo()));
nsCOMPtr<nsIScriptGlobalObject> globalObject;
globalOwner->GetScriptGlobalObject(getter_AddRefs(globalObject));
nsIScriptGlobalObject* globalObject = globalOwner->GetScriptGlobalObject();
NS_ENSURE_TRUE(globalObject, NS_ERROR_UNEXPECTED);
nsIScriptContext *context = globalObject->GetContext();

View File

@ -630,11 +630,11 @@ nsXMLDocument::EndLoad()
nsEventStatus status = nsEventStatus_eIgnore;
nsEvent event(NS_PAGE_LOAD);
nsCOMPtr<nsIScriptGlobalObject> sgo;
nsIScriptGlobalObject* sgo = nsnull;
nsCOMPtr<nsIScriptGlobalObjectOwner> container =
do_QueryReferent(mDocumentContainer);
if (container) {
container->GetScriptGlobalObject(getter_AddRefs(sgo));
sgo = container->GetScriptGlobalObject();
}
nsCxPusher pusher(sgo);

View File

@ -1482,8 +1482,7 @@ nsXULElement::CompileEventHandler(nsIScriptContext* aContext,
nsCOMPtr<nsIScriptGlobalObjectOwner> globalOwner =
do_QueryInterface(protodoc);
nsCOMPtr<nsIScriptGlobalObject> global;
globalOwner->GetScriptGlobalObject(getter_AddRefs(global));
nsIScriptGlobalObject* global = globalOwner->GetScriptGlobalObject();
NS_ENSURE_TRUE(global, NS_ERROR_UNEXPECTED);
context = global->GetContext();
@ -4656,10 +4655,9 @@ nsXULPrototypeScript::Compile(const PRUnichar* aText,
nsIScriptContext *context = nsnull;
{
nsCOMPtr<nsIScriptGlobalObjectOwner> globalOwner
= do_QueryInterface(aPrototypeDocument);
nsCOMPtr<nsIScriptGlobalObject> global;
globalOwner->GetScriptGlobalObject(getter_AddRefs(global));
nsCOMPtr<nsIScriptGlobalObjectOwner> globalOwner =
do_QueryInterface(aPrototypeDocument);
nsIScriptGlobalObject* global = globalOwner->GetScriptGlobalObject();
NS_ASSERTION(global != nsnull, "prototype doc has no script global");
if (! global)
return NS_ERROR_UNEXPECTED;

View File

@ -71,7 +71,6 @@
#include "nsIPresShell.h"
#include "nsIScriptContext.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptGlobalObjectOwner.h"
#include "nsIServiceManager.h"
#include "nsITextContent.h"
#include "nsIURL.h"

View File

@ -3234,10 +3234,10 @@ nsXULDocument::OnStreamComplete(nsIStreamLoader* aLoader,
// Ignore the return value, as we don't need to propagate
// a failure to write to the FastLoad file, because this
// method aborts that whole process on error.
nsCOMPtr<nsIScriptGlobalObjectOwner> globalOwner
= do_QueryInterface(mCurrentPrototype);
nsCOMPtr<nsIScriptGlobalObject> global;
globalOwner->GetScriptGlobalObject(getter_AddRefs(global));
nsCOMPtr<nsIScriptGlobalObjectOwner> globalOwner =
do_QueryInterface(mCurrentPrototype);
nsIScriptGlobalObject* global =
globalOwner->GetScriptGlobalObject();
NS_ASSERTION(global != nsnull, "master prototype w/o global?!");
if (global) {

View File

@ -157,7 +157,7 @@ public:
virtual nsNodeInfoManager *GetNodeInfoManager();
// nsIScriptGlobalObjectOwner methods
NS_DECL_NSISCRIPTGLOBALOBJECTOWNER
virtual nsIScriptGlobalObject* GetScriptGlobalObject();
NS_DEFINE_STATIC_CID_ACCESSOR(NS_XULPROTOTYPEDOCUMENT_CID);
@ -540,8 +540,8 @@ nsXULPrototypeDocument::Write(nsIObjectOutputStream* aStream)
}
// Now serialize the document contents
nsCOMPtr<nsIScriptGlobalObject> globalObject;
rv |= GetScriptGlobalObject(getter_AddRefs(globalObject));
nsIScriptGlobalObject* globalObject = GetScriptGlobalObject();
NS_ENSURE_TRUE(globalObject, NS_ERROR_UNEXPECTED);
nsIScriptContext *scriptContext = globalObject->GetContext();
@ -764,39 +764,13 @@ nsXULPrototypeDocument::NotifyLoadDone()
// nsIScriptGlobalObjectOwner methods
//
NS_IMETHODIMP
nsXULPrototypeDocument::GetScriptGlobalObject(nsIScriptGlobalObject** _result)
nsIScriptGlobalObject*
nsXULPrototypeDocument::GetScriptGlobalObject()
{
nsresult rv = NS_OK;
if (!mGlobalObject)
rv = NewXULPDGlobalObject(getter_AddRefs(mGlobalObject));
*_result = mGlobalObject;
NS_IF_ADDREF(*_result);
return rv;
}
NewXULPDGlobalObject(getter_AddRefs(mGlobalObject));
NS_IMETHODIMP
nsXULPrototypeDocument::ReportScriptError(nsIScriptError *errorObject)
{
nsresult rv;
if (errorObject == nsnull)
return NS_ERROR_NULL_POINTER;
// Get the console service, where we're going to register the error.
nsCOMPtr<nsIConsoleService> consoleService
(do_GetService("@mozilla.org/consoleservice;1"));
if (consoleService != nsnull) {
rv = consoleService->LogMessage(errorObject);
if (NS_SUCCEEDED(rv)) {
return NS_OK;
} else {
return rv;
}
} else {
return NS_ERROR_NOT_AVAILABLE;
}
return mGlobalObject;
}
//----------------------------------------------------------------------

View File

@ -43,7 +43,6 @@
#include "nsIBaseWindow.idl"
#include "nsIScrollable.idl"
#include "nsITextScroll.idl"
#include "nsIScriptGlobalObjectOwner.idl"
/*
nsCHTMLDocShell implements:
@ -54,11 +53,10 @@ nsIDocShellTreeNode
nsIBaseWindow
nsIScrollable
nsITextScroll
nsIScriptGlobalObjectOwner
*/
%{ C++
// {F1EAC762-87E9-11d3-AF80-00A024FFC08C} -
// {F1EAC762-87E9-11d3-AF80-00A024FFC08C} -
#define NS_DOCSHELL_CID \
{ 0xf1eac762, 0x87e9, 0x11d3, { 0xaf, 0x80, 0x00, 0xa0, 0x24, 0xff, 0xc0, 0x8c } }
#define NS_DOCSHELL_CONTRACTID \

View File

@ -3835,45 +3835,16 @@ nsDocShell::ScrollByPages(PRInt32 numPages)
// nsDocShell::nsIScriptGlobalObjectOwner
//*****************************************************************************
NS_IMETHODIMP
nsDocShell::GetScriptGlobalObject(nsIScriptGlobalObject ** aGlobal)
nsIScriptGlobalObject*
nsDocShell::GetScriptGlobalObject()
{
if (mIsBeingDestroyed) {
return NS_ERROR_NOT_AVAILABLE;
return nsnull;
}
NS_ENSURE_ARG_POINTER(aGlobal);
NS_ENSURE_SUCCESS(EnsureScriptEnvironment(), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(EnsureScriptEnvironment(), nsnull);
*aGlobal = mScriptGlobal;
NS_IF_ADDREF(*aGlobal);
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::ReportScriptError(nsIScriptError * errorObject)
{
nsresult rv;
if (errorObject == nsnull)
return NS_ERROR_NULL_POINTER;
// Get the console service, where we're going to register the error.
nsCOMPtr<nsIConsoleService> consoleService
(do_GetService("@mozilla.org/consoleservice;1"));
if (consoleService != nsnull) {
rv = consoleService->LogMessage(errorObject);
if (NS_SUCCEEDED(rv)) {
return NS_OK;
}
else {
return rv;
}
}
else {
return NS_ERROR_NOT_AVAILABLE;
}
return mScriptGlobal;
}
//*****************************************************************************
@ -6957,9 +6928,9 @@ NS_IMETHODIMP nsDocShell::EnsureFind()
// we promise that the nsIWebBrowserFind that we return has been set
// up to point to the focussed, or content window, so we have to
// set that up each time.
nsCOMPtr<nsIScriptGlobalObject> scriptGO;
rv = GetScriptGlobalObject(getter_AddRefs(scriptGO));
if (NS_FAILED(rv)) return rv;
nsIScriptGlobalObject* scriptGO = GetScriptGlobalObject();
NS_ENSURE_TRUE(scriptGO, NS_ERROR_UNEXPECTED);
// default to our window
nsCOMPtr<nsIDOMWindow> rootWindow = do_QueryInterface(scriptGO);

View File

@ -214,7 +214,6 @@ public:
NS_DECL_NSITEXTSCROLL
NS_DECL_NSIDOCCHARSET
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSISCRIPTGLOBALOBJECTOWNER
NS_DECL_NSIWEBPROGRESSLISTENER
NS_DECL_NSIREFRESHURI
NS_DECL_NSICONTENTVIEWERCONTAINER
@ -226,6 +225,8 @@ public:
nsDocShellInfoLoadType ConvertLoadTypeToDocShellLoadInfo(PRUint32 aLoadType);
PRUint32 ConvertDocShellLoadInfoToLoadType(nsDocShellInfoLoadType aDocShellLoadType);
// nsIScriptGlobalObjectOwner methods
virtual nsIScriptGlobalObject* GetScriptGlobalObject();
protected:
// Object Management
virtual ~nsDocShell();

View File

@ -48,7 +48,6 @@ GRE_MODULE = 1
DIRS = idl coreEvents base
XPIDLSRCS = nsIScriptContextOwner.idl \
nsIScriptGlobalObjectOwner.idl \
nsIEntropyCollector.idl \
$(NULL)
@ -57,6 +56,7 @@ EXPORTS=nsIScriptContext.h \
nsIScriptObjectOwner.h \
nsIScriptObjectPrincipal.h \
nsIScriptGlobalObject.h \
nsIScriptGlobalObjectOwner.h \
nsIDOMScriptObjectFactory.h \
nsDOMCID.h \
nsIScriptExternalNameSet.h \

View File

@ -1,6 +1,5 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* ***** BEGIN LICENSE BLOCK *****
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
@ -13,11 +12,11 @@
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Mozilla browser.
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications, Inc.
* Portions created by the Initial Developer are Copyright (C) 1999
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998-1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
@ -37,34 +36,31 @@
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
#ifndef nsIScriptGlobalObjectOwner_h__
#define nsIScriptGlobalObjectOwner_h__
%{ C++
#include "nscore.h"
#include "nsIScriptGlobalObject.h"
%}
#include "nsISupports.h"
class nsIScriptGlobalObject;
#define NS_ISCRIPTGLOBALOBJECTOWNER_IID \
{0xfd25ca8e, 0x6b63, 0x435f, \
{ 0xb8, 0xc6, 0xb8, 0x07, 0x68, 0xa4, 0x0a, 0xdc }}
/**
* Implemented by any object capable of supplying a nsIScriptGlobalObject.
* The implentor may create the script global object on demand and is
* allowed (though not expected) to throw it away on release.
* The implentor may create the script global object on demand.
*/
interface nsIScriptGlobalObject;
interface nsIScriptError;
[scriptable, uuid(413E8400-A87F-11d3-AFC6-00A024FFC08C)]
interface nsIScriptGlobalObjectOwner : nsISupports
class nsIScriptGlobalObjectOwner : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISCRIPTGLOBALOBJECTOWNER_IID)
/**
* Returns the script global object
*/
nsIScriptGlobalObject getScriptGlobalObject();
/**
* Error notification method. Informs the owner that an error
* occurred while a script was being evaluted.
*
*/
void reportScriptError(in nsIScriptError aError);
virtual nsIScriptGlobalObject* GetScriptGlobalObject() = 0;
};
#endif /* nsIScriptGlobalObjectOwner_h__ */

View File

@ -38,7 +38,6 @@
#include "nsJSEnvironment.h"
#include "nsIScriptContextOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptGlobalObjectOwner.h"
#include "nsIScriptObjectPrincipal.h"
#include "nsIDOMWindowInternal.h"
#include "nsIDOMNode.h"
@ -238,18 +237,10 @@ NS_ScriptErrorReporter(JSContext *cx,
}
if (NS_SUCCEEDED(rv)) {
nsIScriptGlobalObjectOwner *owner =
globalObject->GetGlobalObjectOwner();
if (owner) {
owner->ReportScriptError(errorObject);
} else {
// We lack an owner to report this error to, so let's just
// report it to the console service so as to not lose it.
nsCOMPtr<nsIConsoleService> consoleService =
do_GetService(NS_CONSOLESERVICE_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
consoleService->LogMessage(errorObject);
}
nsCOMPtr<nsIConsoleService> consoleService =
do_GetService(NS_CONSOLESERVICE_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
consoleService->LogMessage(errorObject);
}
}
}

View File

@ -167,13 +167,12 @@ nsresult nsJSThunk::EvaluateScript(nsIChannel *aChannel)
}
// So far so good: get the script context from its owner.
nsCOMPtr<nsIScriptGlobalObject> global;
rv = globalOwner->GetScriptGlobalObject(getter_AddRefs(global));
nsIScriptGlobalObject* global = globalOwner->GetScriptGlobalObject();
NS_ASSERTION(NS_SUCCEEDED(rv) && global,
NS_ASSERTION(global,
"Unable to get an nsIScriptGlobalObject from the "
"ScriptGlobalObjectOwner!");
if (NS_FAILED(rv) || !global) {
if (!global) {
return NS_ERROR_FAILURE;
}

View File

@ -57,7 +57,6 @@
#include "nsICSSStyleSheet.h"
#include "nsIFrame.h"
#include "nsIScriptGlobalObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsILinkHandler.h"
#include "nsIDOMDocument.h"

View File

@ -117,8 +117,6 @@ static const char kPrintingPromptService[] = "@mozilla.org/embedcomp/printingpro
#include "nsISupportsUtils.h"
#include "nsIFrame.h"
#include "nsIScriptContext.h"
#include "nsIScriptGlobalObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsILinkHandler.h"
#include "nsIDOMDocument.h"
#include "nsISelectionListener.h"

View File

@ -1075,8 +1075,7 @@ nsWebShellWindow::ConvertWebShellToDOMWindow(nsIWebShell* aShell, nsIDOMWindowIn
nsCOMPtr<nsIScriptGlobalObjectOwner> globalObjectOwner(do_QueryInterface(aShell));
NS_ENSURE_TRUE(globalObjectOwner, NS_ERROR_FAILURE);
nsCOMPtr<nsIScriptGlobalObject> globalObject;
globalObjectOwner->GetScriptGlobalObject(getter_AddRefs(globalObject));
nsIScriptGlobalObject* globalObject = globalObjectOwner->GetScriptGlobalObject();
NS_ENSURE_TRUE(globalObject, NS_ERROR_FAILURE);
nsCOMPtr<nsIDOMWindowInternal> newDOMWindow(do_QueryInterface(globalObject));

View File

@ -196,12 +196,12 @@ nsInstallTrigger::HandleContent(const char * aContentType,
// Get the global object of the target window for StartSoftwareUpdate
nsCOMPtr<nsIScriptGlobalObject> globalObject;
nsIScriptGlobalObject* globalObject = nsnull;
nsCOMPtr<nsIScriptGlobalObjectOwner> globalObjectOwner =
do_QueryInterface(aWindowContext);
if ( globalObjectOwner )
{
globalObjectOwner->GetScriptGlobalObject(getter_AddRefs(globalObject));
globalObject = globalObjectOwner->GetScriptGlobalObject();
}
if ( !globalObject )
return NS_ERROR_INVALID_ARG;