File: pdf_view_web_plugin_client.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 (121 lines) | stat: -rw-r--r-- 4,672 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
117
118
119
120
121
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_PDF_RENDERER_PDF_VIEW_WEB_PLUGIN_CLIENT_H_
#define COMPONENTS_PDF_RENDERER_PDF_VIEW_WEB_PLUGIN_CLIENT_H_

#include <memory>

#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "pdf/pdf_view_web_plugin.h"
#include "services/screen_ai/public/mojom/screen_ai_service.mojom.h"

namespace blink {
class WebLocalFrame;
class WebPluginContainer;
}  // namespace blink

namespace content {
class RenderFrame;
class V8ValueConverter;
}  // namespace content

namespace v8 {
class Isolate;
}  // namespace v8

namespace pdf {

class PdfViewWebPluginClient : public chrome_pdf::PdfViewWebPlugin::Client {
 public:
  explicit PdfViewWebPluginClient(content::RenderFrame* render_frame);
  PdfViewWebPluginClient(const PdfViewWebPluginClient&) = delete;
  PdfViewWebPluginClient& operator=(const PdfViewWebPluginClient&) = delete;
  ~PdfViewWebPluginClient() override;

  // chrome_pdf::PdfViewWebPlugin::Client:
  std::unique_ptr<base::Value> FromV8Value(
      v8::Local<v8::Value> value,
      v8::Local<v8::Context> context) override;
  base::WeakPtr<chrome_pdf::PdfViewWebPlugin::Client> GetWeakPtr() override;
  void SetPluginContainer(blink::WebPluginContainer* container) override;
  blink::WebPluginContainer* PluginContainer() override;
  v8::Isolate* GetIsolate() override;
  net::SiteForCookies SiteForCookies() const override;
  blink::WebURL CompleteURL(const blink::WebString& partial_url) const override;
  void PostMessage(base::Value::Dict message) override;
  void Invalidate() override;
  void RequestTouchEventType(
      blink::WebPluginContainer::TouchEventRequestType request_type) override;
  void ReportFindInPageMatchCount(int identifier,
                                  int total,
                                  bool final_update) override;
  void ReportFindInPageSelection(int identifier,
                                 int index,
                                 bool final_update) override;
  void ReportFindInPageTickmarks(
      const std::vector<gfx::Rect>& tickmarks) override;
  float DeviceScaleFactor() override;
  gfx::PointF GetScrollPosition() override;
  void UsePluginAsFindHandler() override;
  void SetReferrerForRequest(blink::WebURLRequest& request,
                             const blink::WebURL& referrer_url) override;
  void Alert(const blink::WebString& message) override;
  bool Confirm(const blink::WebString& message) override;
  blink::WebString Prompt(const blink::WebString& message,
                          const blink::WebString& default_value) override;
  void TextSelectionChanged(const blink::WebString& selection_text,
                            uint32_t offset,
                            const gfx::Range& range) override;
  std::unique_ptr<blink::WebAssociatedURLLoader> CreateAssociatedURLLoader(
      const blink::WebAssociatedURLLoaderOptions& options) override;
  void UpdateTextInputState() override;
  void UpdateSelectionBounds() override;
  std::string GetEmbedderOriginString() override;
  bool HasFrame() const override;
  void DidStartLoading() override;
  void DidStopLoading() override;
  void Print() override;
  void RecordComputedAction(const std::string& action) override;
  std::unique_ptr<chrome_pdf::PdfAccessibilityDataHandler>
  CreateAccessibilityDataHandler(
      chrome_pdf::PdfAccessibilityActionHandler* action_handler,
      blink::WebPluginContainer* plugin_element) override;
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
  void GetOcrMaxImageDimension(
      base::OnceCallback<void(uint32_t)> callback) override;
  void PerformOcr(
      const SkBitmap& image,
      base::OnceCallback<void(screen_ai::mojom::VisualAnnotationPtr)> callback)
      override;
  void SetOcrDisconnectedCallback(base::RepeatingClosure callback) override;
#endif

 private:
  blink::WebLocalFrame* GetFrame() const;

#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
  void OnOcrDisconnected();
  void ConnectOcrIfNeeded();
#endif

  const raw_ptr<content::RenderFrame> render_frame_;

  const std::unique_ptr<content::V8ValueConverter> v8_value_converter_;
  const raw_ptr<v8::Isolate> isolate_;

  raw_ptr<blink::WebPluginContainer> plugin_container_;

  mojo::Remote<screen_ai::mojom::ScreenAIAnnotator> screen_ai_annotator_;
  base::RepeatingClosure ocr_disconnect_callback_;

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

}  // namespace pdf

#endif  // COMPONENTS_PDF_RENDERER_PDF_VIEW_WEB_PLUGIN_CLIENT_H_