| 
									
										
										
										
											2014-02-24 11:53:13 +08:00
										 |  |  | // Copyright (c) 2014 GitHub, Inc. All rights reserved.
 | 
					
						
							|  |  |  | // Use of this source code is governed by a BSD-style license that can be
 | 
					
						
							|  |  |  | // found in the LICENSE file.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-16 08:30:26 +08:00
										 |  |  | #include "atom/browser/devtools_delegate.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-24 11:53:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-16 09:13:06 +08:00
										 |  |  | #include <string>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-04 19:02:48 +08:00
										 |  |  | #include "base/message_loop/message_loop.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-24 11:53:13 +08:00
										 |  |  | #include "base/values.h"
 | 
					
						
							| 
									
										
										
										
											2014-03-16 08:30:26 +08:00
										 |  |  | #include "atom/browser/native_window.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-24 11:53:13 +08:00
										 |  |  | #include "content/public/browser/devtools_agent_host.h"
 | 
					
						
							|  |  |  | #include "content/public/browser/devtools_client_host.h"
 | 
					
						
							|  |  |  | #include "content/public/browser/devtools_http_handler.h"
 | 
					
						
							|  |  |  | #include "content/public/browser/devtools_manager.h"
 | 
					
						
							|  |  |  | #include "content/public/browser/web_contents.h"
 | 
					
						
							| 
									
										
										
										
											2014-03-04 17:50:57 +08:00
										 |  |  | #include "ui/gfx/point.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-24 11:53:13 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace atom { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | DevToolsDelegate::DevToolsDelegate(NativeWindow* window, | 
					
						
							|  |  |  |                                    content::WebContents* target_web_contents) | 
					
						
							|  |  |  |     : content::WebContentsObserver(window->GetWebContents()), | 
					
						
							| 
									
										
										
										
											2014-03-04 17:50:57 +08:00
										 |  |  |       owner_window_(window), | 
					
						
							| 
									
										
										
										
											2014-03-04 19:59:25 +08:00
										 |  |  |       delegate_(NULL), | 
					
						
							| 
									
										
										
										
											2014-03-04 17:50:57 +08:00
										 |  |  |       embedder_message_dispatcher_( | 
					
						
							|  |  |  |           new DevToolsEmbedderMessageDispatcher(this)) { | 
					
						
							| 
									
										
										
										
											2014-02-24 11:53:13 +08:00
										 |  |  |   content::WebContents* web_contents = window->GetWebContents(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Setup devtools.
 | 
					
						
							|  |  |  |   devtools_agent_host_ = content::DevToolsAgentHost::GetOrCreateFor( | 
					
						
							|  |  |  |       target_web_contents->GetRenderViewHost()); | 
					
						
							|  |  |  |   devtools_client_host_.reset( | 
					
						
							|  |  |  |       content::DevToolsClientHost::CreateDevToolsFrontendHost(web_contents, | 
					
						
							|  |  |  |                                                               this)); | 
					
						
							|  |  |  |   content::DevToolsManager::GetInstance()->RegisterDevToolsClientHostFor( | 
					
						
							|  |  |  |       devtools_agent_host_.get(), devtools_client_host_.get()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Go!
 | 
					
						
							|  |  |  |   base::DictionaryValue options; | 
					
						
							|  |  |  |   options.SetString("title", "DevTools Debugger"); | 
					
						
							|  |  |  |   window->InitFromOptions(&options); | 
					
						
							| 
									
										
										
										
											2014-03-04 19:02:48 +08:00
										 |  |  |   window->AddObserver(this); | 
					
						
							| 
									
										
										
										
											2014-02-24 11:53:13 +08:00
										 |  |  |   web_contents->GetController().LoadURL( | 
					
						
							| 
									
										
										
										
											2014-03-04 17:50:57 +08:00
										 |  |  |       GURL("chrome-devtools://devtools/devtools.html?dockSide=undocked"), | 
					
						
							| 
									
										
										
										
											2014-02-24 11:53:13 +08:00
										 |  |  |       content::Referrer(), | 
					
						
							|  |  |  |       content::PAGE_TRANSITION_AUTO_TOPLEVEL, | 
					
						
							|  |  |  |       std::string()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | DevToolsDelegate::~DevToolsDelegate() { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DevToolsDelegate::DispatchOnEmbedder(const std::string& message) { | 
					
						
							| 
									
										
										
										
											2014-03-04 17:50:57 +08:00
										 |  |  |   embedder_message_dispatcher_->Dispatch(message); | 
					
						
							| 
									
										
										
										
											2014-02-24 11:53:13 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DevToolsDelegate::InspectedContentsClosing() { | 
					
						
							| 
									
										
										
										
											2014-03-04 19:02:48 +08:00
										 |  |  |   owner_window_->Close(); | 
					
						
							| 
									
										
										
										
											2014-02-24 11:53:13 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DevToolsDelegate::AboutToNavigateRenderView( | 
					
						
							|  |  |  |       content::RenderViewHost* render_view_host) { | 
					
						
							|  |  |  |   content::DevToolsClientHost::SetupDevToolsFrontendClient( | 
					
						
							|  |  |  |       owner_window_->GetWebContents()->GetRenderViewHost()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-24 12:17:10 +08:00
										 |  |  | void DevToolsDelegate::OnWindowClosed() { | 
					
						
							| 
									
										
										
										
											2014-03-04 19:02:48 +08:00
										 |  |  |   base::MessageLoop::current()->DeleteSoon(FROM_HERE, owner_window_); | 
					
						
							| 
									
										
										
										
											2014-02-24 12:17:10 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-04 17:50:57 +08:00
										 |  |  | void DevToolsDelegate::ActivateWindow() { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DevToolsDelegate::CloseWindow() { | 
					
						
							|  |  |  |   owner_window_->Close(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DevToolsDelegate::MoveWindow(int x, int y) { | 
					
						
							|  |  |  |   owner_window_->SetPosition(gfx::Point(x, y)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DevToolsDelegate::SetDockSide(const std::string& dock_side) { | 
					
						
							| 
									
										
										
										
											2014-03-04 19:59:25 +08:00
										 |  |  |   bool succeed = true; | 
					
						
							|  |  |  |   if (delegate_ && | 
					
						
							|  |  |  |       delegate_->DevToolsSetDockSide("attach-back", &succeed) && | 
					
						
							|  |  |  |       succeed) | 
					
						
							|  |  |  |     owner_window_->Close(); | 
					
						
							| 
									
										
										
										
											2014-03-04 17:50:57 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DevToolsDelegate::OpenInNewTab(const std::string& url) { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DevToolsDelegate::SaveToFile( | 
					
						
							|  |  |  |     const std::string& url, const std::string& content, bool save_as) { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DevToolsDelegate::AppendToFile( | 
					
						
							|  |  |  |     const std::string& url, const std::string& content) { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DevToolsDelegate::RequestFileSystems() { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DevToolsDelegate::AddFileSystem() { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DevToolsDelegate::RemoveFileSystem(const std::string& file_system_path) { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DevToolsDelegate::IndexPath( | 
					
						
							|  |  |  |     int request_id, const std::string& file_system_path) { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DevToolsDelegate::StopIndexing(int request_id) { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DevToolsDelegate::SearchInPath( | 
					
						
							|  |  |  |     int request_id, | 
					
						
							|  |  |  |     const std::string& file_system_path, | 
					
						
							|  |  |  |     const std::string& query) { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-24 11:53:13 +08:00
										 |  |  | }  // namespace atom
 |