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/guest_view/app_view/app_view_guest.h" | |
| 18 #include "extensions/browser/guest_view/extension_options/extension_options_gues t.h" | |
| 19 #include "extensions/browser/guest_view/extension_view/extension_view_guest.h" | |
| 20 #include "extensions/browser/guest_view/guest_view_base.h" | 17 #include "extensions/browser/guest_view/guest_view_base.h" |
| 18 #include "extensions/browser/guest_view/guest_view_manager_delegate.h" | |
| 21 #include "extensions/browser/guest_view/guest_view_manager_factory.h" | 19 #include "extensions/browser/guest_view/guest_view_manager_factory.h" |
| 22 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_gues t.h" | |
| 23 #include "extensions/browser/guest_view/surface_worker/surface_worker_guest.h" | |
| 24 #include "extensions/browser/guest_view/web_view/web_view_guest.h" | |
| 25 #include "extensions/browser/process_manager.h" | |
| 26 #include "extensions/browser/process_map.h" | |
| 27 #include "extensions/common/features/feature.h" | |
| 28 #include "extensions/common/features/feature_provider.h" | |
| 29 #include "extensions/common/guest_view/guest_view_constants.h" | 20 #include "extensions/common/guest_view/guest_view_constants.h" |
| 30 #include "net/base/escape.h" | 21 #include "net/base/escape.h" |
| 31 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 32 | 23 |
| 33 using content::BrowserContext; | 24 using content::BrowserContext; |
| 34 using content::SiteInstance; | 25 using content::SiteInstance; |
| 35 using content::WebContents; | 26 using content::WebContents; |
| 27 using guestview::GuestViewManagerDelegate; | |
| 36 | 28 |
| 37 namespace extensions { | 29 namespace extensions { |
| 38 | 30 |
| 39 // static | 31 // static |
| 40 GuestViewManagerFactory* GuestViewManager::factory_ = nullptr; | 32 GuestViewManagerFactory* GuestViewManager::factory_ = nullptr; |
| 41 | 33 |
| 42 GuestViewManager::GuestViewManager(content::BrowserContext* context) | 34 GuestViewManager::GuestViewManager( |
| 43 : current_instance_id_(0), last_instance_id_removed_(0), context_(context) { | 35 content::BrowserContext* context, |
| 36 scoped_ptr<GuestViewManagerDelegate> delegate) | |
| 37 : current_instance_id_(0), | |
| 38 last_instance_id_removed_(0), | |
| 39 context_(context), | |
| 40 delegate_(delegate.Pass()) { | |
| 44 } | 41 } |
| 45 | 42 |
| 46 GuestViewManager::~GuestViewManager() {} | 43 GuestViewManager::~GuestViewManager() {} |
| 47 | 44 |
| 48 // static | 45 // static |
| 49 GuestViewManager* GuestViewManager::FromBrowserContext( | 46 GuestViewManager* GuestViewManager::CreateWithDelegate( |
| 50 BrowserContext* context) { | 47 BrowserContext* context, |
| 51 GuestViewManager* guest_manager = | 48 scoped_ptr<GuestViewManagerDelegate> delegate) { |
| 52 static_cast<GuestViewManager*>(context->GetUserData( | 49 GuestViewManager* guest_manager = FromBrowserContext(context); |
| 53 guestview::kGuestViewManagerKeyName)); | |
| 54 if (!guest_manager) { | 50 if (!guest_manager) { |
| 55 if (factory_) { | 51 if (factory_) { |
| 56 guest_manager = factory_->CreateGuestViewManager(context); | 52 guest_manager = factory_->CreateGuestViewManager(context); |
| 57 } else { | 53 } else { |
| 58 guest_manager = new GuestViewManager(context); | 54 guest_manager = new GuestViewManager(context, delegate.Pass()); |
| 59 } | 55 } |
| 60 context->SetUserData(guestview::kGuestViewManagerKeyName, guest_manager); | 56 context->SetUserData(guestview::kGuestViewManagerKeyName, guest_manager); |
| 61 } | 57 } |
| 62 return guest_manager; | 58 return guest_manager; |
| 63 } | 59 } |
| 64 | 60 |
| 65 // static | 61 // static |
| 66 GuestViewManager* GuestViewManager::FromBrowserContextIfAvailable( | 62 GuestViewManager* GuestViewManager::FromBrowserContext( |
| 67 BrowserContext* context) { | 63 BrowserContext* context) { |
| 68 return static_cast<GuestViewManager*>(context->GetUserData( | 64 return static_cast<GuestViewManager*>(context->GetUserData( |
| 69 guestview::kGuestViewManagerKeyName)); | 65 guestview::kGuestViewManagerKeyName)); |
| 70 } | 66 } |
| 71 | 67 |
| 72 content::WebContents* GuestViewManager::GetGuestByInstanceIDSafely( | 68 content::WebContents* GuestViewManager::GetGuestByInstanceIDSafely( |
| 73 int guest_instance_id, | 69 int guest_instance_id, |
| 74 int embedder_render_process_id) { | 70 int embedder_render_process_id) { |
| 75 if (!CanEmbedderAccessInstanceIDMaybeKill(embedder_render_process_id, | 71 if (!CanEmbedderAccessInstanceIDMaybeKill(embedder_render_process_id, |
| 76 guest_instance_id)) { | 72 guest_instance_id)) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 | 111 |
| 116 const ElementInstanceKey& key = reverse_it->second; | 112 const ElementInstanceKey& key = reverse_it->second; |
| 117 | 113 |
| 118 auto it = instance_id_map_.find(key); | 114 auto it = instance_id_map_.find(key); |
| 119 DCHECK(it != instance_id_map_.end()); | 115 DCHECK(it != instance_id_map_.end()); |
| 120 | 116 |
| 121 reverse_instance_id_map_.erase(reverse_it); | 117 reverse_instance_id_map_.erase(reverse_it); |
| 122 instance_id_map_.erase(it); | 118 instance_id_map_.erase(it); |
| 123 } | 119 } |
| 124 | 120 |
| 121 bool GuestViewManager::IsOwnedByExtension(GuestViewBase* guest) { | |
| 122 return delegate_->IsOwnedByExtension(guest); | |
| 123 } | |
| 124 | |
| 125 int GuestViewManager::GetNextInstanceID() { | 125 int GuestViewManager::GetNextInstanceID() { |
| 126 return ++current_instance_id_; | 126 return ++current_instance_id_; |
| 127 } | 127 } |
| 128 | 128 |
| 129 void GuestViewManager::CreateGuest(const std::string& view_type, | 129 void GuestViewManager::CreateGuest(const std::string& view_type, |
| 130 content::WebContents* owner_web_contents, | 130 content::WebContents* owner_web_contents, |
| 131 const base::DictionaryValue& create_params, | 131 const base::DictionaryValue& create_params, |
| 132 const WebContentsCreatedCallback& callback) { | 132 const WebContentsCreatedCallback& callback) { |
| 133 GuestViewBase* guest = CreateGuestInternal(owner_web_contents, view_type); | 133 GuestViewBase* guest = CreateGuestInternal(owner_web_contents, view_type); |
| 134 if (!guest) { | 134 if (!guest) { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 | 253 |
| 254 auto it = guest_view_registry_.find(view_type); | 254 auto it = guest_view_registry_.find(view_type); |
| 255 if (it == guest_view_registry_.end()) { | 255 if (it == guest_view_registry_.end()) { |
| 256 NOTREACHED(); | 256 NOTREACHED(); |
| 257 return nullptr; | 257 return nullptr; |
| 258 } | 258 } |
| 259 | 259 |
| 260 return it->second.Run(owner_web_contents); | 260 return it->second.Run(owner_web_contents); |
| 261 } | 261 } |
| 262 | 262 |
| 263 // static | 263 // static |
|
lazyboy
2015/04/22 15:16:29
not static
Fady Samuel
2015/04/22 23:09:48
Done.
| |
| 264 void GuestViewManager::RegisterGuestViewTypes() { | 264 void GuestViewManager::RegisterGuestViewTypes() { |
| 265 RegisterGuestViewType<AppViewGuest>(); | 265 delegate_->RegisterAdditionalGuestViewTypes(); |
| 266 RegisterGuestViewType<ExtensionOptionsGuest>(); | |
| 267 RegisterGuestViewType<ExtensionViewGuest>(); | |
| 268 RegisterGuestViewType<MimeHandlerViewGuest>(); | |
| 269 RegisterGuestViewType<SurfaceWorkerGuest>(); | |
| 270 RegisterGuestViewType<WebViewGuest>(); | |
| 271 } | 266 } |
| 272 | 267 |
| 273 bool GuestViewManager::IsGuestAvailableToContext( | 268 bool GuestViewManager::IsGuestAvailableToContext(GuestViewBase* guest) { |
| 274 GuestViewBase* guest, | 269 return delegate_->IsGuestAvailableToContext(guest); |
| 275 std::string* owner_extension_id) { | |
| 276 const Feature* feature = | |
| 277 FeatureProvider::GetAPIFeature(guest->GetAPINamespace()); | |
| 278 CHECK(feature); | |
| 279 | |
| 280 ProcessMap* process_map = ProcessMap::Get(context_); | |
| 281 CHECK(process_map); | |
| 282 | |
| 283 const Extension* owner_extension = ProcessManager::Get(context_)-> | |
| 284 GetExtensionForWebContents(guest->owner_web_contents()); | |
| 285 *owner_extension_id = owner_extension ? owner_extension->id() : std::string(); | |
| 286 | |
| 287 // Ok for |owner_extension| to be nullptr, the embedder might be WebUI. | |
| 288 Feature::Availability availability = feature->IsAvailableToContext( | |
| 289 owner_extension, | |
| 290 process_map->GetMostLikelyContextType( | |
| 291 owner_extension, | |
| 292 guest->owner_web_contents()->GetRenderProcessHost()->GetID()), | |
| 293 guest->GetOwnerSiteURL()); | |
| 294 | |
| 295 return availability.is_available(); | |
| 296 } | 270 } |
| 297 | 271 |
| 298 content::WebContents* GuestViewManager::GetGuestByInstanceID( | 272 content::WebContents* GuestViewManager::GetGuestByInstanceID( |
| 299 int guest_instance_id) { | 273 int guest_instance_id) { |
| 300 auto it = guest_web_contents_by_instance_id_.find(guest_instance_id); | 274 auto it = guest_web_contents_by_instance_id_.find(guest_instance_id); |
| 301 if (it == guest_web_contents_by_instance_id_.end()) | 275 if (it == guest_web_contents_by_instance_id_.end()) |
| 302 return nullptr; | 276 return nullptr; |
| 303 return it->second; | 277 return it->second; |
| 304 } | 278 } |
| 305 | 279 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 return element_instance_id < other.element_instance_id; | 359 return element_instance_id < other.element_instance_id; |
| 386 } | 360 } |
| 387 | 361 |
| 388 bool GuestViewManager::ElementInstanceKey::operator==( | 362 bool GuestViewManager::ElementInstanceKey::operator==( |
| 389 const GuestViewManager::ElementInstanceKey& other) const { | 363 const GuestViewManager::ElementInstanceKey& other) const { |
| 390 return (embedder_process_id == other.embedder_process_id) && | 364 return (embedder_process_id == other.embedder_process_id) && |
| 391 (element_instance_id == other.element_instance_id); | 365 (element_instance_id == other.element_instance_id); |
| 392 } | 366 } |
| 393 | 367 |
| 394 } // namespace extensions | 368 } // namespace extensions |
| OLD | NEW |