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
;
20 // A factory for creating RenderFrameHosts. There is a global factory function
21 // that can be installed for the purposes of testing to provide a specialized
22 // RenderFrameHostImpl class.
23 class CONTENT_EXPORT RenderFrameHostFactory
{
25 // Creates a new RenderFrameHostImpl using the currently registered factory,
26 // or a regular RenderFrameHostImpl if no factory is registered.
27 static scoped_ptr
<RenderFrameHostImpl
> Create(
28 RenderViewHostImpl
* render_view_host
,
29 RenderFrameHostDelegate
* delegate
,
30 FrameTree
* frame_tree
,
31 FrameTreeNode
* frame_tree_node
,
35 // Returns true if there is currently a globally-registered factory.
36 static bool has_factory() { return !!factory_
; }
39 RenderFrameHostFactory() {}
40 virtual ~RenderFrameHostFactory() {}
42 // You can derive from this class and specify an implementation for this
43 // function to create an alternate kind of RenderFrameHostImpl for testing.
44 virtual scoped_ptr
<RenderFrameHostImpl
> CreateRenderFrameHost(
45 RenderViewHostImpl
* render_view_host
,
46 RenderFrameHostDelegate
* delegate
,
47 FrameTree
* frame_tree
,
48 FrameTreeNode
* frame_tree_node
,
50 bool is_swapped_out
) = 0;
52 // Registers a factory to be called when new RenderFrameHostImpls are created.
53 // We have only one global factory, so there must be no factory registered
54 // before the call. This class does NOT take ownership of the pointer.
55 static void RegisterFactory(RenderFrameHostFactory
* factory
);
57 // Unregister the previously registered factory. With no factory registered,
58 // regular RenderFrameHostImpls will be created.
59 static void UnregisterFactory();
62 // The current globally registered factory. This is NULL when we should create
63 // regular RenderFrameHostImpls.
64 static RenderFrameHostFactory
* factory_
;
66 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostFactory
);
69 } // namespace content
71 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_FACTORY_H_