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/gtest_prod_util.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 } | 38 } |
39 // Returns the guest WebContents associated with the given |guest_instance_id| | 39 // Returns the guest WebContents associated with the given |guest_instance_id| |
40 // if the provided |embedder_render_process_id| is allowed to access it. | 40 // if the provided |embedder_render_process_id| is allowed to access it. |
41 // If the embedder is not allowed access, the embedder will be killed, and | 41 // If the embedder is not allowed access, the embedder will be killed, and |
42 // this method will return NULL. If no WebContents exists with the given | 42 // this method will return NULL. If no WebContents exists with the given |
43 // instance ID, then NULL will also be returned. | 43 // instance ID, then NULL will also be returned. |
44 content::WebContents* GetGuestByInstanceIDSafely( | 44 content::WebContents* GetGuestByInstanceIDSafely( |
45 int guest_instance_id, | 45 int guest_instance_id, |
46 int embedder_render_process_id); | 46 int embedder_render_process_id); |
47 | 47 |
| 48 // Associates the Browser Plugin with |element_instance_id| to a |
| 49 // guest that has ID of |guest_instance_id| and sets initialization |
| 50 // parameters, |params| for it. |
| 51 void SetAttachParamsForGuest(int embedder_render_process_id, |
| 52 int embedder_routing_id, |
| 53 int element_instance_id, |
| 54 int guest_instance_id, |
| 55 const base::DictionaryValue& params); |
| 56 |
48 int GetNextInstanceID(); | 57 int GetNextInstanceID(); |
49 | 58 |
50 typedef base::Callback<void(content::WebContents*)> | 59 typedef base::Callback<void(content::WebContents*)> |
51 WebContentsCreatedCallback; | 60 WebContentsCreatedCallback; |
52 void CreateGuest(const std::string& view_type, | 61 void CreateGuest(const std::string& view_type, |
53 const std::string& embedder_extension_id, | 62 const std::string& embedder_extension_id, |
54 content::WebContents* embedder_web_contents, | 63 content::WebContents* embedder_web_contents, |
55 const base::DictionaryValue& create_params, | 64 const base::DictionaryValue& create_params, |
56 const WebContentsCreatedCallback& callback); | 65 const WebContentsCreatedCallback& callback); |
57 | 66 |
58 content::WebContents* CreateGuestWithWebContentsParams( | 67 content::WebContents* CreateGuestWithWebContentsParams( |
59 const std::string& view_type, | 68 const std::string& view_type, |
60 const std::string& embedder_extension_id, | 69 const std::string& embedder_extension_id, |
61 int embedder_render_process_id, | 70 int embedder_render_process_id, |
62 const content::WebContents::CreateParams& create_params); | 71 const content::WebContents::CreateParams& create_params); |
63 | 72 |
64 content::SiteInstance* GetGuestSiteInstance( | 73 content::SiteInstance* GetGuestSiteInstance( |
65 const GURL& guest_site); | 74 const GURL& guest_site); |
66 | 75 |
67 // BrowserPluginGuestManager implementation. | 76 // BrowserPluginGuestManager implementation. |
68 virtual void MaybeGetGuestByInstanceIDOrKill( | 77 virtual void MaybeGetGuestByInstanceIDOrKill( |
69 int guest_instance_id, | 78 int guest_instance_id, |
70 int embedder_render_process_id, | 79 int embedder_render_process_id, |
71 const GuestByInstanceIDCallback& callback) OVERRIDE; | 80 const GuestByInstanceIDCallback& callback) OVERRIDE; |
72 virtual bool ForEachGuest(content::WebContents* embedder_web_contents, | 81 virtual bool ForEachGuest(content::WebContents* embedder_web_contents, |
73 const GuestCallback& callback) OVERRIDE; | 82 const GuestCallback& callback) OVERRIDE; |
| 83 virtual int GetGuestInstanceIDForPluginID( |
| 84 content::WebContents* embedder_web_contents, |
| 85 int element_instance_id) OVERRIDE; |
74 | 86 |
75 protected: | 87 protected: |
76 friend class GuestViewBase; | 88 friend class GuestViewBase; |
77 FRIEND_TEST_ALL_PREFIXES(GuestViewManagerTest, AddRemove); | 89 FRIEND_TEST_ALL_PREFIXES(GuestViewManagerTest, AddRemove); |
78 | 90 |
79 // Can be overriden in tests. | 91 // Can be overriden in tests. |
80 virtual void AddGuest(int guest_instance_id, | 92 virtual void AddGuest(int guest_instance_id, |
81 content::WebContents* guest_web_contents); | 93 content::WebContents* guest_web_contents); |
82 | 94 |
83 void RemoveGuest(int guest_instance_id); | 95 void RemoveGuest(int guest_instance_id); |
(...skipping 13 matching lines...) Expand all Loading... |
97 // from this manager using RemoveGuest. | 109 // from this manager using RemoveGuest. |
98 bool CanUseGuestInstanceID(int guest_instance_id); | 110 bool CanUseGuestInstanceID(int guest_instance_id); |
99 | 111 |
100 // Static factory instance (always NULL for non-test). | 112 // Static factory instance (always NULL for non-test). |
101 static GuestViewManagerFactory* factory_; | 113 static GuestViewManagerFactory* factory_; |
102 | 114 |
103 // Contains guests' WebContents, mapping from their instance ids. | 115 // Contains guests' WebContents, mapping from their instance ids. |
104 typedef std::map<int, content::WebContents*> GuestInstanceMap; | 116 typedef std::map<int, content::WebContents*> GuestInstanceMap; |
105 GuestInstanceMap guest_web_contents_by_instance_id_; | 117 GuestInstanceMap guest_web_contents_by_instance_id_; |
106 | 118 |
| 119 struct ElementInstanceKey { |
| 120 content::WebContents* embedder_web_contents; |
| 121 int element_instance_id; |
| 122 ElementInstanceKey(content::WebContents* embedder_web_contents, |
| 123 int element_instance_id) |
| 124 : embedder_web_contents(embedder_web_contents), |
| 125 element_instance_id(element_instance_id) {} |
| 126 bool operator<(const ElementInstanceKey& other) const { |
| 127 if (embedder_web_contents != other.embedder_web_contents) |
| 128 return embedder_web_contents < other.embedder_web_contents; |
| 129 return element_instance_id < other.element_instance_id; |
| 130 } |
| 131 }; |
| 132 |
| 133 typedef std::map<ElementInstanceKey, int> GuestInstanceIDMap; |
| 134 GuestInstanceIDMap instance_id_map_; |
| 135 // The reverse map of GuestInstanceIDMap. |
| 136 typedef std::map<int, ElementInstanceKey> GuestInstanceIDReverseMap; |
| 137 GuestInstanceIDReverseMap reverse_instance_id_map_; |
| 138 |
107 int current_instance_id_; | 139 int current_instance_id_; |
108 | 140 |
109 // Any instance ID whose number not greater than this was removed via | 141 // Any instance ID whose number not greater than this was removed via |
110 // RemoveGuest. | 142 // RemoveGuest. |
111 // This is used so that we don't have store all removed instance IDs in | 143 // This is used so that we don't have store all removed instance IDs in |
112 // |removed_instance_ids_|. | 144 // |removed_instance_ids_|. |
113 int last_instance_id_removed_; | 145 int last_instance_id_removed_; |
114 // The remaining instance IDs that are greater than | 146 // The remaining instance IDs that are greater than |
115 // |last_instance_id_removed_| are kept here. | 147 // |last_instance_id_removed_| are kept here. |
116 std::set<int> removed_instance_ids_; | 148 std::set<int> removed_instance_ids_; |
117 | 149 |
118 content::BrowserContext* context_; | 150 content::BrowserContext* context_; |
119 | 151 |
120 DISALLOW_COPY_AND_ASSIGN(GuestViewManager); | 152 DISALLOW_COPY_AND_ASSIGN(GuestViewManager); |
121 }; | 153 }; |
122 | 154 |
123 #endif // CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ | 155 #endif // CHROME_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ |
OLD | NEW |