Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(415)

Side by Side Diff: extensions/browser/guest_view/guest_view_manager.cc

Issue 1096623002: Moved guest_view_registry to GuestViewManager and made it an instance map (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@switch_to_frombrowsercontextifavailable
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 if (instance_id != last_instance_id_removed_ + 1) 230 if (instance_id != last_instance_id_removed_ + 1)
225 break; 231 break;
226 ++last_instance_id_removed_; 232 ++last_instance_id_removed_;
227 removed_instance_ids_.erase(iter++); 233 removed_instance_ids_.erase(iter++);
228 } 234 }
229 } else { 235 } else {
230 removed_instance_ids_.insert(guest_instance_id); 236 removed_instance_ids_.insert(guest_instance_id);
231 } 237 }
232 } 238 }
233 239
240 GuestViewBase* GuestViewManager::CreateGuestInternal(
241 content::WebContents* owner_web_contents,
242 const std::string& view_type) {
243 if (guest_view_registry_.empty())
244 RegisterGuestViewTypes();
245
246 auto it = guest_view_registry_.find(view_type);
247 if (it == guest_view_registry_.end()) {
248 NOTREACHED();
249 return nullptr;
250 }
251
252 return it->second.Run(owner_web_contents);
253 }
254
255 // static
256 void GuestViewManager::RegisterGuestViewTypes() {
257 RegisterGuestViewType<AppViewGuest>();
258 RegisterGuestViewType<ExtensionOptionsGuest>();
259 RegisterGuestViewType<ExtensionViewGuest>();
260 RegisterGuestViewType<MimeHandlerViewGuest>();
261 RegisterGuestViewType<SurfaceWorkerGuest>();
262 RegisterGuestViewType<WebViewGuest>();
263 }
264
234 bool GuestViewManager::IsGuestAvailableToContext( 265 bool GuestViewManager::IsGuestAvailableToContext(
235 GuestViewBase* guest, 266 GuestViewBase* guest,
236 std::string* owner_extension_id) { 267 std::string* owner_extension_id) {
237 const Feature* feature = 268 const Feature* feature =
238 FeatureProvider::GetAPIFeature(guest->GetAPINamespace()); 269 FeatureProvider::GetAPIFeature(guest->GetAPINamespace());
239 CHECK(feature); 270 CHECK(feature);
240 271
241 ProcessMap* process_map = ProcessMap::Get(context_); 272 ProcessMap* process_map = ProcessMap::Get(context_);
242 CHECK(process_map); 273 CHECK(process_map);
243 274
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 return element_instance_id < other.element_instance_id; 365 return element_instance_id < other.element_instance_id;
335 } 366 }
336 367
337 bool GuestViewManager::ElementInstanceKey::operator==( 368 bool GuestViewManager::ElementInstanceKey::operator==(
338 const GuestViewManager::ElementInstanceKey& other) const { 369 const GuestViewManager::ElementInstanceKey& other) const {
339 return (embedder_process_id == other.embedder_process_id) && 370 return (embedder_process_id == other.embedder_process_id) &&
340 (element_instance_id == other.element_instance_id); 371 (element_instance_id == other.element_instance_id);
341 } 372 }
342 373
343 } // namespace extensions 374 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698