From b107f3ff5f6aa9c8fceed30dce1d307f680f660f Mon Sep 17 00:00:00 2001 From: "mccabe%netscape.com" Date: Sat, 25 Mar 2000 04:23:31 +0000 Subject: [PATCH] Initial add of files to support a JavaScript console. r=jband, r=ben (though I've changed things slightly since they saw it.) git-svn-id: svn://10.0.0.236/trunk@64105 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/xpfe/components/console/Makefile.in | 60 ++++++ mozilla/xpfe/components/console/makefile.win | 69 +++++++ .../components/console/nsConsoleMessage.cpp | 38 ++++ .../components/console/nsConsoleMessage.h | 44 +++++ .../components/console/nsConsoleService.cpp | 182 ++++++++++++++++++ .../components/console/nsConsoleService.h | 55 ++++++ .../console/nsConsoleServiceModule.cpp | 53 +++++ .../components/console/nsIConsoleListener.idl | 34 ++++ .../components/console/nsIConsoleMessage.idl | 34 ++++ .../components/console/nsIConsoleService.idl | 50 +++++ .../components/console/nsIScriptError.idl | 69 +++++++ .../components/console/resources/Makefile.in | 32 +++ .../console/resources/content/Makefile.in | 40 ++++ .../console/resources/content/console.js | 120 ++++++++++++ .../console/resources/content/console.xul | 39 ++++ .../console/resources/content/makefile.win | 34 ++++ .../console/resources/locale/Makefile.in | 32 +++ .../resources/locale/en-US/Makefile.in | 37 ++++ .../resources/locale/en-US/console.dtd | 21 ++ .../resources/locale/en-US/makefile.win | 33 ++++ .../console/resources/locale/makefile.win | 29 +++ .../components/console/resources/makefile.win | 27 +++ 22 files changed, 1132 insertions(+) create mode 100644 mozilla/xpfe/components/console/Makefile.in create mode 100644 mozilla/xpfe/components/console/makefile.win create mode 100644 mozilla/xpfe/components/console/nsConsoleMessage.cpp create mode 100644 mozilla/xpfe/components/console/nsConsoleMessage.h create mode 100644 mozilla/xpfe/components/console/nsConsoleService.cpp create mode 100644 mozilla/xpfe/components/console/nsConsoleService.h create mode 100644 mozilla/xpfe/components/console/nsConsoleServiceModule.cpp create mode 100644 mozilla/xpfe/components/console/nsIConsoleListener.idl create mode 100644 mozilla/xpfe/components/console/nsIConsoleMessage.idl create mode 100644 mozilla/xpfe/components/console/nsIConsoleService.idl create mode 100644 mozilla/xpfe/components/console/nsIScriptError.idl create mode 100644 mozilla/xpfe/components/console/resources/Makefile.in create mode 100644 mozilla/xpfe/components/console/resources/content/Makefile.in create mode 100644 mozilla/xpfe/components/console/resources/content/console.js create mode 100644 mozilla/xpfe/components/console/resources/content/console.xul create mode 100644 mozilla/xpfe/components/console/resources/content/makefile.win create mode 100644 mozilla/xpfe/components/console/resources/locale/Makefile.in create mode 100644 mozilla/xpfe/components/console/resources/locale/en-US/Makefile.in create mode 100644 mozilla/xpfe/components/console/resources/locale/en-US/console.dtd create mode 100644 mozilla/xpfe/components/console/resources/locale/en-US/makefile.win create mode 100644 mozilla/xpfe/components/console/resources/locale/makefile.win create mode 100644 mozilla/xpfe/components/console/resources/makefile.win diff --git a/mozilla/xpfe/components/console/Makefile.in b/mozilla/xpfe/components/console/Makefile.in new file mode 100644 index 00000000000..08e1095de16 --- /dev/null +++ b/mozilla/xpfe/components/console/Makefile.in @@ -0,0 +1,60 @@ +# +# 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): +# + + +DEPTH = ../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +IS_COMPONENT = 1 + +DIRS = resources + +MODULE = consoleservice +LIBRARY_NAME = consoleservice +IS_COMPONENT = 1 + +CPPSRCS = \ + nsConsoleMessage.cpp \ + nsConsoleService.cpp \ + nsConsoleServiceModule.cpp \ + $(NULL) + +XPIDLSRCS = \ + nsIConsoleService.idl \ + nsIConsoleMessage.idl \ + nsIConsoleListener.idl \ + nsIScriptError.idl \ + $(NULL) + +include $(topsrcdir)/config/rules.mk + + + + + + + + + diff --git a/mozilla/xpfe/components/console/makefile.win b/mozilla/xpfe/components/console/makefile.win new file mode 100644 index 00000000000..f0499c944ab --- /dev/null +++ b/mozilla/xpfe/components/console/makefile.win @@ -0,0 +1,69 @@ +#!nmake +# +# 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): + +# copied in part from ../timebomb/makefile.win + +DEPTH = ..\..\.. +MODULE = consoleservice +DLL = .\$(OBJDIR)\$(MODULE).dll +MAKE_OBJ_TYPE = DLL + +include <$(DEPTH)/config/config.mak> + +DIRS = resources + +EXPORTS = \ + $(NULL) + +XPIDLSRCS = \ + nsIConsoleService.idl \ + nsIConsoleMessage.idl \ + nsIConsoleListener.idl \ + nsIScriptError.idl \ + $(NULL) + + +LINCS = \ + $(NULL) + +LLIBS = \ + $(LIBNSPR) \ + $(DIST)\lib\xpcom.lib \ + $(NULL) + + +OBJS = \ + nsConsoleMessage.obj \ + nsConsoleService.obj \ + nsConsoleServiceModule.cpp \ + $(NULL) + +include <$(DEPTH)\config\rules.mak> + +install:: $(DLL) + $(MAKE_INSTALL) .\$(OBJDIR)\$(MODULE).dll $(DIST)\bin\components + +clobber:: + rm -f $(DIST)\bin\components\$(MODULE).dll + + + + diff --git a/mozilla/xpfe/components/console/nsConsoleMessage.cpp b/mozilla/xpfe/components/console/nsConsoleMessage.cpp new file mode 100644 index 00000000000..616e37047d7 --- /dev/null +++ b/mozilla/xpfe/components/console/nsConsoleMessage.cpp @@ -0,0 +1,38 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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. + * + */ + +/* + * Base interface for console messages. + */ + +#include "nsConsoleMessage.h" + +NS_IMPL_THREADSAFE_ISUPPORTS(nsConsoleMessage, NS_GET_IID(nsIConsoleMessage)); + +nsConsoleMessage::nsConsoleMessage() {}; +nsConsoleMessage::~nsConsoleMessage() {}; + +NS_IMETHODIMP +nsConsoleMessage::GetMessage(PRUnichar **result) { + *result = mMessage.ToNewUnicode(); + + return NS_OK; +} diff --git a/mozilla/xpfe/components/console/nsConsoleMessage.h b/mozilla/xpfe/components/console/nsConsoleMessage.h new file mode 100644 index 00000000000..7404efca1c2 --- /dev/null +++ b/mozilla/xpfe/components/console/nsConsoleMessage.h @@ -0,0 +1,44 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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. + * + */ + +/* + * 'lil description of this file. + */ + +#include "nsIConsoleMessage.h" +#include "nsString.h" + +class nsConsoleMessage : public nsIConsoleMessage { +public: + nsConsoleMessage(); + + virtual ~nsConsoleMessage(); + + nsConsoleMessage(const PRUnichar *message) { + mMessage.SetString(message); + } + + NS_DECL_ISUPPORTS + NS_DECL_NSICONSOLEMESSAGE + +private: + nsAutoString mMessage; +}; diff --git a/mozilla/xpfe/components/console/nsConsoleService.cpp b/mozilla/xpfe/components/console/nsConsoleService.cpp new file mode 100644 index 00000000000..2850458bc1d --- /dev/null +++ b/mozilla/xpfe/components/console/nsConsoleService.cpp @@ -0,0 +1,182 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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. + * + */ + +/* + * Maintains a circular buffer of recent messages, and notifies + * listeners when new messages are logged. + */ + +#include "nsConsoleService.h" +#include "nsConsoleMessage.h" +#include "nsIAllocator.h" + +NS_IMPL_THREADSAFE_ISUPPORTS(nsConsoleService, NS_GET_IID(nsIConsoleService)); + +nsConsoleService::nsConsoleService() +{ + mCurrent = 0; + mFull = PR_FALSE; + + // XXX grab this from a pref! + mBufferSize = 250; + + // Any reasonable way to deal with failure of the below two? + nsresult rv; + rv = nsSupportsArray::Create(NULL, NS_GET_IID(nsISupportsArray), + (void**)&mListeners); + mMessages = (nsIConsoleMessage **) + nsAllocator::Alloc(mBufferSize * sizeof(nsIConsoleMessage *)); + + // Array elements should be 0 initially for circular buffer algorithm. + for (PRUint32 i = 0; i < mBufferSize; i++) { + mMessages[i] = nsnull; + } + + NS_INIT_REFCNT(); +} + +nsConsoleService::~nsConsoleService() +{ + PRUint32 i = 0; + while (i < mBufferSize && mMessages[i] != nsnull) { + NS_RELEASE(mMessages[i]); + i++; + } + nsAllocator::Free(mMessages); +} + +NS_IMETHODIMP +nsConsoleService::LogMessage(nsIConsoleMessage *message) +{ + if (message == nsnull) + return NS_ERROR_FAILURE; + + // If there's already a message in the slot we're about to replace, + // we've wrapped around, and we need to release the old message before + // overwriting it. + if (mMessages[mCurrent] != nsnull) + NS_RELEASE(mMessages[mCurrent]); + + NS_ADDREF(message); + mMessages[mCurrent++] = message; + if (mCurrent == mBufferSize) { + mCurrent = 0; + mFull = PR_TRUE; + } + + // Iterate through any registered listeners and tell them about the message. + nsIConsoleListener *listener; + nsresult rv; + PRUint32 listenerCount; + rv = mListeners->Count(&listenerCount); + if (NS_FAILED(rv)) + return rv; + + for (PRUint32 i = 0; i < listenerCount; i++) { + rv = mListeners->GetElementAt(i, (nsISupports **)&listener); + if (NS_FAILED(rv)) + return rv; + listener->Observe(message); + NS_RELEASE(listener); + } + return NS_OK; +} + +NS_IMETHODIMP +nsConsoleService::LogStringMessage(const PRUnichar *message) +{ + // LogMessage adds a ref to this, and eventual release does delete. + nsConsoleMessage *msg = new nsConsoleMessage(message); + return this->LogMessage(msg); +} + +NS_IMETHODIMP +nsConsoleService::GetMessageArray(nsIConsoleMessage ***messages, PRUint32 *count) +{ + nsIConsoleMessage **messageArray; + + if (mCurrent == 0 && !mFull) { + // not sure how to return a 0-length array... + *messages = nsnull; + *count = 0; + return NS_ERROR_FAILURE; + } + + PRUint32 resultSize = mFull ? mBufferSize : mCurrent; + messageArray = + (nsIConsoleMessage **)nsAllocator::Alloc((sizeof (nsIConsoleMessage *)) + * resultSize); + + + // XXX jband sez malloc array with 1 member and return 0 count; + // might not work; if not, bug jband. + // could also return null if I want to do such. + // open question about interface contract here. + // + // jband sez: should guard against both b/c the interface doesn't specify + // which. And add my convention to /** */ in the interface. + if (messageArray == nsnull) { + *messages = nsnull; + *count = 0; + return NS_ERROR_FAILURE; + } + + PRUint32 i; + if (mFull) { + for (i = 0; i < mBufferSize; i++) { + // if full, fill the buffer starting from mCurrent (which'll be + // oldest) wrapping around the buffer to the most recent. + messageArray[i] = mMessages[(mCurrent + i) % mBufferSize]; + NS_ADDREF(messageArray[i]); + } + } else { + for (i = 0; i < mCurrent; i++) { + messageArray[i] = mMessages[i]; + NS_ADDREF(messageArray[i]); + } + } + *count = resultSize; + *messages = messageArray; + + return NS_OK; +} + +NS_IMETHODIMP +nsConsoleService::RegisterListener(nsIConsoleListener *listener) { + // ignore rv for now, as a comment says it returns prbool instead of + // nsresult. + + // Any need to check for multiply registered listeners? + mListeners->AppendElement(listener); + return NS_OK; +} + +NS_IMETHODIMP +nsConsoleService::UnregisterListener(nsIConsoleListener *listener) { + // ignore rv for now, as a comment says it returns prbool instead of + // nsresult. + mListeners->RemoveElement(listener); + return NS_OK; +} + + + + diff --git a/mozilla/xpfe/components/console/nsConsoleService.h b/mozilla/xpfe/components/console/nsConsoleService.h new file mode 100644 index 00000000000..3fa1d5fa211 --- /dev/null +++ b/mozilla/xpfe/components/console/nsConsoleService.h @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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): + */ + +/* + * 'lil description of this file. + */ + +#include "nsIConsoleService.h" +#include "nsSupportsArray.h" +#include "nsCOMPtr.h" + +class nsConsoleService : public nsIConsoleService +{ +public: + nsConsoleService(); + virtual ~nsConsoleService(); + + NS_DECL_ISUPPORTS + NS_DECL_NSICONSOLESERVICE + +private: + // Circular buffer of saved messages + nsIConsoleMessage **mMessages; + + // How big? + PRUint32 mBufferSize; + + // Index of slot in mMessages that'll be filled by *next* log message + PRUint32 mCurrent; + + // Is the buffer full? (Has mCurrent wrapped around at least once?) + PRBool mFull; + + // Listeners to notify whenever a new message is logged. + nsCOMPtr mListeners; +}; diff --git a/mozilla/xpfe/components/console/nsConsoleServiceModule.cpp b/mozilla/xpfe/components/console/nsConsoleServiceModule.cpp new file mode 100644 index 00000000000..36a681ea3d0 --- /dev/null +++ b/mozilla/xpfe/components/console/nsConsoleServiceModule.cpp @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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): + */ +#include "nsIModule.h" +#include "nsIGenericFactory.h" + +#include "nsConsoleService.h" + +NS_GENERIC_FACTORY_CONSTRUCTOR(nsConsoleService) + +static nsModuleComponentInfo components[] = +{ + { "Console Service", NS_CONSOLESERVICE_CID, NS_CONSOLESERVICE_PROGID, + nsConsoleServiceConstructor, + nsnull, // RegisterConsoleService + nsnull, // UnregisterConsoleService + } +}; + +//////////////////////////////////////////////////////////////////////// +// Implement the NSGetModule() exported function for your module +// and the entire implementation of the module object. +// +// NOTE: If you want to use the module shutdown to release any +// module specific resources, use the macro +// NS_IMPL_NSGETMODULE_WITH_DTOR() instead of the vanilla +// NS_IMPL_NSGETMODULE() +// + +// e.g. xpconnect uses this to release some singletons; +// xdr search on ..._WITH_DTOR + +NS_IMPL_NSGETMODULE("nsConsoleServiceModule", components) + + diff --git a/mozilla/xpfe/components/console/nsIConsoleListener.idl b/mozilla/xpfe/components/console/nsIConsoleListener.idl new file mode 100644 index 00000000000..4def7ec5233 --- /dev/null +++ b/mozilla/xpfe/components/console/nsIConsoleListener.idl @@ -0,0 +1,34 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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): + */ + +/* + * Used by the console service to notify listeners of new console messages. + */ + +#include "nsISupports.idl" +#include "nsIConsoleMessage.idl" + +[scriptable, uuid(eaaf61d6-1dd1-11b2-bc6e-8fc96480f20d)] +interface nsIConsoleListener : nsISupports +{ + void observe(in nsIConsoleMessage aMessage); +}; diff --git a/mozilla/xpfe/components/console/nsIConsoleMessage.idl b/mozilla/xpfe/components/console/nsIConsoleMessage.idl new file mode 100644 index 00000000000..e21a0fed985 --- /dev/null +++ b/mozilla/xpfe/components/console/nsIConsoleMessage.idl @@ -0,0 +1,34 @@ +/* -*- Mode: C++; tab-width: 4; 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): + */ + +#include "nsISupports.idl" + +/** + * This is intended as a base interface; implementations may want to + * provide an object that can be qi'ed to provide more specific + * message information. + */ +[scriptable, uuid(41bd8784-1dd2-11b2-9553-8606958fffe1)] +interface nsIConsoleMessage : nsISupports +{ + readonly attribute wstring message; +}; diff --git a/mozilla/xpfe/components/console/nsIConsoleService.idl b/mozilla/xpfe/components/console/nsIConsoleService.idl new file mode 100644 index 00000000000..52dca82bb44 --- /dev/null +++ b/mozilla/xpfe/components/console/nsIConsoleService.idl @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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): + */ + +#include "nsISupports.idl" +#include "nsIConsoleListener.idl" +#include "nsIConsoleMessage.idl" + + +[scriptable, uuid(a647f184-1dd1-11b2-a9d1-8537b201161b)] +interface nsIConsoleService : nsISupports +{ + void logMessage(in nsIConsoleMessage message); + // Needed for folks who need to avoid nsIConsoleMessage hassle + void logStringMessage(in wstring message); + + void getMessageArray([array, size_is(count)] out nsIConsoleMessage messages, + out PRUint32 count); + + void registerListener(in nsIConsoleListener listener); + + void unregisterListener(in nsIConsoleListener listener); + +}; + + +%{ C++ +#define NS_CONSOLESERVICE_CID \ +{ 0x7e3ff85c, 0x1dd2, 0x11b2, { 0x8d, 0x4b, 0xeb, 0x45, 0x2c, 0xb0, 0xff, 0x40 }} + +#define NS_CONSOLESERVICE_PROGID "consoleservice" +%} diff --git a/mozilla/xpfe/components/console/nsIScriptError.idl b/mozilla/xpfe/components/console/nsIScriptError.idl new file mode 100644 index 00000000000..0c851b7d92a --- /dev/null +++ b/mozilla/xpfe/components/console/nsIScriptError.idl @@ -0,0 +1,69 @@ +/* -*- Mode: C++; tab-width: 4; 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): + */ + +#include "nsISupports.idl" +#include "nsIConsoleMessage.idl" + +[scriptable, uuid(fc9e5a94-1dd1-11b2-888b-d8907b2c6996)] +interface nsIScriptError : nsIConsoleMessage +{ + /** pseudo-flag for default case */ + const unsigned long ERROR = 0x0; + + /** message is warning */ + const unsigned long WARNING = 0x1; + + /** exception was thrown for this case - exception-aware hosts can ignore */ + const unsigned long EXCEPTION = 0x2; + + // XXX check how strict is implemented these days. + /** error or warning is due to strict option */ + const unsigned long STRICT = 0x4; + + readonly attribute wstring fileName; + readonly attribute PRUint32 lineNumber; + readonly attribute wstring sourceLine; + readonly attribute PRUint32 columnNumber; + readonly attribute PRUint32 flags; + + readonly attribute wstring category; +}; + +// jband asks: save more info for debuggy stuff in console? +// e.g. title of window, maybe weak reference to originating window? +// maybe just way to get from url to loaded document. + + + +// struct JSErrorReport { +// const char *filename; /* source file name, URL, etc., or null */ +// uintN lineno; /* source line number */ +// const char *linebuf; /* offending source line without final \n */ +// const char *tokenptr; /* pointer to error token in linebuf */ +// const jschar *uclinebuf; /* unicode (original) line buffer */ +// const jschar *uctokenptr; /* unicode (original) token pointer */ +// uintN flags; /* error/warning, etc. */ +// uintN errorNumber; /* the error number, e.g. see js.msg */ +// const jschar *ucmessage; /* the (default) error message */ +// const jschar **messageArgs; /* arguments for the error message */ +// }; + diff --git a/mozilla/xpfe/components/console/resources/Makefile.in b/mozilla/xpfe/components/console/resources/Makefile.in new file mode 100644 index 00000000000..1d58468949a --- /dev/null +++ b/mozilla/xpfe/components/console/resources/Makefile.in @@ -0,0 +1,32 @@ +# +# 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): +# + +DEPTH = ../../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +DIRS = content locale + +include $(topsrcdir)/config/rules.mk + diff --git a/mozilla/xpfe/components/console/resources/content/Makefile.in b/mozilla/xpfe/components/console/resources/content/Makefile.in new file mode 100644 index 00000000000..1aa87d23b51 --- /dev/null +++ b/mozilla/xpfe/components/console/resources/content/Makefile.in @@ -0,0 +1,40 @@ +# +# 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): +# + +DEPTH = ../../../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +EXPORT_RESOURCE_CONTENT := \ + console.js \ + console.xul \ + $(NULL) + +EXPORT_RESOURCE_CONTENT := $(addprefix $(srcdir)/, $(EXPORT_RESOURCE_CONTENT)) + +include $(topsrcdir)/config/rules.mk + +install:: + $(INSTALL) $(EXPORT_RESOURCE_CONTENT) $(DIST)/bin/chrome/global/content/default + diff --git a/mozilla/xpfe/components/console/resources/content/console.js b/mozilla/xpfe/components/console/resources/content/console.js new file mode 100644 index 00000000000..8e5844b8314 --- /dev/null +++ b/mozilla/xpfe/components/console/resources/content/console.js @@ -0,0 +1,120 @@ +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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): + */ + +/* + * Functions for initializing and updating the JavaScript Console. + */ + +/* + * Listener to be registered with the console service, called on new errors. + */ +var consoleListener = { + observe : function(messageObject) { + appendMessage(messageObject); + } +} + +/* + * Gets the current context of the console service and dumps it to the window, + * and registers a listener with the service to be called on additional errors. + */ +function onLoadJSConsole() +{ + + dump('\n\nconsole loading\n\n'); + + + try { + var cs_class = Components.classes['consoleservice']; + var cs_iface = Components.interfaces.nsIConsoleService; + var cs_isupports = cs_class.getService(); + var cs = cs_isupports.QueryInterface(cs_iface); + } catch(exn) { + // Couldn't get the console service for some reason... + // pretend it never happened. + + // XXX instead should write some message to the console re: + // unable to get console service. + + return; + } + + + dump('\n\ngot console service\n\n'); + + var o1 = {}; // Throwaway references to support 'out' parameters. + var o2 = {}; + + var messages; + try { + cs.getMessageArray(o1, o2); + messages = o1.value; + } catch (exn) { + // getMessageArray throws an exception when there are no elements. + messages = []; + } + + for (i = 0; i < messages.length; i++) { + appendMessage(messages[i]); + } + + dump('\n\nregistering...\n'); + cs.registerListener(consoleListener); + dump('registered listener\n\n'); +} + +function onUnloadJSConsole() +{ + // keep a global ref. to it instead??? + + try { + var cs_class = Components.classes['consoleservice']; + var cs_iface = Components.interfaces.nsIConsoleService; + var cs_isupports = cs_class.getService(); + var cs = cs_isupports.QueryInterface(cs_iface); + } catch(exn) { + // Couldn't get the console service for some reason... + // pretend it never happened. + return; + } + + cs.unregisterListener(consoleListener); +} + +/* + * Given a message, write it to the page. + * + * TODO: (When interesting subclasses of message objects become available) - + * reflect structure of messages (e.g. lineno, etc.) as CSS-decorable structure. + */ +function appendMessage(messageObject) +{ + var c = document.getElementById("console"); + var e = document.createElement("message"); + var t = document.createTextNode(messageObject.message); + e.appendChild(t); + c.appendChild(e); +} + + +// XXX q: if window is open, does it grow forever? Is that OK? +// or should it do its own retiring? diff --git a/mozilla/xpfe/components/console/resources/content/console.xul b/mozilla/xpfe/components/console/resources/content/console.xul new file mode 100644 index 00000000000..3aaad3f521e --- /dev/null +++ b/mozilla/xpfe/components/console/resources/content/console.xul @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + diff --git a/mozilla/xpfe/components/console/resources/content/makefile.win b/mozilla/xpfe/components/console/resources/content/makefile.win new file mode 100644 index 00000000000..1c9b2be7364 --- /dev/null +++ b/mozilla/xpfe/components/console/resources/content/makefile.win @@ -0,0 +1,34 @@ +#!nmake +# +# 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): + +DEPTH=..\..\..\.. + +include <$(DEPTH)\config\rules.mak> + +DISTBROWSWER=$(DIST)\bin\chrome\global\content\default + +install:: + $(MAKE_INSTALL) console.js $(DISTBROWSER) + $(MAKE_INSTALL) console.xul $(DISTBROWSER) + +clobber:: + rm -f $(DISTBROWSER)\console.js + rm -f $(DISTBROWSER)\console.xul diff --git a/mozilla/xpfe/components/console/resources/locale/Makefile.in b/mozilla/xpfe/components/console/resources/locale/Makefile.in new file mode 100644 index 00000000000..196a33733d0 --- /dev/null +++ b/mozilla/xpfe/components/console/resources/locale/Makefile.in @@ -0,0 +1,32 @@ +# +# 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): +# + +DEPTH = ../../../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +DIRS = en-US + +include $(topsrcdir)/config/rules.mk + diff --git a/mozilla/xpfe/components/console/resources/locale/en-US/Makefile.in b/mozilla/xpfe/components/console/resources/locale/en-US/Makefile.in new file mode 100644 index 00000000000..a70aa1a09db --- /dev/null +++ b/mozilla/xpfe/components/console/resources/locale/en-US/Makefile.in @@ -0,0 +1,37 @@ +# +# 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): +# + +DEPTH = ../../../../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +EXPORT_RESOURCE_CONTENT = \ + console.dtd \ + $(NULL) + +include $(topsrcdir)/config/rules.mk + +install:: + $(INSTALL) $(EXPORT_RESOURCE_CONTENT) $(DIST)/bin/chrome/global/locale/en-US + diff --git a/mozilla/xpfe/components/console/resources/locale/en-US/console.dtd b/mozilla/xpfe/components/console/resources/locale/en-US/console.dtd new file mode 100644 index 00000000000..9051aea37a7 --- /dev/null +++ b/mozilla/xpfe/components/console/resources/locale/en-US/console.dtd @@ -0,0 +1,21 @@ + + + diff --git a/mozilla/xpfe/components/console/resources/locale/en-US/makefile.win b/mozilla/xpfe/components/console/resources/locale/en-US/makefile.win new file mode 100644 index 00000000000..39a0db5d327 --- /dev/null +++ b/mozilla/xpfe/components/console/resources/locale/en-US/makefile.win @@ -0,0 +1,33 @@ +#!nmake +# +# 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): + +DEPTH=..\..\..\..\..\.. + +include <$(DEPTH)\config\rules.mak> + +DISTBROWSER=$(DIST)\bin\chrome\global\locale\en-US + +install:: + $(MAKE_INSTALL) console.dtd $(DISTBROWSER) + +clobber:: + rm -f $(DISTBROWSER)\console.dtd + diff --git a/mozilla/xpfe/components/console/resources/locale/makefile.win b/mozilla/xpfe/components/console/resources/locale/makefile.win new file mode 100644 index 00000000000..1deb5c0eeb9 --- /dev/null +++ b/mozilla/xpfe/components/console/resources/locale/makefile.win @@ -0,0 +1,29 @@ +#!nmake +# +# 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): + + + +DEPTH=..\..\..\..\.. + +DIRS= en-US + +include <$(DEPTH)\config\rules.mak> + diff --git a/mozilla/xpfe/components/console/resources/makefile.win b/mozilla/xpfe/components/console/resources/makefile.win new file mode 100644 index 00000000000..0866dd40cfb --- /dev/null +++ b/mozilla/xpfe/components/console/resources/makefile.win @@ -0,0 +1,27 @@ +#!nmake +# +# 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): + +DEPTH=..\..\..\.. + +DIRS= content locale + +include <$(DEPTH)\config\rules.mak> +