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

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

Issue 921473006: GuestView: Fix message routing across embedder navigations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated comments CQ'ing Created 5 years, 10 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/gtest_prod_util.h" 10 #include "base/gtest_prod_util.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 ElementInstanceKey(int embedder_process_id,
136 element_instance_id(0) {} 135 int element_instance_id);
137 136
138 ElementInstanceKey(content::WebContents* owner_web_contents, 137 bool operator<(const ElementInstanceKey& other) const;
139 int element_instance_id) 138 bool operator==(const ElementInstanceKey& other) const;
140 : owner_web_contents(owner_web_contents),
141 element_instance_id(element_instance_id) {}
142
143 bool operator<(const ElementInstanceKey& other) const {
144 if (owner_web_contents != other.owner_web_contents)
145 return owner_web_contents < other.owner_web_contents;
146 return element_instance_id < other.element_instance_id;
147 }
148
149 bool operator==(const ElementInstanceKey& other) const {
150 return (owner_web_contents == other.owner_web_contents) &&
151 (element_instance_id == other.element_instance_id);
152 }
153 }; 139 };
154 140
155 using GuestInstanceIDMap = std::map<ElementInstanceKey, int>; 141 using GuestInstanceIDMap = std::map<ElementInstanceKey, int>;
156 GuestInstanceIDMap instance_id_map_; 142 GuestInstanceIDMap instance_id_map_;
157 143
158 // The reverse map of GuestInstanceIDMap. 144 // The reverse map of GuestInstanceIDMap.
159 using GuestInstanceIDReverseMap = std::map<int, ElementInstanceKey>; 145 using GuestInstanceIDReverseMap = std::map<int, ElementInstanceKey>;
160 GuestInstanceIDReverseMap reverse_instance_id_map_; 146 GuestInstanceIDReverseMap reverse_instance_id_map_;
161 147
162 int current_instance_id_; 148 int current_instance_id_;
163 149
164 // Any instance ID whose number not greater than this was removed via 150 // Any instance ID whose number not greater than this was removed via
165 // RemoveGuest. 151 // RemoveGuest.
166 // This is used so that we don't have store all removed instance IDs in 152 // This is used so that we don't have store all removed instance IDs in
167 // |removed_instance_ids_|. 153 // |removed_instance_ids_|.
168 int last_instance_id_removed_; 154 int last_instance_id_removed_;
169 // The remaining instance IDs that are greater than 155 // The remaining instance IDs that are greater than
170 // |last_instance_id_removed_| are kept here. 156 // |last_instance_id_removed_| are kept here.
171 std::set<int> removed_instance_ids_; 157 std::set<int> removed_instance_ids_;
172 158
173 content::BrowserContext* context_; 159 content::BrowserContext* context_;
174 160
175 DISALLOW_COPY_AND_ASSIGN(GuestViewManager); 161 DISALLOW_COPY_AND_ASSIGN(GuestViewManager);
176 }; 162 };
177 163
178 } // namespace extensions 164 } // namespace extensions
179 165
180 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_GUEST_VIEW_MANAGER_H_ 166 #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