| 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_process_host.h" | 9 #include "content/public/browser/render_process_host.h" |
| 10 #include "content/public/browser/render_view_host.h" | 10 #include "content/public/browser/render_view_host.h" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 content::WebContents::CreateParams guest_create_params(create_params); | 141 content::WebContents::CreateParams guest_create_params(create_params); |
| 142 guest_create_params.guest_delegate = guest; | 142 guest_create_params.guest_delegate = guest; |
| 143 content::WebContents* guest_web_contents = | 143 content::WebContents* guest_web_contents = |
| 144 WebContents::Create(guest_create_params); | 144 WebContents::Create(guest_create_params); |
| 145 guest->InitWithWebContents(embedder_extension_id, | 145 guest->InitWithWebContents(embedder_extension_id, |
| 146 embedder_render_process_id, | 146 embedder_render_process_id, |
| 147 guest_web_contents); | 147 guest_web_contents); |
| 148 return guest_web_contents; | 148 return guest_web_contents; |
| 149 } | 149 } |
| 150 | 150 |
| 151 void GuestViewManager::MaybeGetGuestByInstanceIDOrKill( | 151 content::WebContents* GuestViewManager::GetGuestByInstanceID( |
| 152 content::WebContents* embedder_web_contents, | 152 content::WebContents* embedder_web_contents, |
| 153 int element_instance_id, | 153 int element_instance_id) { |
| 154 const GuestByInstanceIDCallback& callback) { | 154 int guest_instance_id = GetGuestInstanceIDForElementID(embedder_web_contents, |
| 155 int guest_instance_id = GetGuestInstanceIDForPluginID(embedder_web_contents, | 155 element_instance_id); |
| 156 element_instance_id); | |
| 157 if (guest_instance_id == guestview::kInstanceIDNone) | 156 if (guest_instance_id == guestview::kInstanceIDNone) |
| 158 return; | 157 return NULL; |
| 159 int embedder_render_process_id = | 158 |
| 160 embedder_web_contents->GetRenderProcessHost()->GetID(); | 159 return GetGuestByInstanceID(guest_instance_id); |
| 161 if (!CanEmbedderAccessInstanceIDMaybeKill(embedder_render_process_id, | |
| 162 guest_instance_id)) { | |
| 163 // If we kill the embedder, then don't bother calling back. | |
| 164 return; | |
| 165 } | |
| 166 content::WebContents* guest_web_contents = | |
| 167 GetGuestByInstanceID(guest_instance_id); | |
| 168 callback.Run(guest_web_contents); | |
| 169 } | 160 } |
| 170 | 161 |
| 171 int GuestViewManager::GetGuestInstanceIDForPluginID( | 162 int GuestViewManager::GetGuestInstanceIDForElementID( |
| 172 content::WebContents* embedder_web_contents, | 163 content::WebContents* embedder_web_contents, |
| 173 int element_instance_id) { | 164 int element_instance_id) { |
| 174 GuestInstanceIDMap::iterator iter = instance_id_map_.find( | 165 GuestInstanceIDMap::iterator iter = instance_id_map_.find( |
| 175 ElementInstanceKey(embedder_web_contents, element_instance_id)); | 166 ElementInstanceKey(embedder_web_contents, element_instance_id)); |
| 176 if (iter == instance_id_map_.end()) | 167 if (iter == instance_id_map_.end()) |
| 177 return guestview::kInstanceIDNone; | 168 return guestview::kInstanceIDNone; |
| 178 return iter->second; | 169 return iter->second; |
| 179 } | 170 } |
| 180 | 171 |
| 181 SiteInstance* GuestViewManager::GetGuestSiteInstance( | 172 SiteInstance* GuestViewManager::GetGuestSiteInstance( |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 return true; | 296 return true; |
| 306 | 297 |
| 307 GuestViewBase* guest_view = GuestViewBase::FromWebContents(it->second); | 298 GuestViewBase* guest_view = GuestViewBase::FromWebContents(it->second); |
| 308 if (!guest_view) | 299 if (!guest_view) |
| 309 return false; | 300 return false; |
| 310 | 301 |
| 311 return embedder_render_process_id == guest_view->embedder_render_process_id(); | 302 return embedder_render_process_id == guest_view->embedder_render_process_id(); |
| 312 } | 303 } |
| 313 | 304 |
| 314 } // namespace extensions | 305 } // namespace extensions |
| OLD | NEW |