Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Side by Side Diff: extensions/browser/guest_view/guest_view_manager.h

Issue 1096623002: Moved guest_view_registry to GuestViewManager and made it an instance map (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@switch_to_frombrowsercontextifavailable
Patch Set: Addressed comments Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 15 matching lines...) Expand all
99 friend class GuestViewBase; 107 friend class GuestViewBase;
100 FRIEND_TEST_ALL_PREFIXES(GuestViewManagerTest, AddRemove); 108 FRIEND_TEST_ALL_PREFIXES(GuestViewManagerTest, AddRemove);
101 109
102 // Can be overriden in tests. 110 // Can be overriden in tests.
103 virtual void AddGuest(int guest_instance_id, 111 virtual void AddGuest(int guest_instance_id,
104 content::WebContents* guest_web_contents); 112 content::WebContents* guest_web_contents);
105 113
106 // Can be overriden in tests. 114 // Can be overriden in tests.
107 virtual void RemoveGuest(int guest_instance_id); 115 virtual void RemoveGuest(int guest_instance_id);
108 116
117 // Creates a guest of the provided |view_type|.
118 GuestViewBase* CreateGuestInternal(content::WebContents* owner_web_contents,
119 const std::string& view_type);
120
121 // Adds GuestView types to the GuestView registry.
122 void RegisterGuestViewTypes();
123
109 // Indicates whether the provided |guest| can be used in the context it has 124 // Indicates whether the provided |guest| can be used in the context it has
110 // been created. 125 // been created.
111 bool IsGuestAvailableToContext(GuestViewBase* guest, 126 bool IsGuestAvailableToContext(GuestViewBase* guest,
112 std::string* owner_extension_id); 127 std::string* owner_extension_id);
113 128
114 content::WebContents* GetGuestByInstanceID(int guest_instance_id); 129 content::WebContents* GetGuestByInstanceID(int guest_instance_id);
115 130
116 bool CanEmbedderAccessInstanceIDMaybeKill( 131 bool CanEmbedderAccessInstanceIDMaybeKill(
117 int embedder_render_process_id, 132 int embedder_render_process_id,
118 int guest_instance_id); 133 int guest_instance_id);
(...skipping 29 matching lines...) Expand all
148 bool operator==(const ElementInstanceKey& other) const; 163 bool operator==(const ElementInstanceKey& other) const;
149 }; 164 };
150 165
151 using GuestInstanceIDMap = std::map<ElementInstanceKey, int>; 166 using GuestInstanceIDMap = std::map<ElementInstanceKey, int>;
152 GuestInstanceIDMap instance_id_map_; 167 GuestInstanceIDMap instance_id_map_;
153 168
154 // The reverse map of GuestInstanceIDMap. 169 // The reverse map of GuestInstanceIDMap.
155 using GuestInstanceIDReverseMap = std::map<int, ElementInstanceKey>; 170 using GuestInstanceIDReverseMap = std::map<int, ElementInstanceKey>;
156 GuestInstanceIDReverseMap reverse_instance_id_map_; 171 GuestInstanceIDReverseMap reverse_instance_id_map_;
157 172
173 using GuestCreationCallback =
174 base::Callback<GuestViewBase*(content::WebContents*)>;
175 using GuestViewCreationMap =
176 std::map<std::string, GuestViewManager::GuestCreationCallback>;
177 GuestViewCreationMap guest_view_registry_;
178
158 int current_instance_id_; 179 int current_instance_id_;
159 180
160 // Any instance ID whose number not greater than this was removed via 181 // Any instance ID whose number not greater than this was removed via
161 // RemoveGuest. 182 // RemoveGuest.
162 // This is used so that we don't have store all removed instance IDs in 183 // This is used so that we don't have store all removed instance IDs in
163 // |removed_instance_ids_|. 184 // |removed_instance_ids_|.
164 int last_instance_id_removed_; 185 int last_instance_id_removed_;
165 // The remaining instance IDs that are greater than 186 // The remaining instance IDs that are greater than
166 // |last_instance_id_removed_| are kept here. 187 // |last_instance_id_removed_| are kept here.
167 std::set<int> removed_instance_ids_; 188 std::set<int> removed_instance_ids_;
168 189
169 content::BrowserContext* context_; 190 content::BrowserContext* context_;
170 191
171 DISALLOW_COPY_AND_ASSIGN(GuestViewManager); 192 DISALLOW_COPY_AND_ASSIGN(GuestViewManager);
172 }; 193 };
173 194
174 } // namespace extensions 195 } // namespace extensions
175 196
176 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ 197 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_
OLDNEW
« no previous file with comments | « extensions/browser/guest_view/guest_view_base.cc ('k') | extensions/browser/guest_view/guest_view_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698