Backed out changeset 1d9301697aa0 (bug 1887752) for causing failures on browser_all_f...
[gecko.git] / dom / ipc / URLClassifierChild.h
blobb5f0537ddca9c0421648c9e3b3aad9c174bbc76a
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 {
20 public:
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);
28 if (aInfo.isSome()) {
29 mCallback->OnClassifyComplete(aResult, aInfo.ref().list(),
30 aInfo.ref().provider(),
31 aInfo.ref().fullhash());
33 return IPC_OK();
36 private:
37 nsCOMPtr<nsIURIClassifierCallback> mCallback;
40 class URLClassifierLocalChild : public PURLClassifierLocalChild {
41 public:
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) {
56 nsAutoCString name;
57 nsresult rv = feature->GetName(name);
58 if (NS_WARN_IF(NS_FAILED(rv))) {
59 continue;
62 if (result.featureName() != name) {
63 continue;
66 RefPtr<nsIURI> uri = result.uri();
67 if (NS_WARN_IF(!uri)) {
68 continue;
71 RefPtr<net::UrlClassifierFeatureResult> r =
72 new net::UrlClassifierFeatureResult(uri, feature,
73 result.matchingList());
74 finalResults.AppendElement(r);
75 break;
79 mCallback->OnClassifyComplete(finalResults);
80 return IPC_OK();
83 private:
84 nsCOMPtr<nsIUrlClassifierFeatureCallback> mCallback;
85 nsTArray<RefPtr<nsIUrlClassifierFeature>> mFeatures;
88 } // namespace mozilla::dom
90 #endif // mozilla_dom_URLClassifierChild_h