Bug 1109291 - Include better paths for hanging chrome scripts in profile extensions directory; r=snorp r=bsmedberg

This commit is contained in:
Jim Chen
2014-12-16 17:09:17 -05:00
parent e6bc7a6b6e
commit e034c991d4

View File

@@ -541,6 +541,8 @@ IsChromeJSScript(JSScript* aScript)
return secman->IsSystemPrincipal(nsJSPrincipals::get(principals));
}
// Get the full path after the URI scheme, if the URI matches the scheme.
// For example, GetFullPathForScheme("a://b/c/d/e", "a://") returns "b/c/d/e".
template <size_t LEN>
const char*
GetFullPathForScheme(const char* filename, const char (&scheme)[LEN]) {
@@ -551,6 +553,23 @@ GetFullPathForScheme(const char* filename, const char (&scheme)[LEN]) {
return nullptr;
}
// Get the full path after a URI component, if the URI contains the component.
// For example, GetPathAfterComponent("a://b/c/d/e", "/c/") returns "d/e".
template <size_t LEN>
const char*
GetPathAfterComponent(const char* filename, const char (&component)[LEN]) {
const char* found = nullptr;
const char* next = strstr(filename, component);
while (next) {
// Move 'found' to end of the component, after the separator '/'.
// 'LEN - 1' accounts for the null terminator included in LEN,
found = next + LEN - 1;
// Resume searching before the separator '/'.
next = strstr(found - 1, component);
}
return found;
}
} // namespace
const char*
@@ -566,19 +585,30 @@ ThreadStackHelper::AppendJSEntry(const volatile StackEntry* aEntry,
const char* label;
if (IsChromeJSScript(aEntry->script())) {
const char* const filename = JS_GetScriptFilename(aEntry->script());
unsigned lineno = JS_PCToLineNumber(aEntry->script(), aEntry->pc());
const char* filename = JS_GetScriptFilename(aEntry->script());
const unsigned lineno = JS_PCToLineNumber(aEntry->script(), aEntry->pc());
MOZ_ASSERT(filename);
char buffer[64]; // Enough to fit longest js file name from the tree
const char* basename;
char buffer[128]; // Enough to fit longest js file name from the tree
// Some script names are in the form "foo -> bar -> baz".
// Here we find the origin of these redirected scripts.
const char* basename = GetPathAfterComponent(filename, " -> ");
if (basename) {
filename = basename;
}
basename = GetFullPathForScheme(filename, "chrome://");
if (!basename) {
basename = GetFullPathForScheme(filename, "resource://");
}
if (!basename) {
// Only keep the file base name for paths not under the above schemes.
// If the (add-on) script is located under the {profile}/extensions
// directory, extract the path after the /extensions/ part.
basename = GetPathAfterComponent(filename, "/extensions/");
}
if (!basename) {
// Only keep the file base name for paths outside the above formats.
basename = strrchr(filename, '/');
basename = basename ? basename + 1 : filename;
}