зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1465728 part 1 - Move location and locationURI fields from CompartmentPrivate to RealmPrivate. r=bz
The xpcprivate.h changes are just code motion, except I changed the order of the GetLocationURI methods to get a much more readable diff.
This commit is contained in:
Родитель
d113b6d4a4
Коммит
71d86bded9
|
@ -3021,7 +3021,7 @@ nsXPCComponents_Utils::GetCompartmentLocation(HandleValue val,
|
|||
obj = js::CheckedUnwrap(obj);
|
||||
MOZ_ASSERT(obj);
|
||||
|
||||
result = xpc::CompartmentPrivate::Get(obj)->GetLocation();
|
||||
result = xpc::RealmPrivate::Get(obj)->GetLocation();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -206,14 +206,14 @@ RealmPrivate::RealmPrivate(JS::Realm* realm)
|
|||
|
||||
static bool
|
||||
TryParseLocationURICandidate(const nsACString& uristr,
|
||||
CompartmentPrivate::LocationHint aLocationHint,
|
||||
RealmPrivate::LocationHint aLocationHint,
|
||||
nsIURI** aURI)
|
||||
{
|
||||
static NS_NAMED_LITERAL_CSTRING(kGRE, "resource://gre/");
|
||||
static NS_NAMED_LITERAL_CSTRING(kToolkit, "chrome://global/");
|
||||
static NS_NAMED_LITERAL_CSTRING(kBrowser, "chrome://browser/");
|
||||
|
||||
if (aLocationHint == CompartmentPrivate::LocationHintAddon) {
|
||||
if (aLocationHint == RealmPrivate::LocationHintAddon) {
|
||||
// Blacklist some known locations which are clearly not add-on related.
|
||||
if (StringBeginsWith(uristr, kGRE) ||
|
||||
StringBeginsWith(uristr, kToolkit) ||
|
||||
|
@ -249,7 +249,8 @@ TryParseLocationURICandidate(const nsACString& uristr,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool CompartmentPrivate::TryParseLocationURI(CompartmentPrivate::LocationHint aLocationHint,
|
||||
bool
|
||||
RealmPrivate::TryParseLocationURI(RealmPrivate::LocationHint aLocationHint,
|
||||
nsIURI** aURI)
|
||||
{
|
||||
if (!aURI)
|
||||
|
@ -1089,13 +1090,13 @@ GetCompartmentName(JSCompartment* c, nsCString& name, int* anonymizeID,
|
|||
name.AssignLiteral("(unknown)");
|
||||
}
|
||||
|
||||
// If the compartment's location (name) differs from the principal's
|
||||
// script location, append the compartment's location to allow
|
||||
// differentiation of multiple compartments owned by the same principal
|
||||
// (e.g. components owned by the system or null principal).
|
||||
CompartmentPrivate* compartmentPrivate = CompartmentPrivate::Get(c);
|
||||
if (compartmentPrivate) {
|
||||
const nsACString& location = compartmentPrivate->GetLocation();
|
||||
// If the realm's location (name) differs from the principal's script
|
||||
// location, append the realm's location to allow differentiation of
|
||||
// multiple realms owned by the same principal (e.g. components owned
|
||||
// by the system or null principal).
|
||||
RealmPrivate* realmPrivate = RealmPrivate::Get(realm);
|
||||
if (realmPrivate) {
|
||||
const nsACString& location = realmPrivate->GetLocation();
|
||||
if (!location.IsEmpty() && !location.Equals(name)) {
|
||||
name.AppendLiteral(", ");
|
||||
name.Append(location);
|
||||
|
|
|
@ -964,14 +964,14 @@ void
|
|||
SetLocationForGlobal(JSObject* global, const nsACString& location)
|
||||
{
|
||||
MOZ_ASSERT(global);
|
||||
CompartmentPrivate::Get(global)->SetLocation(location);
|
||||
RealmPrivate::Get(global)->SetLocation(location);
|
||||
}
|
||||
|
||||
void
|
||||
SetLocationForGlobal(JSObject* global, nsIURI* locationURI)
|
||||
{
|
||||
MOZ_ASSERT(global);
|
||||
CompartmentPrivate::Get(global)->SetLocationURI(locationURI);
|
||||
RealmPrivate::Get(global)->SetLocationURI(locationURI);
|
||||
}
|
||||
|
||||
} // namespace xpc
|
||||
|
|
|
@ -2834,11 +2834,6 @@ class CompartmentPrivate
|
|||
CompartmentPrivate(const CompartmentPrivate&) = delete;
|
||||
|
||||
public:
|
||||
enum LocationHint {
|
||||
LocationHintRegular,
|
||||
LocationHintAddon
|
||||
};
|
||||
|
||||
explicit CompartmentPrivate(JSCompartment* c);
|
||||
|
||||
~CompartmentPrivate();
|
||||
|
@ -2911,48 +2906,6 @@ public:
|
|||
// by a security wrapper. See XrayWrapper.cpp.
|
||||
bool wrapperDenialWarnings[WrapperDenialTypeCount];
|
||||
|
||||
const nsACString& GetLocation() {
|
||||
if (location.IsEmpty() && locationURI) {
|
||||
|
||||
nsCOMPtr<nsIXPConnectWrappedJS> jsLocationURI =
|
||||
do_QueryInterface(locationURI);
|
||||
if (jsLocationURI) {
|
||||
// We cannot call into JS-implemented nsIURI objects, because
|
||||
// we are iterating over the JS heap at this point.
|
||||
location =
|
||||
NS_LITERAL_CSTRING("<JS-implemented nsIURI location>");
|
||||
} else if (NS_FAILED(locationURI->GetSpec(location))) {
|
||||
location = NS_LITERAL_CSTRING("<unknown location>");
|
||||
}
|
||||
}
|
||||
return location;
|
||||
}
|
||||
bool GetLocationURI(nsIURI** aURI) {
|
||||
return GetLocationURI(LocationHintRegular, aURI);
|
||||
}
|
||||
bool GetLocationURI(LocationHint aLocationHint, nsIURI** aURI) {
|
||||
if (locationURI) {
|
||||
nsCOMPtr<nsIURI> rval = locationURI;
|
||||
rval.forget(aURI);
|
||||
return true;
|
||||
}
|
||||
return TryParseLocationURI(aLocationHint, aURI);
|
||||
}
|
||||
void SetLocation(const nsACString& aLocation) {
|
||||
if (aLocation.IsEmpty())
|
||||
return;
|
||||
if (!location.IsEmpty() || locationURI)
|
||||
return;
|
||||
location = aLocation;
|
||||
}
|
||||
void SetLocationURI(nsIURI* aLocationURI) {
|
||||
if (!aLocationURI)
|
||||
return;
|
||||
if (locationURI)
|
||||
return;
|
||||
locationURI = aLocationURI;
|
||||
}
|
||||
|
||||
JSObject2WrappedJSMap* GetWrappedJSMap() const { return mWrappedJSMap; }
|
||||
void UpdateWeakPointersAfterGC();
|
||||
|
||||
|
@ -2961,11 +2914,7 @@ public:
|
|||
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf);
|
||||
|
||||
private:
|
||||
nsCString location;
|
||||
nsCOMPtr<nsIURI> locationURI;
|
||||
JSObject2WrappedJSMap* mWrappedJSMap;
|
||||
|
||||
bool TryParseLocationURI(LocationHint aType, nsIURI** aURI);
|
||||
};
|
||||
|
||||
bool IsUniversalXPConnectEnabled(JSCompartment* compartment);
|
||||
|
@ -2984,13 +2933,18 @@ CrashIfNotInAutomation()
|
|||
//
|
||||
// Following the ECMAScript spec, a realm contains a global (e.g. an inner
|
||||
// Window) and its associated scripts and objects; a compartment may contain
|
||||
// several same-origin, same-principal realms.
|
||||
// several same-origin realms.
|
||||
class RealmPrivate
|
||||
{
|
||||
RealmPrivate() = delete;
|
||||
RealmPrivate(const RealmPrivate&) = delete;
|
||||
|
||||
public:
|
||||
enum LocationHint {
|
||||
LocationHintRegular,
|
||||
LocationHintAddon
|
||||
};
|
||||
|
||||
explicit RealmPrivate(JS::Realm* realm);
|
||||
|
||||
static RealmPrivate* Get(JS::Realm* realm)
|
||||
|
@ -3015,6 +2969,55 @@ public:
|
|||
// Our XPCWrappedNativeScope. This is non-null if and only if this is an
|
||||
// XPConnect realm.
|
||||
XPCWrappedNativeScope* scope;
|
||||
|
||||
const nsACString& GetLocation() {
|
||||
if (location.IsEmpty() && locationURI) {
|
||||
|
||||
nsCOMPtr<nsIXPConnectWrappedJS> jsLocationURI =
|
||||
do_QueryInterface(locationURI);
|
||||
if (jsLocationURI) {
|
||||
// We cannot call into JS-implemented nsIURI objects, because
|
||||
// we are iterating over the JS heap at this point.
|
||||
location =
|
||||
NS_LITERAL_CSTRING("<JS-implemented nsIURI location>");
|
||||
} else if (NS_FAILED(locationURI->GetSpec(location))) {
|
||||
location = NS_LITERAL_CSTRING("<unknown location>");
|
||||
}
|
||||
}
|
||||
return location;
|
||||
}
|
||||
bool GetLocationURI(LocationHint aLocationHint, nsIURI** aURI) {
|
||||
if (locationURI) {
|
||||
nsCOMPtr<nsIURI> rval = locationURI;
|
||||
rval.forget(aURI);
|
||||
return true;
|
||||
}
|
||||
return TryParseLocationURI(aLocationHint, aURI);
|
||||
}
|
||||
bool GetLocationURI(nsIURI** aURI) {
|
||||
return GetLocationURI(LocationHintRegular, aURI);
|
||||
}
|
||||
|
||||
void SetLocation(const nsACString& aLocation) {
|
||||
if (aLocation.IsEmpty())
|
||||
return;
|
||||
if (!location.IsEmpty() || locationURI)
|
||||
return;
|
||||
location = aLocation;
|
||||
}
|
||||
void SetLocationURI(nsIURI* aLocationURI) {
|
||||
if (!aLocationURI)
|
||||
return;
|
||||
if (locationURI)
|
||||
return;
|
||||
locationURI = aLocationURI;
|
||||
}
|
||||
|
||||
private:
|
||||
nsCString location;
|
||||
nsCOMPtr<nsIURI> locationURI;
|
||||
|
||||
bool TryParseLocationURI(LocationHint aType, nsIURI** aURI);
|
||||
};
|
||||
|
||||
inline XPCWrappedNativeScope*
|
||||
|
|
Загрузка…
Ссылка в новой задаче