window_list.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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/lazy_instance.h"
  8. #include "base/observer_list.h"
  9. namespace electron {
  10. class NativeWindow;
  11. class WindowListObserver;
  12. class WindowList {
  13. public:
  14. // disable copy
  15. WindowList(const WindowList&) = delete;
  16. WindowList& operator=(const WindowList&) = delete;
  17. typedef std::vector<NativeWindow*> WindowVector;
  18. static WindowVector GetWindows();
  19. static bool IsEmpty();
  20. // Adds or removes |window| from the list it is associated with.
  21. static void AddWindow(NativeWindow* window);
  22. static void RemoveWindow(NativeWindow* window);
  23. // Called by window when a close is cancelled by beforeunload handler.
  24. static void WindowCloseCancelled(NativeWindow* window);
  25. // Adds and removes |observer| from the observer list.
  26. static void AddObserver(WindowListObserver* observer);
  27. static void RemoveObserver(WindowListObserver* observer);
  28. // Closes all windows.
  29. static void CloseAllWindows();
  30. // Destroy all windows.
  31. static void DestroyAllWindows();
  32. private:
  33. static WindowList* GetInstance();
  34. WindowList();
  35. ~WindowList();
  36. // A vector of the windows in this list, in the order they were added.
  37. WindowVector windows_;
  38. // A list of observers which will be notified of every window addition and
  39. // removal across all WindowLists.
  40. static base::LazyInstance<base::ObserverList<WindowListObserver>>::Leaky
  41. observers_;
  42. static WindowList* instance_;
  43. };
  44. } // namespace electron
  45. #endif // ELECTRON_SHELL_BROWSER_WINDOW_LIST_H_