2016-11-19 00:54:57 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_URLClassifierChild_h
|
|
|
|
#define mozilla_dom_URLClassifierChild_h
|
|
|
|
|
|
|
|
#include "mozilla/dom/PURLClassifierChild.h"
|
2017-04-07 09:15:16 +03:00
|
|
|
#include "mozilla/dom/PURLClassifierLocalChild.h"
|
2019-01-04 16:45:42 +03:00
|
|
|
#include "mozilla/ipc/URIUtils.h"
|
2018-12-14 14:40:17 +03:00
|
|
|
#include "mozilla/net/UrlClassifierFeatureResult.h"
|
2016-11-19 00:54:57 +03:00
|
|
|
#include "nsIURIClassifier.h"
|
2018-12-14 14:40:17 +03:00
|
|
|
#include "nsIUrlClassifierFeature.h"
|
2016-11-19 00:54:57 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2018-12-14 14:40:17 +03:00
|
|
|
class URLClassifierChild : public PURLClassifierChild {
|
2017-04-07 09:15:16 +03:00
|
|
|
public:
|
2016-11-19 00:54:57 +03:00
|
|
|
void SetCallback(nsIURIClassifierCallback* aCallback) {
|
|
|
|
mCallback = aCallback;
|
|
|
|
}
|
2017-04-07 09:15:16 +03:00
|
|
|
|
2019-03-19 12:31:07 +03:00
|
|
|
mozilla::ipc::IPCResult Recv__delete__(const Maybe<ClassifierInfo>& aInfo,
|
2020-02-18 23:46:21 +03:00
|
|
|
const nsresult& aResult) {
|
2017-04-07 09:15:16 +03:00
|
|
|
MOZ_ASSERT(mCallback);
|
2019-03-19 12:31:07 +03:00
|
|
|
if (aInfo.isSome()) {
|
|
|
|
mCallback->OnClassifyComplete(aResult, aInfo.ref().list(),
|
|
|
|
aInfo.ref().provider(),
|
|
|
|
aInfo.ref().fullhash());
|
2017-04-07 09:15:16 +03:00
|
|
|
}
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
2016-11-19 00:54:57 +03:00
|
|
|
|
2017-04-07 09:15:16 +03:00
|
|
|
private:
|
2016-11-19 00:54:57 +03:00
|
|
|
nsCOMPtr<nsIURIClassifierCallback> mCallback;
|
|
|
|
};
|
|
|
|
|
2018-12-14 14:40:17 +03:00
|
|
|
class URLClassifierLocalChild : public PURLClassifierLocalChild {
|
|
|
|
public:
|
|
|
|
void SetFeaturesAndCallback(
|
|
|
|
const nsTArray<RefPtr<nsIUrlClassifierFeature>>& aFeatures,
|
|
|
|
nsIUrlClassifierFeatureCallback* aCallback) {
|
|
|
|
mCallback = aCallback;
|
2020-04-30 12:37:05 +03:00
|
|
|
mFeatures = aFeatures.Clone();
|
2018-12-14 14:40:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult Recv__delete__(
|
2020-02-18 23:46:21 +03:00
|
|
|
nsTArray<URLClassifierLocalResult>&& aResults) {
|
2018-12-14 14:40:17 +03:00
|
|
|
nsTArray<RefPtr<nsIUrlClassifierFeatureResult>> finalResults;
|
|
|
|
|
|
|
|
nsTArray<URLClassifierLocalResult> results = std::move(aResults);
|
|
|
|
for (URLClassifierLocalResult& result : results) {
|
|
|
|
for (nsIUrlClassifierFeature* feature : mFeatures) {
|
|
|
|
nsAutoCString name;
|
|
|
|
nsresult rv = feature->GetName(name);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result.featureName() != name) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-01-04 16:45:42 +03:00
|
|
|
RefPtr<nsIURI> uri = result.uri();
|
|
|
|
if (NS_WARN_IF(!uri)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-12-14 14:40:17 +03:00
|
|
|
RefPtr<net::UrlClassifierFeatureResult> r =
|
2019-01-04 16:45:42 +03:00
|
|
|
new net::UrlClassifierFeatureResult(uri, feature,
|
|
|
|
result.matchingList());
|
2018-12-14 14:40:17 +03:00
|
|
|
finalResults.AppendElement(r);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mCallback->OnClassifyComplete(finalResults);
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIUrlClassifierFeatureCallback> mCallback;
|
|
|
|
nsTArray<RefPtr<nsIUrlClassifierFeature>> mFeatures;
|
|
|
|
};
|
2017-04-07 09:15:16 +03:00
|
|
|
|
2016-11-19 00:54:57 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_URLClassifierChild_h
|