mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-03 02:25:34 +00:00
eec96acbf0
We add a new "on-off" protocol PURLClassifierLocal which calls nsIURIClassifier.asyncClassifyLocalWithTables on construction and calls back on destruction. Pretty much the same design as PURLClassifier. In order to avoid code duplication, the actor implementation is templatized and |MaybeInfo| in PURLClassifier.ipdl is moved around. Test case is included and the custom event target is not in place for labelling. The custom event target will be done in Bug 1353701. MozReview-Commit-ID: IdHYgdnBV7S --HG-- extra : rebase_source : ab1c896305b9f76cab13a92c9bd88c2d356aacb7
85 lines
3.0 KiB
C++
85 lines
3.0 KiB
C++
/* -*- 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/. */
|
|
|
|
#include "URLClassifierParent.h"
|
|
#include "nsComponentManagerUtils.h"
|
|
#include "mozilla/Unused.h"
|
|
|
|
using namespace mozilla;
|
|
using namespace mozilla::dom;
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
//URLClassifierParent.
|
|
|
|
NS_IMPL_ISUPPORTS(URLClassifierParent, nsIURIClassifierCallback)
|
|
|
|
mozilla::ipc::IPCResult
|
|
URLClassifierParent::StartClassify(nsIPrincipal* aPrincipal,
|
|
bool aUseTrackingProtection,
|
|
bool* aSuccess)
|
|
{
|
|
*aSuccess = false;
|
|
nsresult rv = NS_OK;
|
|
// Note that in safe mode, the URL classifier service isn't available, so we
|
|
// should handle the service not being present gracefully.
|
|
nsCOMPtr<nsIURIClassifier> uriClassifier =
|
|
do_GetService(NS_URICLASSIFIERSERVICE_CONTRACTID, &rv);
|
|
if (NS_SUCCEEDED(rv)) {
|
|
rv = uriClassifier->Classify(aPrincipal, nullptr, aUseTrackingProtection,
|
|
this, aSuccess);
|
|
}
|
|
if (NS_FAILED(rv) || !*aSuccess) {
|
|
// We treat the case where we fail to classify and the case where the
|
|
// classifier returns successfully but doesn't perform a lookup as the
|
|
// classification not yielding any results, so we just kill the child actor
|
|
// without ever calling out callback in both cases.
|
|
// This means that code using this in the child process will only get a hit
|
|
// on its callback if some classification actually happens.
|
|
*aSuccess = false;
|
|
ClassificationFailed();
|
|
}
|
|
return IPC_OK();
|
|
}
|
|
|
|
void
|
|
URLClassifierParent::ActorDestroy(ActorDestroyReason aWhy)
|
|
{
|
|
mIPCOpen = false;
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
//URLClassifierLocalParent.
|
|
|
|
NS_IMPL_ISUPPORTS(URLClassifierLocalParent, nsIURIClassifierCallback)
|
|
|
|
mozilla::ipc::IPCResult
|
|
URLClassifierLocalParent::StartClassify(nsIURI* aURI, const nsACString& aTables)
|
|
{
|
|
nsresult rv = NS_OK;
|
|
// Note that in safe mode, the URL classifier service isn't available, so we
|
|
// should handle the service not being present gracefully.
|
|
nsCOMPtr<nsIURIClassifier> uriClassifier =
|
|
do_GetService(NS_URICLASSIFIERSERVICE_CONTRACTID, &rv);
|
|
if (NS_SUCCEEDED(rv)) {
|
|
MOZ_ASSERT(aURI);
|
|
rv = uriClassifier->AsyncClassifyLocalWithTables(aURI, aTables, this);
|
|
}
|
|
if (NS_FAILED(rv)) {
|
|
// Cannot do ClassificationFailed() because the child side
|
|
// is expecting a callback. Only the second parameter will
|
|
// be used, which is the "matched list". We treat "unable
|
|
// to classify" as "not on any list".
|
|
OnClassifyComplete(NS_OK, EmptyCString(), EmptyCString(), EmptyCString());
|
|
}
|
|
return IPC_OK();
|
|
}
|
|
|
|
void
|
|
URLClassifierLocalParent::ActorDestroy(ActorDestroyReason aWhy)
|
|
{
|
|
mIPCOpen = false;
|
|
}
|