| 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 "chrome/browser/guest_view/guest_view_manager.h" |    5 #include "chrome/browser/guest_view/guest_view_manager.h" | 
|    6  |    6  | 
|    7 #include "base/strings/stringprintf.h" |    7 #include "base/strings/stringprintf.h" | 
|    8 #include "chrome/browser/extensions/extension_service.h" |    8 #include "chrome/browser/extensions/extension_service.h" | 
|    9 #include "chrome/browser/guest_view/guest_view_base.h" |    9 #include "chrome/browser/guest_view/guest_view_base.h" | 
|   10 #include "chrome/browser/guest_view/guest_view_constants.h" |   10 #include "chrome/browser/guest_view/guest_view_constants.h" | 
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   51   return guest_manager; |   51   return guest_manager; | 
|   52 } |   52 } | 
|   53  |   53  | 
|   54 content::WebContents* GuestViewManager::GetGuestByInstanceIDSafely( |   54 content::WebContents* GuestViewManager::GetGuestByInstanceIDSafely( | 
|   55     int guest_instance_id, |   55     int guest_instance_id, | 
|   56     int embedder_render_process_id) { |   56     int embedder_render_process_id) { | 
|   57   if (!CanEmbedderAccessInstanceIDMaybeKill(embedder_render_process_id, |   57   if (!CanEmbedderAccessInstanceIDMaybeKill(embedder_render_process_id, | 
|   58                                             guest_instance_id)) { |   58                                             guest_instance_id)) { | 
|   59     return NULL; |   59     return NULL; | 
|   60   } |   60   } | 
|   61   return GetGuestByInstanceID(guest_instance_id, embedder_render_process_id); |   61   return GetGuestByInstanceID(guest_instance_id); | 
|   62 } |   62 } | 
|   63  |   63  | 
|   64 int GuestViewManager::GetNextInstanceID() { |   64 int GuestViewManager::GetNextInstanceID() { | 
|   65   return ++current_instance_id_; |   65   return ++current_instance_id_; | 
|   66 } |   66 } | 
|   67  |   67  | 
|   68 void GuestViewManager::CreateGuest( |   68 void GuestViewManager::CreateGuest( | 
|   69     const std::string& view_type, |   69     const std::string& view_type, | 
|   70     const std::string& embedder_extension_id, |   70     const std::string& embedder_extension_id, | 
|   71     int embedder_render_process_id, |   71     int embedder_render_process_id, | 
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  107 void GuestViewManager::MaybeGetGuestByInstanceIDOrKill( |  107 void GuestViewManager::MaybeGetGuestByInstanceIDOrKill( | 
|  108     int guest_instance_id, |  108     int guest_instance_id, | 
|  109     int embedder_render_process_id, |  109     int embedder_render_process_id, | 
|  110     const GuestByInstanceIDCallback& callback) { |  110     const GuestByInstanceIDCallback& callback) { | 
|  111   if (!CanEmbedderAccessInstanceIDMaybeKill(embedder_render_process_id, |  111   if (!CanEmbedderAccessInstanceIDMaybeKill(embedder_render_process_id, | 
|  112                                             guest_instance_id)) { |  112                                             guest_instance_id)) { | 
|  113     // If we kill the embedder, then don't bother calling back. |  113     // If we kill the embedder, then don't bother calling back. | 
|  114     return; |  114     return; | 
|  115   } |  115   } | 
|  116   content::WebContents* guest_web_contents = |  116   content::WebContents* guest_web_contents = | 
|  117       GetGuestByInstanceID(guest_instance_id, embedder_render_process_id); |  117       GetGuestByInstanceID(guest_instance_id); | 
|  118   callback.Run(guest_web_contents); |  118   callback.Run(guest_web_contents); | 
|  119 } |  119 } | 
|  120  |  120  | 
|  121 SiteInstance* GuestViewManager::GetGuestSiteInstance( |  121 SiteInstance* GuestViewManager::GetGuestSiteInstance( | 
|  122     const GURL& guest_site) { |  122     const GURL& guest_site) { | 
|  123   for (GuestInstanceMap::const_iterator it = |  123   for (GuestInstanceMap::const_iterator it = | 
|  124        guest_web_contents_by_instance_id_.begin(); |  124        guest_web_contents_by_instance_id_.begin(); | 
|  125        it != guest_web_contents_by_instance_id_.end(); ++it) { |  125        it != guest_web_contents_by_instance_id_.end(); ++it) { | 
|  126     if (it->second->GetSiteInstance()->GetSiteURL() == guest_site) |  126     if (it->second->GetSiteInstance()->GetSiteURL() == guest_site) | 
|  127       return it->second->GetSiteInstance(); |  127       return it->second->GetSiteInstance(); | 
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  176         break; |  176         break; | 
|  177       ++last_instance_id_removed_; |  177       ++last_instance_id_removed_; | 
|  178       removed_instance_ids_.erase(iter++); |  178       removed_instance_ids_.erase(iter++); | 
|  179     } |  179     } | 
|  180   } else { |  180   } else { | 
|  181     removed_instance_ids_.insert(guest_instance_id); |  181     removed_instance_ids_.insert(guest_instance_id); | 
|  182   } |  182   } | 
|  183 } |  183 } | 
|  184  |  184  | 
|  185 content::WebContents* GuestViewManager::GetGuestByInstanceID( |  185 content::WebContents* GuestViewManager::GetGuestByInstanceID( | 
|  186     int guest_instance_id, |  186     int guest_instance_id) { | 
|  187     int embedder_render_process_id) { |  | 
|  188   GuestInstanceMap::const_iterator it = |  187   GuestInstanceMap::const_iterator it = | 
|  189       guest_web_contents_by_instance_id_.find(guest_instance_id); |  188       guest_web_contents_by_instance_id_.find(guest_instance_id); | 
|  190   if (it == guest_web_contents_by_instance_id_.end()) |  189   if (it == guest_web_contents_by_instance_id_.end()) | 
|  191     return NULL; |  190     return NULL; | 
|  192   return it->second; |  191   return it->second; | 
|  193 } |  192 } | 
|  194  |  193  | 
|  195 bool GuestViewManager::CanEmbedderAccessInstanceIDMaybeKill( |  194 bool GuestViewManager::CanEmbedderAccessInstanceIDMaybeKill( | 
|  196     int embedder_render_process_id, |  195     int embedder_render_process_id, | 
|  197     int guest_instance_id) { |  196     int guest_instance_id) { | 
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  236       guest_web_contents_by_instance_id_.find(guest_instance_id); |  235       guest_web_contents_by_instance_id_.find(guest_instance_id); | 
|  237   if (it == guest_web_contents_by_instance_id_.end()) |  236   if (it == guest_web_contents_by_instance_id_.end()) | 
|  238     return true; |  237     return true; | 
|  239  |  238  | 
|  240   GuestViewBase* guest_view = GuestViewBase::FromWebContents(it->second); |  239   GuestViewBase* guest_view = GuestViewBase::FromWebContents(it->second); | 
|  241   if (!guest_view) |  240   if (!guest_view) | 
|  242     return false; |  241     return false; | 
|  243  |  242  | 
|  244   return embedder_render_process_id == guest_view->embedder_render_process_id(); |  243   return embedder_render_process_id == guest_view->embedder_render_process_id(); | 
|  245 } |  244 } | 
| OLD | NEW |