blob: 8f1c532092d46c59c2fbe5b77a7538933e5328d9 [file] [log] [blame]
Brian Silverman4e662aa2022-05-11 23:10:19 -07001// Copyright 2021 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
6// option. This file may not be copied, modified, or distributed
7// except according to those terms.
8
9#pragma once
10#include <memory>
11#include <string>
12#include <vector>
13
14// This is supposed to be a _fairly_ faithful representation of a few
15// Chromium codebase APIs. Just enough that we can start to experiment
16// with ownership patterns.
17
18namespace content {
19
20class RenderFrameHost {
21public:
22 static RenderFrameHost *FromId(int process_id, int frame_id);
23 virtual int GetRoutingID() = 0;
24
25 /// Returns the assigned name of the frame, the name of the iframe tag
26 /// declaring it. For example, <iframe name="framename">[...]</iframe>. It is
27 /// quite possible for a frame to have no name, in which case GetFrameName
28 /// will return an empty string.
29 virtual std::string GetFrameName() = 0;
30 virtual ~RenderFrameHost() {}
31};
32
33class CreateParams {
34public:
35 CreateParams(const std::string &);
36 std::string main_frame_name_;
37};
38
39class WebContentsObserver;
40
41class WebContents {
42public:
43 static std::unique_ptr<WebContents> Create(const CreateParams &params);
44
45 static WebContents *FromFrameTreeNodeId(int frame_tree_node_id);
46
47 // TODO - should not be in WebContents, just WebContentsImpl
48 virtual void AddObserver(WebContentsObserver *) {}
49 virtual void RemoveObserver(WebContentsObserver *) {}
50
51 virtual ~WebContents(){};
52
53 virtual const std::string &GetTitle() = 0;
54};
55
56class WebContentsObserver {
57public:
58 virtual void RenderFrameCreated(RenderFrameHost *) {}
59 virtual void RenderFrameDeleted(RenderFrameHost *) {}
60 virtual ~WebContentsObserver() {}
61};
62
63class WebContentsImpl : public WebContents {
64public:
65 void AddObserver(WebContentsObserver *);
66 void RemoveObserver(WebContentsObserver *);
67 const std::string &GetTitle();
68 WebContentsImpl(const CreateParams &);
69 void DeleteRFH();
70
71private:
72 std::string title_;
73 std::vector<WebContentsObserver *> observers_;
74 std::vector<std::unique_ptr<RenderFrameHost>> rfhs_;
75};
76} // namespace content
77
78void SimulateRendererShutdown(int frame_id);