Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/thebes/gfxFontSrcURI.cpp
Line
Count
Source (jump to first uncovered line)
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/. */
5
6
#include "gfxFontSrcURI.h"
7
8
#include "nsIProtocolHandler.h"
9
#include "nsProxyRelease.h"
10
#include "nsNetUtil.h"
11
#include "nsSimpleURI.h"
12
#include "nsURIHashKey.h"
13
14
static bool
15
HasFlag(nsIURI* aURI, uint32_t aFlag)
16
0
{
17
0
  nsresult rv;
18
0
  bool value = false;
19
0
  rv = NS_URIChainHasFlags(aURI, aFlag, &value);
20
0
  return NS_SUCCEEDED(rv) && value;
21
0
}
22
23
gfxFontSrcURI::gfxFontSrcURI(nsIURI* aURI)
24
0
{
25
0
  MOZ_ASSERT(NS_IsMainThread());
26
0
  MOZ_ASSERT(aURI);
27
0
28
0
  mURI = aURI;
29
0
30
0
  // If we have a data: URI, we know that it is backed by an nsSimpleURI,
31
0
  // and that we don't need to serialize it ahead of time.
32
0
  nsCString scheme;
33
0
  mURI->GetScheme(scheme);
34
0
35
0
  if (scheme.EqualsLiteral("data")) {
36
0
    // We know that nsSimpleURI::From returns us a pointer to the same object,
37
0
    // and we hold a strong reference to the object in mURI, so no need to
38
0
    // hold it strongly here as well.  (And we'd have to
39
0
    // NS_ReleaseOnMainThreadSystemGroup it in our destructor anyway.)
40
0
    RefPtr<mozilla::net::nsSimpleURI> simpleURI =
41
0
      mozilla::net::nsSimpleURI::From(aURI);
42
0
    mSimpleURI = simpleURI;
43
0
44
0
    NS_ASSERTION(mSimpleURI, "Why aren't our data: URLs backed by nsSimpleURI?");
45
0
  } else {
46
0
    mSimpleURI = nullptr;
47
0
  }
48
0
49
0
  if (!mSimpleURI) {
50
0
    mURI->GetSpec(mSpec);
51
0
  }
52
0
53
0
  mHash = nsURIHashKey::HashKey(mURI);
54
0
55
0
  mInheritsSecurityContext =
56
0
    HasFlag(aURI, nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT);
57
0
  mSyncLoadIsOK =
58
0
    HasFlag(aURI, nsIProtocolHandler::URI_SYNC_LOAD_IS_OK);
59
0
}
60
61
gfxFontSrcURI::~gfxFontSrcURI()
62
0
{
63
0
  NS_ReleaseOnMainThreadSystemGroup("gfxFontSrcURI::mURI", mURI.forget());
64
0
}
65
66
bool
67
gfxFontSrcURI::Equals(gfxFontSrcURI* aOther)
68
0
{
69
0
  if (mSimpleURI) {
70
0
    if (aOther->mSimpleURI) {
71
0
      return mSimpleURI->Equals(aOther->mSimpleURI);
72
0
    }
73
0
74
0
    // The two URIs are probably different.  Do a quick check on the
75
0
    // schemes before deciding to serialize mSimpleURI (which might be
76
0
    // quite large).
77
0
    {
78
0
      nsCString thisScheme;
79
0
      mSimpleURI->GetScheme(thisScheme);
80
0
81
0
      nsCString otherScheme;
82
0
      if (!StringBeginsWith(aOther->mSpec, thisScheme,
83
0
                            nsDefaultCStringComparator())) {
84
0
        return false;
85
0
      }
86
0
    }
87
0
88
0
    nsCString thisSpec;
89
0
    mSimpleURI->GetSpec(thisSpec);
90
0
    return thisSpec == aOther->mSpec;
91
0
  }
92
0
93
0
  if (aOther->mSimpleURI) {
94
0
    return aOther->Equals(this);
95
0
  }
96
0
97
0
  return mSpec == aOther->mSpec;
98
0
}
99
100
nsresult
101
gfxFontSrcURI::GetSpec(nsACString& aResult)
102
0
{
103
0
  if (mSimpleURI) {
104
0
    return mSimpleURI->GetSpec(aResult);
105
0
  }
106
0
107
0
  aResult = mSpec;
108
0
  return NS_OK;
109
0
}
110
111
nsCString
112
gfxFontSrcURI::GetSpecOrDefault()
113
0
{
114
0
  if (mSimpleURI) {
115
0
    return mSimpleURI->GetSpecOrDefault();
116
0
  }
117
0
118
0
  return mSpec;
119
0
}