| 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" |
| 17 #include "extensions/browser/guest_view/guest_view_base.h" | 20 #include "extensions/browser/guest_view/guest_view_base.h" |
| 18 #include "extensions/browser/guest_view/guest_view_manager_factory.h" | 21 #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" |
| 19 #include "extensions/browser/process_manager.h" | 25 #include "extensions/browser/process_manager.h" |
| 20 #include "extensions/browser/process_map.h" | 26 #include "extensions/browser/process_map.h" |
| 21 #include "extensions/common/features/feature.h" | 27 #include "extensions/common/features/feature.h" |
| 22 #include "extensions/common/features/feature_provider.h" | 28 #include "extensions/common/features/feature_provider.h" |
| 23 #include "extensions/common/guest_view/guest_view_constants.h" | 29 #include "extensions/common/guest_view/guest_view_constants.h" |
| 24 #include "net/base/escape.h" | 30 #include "net/base/escape.h" |
| 25 #include "url/gurl.h" | 31 #include "url/gurl.h" |
| 26 | 32 |
| 27 using content::BrowserContext; | 33 using content::BrowserContext; |
| 28 using content::SiteInstance; | 34 using content::SiteInstance; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 } | 123 } |
| 118 | 124 |
| 119 int GuestViewManager::GetNextInstanceID() { | 125 int GuestViewManager::GetNextInstanceID() { |
| 120 return ++current_instance_id_; | 126 return ++current_instance_id_; |
| 121 } | 127 } |
| 122 | 128 |
| 123 void GuestViewManager::CreateGuest(const std::string& view_type, | 129 void GuestViewManager::CreateGuest(const std::string& view_type, |
| 124 content::WebContents* owner_web_contents, | 130 content::WebContents* owner_web_contents, |
| 125 const base::DictionaryValue& create_params, | 131 const base::DictionaryValue& create_params, |
| 126 const WebContentsCreatedCallback& callback) { | 132 const WebContentsCreatedCallback& callback) { |
| 127 auto guest = GuestViewBase::Create(owner_web_contents, view_type); | 133 GuestViewBase* guest = CreateGuestInternal(owner_web_contents, view_type); |
| 128 if (!guest) { | 134 if (!guest) { |
| 129 callback.Run(nullptr); | 135 callback.Run(nullptr); |
| 130 return; | 136 return; |
| 131 } | 137 } |
| 132 guest->Init(create_params, callback); | 138 guest->Init(create_params, callback); |
| 133 } | 139 } |
| 134 | 140 |
| 135 content::WebContents* GuestViewManager::CreateGuestWithWebContentsParams( | 141 content::WebContents* GuestViewManager::CreateGuestWithWebContentsParams( |
| 136 const std::string& view_type, | 142 const std::string& view_type, |
| 137 content::WebContents* owner_web_contents, | 143 content::WebContents* owner_web_contents, |
| 138 const content::WebContents::CreateParams& create_params) { | 144 const content::WebContents::CreateParams& create_params) { |
| 139 auto guest = GuestViewBase::Create(owner_web_contents, view_type); | 145 auto guest = CreateGuestInternal(owner_web_contents, view_type); |
| 140 if (!guest) | 146 if (!guest) |
| 141 return nullptr; | 147 return nullptr; |
| 142 content::WebContents::CreateParams guest_create_params(create_params); | 148 content::WebContents::CreateParams guest_create_params(create_params); |
| 143 guest_create_params.guest_delegate = guest; | 149 guest_create_params.guest_delegate = guest; |
| 144 auto guest_web_contents = WebContents::Create(guest_create_params); | 150 auto guest_web_contents = WebContents::Create(guest_create_params); |
| 145 guest->InitWithWebContents(base::DictionaryValue(), guest_web_contents); | 151 guest->InitWithWebContents(base::DictionaryValue(), guest_web_contents); |
| 146 return guest_web_contents; | 152 return guest_web_contents; |
| 147 } | 153 } |
| 148 | 154 |
| 149 content::WebContents* GuestViewManager::GetGuestByInstanceID( | 155 content::WebContents* GuestViewManager::GetGuestByInstanceID( |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 if (instance_id != last_instance_id_removed_ + 1) | 238 if (instance_id != last_instance_id_removed_ + 1) |
| 233 break; | 239 break; |
| 234 ++last_instance_id_removed_; | 240 ++last_instance_id_removed_; |
| 235 removed_instance_ids_.erase(iter++); | 241 removed_instance_ids_.erase(iter++); |
| 236 } | 242 } |
| 237 } else { | 243 } else { |
| 238 removed_instance_ids_.insert(guest_instance_id); | 244 removed_instance_ids_.insert(guest_instance_id); |
| 239 } | 245 } |
| 240 } | 246 } |
| 241 | 247 |
| 248 GuestViewBase* GuestViewManager::CreateGuestInternal( |
| 249 content::WebContents* owner_web_contents, |
| 250 const std::string& view_type) { |
| 251 if (guest_view_registry_.empty()) |
| 252 RegisterGuestViewTypes(); |
| 253 |
| 254 auto it = guest_view_registry_.find(view_type); |
| 255 if (it == guest_view_registry_.end()) { |
| 256 NOTREACHED(); |
| 257 return nullptr; |
| 258 } |
| 259 |
| 260 return it->second.Run(owner_web_contents); |
| 261 } |
| 262 |
| 263 // static |
| 264 void GuestViewManager::RegisterGuestViewTypes() { |
| 265 RegisterGuestViewType<AppViewGuest>(); |
| 266 RegisterGuestViewType<ExtensionOptionsGuest>(); |
| 267 RegisterGuestViewType<ExtensionViewGuest>(); |
| 268 RegisterGuestViewType<MimeHandlerViewGuest>(); |
| 269 RegisterGuestViewType<SurfaceWorkerGuest>(); |
| 270 RegisterGuestViewType<WebViewGuest>(); |
| 271 } |
| 272 |
| 242 bool GuestViewManager::IsGuestAvailableToContext( | 273 bool GuestViewManager::IsGuestAvailableToContext( |
| 243 GuestViewBase* guest, | 274 GuestViewBase* guest, |
| 244 std::string* owner_extension_id) { | 275 std::string* owner_extension_id) { |
| 245 const Feature* feature = | 276 const Feature* feature = |
| 246 FeatureProvider::GetAPIFeature(guest->GetAPINamespace()); | 277 FeatureProvider::GetAPIFeature(guest->GetAPINamespace()); |
| 247 CHECK(feature); | 278 CHECK(feature); |
| 248 | 279 |
| 249 ProcessMap* process_map = ProcessMap::Get(context_); | 280 ProcessMap* process_map = ProcessMap::Get(context_); |
| 250 CHECK(process_map); | 281 CHECK(process_map); |
| 251 | 282 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 return element_instance_id < other.element_instance_id; | 385 return element_instance_id < other.element_instance_id; |
| 355 } | 386 } |
| 356 | 387 |
| 357 bool GuestViewManager::ElementInstanceKey::operator==( | 388 bool GuestViewManager::ElementInstanceKey::operator==( |
| 358 const GuestViewManager::ElementInstanceKey& other) const { | 389 const GuestViewManager::ElementInstanceKey& other) const { |
| 359 return (embedder_process_id == other.embedder_process_id) && | 390 return (embedder_process_id == other.embedder_process_id) && |
| 360 (element_instance_id == other.element_instance_id); | 391 (element_instance_id == other.element_instance_id); |
| 361 } | 392 } |
| 362 | 393 |
| 363 } // namespace extensions | 394 } // namespace extensions |
| OLD | NEW |