OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_WEB_VIEW_FRAME_H_ | 5 #ifndef COMPONENTS_WEB_VIEW_FRAME_H_ |
6 #define COMPONENTS_WEB_VIEW_FRAME_H_ | 6 #define COMPONENTS_WEB_VIEW_FRAME_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 namespace web_view { | 21 namespace web_view { |
22 | 22 |
23 class FrameTest; | 23 class FrameTest; |
24 class FrameTree; | 24 class FrameTree; |
25 class FrameUserData; | 25 class FrameUserData; |
26 | 26 |
27 namespace mojom { | 27 namespace mojom { |
28 class FrameClient; | 28 class FrameClient; |
29 } | 29 } |
30 | 30 |
31 enum class ViewOwnership { | 31 enum class WindowOwnership { |
32 OWNS_VIEW, | 32 OWNS_WINDOW, |
33 DOESNT_OWN_VIEW, | 33 DOESNT_OWN_WINDOW, |
34 }; | 34 }; |
35 | 35 |
36 // Frame represents an embedding in a frame. Frames own their children. | 36 // Frame represents an embedding in a frame. Frames own their children. |
37 // Frames automatically delete themself if the View the frame is associated | 37 // Frames automatically delete themself if the Window the frame is associated |
38 // with is deleted. | 38 // with is deleted. |
39 // | 39 // |
40 // In general each Frame has a View. When a new Frame is created by a client | 40 // In general each Frame has a Window. When a new Frame is created by a client |
41 // there may be a small amount of time where the View is not yet known | 41 // there may be a small amount of time where the Window is not yet known |
42 // (separate pipes are used for the view and frame, resulting in undefined | 42 // (separate pipes are used for the window and frame, resulting in undefined |
43 // message ordering). In this case the view is null and will be set once we | 43 // message ordering). In this case the window is null and will be set once we |
44 // see the view (OnTreeChanged()). | 44 // see the window (OnTreeChanged()). |
45 // | 45 // |
46 // Each frame has an identifier of the app providing the FrameClient | 46 // Each frame has an identifier of the app providing the FrameClient |
47 // (|app_id|). This id is used when servicing a request to navigate the frame. | 47 // (|app_id|). This id is used when servicing a request to navigate the frame. |
48 // When navigating, if the id of the new app matches that of the existing app, | 48 // When navigating, if the id of the new app matches that of the existing app, |
49 // then it is expected that the new FrameClient will take over rendering to the | 49 // then it is expected that the new FrameClient will take over rendering to the |
50 // existing view. Because of this a new WindowTreeClient is not obtained and | 50 // existing window. Because of this a new WindowTreeClient is not obtained and |
51 // Embed() is not invoked on the View. The FrameClient can detect this case by | 51 // Embed() is not invoked on the Window. The FrameClient can detect this case by |
52 // the argument |reuse_existing_view| supplied to OnConnect(). Typically the id | 52 // the argument |reuse_existing_view| supplied to OnConnect(). Typically the id |
53 // is that of content handler id, but this is left up to the FrameTreeDelegate | 53 // is that of content handler id, but this is left up to the FrameTreeDelegate |
54 // to decide. | 54 // to decide. |
55 class Frame : public mus::WindowObserver, public mojom::Frame { | 55 class Frame : public mus::WindowObserver, public mojom::Frame { |
56 public: | 56 public: |
57 using ClientPropertyMap = std::map<std::string, std::vector<uint8_t>>; | 57 using ClientPropertyMap = std::map<std::string, std::vector<uint8_t>>; |
58 using FindCallback = mojo::Callback<void(bool)>; | 58 using FindCallback = mojo::Callback<void(bool)>; |
59 | 59 |
60 Frame(FrameTree* tree, | 60 Frame(FrameTree* tree, |
61 mus::Window* view, | 61 mus::Window* window, |
62 uint32_t frame_id, | 62 uint32_t frame_id, |
63 uint32_t app_id, | 63 uint32_t app_id, |
64 ViewOwnership view_ownership, | 64 WindowOwnership window_ownership, |
65 mojom::FrameClient* frame_client, | 65 mojom::FrameClient* frame_client, |
66 scoped_ptr<FrameUserData> user_data, | 66 scoped_ptr<FrameUserData> user_data, |
67 const ClientPropertyMap& client_properties); | 67 const ClientPropertyMap& client_properties); |
68 ~Frame() override; | 68 ~Frame() override; |
69 | 69 |
70 void Init(Frame* parent, | 70 void Init(Frame* parent, |
71 mus::mojom::WindowTreeClientPtr window_tree_client, | 71 mus::mojom::WindowTreeClientPtr window_tree_client, |
72 mojo::InterfaceRequest<mojom::Frame> frame_request, | 72 mojo::InterfaceRequest<mojom::Frame> frame_request, |
73 base::TimeTicks navigation_start_time); | 73 base::TimeTicks navigation_start_time); |
74 | 74 |
75 // Walks the View tree starting at |view| going up returning the first | 75 // Walks the Window tree starting at |window| going up returning the first |
76 // Frame that is associated with |view|. For example, if |view| | 76 // Frame that is associated with |window|. For example, if |window| |
77 // has a Frame associated with it, then that is returned. Otherwise | 77 // has a Frame associated with it, then that is returned. Otherwise |
78 // this checks view->parent() and so on. | 78 // this checks window->parent() and so on. |
79 static Frame* FindFirstFrameAncestor(mus::Window* view); | 79 static Frame* FindFirstFrameAncestor(mus::Window* window); |
80 | 80 |
81 FrameTree* tree() { return tree_; } | 81 FrameTree* tree() { return tree_; } |
82 | 82 |
83 Frame* parent() { return parent_; } | 83 Frame* parent() { return parent_; } |
84 const Frame* parent() const { return parent_; } | 84 const Frame* parent() const { return parent_; } |
85 | 85 |
86 mus::Window* view() { return view_; } | 86 mus::Window* window() { return window_; } |
87 const mus::Window* view() const { return view_; } | 87 const mus::Window* window() const { return window_; } |
88 | 88 |
89 uint32_t id() const { return id_; } | 89 uint32_t id() const { return id_; } |
90 | 90 |
91 uint32_t app_id() const { return app_id_; } | 91 uint32_t app_id() const { return app_id_; } |
92 | 92 |
93 bool loading() const { return loading_; } | 93 bool loading() const { return loading_; } |
94 | 94 |
95 const ClientPropertyMap& client_properties() const { | 95 const ClientPropertyMap& client_properties() const { |
96 return client_properties_; | 96 return client_properties_; |
97 } | 97 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 base::TimeTicks navigation_start_time); | 180 base::TimeTicks navigation_start_time); |
181 | 181 |
182 // Completes a navigation request; swapping the existing FrameClient to the | 182 // Completes a navigation request; swapping the existing FrameClient to the |
183 // supplied arguments. | 183 // supplied arguments. |
184 void ChangeClient(mojom::FrameClient* frame_client, | 184 void ChangeClient(mojom::FrameClient* frame_client, |
185 scoped_ptr<FrameUserData> user_data, | 185 scoped_ptr<FrameUserData> user_data, |
186 mus::mojom::WindowTreeClientPtr window_tree_client, | 186 mus::mojom::WindowTreeClientPtr window_tree_client, |
187 uint32 app_id, | 187 uint32 app_id, |
188 base::TimeTicks navigation_start_time); | 188 base::TimeTicks navigation_start_time); |
189 | 189 |
190 void SetView(mus::Window* view); | 190 void SetWindow(mus::Window* window); |
191 | 191 |
192 // Adds this to |frames| and recurses through the children calling the | 192 // Adds this to |frames| and recurses through the children calling the |
193 // same function. | 193 // same function. |
194 void BuildFrameTree(std::vector<const Frame*>* frames) const; | 194 void BuildFrameTree(std::vector<const Frame*>* frames) const; |
195 | 195 |
196 void Add(Frame* node); | 196 void Add(Frame* node); |
197 void Remove(Frame* node); | 197 void Remove(Frame* node); |
198 | 198 |
199 // Starts a new navigation to |request|. The navigation proceeds as long | 199 // Starts a new navigation to |request|. The navigation proceeds as long |
200 // as there is a View and once OnWillNavigate() has returned. If there is | 200 // as there is a Window and once OnWillNavigate() has returned. If there is |
201 // no View the navigation waits until the View is available. | 201 // no Window the navigation waits until the Window is available. |
202 void StartNavigate(mojo::URLRequestPtr request); | 202 void StartNavigate(mojo::URLRequestPtr request); |
203 void OnCanNavigateFrame(const GURL& url, | 203 void OnCanNavigateFrame(const GURL& url, |
204 base::TimeTicks navigation_start_time, | 204 base::TimeTicks navigation_start_time, |
205 uint32_t app_id, | 205 uint32_t app_id, |
206 mojom::FrameClient* frame_client, | 206 mojom::FrameClient* frame_client, |
207 scoped_ptr<FrameUserData> user_data, | 207 scoped_ptr<FrameUserData> user_data, |
208 mus::mojom::WindowTreeClientPtr window_tree_client); | 208 mus::mojom::WindowTreeClientPtr window_tree_client); |
209 | 209 |
210 // Notifies the client and all descendants as appropriate. | 210 // Notifies the client and all descendants as appropriate. |
211 void NotifyAdded(const Frame* source, | 211 void NotifyAdded(const Frame* source, |
212 const Frame* added_node, | 212 const Frame* added_node, |
213 uint32_t change_id); | 213 uint32_t change_id); |
214 void NotifyRemoved(const Frame* source, | 214 void NotifyRemoved(const Frame* source, |
215 const Frame* removed_node, | 215 const Frame* removed_node, |
216 uint32_t change_id); | 216 uint32_t change_id); |
217 void NotifyClientPropertyChanged(const Frame* source, | 217 void NotifyClientPropertyChanged(const Frame* source, |
218 const mojo::String& name, | 218 const mojo::String& name, |
219 const mojo::Array<uint8_t>& value); | 219 const mojo::Array<uint8_t>& value); |
220 void NotifyFrameLoadingStateChanged(const Frame* frame, bool loading); | 220 void NotifyFrameLoadingStateChanged(const Frame* frame, bool loading); |
221 void NotifyDispatchFrameLoadEvent(const Frame* frame); | 221 void NotifyDispatchFrameLoadEvent(const Frame* frame); |
222 | 222 |
223 // mus::WindowObserver: | 223 // mus::WindowObserver: |
224 void OnTreeChanged(const TreeChangeParams& params) override; | 224 void OnTreeChanged(const TreeChangeParams& params) override; |
225 void OnWindowDestroying(mus::Window* view) override; | 225 void OnWindowDestroying(mus::Window* window) override; |
226 void OnWindowEmbeddedAppDisconnected(mus::Window* view) override; | 226 void OnWindowEmbeddedAppDisconnected(mus::Window* window) override; |
227 | 227 |
228 // mojom::Frame: | 228 // mojom::Frame: |
229 void PostMessageEventToFrame(uint32_t target_frame_id, | 229 void PostMessageEventToFrame(uint32_t target_frame_id, |
230 mojom::HTMLMessageEventPtr event) override; | 230 mojom::HTMLMessageEventPtr event) override; |
231 void LoadingStateChanged(bool loading, double progress) override; | 231 void LoadingStateChanged(bool loading, double progress) override; |
232 void TitleChanged(const mojo::String& title) override; | 232 void TitleChanged(const mojo::String& title) override; |
233 void DidCommitProvisionalLoad() override; | 233 void DidCommitProvisionalLoad() override; |
234 void SetClientProperty(const mojo::String& name, | 234 void SetClientProperty(const mojo::String& name, |
235 mojo::Array<uint8_t> value) override; | 235 mojo::Array<uint8_t> value) override; |
236 void OnCreatedFrame( | 236 void OnCreatedFrame( |
237 mojo::InterfaceRequest<mojom::Frame> frame_request, | 237 mojo::InterfaceRequest<mojom::Frame> frame_request, |
238 mojom::FrameClientPtr client, | 238 mojom::FrameClientPtr client, |
239 uint32_t frame_id, | 239 uint32_t frame_id, |
240 mojo::Map<mojo::String, mojo::Array<uint8_t>> client_properties) override; | 240 mojo::Map<mojo::String, mojo::Array<uint8_t>> client_properties) override; |
241 void RequestNavigate(mojom::NavigationTargetType target_type, | 241 void RequestNavigate(mojom::NavigationTargetType target_type, |
242 uint32_t target_frame_id, | 242 uint32_t target_frame_id, |
243 mojo::URLRequestPtr request) override; | 243 mojo::URLRequestPtr request) override; |
244 void DidNavigateLocally(const mojo::String& url) override; | 244 void DidNavigateLocally(const mojo::String& url) override; |
245 void DispatchLoadEventToParent() override; | 245 void DispatchLoadEventToParent() override; |
246 void OnFindInFrameCountUpdated(int32_t request_id, | 246 void OnFindInFrameCountUpdated(int32_t request_id, |
247 int32_t count, | 247 int32_t count, |
248 bool final_update) override; | 248 bool final_update) override; |
249 void OnFindInPageSelectionUpdated(int32_t request_id, | 249 void OnFindInPageSelectionUpdated(int32_t request_id, |
250 int32_t active_match_ordinal) override; | 250 int32_t active_match_ordinal) override; |
251 | 251 |
252 FrameTree* const tree_; | 252 FrameTree* const tree_; |
253 // WARNING: this may be null. See class description for details. | 253 // WARNING: this may be null. See class description for details. |
254 mus::Window* view_; | 254 mus::Window* window_; |
255 // The connection id returned from ViewManager::Embed(). Frames created by | 255 // The connection id returned from WindowManager::Embed(). Frames created by |
256 // way of OnCreatedFrame() inherit the id from the parent. | 256 // way of OnCreatedFrame() inherit the id from the parent. |
257 mus::ConnectionSpecificId embedded_connection_id_; | 257 mus::ConnectionSpecificId embedded_connection_id_; |
258 // ID for the frame, which is the same as that of the view. | 258 // ID for the frame, which is the same as that of the window. |
259 const uint32_t id_; | 259 const uint32_t id_; |
260 // ID of the app providing the FrameClient and WindowTreeClient. | 260 // ID of the app providing the FrameClient and WindowTreeClient. |
261 uint32_t app_id_; | 261 uint32_t app_id_; |
262 Frame* parent_; | 262 Frame* parent_; |
263 ViewOwnership view_ownership_; | 263 WindowOwnership window_ownership_; |
264 std::vector<Frame*> children_; | 264 std::vector<Frame*> children_; |
265 scoped_ptr<FrameUserData> user_data_; | 265 scoped_ptr<FrameUserData> user_data_; |
266 | 266 |
267 mojom::FrameClient* frame_client_; | 267 mojom::FrameClient* frame_client_; |
268 | 268 |
269 bool loading_; | 269 bool loading_; |
270 double progress_; | 270 double progress_; |
271 | 271 |
272 ClientPropertyMap client_properties_; | 272 ClientPropertyMap client_properties_; |
273 | 273 |
274 // StartNavigate() stores the request here if the view isn't available at | 274 // StartNavigate() stores the request here if the window isn't available at |
275 // the time of StartNavigate(). | 275 // the time of StartNavigate(). |
276 mojo::URLRequestPtr pending_navigate_; | 276 mojo::URLRequestPtr pending_navigate_; |
277 | 277 |
278 scoped_ptr<mojo::Binding<mojom::Frame>> frame_binding_; | 278 scoped_ptr<mojo::Binding<mojom::Frame>> frame_binding_; |
279 | 279 |
280 // True if waiting on callback from FrameClient::OnWillNavigate(). | 280 // True if waiting on callback from FrameClient::OnWillNavigate(). |
281 bool waiting_for_on_will_navigate_ack_; | 281 bool waiting_for_on_will_navigate_ack_; |
282 | 282 |
283 base::WeakPtrFactory<Frame> embed_weak_ptr_factory_; | 283 base::WeakPtrFactory<Frame> embed_weak_ptr_factory_; |
284 | 284 |
285 base::WeakPtrFactory<Frame> navigate_weak_ptr_factory_; | 285 base::WeakPtrFactory<Frame> navigate_weak_ptr_factory_; |
286 | 286 |
287 DISALLOW_COPY_AND_ASSIGN(Frame); | 287 DISALLOW_COPY_AND_ASSIGN(Frame); |
288 }; | 288 }; |
289 | 289 |
290 } // namespace web_view | 290 } // namespace web_view |
291 | 291 |
292 #endif // COMPONENTS_WEB_VIEW_FRAME_H_ | 292 #endif // COMPONENTS_WEB_VIEW_FRAME_H_ |
OLD | NEW |