window_list.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright (c) 2013 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ELECTRON_SHELL_BROWSER_WINDOW_LIST_H_
  5. #define ELECTRON_SHELL_BROWSER_WINDOW_LIST_H_
  6. #include <vector>
  7. #include "base/observer_list.h"
  8. namespace electron {
  9. class NativeWindow;
  10. class WindowListObserver;
  11. class WindowList {
  12. public:
  13. // disable copy
  14. WindowList(const WindowList&) = delete;
  15. WindowList& operator=(const WindowList&) = delete;
  16. typedef std::vector<NativeWindow*> WindowVector;
  17. static WindowVector GetWindows();
  18. static bool IsEmpty();
  19. // Adds or removes |window| from the list it is associated with.
  20. static void AddWindow(NativeWindow* window);
  21. static void RemoveWindow(NativeWindow* window);
  22. // Called by window when a close is cancelled by beforeunload handler.
  23. static void WindowCloseCancelled(NativeWindow* window);
  24. // Adds and removes |observer| from the observer list.
  25. static void AddObserver(WindowListObserver* observer);
  26. static void RemoveObserver(WindowListObserver* observer);
  27. // Closes all windows.
  28. static void CloseAllWindows();
  29. // Destroy all windows.
  30. static void DestroyAllWindows();
  31. private:
  32. static WindowList* GetInstance();
  33. WindowList();
  34. ~WindowList();
  35. // A list of observers which will be notified of every window addition and
  36. // removal across all WindowLists.
  37. [[nodiscard]] static base::ObserverList<WindowListObserver>& GetObservers();
  38. // A vector of the windows in this list, in the order they were added.
  39. WindowVector windows_;
  40. static WindowList* instance_;
  41. };
  42. } // namespace electron
  43. #endif // ELECTRON_SHELL_BROWSER_WINDOW_LIST_H_