| 
									
										
										
										
											2015-03-13 16:33:06 -07:00
										 |  |  | // Copyright (c) 2015 GitHub, Inc.
 | 
					
						
							|  |  |  | // Use of this source code is governed by the MIT license that can be
 | 
					
						
							|  |  |  | // found in the LICENSE file.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-19 13:46:59 -07:00
										 |  |  | #include "shell/renderer/guest_view_container.h"
 | 
					
						
							| 
									
										
										
										
											2015-03-13 16:33:06 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-29 13:47:09 +08:00
										 |  |  | #include <map>
 | 
					
						
							| 
									
										
										
										
											2018-09-12 19:25:56 -05:00
										 |  |  | #include <utility>
 | 
					
						
							| 
									
										
										
										
											2015-05-29 13:47:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-02 15:16:49 +08:00
										 |  |  | #include "base/bind.h"
 | 
					
						
							| 
									
										
										
										
											2015-05-29 13:47:09 +08:00
										 |  |  | #include "base/lazy_instance.h"
 | 
					
						
							| 
									
										
										
										
											2016-11-30 16:30:03 +09:00
										 |  |  | #include "base/threading/thread_task_runner_handle.h"
 | 
					
						
							| 
									
										
										
										
											2021-07-01 17:51:37 -07:00
										 |  |  | #include "content/public/renderer/render_frame.h"
 | 
					
						
							| 
									
										
										
										
											2015-08-10 11:56:42 +08:00
										 |  |  | #include "ui/gfx/geometry/size.h"
 | 
					
						
							| 
									
										
										
										
											2015-05-29 13:47:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-13 16:33:06 -07:00
										 |  |  | namespace electron { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-29 13:47:09 +08:00
										 |  |  | namespace { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using GuestViewContainerMap = std::map<int, GuestViewContainer*>; | 
					
						
							| 
									
										
										
										
											2017-06-20 22:14:39 +03:00
										 |  |  | static base::LazyInstance<GuestViewContainerMap>::DestructorAtExit | 
					
						
							|  |  |  |     g_guest_view_container_map = LAZY_INSTANCE_INITIALIZER; | 
					
						
							| 
									
										
										
										
											2015-05-29 13:47:09 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | }  // namespace
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-26 19:16:21 +01:00
										 |  |  | GuestViewContainer::GuestViewContainer(content::RenderFrame* render_frame) {} | 
					
						
							| 
									
										
										
										
											2015-03-13 16:33:06 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | GuestViewContainer::~GuestViewContainer() { | 
					
						
							| 
									
										
										
										
											2015-05-29 13:47:09 +08:00
										 |  |  |   if (element_instance_id_ > 0) | 
					
						
							|  |  |  |     g_guest_view_container_map.Get().erase(element_instance_id_); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // static
 | 
					
						
							|  |  |  | GuestViewContainer* GuestViewContainer::FromID(int element_instance_id) { | 
					
						
							|  |  |  |   GuestViewContainerMap* guest_view_containers = | 
					
						
							|  |  |  |       g_guest_view_container_map.Pointer(); | 
					
						
							|  |  |  |   auto it = guest_view_containers->find(element_instance_id); | 
					
						
							|  |  |  |   return it == guest_view_containers->end() ? nullptr : it->second; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GuestViewContainer::RegisterElementResizeCallback( | 
					
						
							|  |  |  |     const ResizeCallback& callback) { | 
					
						
							|  |  |  |   element_resize_callback_ = callback; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GuestViewContainer::SetElementInstanceID(int element_instance_id) { | 
					
						
							|  |  |  |   element_instance_id_ = element_instance_id; | 
					
						
							|  |  |  |   g_guest_view_container_map.Get().insert( | 
					
						
							|  |  |  |       std::make_pair(element_instance_id, this)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-04 17:07:31 +08:00
										 |  |  | void GuestViewContainer::DidResizeElement(const gfx::Size& new_size) { | 
					
						
							| 
									
										
										
										
											2015-05-29 13:47:09 +08:00
										 |  |  |   if (element_resize_callback_.is_null()) | 
					
						
							|  |  |  |     return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-30 16:30:03 +09:00
										 |  |  |   base::ThreadTaskRunnerHandle::Get()->PostTask( | 
					
						
							| 
									
										
										
										
											2018-04-20 16:25:05 +05:30
										 |  |  |       FROM_HERE, base::BindOnce(element_resize_callback_, new_size)); | 
					
						
							| 
									
										
										
										
											2015-03-13 16:33:06 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }  // namespace electron
 |