Home | History | Annotate | Download | only in frame_host
      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.
      4 
      5 #ifndef CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_FACTORY_H_
      6 #define CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_FACTORY_H_
      7 
      8 #include "base/basictypes.h"
      9 #include "base/memory/scoped_ptr.h"
     10 #include "content/common/content_export.h"
     11 
     12 namespace content {
     13 
     14 class FrameTree;
     15 class FrameTreeNode;
     16 class RenderFrameHostDelegate;
     17 class RenderFrameHostImpl;
     18 class RenderViewHostImpl;
     19 
     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 {
     24  public:
     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,
     32       int routing_id,
     33       bool is_swapped_out);
     34 
     35   // Returns true if there is currently a globally-registered factory.
     36   static bool has_factory() { return !!factory_; }
     37 
     38  protected:
     39   RenderFrameHostFactory() {}
     40   virtual ~RenderFrameHostFactory() {}
     41 
     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,
     49       int routing_id,
     50       bool is_swapped_out) = 0;
     51 
     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);
     56 
     57   // Unregister the previously registered factory. With no factory registered,
     58   // regular RenderFrameHostImpls will be created.
     59   static void UnregisterFactory();
     60 
     61  private:
     62   // The current globally registered factory. This is NULL when we should create
     63   // regular RenderFrameHostImpls.
     64   static RenderFrameHostFactory* factory_;
     65 
     66   DISALLOW_COPY_AND_ASSIGN(RenderFrameHostFactory);
     67 };
     68 
     69 }  // namespace content
     70 
     71 #endif  // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_FACTORY_H_
     72