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_base.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: Addressed comments 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_base.h" 5 #include "extensions/browser/guest_view/guest_view_base.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "components/ui/zoom/page_zoom.h" 9 #include "components/ui/zoom/page_zoom.h"
10 #include "components/ui/zoom/zoom_controller.h" 10 #include "components/ui/zoom/zoom_controller.h"
11 #include "content/public/browser/navigation_details.h" 11 #include "content/public/browser/navigation_details.h"
12 #include "content/public/browser/render_frame_host.h" 12 #include "content/public/browser/render_frame_host.h"
13 #include "content/public/browser/render_process_host.h" 13 #include "content/public/browser/render_process_host.h"
14 #include "content/public/browser/render_view_host.h" 14 #include "content/public/browser/render_view_host.h"
15 #include "content/public/browser/render_widget_host_view.h" 15 #include "content/public/browser/render_widget_host_view.h"
16 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
17 #include "content/public/common/page_zoom.h" 17 #include "content/public/common/page_zoom.h"
18 #include "content/public/common/url_constants.h" 18 #include "content/public/common/url_constants.h"
19 #include "extensions/browser/guest_view/app_view/app_view_guest.h"
20 #include "extensions/browser/guest_view/extension_options/extension_options_gues t.h"
21 #include "extensions/browser/guest_view/extension_view/extension_view_guest.h"
22 #include "extensions/browser/guest_view/guest_view_event.h" 19 #include "extensions/browser/guest_view/guest_view_event.h"
23 #include "extensions/browser/guest_view/guest_view_manager.h" 20 #include "extensions/browser/guest_view/guest_view_manager.h"
24 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_gues t.h"
25 #include "extensions/browser/guest_view/surface_worker/surface_worker_guest.h"
26 #include "extensions/browser/guest_view/web_view/web_view_guest.h"
27 #include "extensions/common/guest_view/guest_view_constants.h" 21 #include "extensions/common/guest_view/guest_view_constants.h"
28 #include "extensions/common/guest_view/guest_view_messages.h" 22 #include "extensions/common/guest_view/guest_view_messages.h"
29 #include "third_party/WebKit/public/web/WebInputEvent.h" 23 #include "third_party/WebKit/public/web/WebInputEvent.h"
30 24
31 using content::WebContents; 25 using content::WebContents;
32 26
33 namespace content { 27 namespace content {
34 struct FrameNavigateParams; 28 struct FrameNavigateParams;
35 } 29 }
36 30
37 namespace extensions { 31 namespace extensions {
38 32
39 namespace { 33 namespace {
40 34
41 using GuestViewCreationMap =
42 std::map<std::string, GuestViewBase::GuestCreationCallback>;
43 static base::LazyInstance<GuestViewCreationMap> guest_view_registry =
44 LAZY_INSTANCE_INITIALIZER;
45
46 using WebContentsGuestViewMap = std::map<const WebContents*, GuestViewBase*>; 35 using WebContentsGuestViewMap = std::map<const WebContents*, GuestViewBase*>;
47 static base::LazyInstance<WebContentsGuestViewMap> webcontents_guestview_map = 36 static base::LazyInstance<WebContentsGuestViewMap> webcontents_guestview_map =
48 LAZY_INSTANCE_INITIALIZER; 37 LAZY_INSTANCE_INITIALIZER;
49 38
50 } // namespace 39 } // namespace
51 40
52 SetSizeParams::SetSizeParams() { 41 SetSizeParams::SetSizeParams() {
53 } 42 }
54 SetSizeParams::~SetSizeParams() { 43 SetSizeParams::~SetSizeParams() {
55 } 44 }
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 } 310 }
322 311
323 DispatchOnResizeEvent(guest_size_, new_size); 312 DispatchOnResizeEvent(guest_size_, new_size);
324 guest_size_ = new_size; 313 guest_size_ = new_size;
325 } 314 }
326 315
327 auto_size_enabled_ = enable_auto_size; 316 auto_size_enabled_ = enable_auto_size;
328 } 317 }
329 318
330 // static 319 // static
331 void GuestViewBase::RegisterGuestViewType(
332 const std::string& view_type,
333 const GuestCreationCallback& callback) {
334 auto it = guest_view_registry.Get().find(view_type);
335 DCHECK(it == guest_view_registry.Get().end());
336 guest_view_registry.Get()[view_type] = callback;
337 }
338
339 // static
340 GuestViewBase* GuestViewBase::Create(
341 content::WebContents* owner_web_contents,
342 const std::string& view_type) {
343 if (guest_view_registry.Get().empty())
344 RegisterGuestViewTypes();
345
346 auto it = guest_view_registry.Get().find(view_type);
347 if (it == guest_view_registry.Get().end()) {
348 NOTREACHED();
349 return nullptr;
350 }
351 return it->second.Run(owner_web_contents);
352 }
353
354 // static
355 GuestViewBase* GuestViewBase::FromWebContents(const WebContents* web_contents) { 320 GuestViewBase* GuestViewBase::FromWebContents(const WebContents* web_contents) {
356 WebContentsGuestViewMap* guest_map = webcontents_guestview_map.Pointer(); 321 WebContentsGuestViewMap* guest_map = webcontents_guestview_map.Pointer();
357 auto it = guest_map->find(web_contents); 322 auto it = guest_map->find(web_contents);
358 return it == guest_map->end() ? nullptr : it->second; 323 return it == guest_map->end() ? nullptr : it->second;
359 } 324 }
360 325
361 // static 326 // static
362 GuestViewBase* GuestViewBase::From(int owner_process_id, 327 GuestViewBase* GuestViewBase::From(int owner_process_id,
363 int guest_instance_id) { 328 int guest_instance_id) {
364 auto host = content::RenderProcessHost::FromID(owner_process_id); 329 auto host = content::RenderProcessHost::FromID(owner_process_id);
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 return; 799 return;
835 800
836 auto embedder_zoom_controller = 801 auto embedder_zoom_controller =
837 ui_zoom::ZoomController::FromWebContents(owner_web_contents()); 802 ui_zoom::ZoomController::FromWebContents(owner_web_contents());
838 // Chrome Apps do not have a ZoomController. 803 // Chrome Apps do not have a ZoomController.
839 if (!embedder_zoom_controller) 804 if (!embedder_zoom_controller)
840 return; 805 return;
841 embedder_zoom_controller->RemoveObserver(this); 806 embedder_zoom_controller->RemoveObserver(this);
842 } 807 }
843 808
844 // static
845 void GuestViewBase::RegisterGuestViewTypes() {
846 AppViewGuest::Register();
847 ExtensionOptionsGuest::Register();
848 ExtensionViewGuest::Register();
849 MimeHandlerViewGuest::Register();
850 SurfaceWorkerGuest::Register();
851 WebViewGuest::Register();
852 }
853
854 } // namespace extensions 809 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/guest_view/guest_view_base.h ('k') | extensions/browser/guest_view/guest_view_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698