OLD | NEW |
| (Empty) |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef COMPONENTS_HTML_VIEWER_DOCUMENT_RESOURCE_WAITER_H_ | |
6 #define COMPONENTS_HTML_VIEWER_DOCUMENT_RESOURCE_WAITER_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include "base/macros.h" | |
11 #include "base/time/time.h" | |
12 #include "components/html_viewer/html_frame_tree_manager_observer.h" | |
13 #include "components/mus/public/cpp/window_observer.h" | |
14 #include "components/web_view/public/interfaces/frame.mojom.h" | |
15 #include "mojo/public/cpp/bindings/binding.h" | |
16 #include "mojo/services/network/public/interfaces/url_loader.mojom.h" | |
17 | |
18 namespace html_viewer { | |
19 | |
20 class HTMLDocument; | |
21 class HTMLFrameTreeManager; | |
22 class GlobalState; | |
23 | |
24 // DocumentResourceWaiter waits for the necessary resources needed to load an | |
25 // HTMLDocument. Once ready it calls to HTMLDocument::Load(). Once ready it is | |
26 // assumed HTMLDocument will call back for the FrameClient and FrameData. | |
27 class DocumentResourceWaiter : public web_view::mojom::FrameClient, | |
28 public HTMLFrameTreeManagerObserver, | |
29 public mus::WindowObserver { | |
30 public: | |
31 DocumentResourceWaiter(GlobalState* global_state, | |
32 mojo::URLResponsePtr response, | |
33 HTMLDocument* document); | |
34 ~DocumentResourceWaiter() override; | |
35 | |
36 // Releases all the resources that have been accumulated. | |
37 void Release(mojo::InterfaceRequest<web_view::mojom::FrameClient>* | |
38 frame_client_request, | |
39 web_view::mojom::FramePtr* frame, | |
40 mojo::Array<web_view::mojom::FrameDataPtr>* frame_data, | |
41 uint32_t* window_id, | |
42 uint32_t* change_id, | |
43 web_view::mojom::WindowConnectType* window_connect_type, | |
44 OnConnectCallback* on_connect_callback); | |
45 | |
46 uint32_t change_id() const { return change_id_; } | |
47 | |
48 mojo::URLResponsePtr ReleaseURLResponse(); | |
49 | |
50 // See class description. | |
51 bool is_ready() const { return is_ready_; } | |
52 | |
53 base::TimeTicks navigation_start_time() const { | |
54 return navigation_start_time_; | |
55 } | |
56 | |
57 void SetRoot(mus::Window* root); | |
58 mus::Window* root() { return root_; } | |
59 | |
60 void Bind(mojo::InterfaceRequest<web_view::mojom::FrameClient> request); | |
61 | |
62 private: | |
63 // Updates |is_ready_|, and if ready starts the Load() in the document. | |
64 void UpdateIsReady(); | |
65 | |
66 // web_view::mojom::FrameClient: | |
67 void OnConnect(web_view::mojom::FramePtr frame, | |
68 uint32_t change_id, | |
69 uint32_t window_id, | |
70 web_view::mojom::WindowConnectType window_connect_type, | |
71 mojo::Array<web_view::mojom::FrameDataPtr> frame_data, | |
72 int64_t navigation_start_time_ticks, | |
73 const OnConnectCallback& callback) override; | |
74 void OnFrameAdded(uint32_t change_id, | |
75 web_view::mojom::FrameDataPtr frame_data) override; | |
76 void OnFrameRemoved(uint32_t change_id, uint32_t frame_id) override; | |
77 void OnFrameClientPropertyChanged(uint32_t frame_id, | |
78 const mojo::String& name, | |
79 mojo::Array<uint8_t> new_value) override; | |
80 void OnPostMessageEvent(uint32_t source_frame_id, | |
81 uint32_t target_frame_id, | |
82 web_view::mojom::HTMLMessageEventPtr event) override; | |
83 void OnWillNavigate(const mojo::String& origin, | |
84 const OnWillNavigateCallback& callback) override; | |
85 void OnFrameLoadingStateChanged(uint32_t frame_id, bool loading) override; | |
86 void OnDispatchFrameLoadEvent(uint32_t frame_id) override; | |
87 void Find(int32_t request_id, | |
88 const mojo::String& search_text, | |
89 web_view::mojom::FindOptionsPtr options, | |
90 bool wrap_within_frame, | |
91 const FindCallback& callback) override; | |
92 void StopFinding(bool clear_selection) override; | |
93 void HighlightFindResults(int32_t request_id, | |
94 const mojo::String& search_test, | |
95 web_view::mojom::FindOptionsPtr options, | |
96 bool reset) override; | |
97 void StopHighlightingFindResults() override; | |
98 | |
99 // WindowObserver: | |
100 void OnWindowViewportMetricsChanged( | |
101 mus::Window* window, | |
102 const mus::mojom::ViewportMetrics& old_metrics, | |
103 const mus::mojom::ViewportMetrics& new_metrics) override; | |
104 void OnWindowDestroyed(mus::Window* window) override; | |
105 | |
106 // HTMLFrameTreeManagerObserver: | |
107 void OnHTMLFrameTreeManagerChangeIdAdvanced() override; | |
108 void OnHTMLFrameTreeManagerDestroyed() override; | |
109 | |
110 GlobalState* global_state_; | |
111 HTMLDocument* document_; | |
112 mojo::URLResponsePtr response_; | |
113 mus::Window* root_; | |
114 web_view::mojom::FramePtr frame_; | |
115 mojo::Array<web_view::mojom::FrameDataPtr> frame_data_; | |
116 uint32_t change_id_; | |
117 uint32_t window_id_; | |
118 base::TimeTicks navigation_start_time_; | |
119 web_view::mojom::WindowConnectType window_connect_type_; | |
120 OnConnectCallback on_connect_callback_; | |
121 | |
122 // Once we get OnConnect() we unbind |frame_client_binding_| and put it here. | |
123 mojo::InterfaceRequest<web_view::mojom::FrameClient> frame_client_request_; | |
124 mojo::Binding<web_view::mojom::FrameClient> frame_client_binding_; | |
125 | |
126 bool is_ready_; | |
127 | |
128 // See comments in UpdateIsReady() for details of this. | |
129 // | |
130 // While |waiting_for_change_id_| is true DocumentResourceWaiter is an | |
131 // HTMLFrameTreeManagerObserver on |target_frame_tree_|. | |
132 bool waiting_for_change_id_; | |
133 | |
134 HTMLFrameTreeManager* target_frame_tree_; | |
135 | |
136 DISALLOW_COPY_AND_ASSIGN(DocumentResourceWaiter); | |
137 }; | |
138 | |
139 } // namespace html_viewer | |
140 | |
141 #endif // COMPONENTS_HTML_VIEWER_DOCUMENT_RESOURCE_WAITER_H_ | |
OLD | NEW |