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