File: printer_query_oop.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (116 lines) | stat: -rw-r--r-- 4,475 bytes parent folder | download | duplicates (3)
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
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_PRINTING_PRINTER_QUERY_OOP_H_
#define CHROME_BROWSER_PRINTING_PRINTER_QUERY_OOP_H_

#include <memory>
#include <optional>

#include "base/functional/callback.h"
#include "base/types/expected.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/printing/print_backend_service_manager.h"
#include "chrome/browser/printing/print_job_worker_oop.h"
#include "chrome/browser/printing/printer_query.h"
#include "chrome/services/printing/public/mojom/print_backend_service.mojom.h"
#include "printing/buildflags/buildflags.h"
#include "printing/mojom/print.mojom.h"
#include "printing/print_settings.h"
#include "printing/printing_context.h"

namespace printing {

class PrinterQueryOop : public PrinterQuery {
 public:
  explicit PrinterQueryOop(content::GlobalRenderFrameHostId rfh_id);
  ~PrinterQueryOop() override;

  // PrinterQuery overrides:
  std::unique_ptr<PrintJobWorker> TransferContextToNewWorker(
      PrintJob* print_job) override;
#if BUILDFLAG(IS_WIN)
  void UpdatePrintableArea(PrintSettings* print_settings,
                           OnDidUpdatePrintableAreaCallback callback) override;
#endif
  void SetClientId(PrintBackendServiceManager::ClientId client_id) override;

 protected:
  // Local callback wrappers for Print Backend Service mojom call.  Some
  // wrappers are virtual to support testing.
  virtual void OnDidUseDefaultSettings(
      SettingsCallback callback,
      base::expected<PrintSettings, mojom::ResultCode> print_settings);
#if BUILDFLAG(ENABLE_OOP_BASIC_PRINT_DIALOG)
  virtual void OnDidAskUserForSettings(
      SettingsCallback callback,
      base::expected<PrintSettings, mojom::ResultCode> print_settings);
#else
  virtual void OnDidAskUserForSettings(
      SettingsCallback callback,
      std::unique_ptr<PrintSettings> new_settings,
      mojom::ResultCode result);
#endif
  virtual void OnDidUpdatePrintSettings(
      const std::string& device_name,
      SettingsCallback callback,
      base::expected<PrintSettings, mojom::ResultCode> print_settings);
#if BUILDFLAG(IS_WIN)
  void OnDidGetPaperPrintableArea(PrintSettings* print_settings,
                                  OnDidUpdatePrintableAreaCallback callback,
                                  const gfx::Rect& printable_area_um);
#endif

  void UseDefaultSettings(SettingsCallback callback) override;
  void GetSettingsWithUI(uint32_t document_page_count,
                         bool has_selection,
                         bool is_scripted,
                         SettingsCallback callback) override;
  void UpdatePrintSettings(base::Value::Dict new_settings,
                           SettingsCallback callback) override;

  // Mojo support to send messages from UI thread.
  void SendEstablishPrintingContext(
      PrintBackendServiceManager::ClientId client_id,
      const std::string& printer_name);
  void SendUpdatePrintSettings(const std::string& printer_name,
                               base::Value::Dict new_settings,
                               SettingsCallback callback);
  void SendUseDefaultSettings(SettingsCallback callback);
#if BUILDFLAG(ENABLE_OOP_BASIC_PRINT_DIALOG)
  void SendAskUserForSettings(uint32_t document_page_count,
                              bool has_selection,
                              bool is_scripted,
                              SettingsCallback callback);
#endif

  // Used by `TransferContextToNewWorker()`.  Virtual to support testing.
  virtual std::unique_ptr<PrintJobWorkerOop> CreatePrintJobWorkerOop(
      PrintJob* print_job);

  const std::optional<PrintBackendServiceManager::ClientId>&
  print_document_client_id() const {
    return print_document_client_id_;
  }

  bool print_from_system_dialog() const { return print_from_system_dialog_; }

  const std::optional<PrintBackendServiceManager::ContextId>& context_id()
      const {
    return context_id_;
  }

 private:
  bool print_from_system_dialog_ = false;
  std::optional<PrintBackendServiceManager::ClientId> query_with_ui_client_id_;
  std::optional<PrintBackendServiceManager::ClientId> print_document_client_id_;
  std::optional<PrintBackendServiceManager::ContextId> context_id_;

  base::WeakPtrFactory<PrinterQueryOop> weak_factory_{this};
};

}  // namespace printing

#endif  // CHROME_BROWSER_PRINTING_PRINTER_QUERY_OOP_H_