tor-browser

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

LoadContextBase.h (2210B)


      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 js_loader_BaseLoadContext_h
      8 #define js_loader_BaseLoadContext_h
      9 
     10 #include "nsCycleCollectionParticipant.h"
     11 #include "nsIStringBundle.h"
     12 
     13 namespace mozilla::dom {
     14 class ScriptLoadContext;
     15 class WorkerLoadContext;
     16 class WorkletLoadContext;
     17 }  // namespace mozilla::dom
     18 
     19 namespace mozilla::loader {
     20 class SyncLoadContext;
     21 }
     22 
     23 namespace JS::loader {
     24 
     25 class ScriptLoadRequest;
     26 
     27 /*
     28 * LoadContextBase
     29 *
     30 * LoadContexts augment the loading of a ScriptLoadRequest.  This class
     31 * is used as a base for all LoadContexts, and provides shared functionality.
     32 *
     33 */
     34 
     35 enum class ContextKind { Window, Sync, Worker, Worklet };
     36 
     37 class LoadContextBase : public nsISupports {
     38 private:
     39  ContextKind mKind;
     40 
     41 protected:
     42  virtual ~LoadContextBase();
     43 
     44 public:
     45  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     46  NS_DECL_CYCLE_COLLECTION_CLASS(LoadContextBase)
     47 
     48  explicit LoadContextBase(ContextKind kind);
     49 
     50  void SetRequest(ScriptLoadRequest* aRequest);
     51 
     52  // Used to output a string for the Gecko Profiler.
     53  virtual void GetProfilerLabel(nsACString& aOutString);
     54 
     55  // Whether this is a preload, for contexts that support them.
     56  virtual bool IsPreload() const { return false; }
     57 
     58  // Casting to the different contexts
     59  bool IsWindowContext() const { return mKind == ContextKind::Window; }
     60  mozilla::dom::ScriptLoadContext* AsWindowContext();
     61  const mozilla::dom::ScriptLoadContext* AsWindowContext() const;
     62 
     63  bool IsSyncContext() const { return mKind == ContextKind::Sync; }
     64  mozilla::loader::SyncLoadContext* AsSyncContext();
     65 
     66  bool IsWorkerContext() const { return mKind == ContextKind::Worker; }
     67  mozilla::dom::WorkerLoadContext* AsWorkerContext();
     68 
     69  bool IsWorkletContext() const { return mKind == ContextKind::Worklet; }
     70  mozilla::dom::WorkletLoadContext* AsWorkletContext();
     71 
     72  RefPtr<ScriptLoadRequest> mRequest;
     73 };
     74 
     75 }  // namespace JS::loader
     76 
     77 #endif  // js_loader_BaseLoadContext_h