Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / base / AutoSuppressEventHandlingAndSuspend.h
blob6f23fce475bb40390b471608bcfd18fa69553789
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 dom_base_AutoSuppressEventHandlingAndSuspend_h
8 #define dom_base_AutoSuppressEventHandlingAndSuspend_h
10 #include "mozilla/dom/BrowsingContext.h"
11 #include "mozilla/dom/BrowsingContextGroup.h"
12 #include "mozilla/dom/Document.h"
13 #include "nsCOMPtr.h"
14 #include "nsPIDOMWindow.h"
15 #include "nsTArray.h"
17 namespace mozilla::dom {
19 /**
20 * Suppresses event handling and suspends for all in-process documents in a
21 * BrowsingContext subtree.
23 class MOZ_RAII AutoSuppressEventHandling : public AutoWalkBrowsingContextGroup {
24 public:
25 AutoSuppressEventHandling() = default;
27 explicit AutoSuppressEventHandling(BrowsingContext* aContext) {
28 if (aContext) {
29 SuppressBrowsingContext(aContext);
33 ~AutoSuppressEventHandling();
35 protected:
36 virtual void SuppressDocument(Document* aDocument) override;
37 void UnsuppressDocument(Document* aDocument) override;
40 /**
41 * Suppresses event handling and suspends the active inner window for all
42 * in-process documents in a BrowsingContextGroup. This should be used while
43 * spinning the event loop for a synchronous operation (like `window.open()`)
44 * which affects operations in any other window in the same BrowsingContext
45 * group.
47 class MOZ_RAII AutoSuppressEventHandlingAndSuspend
48 : private AutoSuppressEventHandling {
49 public:
50 explicit AutoSuppressEventHandlingAndSuspend(BrowsingContextGroup* aGroup) {
51 if (aGroup) {
52 SuppressBrowsingContextGroup(aGroup);
56 ~AutoSuppressEventHandlingAndSuspend();
58 protected:
59 void SuppressDocument(Document* aDocument) override;
61 private:
62 AutoTArray<nsCOMPtr<nsPIDOMWindowInner>, 16> mWindows;
64 } // namespace mozilla::dom
66 #endif