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 EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ | 5 #ifndef EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ |
6 #define EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ | 6 #define EXTENSIONS_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/gtest_prod_util.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 // If the embedder is not allowed access, the embedder will be killed, and | 50 // If the embedder is not allowed access, the embedder will be killed, and |
51 // this method will return NULL. If no WebContents exists with the given | 51 // this method will return NULL. If no WebContents exists with the given |
52 // instance ID, then NULL will also be returned. | 52 // instance ID, then NULL will also be returned. |
53 content::WebContents* GetGuestByInstanceIDSafely( | 53 content::WebContents* GetGuestByInstanceIDSafely( |
54 int guest_instance_id, | 54 int guest_instance_id, |
55 int embedder_render_process_id); | 55 int embedder_render_process_id); |
56 | 56 |
57 // Associates the Browser Plugin with |element_instance_id| to a | 57 // Associates the Browser Plugin with |element_instance_id| to a |
58 // guest that has ID of |guest_instance_id| and sets initialization | 58 // guest that has ID of |guest_instance_id| and sets initialization |
59 // parameters, |params| for it. | 59 // parameters, |params| for it. |
60 void AttachGuest(int embedder_render_process_id, | 60 void AttachGuest(int embedder_process_id, |
61 int embedder_routing_id, | |
62 int element_instance_id, | 61 int element_instance_id, |
63 int guest_instance_id, | 62 int guest_instance_id, |
64 const base::DictionaryValue& attach_params); | 63 const base::DictionaryValue& attach_params); |
65 | 64 |
66 // Removes the association between |element_instance_id| and a guest instance | 65 // Removes the association between |element_instance_id| and a guest instance |
67 // ID if one exists. | 66 // ID if one exists. |
68 void DetachGuest(GuestViewBase* guest, int element_instance_id); | 67 void DetachGuest(GuestViewBase* guest); |
69 | 68 |
70 int GetNextInstanceID(); | 69 int GetNextInstanceID(); |
71 int GetGuestInstanceIDForElementID( | 70 int GetGuestInstanceIDForElementID( |
72 content::WebContents* owner_web_contents, | 71 int owner_process_id, |
73 int element_instance_id); | 72 int element_instance_id); |
74 | 73 |
75 using WebContentsCreatedCallback = | 74 using WebContentsCreatedCallback = |
76 base::Callback<void(content::WebContents*)>; | 75 base::Callback<void(content::WebContents*)>; |
77 void CreateGuest(const std::string& view_type, | 76 void CreateGuest(const std::string& view_type, |
78 content::WebContents* owner_web_contents, | 77 content::WebContents* owner_web_contents, |
79 const base::DictionaryValue& create_params, | 78 const base::DictionaryValue& create_params, |
80 const WebContentsCreatedCallback& callback); | 79 const WebContentsCreatedCallback& callback); |
81 | 80 |
82 content::WebContents* CreateGuestWithWebContentsParams( | 81 content::WebContents* CreateGuestWithWebContentsParams( |
83 const std::string& view_type, | 82 const std::string& view_type, |
84 content::WebContents* owner_web_contents, | 83 content::WebContents* owner_web_contents, |
85 const content::WebContents::CreateParams& create_params); | 84 const content::WebContents::CreateParams& create_params); |
86 | 85 |
87 content::SiteInstance* GetGuestSiteInstance( | 86 content::SiteInstance* GetGuestSiteInstance( |
88 const GURL& guest_site); | 87 const GURL& guest_site); |
89 | 88 |
90 // BrowserPluginGuestManager implementation. | 89 // BrowserPluginGuestManager implementation. |
91 content::WebContents* GetGuestByInstanceID( | 90 content::WebContents* GetGuestByInstanceID( |
92 content::WebContents* owner_web_contents, | 91 int owner_process_id, |
93 int element_instance_id) override; | 92 int element_instance_id) override; |
94 bool ForEachGuest(content::WebContents* owner_web_contents, | 93 bool ForEachGuest(content::WebContents* owner_web_contents, |
95 const GuestCallback& callback) override; | 94 const GuestCallback& callback) override; |
96 | 95 |
97 protected: | 96 protected: |
98 friend class GuestViewBase; | 97 friend class GuestViewBase; |
99 FRIEND_TEST_ALL_PREFIXES(GuestViewManagerTest, AddRemove); | 98 FRIEND_TEST_ALL_PREFIXES(GuestViewManagerTest, AddRemove); |
100 | 99 |
101 // Can be overriden in tests. | 100 // Can be overriden in tests. |
102 virtual void AddGuest(int guest_instance_id, | 101 virtual void AddGuest(int guest_instance_id, |
(...skipping 18 matching lines...) Expand all Loading... | |
121 bool CanUseGuestInstanceID(int guest_instance_id); | 120 bool CanUseGuestInstanceID(int guest_instance_id); |
122 | 121 |
123 // Static factory instance (always NULL for non-test). | 122 // Static factory instance (always NULL for non-test). |
124 static GuestViewManagerFactory* factory_; | 123 static GuestViewManagerFactory* factory_; |
125 | 124 |
126 // Contains guests' WebContents, mapping from their instance ids. | 125 // Contains guests' WebContents, mapping from their instance ids. |
127 using GuestInstanceMap = std::map<int, content::WebContents*>; | 126 using GuestInstanceMap = std::map<int, content::WebContents*>; |
128 GuestInstanceMap guest_web_contents_by_instance_id_; | 127 GuestInstanceMap guest_web_contents_by_instance_id_; |
129 | 128 |
130 struct ElementInstanceKey { | 129 struct ElementInstanceKey { |
131 content::WebContents* owner_web_contents; | 130 int embedder_process_id; |
132 int element_instance_id; | 131 int element_instance_id; |
133 | 132 |
134 ElementInstanceKey() | 133 ElementInstanceKey() |
135 : owner_web_contents(nullptr), | 134 : embedder_process_id(0), |
lazyboy
2015/02/12 17:41:32
0 should really be content::ChildProcessHost::kInv
Fady Samuel
2015/02/12 19:00:54
Done + moved implementation to cc file.
| |
136 element_instance_id(0) {} | 135 element_instance_id(0) {} |
137 | 136 |
138 ElementInstanceKey(content::WebContents* owner_web_contents, | 137 ElementInstanceKey(int embedder_process_id, |
139 int element_instance_id) | 138 int element_instance_id) |
140 : owner_web_contents(owner_web_contents), | 139 : embedder_process_id(embedder_process_id), |
141 element_instance_id(element_instance_id) {} | 140 element_instance_id(element_instance_id) {} |
142 | 141 |
143 bool operator<(const ElementInstanceKey& other) const { | 142 bool operator<(const ElementInstanceKey& other) const { |
144 if (owner_web_contents != other.owner_web_contents) | 143 if (embedder_process_id != other.embedder_process_id) |
145 return owner_web_contents < other.owner_web_contents; | 144 return embedder_process_id < other.embedder_process_id; |
145 | |
146 return element_instance_id < other.element_instance_id; | 146 return element_instance_id < other.element_instance_id; |
147 } | 147 } |
148 | 148 |
149 bool operator==(const ElementInstanceKey& other) const { | 149 bool operator==(const ElementInstanceKey& other) const { |
150 return (owner_web_contents == other.owner_web_contents) && | 150 return (embedder_process_id == other.embedder_process_id) && |
151 (element_instance_id == other.element_instance_id); | 151 (element_instance_id == other.element_instance_id); |
152 } | 152 } |
153 }; | 153 }; |
154 | 154 |
155 using GuestInstanceIDMap = std::map<ElementInstanceKey, int>; | 155 using GuestInstanceIDMap = std::map<ElementInstanceKey, int>; |
156 GuestInstanceIDMap instance_id_map_; | 156 GuestInstanceIDMap instance_id_map_; |
157 | 157 |
158 // The reverse map of GuestInstanceIDMap. | 158 // The reverse map of GuestInstanceIDMap. |
159 using GuestInstanceIDReverseMap = std::map<int, ElementInstanceKey>; | 159 using GuestInstanceIDReverseMap = std::map<int, ElementInstanceKey>; |
160 GuestInstanceIDReverseMap reverse_instance_id_map_; | 160 GuestInstanceIDReverseMap reverse_instance_id_map_; |
(...skipping 10 matching lines...) Expand all Loading... | |
171 std::set<int> removed_instance_ids_; | 171 std::set<int> removed_instance_ids_; |
172 | 172 |
173 content::BrowserContext* context_; | 173 content::BrowserContext* context_; |
174 | 174 |
175 DISALLOW_COPY_AND_ASSIGN(GuestViewManager); | 175 DISALLOW_COPY_AND_ASSIGN(GuestViewManager); |
176 }; | 176 }; |
177 | 177 |
178 } // namespace extensions | 178 } // namespace extensions |
179 | 179 |
180 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ | 180 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ |
OLD | NEW |