-
Notifications
You must be signed in to change notification settings - Fork 822
/
page_content_extractor.h
81 lines (63 loc) · 2.9 KB
/
page_content_extractor.h
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
// Copyright (c) 2023 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.
#ifndef BRAVE_COMPONENTS_AI_CHAT_RENDERER_PAGE_CONTENT_EXTRACTOR_H_
#define BRAVE_COMPONENTS_AI_CHAT_RENDERER_PAGE_CONTENT_EXTRACTOR_H_
#include <cstdint>
#include <memory>
#include <optional>
#include <string>
#include "base/values.h"
#include "brave/components/ai_chat/core/common/mojom/page_content_extractor.mojom.h"
#include "brave/components/ai_chat/renderer/ai_chat_resource_sniffer_throttle_delegate.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_frame_observer.h"
#include "content/public/renderer/render_frame_observer_tracker.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
namespace ai_chat {
class PageContentExtractor
: public ai_chat::mojom::PageContentExtractor,
public content::RenderFrameObserver,
public content::RenderFrameObserverTracker<PageContentExtractor>,
public AIChatResourceSnifferThrottleDelegate {
public:
PageContentExtractor(content::RenderFrame* render_frame,
service_manager::BinderRegistry* registry,
int32_t global_world_id,
int32_t isolated_world_id);
PageContentExtractor(const PageContentExtractor&) = delete;
PageContentExtractor& operator=(const PageContentExtractor&) = delete;
~PageContentExtractor() override;
base::WeakPtr<PageContentExtractor> GetWeakPtr();
private:
void OnJSTranscriptUrlResult(
mojom::PageContentExtractor::ExtractPageContentCallback callback,
ai_chat::mojom::PageContentType type,
std::optional<base::Value> value,
base::TimeTicks start_time);
void OnDistillResult(
mojom::PageContentExtractor::ExtractPageContentCallback callback,
const std::optional<std::string>& content);
// RenderFrameObserver implementation:
void OnDestruct() override;
// PageContentExtractor implementation:
void ExtractPageContent(
mojom::PageContentExtractor::ExtractPageContentCallback callback)
override;
// AIChatResourceSnifferThrottleDelegate
void OnInterceptedPageContentChanged(
std::unique_ptr<AIChatResourceSnifferThrottleDelegate::InterceptedContent>
content_update) override;
void BindReceiver(
mojo::PendingReceiver<mojom::PageContentExtractor> receiver);
mojo::Receiver<mojom::PageContentExtractor> receiver_{this};
int32_t global_world_id_;
int32_t isolated_world_id_;
std::unique_ptr<AIChatResourceSnifferThrottleDelegate::InterceptedContent>
intercepted_content_;
base::WeakPtrFactory<PageContentExtractor> weak_ptr_factory_{this};
};
} // namespace ai_chat
#endif // BRAVE_COMPONENTS_AI_CHAT_RENDERER_PAGE_CONTENT_EXTRACTOR_H_