Brian Silverman | 4e662aa | 2022-05-11 23:10:19 -0700 | [diff] [blame^] | 1 | // 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 | |
| 18 | namespace content { |
| 19 | |
| 20 | class RenderFrameHost { |
| 21 | public: |
| 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 | |
| 33 | class CreateParams { |
| 34 | public: |
| 35 | CreateParams(const std::string &); |
| 36 | std::string main_frame_name_; |
| 37 | }; |
| 38 | |
| 39 | class WebContentsObserver; |
| 40 | |
| 41 | class WebContents { |
| 42 | public: |
| 43 | static std::unique_ptr<WebContents> Create(const CreateParams ¶ms); |
| 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 | |
| 56 | class WebContentsObserver { |
| 57 | public: |
| 58 | virtual void RenderFrameCreated(RenderFrameHost *) {} |
| 59 | virtual void RenderFrameDeleted(RenderFrameHost *) {} |
| 60 | virtual ~WebContentsObserver() {} |
| 61 | }; |
| 62 | |
| 63 | class WebContentsImpl : public WebContents { |
| 64 | public: |
| 65 | void AddObserver(WebContentsObserver *); |
| 66 | void RemoveObserver(WebContentsObserver *); |
| 67 | const std::string &GetTitle(); |
| 68 | WebContentsImpl(const CreateParams &); |
| 69 | void DeleteRFH(); |
| 70 | |
| 71 | private: |
| 72 | std::string title_; |
| 73 | std::vector<WebContentsObserver *> observers_; |
| 74 | std::vector<std::unique_ptr<RenderFrameHost>> rfhs_; |
| 75 | }; |
| 76 | } // namespace content |
| 77 | |
| 78 | void SimulateRendererShutdown(int frame_id); |