Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/toolkit/components/alerts/nsAlertsUtils.cpp
Line
Count
Source (jump to first uncovered line)
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5
#include "nsAlertsUtils.h"
6
7
#include "nsCOMPtr.h"
8
#include "nsContentUtils.h"
9
#include "nsIStringBundle.h"
10
#include "nsIURI.h"
11
#include "nsString.h"
12
13
/* static */
14
bool
15
nsAlertsUtils::IsActionablePrincipal(nsIPrincipal* aPrincipal)
16
0
{
17
0
  return aPrincipal &&
18
0
         !nsContentUtils::IsSystemOrExpandedPrincipal(aPrincipal) &&
19
0
         !aPrincipal->GetIsNullPrincipal();
20
0
}
21
22
/* static */
23
void
24
nsAlertsUtils::GetSourceHostPort(nsIPrincipal* aPrincipal,
25
                                 nsAString& aHostPort)
26
0
{
27
0
  if (!IsActionablePrincipal(aPrincipal)) {
28
0
    return;
29
0
  }
30
0
  nsCOMPtr<nsIURI> principalURI;
31
0
  if (NS_WARN_IF(NS_FAILED(
32
0
      aPrincipal->GetURI(getter_AddRefs(principalURI))))) {
33
0
    return;
34
0
  }
35
0
  if (!principalURI) {
36
0
    return;
37
0
  }
38
0
  nsAutoCString hostPort;
39
0
  if (NS_WARN_IF(NS_FAILED(principalURI->GetHostPort(hostPort)))) {
40
0
    return;
41
0
  }
42
0
  CopyUTF8toUTF16(hostPort, aHostPort);
43
0
}