This component provides the shared Cast receiver implementation that is used by various embedders throughout Chromium. It is planned to be used for WebEngine, Chromecast hardware, and others.
The specifics of integrating this component with an existing Chromium embedder are described below. The canonical implementation of this component can be found at //chromecast/cast_core
. For specific usages of the below described APIs, see its RuntimeServiceImpl and RuntimeApplicationServiceImpl classes, which use this component to implement a gRPC
-defined service.
Integration with an existing Chromium embedder is relateively easy, with only a small number of integration points required:
Browser-side integration has two parts:
The Permissions Manager
is used to define the permissions that can be used by a given application. It is integrated into an existing Chromium embedder by calling into the PermissionsManager::GetPermissionsStatus() function from the embedder's implementation of content::PermissionControllerDelegate::GetPermissionStatus()
.
The remaining integration is done by creating an instance of the ContentBrowserClientMixins
class in the ContentBrowserClient
implementation for this embedder. For instance, this is currently done in the Cast Core implementation. From there, the OnWebContentsCreated()
and CreateURLLoaderThrottles()
functions must be called from the ContentBrowserClient
functions of the same name.
The embedder may additionally call AddApplicationStateObserver()
or AddStreamingResolutionObserver()
to subscribe to state change events for the runtime.
Renderer side integration is done very similarly to the runtime hooks for the browser-side integration as described above. Specifically, from the embedder‘s ContentRendererClient
implementation, an instance of ContentRendererClientMixins
must be created as is currently done in the Cast Core implementation. Then, the functions of this calls must all be called from the appropriate ContentRendererClient
functions as outlined in the class’s documentation.
Once the above integration is done, applications can be created by first creating an instance of RuntimeApplicationDispatcher
using the ContentBrowserClientMixins::CreateApplicationDispatcher()
function, then calling CreateApplication()
and providing basic information about the application (such as application id, requested permissions, etc). Note that this requires a template parameter of a type implementing the EmbedderApplication
interface.
After creation, an application will always exist in one of the following lifetime states, transitioning between them using functions defined in the RuntimeApplication
interface:
RuntimeApplication
object has been created, but nothing else has been done.It is expected that the application will be loaded immediately after being created, and then launched shortly after.
When the application is to be destroyed, this can be done through calling RuntimeApplicationDispatcher::DestroyApplication()
.
Implementing EmbedderApplication
is where the majority of the embedder's work is located. Doing so requires the following:
NotifyApplicationStarted()
, NotifyApplicationStopped()
, and NotifyMediaPlaybackChanged()
).GetWebContents()
and GetAllBindings()
).GetMessagePortService()
and GetContentWindowControls()
).Implementing this type therefore requires at minimum implementations of the following two embedder-specific classes:
ContentWindowControls
: Used for controlling the UX Window associated with this application.MessagePortService
: A wrapper around message port functionality, used to handle communication with services outside of this component.When creating an instance of EmbedderApplication
through RuntimeApplicationDispatcher
, an instance of RuntimeApplication
is provided, which can be used for control of this application. Specifically:
Load()
, Launch()
, and Stop()
functions.SetMediaBlocking()
, SetVisibility()
, SetTouchInputEnabled()
, and SetUrlRewriteRules()
functions.A pointer to this instance of EmbedderApplication
will also be provided to the RuntimeApplicaiton
, which will use the callbacks and controls as described previously throughout the application's lifetime.
TODO(crbug.com/1357171): Add additional documentation.