gecko-dev/dom/ipc/URLClassifierParent.cpp
Thomas Nguyen 65d9ef988a Bug 1288633 - Add more information when an URL matches Safe Browsing list. r=dragana,francois
MozReview-Commit-ID: 6u0dUOB838F

--HG--
extra : rebase_source : 8800e60e6a3b787f1ebaeafb48057e3a3d509468
2017-02-21 09:46:36 +08:00

74 lines
2.4 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;
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, 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();
}
nsresult
URLClassifierParent::OnClassifyComplete(nsresult aErrorCode,
const nsACString& aList,
const nsACString& aProvider,
const nsACString& aPrefix)
{
if (mIPCOpen) {
ClassifierInfo info;
info.list() = aList;
info.prefix() = aPrefix;
info.provider() = aProvider;
Unused << Send__delete__(this, info, aErrorCode);
}
return NS_OK;
}
void
URLClassifierParent::ClassificationFailed()
{
if (mIPCOpen) {
Unused << Send__delete__(this, void_t(), NS_ERROR_FAILURE);
}
}
void
URLClassifierParent::ActorDestroy(ActorDestroyReason aWhy)
{
mIPCOpen = false;
}