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 CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ |
6 #define CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ | 6 #define CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
| 10 #include "base/gtest_prod_util.h" |
10 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "content/public/browser/browser_plugin_guest_manager.h" | 13 #include "content/public/browser/browser_plugin_guest_manager.h" |
13 #include "content/public/browser/site_instance.h" | 14 #include "content/public/browser/site_instance.h" |
14 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
15 | 16 |
16 class GuestViewBase; | 17 class GuestViewBase; |
17 class GuestWebContentsObserver; | 18 class GuestWebContentsObserver; |
18 class GURL; | 19 class GURL; |
19 | 20 |
(...skipping 29 matching lines...) Expand all Loading... |
49 virtual void MaybeGetGuestByInstanceIDOrKill( | 50 virtual void MaybeGetGuestByInstanceIDOrKill( |
50 int guest_instance_id, | 51 int guest_instance_id, |
51 int embedder_render_process_id, | 52 int embedder_render_process_id, |
52 const GuestByInstanceIDCallback& callback) OVERRIDE; | 53 const GuestByInstanceIDCallback& callback) OVERRIDE; |
53 virtual bool ForEachGuest(content::WebContents* embedder_web_contents, | 54 virtual bool ForEachGuest(content::WebContents* embedder_web_contents, |
54 const GuestCallback& callback) OVERRIDE; | 55 const GuestCallback& callback) OVERRIDE; |
55 | 56 |
56 private: | 57 private: |
57 friend class GuestViewBase; | 58 friend class GuestViewBase; |
58 friend class GuestWebContentsObserver; | 59 friend class GuestWebContentsObserver; |
| 60 friend class TestGuestViewManager; |
| 61 FRIEND_TEST_ALL_PREFIXES(GuestViewManagerTest, AddRemove); |
59 | 62 |
60 void AddGuest(int guest_instance_id, | 63 void AddGuest(int guest_instance_id, |
61 content::WebContents* guest_web_contents); | 64 content::WebContents* guest_web_contents); |
62 | 65 |
63 void RemoveGuest(int guest_instance_id); | 66 void RemoveGuest(int guest_instance_id); |
64 | 67 |
65 void AddRenderProcessHostID(int render_process_host_id); | 68 void AddRenderProcessHostID(int render_process_host_id); |
66 | 69 |
67 content::SiteInstance* GetGuestSiteInstance( | 70 content::SiteInstance* GetGuestSiteInstance( |
68 const GURL& guest_site); | 71 const GURL& guest_site); |
69 | 72 |
70 content::WebContents* GetGuestByInstanceID( | 73 content::WebContents* GetGuestByInstanceID( |
71 int guest_instance_id, | 74 int guest_instance_id, |
72 int embedder_render_process_id); | 75 int embedder_render_process_id); |
73 | 76 |
74 bool CanEmbedderAccessInstanceIDMaybeKill( | 77 bool CanEmbedderAccessInstanceIDMaybeKill( |
75 int embedder_render_process_id, | 78 int embedder_render_process_id, |
76 int guest_instance_id); | 79 int guest_instance_id); |
77 | 80 |
78 bool CanEmbedderAccessInstanceID(int embedder_render_process_id, | 81 bool CanEmbedderAccessInstanceID(int embedder_render_process_id, |
79 int guest_instance_id); | 82 int guest_instance_id); |
80 | 83 |
| 84 // Returns true if |guest_instance_id| can be used to add a new guest to this |
| 85 // manager. |
| 86 // We disallow adding new guest with instance IDs that were previously removed |
| 87 // from this manager using RemoveGuest. |
| 88 bool CanUseGuestInstanceID(int guest_instance_id); |
| 89 |
81 static bool CanEmbedderAccessGuest(int embedder_render_process_id, | 90 static bool CanEmbedderAccessGuest(int embedder_render_process_id, |
82 GuestViewBase* guest); | 91 GuestViewBase* guest); |
83 | 92 |
84 // Counts RenderProcessHost IDs of GuestViewBases. | 93 // Counts RenderProcessHost IDs of GuestViewBases. |
85 std::multiset<int> render_process_host_id_multiset_; | 94 std::multiset<int> render_process_host_id_multiset_; |
86 | 95 |
87 // Contains guests' WebContents, mapping from their instance ids. | 96 // Contains guests' WebContents, mapping from their instance ids. |
88 typedef std::map<int, content::WebContents*> GuestInstanceMap; | 97 typedef std::map<int, content::WebContents*> GuestInstanceMap; |
89 GuestInstanceMap guest_web_contents_by_instance_id_; | 98 GuestInstanceMap guest_web_contents_by_instance_id_; |
90 | 99 |
91 int current_instance_id_; | 100 int current_instance_id_; |
| 101 |
| 102 // Any instance ID whose number not greater than this was removed via |
| 103 // RemoveGuest. |
| 104 // This is used so that we don't have store all removed instance IDs in |
| 105 // |removed_instance_ids_|. |
| 106 int last_instance_id_removed_; |
| 107 // The remaining instance IDs that are greater than |
| 108 // |last_instance_id_removed_| are kept here. |
| 109 std::set<int> removed_instance_ids_; |
| 110 |
92 content::BrowserContext* context_; | 111 content::BrowserContext* context_; |
93 | 112 |
94 DISALLOW_COPY_AND_ASSIGN(GuestViewManager); | 113 DISALLOW_COPY_AND_ASSIGN(GuestViewManager); |
95 }; | 114 }; |
96 | 115 |
97 #endif // CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ | 116 #endif // CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ |
OLD | NEW |