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