forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathheadless_web_contents_impl.h
169 lines (135 loc) · 5.96 KB
/
headless_web_contents_impl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef HEADLESS_LIB_BROWSER_HEADLESS_WEB_CONTENTS_IMPL_H_
#define HEADLESS_LIB_BROWSER_HEADLESS_WEB_CONTENTS_IMPL_H_
#include <memory>
#include <set>
#include <string>
#include "base/memory/scoped_refptr.h"
#include "base/observer_list.h"
#include "components/viz/common/frame_sinks/begin_frame_args.h"
#include "content/public/browser/devtools_agent_host_observer.h"
#include "content/public/browser/render_process_host_observer.h"
#include "content/public/browser/web_contents_observer.h"
#include "headless/lib/browser/headless_window_tree_host.h"
#include "headless/public/headless_devtools_target.h"
#include "headless/public/headless_export.h"
#include "headless/public/headless_web_contents.h"
class SkBitmap;
namespace content {
class DevToolsAgentHost;
class WebContents;
}
namespace gfx {
class Rect;
}
namespace headless {
class HeadlessBrowser;
class HeadlessBrowserImpl;
// Exported for tests.
class HEADLESS_EXPORT HeadlessWebContentsImpl
: public HeadlessWebContents,
public HeadlessDevToolsTarget,
public content::DevToolsAgentHostObserver,
public content::RenderProcessHostObserver,
public content::WebContentsObserver {
public:
~HeadlessWebContentsImpl() override;
static HeadlessWebContentsImpl* From(HeadlessWebContents* web_contents);
static HeadlessWebContentsImpl* From(HeadlessBrowser* browser,
content::WebContents* contents);
static std::unique_ptr<HeadlessWebContentsImpl> Create(
HeadlessWebContents::Builder* builder);
// Takes ownership of |child_contents|.
static std::unique_ptr<HeadlessWebContentsImpl> CreateForChildContents(
HeadlessWebContentsImpl* parent,
std::unique_ptr<content::WebContents> child_contents);
// HeadlessWebContents implementation:
void AddObserver(Observer* observer) override;
void RemoveObserver(Observer* observer) override;
HeadlessDevToolsTarget* GetDevToolsTarget() override;
int GetMainFrameRenderProcessId() const override;
int GetMainFrameTreeNodeId() const override;
std::string GetMainFrameDevToolsId() const override;
std::unique_ptr<HeadlessDevToolsChannel> CreateDevToolsChannel() override;
// HeadlessDevToolsTarget implementation:
void AttachClient(HeadlessDevToolsClient* client) override;
void DetachClient(HeadlessDevToolsClient* client) override;
bool IsAttached() override;
// content::DevToolsAgentHostObserver implementation:
void DevToolsAgentHostAttached(
content::DevToolsAgentHost* agent_host) override;
void DevToolsAgentHostDetached(
content::DevToolsAgentHost* agent_host) override;
// content::RenderProcessHostObserver implementation:
void RenderProcessExited(
content::RenderProcessHost* host,
const content::ChildProcessTerminationInfo& info) override;
void RenderProcessHostDestroyed(content::RenderProcessHost* host) override;
// content::WebContentsObserver implementation:
void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override;
void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override;
void RenderViewReady() override;
content::WebContents* web_contents() const;
bool OpenURL(const GURL& url);
void Close() override;
std::string GetDevToolsAgentHostId();
HeadlessBrowserImpl* browser() const;
HeadlessBrowserContextImpl* browser_context() const;
void set_window_tree_host(std::unique_ptr<HeadlessWindowTreeHost> host) {
window_tree_host_ = std::move(host);
}
HeadlessWindowTreeHost* window_tree_host() const {
return window_tree_host_.get();
}
int window_id() const { return window_id_; }
void set_window_state(const std::string& state) {
DCHECK(state == "normal" || state == "minimized" || state == "maximized" ||
state == "fullscreen");
window_state_ = state;
}
const std::string& window_state() const { return window_state_; }
// Set bounds of WebContent's platform window.
void SetBounds(const gfx::Rect& bounds);
bool begin_frame_control_enabled() const {
return begin_frame_control_enabled_;
}
using FrameFinishedCallback =
base::OnceCallback<void(bool /* has_damage */,
std::unique_ptr<SkBitmap>,
std::string /* error_message*/)>;
void BeginFrame(const base::TimeTicks& frame_timeticks,
const base::TimeTicks& deadline,
const base::TimeDelta& interval,
bool animate_only,
bool capture_screenshot,
FrameFinishedCallback frame_finished_callback);
private:
// Takes ownership of |web_contents|.
HeadlessWebContentsImpl(std::unique_ptr<content::WebContents> web_contents,
HeadlessBrowserContextImpl* browser_context);
void InitializeWindow(const gfx::Rect& initial_bounds);
uint64_t begin_frame_sequence_number_ =
viz::BeginFrameArgs::kStartingFrameNumber;
bool begin_frame_control_enabled_ = false;
HeadlessBrowserContextImpl* browser_context_; // Not owned.
// TODO(alexclarke): With OOPIF there may be more than one renderer, we need
// to fix this. See crbug.com/715924
content::RenderProcessHost* render_process_host_; // Not owned.
class Delegate;
std::unique_ptr<Delegate> web_contents_delegate_;
std::unique_ptr<HeadlessWindowTreeHost> window_tree_host_;
int window_id_ = 0;
std::string window_state_;
std::unique_ptr<content::WebContents> web_contents_;
scoped_refptr<content::DevToolsAgentHost> agent_host_;
bool devtools_target_ready_notification_sent_ = false;
bool render_process_exited_ = false;
base::ObserverList<HeadlessWebContents::Observer>::Unchecked observers_;
class PendingFrame;
base::WeakPtr<PendingFrame> pending_frame_;
DISALLOW_COPY_AND_ASSIGN(HeadlessWebContentsImpl);
};
} // namespace headless
#endif // HEADLESS_LIB_BROWSER_HEADLESS_WEB_CONTENTS_IMPL_H_