1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CONTENT_BROWSER_DEVTOOLS_RENDER_VIEW_DEVTOOLS_AGENT_HOST_H_ 6 #define CONTENT_BROWSER_DEVTOOLS_RENDER_VIEW_DEVTOOLS_AGENT_HOST_H_ 7 8 #include <map> 9 10 #include "base/basictypes.h" 11 #include "base/compiler_specific.h" 12 #include "base/memory/scoped_ptr.h" 13 #include "content/browser/devtools/ipc_devtools_agent_host.h" 14 #include "content/common/content_export.h" 15 #include "content/public/browser/notification_observer.h" 16 #include "content/public/browser/notification_registrar.h" 17 #include "content/public/browser/web_contents_observer.h" 18 19 namespace cc { 20 class CompositorFrameMetadata; 21 } 22 23 namespace content { 24 25 class DevToolsPowerHandler; 26 class DevToolsTracingHandler; 27 class RendererOverridesHandler; 28 class RenderViewHost; 29 class RenderViewHostImpl; 30 31 #if defined(OS_ANDROID) 32 class PowerSaveBlockerImpl; 33 #endif 34 35 class CONTENT_EXPORT RenderViewDevToolsAgentHost 36 : public IPCDevToolsAgentHost, 37 private WebContentsObserver, 38 public NotificationObserver { 39 public: 40 static void OnCancelPendingNavigation(RenderViewHost* pending, 41 RenderViewHost* current); 42 43 RenderViewDevToolsAgentHost(RenderViewHost*); 44 45 void SynchronousSwapCompositorFrame( 46 const cc::CompositorFrameMetadata& frame_metadata); 47 48 // DevTooolsAgentHost overrides. 49 virtual void DisconnectWebContents() OVERRIDE; 50 virtual void ConnectWebContents(WebContents* web_contents) OVERRIDE; 51 virtual WebContents* GetWebContents() OVERRIDE; 52 virtual Type GetType() OVERRIDE; 53 virtual std::string GetTitle() OVERRIDE; 54 virtual GURL GetURL() OVERRIDE; 55 virtual bool Activate() OVERRIDE; 56 virtual bool Close() OVERRIDE; 57 58 private: 59 friend class DevToolsAgentHost; 60 virtual ~RenderViewDevToolsAgentHost(); 61 62 // IPCDevToolsAgentHost overrides. 63 virtual void DispatchProtocolMessage(const std::string& message) OVERRIDE; 64 virtual void SendMessageToAgent(IPC::Message* msg) OVERRIDE; 65 virtual void OnClientAttached() OVERRIDE; 66 virtual void OnClientDetached() OVERRIDE; 67 68 // WebContentsObserver overrides. 69 virtual void AboutToNavigateRenderView(RenderViewHost* dest_rvh) OVERRIDE; 70 virtual void RenderViewHostChanged(RenderViewHost* old_host, 71 RenderViewHost* new_host) OVERRIDE; 72 virtual void RenderViewDeleted(RenderViewHost* rvh) OVERRIDE; 73 virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE; 74 virtual bool OnMessageReceived(const IPC::Message& message, 75 RenderFrameHost* render_frame_host) OVERRIDE; 76 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 77 virtual void DidAttachInterstitialPage() OVERRIDE; 78 virtual void DidDetachInterstitialPage() OVERRIDE; 79 80 // NotificationObserver overrides: 81 virtual void Observe(int type, 82 const NotificationSource& source, 83 const NotificationDetails& details) OVERRIDE; 84 85 void DisconnectRenderViewHost(); 86 void ConnectRenderViewHost(RenderViewHost* rvh); 87 void ReattachToRenderViewHost(RenderViewHost* rvh); 88 89 bool DispatchIPCMessage(const IPC::Message& message); 90 91 void SetRenderViewHost(RenderViewHost* rvh); 92 void ClearRenderViewHost(); 93 94 void RenderViewCrashed(); 95 void OnSwapCompositorFrame(const IPC::Message& message); 96 bool OnSetTouchEventEmulationEnabled(const IPC::Message& message); 97 98 void OnDispatchOnInspectorFrontend(const std::string& message); 99 void OnSaveAgentRuntimeState(const std::string& state); 100 101 void ClientDetachedFromRenderer(); 102 103 void InnerOnClientAttached(); 104 void InnerClientDetachedFromRenderer(); 105 106 RenderViewHostImpl* render_view_host_; 107 scoped_ptr<RendererOverridesHandler> overrides_handler_; 108 scoped_ptr<DevToolsTracingHandler> tracing_handler_; 109 scoped_ptr<DevToolsPowerHandler> power_handler_; 110 #if defined(OS_ANDROID) 111 scoped_ptr<PowerSaveBlockerImpl> power_save_blocker_; 112 #endif 113 std::string state_; 114 NotificationRegistrar registrar_; 115 bool reattaching_; 116 117 DISALLOW_COPY_AND_ASSIGN(RenderViewDevToolsAgentHost); 118 }; 119 120 } // namespace content 121 122 #endif // CONTENT_BROWSER_DEVTOOLS_RENDER_VIEW_DEVTOOLS_AGENT_HOST_H_ 123