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/. */
7 #ifndef js_loader_BaseLoadContext_h
8 #define js_loader_BaseLoadContext_h
10 #include "js/loader/ScriptLoadRequest.h"
11 #include "nsIStringBundle.h"
13 namespace mozilla::dom
{
14 class ScriptLoadContext
;
15 class WorkerLoadContext
;
16 class WorkletLoadContext
;
17 } // namespace mozilla::dom
19 namespace mozilla::loader
{
20 class ComponentLoadContext
;
23 namespace JS::loader
{
25 class ScriptLoadRequest
;
30 * LoadContexts augment the loading of a ScriptLoadRequest. This class
31 * is used as a base for all LoadContexts, and provides shared functionality.
35 enum class ContextKind
{ Window
, Component
, Worker
, Worklet
};
37 class LoadContextBase
: public nsISupports
{
42 virtual ~LoadContextBase() = default;
45 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
46 NS_DECL_CYCLE_COLLECTION_CLASS(LoadContextBase
)
48 explicit LoadContextBase(ContextKind kind
);
50 void SetRequest(JS::loader::ScriptLoadRequest
* aRequest
);
52 // Used to output a string for the Gecko Profiler.
53 virtual void GetProfilerLabel(nsACString
& aOutString
);
55 // Casting to the different contexts
56 bool IsWindowContext() const { return mKind
== ContextKind::Window
; }
57 mozilla::dom::ScriptLoadContext
* AsWindowContext();
59 bool IsComponentContext() const { return mKind
== ContextKind::Component
; }
60 mozilla::loader::ComponentLoadContext
* AsComponentContext();
62 bool IsWorkerContext() const { return mKind
== ContextKind::Worker
; }
63 mozilla::dom::WorkerLoadContext
* AsWorkerContext();
65 bool IsWorkletContext() const { return mKind
== ContextKind::Worklet
; }
66 mozilla::dom::WorkletLoadContext
* AsWorkletContext();
68 RefPtr
<JS::loader::ScriptLoadRequest
> mRequest
;
71 } // namespace JS::loader
73 #endif // js_loader_BaseLoadContext_h