| 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" |
| 11 #include "content/public/browser/render_view_host.h" | 11 #include "content/public/browser/render_view_host.h" |
| 12 #include "content/public/browser/user_metrics.h" | 12 #include "content/public/browser/user_metrics.h" |
| 13 #include "content/public/browser/web_contents_observer.h" | 13 #include "content/public/browser/web_contents_observer.h" |
| 14 #include "content/public/common/child_process_host.h" | 14 #include "content/public/common/child_process_host.h" |
| 15 #include "content/public/common/result_codes.h" | 15 #include "content/public/common/result_codes.h" |
| 16 #include "content/public/common/url_constants.h" | 16 #include "content/public/common/url_constants.h" |
| 17 #include "extensions/browser/extension_system.h" | |
| 18 #include "extensions/browser/guest_view/guest_view_base.h" | 17 #include "extensions/browser/guest_view/guest_view_base.h" |
| 19 #include "extensions/browser/guest_view/guest_view_manager_factory.h" | 18 #include "extensions/browser/guest_view/guest_view_manager_factory.h" |
| 20 #include "extensions/common/extension_messages.h" | 19 #include "extensions/browser/process_manager.h" |
| 20 #include "extensions/browser/process_map.h" |
| 21 #include "extensions/common/features/feature.h" |
| 22 #include "extensions/common/features/feature_provider.h" |
| 21 #include "extensions/common/guest_view/guest_view_constants.h" | 23 #include "extensions/common/guest_view/guest_view_constants.h" |
| 22 #include "net/base/escape.h" | 24 #include "net/base/escape.h" |
| 23 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| 24 | 26 |
| 25 using content::BrowserContext; | 27 using content::BrowserContext; |
| 26 using content::SiteInstance; | 28 using content::SiteInstance; |
| 27 using content::WebContents; | 29 using content::WebContents; |
| 28 | 30 |
| 29 namespace extensions { | 31 namespace extensions { |
| 30 | 32 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 if (instance_id != last_instance_id_removed_ + 1) | 224 if (instance_id != last_instance_id_removed_ + 1) |
| 223 break; | 225 break; |
| 224 ++last_instance_id_removed_; | 226 ++last_instance_id_removed_; |
| 225 removed_instance_ids_.erase(iter++); | 227 removed_instance_ids_.erase(iter++); |
| 226 } | 228 } |
| 227 } else { | 229 } else { |
| 228 removed_instance_ids_.insert(guest_instance_id); | 230 removed_instance_ids_.insert(guest_instance_id); |
| 229 } | 231 } |
| 230 } | 232 } |
| 231 | 233 |
| 234 bool GuestViewManager::IsGuestAvailableToContext( |
| 235 GuestViewBase* guest, |
| 236 std::string* owner_extension_id) { |
| 237 const Feature* feature = |
| 238 FeatureProvider::GetAPIFeature(guest->GetAPINamespace()); |
| 239 CHECK(feature); |
| 240 |
| 241 ProcessMap* process_map = ProcessMap::Get(context_); |
| 242 CHECK(process_map); |
| 243 |
| 244 const Extension* owner_extension = ProcessManager::Get(context_)-> |
| 245 GetExtensionForWebContents(guest->owner_web_contents()); |
| 246 *owner_extension_id = owner_extension ? owner_extension->id() : std::string(); |
| 247 |
| 248 // Ok for |owner_extension| to be nullptr, the embedder might be WebUI. |
| 249 Feature::Availability availability = feature->IsAvailableToContext( |
| 250 owner_extension, |
| 251 process_map->GetMostLikelyContextType( |
| 252 owner_extension, |
| 253 guest->owner_web_contents()->GetRenderProcessHost()->GetID()), |
| 254 guest->GetOwnerSiteURL()); |
| 255 |
| 256 return availability.is_available(); |
| 257 } |
| 258 |
| 232 content::WebContents* GuestViewManager::GetGuestByInstanceID( | 259 content::WebContents* GuestViewManager::GetGuestByInstanceID( |
| 233 int guest_instance_id) { | 260 int guest_instance_id) { |
| 234 auto it = guest_web_contents_by_instance_id_.find(guest_instance_id); | 261 auto it = guest_web_contents_by_instance_id_.find(guest_instance_id); |
| 235 if (it == guest_web_contents_by_instance_id_.end()) | 262 if (it == guest_web_contents_by_instance_id_.end()) |
| 236 return nullptr; | 263 return nullptr; |
| 237 return it->second; | 264 return it->second; |
| 238 } | 265 } |
| 239 | 266 |
| 240 bool GuestViewManager::CanEmbedderAccessInstanceIDMaybeKill( | 267 bool GuestViewManager::CanEmbedderAccessInstanceIDMaybeKill( |
| 241 int embedder_render_process_id, | 268 int embedder_render_process_id, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 return element_instance_id < other.element_instance_id; | 334 return element_instance_id < other.element_instance_id; |
| 308 } | 335 } |
| 309 | 336 |
| 310 bool GuestViewManager::ElementInstanceKey::operator==( | 337 bool GuestViewManager::ElementInstanceKey::operator==( |
| 311 const GuestViewManager::ElementInstanceKey& other) const { | 338 const GuestViewManager::ElementInstanceKey& other) const { |
| 312 return (embedder_process_id == other.embedder_process_id) && | 339 return (embedder_process_id == other.embedder_process_id) && |
| 313 (element_instance_id == other.element_instance_id); | 340 (element_instance_id == other.element_instance_id); |
| 314 } | 341 } |
| 315 | 342 |
| 316 } // namespace extensions | 343 } // namespace extensions |
| OLD | NEW |