AutoSuppressEventHandlingAndSuspend.h (2003B)
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 dom_base_AutoSuppressEventHandlingAndSuspend_h 8 #define dom_base_AutoSuppressEventHandlingAndSuspend_h 9 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" 16 17 namespace mozilla::dom { 18 19 /** 20 * Suppresses event handling and suspends for all in-process documents in a 21 * BrowsingContext subtree. 22 */ 23 class MOZ_RAII AutoSuppressEventHandling : public AutoWalkBrowsingContextGroup { 24 public: 25 AutoSuppressEventHandling() = default; 26 27 explicit AutoSuppressEventHandling(BrowsingContext* aContext) { 28 if (aContext) { 29 SuppressBrowsingContext(aContext); 30 } 31 } 32 33 ~AutoSuppressEventHandling(); 34 35 protected: 36 virtual void SuppressDocument(Document* aDocument) override; 37 void UnsuppressDocument(Document* aDocument) override; 38 }; 39 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. 46 */ 47 class MOZ_RAII AutoSuppressEventHandlingAndSuspend 48 : private AutoSuppressEventHandling { 49 public: 50 explicit AutoSuppressEventHandlingAndSuspend(BrowsingContextGroup* aGroup) { 51 if (aGroup) { 52 SuppressBrowsingContextGroup(aGroup); 53 } 54 } 55 56 ~AutoSuppressEventHandlingAndSuspend(); 57 58 protected: 59 void SuppressDocument(Document* aDocument) override; 60 61 private: 62 AutoTArray<nsCOMPtr<nsPIDOMWindowInner>, 16> mWindows; 63 }; 64 } // namespace mozilla::dom 65 66 #endif