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