| 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_HTML_FRAME_TREE_MANAGER_H_ | |
| 6 #define COMPONENTS_HTML_VIEWER_HTML_FRAME_TREE_MANAGER_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include <map> | |
| 11 #include <set> | |
| 12 | |
| 13 #include "base/macros.h" | |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/memory/weak_ptr.h" | |
| 16 #include "base/observer_list.h" | |
| 17 #include "components/web_view/public/interfaces/frame.mojom.h" | |
| 18 | |
| 19 namespace blink { | |
| 20 class WebView; | |
| 21 } | |
| 22 | |
| 23 namespace mus { | |
| 24 class Window; | |
| 25 } | |
| 26 | |
| 27 namespace html_viewer { | |
| 28 | |
| 29 class DocumentResourceWaiter; | |
| 30 class GlobalState; | |
| 31 class HTMLFrame; | |
| 32 class HTMLFrameDelegate; | |
| 33 class HTMLFrameTreeManagerObserver; | |
| 34 | |
| 35 // HTMLFrameTreeManager is responsible for managing the frames that comprise a | |
| 36 // document. Some of the frames may be remote. HTMLFrameTreeManager updates its | |
| 37 // state in response to changes from the server Frame, as well as changes | |
| 38 // from the underlying frames. The frame tree has at least one local frame | |
| 39 // that is backed by a mus::Window. | |
| 40 class HTMLFrameTreeManager { | |
| 41 public: | |
| 42 // Returns a new HTMLFrame or null if a HTMLFrame does not need to be created. | |
| 43 // If this returns non-null the caller owns the return value and must call | |
| 44 // Close() when done. | |
| 45 static HTMLFrame* CreateFrameAndAttachToTree( | |
| 46 GlobalState* global_state, | |
| 47 mus::Window* window, | |
| 48 scoped_ptr<DocumentResourceWaiter> resource_waiter, | |
| 49 HTMLFrameDelegate* delegate); | |
| 50 | |
| 51 // Returns the HTMLFrameTreeManager with the specified root id. | |
| 52 static HTMLFrameTreeManager* FindFrameTreeWithRoot(uint32_t root_frame_id); | |
| 53 | |
| 54 GlobalState* global_state() { return global_state_; } | |
| 55 | |
| 56 blink::WebView* GetWebView(); | |
| 57 | |
| 58 // Ever increasing value that is used to identify the state the tree is in. | |
| 59 // That is, the value increases every time a structural change is made to | |
| 60 // the tree, eg add or remove. | |
| 61 uint32_t change_id() const { return change_id_; } | |
| 62 | |
| 63 void AddObserver(HTMLFrameTreeManagerObserver* observer); | |
| 64 void RemoveObserver(HTMLFrameTreeManagerObserver* observer); | |
| 65 | |
| 66 private: | |
| 67 friend class HTMLFrame; | |
| 68 class ChangeIdAdvancedNotifier; | |
| 69 using TreeMap = std::map<uint32_t, HTMLFrameTreeManager*>; | |
| 70 using ChangeIDSet = std::set<uint32_t>; | |
| 71 | |
| 72 explicit HTMLFrameTreeManager(GlobalState* global_state); | |
| 73 ~HTMLFrameTreeManager(); | |
| 74 | |
| 75 void Init(HTMLFrameDelegate* delegate, | |
| 76 mus::Window* local_window, | |
| 77 const mojo::Array<web_view::mojom::FrameDataPtr>& frame_data, | |
| 78 uint32_t change_id); | |
| 79 | |
| 80 // Creates a Frame per FrameData element in |frame_data|. Returns the root. | |
| 81 HTMLFrame* BuildFrameTree( | |
| 82 HTMLFrameDelegate* delegate, | |
| 83 const mojo::Array<web_view::mojom::FrameDataPtr>& frame_data, | |
| 84 uint32_t local_frame_id, | |
| 85 mus::Window* local_window); | |
| 86 | |
| 87 // Returns this HTMLFrameTreeManager from |instances_|. | |
| 88 void RemoveFromInstances(); | |
| 89 | |
| 90 // Invoked when a Frame is destroyed. | |
| 91 void OnFrameDestroyed(HTMLFrame* frame); | |
| 92 | |
| 93 // Call before applying a structure change from the server. |source| is the | |
| 94 // the source of the change, and |change_id| the id from the server. Returns | |
| 95 // true if the change should be applied, false otherwise. | |
| 96 bool PrepareForStructureChange(HTMLFrame* source, uint32_t change_id); | |
| 97 | |
| 98 // Each HTMLFrame delegates FrameClient methods to the HTMLFrameTreeManager | |
| 99 // the frame is in. HTMLFrameTreeManager only responds to changes from the | |
| 100 // |local_frame_| (this is because each FrameClient sees the same change, and | |
| 101 // a change only need be processed once). | |
| 102 void ProcessOnFrameAdded(HTMLFrame* source, | |
| 103 uint32_t change_id, | |
| 104 web_view::mojom::FrameDataPtr frame_data); | |
| 105 void ProcessOnFrameRemoved(HTMLFrame* source, | |
| 106 uint32_t change_id, | |
| 107 uint32_t frame_id); | |
| 108 void ProcessOnFrameClientPropertyChanged(HTMLFrame* source, | |
| 109 uint32_t frame_id, | |
| 110 const mojo::String& name, | |
| 111 mojo::Array<uint8_t> new_data); | |
| 112 | |
| 113 // Finds a new local frame which satisfies: | |
| 114 // - it is not a descendant of |local_frame_|; | |
| 115 // - it is the highest local frame or one of the highest local frames if | |
| 116 // there are multiple. | |
| 117 HTMLFrame* FindNewLocalFrame(); | |
| 118 | |
| 119 static TreeMap* instances_; | |
| 120 | |
| 121 GlobalState* global_state_; | |
| 122 | |
| 123 HTMLFrame* root_; | |
| 124 | |
| 125 // The |local_frame_| is the HTMLFrame that is the highest frame that is | |
| 126 // local. Please note that it is not necessarily the ancestor of all local | |
| 127 // frames. | |
| 128 HTMLFrame* local_frame_; | |
| 129 | |
| 130 uint32_t change_id_; | |
| 131 | |
| 132 // When a frame is locally removed the id is added here. When the server | |
| 133 // notifies us we remove from this set. This is done to ensure an add/remove | |
| 134 // followed by notification from the server doesn't attempt to add the frame | |
| 135 // back that was locally removed. | |
| 136 ChangeIDSet pending_remove_ids_; | |
| 137 | |
| 138 // If true, we're in ProcessOnFrameRemoved(). | |
| 139 bool in_process_on_frame_removed_; | |
| 140 | |
| 141 base::ObserverList<HTMLFrameTreeManagerObserver> observers_; | |
| 142 | |
| 143 base::WeakPtrFactory<HTMLFrameTreeManager> weak_factory_; | |
| 144 | |
| 145 DISALLOW_COPY_AND_ASSIGN(HTMLFrameTreeManager); | |
| 146 }; | |
| 147 | |
| 148 } // namespace html_viewer | |
| 149 | |
| 150 #endif // COMPONENTS_HTML_VIEWER_HTML_FRAME_TREE_MANAGER_H_ | |
| OLD | NEW |