Loading js/xpconnect/src/XPCConvert.cpp +4 −1 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ /* Data conversion between native and JavaScript types. */ #include "mozilla/Util.h" #include "mozilla/Omnijar.h" #include "xpcprivate.h" #include "nsString.h" Loading Loading @@ -1319,9 +1320,11 @@ XPCConvert::JSErrorToXPCException(const char* message, static_cast<const PRUnichar*>(report->uclinebuf); data = new nsScriptError(); nsAutoCString resourceFilename; Omnijar::ConvertToResourceFilename(nsCString(report->filename), resourceFilename); data->InitWithWindowID( bestMessage, NS_ConvertASCIItoUTF16(report->filename), NS_ConvertASCIItoUTF16(resourceFilename.get()), uclinebuf ? nsDependentString(uclinebuf) : EmptyString(), report->lineno, report->uctokenptr - report->uclinebuf, report->flags, Loading js/xpconnect/src/XPCException.cpp +7 −1 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ #include "xpcprivate.h" #include "nsError.h" #include "nsIUnicodeDecoder.h" #include "mozilla/Omnijar.h" /***************************************************************************/ /* Quick and dirty mapping of well known result codes to strings. We only Loading Loading @@ -291,8 +292,13 @@ nsXPCException::Initialize(const char *aMessage, nsresult aResult, const char *a // For now, fill in our location details from our stack frame. // Later we may allow other locations? nsresult rc; if (NS_FAILED(rc = aLocation->GetFilename(&mFilename))) char* rawFilename = nullptr; if (NS_FAILED(rc = aLocation->GetFilename(&rawFilename))) return rc; nsAutoCString resourceFilename; mozilla::Omnijar::ConvertToResourceFilename(nsCString(rawFilename), resourceFilename); mFilename = (char *) nsMemory::Clone(resourceFilename.get(), resourceFilename.Length()+1); nsMemory::Free(rawFilename); // allocated by GetFilename if (NS_FAILED(rc = aLocation->GetLineNumber(&mLineNumber))) return rc; } else { Loading js/xpconnect/src/XPCStack.cpp +5 −2 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ /* Implements nsIStackFrame. */ #include "xpcprivate.h" #include "mozilla/Omnijar.h" class XPCJSStackFrame : public nsIStackFrame { Loading Loading @@ -107,9 +108,11 @@ XPCJSStackFrame::CreateStack(JSContext* cx, XPCJSStackFrame** stack) JSAutoCompartment ac(cx, desc->frames[i].script); const char* filename = JS_GetScriptFilename(cx, desc->frames[i].script); if (filename) { nsAutoCString resourceFilename; mozilla::Omnijar::ConvertToResourceFilename(nsCString(filename), resourceFilename); self->mFilename = (char*) nsMemory::Clone(filename, sizeof(char)*(strlen(filename)+1)); nsMemory::Clone(resourceFilename.get(), sizeof(char)*(resourceFilename.Length()+1)); } self->mLineno = desc->frames[i].lineno; Loading xpcom/build/Omnijar.cpp +30 −0 Original line number Diff line number Diff line Loading @@ -164,4 +164,34 @@ Omnijar::GetURIString(Type aType, nsACString &result) return NS_OK; } bool Omnijar::RebaseFilename(const nsCString& filename, const nsCString& oldBase, const nsCString& newBase, nsACString &result) { PRInt32 pos = filename.Find(oldBase); PRInt32 pathLen = filename.Length() - pos - oldBase.Length(); if (pos > -1 && pathLen > -1 && pathLen <= filename.Length()) { nsAutoCString path; filename.Right(path, pathLen); result = newBase + path; return true; } result = filename; return false; } void Omnijar::ConvertToResourceFilename(const nsCString& filename, nsACString &result) { if (StringBeginsWith(filename, NS_LITERAL_CSTRING("file://")) || StringBeginsWith(filename, NS_LITERAL_CSTRING("jar:"))) { if (RebaseFilename(filename, NS_LITERAL_CSTRING("/browser/omni.ja!/"), NS_LITERAL_CSTRING("resource://app/"), result)) { return; } if (RebaseFilename(filename, NS_LITERAL_CSTRING("/omni.ja!/"), NS_LITERAL_CSTRING("resource://gre/"), result)) { return; } } result = filename; } } /* namespace mozilla */ xpcom/build/Omnijar.h +13 −0 Original line number Diff line number Diff line Loading @@ -117,12 +117,25 @@ static already_AddRefed<nsZipArchive> GetReader(nsIFile *aPath); */ static nsresult GetURIString(Type aType, nsACString &result); /** * If the filename contains a "file://" URI, which is an absolute path, * attempts to convert to a "resource://" URI. Otherwise returns the * filename unchanged. */ static void ConvertToResourceFilename(const nsCString& filename, nsACString &result); private: /** * Used internally, respectively by Init() and CleanUp() */ static void InitOne(nsIFile *aPath, Type aType); static void CleanUpOne(Type aType); /** * Rebases a filename, given a (possibly internal) base directory, and a new * base directory name. E.g.: RebaseFilename("a/b/c","b","d",result) -> result = "d/c". */ static bool RebaseFilename(const nsCString& filename, const nsCString& oldBase, const nsCString& newBase, nsACString &result); }; /* class Omnijar */ Loading Loading
js/xpconnect/src/XPCConvert.cpp +4 −1 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ /* Data conversion between native and JavaScript types. */ #include "mozilla/Util.h" #include "mozilla/Omnijar.h" #include "xpcprivate.h" #include "nsString.h" Loading Loading @@ -1319,9 +1320,11 @@ XPCConvert::JSErrorToXPCException(const char* message, static_cast<const PRUnichar*>(report->uclinebuf); data = new nsScriptError(); nsAutoCString resourceFilename; Omnijar::ConvertToResourceFilename(nsCString(report->filename), resourceFilename); data->InitWithWindowID( bestMessage, NS_ConvertASCIItoUTF16(report->filename), NS_ConvertASCIItoUTF16(resourceFilename.get()), uclinebuf ? nsDependentString(uclinebuf) : EmptyString(), report->lineno, report->uctokenptr - report->uclinebuf, report->flags, Loading
js/xpconnect/src/XPCException.cpp +7 −1 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ #include "xpcprivate.h" #include "nsError.h" #include "nsIUnicodeDecoder.h" #include "mozilla/Omnijar.h" /***************************************************************************/ /* Quick and dirty mapping of well known result codes to strings. We only Loading Loading @@ -291,8 +292,13 @@ nsXPCException::Initialize(const char *aMessage, nsresult aResult, const char *a // For now, fill in our location details from our stack frame. // Later we may allow other locations? nsresult rc; if (NS_FAILED(rc = aLocation->GetFilename(&mFilename))) char* rawFilename = nullptr; if (NS_FAILED(rc = aLocation->GetFilename(&rawFilename))) return rc; nsAutoCString resourceFilename; mozilla::Omnijar::ConvertToResourceFilename(nsCString(rawFilename), resourceFilename); mFilename = (char *) nsMemory::Clone(resourceFilename.get(), resourceFilename.Length()+1); nsMemory::Free(rawFilename); // allocated by GetFilename if (NS_FAILED(rc = aLocation->GetLineNumber(&mLineNumber))) return rc; } else { Loading
js/xpconnect/src/XPCStack.cpp +5 −2 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ /* Implements nsIStackFrame. */ #include "xpcprivate.h" #include "mozilla/Omnijar.h" class XPCJSStackFrame : public nsIStackFrame { Loading Loading @@ -107,9 +108,11 @@ XPCJSStackFrame::CreateStack(JSContext* cx, XPCJSStackFrame** stack) JSAutoCompartment ac(cx, desc->frames[i].script); const char* filename = JS_GetScriptFilename(cx, desc->frames[i].script); if (filename) { nsAutoCString resourceFilename; mozilla::Omnijar::ConvertToResourceFilename(nsCString(filename), resourceFilename); self->mFilename = (char*) nsMemory::Clone(filename, sizeof(char)*(strlen(filename)+1)); nsMemory::Clone(resourceFilename.get(), sizeof(char)*(resourceFilename.Length()+1)); } self->mLineno = desc->frames[i].lineno; Loading
xpcom/build/Omnijar.cpp +30 −0 Original line number Diff line number Diff line Loading @@ -164,4 +164,34 @@ Omnijar::GetURIString(Type aType, nsACString &result) return NS_OK; } bool Omnijar::RebaseFilename(const nsCString& filename, const nsCString& oldBase, const nsCString& newBase, nsACString &result) { PRInt32 pos = filename.Find(oldBase); PRInt32 pathLen = filename.Length() - pos - oldBase.Length(); if (pos > -1 && pathLen > -1 && pathLen <= filename.Length()) { nsAutoCString path; filename.Right(path, pathLen); result = newBase + path; return true; } result = filename; return false; } void Omnijar::ConvertToResourceFilename(const nsCString& filename, nsACString &result) { if (StringBeginsWith(filename, NS_LITERAL_CSTRING("file://")) || StringBeginsWith(filename, NS_LITERAL_CSTRING("jar:"))) { if (RebaseFilename(filename, NS_LITERAL_CSTRING("/browser/omni.ja!/"), NS_LITERAL_CSTRING("resource://app/"), result)) { return; } if (RebaseFilename(filename, NS_LITERAL_CSTRING("/omni.ja!/"), NS_LITERAL_CSTRING("resource://gre/"), result)) { return; } } result = filename; } } /* namespace mozilla */
xpcom/build/Omnijar.h +13 −0 Original line number Diff line number Diff line Loading @@ -117,12 +117,25 @@ static already_AddRefed<nsZipArchive> GetReader(nsIFile *aPath); */ static nsresult GetURIString(Type aType, nsACString &result); /** * If the filename contains a "file://" URI, which is an absolute path, * attempts to convert to a "resource://" URI. Otherwise returns the * filename unchanged. */ static void ConvertToResourceFilename(const nsCString& filename, nsACString &result); private: /** * Used internally, respectively by Init() and CleanUp() */ static void InitOne(nsIFile *aPath, Type aType); static void CleanUpOne(Type aType); /** * Rebases a filename, given a (possibly internal) base directory, and a new * base directory name. E.g.: RebaseFilename("a/b/c","b","d",result) -> result = "d/c". */ static bool RebaseFilename(const nsCString& filename, const nsCString& oldBase, const nsCString& newBase, nsACString &result); }; /* class Omnijar */ Loading