1 // Copyright 2015 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.
7 struct PresentationSessionInfo {
12 enum PresentationSessionState {
17 enum PresentationErrorType {
19 SESSION_REQUEST_CANCELLED,
20 NO_PRESENTATION_FOUND,
24 struct PresentationError {
25 PresentationErrorType error_type;
29 enum PresentationMessageType {
35 struct SessionMessage {
36 string presentation_url;
37 string presentation_id;
38 PresentationMessageType type;
39 // Used when message type is TEXT.
41 // Used when message type is ARRAY_BUFFER or BLOB.
45 interface PresentationService {
46 // Called when the frame sets or changes the default presentation URL.
47 SetDefaultPresentationURL(string url);
49 // Sets the PresentationServiceClient.
50 SetClient(PresentationServiceClient client);
52 // Starts listening for screen availability for the current default
53 // presentation URL. Availability results will be returned to the client
54 // via PresentationServiceClient::OnScreenAvailabilityUpdated.
55 ListenForScreenAvailability();
57 // Stops listening for screen availability for the current default
58 // default presentation URL. The client will stop receiving availability
60 StopListeningForScreenAvailability();
62 // Called when the renderer is ready to receive the browser initiated
63 // session. If the default session is started by the embedder before this
64 // call, the embedder may queue it and run the callback when the call is
66 ListenForDefaultSessionStart()
67 => (PresentationSessionInfo? defaultSessionInfo);
69 // Called when startSession() is called by the frame. The result callback
70 // will return a non-null and valid PresentationSessionInfo if starting the
71 // session succeeded, or null with a PresentationError if starting the
73 // The presentation id returned in |sessionInfo| on success is generated by
75 // If the UA identifies a matching session (same presentation url), the user
76 // may choose this existing session and the page will join it rather than get
78 StartSession(string presentation_url)
79 => (PresentationSessionInfo? sessionInfo, PresentationError? error);
81 // Called when joinSession() is called by the frame. The result callback
82 // works the same as for the method above. JoinSession will join a known
83 // session (i.e. when the page navigates or the user opens another tab)
84 // silently and without user action.
85 JoinSession(string presentation_url, string? presentation_id)
86 => (PresentationSessionInfo? sessionInfo, PresentationError? error);
88 // Called when send() is called by the frame. The true in the
89 // result callback notifies that the service is ready for next message.
90 // The false in the result callback notifies the renderer to stop sending
91 // the send requests and invalidate all pending requests. This occurs
92 // for eg., when frame is deleted or navigated away.
93 SendSessionMessage(SessionMessage message_request) => (bool success);
95 // Called when closeSession() is called by the frame.
96 CloseSession(string presentation_url, string presentation_id);
98 // Starts listening for state changes for sessions created on this frame.
99 // When state change occurs, PresentationServiceClient::OnSessionStateChanged
100 // will be invoked with the session and its new state.
101 ListenForSessionStateChange();
103 // Called when the frame is ready to process the next batch of messages.
104 // When the callback carries null messages, there is an error
105 // at the presentation service side.
106 ListenForSessionMessages()
107 => (array<SessionMessage>? messages);
110 interface PresentationServiceClient {
111 // Called when the client tries to listen for screen availability changes but
112 // it is not supported by the device or underlying platform. This can also be
113 // called if the device is currently in a mode where it can't do screen
114 // discoveries (eg. low battery).
115 OnScreenAvailabilityNotSupported();
117 // Called when the client is listening for screen availability and the state
118 // changes. When the client starts to listen for screen availability, this
119 // method will always be called to give the current known state. It will then
120 // be called to notify of state updates.
121 OnScreenAvailabilityUpdated(bool available);
123 // See PresentationService::ListenForSessionStateChange.
124 OnSessionStateChanged(PresentationSessionInfo sessionInfo,
125 PresentationSessionState newState);