blob: 78b9f5b74e9b4d0f0f8d05a13fc9bba284975e18 [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2017 The Chromium Authors
Sadrul Habib Chowdhury33770462017-09-26 20:36:192// 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_PROTOCOL_PAGE_HANDLER_H_
6#define CHROME_BROWSER_DEVTOOLS_PROTOCOL_PAGE_HANDLER_H_
7
Peter Kvitek802b2be2021-08-20 20:46:118#include <memory>
9
Avi Drissman20f92412021-08-15 00:09:2010#include "base/memory/weak_ptr.h"
Sadrul Habib Chowdhury33770462017-09-26 20:36:1911#include "chrome/browser/devtools/protocol/page.h"
Wolfgang Beyerf5489332021-08-23 09:51:4112#include "components/webapps/browser/installable/installable_manager.h"
Peter Kvitek07e00302021-08-27 21:53:4213#include "content/public/browser/devtools_agent_host.h"
Wolfgang Beyerf5489332021-08-23 09:51:4114#include "content/public/browser/web_contents_observer.h"
Peter Kvitek07e00302021-08-27 21:53:4215#include "printing/buildflags/buildflags.h"
Wolfgang Beyerf5489332021-08-23 09:51:4116#include "third_party/blink/public/common/manifest/manifest.h"
Sadrul Habib Chowdhury33770462017-09-26 20:36:1917
Peter Kvitek07e00302021-08-27 21:53:4218#if BUILDFLAG(ENABLE_PRINTING)
Peter Kvitek9d9c4ef2022-07-21 18:48:5219#include "components/printing/browser/headless/headless_print_manager.h"
20#include "components/printing/browser/print_to_pdf/pdf_print_result.h"
Peter Kvitek07e00302021-08-27 21:53:4221#endif // BUILDFLAG(ENABLE_PRINTING)
22
Sadrul Habib Chowdhury33770462017-09-26 20:36:1923namespace content {
Mandy Chen290780142020-01-23 03:21:5624struct InstallabilityError;
Sadrul Habib Chowdhury33770462017-09-26 20:36:1925class WebContents;
Peter Kvitek802b2be2021-08-20 20:46:1126} // namespace content
Sadrul Habib Chowdhury33770462017-09-26 20:36:1927
Jan Scheffler2a81b322019-12-14 09:09:0028class SkBitmap;
29
Avi Drissman20f92412021-08-15 00:09:2030class PageHandler : public protocol::Page::Backend {
Sadrul Habib Chowdhury33770462017-09-26 20:36:1931 public:
Peter Kvitek07e00302021-08-27 21:53:4232 PageHandler(scoped_refptr<content::DevToolsAgentHost> agent_host,
33 content::WebContents* web_contents,
Sadrul Habib Chowdhury33770462017-09-26 20:36:1934 protocol::UberDispatcher* dispatcher);
Peter Boström53c6c5952021-09-17 09:41:2635
36 PageHandler(const PageHandler&) = delete;
37 PageHandler& operator=(const PageHandler&) = delete;
38
Sadrul Habib Chowdhury33770462017-09-26 20:36:1939 ~PageHandler() override;
40
41 void ToggleAdBlocking(bool enabled);
42
43 // Page::Backend:
44 protocol::Response Enable() override;
45 protocol::Response Disable() override;
46 protocol::Response SetAdBlockingEnabled(bool enabled) override;
Stephen McGruera3d64f2c42021-11-04 21:22:5547 protocol::Response SetSPCTransactionMode(
48 const protocol::String& mode) override;
Javier Fernández García-Boentec0e70552023-02-03 09:41:1349 protocol::Response SetRPHRegistrationMode(
50 const protocol::String& mode) override;
Pavel Feldmanc94653622019-04-11 03:02:1751 void GetInstallabilityErrors(
52 std::unique_ptr<GetInstallabilityErrorsCallback> callback) override;
Sadrul Habib Chowdhury33770462017-09-26 20:36:1953
Jan Scheffler2a81b322019-12-14 09:09:0054 void GetManifestIcons(
55 std::unique_ptr<GetManifestIconsCallback> callback) override;
56
Peter Kvitek802b2be2021-08-20 20:46:1157 void PrintToPDF(protocol::Maybe<bool> landscape,
58 protocol::Maybe<bool> display_header_footer,
59 protocol::Maybe<bool> print_background,
60 protocol::Maybe<double> scale,
61 protocol::Maybe<double> paper_width,
62 protocol::Maybe<double> paper_height,
63 protocol::Maybe<double> margin_top,
64 protocol::Maybe<double> margin_bottom,
65 protocol::Maybe<double> margin_left,
66 protocol::Maybe<double> margin_right,
67 protocol::Maybe<protocol::String> page_ranges,
Peter Kvitek802b2be2021-08-20 20:46:1168 protocol::Maybe<protocol::String> header_template,
69 protocol::Maybe<protocol::String> footer_template,
70 protocol::Maybe<bool> prefer_css_page_size,
71 protocol::Maybe<protocol::String> transfer_mode,
72 std::unique_ptr<PrintToPDFCallback> callback) override;
73
Wolfgang Beyerf5489332021-08-23 09:51:4174 void GetAppId(std::unique_ptr<GetAppIdCallback> callback) override;
75
Sadrul Habib Chowdhury33770462017-09-26 20:36:1976 private:
Pavel Feldmanc94653622019-04-11 03:02:1777 static void GotInstallabilityErrors(
78 std::unique_ptr<GetInstallabilityErrorsCallback> callback,
Mandy Chen290780142020-01-23 03:21:5679 std::vector<content::InstallabilityError> installability_errors);
Pavel Feldmanc94653622019-04-11 03:02:1780
Jan Scheffler2a81b322019-12-14 09:09:0081 static void GotManifestIcons(
82 std::unique_ptr<GetManifestIconsCallback> callback,
83 const SkBitmap* primary_icon);
84
Wolfgang Beyerf5489332021-08-23 09:51:4185 void OnDidGetManifest(std::unique_ptr<GetAppIdCallback> callback,
86 const webapps::InstallableData& data);
87
Peter Kvitek07e00302021-08-27 21:53:4288#if BUILDFLAG(ENABLE_PRINTING)
89 void OnPDFCreated(bool return_as_stream,
90 std::unique_ptr<PrintToPDFCallback> callback,
Peter Kviteka6b36c82022-07-16 00:07:1691 print_to_pdf::PdfPrintResult print_result,
Peter Kvitek07e00302021-08-27 21:53:4292 scoped_refptr<base::RefCountedMemory> data);
93#endif
94
95 scoped_refptr<content::DevToolsAgentHost> agent_host_;
Avi Drissman20f92412021-08-15 00:09:2096 base::WeakPtr<content::WebContents> web_contents_;
Peter Kvitek802b2be2021-08-20 20:46:1197
Sadrul Habib Chowdhury33770462017-09-26 20:36:1998 bool enabled_ = false;
Peter Kvitek07e00302021-08-27 21:53:4299
Wolfgang Beyerf5489332021-08-23 09:51:41100 base::WeakPtrFactory<PageHandler> weak_ptr_factory_{this};
Sadrul Habib Chowdhury33770462017-09-26 20:36:19101};
102
103#endif // CHROME_BROWSER_DEVTOOLS_PROTOCOL_PAGE_HANDLER_H_