1 // Copyright 2014 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.
5 #ifndef CONTENT_BROWSER_DEVTOOLS_PROTOCOL_PAGE_HANDLER_H_
6 #define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_PAGE_HANDLER_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/time/time.h"
12 #include "cc/output/compositor_frame_metadata.h"
13 #include "content/browser/devtools/protocol/devtools_protocol_dispatcher.h"
14 #include "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h"
16 #include "content/public/browser/readback_types.h"
22 class RenderFrameHostImpl
;
23 class WebContentsImpl
;
30 class PageHandler
: public NotificationObserver
{
32 typedef DevToolsProtocolClient::Response Response
;
34 class ScreencastListener
{
36 virtual ~ScreencastListener() { }
37 virtual void ScreencastEnabledChanged() = 0;
41 ~PageHandler() override
;
43 void SetRenderFrameHost(RenderFrameHostImpl
* host
);
44 void SetClient(scoped_ptr
<Client
> client
);
46 void OnSwapCompositorFrame(const cc::CompositorFrameMetadata
& frame_metadata
);
47 void OnSynchronousSwapCompositorFrame(const cc::CompositorFrameMetadata
&
49 void DidAttachInterstitialPage();
50 void DidDetachInterstitialPage();
51 void SetScreencastListener(ScreencastListener
* listener
);
52 bool screencast_enabled() const { return enabled_
&& screencast_enabled_
; }
57 Response
Reload(const bool* ignoreCache
,
58 const std::string
* script_to_evaluate_on_load
,
59 const std::string
* script_preprocessor
= NULL
);
61 Response
Navigate(const std::string
& url
, FrameId
* frame_id
);
63 using NavigationEntries
= std::vector
<scoped_refptr
<NavigationEntry
>>;
64 Response
GetNavigationHistory(int* current_index
,
65 NavigationEntries
* entries
);
67 Response
NavigateToHistoryEntry(int entry_id
);
69 Response
CaptureScreenshot(DevToolsCommandId command_id
);
71 Response
CanScreencast(bool* result
);
72 Response
StartScreencast(const std::string
* format
,
75 const int* max_height
);
76 Response
StopScreencast();
77 Response
ScreencastFrameAck(int frame_number
);
79 Response
HandleJavaScriptDialog(bool accept
, const std::string
* prompt_text
);
81 Response
QueryUsageAndQuota(DevToolsCommandId command_id
,
82 const std::string
& security_origin
);
84 Response
SetColorPickerEnabled(bool enabled
);
87 WebContentsImpl
* GetWebContents();
88 void NotifyScreencastVisibility(bool visible
);
89 void InnerSwapCompositorFrame();
90 void ScreencastFrameCaptured(const cc::CompositorFrameMetadata
& metadata
,
91 const SkBitmap
& bitmap
,
92 ReadbackResponse response
);
93 void ScreencastFrameEncoded(const cc::CompositorFrameMetadata
& metadata
,
94 const base::Time
& timestamp
,
95 const std::string
& data
);
97 void ScreenshotCaptured(
98 DevToolsCommandId command_id
,
99 const unsigned char* png_data
,
102 void OnColorPicked(int r
, int g
, int b
, int a
);
104 // NotificationObserver overrides.
105 void Observe(int type
,
106 const NotificationSource
& source
,
107 const NotificationDetails
& details
) override
;
111 bool screencast_enabled_
;
112 std::string screencast_format_
;
113 int screencast_quality_
;
114 int screencast_max_width_
;
115 int screencast_max_height_
;
116 int capture_retry_count_
;
117 bool has_compositor_frame_metadata_
;
118 cc::CompositorFrameMetadata next_compositor_frame_metadata_
;
119 cc::CompositorFrameMetadata last_compositor_frame_metadata_
;
120 int screencast_frame_sent_
;
121 int screencast_frame_acked_
;
122 bool processing_screencast_frame_
;
124 scoped_ptr
<ColorPicker
> color_picker_
;
126 RenderFrameHostImpl
* host_
;
127 scoped_ptr
<Client
> client_
;
128 ScreencastListener
* screencast_listener_
;
129 NotificationRegistrar registrar_
;
130 base::WeakPtrFactory
<PageHandler
> weak_factory_
;
132 DISALLOW_COPY_AND_ASSIGN(PageHandler
);
136 } // namespace devtools
137 } // namespace content
139 #endif // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_PAGE_HANDLER_H_