Bug 1932613 - temporarily disable browser_ml_end_to_end.js for permanent failures...
[gecko.git] / gfx / thebes / gfxFontSrcURI.cpp
blob3153d2abce18c4ade8eb43571ef4358cfa674d81
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) {
16 nsresult rv;
17 bool value = false;
18 rv = NS_URIChainHasFlags(aURI, aFlag, &value);
19 return NS_SUCCEEDED(rv) && value;
22 gfxFontSrcURI::gfxFontSrcURI(nsIURI* aURI) : mURI(aURI) {
23 MOZ_ASSERT(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.
27 nsCString scheme;
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?");
41 } else {
42 mSimpleURI = nullptr;
45 if (!mSimpleURI) {
46 mURI->GetSpec(mSpec);
49 mHash = nsURIHashKey::HashKey(mURI);
52 gfxFontSrcURI::~gfxFontSrcURI() = default;
54 void gfxFontSrcURI::EnsureInitialized() {
55 MOZ_ASSERT(NS_IsMainThread() || mozilla::ServoStyleSet::IsInServoTraversal());
57 if (mInitialized) {
58 return;
61 mInheritsSecurityContext =
62 HasFlag(mURI, nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT);
63 mSyncLoadIsOK = HasFlag(mURI, nsIProtocolHandler::URI_SYNC_LOAD_IS_OK);
64 mInitialized = true;
67 bool gfxFontSrcURI::Equals(gfxFontSrcURI* aOther) {
68 if (mSimpleURI) {
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
75 // quite large).
77 nsCString thisScheme;
78 mSimpleURI->GetScheme(thisScheme);
80 nsCString otherScheme;
81 if (!StringBeginsWith(aOther->mSpec, thisScheme)) {
82 return false;
86 nsCString thisSpec;
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) {
99 if (mSimpleURI) {
100 return mSimpleURI->GetSpec(aResult);
103 aResult = mSpec;
104 return NS_OK;
107 nsCString gfxFontSrcURI::GetSpecOrDefault() {
108 if (mSimpleURI) {
109 return mSimpleURI->GetSpecOrDefault();
112 return mSpec;