1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_FACTORY_H_
6 #define CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_FACTORY_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "content/common/content_export.h"
16 class RenderFrameHostDelegate
;
17 class RenderFrameHostImpl
;
18 class RenderViewHostImpl
;
19 class RenderWidgetHostDelegate
;
22 // A factory for creating RenderFrameHosts. There is a global factory function
23 // that can be installed for the purposes of testing to provide a specialized
24 // RenderFrameHostImpl class.
25 class CONTENT_EXPORT RenderFrameHostFactory
{
27 // Creates a new RenderFrameHostImpl using the currently registered factory,
28 // or a regular RenderFrameHostImpl if no factory is registered.
29 static scoped_ptr
<RenderFrameHostImpl
> Create(
30 SiteInstance
* site_instance
,
31 RenderViewHostImpl
* render_view_host
,
32 RenderFrameHostDelegate
* delegate
,
33 RenderWidgetHostDelegate
* rwh_delegate
,
34 FrameTree
* frame_tree
,
35 FrameTreeNode
* frame_tree_node
,
37 int32 widget_routing_id
,
41 // Returns true if there is currently a globally-registered factory.
42 static bool has_factory() { return !!factory_
; }
45 RenderFrameHostFactory() {}
46 virtual ~RenderFrameHostFactory() {}
48 // You can derive from this class and specify an implementation for this
49 // function to create an alternate kind of RenderFrameHostImpl for testing.
50 virtual scoped_ptr
<RenderFrameHostImpl
> CreateRenderFrameHost(
51 SiteInstance
* site_instance
,
52 RenderViewHostImpl
* render_view_host
,
53 RenderFrameHostDelegate
* delegate
,
54 RenderWidgetHostDelegate
* rwh_delegate
,
55 FrameTree
* frame_tree
,
56 FrameTreeNode
* frame_tree_node
,
58 int32 widget_routing_id
,
62 // Registers a factory to be called when new RenderFrameHostImpls are created.
63 // We have only one global factory, so there must be no factory registered
64 // before the call. This class does NOT take ownership of the pointer.
65 static void RegisterFactory(RenderFrameHostFactory
* factory
);
67 // Unregister the previously registered factory. With no factory registered,
68 // regular RenderFrameHostImpls will be created.
69 static void UnregisterFactory();
72 // The current globally registered factory. This is NULL when we should create
73 // regular RenderFrameHostImpls.
74 static RenderFrameHostFactory
* factory_
;
76 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostFactory
);
79 } // namespace content
81 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_FACTORY_H_