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
Родитель 1ebd6baf37
Коммит 693923a31f
25 изменённых файлов: 116 добавлений и 146 удалений

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

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

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

@ -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"

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

@ -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);
}

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

@ -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"

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

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

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

@ -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;
}

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

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

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

@ -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();

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

@ -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);

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

@ -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;

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

@ -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"

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

@ -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) {

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

@ -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;
}
//----------------------------------------------------------------------

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

@ -43,7 +43,6 @@
#include "nsIBaseWindow.idl"
#include "nsIScrollable.idl"
#include "nsITextScroll.idl"
#include "nsIScriptGlobalObjectOwner.idl"
/*
nsCHTMLDocShell implements:
@ -54,7 +53,6 @@ nsIDocShellTreeNode
nsIBaseWindow
nsIScrollable
nsITextScroll
nsIScriptGlobalObjectOwner
*/
%{ C++

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

@ -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);

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

@ -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();

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

@ -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 \

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

@ -0,0 +1,66 @@
/* -*- 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
* 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/MPL/
*
* 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 the Initial Developer are Copyright (C) 1998-1999
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Travis Bogard <travis@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsIScriptGlobalObjectOwner_h__
#define nsIScriptGlobalObjectOwner_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.
*/
class nsIScriptGlobalObjectOwner : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISCRIPTGLOBALOBJECTOWNER_IID)
/**
* Returns the script global object
*/
virtual nsIScriptGlobalObject* GetScriptGlobalObject() = 0;
};
#endif /* nsIScriptGlobalObjectOwner_h__ */

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

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

@ -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,13 +237,6 @@ 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)) {
@ -255,7 +247,6 @@ NS_ScriptErrorReporter(JSContext *cx,
}
}
}
}
#ifdef DEBUG
// Print it to stderr as well, for the benefit of those invoking

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

@ -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;
}

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

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

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

@ -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"

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

@ -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));

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

@ -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;