#include "headless/lib/browser/headless_web_contents_impl.h"
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/trace_event/trace_event.h"
#include "base/values.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/child_process_termination_info.h"
#include "content/public/browser/devtools_agent_host.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/renderer_preferences_util.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/common/bindings_policy.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/origin_util.h"
#include "headless/lib/browser/directory_enumerator.h"
#include "headless/lib/browser/headless_browser_context_impl.h"
#include "headless/lib/browser/headless_browser_impl.h"
#include "headless/lib/browser/headless_browser_main_parts.h"
#include "headless/lib/browser/protocol/headless_handler.h"
#include "headless/public/switches.h"
#include "printing/buildflags/buildflags.h"
#include "third_party/blink/public/common/renderer_preferences/renderer_preferences.h"
#include "third_party/blink/public/mojom/window_features/window_features.mojom.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/ui_base_features.h"
#include "ui/compositor/compositor.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/switches.h"
#if BUILDFLAG(ENABLE_PRINTING)
#include "components/printing/browser/headless/headless_print_manager.h"
#endif
namespace headless {
namespace {
void UpdatePrefsFromSystemSettings(blink::RendererPreferences* prefs) { … }
}
HeadlessWebContentsImpl* HeadlessWebContentsImpl::From(
HeadlessWebContents* web_contents) { … }
HeadlessWebContentsImpl* HeadlessWebContentsImpl::From(
HeadlessBrowser* browser,
content::WebContents* contents) { … }
class HeadlessWebContentsImpl::Delegate : public content::WebContentsDelegate { … };
namespace {
constexpr uint64_t kBeginFrameSourceId = …;
}
class HeadlessWebContentsImpl::PendingFrame final
: public base::RefCounted<HeadlessWebContentsImpl::PendingFrame> { … };
std::unique_ptr<HeadlessWebContentsImpl> HeadlessWebContentsImpl::Create(
HeadlessWebContents::Builder* builder) { … }
std::unique_ptr<HeadlessWebContentsImpl>
HeadlessWebContentsImpl::CreateForChildContents(
HeadlessWebContentsImpl* parent,
std::unique_ptr<content::WebContents> child_contents) { … }
void HeadlessWebContentsImpl::InitializeWindow(
const gfx::Rect& initial_bounds) { … }
void HeadlessWebContentsImpl::SetBounds(const gfx::Rect& bounds) { … }
HeadlessWebContentsImpl::HeadlessWebContentsImpl(
std::unique_ptr<content::WebContents> web_contents,
HeadlessBrowserContextImpl* browser_context,
bool use_tab_target)
: … { … }
HeadlessWebContentsImpl::~HeadlessWebContentsImpl() { … }
void HeadlessWebContentsImpl::RenderViewReady() { … }
bool HeadlessWebContentsImpl::OpenURL(const GURL& url) { … }
void HeadlessWebContentsImpl::Close() { … }
std::string HeadlessWebContentsImpl::GetDevToolsAgentHostId() { … }
void HeadlessWebContentsImpl::AddObserver(Observer* observer) { … }
void HeadlessWebContentsImpl::RemoveObserver(Observer* observer) { … }
void HeadlessWebContentsImpl::RenderProcessExited(
content::RenderProcessHost* host,
const content::ChildProcessTerminationInfo& info) { … }
void HeadlessWebContentsImpl::RenderProcessHostDestroyed(
content::RenderProcessHost* host) { … }
content::WebContents* HeadlessWebContentsImpl::web_contents() const { … }
HeadlessBrowserImpl* HeadlessWebContentsImpl::browser() const { … }
HeadlessBrowserContextImpl* HeadlessWebContentsImpl::browser_context() const { … }
void HeadlessWebContentsImpl::BeginFrame(
const base::TimeTicks& frame_timeticks,
const base::TimeTicks& deadline,
const base::TimeDelta& interval,
bool animate_only,
bool capture_screenshot,
FrameFinishedCallback frame_finished_callback) { … }
HeadlessWebContents::Builder::Builder(
HeadlessBrowserContextImpl* browser_context)
: … { … }
HeadlessWebContents::Builder::~Builder() = default;
HeadlessWebContents::Builder::Builder(Builder&&) = default;
HeadlessWebContents::Builder& HeadlessWebContents::Builder::SetInitialURL(
const GURL& initial_url) { … }
HeadlessWebContents::Builder& HeadlessWebContents::Builder::SetWindowSize(
const gfx::Size& size) { … }
HeadlessWebContents::Builder&
HeadlessWebContents::Builder::SetEnableBeginFrameControl(
bool enable_begin_frame_control) { … }
HeadlessWebContents::Builder& HeadlessWebContents::Builder::SetUseTabTarget(
bool use_tab_target) { … }
HeadlessWebContents* HeadlessWebContents::Builder::Build() { … }
}