blob: 3ba7601f9f03ab24f899d87a11f64015f37f80ef [file] [log] [blame]
dgozman1137e622017-04-17 19:49:121// 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.
4
5#ifndef CHROME_BROWSER_DEVTOOLS_DEVTOOLS_EYE_DROPPER_H_
6#define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_EYE_DROPPER_H_
7
Yuri Wiitalafc5fe702018-06-20 06:14:008#include <memory>
9
dgozman1137e622017-04-17 19:49:1210#include "base/callback.h"
11#include "base/macros.h"
Saman Samid2dc25f2018-05-24 20:41:0712#include "components/viz/host/client_frame_sink_video_capturer.h"
dgozman1137e622017-04-17 19:49:1213#include "content/public/browser/render_widget_host.h"
14#include "content/public/browser/web_contents_observer.h"
15#include "third_party/skia/include/core/SkBitmap.h"
16
17namespace blink {
18class WebMouseEvent;
19}
20
Saman Sami2acabd12018-03-10 00:51:0921class DevToolsEyeDropper : public content::WebContentsObserver,
22 public viz::mojom::FrameSinkVideoConsumer {
dgozman1137e622017-04-17 19:49:1223 public:
24 typedef base::Callback<void(int, int, int, int)> EyeDropperCallback;
25
26 DevToolsEyeDropper(content::WebContents* web_contents,
27 EyeDropperCallback callback);
28 ~DevToolsEyeDropper() override;
29
30 private:
31 void AttachToHost(content::RenderWidgetHost* host);
32 void DetachFromHost();
33
34 // content::WebContentsObserver.
dgozman1137e622017-04-17 19:49:1235 void RenderViewCreated(content::RenderViewHost* host) override;
36 void RenderViewDeleted(content::RenderViewHost* host) override;
37 void RenderViewHostChanged(content::RenderViewHost* old_host,
38 content::RenderViewHost* new_host) override;
39
dgozman1137e622017-04-17 19:49:1240 void ResetFrame();
Yuri Wiitala6a4443f02018-02-27 22:29:2741 void FrameUpdated(const SkBitmap&);
dgozman1137e622017-04-17 19:49:1242 bool HandleMouseEvent(const blink::WebMouseEvent& event);
43 void UpdateCursor();
44
Saman Sami2acabd12018-03-10 00:51:0945 // viz::mojom::FrameSinkVideoConsumer implementation.
46 void OnFrameCaptured(
Yuri Wiitala4a74fb02018-08-29 06:09:3547 base::ReadOnlySharedMemoryRegion data,
Saman Sami2acabd12018-03-10 00:51:0948 ::media::mojom::VideoFrameInfoPtr info,
Saman Sami2acabd12018-03-10 00:51:0949 const gfx::Rect& content_rect,
50 viz::mojom::FrameSinkVideoConsumerFrameCallbacksPtr callbacks) override;
Saman Sami2acabd12018-03-10 00:51:0951 void OnStopped() override;
52
dgozman1137e622017-04-17 19:49:1253 EyeDropperCallback callback_;
54 SkBitmap frame_;
55 int last_cursor_x_;
56 int last_cursor_y_;
57 content::RenderWidgetHost::MouseEventCallback mouse_event_callback_;
58 content::RenderWidgetHost* host_;
Saman Samid2dc25f2018-05-24 20:41:0759 std::unique_ptr<viz::ClientFrameSinkVideoCapturer> video_capturer_;
Jeremy Roman495db682019-07-12 16:03:2460 base::WeakPtrFactory<DevToolsEyeDropper> weak_factory_{this};
dgozman1137e622017-04-17 19:49:1261
62 DISALLOW_COPY_AND_ASSIGN(DevToolsEyeDropper);
63};
64
65#endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_EYE_DROPPER_H_