1 // Copyright (c) 2013 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_RENDERER_OVERRIDES_HANDLER_H_ 6 #define CONTENT_BROWSER_DEVTOOLS_RENDERER_OVERRIDES_HANDLER_H_ 7 8 #include "base/basictypes.h" 9 #include "base/compiler_specific.h" 10 #include "base/memory/ref_counted_memory.h" 11 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/weak_ptr.h" 13 #include "base/time/time.h" 14 #include "cc/output/compositor_frame_metadata.h" 15 #include "content/browser/devtools/devtools_protocol.h" 16 #include "content/common/content_export.h" 17 #include "content/public/browser/render_widget_host.h" 18 #include "third_party/skia/include/core/SkBitmap.h" 19 20 class SkBitmap; 21 22 namespace IPC { 23 class Message; 24 } 25 26 namespace blink { 27 class WebMouseEvent; 28 } 29 30 namespace content { 31 32 class DevToolsTracingHandler; 33 class RenderViewHostImpl; 34 35 // Overrides Inspector commands before they are sent to the renderer. 36 // May override the implementation completely, ignore it, or handle 37 // additional browser process implementation details. 38 class CONTENT_EXPORT RendererOverridesHandler 39 : public DevToolsProtocol::Handler { 40 public: 41 RendererOverridesHandler(); 42 virtual ~RendererOverridesHandler(); 43 44 void OnClientDetached(); 45 void OnSwapCompositorFrame(const cc::CompositorFrameMetadata& frame_metadata); 46 void OnVisibilityChanged(bool visible); 47 void SetRenderViewHost(RenderViewHostImpl* host); 48 void ClearRenderViewHost(); 49 void DidAttachInterstitialPage(); 50 void DidDetachInterstitialPage(); 51 52 private: 53 void InnerSwapCompositorFrame(); 54 55 // DOM domain. 56 scoped_refptr<DevToolsProtocol::Response> 57 GrantPermissionsForSetFileInputFiles( 58 scoped_refptr<DevToolsProtocol::Command> command); 59 60 // Network domain. 61 scoped_refptr<DevToolsProtocol::Response> CanEmulateNetworkConditions( 62 scoped_refptr<DevToolsProtocol::Command> command); 63 scoped_refptr<DevToolsProtocol::Response> ClearBrowserCache( 64 scoped_refptr<DevToolsProtocol::Command> command); 65 scoped_refptr<DevToolsProtocol::Response> ClearBrowserCookies( 66 scoped_refptr<DevToolsProtocol::Command> command); 67 68 // Page domain. 69 scoped_refptr<DevToolsProtocol::Response> PageEnable( 70 scoped_refptr<DevToolsProtocol::Command> command); 71 scoped_refptr<DevToolsProtocol::Response> PageDisable( 72 scoped_refptr<DevToolsProtocol::Command> command); 73 scoped_refptr<DevToolsProtocol::Response> PageHandleJavaScriptDialog( 74 scoped_refptr<DevToolsProtocol::Command> command); 75 scoped_refptr<DevToolsProtocol::Response> PageNavigate( 76 scoped_refptr<DevToolsProtocol::Command> command); 77 scoped_refptr<DevToolsProtocol::Response> PageReload( 78 scoped_refptr<DevToolsProtocol::Command> command); 79 scoped_refptr<DevToolsProtocol::Response> PageGetNavigationHistory( 80 scoped_refptr<DevToolsProtocol::Command> command); 81 scoped_refptr<DevToolsProtocol::Response> PageNavigateToHistoryEntry( 82 scoped_refptr<DevToolsProtocol::Command> command); 83 scoped_refptr<DevToolsProtocol::Response> PageSetTouchEmulationEnabled( 84 scoped_refptr<DevToolsProtocol::Command> command); 85 scoped_refptr<DevToolsProtocol::Response> PageCaptureScreenshot( 86 scoped_refptr<DevToolsProtocol::Command> command); 87 scoped_refptr<DevToolsProtocol::Response> PageCanEmulate( 88 scoped_refptr<DevToolsProtocol::Command> command); 89 scoped_refptr<DevToolsProtocol::Response> PageCanScreencast( 90 scoped_refptr<DevToolsProtocol::Command> command); 91 scoped_refptr<DevToolsProtocol::Response> PageStartScreencast( 92 scoped_refptr<DevToolsProtocol::Command> command); 93 scoped_refptr<DevToolsProtocol::Response> PageStopScreencast( 94 scoped_refptr<DevToolsProtocol::Command> command); 95 scoped_refptr<DevToolsProtocol::Response> PageQueryUsageAndQuota( 96 scoped_refptr<DevToolsProtocol::Command>); 97 scoped_refptr<DevToolsProtocol::Response> PageSetColorPickerEnabled( 98 scoped_refptr<DevToolsProtocol::Command>); 99 100 void ScreenshotCaptured( 101 scoped_refptr<DevToolsProtocol::Command> command, 102 const unsigned char* png_data, 103 size_t png_size); 104 105 void ScreencastFrameCaptured( 106 const std::string& format, 107 int quality, 108 const cc::CompositorFrameMetadata& metadata, 109 bool success, 110 const SkBitmap& bitmap); 111 112 void PageQueryUsageAndQuotaCompleted( 113 scoped_refptr<DevToolsProtocol::Command>, 114 scoped_ptr<base::DictionaryValue> response_data); 115 116 void NotifyScreencastVisibility(bool visible); 117 void SetColorPickerEnabled(bool enabled); 118 void UpdateColorPickerFrame(); 119 void ResetColorPickerFrame(); 120 void ColorPickerFrameUpdated(bool succeeded, const SkBitmap& bitmap); 121 bool HandleMouseEvent(const blink::WebMouseEvent& event); 122 void UpdateColorPickerCursor(); 123 124 // Input domain. 125 scoped_refptr<DevToolsProtocol::Response> InputEmulateTouchFromMouseEvent( 126 scoped_refptr<DevToolsProtocol::Command> command); 127 128 void UpdateTouchEventEmulationState(); 129 130 RenderViewHostImpl* host_; 131 bool page_domain_enabled_; 132 scoped_refptr<DevToolsProtocol::Command> screencast_command_; 133 bool has_last_compositor_frame_metadata_; 134 cc::CompositorFrameMetadata last_compositor_frame_metadata_; 135 base::TimeTicks last_frame_time_; 136 int capture_retry_count_; 137 bool touch_emulation_enabled_; 138 bool color_picker_enabled_; 139 SkBitmap color_picker_frame_; 140 int last_cursor_x_; 141 int last_cursor_y_; 142 RenderWidgetHost::MouseEventCallback mouse_event_callback_; 143 base::WeakPtrFactory<RendererOverridesHandler> weak_factory_; 144 DISALLOW_COPY_AND_ASSIGN(RendererOverridesHandler); 145 }; 146 147 } // namespace content 148 149 #endif // CONTENT_BROWSER_DEVTOOLS_RENDERER_OVERRIDES_HANDLER_H_ 150