dom/ipc/URLClassifierParent.h
author Dorel Luca <dluca@mozilla.com>
Thu, 15 Aug 2019 01:04:46 +0300
changeset 488131 3cf55b7f12f2cb7dfcdbcbcd817d77e298e76fbd
parent 488059 ae221b6288996b15104e52c497e2cae59da9f536
child 488293 a8966ba20267de4cd27a8da1bcb61f39297d4047
permissions -rw-r--r--
Backed out 22 changesets (bug 1231213) for Browser-chrome failures on /workers/remoteworkers/RemoteWorkerChild.cpp Backed out changeset 7e09ad9ceea6 (bug 1231213) Backed out changeset a275eb0b1a19 (bug 1231213) Backed out changeset 906b80778539 (bug 1231213) Backed out changeset 6a40ab6852cb (bug 1231213) Backed out changeset 216591953f97 (bug 1231213) Backed out changeset 1de357bc1921 (bug 1231213) Backed out changeset 8e3fedf6502a (bug 1231213) Backed out changeset 1b9a8b022fce (bug 1231213) Backed out changeset 85df1959eb98 (bug 1231213) Backed out changeset 666bf4260046 (bug 1231213) Backed out changeset 0b03a19a6dc1 (bug 1231213) Backed out changeset 11f010e6d6e7 (bug 1231213) Backed out changeset 6ed55807374f (bug 1231213) Backed out changeset 395062aef2ec (bug 1231213) Backed out changeset bacf8499ba7b (bug 1231213) Backed out changeset bf5d60c7a85a (bug 1231213) Backed out changeset cd434b787ce6 (bug 1231213) Backed out changeset ee4565104217 (bug 1231213) Backed out changeset 581653ef33dd (bug 1231213) Backed out changeset 2d5628a0e52d (bug 1231213) Backed out changeset 3449c2eba4c6 (bug 1231213) Backed out changeset ae221b628899 (bug 1231213)

/* -*- 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_URLClassifierParent_h
#define mozilla_dom_URLClassifierParent_h

#include "mozilla/dom/PContent.h"
#include "mozilla/dom/PURLClassifierParent.h"
#include "mozilla/dom/PURLClassifierLocalParent.h"
#include "nsIURIClassifier.h"
#include "nsIUrlClassifierFeature.h"

namespace mozilla {
namespace dom {

//////////////////////////////////////////////////////////////
// URLClassifierParent

class URLClassifierParent : public nsIURIClassifierCallback,
                            public PURLClassifierParent {
 public:
  NS_DECL_THREADSAFE_ISUPPORTS

  mozilla::ipc::IPCResult StartClassify(nsIPrincipal* aPrincipal,
                                        bool* aSuccess);

  // nsIURIClassifierCallback.
  NS_IMETHOD OnClassifyComplete(nsresult aErrorCode, const nsACString& aList,
                                const nsACString& aProvider,
                                const nsACString& aFullHash) override {
    if (mIPCOpen) {
      ClassifierInfo info = ClassifierInfo(
          nsCString(aList), nsCString(aProvider), nsCString(aFullHash));
      Unused << Send__delete__(this, Some(info), aErrorCode);
    }
    return NS_OK;
  }

  // Custom.
  void ClassificationFailed() {
    if (mIPCOpen) {
      Unused << Send__delete__(this, Nothing(), NS_ERROR_FAILURE);
    }
  }

 private:
  ~URLClassifierParent() = default;

  // Override PURLClassifierParent::ActorDestroy. We seem to unable to
  // override from the base template class.
  void ActorDestroy(ActorDestroyReason aWhy) override { mIPCOpen = false; }

  bool mIPCOpen = true;
};

//////////////////////////////////////////////////////////////
// URLClassifierLocalParent

class URLClassifierLocalParent : public nsIUrlClassifierFeatureCallback,
                                 public PURLClassifierLocalParent {
 public:
  NS_DECL_THREADSAFE_ISUPPORTS

  mozilla::ipc::IPCResult StartClassify(
      nsIURI* aURI, const nsTArray<IPCURLClassifierFeature>& aFeatureNames);

  // nsIUrlClassifierFeatureCallback.
  NS_IMETHOD
  OnClassifyComplete(
      const nsTArray<RefPtr<nsIUrlClassifierFeatureResult>>& aResults) override;

 private:
  ~URLClassifierLocalParent() = default;

  // Override PURLClassifierLocalParent::ActorDestroy.
  void ActorDestroy(ActorDestroyReason aWhy) override { mIPCOpen = false; }

  bool mIPCOpen = true;
};

}  // namespace dom
}  // namespace mozilla

#endif  // mozilla_dom_URLClassifierParent_h