| 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 29 matching lines...) Expand all Loading... |
| 40 // In general each Frame has a View. When a new Frame is created by a client | 40 // In general each Frame has a View. 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 View is not yet known |
| 42 // (separate pipes are used for the view and frame, resulting in undefined | 42 // (separate pipes are used for the view 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 view is null and will be set once we |
| 44 // see the view (OnTreeChanged()). | 44 // see the view (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 ViewTreeClient is not obtained and | 50 // existing view. 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 View. 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* view, |
| 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 ViewOwnership view_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 mojo::ViewTreeClientPtr view_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 View tree starting at |view| going up returning the first |
| 76 // Frame that is associated with |view|. For example, if |view| | 76 // Frame that is associated with |view|. For example, if |view| |
| 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 view->parent() and so on. |
| 79 static Frame* FindFirstFrameAncestor(mus::Window* view); | 79 static Frame* FindFirstFrameAncestor(mus::Window* view); |
| 80 | 80 |
| 81 FrameTree* tree() { return tree_; } | 81 FrameTree* tree() { return tree_; } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 // |data_and_binding| contains the current FrameUserDataAndBinding (if any) | 152 // |data_and_binding| contains the current FrameUserDataAndBinding (if any) |
| 153 // and is destroyed after the connection responds to OnConnect(). | 153 // and is destroyed after the connection responds to OnConnect(). |
| 154 // | 154 // |
| 155 // If |client_type| is SAME_APP we can't destroy the existing client | 155 // If |client_type| is SAME_APP we can't destroy the existing client |
| 156 // (and related data) until we get back the ack from OnConnect(). This way | 156 // (and related data) until we get back the ack from OnConnect(). This way |
| 157 // we know the client has completed the switch. If we did not do this it | 157 // we know the client has completed the switch. If we did not do this it |
| 158 // would be possible for the app to see it's existing Frame connection lost | 158 // would be possible for the app to see it's existing Frame connection lost |
| 159 // (and assume the frame is being torn down) before the OnConnect(). | 159 // (and assume the frame is being torn down) before the OnConnect(). |
| 160 void InitClient(ClientType client_type, | 160 void InitClient(ClientType client_type, |
| 161 scoped_ptr<FrameUserDataAndBinding> data_and_binding, | 161 scoped_ptr<FrameUserDataAndBinding> data_and_binding, |
| 162 mojo::ViewTreeClientPtr view_tree_client, | 162 mus::mojom::WindowTreeClientPtr window_tree_client, |
| 163 mojo::InterfaceRequest<mojom::Frame> frame_request, | 163 mojo::InterfaceRequest<mojom::Frame> frame_request, |
| 164 base::TimeTicks navigation_start_time); | 164 base::TimeTicks navigation_start_time); |
| 165 | 165 |
| 166 // Callback from OnConnect(). This does nothing (other than destroying | 166 // Callback from OnConnect(). This does nothing (other than destroying |
| 167 // |data_and_binding|). See InitClient() for details as to why destruction of | 167 // |data_and_binding|). See InitClient() for details as to why destruction of |
| 168 // |data_and_binding| happens after OnConnect(). | 168 // |data_and_binding| happens after OnConnect(). |
| 169 static void OnConnectAck( | 169 static void OnConnectAck( |
| 170 scoped_ptr<FrameUserDataAndBinding> data_and_binding); | 170 scoped_ptr<FrameUserDataAndBinding> data_and_binding); |
| 171 | 171 |
| 172 // Callback from OnEmbed(). | 172 // Callback from OnEmbed(). |
| 173 void OnEmbedAck(bool success, mus::ConnectionSpecificId connection_id); | 173 void OnEmbedAck(bool success, mus::ConnectionSpecificId connection_id); |
| 174 | 174 |
| 175 // Callback from Frame::OnWillNavigate(). Completes navigation. | 175 // Callback from Frame::OnWillNavigate(). Completes navigation. |
| 176 void OnWillNavigateAck(mojom::FrameClient* frame_client, | 176 void OnWillNavigateAck(mojom::FrameClient* frame_client, |
| 177 scoped_ptr<FrameUserData> user_data, | 177 scoped_ptr<FrameUserData> user_data, |
| 178 mojo::ViewTreeClientPtr view_tree_client, | 178 mus::mojom::WindowTreeClientPtr window_tree_client, |
| 179 uint32 app_id, | 179 uint32 app_id, |
| 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 mojo::ViewTreeClientPtr view_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 SetView(mus::Window* view); |
| 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 View and once OnWillNavigate() has returned. If there is |
| 201 // no View the navigation waits until the View is available. | 201 // no View the navigation waits until the View 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 mojo::ViewTreeClientPtr view_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, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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* view_; |
| 255 // The connection id returned from ViewManager::Embed(). Frames created by | 255 // The connection id returned from ViewManager::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 view. |
| 259 const uint32_t id_; | 259 const uint32_t id_; |
| 260 // ID of the app providing the FrameClient and ViewTreeClient. | 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 ViewOwnership view_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_; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 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 |