URLClassifierParent.h (3645B)
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/. */ 6 7 #ifndef mozilla_dom_URLClassifierParent_h 8 #define mozilla_dom_URLClassifierParent_h 9 10 #include "mozilla/dom/PContent.h" 11 #include "mozilla/dom/PURLClassifierLocalByNameParent.h" 12 #include "mozilla/dom/PURLClassifierLocalParent.h" 13 #include "mozilla/dom/PURLClassifierParent.h" 14 #include "nsIURIClassifier.h" 15 #include "nsIUrlClassifierFeature.h" 16 17 namespace mozilla::dom { 18 19 class IPCURLClassifierFeature; 20 21 ////////////////////////////////////////////////////////////// 22 // URLClassifierParent 23 24 class URLClassifierParent : public nsIURIClassifierCallback, 25 public PURLClassifierParent { 26 public: 27 NS_DECL_THREADSAFE_ISUPPORTS 28 29 mozilla::ipc::IPCResult StartClassify(nsIPrincipal* aPrincipal, 30 bool* aSuccess); 31 32 // nsIURIClassifierCallback. 33 NS_IMETHOD OnClassifyComplete(nsresult aErrorCode, const nsACString& aList, 34 const nsACString& aProvider, 35 const nsACString& aFullHash) override { 36 if (mIPCOpen) { 37 ClassifierInfo info = ClassifierInfo( 38 nsCString(aList), nsCString(aProvider), nsCString(aFullHash)); 39 (void)Send__delete__(this, Some(info), aErrorCode); 40 } 41 return NS_OK; 42 } 43 44 // Custom. 45 void ClassificationFailed() { 46 if (mIPCOpen) { 47 (void)Send__delete__(this, Nothing(), NS_ERROR_FAILURE); 48 } 49 } 50 51 private: 52 ~URLClassifierParent() = default; 53 54 // Override PURLClassifierParent::ActorDestroy. We seem to unable to 55 // override from the base template class. 56 void ActorDestroy(ActorDestroyReason aWhy) override { mIPCOpen = false; } 57 58 bool mIPCOpen = true; 59 }; 60 61 ////////////////////////////////////////////////////////////// 62 // URLClassifierLocalParent 63 64 class URLClassifierLocalParent : public nsIUrlClassifierFeatureCallback, 65 public PURLClassifierLocalParent { 66 public: 67 NS_DECL_THREADSAFE_ISUPPORTS 68 69 mozilla::ipc::IPCResult StartClassify( 70 nsIURI* aURI, const nsTArray<IPCURLClassifierFeature>& aFeatureNames); 71 72 // nsIUrlClassifierFeatureCallback. 73 NS_IMETHOD 74 OnClassifyComplete( 75 const nsTArray<RefPtr<nsIUrlClassifierFeatureResult>>& aResults) override; 76 77 private: 78 ~URLClassifierLocalParent() = default; 79 80 // Override PURLClassifierLocalParent::ActorDestroy. 81 void ActorDestroy(ActorDestroyReason aWhy) override { mIPCOpen = false; } 82 83 bool mIPCOpen = true; 84 }; 85 86 ////////////////////////////////////////////////////////////// 87 // URLClassifierLocalByNameParent 88 89 class URLClassifierLocalByNameParent : public nsIUrlClassifierFeatureCallback, 90 public PURLClassifierLocalByNameParent { 91 public: 92 NS_DECL_THREADSAFE_ISUPPORTS 93 94 mozilla::ipc::IPCResult StartClassify( 95 nsIURI* aURI, const nsTArray<IPCURLClassifierFeature>& aFeatureNames, 96 nsIUrlClassifierFeature::listType aListType); 97 98 // nsIUrlClassifierFeatureCallback. 99 NS_IMETHOD 100 OnClassifyComplete( 101 const nsTArray<RefPtr<nsIUrlClassifierFeatureResult>>& aResults) override; 102 103 private: 104 ~URLClassifierLocalByNameParent() = default; 105 106 // Override PURLClassifierLocalParent::ActorDestroy. 107 void ActorDestroy(ActorDestroyReason aWhy) override { mIPCOpen = false; } 108 109 bool mIPCOpen = true; 110 }; 111 112 } // namespace mozilla::dom 113 114 #endif // mozilla_dom_URLClassifierParent_h