Bug 1805526 - Refactor extension.startup() permissions setup, r=robwu
[gecko.git] / toolkit / components / extensions / DocumentObserver.h
blobb9b0dc6f78342e4d33765fdd60c10d42ebd6c73c
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/. */
6 #ifndef mozilla_extensions_DocumentObserver_h
7 #define mozilla_extensions_DocumentObserver_h
9 #include "mozilla/dom/BindingDeclarations.h"
10 #include "mozilla/dom/MozDocumentObserverBinding.h"
12 #include "mozilla/extensions/WebExtensionContentScript.h"
14 class nsILoadInfo;
15 class nsPIDOMWindowOuter;
17 namespace mozilla {
18 namespace extensions {
20 class DocumentObserver final : public nsISupports, public nsWrapperCache {
21 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
22 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(DocumentObserver)
24 static already_AddRefed<DocumentObserver> Constructor(
25 dom::GlobalObject& aGlobal, dom::MozDocumentCallback& aCallbacks);
27 void Observe(const dom::Sequence<OwningNonNull<MozDocumentMatcher>>& matchers,
28 ErrorResult& aRv);
30 void Disconnect();
32 const nsTArray<RefPtr<MozDocumentMatcher>>& Matchers() const {
33 return mMatchers;
36 void NotifyMatch(MozDocumentMatcher& aMatcher, nsPIDOMWindowOuter* aWindow);
37 void NotifyMatch(MozDocumentMatcher& aMatcher, nsILoadInfo* aLoadInfo);
39 nsISupports* GetParentObject() const { return mParent; }
40 JSObject* WrapObject(JSContext* aCx,
41 JS::Handle<JSObject*> aGivenProto) override;
43 protected:
44 virtual ~DocumentObserver() = default;
46 private:
47 explicit DocumentObserver(nsISupports* aParent,
48 dom::MozDocumentCallback& aCallbacks)
49 : mParent(aParent), mCallbacks(&aCallbacks) {}
51 nsCOMPtr<nsISupports> mParent;
52 RefPtr<dom::MozDocumentCallback> mCallbacks;
53 nsTArray<RefPtr<MozDocumentMatcher>> mMatchers;
56 } // namespace extensions
57 } // namespace mozilla
59 #endif // mozilla_extensions_DocumentObserver_h