blob: 7f4ac8617f1ef792f4f342ef38edda9976f7163d (
plain)
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
|
// 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_BROWSER_IMPL_H_
#define HEADLESS_LIB_BROWSER_HEADLESS_BROWSER_IMPL_H_
#include "base/memory/raw_ptr.h"
#include "headless/public/headless_browser.h"
#include <memory>
#include <string>
#include <vector>
#include "base/memory/weak_ptr.h"
#include "base/task/single_thread_task_runner.h"
#include "build/build_config.h"
#include "headless/lib/browser/headless_devtools_manager_delegate.h"
#include "headless/public/headless_devtools_target.h"
#include "headless/public/headless_export.h"
#if defined(HEADLESS_USE_PREFS)
class PrefService;
#endif
#if defined(HEADLESS_USE_POLICY)
namespace policy {
class PolicyService;
} // namespace policy
#endif
#if BUILDFLAG(IS_MAC)
#include "ui/display/screen.h"
#endif
namespace ui {
class Compositor;
} // namespace ui
namespace gfx {
class Rect;
} // namespace gfx
namespace headless {
class HeadlessBrowserContextImpl;
class HeadlessBrowserMainParts;
class HeadlessRequestContextManager;
class HeadlessWebContentsImpl;
extern const base::FilePath::CharType kDefaultProfileName[];
// Exported for tests.
class HEADLESS_EXPORT HeadlessBrowserImpl : public HeadlessBrowser,
public HeadlessDevToolsTarget {
public:
HeadlessBrowserImpl(
base::OnceCallback<void(HeadlessBrowser*)> on_start_callback,
HeadlessBrowser::Options options);
HeadlessBrowserImpl(const HeadlessBrowserImpl&) = delete;
HeadlessBrowserImpl& operator=(const HeadlessBrowserImpl&) = delete;
~HeadlessBrowserImpl() override;
// HeadlessBrowser implementation:
HeadlessBrowserContext::Builder CreateBrowserContextBuilder() override;
scoped_refptr<base::SingleThreadTaskRunner> BrowserMainThread()
const override;
void Shutdown() override;
std::vector<HeadlessBrowserContext*> GetAllBrowserContexts() override;
HeadlessWebContents* GetWebContentsForDevToolsAgentHostId(
const std::string& devtools_agent_host_id) override;
HeadlessBrowserContext* GetBrowserContextForId(
const std::string& id) override;
void SetDefaultBrowserContext(
HeadlessBrowserContext* browser_context) override;
HeadlessBrowserContext* GetDefaultBrowserContext() override;
HeadlessDevToolsTarget* GetDevToolsTarget() override;
std::unique_ptr<HeadlessDevToolsChannel> CreateDevToolsChannel() override;
// HeadlessDevToolsTarget implementation:
void AttachClient(HeadlessDevToolsClient* client) override;
void DetachClient(HeadlessDevToolsClient* client) override;
bool IsAttached() override;
void set_browser_main_parts(HeadlessBrowserMainParts* browser_main_parts);
HeadlessBrowserMainParts* browser_main_parts() const;
void RunOnStartCallback();
HeadlessBrowser::Options* options() { return &options_; }
HeadlessBrowserContext* CreateBrowserContext(
HeadlessBrowserContext::Builder* builder);
// Close given |browser_context| and delete it
// (all web contents associated with it go away too).
void DestroyBrowserContext(HeadlessBrowserContextImpl* browser_context);
HeadlessWebContentsImpl* GetWebContentsForWindowId(const int window_id);
base::WeakPtr<HeadlessBrowserImpl> GetWeakPtr();
// All the methods that begin with Platform need to be implemented by the
// platform specific headless implementation.
// Helper for one time initialization of application
void PlatformInitialize();
void PlatformStart();
void PlatformInitializeWebContents(HeadlessWebContentsImpl* web_contents);
void PlatformSetWebContentsBounds(HeadlessWebContentsImpl* web_contents,
const gfx::Rect& bounds);
ui::Compositor* PlatformGetCompositor(HeadlessWebContentsImpl* web_contents);
#if defined(HEADLESS_USE_PREFS)
PrefService* GetPrefs();
#endif
#if defined(HEADLESS_USE_POLICY)
policy::PolicyService* GetPolicyService();
#endif
protected:
#if BUILDFLAG(IS_MAC)
std::unique_ptr<display::ScopedNativeScreen> screen_;
#endif
base::OnceCallback<void(HeadlessBrowser*)> on_start_callback_;
HeadlessBrowser::Options options_;
raw_ptr<HeadlessBrowserMainParts> browser_main_parts_; // Not owned.
base::flat_map<std::string, std::unique_ptr<HeadlessBrowserContextImpl>>
browser_contexts_;
raw_ptr<HeadlessBrowserContext> default_browser_context_; // Not owned.
scoped_refptr<content::DevToolsAgentHost> agent_host_;
std::unique_ptr<HeadlessRequestContextManager>
system_request_context_manager_;
base::WeakPtrFactory<HeadlessBrowserImpl> weak_ptr_factory_{this};
};
} // namespace headless
#endif // HEADLESS_LIB_BROWSER_HEADLESS_BROWSER_IMPL_H_
|