Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / browser / renderer_host / render_view_host_factory.h
blobb1c243cbb6216c0c6ad05a5307b2fad6f3845eeb
1 // Copyright (c) 2012 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_RENDERER_HOST_RENDER_VIEW_HOST_FACTORY_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_FACTORY_H_
8 #include "base/basictypes.h"
9 #include "content/common/content_export.h"
11 namespace content {
12 class RenderFrameHostDelegate;
13 class RenderViewHost;
14 class RenderViewHostDelegate;
15 class RenderWidgetHostDelegate;
16 class SessionStorageNamespace;
17 class SiteInstance;
19 // A factory for creating RenderViewHosts. There is a global factory function
20 // that can be installed for the purposes of testing to provide a specialized
21 // RenderViewHost class.
22 class RenderViewHostFactory {
23 public:
24 // Creates a RenderViewHost using the currently registered factory, or the
25 // default one if no factory is registered. Ownership of the returned
26 // pointer will be passed to the caller.
27 static RenderViewHost* Create(SiteInstance* instance,
28 RenderViewHostDelegate* delegate,
29 RenderWidgetHostDelegate* widget_delegate,
30 int32 routing_id,
31 int32 main_frame_routing_id,
32 bool swapped_out,
33 bool hidden);
35 // Returns true if there is currently a globally-registered factory.
36 static bool has_factory() {
37 return !!factory_;
40 protected:
41 RenderViewHostFactory() {}
42 virtual ~RenderViewHostFactory() {}
44 // You can derive from this class and specify an implementation for this
45 // function to create a different kind of RenderViewHost for testing.
46 virtual RenderViewHost* CreateRenderViewHost(
47 SiteInstance* instance,
48 RenderViewHostDelegate* delegate,
49 RenderWidgetHostDelegate* widget_delegate,
50 int32 routing_id,
51 int32 surface_id,
52 int32 main_frame_routing_id,
53 bool swapped_out) = 0;
55 // Registers your factory to be called when new RenderViewHosts are created.
56 // We have only one global factory, so there must be no factory registered
57 // before the call. This class does NOT take ownership of the pointer.
58 CONTENT_EXPORT static void RegisterFactory(RenderViewHostFactory* factory);
60 // Unregister the previously registered factory. With no factory registered,
61 // the default RenderViewHosts will be created.
62 CONTENT_EXPORT static void UnregisterFactory();
64 private:
65 // The current globally registered factory. This is NULL when we should
66 // create the default RenderViewHosts.
67 CONTENT_EXPORT static RenderViewHostFactory* factory_;
69 DISALLOW_COPY_AND_ASSIGN(RenderViewHostFactory);
72 } // namespace content
74 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_VIEW_HOST_FACTORY_H_