1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "gfxFontSrcURI.h"
8 #include "mozilla/ServoStyleSet.h"
9 #include "nsIProtocolHandler.h"
10 #include "nsProxyRelease.h"
11 #include "nsNetUtil.h"
12 #include "nsSimpleURI.h"
13 #include "nsURIHashKey.h"
15 static bool HasFlag(nsIURI
* aURI
, uint32_t aFlag
) {
18 rv
= NS_URIChainHasFlags(aURI
, aFlag
, &value
);
19 return NS_SUCCEEDED(rv
) && value
;
22 gfxFontSrcURI::gfxFontSrcURI(nsIURI
* aURI
) : mURI(aURI
) {
25 // If we have a data: URI, we know that it is backed by an nsSimpleURI,
26 // and that we don't need to serialize it ahead of time.
28 mURI
->GetScheme(scheme
);
30 if (scheme
.EqualsLiteral("data")) {
31 // We know that nsSimpleURI::From returns us a pointer to the same object,
32 // and we hold a strong reference to the object in mURI, so no need to
33 // hold it strongly here as well. (And we'd have to
34 // NS_ReleaseOnMainThread it in our destructor anyway.)
35 RefPtr
<mozilla::net::nsSimpleURI
> simpleURI
=
36 mozilla::net::nsSimpleURI::From(aURI
);
37 mSimpleURI
= simpleURI
;
39 NS_ASSERTION(mSimpleURI
,
40 "Why aren't our data: URLs backed by nsSimpleURI?");
49 mHash
= nsURIHashKey::HashKey(mURI
);
52 gfxFontSrcURI::~gfxFontSrcURI() = default;
54 void gfxFontSrcURI::EnsureInitialized() {
55 MOZ_ASSERT(NS_IsMainThread() || mozilla::ServoStyleSet::IsInServoTraversal());
61 mInheritsSecurityContext
=
62 HasFlag(mURI
, nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT
);
63 mSyncLoadIsOK
= HasFlag(mURI
, nsIProtocolHandler::URI_SYNC_LOAD_IS_OK
);
67 bool gfxFontSrcURI::Equals(gfxFontSrcURI
* aOther
) {
69 if (aOther
->mSimpleURI
) {
70 return mSimpleURI
->Equals(aOther
->mSimpleURI
);
73 // The two URIs are probably different. Do a quick check on the
74 // schemes before deciding to serialize mSimpleURI (which might be
78 mSimpleURI
->GetScheme(thisScheme
);
80 nsCString otherScheme
;
81 if (!StringBeginsWith(aOther
->mSpec
, thisScheme
)) {
87 mSimpleURI
->GetSpec(thisSpec
);
88 return thisSpec
== aOther
->mSpec
;
91 if (aOther
->mSimpleURI
) {
92 return aOther
->Equals(this);
95 return mSpec
== aOther
->mSpec
;
98 nsresult
gfxFontSrcURI::GetSpec(nsACString
& aResult
) {
100 return mSimpleURI
->GetSpec(aResult
);
107 nsCString
gfxFontSrcURI::GetSpecOrDefault() {
109 return mSimpleURI
->GetSpecOrDefault();