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 #include "extensions/browser/guest_view/guest_view_manager.h" | 5 #include "extensions/browser/guest_view/guest_view_manager.h" |
6 | 6 |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "content/public/browser/browser_context.h" | 8 #include "content/public/browser/browser_context.h" |
9 #include "content/public/browser/render_frame_host.h" | 9 #include "content/public/browser/render_frame_host.h" |
10 #include "content/public/browser/render_process_host.h" | 10 #include "content/public/browser/render_process_host.h" |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 auto guest_view = GuestViewBase::FromWebContents(guest.second); | 179 auto guest_view = GuestViewBase::FromWebContents(guest.second); |
180 if (guest_view->owner_web_contents() != owner_web_contents) | 180 if (guest_view->owner_web_contents() != owner_web_contents) |
181 continue; | 181 continue; |
182 | 182 |
183 if (callback.Run(guest_view->web_contents())) | 183 if (callback.Run(guest_view->web_contents())) |
184 return true; | 184 return true; |
185 } | 185 } |
186 return false; | 186 return false; |
187 } | 187 } |
188 | 188 |
| 189 WebContents* GuestViewManager::GetFullPageGuest( |
| 190 WebContents* embedder_web_contents) { |
| 191 WebContents* result = nullptr; |
| 192 ForEachGuest(embedder_web_contents, |
| 193 base::Bind(&GuestViewManager::GetFullPageGuestHelper, &result)); |
| 194 return result; |
| 195 } |
| 196 |
189 void GuestViewManager::AddGuest(int guest_instance_id, | 197 void GuestViewManager::AddGuest(int guest_instance_id, |
190 WebContents* guest_web_contents) { | 198 WebContents* guest_web_contents) { |
191 CHECK(!ContainsKey(guest_web_contents_by_instance_id_, guest_instance_id)); | 199 CHECK(!ContainsKey(guest_web_contents_by_instance_id_, guest_instance_id)); |
192 CHECK(CanUseGuestInstanceID(guest_instance_id)); | 200 CHECK(CanUseGuestInstanceID(guest_instance_id)); |
193 guest_web_contents_by_instance_id_[guest_instance_id] = guest_web_contents; | 201 guest_web_contents_by_instance_id_[guest_instance_id] = guest_web_contents; |
194 } | 202 } |
195 | 203 |
196 void GuestViewManager::RemoveGuest(int guest_instance_id) { | 204 void GuestViewManager::RemoveGuest(int guest_instance_id) { |
197 auto it = guest_web_contents_by_instance_id_.find(guest_instance_id); | 205 auto it = guest_web_contents_by_instance_id_.find(guest_instance_id); |
198 DCHECK(it != guest_web_contents_by_instance_id_.end()); | 206 DCHECK(it != guest_web_contents_by_instance_id_.end()); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 } | 259 } |
252 return true; | 260 return true; |
253 } | 261 } |
254 | 262 |
255 bool GuestViewManager::CanUseGuestInstanceID(int guest_instance_id) { | 263 bool GuestViewManager::CanUseGuestInstanceID(int guest_instance_id) { |
256 if (guest_instance_id <= last_instance_id_removed_) | 264 if (guest_instance_id <= last_instance_id_removed_) |
257 return false; | 265 return false; |
258 return !ContainsKey(removed_instance_ids_, guest_instance_id); | 266 return !ContainsKey(removed_instance_ids_, guest_instance_id); |
259 } | 267 } |
260 | 268 |
| 269 // static |
| 270 bool GuestViewManager::GetFullPageGuestHelper( |
| 271 content::WebContents** result, |
| 272 content::WebContents* guest_web_contents) { |
| 273 auto guest_view = GuestViewBase::FromWebContents(guest_web_contents); |
| 274 if (guest_view && guest_view->is_full_page_plugin()) { |
| 275 *result = guest_web_contents; |
| 276 return true; |
| 277 } |
| 278 return false; |
| 279 } |
| 280 |
261 bool GuestViewManager::CanEmbedderAccessInstanceID( | 281 bool GuestViewManager::CanEmbedderAccessInstanceID( |
262 int embedder_render_process_id, | 282 int embedder_render_process_id, |
263 int guest_instance_id) { | 283 int guest_instance_id) { |
264 // The embedder is trying to access a guest with a negative or zero | 284 // The embedder is trying to access a guest with a negative or zero |
265 // instance ID. | 285 // instance ID. |
266 if (guest_instance_id <= guestview::kInstanceIDNone) | 286 if (guest_instance_id <= guestview::kInstanceIDNone) |
267 return false; | 287 return false; |
268 | 288 |
269 // The embedder is trying to access an instance ID that has not yet been | 289 // The embedder is trying to access an instance ID that has not yet been |
270 // allocated by GuestViewManager. This could cause instance ID | 290 // allocated by GuestViewManager. This could cause instance ID |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 return element_instance_id < other.element_instance_id; | 327 return element_instance_id < other.element_instance_id; |
308 } | 328 } |
309 | 329 |
310 bool GuestViewManager::ElementInstanceKey::operator==( | 330 bool GuestViewManager::ElementInstanceKey::operator==( |
311 const GuestViewManager::ElementInstanceKey& other) const { | 331 const GuestViewManager::ElementInstanceKey& other) const { |
312 return (embedder_process_id == other.embedder_process_id) && | 332 return (embedder_process_id == other.embedder_process_id) && |
313 (element_instance_id == other.element_instance_id); | 333 (element_instance_id == other.element_instance_id); |
314 } | 334 } |
315 | 335 |
316 } // namespace extensions | 336 } // namespace extensions |
OLD | NEW |