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 30 #if defined(OS_ANDROID) 31 class PowerSaveBlockerImpl; 32 #endif 33 34 class CONTENT_EXPORT RenderViewDevToolsAgentHost 35 : public IPCDevToolsAgentHost, 36 private WebContentsObserver, 37 public NotificationObserver { 38 public: 39 static void OnCancelPendingNavigation(RenderViewHost* pending, 40 RenderViewHost* current); 41 42 static bool DispatchIPCMessage(RenderViewHost* source, 43 const IPC::Message& message); 44 45 RenderViewDevToolsAgentHost(RenderViewHost*); 46 render_view_host()47 RenderViewHost* render_view_host() { return render_view_host_; } 48 49 void SynchronousSwapCompositorFrame( 50 const cc::CompositorFrameMetadata& frame_metadata); 51 52 private: 53 friend class DevToolsAgentHost; 54 55 virtual ~RenderViewDevToolsAgentHost(); 56 57 // DevTooolsAgentHost overrides. 58 virtual void DisconnectRenderViewHost() OVERRIDE; 59 virtual void ConnectRenderViewHost(RenderViewHost* rvh) OVERRIDE; 60 virtual RenderViewHost* GetRenderViewHost() OVERRIDE; 61 62 // IPCDevToolsAgentHost overrides. 63 virtual void DispatchOnInspectorBackend(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 void DidAttachInterstitialPage() OVERRIDE; 75 76 // NotificationObserver overrides: 77 virtual void Observe(int type, 78 const NotificationSource& source, 79 const NotificationDetails& details) OVERRIDE; 80 81 void ReattachToRenderViewHost(RenderViewHost* rvh); 82 83 bool DispatchIPCMessage(const IPC::Message& message); 84 85 void SetRenderViewHost(RenderViewHost* rvh); 86 void ClearRenderViewHost(); 87 88 void RenderViewCrashed(); 89 void OnSwapCompositorFrame(const IPC::Message& message); 90 91 void OnDispatchOnInspectorFrontend(const std::string& message); 92 void OnSaveAgentRuntimeState(const std::string& state); 93 94 void ClientDetachedFromRenderer(); 95 96 void InnerOnClientAttached(); 97 void InnerClientDetachedFromRenderer(); 98 99 RenderViewHost* render_view_host_; 100 scoped_ptr<RendererOverridesHandler> overrides_handler_; 101 scoped_ptr<DevToolsTracingHandler> tracing_handler_; 102 scoped_ptr<DevToolsPowerHandler> power_handler_; 103 #if defined(OS_ANDROID) 104 scoped_ptr<PowerSaveBlockerImpl> power_save_blocker_; 105 #endif 106 std::string state_; 107 NotificationRegistrar registrar_; 108 bool reattaching_; 109 110 DISALLOW_COPY_AND_ASSIGN(RenderViewDevToolsAgentHost); 111 }; 112 113 } // namespace content 114 115 #endif // CONTENT_BROWSER_DEVTOOLS_RENDER_VIEW_DEVTOOLS_AGENT_HOST_H_ 116