Bug 1052096 - Add an API to access the 'Location' string (used by memory reporters) of a compartment. r=billm

This commit is contained in:
Bobby Holley 2014-09-12 17:41:18 -07:00
parent 5d41b32105
commit 90951a49fc
2 changed files with 28 additions and 1 deletions

View File

@ -122,7 +122,7 @@ interface ScheduledGCCallback : nsISupports
/**
* interface of Components.utils
*/
[scriptable, uuid(60b1ddd1-7567-41da-85f6-638096acd564)]
[scriptable, uuid(faa33210-536b-42e5-b9b0-8ea239899ba4)]
interface nsIXPCComponents_Utils : nsISupports
{
@ -640,6 +640,18 @@ interface nsIXPCComponents_Utils : nsISupports
[implicit_jscontext]
nsIPrincipal getObjectPrincipal(in jsval obj);
/*
* Gets the URI or identifier string associated with an object's
* compartment (the same one used by the memory reporter machinery).
*
* Unwraps cross-compartment wrappers first.
*
* The string formats and values may change at any time. Do not depend on
* this from addon code.
*/
[implicit_jscontext]
ACString getCompartmentLocation(in jsval obj);
[implicit_jscontext]
void setAddonInterposition(in ACString addonId, in nsIAddonInterposition interposition);

View File

@ -3540,6 +3540,21 @@ nsXPCComponents_Utils::GetObjectPrincipal(HandleValue val, JSContext *cx,
return NS_OK;
}
NS_IMETHODIMP
nsXPCComponents_Utils::GetCompartmentLocation(HandleValue val,
JSContext *cx,
nsACString &result)
{
if (!val.isObject())
return NS_ERROR_INVALID_ARG;
RootedObject obj(cx, &val.toObject());
obj = js::CheckedUnwrap(obj);
MOZ_ASSERT(obj);
result = xpc::CompartmentPrivate::Get(obj)->GetLocation();
return NS_OK;
}
NS_IMETHODIMP
nsXPCComponents_Utils::SetAddonInterposition(const nsACString &addonIdStr,
nsIAddonInterposition *interposition,