Bug 859756 - [browserconsole] Add timestamp, category and window IDs to nsIConsoleMessages; r=bz

This commit is contained in:
Mihai Sucan 2013-05-16 20:23:46 +03:00
parent 1c4ff5e9b2
commit 7c419043ce
8 changed files with 157 additions and 45 deletions

View File

@ -11,7 +11,7 @@
#include "nsISupports.idl"
#include "nsIConsoleMessage.idl"
[scriptable, uuid(ec640482-be5f-49a0-a9cb-c87eacce9291)]
[scriptable, uuid(cac9d8e8-0d53-4fa8-9903-bb367e4fa1fe)]
interface nsIScriptError : nsIConsoleMessage
{
/** pseudo-flag for default case */
@ -41,33 +41,6 @@ interface nsIScriptError : nsIConsoleMessage
readonly attribute uint32_t columnNumber;
readonly attribute uint32_t flags;
/**
* Categories I know about -
* XUL javascript
* content javascript (both of these from nsDocShell, currently)
* component javascript (errors in JS components)
*/
readonly attribute string category;
/*
The time (in milliseconds from the Epoch) that the script error instance
was initialised, and thus the time when the error occurred.
Currently used to display date and time of the message in Error console.
The timestamp is initialized as JS_now/1000 so that it can be
compared to Date.now in Javascript.
*/
readonly attribute long long timeStamp;
/* Get the window id this was initialized with. Zero will be
returned if init() was used instead of initWithWindowID(). */
readonly attribute unsigned long long outerWindowID;
/* Get the inner window id this was initialized with. Zero will be
returned if init() was used instead of initWithWindowID(). */
readonly attribute unsigned long long innerWindowID;
readonly attribute boolean isFromPrivateWindow;
void init(in AString message,
in AString sourceName,
in AString sourceLine,
@ -87,13 +60,11 @@ interface nsIScriptError : nsIConsoleMessage
in uint32_t flags,
in string category,
in unsigned long long innerWindowID);
AUTF8String toString();
};
%{ C++
#define NS_SCRIPTERROR_CID \
{ 0xe38e53b9, 0x5bb0, 0x456a, { 0xb5, 0x53, 0x57, 0x93, 0x70, 0xcb, 0x15, 0x67 }}
{ 0x1950539a, 0x90f0, 0x4d22, { 0xb5, 0xaf, 0x71, 0x32, 0x9c, 0x68, 0xfa, 0x35 }}
#define NS_SCRIPTERROR_CONTRACTID "@mozilla.org/scripterror;1"
%}

View File

