tor-browser

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

RemoteImageProtocolHandler.h (1383B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #ifndef mozilla_image_remote_RemoteImageProtocolHandler_h
      7 #define mozilla_image_remote_RemoteImageProtocolHandler_h
      8 
      9 #include "mozilla/AlreadyAddRefed.h"
     10 #include "mozilla/ClearOnShutdown.h"
     11 #include "mozilla/StaticPtr.h"
     12 #include "mozilla/dom/ContentParent.h"
     13 #include "mozilla/MozPromise.h"
     14 #include "nsIProtocolHandler.h"
     15 #include "nsThreadUtils.h"
     16 #include "nsWeakReference.h"
     17 
     18 namespace mozilla::image {
     19 
     20 class RemoteImageProtocolHandler : public nsIProtocolHandler,
     21                                   public nsSupportsWeakReference {
     22 public:
     23  NS_DECL_ISUPPORTS
     24  NS_DECL_NSIPROTOCOLHANDLER
     25 
     26  static already_AddRefed<RemoteImageProtocolHandler> GetSingleton() {
     27    MOZ_ASSERT(NS_IsMainThread());
     28    if (MOZ_UNLIKELY(!sSingleton)) {
     29      sSingleton = new RemoteImageProtocolHandler();
     30      ClearOnShutdown(&sSingleton);
     31    }
     32    return do_AddRef(sSingleton);
     33  }
     34 
     35 private:
     36  virtual ~RemoteImageProtocolHandler() = default;
     37 
     38  static StaticRefPtr<RemoteImageProtocolHandler> sSingleton;
     39 };
     40 
     41 }  // namespace mozilla::image
     42 
     43 #endif  // mozilla_image_remote_RemoteImageProtocolHandler_h