LoginDetectionService.h (1929B)
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 file, 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_dom_LoginDetectionService_h 8 #define mozilla_dom_LoginDetectionService_h 9 10 #include "mozilla/Logging.h" 11 #include "mozilla/Preferences.h" 12 #include "nsILoginDetectionService.h" 13 #include "nsILoginManager.h" 14 #include "nsIObserver.h" 15 #include "nsIObserverService.h" 16 #include "nsWeakReference.h" 17 18 namespace mozilla::dom { 19 20 /** 21 * Detect whether the user is 'possibly' logged in to a site, and add the 22 * HighValue permission to the permission manager. We say 'possibly' because 23 * the detection is done in a very loose way. For example, for sites that have 24 * an associated login stored in the password manager are considered `logged in` 25 * by the service, which is not always true in terms of whether the users is 26 * really logged in to the site. 27 */ 28 class LoginDetectionService final : public nsILoginDetectionService, 29 public nsILoginSearchCallback, 30 public nsIObserver, 31 public nsSupportsWeakReference { 32 public: 33 NS_DECL_ISUPPORTS 34 NS_DECL_NSILOGINDETECTIONSERVICE 35 NS_DECL_NSILOGINSEARCHCALLBACK 36 NS_DECL_NSIOBSERVER 37 38 static already_AddRefed<LoginDetectionService> GetSingleton(); 39 40 void MaybeStartMonitoring(); 41 42 private: 43 LoginDetectionService(); 44 virtual ~LoginDetectionService(); 45 46 // Fetch saved logins from the password manager. 47 void FetchLogins(); 48 49 void RegisterObserver(); 50 void UnregisterObserver(); 51 52 nsCOMPtr<nsIObserverService> mObs; 53 54 // Used by testcase to make sure logins are fetched. 55 bool mIsLoginsLoaded; 56 }; 57 58 } // namespace mozilla::dom 59 60 #endif