@ -93,6 +93,16 @@ nsScriptError::GetCategory(char **result) {
return NS_OK;
}
// nsIConsoleMessage method
NS_IMETHODIMP
nsScriptError::InitMessage(const nsAString& message,
const char *category,
uint64_t innerWindowID)
{
return InitWithWindowID(message, EmptyString(), EmptyString(), 0, 0, 0,
category, innerWindowID);
}
NS_IMETHODIMP
nsScriptError::Init(const nsAString& message,
const nsAString& sourceName,

View File

@ -103,6 +103,7 @@ endif
LOCAL_INCLUDES += \
-I$(srcdir)/../build \
-I$(topsrcdir)/xpcom/ds \
-I$(topsrcdir)/dom/base \
$(NULL)
# We generate ErrorListCxxDefines.h from ErrorList.h using regex. The -n option

View File

@ -9,29 +9,115 @@
#include "nsConsoleMessage.h"
#include "nsReadableUtils.h"
#include "jsapi.h"
#include "nsGlobalWindow.h"
#include "nsPIDOMWindow.h"
#include "nsILoadContext.h"
#include "nsIDocShell.h"
NS_IMPL_THREADSAFE_ISUPPORTS1(nsConsoleMessage, nsIConsoleMessage)
nsConsoleMessage::nsConsoleMessage()
nsConsoleMessage::nsConsoleMessage()
: mMessage(),
mCategory(),
mOuterWindowID(0),
mInnerWindowID(0),
mTimeStamp(0),
mIsFromPrivateWindow(false)
{
}
nsConsoleMessage::nsConsoleMessage(const PRUnichar *message)
nsConsoleMessage::nsConsoleMessage(const PRUnichar *message)
{
mMessage.Assign(message);
nsString m;
m.Assign(message);
InitMessage(m, nullptr, 0);
}
NS_IMETHODIMP
nsConsoleMessage::GetMessageMoz(PRUnichar **result) {
*result = ToNewUnicode(mMessage);
nsConsoleMessage::InitMessage(const nsAString& message,
const char *category,
uint64_t innerWindowID)
{
mTimeStamp = JS_Now() / 1000;
mMessage.Assign(message);
mCategory.Assign(category);
mInnerWindowID = innerWindowID;
return NS_OK;
if (innerWindowID) {
nsGlobalWindow* window = nsGlobalWindow::GetInnerWindowWithId(innerWindowID);
if (window) {
nsPIDOMWindow* outer = window->GetOuterWindow();
if (outer)
mOuterWindowID = outer->WindowID();
nsIDocShell* docShell = window->GetDocShell();
nsCOMPtr<nsILoadContext> loadContext = do_QueryInterface(docShell);
if (loadContext) {
// Never mark exceptions from chrome windows as having come from
// private windows, since we always want them to be reported.
nsIPrincipal* winPrincipal = window->GetPrincipal();
mIsFromPrivateWindow = loadContext->UsePrivateBrowsing() &&
!nsContentUtils::IsSystemPrincipal(winPrincipal);
}
}
}
return NS_OK;
}
// NS_IMETHODIMP
// nsConsoleMessage::Init(const PRUnichar *message) {
// nsAutoString newMessage(message);
// mMessage = ToNewUnicode(newMessage);
// return NS_OK;
// }
NS_IMETHODIMP
nsConsoleMessage::GetMessageMoz(PRUnichar **result)
{
*result = ToNewUnicode(mMessage);
return NS_OK;
}
NS_IMETHODIMP
nsConsoleMessage::GetCategory(char **result)
{
*result = ToNewCString(mCategory);
return NS_OK;
}
NS_IMETHODIMP
nsConsoleMessage::GetOuterWindowID(uint64_t *aOuterWindowID)
{
*aOuterWindowID = mOuterWindowID;
return NS_OK;
}
NS_IMETHODIMP
nsConsoleMessage::GetInnerWindowID(uint64_t *aInnerWindowID)
{
*aInnerWindowID = mInnerWindowID;
return NS_OK;
}
NS_IMETHODIMP
nsConsoleMessage::GetTimeStamp(int64_t *aTimeStamp)
{
*aTimeStamp = mTimeStamp;
return NS_OK;
}
NS_IMETHODIMP
nsConsoleMessage::GetIsFromPrivateWindow(bool *aIsFromPrivateWindow)
{
*aIsFromPrivateWindow = mIsFromPrivateWindow;
return NS_OK;
}
NS_IMETHODIMP
nsConsoleMessage::ToString(nsACString& /*UTF8*/ aResult)
{
if (!mCategory.IsEmpty())
aResult.Assign(mCategory + NS_LITERAL_CSTRING(": ") +
NS_ConvertUTF16toUTF8(mMessage));
else
CopyUTF16toUTF8(mMessage, aResult);
return NS_OK;
}

View File

@ -22,6 +22,11 @@ public:
private:
~nsConsoleMessage() {}
int64_t mTimeStamp;
nsCString mCategory;
uint64_t mOuterWindowID;
uint64_t mInnerWindowID;
bool mIsFromPrivateWindow;
nsString mMessage;
};

View File

@ -10,13 +10,49 @@
* provide an object that can be qi'ed to provide more specific
* message information.
*/
[scriptable, uuid(41bd8784-1dd2-11b2-9553-8606958fffe1)]
[scriptable, uuid(c14c151b-5ea4-47ed-8e85-d392cdd3e154)]
interface nsIConsoleMessage : nsISupports
{
void initMessage(in AString message, [optional] in string category, [optional] in unsigned long long innerWindowID);
/**
* The time (in milliseconds from the Epoch) that the message instance
* was initialised.
* The timestamp is initialized as JS_now/1000 so that it can be
* compared to Date.now in Javascript.
*/
readonly attribute long long timeStamp;
/**
* Categories I know about
* - nsIScriptError:
* XUL javascript
* content javascript (both of these from nsDocShell, currently)
* component javascript (errors in JS components)
* - nsIConsoleMessage: none yet.
*/
readonly attribute string category;
/**
* Get the window id this was initialized with.
*/
readonly attribute unsigned long long outerWindowID;
/**
* Get the inner window id this was initialized with.
*/
readonly attribute unsigned long long innerWindowID;
readonly attribute boolean isFromPrivateWindow;
[binaryname(MessageMoz)] readonly attribute wstring message;
AUTF8String toString();
};
%{ C++
#define NS_CONSOLEMESSAGE_CID \
{ 0x56c9d666, 0x1dd2, 0x11b2, { 0xb4, 0x3c, 0xa8, 0x4b, 0xf3, 0xb3, 0xec, 0xbb }}
{ 0x024efc9e, 0x54dc, 0x4844, { 0x80, 0x4b, 0x41, 0xd3, 0xf3, 0x69, 0x90, 0x73 }}
#define NS_CONSOLEMESSAGE_CONTRACTID "@mozilla.org/consolemessage;1"
%}

View File

@ -21,6 +21,7 @@
COMPONENT(ARRAY, nsArray::XPCOMConstructor)
COMPONENT(CONSOLESERVICE, nsConsoleServiceConstructor)
COMPONENT(EXCEPTIONSERVICE, nsExceptionServiceConstructor)
COMPONENT(CONSOLEMESSAGE, nsConsoleMessageConstructor)
COMPONENT(ATOMSERVICE, nsAtomServiceConstructor)
COMPONENT(OBSERVERSERVICE, nsObserverService::Create)
#ifdef MOZ_VISUAL_EVENT_TRACER

View File

@ -39,6 +39,7 @@
#include "nsSupportsPrimitives.h"
#include "nsConsoleService.h"
#include "nsExceptionService.h"
#include "nsConsoleMessage.h"
#include "nsComponentManager.h"
#include "nsCategoryManagerUtils.h"
@ -178,6 +179,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsVoidImpl)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsInterfacePointerImpl)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsConsoleService, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsConsoleMessage)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAtomService)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsExceptionService)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsTimerImpl)