tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

WindowsLocationProvider.h (2487B)


      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_WindowsLocationProvider_h__
      8 #define mozilla_dom_WindowsLocationProvider_h__
      9 
     10 #include "mozilla/MozPromise.h"
     11 #include "nsCOMPtr.h"
     12 #include "nsIGeolocationProvider.h"
     13 
     14 class MLSFallback;
     15 
     16 namespace mozilla::dom {
     17 
     18 class WindowsLocationParent;
     19 
     20 // Uses a PWindowsLocation actor to subscribe to geolocation updates from the
     21 // Windows utility process and falls back to MLS when it is not available or
     22 // fails.
     23 class WindowsLocationProvider final : public nsIGeolocationProvider {
     24 public:
     25  NS_DECL_ISUPPORTS
     26  NS_DECL_NSIGEOLOCATIONPROVIDER
     27 
     28  WindowsLocationProvider();
     29 
     30 private:
     31  friend WindowsLocationParent;
     32 
     33  ~WindowsLocationProvider();
     34 
     35  nsresult CreateAndWatchMLSProvider(nsIGeolocationUpdate* aCallback);
     36  void CancelMLSProvider();
     37 
     38  void MaybeCreateLocationActor();
     39  void ReleaseUtilityProcess();
     40 
     41  // These methods either send the message on the existing actor or queue
     42  // the messages to be sent (in order) once the actor exists.
     43  bool SendStartup();
     44  bool SendRegisterForReport(nsIGeolocationUpdate* aCallback);
     45  bool SendUnregisterForReport();
     46  bool SendSetHighAccuracy(bool aEnable);
     47  bool Send__delete__();
     48 
     49  void RecvUpdate(RefPtr<nsIDOMGeoPosition> aGeoPosition);
     50  // See bug 1539864 for MOZ_CAN_RUN_SCRIPT_BOUNDARY justification.
     51  MOZ_CAN_RUN_SCRIPT_BOUNDARY void RecvFailed(uint16_t err);
     52 
     53  // The utility process actor has ended its connection, either successfully
     54  // or with an error.
     55  void ActorStopped();
     56 
     57  // Run fn once actor is ready to send messages, which may be immediately.
     58  template <typename Fn>
     59  bool WhenActorIsReady(Fn&& fn);
     60 
     61  RefPtr<MLSFallback> mMLSProvider;
     62 
     63  nsCOMPtr<nsIGeolocationUpdate> mCallback;
     64 
     65  using WindowsLocationPromise =
     66      MozPromise<RefPtr<WindowsLocationParent>, bool, false>;
     67 
     68  // Before the utility process exists, we have a promise that we will get our
     69  // location actor.  mActor and mActorPromise are never both set.
     70  RefPtr<WindowsLocationPromise> mActorPromise;
     71  RefPtr<WindowsLocationParent> mActor;
     72 
     73  bool mWatching = false;
     74  bool mEverUpdated = false;
     75 };
     76 
     77 }  // namespace mozilla::dom
     78 
     79 #endif  // mozilla_dom_WindowsLocationProvider_h__