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_handler.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 DidAttachInterstitialPage();
48 void DidDetachInterstitialPage();
49 void SetScreencastListener(ScreencastListener
* listener
);
50 bool screencast_enabled() const { return enabled_
&& screencast_enabled_
; }
55 Response
Reload(const bool* ignoreCache
,
56 const std::string
* script_to_evaluate_on_load
,
57 const std::string
* script_preprocessor
= NULL
);
59 Response
Navigate(const std::string
& url
, FrameId
* frame_id
);
61 using NavigationEntries
= std::vector
<scoped_refptr
<NavigationEntry
>>;
62 Response
GetNavigationHistory(int* current_index
,
63 NavigationEntries
* entries
);
65 Response
NavigateToHistoryEntry(int entry_id
);
67 Response
CaptureScreenshot(DevToolsCommandId command_id
);
69 Response
CanScreencast(bool* result
);
70 Response
StartScreencast(const std::string
* format
,
73 const int* max_height
);
74 Response
StopScreencast();
75 Response
ScreencastFrameAck(int frame_number
);
77 Response
HandleJavaScriptDialog(bool accept
, const std::string
* prompt_text
);
79 Response
QueryUsageAndQuota(DevToolsCommandId command_id
,
80 const std::string
& security_origin
);
82 Response
SetColorPickerEnabled(bool enabled
);
85 WebContentsImpl
* GetWebContents();
86 void NotifyScreencastVisibility(bool visible
);
87 void InnerSwapCompositorFrame();
88 void ScreencastFrameCaptured(const cc::CompositorFrameMetadata
& metadata
,
89 const SkBitmap
& bitmap
,
90 ReadbackResponse response
);
91 void ScreencastFrameEncoded(const cc::CompositorFrameMetadata
& metadata
,
92 const base::Time
& timestamp
,
93 const std::string
& data
);
95 void ScreenshotCaptured(
96 DevToolsCommandId command_id
,
97 const unsigned char* png_data
,
100 void OnColorPicked(int r
, int g
, int b
, int a
);
102 // NotificationObserver overrides.
103 void Observe(int type
,
104 const NotificationSource
& source
,
105 const NotificationDetails
& details
) override
;
109 bool screencast_enabled_
;
110 std::string screencast_format_
;
111 int screencast_quality_
;
112 int screencast_max_width_
;
113 int screencast_max_height_
;
114 int capture_retry_count_
;
115 bool has_compositor_frame_metadata_
;
116 cc::CompositorFrameMetadata next_compositor_frame_metadata_
;
117 cc::CompositorFrameMetadata last_compositor_frame_metadata_
;
118 int screencast_frame_sent_
;
119 int screencast_frame_acked_
;
120 bool processing_screencast_frame_
;
122 scoped_ptr
<ColorPicker
> color_picker_
;
124 RenderFrameHostImpl
* host_
;
125 scoped_ptr
<Client
> client_
;
126 ScreencastListener
* screencast_listener_
;
127 NotificationRegistrar registrar_
;
128 base::WeakPtrFactory
<PageHandler
> weak_factory_
;
130 DISALLOW_COPY_AND_ASSIGN(PageHandler
);
134 } // namespace devtools
135 } // namespace content
137 #endif // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_PAGE_HANDLER_H_