Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/ipc/URLClassifierParent.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "URLClassifierParent.h"
8
#include "nsComponentManagerUtils.h"
9
#include "mozilla/Unused.h"
10
11
using namespace mozilla;
12
using namespace mozilla::dom;
13
14
/////////////////////////////////////////////////////////////////////
15
//URLClassifierParent.
16
17
NS_IMPL_ISUPPORTS(URLClassifierParent, nsIURIClassifierCallback)
18
19
mozilla::ipc::IPCResult
20
URLClassifierParent::StartClassify(nsIPrincipal* aPrincipal,
21
                                   bool aUseTrackingProtection,
22
                                   bool* aSuccess)
23
0
{
24
0
  *aSuccess = false;
25
0
  nsresult rv = NS_OK;
26
0
  // Note that in safe mode, the URL classifier service isn't available, so we
27
0
  // should handle the service not being present gracefully.
28
0
  nsCOMPtr<nsIURIClassifier> uriClassifier =
29
0
    do_GetService(NS_URICLASSIFIERSERVICE_CONTRACTID, &rv);
30
0
  if (NS_SUCCEEDED(rv)) {
31
0
    rv = uriClassifier->Classify(aPrincipal, nullptr, aUseTrackingProtection,
32
0
                                 this, aSuccess);
33
0
  }
34
0
  if (NS_FAILED(rv) || !*aSuccess) {
35
0
    // We treat the case where we fail to classify and the case where the
36
0
    // classifier returns successfully but doesn't perform a lookup as the
37
0
    // classification not yielding any results, so we just kill the child actor
38
0
    // without ever calling out callback in both cases.
39
0
    // This means that code using this in the child process will only get a hit
40
0
    // on its callback if some classification actually happens.
41
0
    *aSuccess = false;
42
0
    ClassificationFailed();
43
0
  }
44
0
  return IPC_OK();
45
0
}
46
47
void
48
URLClassifierParent::ActorDestroy(ActorDestroyReason aWhy)
49
0
{
50
0
  mIPCOpen = false;
51
0
}
52
53
/////////////////////////////////////////////////////////////////////
54
//URLClassifierLocalParent.
55
56
NS_IMPL_ISUPPORTS(URLClassifierLocalParent, nsIURIClassifierCallback)
57
58
mozilla::ipc::IPCResult
59
URLClassifierLocalParent::StartClassify(nsIURI* aURI, const nsACString& aTables)
60
0
{
61
0
  nsresult rv = NS_OK;
62
0
  // Note that in safe mode, the URL classifier service isn't available, so we
63
0
  // should handle the service not being present gracefully.
64
0
  nsCOMPtr<nsIURIClassifier> uriClassifier =
65
0
    do_GetService(NS_URICLASSIFIERSERVICE_CONTRACTID, &rv);
66
0
  if (NS_SUCCEEDED(rv)) {
67
0
    MOZ_ASSERT(aURI);
68
0
    rv = uriClassifier->AsyncClassifyLocalWithTables(aURI, aTables,
69
0
                                                     nsTArray<nsCString>(),
70
0
                                                     nsTArray<nsCString>(),
71
0
                                                     this);
72
0
  }
73
0
  if (NS_FAILED(rv)) {
74
0
    // Cannot do ClassificationFailed() because the child side
75
0
    // is expecting a callback. Only the second parameter will
76
0
    // be used, which is the "matched list". We treat "unable
77
0
    // to classify" as "not on any list".
78
0
    OnClassifyComplete(NS_OK, EmptyCString(), EmptyCString(), EmptyCString());
79
0
  }
80
0
  return IPC_OK();
81
0
}
82
83
void
84
URLClassifierLocalParent::ActorDestroy(ActorDestroyReason aWhy)
85
0
{
86
0
  mIPCOpen = false;
87
0
}