Chromium Code Reviews| 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/bind.h" | |
| 10 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 11 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "content/public/browser/browser_plugin_guest_manager.h" | 14 #include "content/public/browser/browser_plugin_guest_manager.h" |
| 14 #include "content/public/browser/site_instance.h" | 15 #include "content/public/browser/site_instance.h" |
| 15 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 16 | 17 |
| 17 class GURL; | 18 class GURL; |
| 18 | 19 |
| 19 namespace content { | 20 namespace content { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 | 65 |
| 65 // Removes the association between |element_instance_id| and a guest instance | 66 // Removes the association between |element_instance_id| and a guest instance |
| 66 // ID if one exists. | 67 // ID if one exists. |
| 67 void DetachGuest(GuestViewBase* guest); | 68 void DetachGuest(GuestViewBase* guest); |
| 68 | 69 |
| 69 int GetNextInstanceID(); | 70 int GetNextInstanceID(); |
| 70 int GetGuestInstanceIDForElementID( | 71 int GetGuestInstanceIDForElementID( |
| 71 int owner_process_id, | 72 int owner_process_id, |
| 72 int element_instance_id); | 73 int element_instance_id); |
| 73 | 74 |
| 75 template <typename T> | |
| 76 void RegisterGuestViewType() { | |
| 77 auto it = guest_view_registry_.find(T::Type); | |
| 78 DCHECK(it == guest_view_registry_.end()); | |
| 79 guest_view_registry_[T::Type] = base::Bind(&T::Create); | |
| 80 } | |
| 81 | |
| 74 using WebContentsCreatedCallback = | 82 using WebContentsCreatedCallback = |
| 75 base::Callback<void(content::WebContents*)>; | 83 base::Callback<void(content::WebContents*)>; |
| 76 void CreateGuest(const std::string& view_type, | 84 void CreateGuest(const std::string& view_type, |
| 77 content::WebContents* owner_web_contents, | 85 content::WebContents* owner_web_contents, |
| 78 const base::DictionaryValue& create_params, | 86 const base::DictionaryValue& create_params, |
| 79 const WebContentsCreatedCallback& callback); | 87 const WebContentsCreatedCallback& callback); |
| 80 | 88 |
| 81 content::WebContents* CreateGuestWithWebContentsParams( | 89 content::WebContents* CreateGuestWithWebContentsParams( |
| 82 const std::string& view_type, | 90 const std::string& view_type, |
| 83 content::WebContents* owner_web_contents, | 91 content::WebContents* owner_web_contents, |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 97 friend class GuestViewBase; | 105 friend class GuestViewBase; |
| 98 FRIEND_TEST_ALL_PREFIXES(GuestViewManagerTest, AddRemove); | 106 FRIEND_TEST_ALL_PREFIXES(GuestViewManagerTest, AddRemove); |
| 99 | 107 |
| 100 // Can be overriden in tests. | 108 // Can be overriden in tests. |
| 101 virtual void AddGuest(int guest_instance_id, | 109 virtual void AddGuest(int guest_instance_id, |
| 102 content::WebContents* guest_web_contents); | 110 content::WebContents* guest_web_contents); |
| 103 | 111 |
| 104 // Can be overriden in tests. | 112 // Can be overriden in tests. |
| 105 virtual void RemoveGuest(int guest_instance_id); | 113 virtual void RemoveGuest(int guest_instance_id); |
| 106 | 114 |
| 115 // Create a guest of the provided |view_type|. | |
|
lazyboy
2015/04/20 19:08:57
Creates
Fady Samuel
2015/04/20 20:35:23
Done.
| |
| 116 GuestViewBase* CreateGuestInternal(content::WebContents* owner_web_contents, | |
| 117 const std::string& view_type); | |
| 118 | |
| 119 // Adds GuestView types to the GuestView registry. | |
| 120 void RegisterGuestViewTypes(); | |
| 121 | |
| 107 // Indicates whether the provided |guest| can be used in the context it has | 122 // Indicates whether the provided |guest| can be used in the context it has |
| 108 // been created. | 123 // been created. |
| 109 bool IsGuestAvailableToContext(GuestViewBase* guest, | 124 bool IsGuestAvailableToContext(GuestViewBase* guest, |
| 110 std::string* owner_extension_id); | 125 std::string* owner_extension_id); |
| 111 | 126 |
| 112 content::WebContents* GetGuestByInstanceID(int guest_instance_id); | 127 content::WebContents* GetGuestByInstanceID(int guest_instance_id); |
| 113 | 128 |
| 114 bool CanEmbedderAccessInstanceIDMaybeKill( | 129 bool CanEmbedderAccessInstanceIDMaybeKill( |
| 115 int embedder_render_process_id, | 130 int embedder_render_process_id, |
| 116 int guest_instance_id); | 131 int guest_instance_id); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 143 bool operator==(const ElementInstanceKey& other) const; | 158 bool operator==(const ElementInstanceKey& other) const; |
| 144 }; | 159 }; |
| 145 | 160 |
| 146 using GuestInstanceIDMap = std::map<ElementInstanceKey, int>; | 161 using GuestInstanceIDMap = std::map<ElementInstanceKey, int>; |
| 147 GuestInstanceIDMap instance_id_map_; | 162 GuestInstanceIDMap instance_id_map_; |
| 148 | 163 |
| 149 // The reverse map of GuestInstanceIDMap. | 164 // The reverse map of GuestInstanceIDMap. |
| 150 using GuestInstanceIDReverseMap = std::map<int, ElementInstanceKey>; | 165 using GuestInstanceIDReverseMap = std::map<int, ElementInstanceKey>; |
| 151 GuestInstanceIDReverseMap reverse_instance_id_map_; | 166 GuestInstanceIDReverseMap reverse_instance_id_map_; |
| 152 | 167 |
| 168 using GuestCreationCallback = | |
| 169 base::Callback<GuestViewBase*(content::WebContents*)>; | |
| 170 using GuestViewCreationMap = | |
| 171 std::map<std::string, GuestViewManager::GuestCreationCallback>; | |
| 172 GuestViewCreationMap guest_view_registry_; | |
| 173 | |
| 153 int current_instance_id_; | 174 int current_instance_id_; |
| 154 | 175 |
| 155 // Any instance ID whose number not greater than this was removed via | 176 // Any instance ID whose number not greater than this was removed via |
| 156 // RemoveGuest. | 177 // RemoveGuest. |
| 157 // This is used so that we don't have store all removed instance IDs in | 178 // This is used so that we don't have store all removed instance IDs in |
| 158 // |removed_instance_ids_|. | 179 // |removed_instance_ids_|. |
| 159 int last_instance_id_removed_; | 180 int last_instance_id_removed_; |
| 160 // The remaining instance IDs that are greater than | 181 // The remaining instance IDs that are greater than |
| 161 // |last_instance_id_removed_| are kept here. | 182 // |last_instance_id_removed_| are kept here. |
| 162 std::set<int> removed_instance_ids_; | 183 std::set<int> removed_instance_ids_; |
| 163 | 184 |
| 164 content::BrowserContext* context_; | 185 content::BrowserContext* context_; |
| 165 | 186 |
| 166 DISALLOW_COPY_AND_ASSIGN(GuestViewManager); | 187 DISALLOW_COPY_AND_ASSIGN(GuestViewManager); |
| 167 }; | 188 }; |
| 168 | 189 |
| 169 } // namespace extensions | 190 } // namespace extensions |
| 170 | 191 |
| 171 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ | 192 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ |
| OLD | NEW |