| 
									
										
										
										
											2014-10-31 11:17:05 -07:00
										 |  |  | // Copyright (c) 2013 GitHub, Inc.
 | 
					
						
							| 
									
										
										
										
											2014-04-25 17:49:37 +08:00
										 |  |  | // Use of this source code is governed by the MIT license that can be
 | 
					
						
							| 
									
										
										
										
											2013-05-02 22:54:09 +08:00
										 |  |  | // found in the LICENSE file.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-22 08:34:31 +01:00
										 |  |  | #ifndef ELECTRON_SHELL_BROWSER_WINDOW_LIST_H_
 | 
					
						
							|  |  |  | #define ELECTRON_SHELL_BROWSER_WINDOW_LIST_H_
 | 
					
						
							| 
									
										
										
										
											2013-05-02 22:54:09 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <vector>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "base/observer_list.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace electron { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class NativeWindow; | 
					
						
							|  |  |  | class WindowListObserver; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class WindowList { | 
					
						
							|  |  |  |  public: | 
					
						
							| 
									
										
										
										
											2021-11-03 12:41:45 +01:00
										 |  |  |   // disable copy
 | 
					
						
							|  |  |  |   WindowList(const WindowList&) = delete; | 
					
						
							|  |  |  |   WindowList& operator=(const WindowList&) = delete; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-02 22:54:09 +08:00
										 |  |  |   typedef std::vector<NativeWindow*> WindowVector; | 
					
						
							| 
									
										
										
										
											2014-01-02 14:47:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-06 14:43:37 -07:00
										 |  |  |   static WindowVector GetWindows(); | 
					
						
							| 
									
										
										
										
											2017-04-06 14:48:58 -07:00
										 |  |  |   static bool IsEmpty(); | 
					
						
							| 
									
										
										
										
											2017-04-06 14:43:37 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-02 22:54:09 +08:00
										 |  |  |   // Adds or removes |window| from the list it is associated with.
 | 
					
						
							|  |  |  |   static void AddWindow(NativeWindow* window); | 
					
						
							|  |  |  |   static void RemoveWindow(NativeWindow* window); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-02 23:43:23 +08:00
										 |  |  |   // Called by window when a close is cancelled by beforeunload handler.
 | 
					
						
							|  |  |  |   static void WindowCloseCancelled(NativeWindow* window); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-02 22:54:09 +08:00
										 |  |  |   // Adds and removes |observer| from the observer list.
 | 
					
						
							|  |  |  |   static void AddObserver(WindowListObserver* observer); | 
					
						
							|  |  |  |   static void RemoveObserver(WindowListObserver* observer); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Closes all windows.
 | 
					
						
							|  |  |  |   static void CloseAllWindows(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-06 14:25:22 -07:00
										 |  |  |   // Destroy all windows.
 | 
					
						
							|  |  |  |   static void DestroyAllWindows(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-02 22:54:09 +08:00
										 |  |  |  private: | 
					
						
							| 
									
										
										
										
											2017-04-06 14:48:58 -07:00
										 |  |  |   static WindowList* GetInstance(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-02 22:54:09 +08:00
										 |  |  |   WindowList(); | 
					
						
							|  |  |  |   ~WindowList(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // A list of observers which will be notified of every window addition and
 | 
					
						
							|  |  |  |   // removal across all WindowLists.
 | 
					
						
							| 
									
										
										
										
											2024-01-10 14:01:49 -06:00
										 |  |  |   [[nodiscard]] static base::ObserverList<WindowListObserver>& GetObservers(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // A vector of the windows in this list, in the order they were added.
 | 
					
						
							|  |  |  |   WindowVector windows_; | 
					
						
							| 
									
										
										
										
											2013-05-02 22:54:09 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   static WindowList* instance_; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }  // namespace electron
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-22 08:34:31 +01:00
										 |  |  | #endif  // ELECTRON_SHELL_BROWSER_WINDOW_LIST_H_
 |