| 
									
										
										
										
											2018-09-16 01:42:43 +10: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.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "atom/browser/atom_navigation_throttle.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "atom/browser/api/atom_api_web_contents.h"
 | 
					
						
							|  |  |  | #include "content/public/browser/navigation_handle.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace atom { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AtomNavigationThrottle::AtomNavigationThrottle( | 
					
						
							|  |  |  |     content::NavigationHandle* navigation_handle) | 
					
						
							|  |  |  |     : content::NavigationThrottle(navigation_handle) {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AtomNavigationThrottle::~AtomNavigationThrottle() {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const char* AtomNavigationThrottle::GetNameForLogging() { | 
					
						
							|  |  |  |   return "AtomNavigationThrottle"; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | content::NavigationThrottle::ThrottleCheckResult | 
					
						
							|  |  |  | AtomNavigationThrottle::WillRedirectRequest() { | 
					
						
							|  |  |  |   auto* handle = navigation_handle(); | 
					
						
							|  |  |  |   auto* contents = handle->GetWebContents(); | 
					
						
							|  |  |  |   if (!contents) { | 
					
						
							|  |  |  |     NOTREACHED(); | 
					
						
							|  |  |  |     return PROCEED; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   auto api_contents = | 
					
						
							| 
									
										
										
										
											2018-10-19 17:52:07 +09:00
										 |  |  |       atom::api::WebContents::From(v8::Isolate::GetCurrent(), contents); | 
					
						
							| 
									
										
										
										
											2018-09-16 01:42:43 +10:00
										 |  |  |   if (api_contents.IsEmpty()) { | 
					
						
							| 
									
										
										
										
											2018-10-19 17:52:07 +09:00
										 |  |  |     // No need to emit any event if the WebContents is not available in JS.
 | 
					
						
							| 
									
										
										
										
											2018-09-16 01:42:43 +10:00
										 |  |  |     return PROCEED; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (api_contents->EmitNavigationEvent("will-redirect", handle)) { | 
					
						
							|  |  |  |     return CANCEL; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   return PROCEED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }  // namespace atom
 |