1f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
2f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// found in the LICENSE file.
4f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
5f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "content/browser/frame_host/render_frame_host_factory.h"
6f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
7f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "base/logging.h"
8a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "content/browser/frame_host/frame_tree_node.h"
9f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "content/browser/frame_host/render_frame_host_impl.h"
10f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
11f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)namespace content {
12f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
13f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// static
14f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)RenderFrameHostFactory* RenderFrameHostFactory::factory_ = NULL;
15f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
16f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// static
17f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)scoped_ptr<RenderFrameHostImpl> RenderFrameHostFactory::Create(
18f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    RenderViewHostImpl* render_view_host,
19a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    RenderFrameHostDelegate* delegate,
20f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    FrameTree* frame_tree,
21a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    FrameTreeNode* frame_tree_node,
22f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    int routing_id,
23f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    bool is_swapped_out) {
24f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  if (factory_) {
25f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    return factory_->CreateRenderFrameHost(render_view_host,
26a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                           delegate,
27f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                                           frame_tree,
28a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                           frame_tree_node,
29f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                                           routing_id,
30f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                                           is_swapped_out).Pass();
31f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  }
32f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  return make_scoped_ptr(new RenderFrameHostImpl(
33a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      render_view_host, delegate, frame_tree, frame_tree_node, routing_id,
34a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      is_swapped_out));
35f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
36f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
37f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// static
38f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void RenderFrameHostFactory::RegisterFactory(RenderFrameHostFactory* factory) {
39f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DCHECK(!factory_) << "Can't register two factories at once.";
40f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  factory_ = factory;
41f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
42f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
43f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// static
44f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)void RenderFrameHostFactory::UnregisterFactory() {
45f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  DCHECK(factory_) << "No factory to unregister.";
46f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  factory_ = NULL;
47f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}
48f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
49f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}  // namespace content
50