Bug 1901387 - Part 1: Ensure URLInfo is safe to use OMT, r=extension-reviewers,robwu

Previously accessing Scheme() on a URLInfo was main-thread-only. As more
extension methods are used OMT, this needs to be switched to the threadsafe
NS_Atomize method instead.

Differential Revision: https://phabricator.services.mozilla.com/D215024
This commit is contained in:
Nika Layzell 2024-06-28 17:34:07 +00:00
parent ecd9936d55
commit d189a217e9
2 changed files with 4 additions and 1 deletions

View file

@ -119,7 +119,7 @@ nsAtom* URLInfo::Scheme() const {
if (!mScheme) { if (!mScheme) {
nsCString scheme; nsCString scheme;
if (NS_SUCCEEDED(mURI->GetScheme(scheme))) { if (NS_SUCCEEDED(mURI->GetScheme(scheme))) {
mScheme = NS_AtomizeMainThread(NS_ConvertASCIItoUTF16(scheme)); mScheme = NS_Atomize(scheme);
} }
} }
return mScheme; return mScheme;
@ -196,6 +196,7 @@ bool URLInfo::InheritsPrincipal() const {
} }
bool URLInfo::IsNonOpaqueURL() const { bool URLInfo::IsNonOpaqueURL() const {
MOZ_ASSERT(NS_IsMainThread());
if (!mIsNonOpaqueURL.isSome()) { if (!mIsNonOpaqueURL.isSome()) {
RefPtr<AtomSet> nonOpaqueSchemes = NonOpaqueSchemes(); RefPtr<AtomSet> nonOpaqueSchemes = NonOpaqueSchemes();
mIsNonOpaqueURL.emplace(nonOpaqueSchemes->Contains(Scheme())); mIsNonOpaqueURL.emplace(nonOpaqueSchemes->Contains(Scheme()));

View file

@ -112,6 +112,8 @@ class URLInfo final {
// that document were to have an opaque origin (null principal). // that document were to have an opaque origin (null principal).
// These URLs are more verbose than the precursor (origin) of a null // These URLs are more verbose than the precursor (origin) of a null
// principal, and therefore preferred for matching purposes. // principal, and therefore preferred for matching purposes.
//
// NOTE: This method is main-thread only
bool IsNonOpaqueURL() const; bool IsNonOpaqueURL() const;
private: private: