blob: c691954c6a37055f51de33f802ccdabfb03d69c9 [file] [log] [blame]
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <stdint.h>
#include "base/macros.h"
#include "content/common/content_export.h"
#include "content/common/widget.mojom.h"
namespace content {
class RenderProcessHost;
class RenderWidgetHostDelegate;
class RenderWidgetHostImpl;
// A factory for creating RenderWidgetHostImpls. There is a global factory
// function that can be installed for the purposes of testing to provide a
// specialized RenderWidgetHostImpl class.
class RenderWidgetHostFactory {
// Creates a RenderWidgetHostImpl using the currently registered factory, or
// the default one if no factory is registered. Ownership of the returned
// pointer will be passed to the caller.
static RenderWidgetHostImpl* Create(RenderWidgetHostDelegate* delegate,
RenderProcessHost* process,
int32_t routing_id,
mojom::WidgetPtr widget_interface,
bool hidden);
// Returns true if there is currently a globally-registered factory.
static bool has_factory() { return !!factory_; }
RenderWidgetHostFactory() {}
virtual ~RenderWidgetHostFactory() {}
// You can derive from this class and specify an implementation for this
// function to create a different kind of RenderWidgetHostImpl for testing.
virtual RenderWidgetHostImpl* CreateRenderWidgetHost(
RenderWidgetHostDelegate* delegate,
RenderProcessHost* process,
int32_t routing_id,
mojom::WidgetPtr widget_interface,
bool hidden) = 0;
// Registers your factory to be called when new RenderWidgetHostImpls are
// created. We have only one global factory, so there must be no factory
// registered before the call. This class does NOT take ownership of the
// pointer.
CONTENT_EXPORT static void RegisterFactory(RenderWidgetHostFactory* factory);
// Unregister the previously registered factory. With no factory registered,
// the default RenderWidgetHostImpls will be created.
CONTENT_EXPORT static void UnregisterFactory();
// The current globally registered factory. This is NULL when we should
// create the default RenderWidgetHostImpls.
CONTENT_EXPORT static RenderWidgetHostFactory* factory_;
} // namespace content