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/. */
7 #ifndef mozilla_dom_URLClassifierChild_h
8 #define mozilla_dom_URLClassifierChild_h
10 #include "mozilla/dom/PURLClassifierChild.h"
11 #include "mozilla/dom/PURLClassifierLocalChild.h"
12 #include "mozilla/ipc/URIUtils.h"
13 #include "mozilla/net/UrlClassifierFeatureResult.h"
14 #include "nsIURIClassifier.h"
15 #include "nsIUrlClassifierFeature.h"
17 namespace mozilla::dom
{
19 class URLClassifierChild
: public PURLClassifierChild
{
21 void SetCallback(nsIURIClassifierCallback
* aCallback
) {
22 mCallback
= aCallback
;
25 mozilla::ipc::IPCResult
Recv__delete__(const Maybe
<ClassifierInfo
>& aInfo
,
26 const nsresult
& aResult
) {
27 MOZ_ASSERT(mCallback
);
29 mCallback
->OnClassifyComplete(aResult
, aInfo
.ref().list(),
30 aInfo
.ref().provider(),
31 aInfo
.ref().fullhash());
37 nsCOMPtr
<nsIURIClassifierCallback
> mCallback
;
40 class URLClassifierLocalChild
: public PURLClassifierLocalChild
{
42 void SetFeaturesAndCallback(
43 const nsTArray
<RefPtr
<nsIUrlClassifierFeature
>>& aFeatures
,
44 nsIUrlClassifierFeatureCallback
* aCallback
) {
45 mCallback
= aCallback
;
46 mFeatures
= aFeatures
.Clone();
49 mozilla::ipc::IPCResult
Recv__delete__(
50 nsTArray
<URLClassifierLocalResult
>&& aResults
) {
51 nsTArray
<RefPtr
<nsIUrlClassifierFeatureResult
>> finalResults
;
53 nsTArray
<URLClassifierLocalResult
> results
= std::move(aResults
);
54 for (URLClassifierLocalResult
& result
: results
) {
55 for (nsIUrlClassifierFeature
* feature
: mFeatures
) {
57 nsresult rv
= feature
->GetName(name
);
58 if (NS_WARN_IF(NS_FAILED(rv
))) {
62 if (result
.featureName() != name
) {
66 RefPtr
<nsIURI
> uri
= result
.uri();
67 if (NS_WARN_IF(!uri
)) {
71 RefPtr
<net::UrlClassifierFeatureResult
> r
=
72 new net::UrlClassifierFeatureResult(uri
, feature
,
73 result
.matchingList());
74 finalResults
.AppendElement(r
);
79 mCallback
->OnClassifyComplete(finalResults
);
84 nsCOMPtr
<nsIUrlClassifierFeatureCallback
> mCallback
;
85 nsTArray
<RefPtr
<nsIUrlClassifierFeature
>> mFeatures
;
88 } // namespace mozilla::dom
90 #endif // mozilla_dom_URLClassifierChild_h