OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_GUEST_VIEW_BROWSER_GUEST_VIEW_MANAGER_H_ | 5 #ifndef COMPONENTS_GUEST_VIEW_BROWSER_GUEST_VIEW_MANAGER_H_ |
6 #define COMPONENTS_GUEST_VIEW_BROWSER_GUEST_VIEW_MANAGER_H_ | 6 #define COMPONENTS_GUEST_VIEW_BROWSER_GUEST_VIEW_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
| 9 #include <set> |
9 #include <vector> | 10 #include <vector> |
10 | 11 |
11 #include "base/bind.h" | 12 #include "base/bind.h" |
12 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
13 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/weak_ptr.h" |
15 #include "content/public/browser/browser_plugin_guest_manager.h" | 17 #include "content/public/browser/browser_plugin_guest_manager.h" |
16 #include "content/public/browser/site_instance.h" | 18 #include "content/public/browser/site_instance.h" |
17 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
18 | 20 |
19 class GURL; | 21 class GURL; |
20 | 22 |
21 namespace content { | 23 namespace content { |
22 class BrowserContext; | 24 class BrowserContext; |
23 class WebContents; | 25 class WebContents; |
24 } // namespace content | 26 } // namespace content |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 bool ForEachGuest(content::WebContents* owner_web_contents, | 127 bool ForEachGuest(content::WebContents* owner_web_contents, |
126 const GuestCallback& callback) override; | 128 const GuestCallback& callback) override; |
127 content::WebContents* GetFullPageGuest( | 129 content::WebContents* GetFullPageGuest( |
128 content::WebContents* embedder_web_contents) override; | 130 content::WebContents* embedder_web_contents) override; |
129 | 131 |
130 protected: | 132 protected: |
131 friend class GuestViewBase; | 133 friend class GuestViewBase; |
132 friend class GuestViewEvent; | 134 friend class GuestViewEvent; |
133 friend class GuestViewMessageFilter; | 135 friend class GuestViewMessageFilter; |
134 | 136 |
| 137 class EmbedderRenderProcessHostObserver; |
| 138 |
135 // These methods are virtual so that they can be overriden in tests. | 139 // These methods are virtual so that they can be overriden in tests. |
136 | 140 |
137 virtual void AddGuest(int guest_instance_id, | 141 virtual void AddGuest(int guest_instance_id, |
138 content::WebContents* guest_web_contents); | 142 content::WebContents* guest_web_contents); |
139 virtual void RemoveGuest(int guest_instance_id); | 143 virtual void RemoveGuest(int guest_instance_id); |
140 | 144 |
141 // This method is called when the embedder process with ID | 145 // This method is called when the embedder process with ID |
142 // |embedder_process_id| is about to be destroyed. | 146 // |embedder_process_id| has been destroyed. |
143 virtual void EmbedderWillBeDestroyed(int embedder_process_id); | 147 virtual void EmbedderProcessDestroyed(int embedder_process_id); |
144 | 148 |
145 // Called when a GuestView has been created in JavaScript. | 149 // Called when a GuestView has been created in JavaScript. |
146 virtual void ViewCreated(int embedder_process_id, | 150 virtual void ViewCreated(int embedder_process_id, |
147 int view_instance_id, | 151 int view_instance_id, |
148 const std::string& view_type); | 152 const std::string& view_type); |
149 | 153 |
150 // Called when a GuestView has been garbage collected in JavaScript. | 154 // Called when a GuestView has been garbage collected in JavaScript. |
151 virtual void ViewGarbageCollected(int embedder_process_id, | 155 virtual void ViewGarbageCollected(int embedder_process_id, |
152 int view_instance_id); | 156 int view_instance_id); |
153 | 157 |
| 158 // Calls all destruction callbacks registered for the GuestView identified by |
| 159 // |embedder_process_id| and |view_instance_id|. |
| 160 void CallViewDestructionCallbacks(int embedder_process_id, |
| 161 int view_instance_id); |
| 162 |
| 163 // Calls all destruction callbacks registered for GuestViews in the embedder |
| 164 // with ID |embedder_process_id|. |
| 165 void CallViewDestructionCallbacks(int embedder_process_id); |
| 166 |
154 // Creates a guest of the provided |view_type|. | 167 // Creates a guest of the provided |view_type|. |
155 GuestViewBase* CreateGuestInternal(content::WebContents* owner_web_contents, | 168 GuestViewBase* CreateGuestInternal(content::WebContents* owner_web_contents, |
156 const std::string& view_type); | 169 const std::string& view_type); |
157 | 170 |
158 // Adds GuestView types to the GuestView registry. | 171 // Adds GuestView types to the GuestView registry. |
159 void RegisterGuestViewTypes(); | 172 void RegisterGuestViewTypes(); |
160 | 173 |
161 // Indicates whether the provided |guest| can be used in the context it has | 174 // Indicates whether the provided |guest| can be used in the context it has |
162 // been created. | 175 // been created. |
163 bool IsGuestAvailableToContext(GuestViewBase* guest); | 176 bool IsGuestAvailableToContext(GuestViewBase* guest); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 | 221 |
209 using GuestInstanceIDMap = std::map<ElementInstanceKey, int>; | 222 using GuestInstanceIDMap = std::map<ElementInstanceKey, int>; |
210 GuestInstanceIDMap instance_id_map_; | 223 GuestInstanceIDMap instance_id_map_; |
211 | 224 |
212 // The reverse map of GuestInstanceIDMap. | 225 // The reverse map of GuestInstanceIDMap. |
213 using GuestInstanceIDReverseMap = std::map<int, ElementInstanceKey>; | 226 using GuestInstanceIDReverseMap = std::map<int, ElementInstanceKey>; |
214 GuestInstanceIDReverseMap reverse_instance_id_map_; | 227 GuestInstanceIDReverseMap reverse_instance_id_map_; |
215 | 228 |
216 using GuestViewCreateFunction = | 229 using GuestViewCreateFunction = |
217 base::Callback<GuestViewBase*(content::WebContents*)>; | 230 base::Callback<GuestViewBase*(content::WebContents*)>; |
218 using GuestViewCleanUpFunction = base::Callback<void(int, int)>; | 231 using GuestViewCleanUpFunction = |
| 232 base::Callback<void(content::BrowserContext*, int, int)>; |
219 struct GuestViewData { | 233 struct GuestViewData { |
220 GuestViewData(const GuestViewCreateFunction& create_function, | 234 GuestViewData(const GuestViewCreateFunction& create_function, |
221 const GuestViewCleanUpFunction& cleanup_function); | 235 const GuestViewCleanUpFunction& cleanup_function); |
222 ~GuestViewData(); | 236 ~GuestViewData(); |
223 const GuestViewCreateFunction create_function; | 237 const GuestViewCreateFunction create_function; |
224 const GuestViewCleanUpFunction cleanup_function; | 238 const GuestViewCleanUpFunction cleanup_function; |
225 }; | 239 }; |
226 using GuestViewMethodMap = std::map<std::string, GuestViewData>; | 240 using GuestViewMethodMap = std::map<std::string, GuestViewData>; |
227 GuestViewMethodMap guest_view_registry_; | 241 GuestViewMethodMap guest_view_registry_; |
228 | 242 |
229 int current_instance_id_; | 243 int current_instance_id_; |
230 | 244 |
231 // Any instance ID whose number not greater than this was removed via | 245 // Any instance ID whose number not greater than this was removed via |
232 // RemoveGuest. | 246 // RemoveGuest. |
233 // This is used so that we don't have store all removed instance IDs in | 247 // This is used so that we don't have store all removed instance IDs in |
234 // |removed_instance_ids_|. | 248 // |removed_instance_ids_|. |
235 int last_instance_id_removed_; | 249 int last_instance_id_removed_; |
236 // The remaining instance IDs that are greater than | 250 // The remaining instance IDs that are greater than |
237 // |last_instance_id_removed_| are kept here. | 251 // |last_instance_id_removed_| are kept here. |
238 std::set<int> removed_instance_ids_; | 252 std::set<int> removed_instance_ids_; |
239 | 253 |
240 content::BrowserContext* context_; | 254 content::BrowserContext* context_; |
241 | 255 |
242 scoped_ptr<GuestViewManagerDelegate> delegate_; | 256 scoped_ptr<GuestViewManagerDelegate> delegate_; |
243 | 257 |
| 258 // This tracks which GuestView embedders are currently being observed. |
| 259 std::set<int> embedders_observed_; |
| 260 |
244 // |view_destruction_callback_map_| maps from embedder process ID to view ID | 261 // |view_destruction_callback_map_| maps from embedder process ID to view ID |
245 // to a vector of callback functions to be called when that view is destroyed. | 262 // to a vector of callback functions to be called when that view is destroyed. |
246 using Callbacks = std::vector<base::Closure> ; | 263 using Callbacks = std::vector<base::Closure> ; |
247 using CallbacksForEachViewID = std::map<int, Callbacks> ; | 264 using CallbacksForEachViewID = std::map<int, Callbacks> ; |
248 using CallbacksForEachEmbedderID = std::map<int, CallbacksForEachViewID> ; | 265 using CallbacksForEachEmbedderID = std::map<int, CallbacksForEachViewID> ; |
249 CallbacksForEachEmbedderID view_destruction_callback_map_; | 266 CallbacksForEachEmbedderID view_destruction_callback_map_; |
250 | 267 |
| 268 // This is used to ensure that an EmbedderRenderProcessHostObserver will not |
| 269 // call into this GuestViewManager after it has been destroyed. |
| 270 base::WeakPtrFactory<GuestViewManager> weak_ptr_factory_; |
| 271 |
251 DISALLOW_COPY_AND_ASSIGN(GuestViewManager); | 272 DISALLOW_COPY_AND_ASSIGN(GuestViewManager); |
252 }; | 273 }; |
253 | 274 |
254 } // namespace guest_view | 275 } // namespace guest_view |
255 | 276 |
256 #endif // COMPONETS_GUEST_VIEW_BROWSER_GUEST_VIEW_MANAGER_H_ | 277 #endif // COMPONETS_GUEST_VIEW_BROWSER_GUEST_VIEW_MANAGER_H_ |
OLD | NEW |