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 PresentationMessageType type;
37 // Used when message type is TEXT.
39 // Used when message type is ARRAY_BUFFER or BLOB.
43 interface PresentationService {
44 // Called when the frame sets or changes the default presentation URL.
45 SetDefaultPresentationURL(string url);
47 // Sets the PresentationServiceClient.
48 SetClient(PresentationServiceClient client);
50 // Starts listening for screen availability for presentation of
51 // |url|. Availability results will be returned to the client via
52 // PresentationServiceClient::OnScreenAvailabilityUpdated.
53 ListenForScreenAvailability(string url);
55 // Stops listening for screen availability for the presentation of |url|. The
56 // PresentationServiceClient will stop receiving availability updates for
58 StopListeningForScreenAvailability(string url);
60 // Called when the renderer is ready to receive the browser initiated
61 // session. If the default session is started by the embedder before this
62 // call, the embedder may queue it and run the callback when the call is
64 ListenForDefaultSessionStart()
65 => (PresentationSessionInfo? defaultSessionInfo);
67 // Called when startSession() is called by the frame. The result callback
68 // will return a non-null and valid PresentationSessionInfo if starting the
69 // session succeeded, or null with a PresentationError if starting the
71 // The presentation id returned in |sessionInfo| on success is generated by
73 // If the UA identifies a matching session (same presentation url), the user
74 // may choose this existing session and the page will join it rather than get
76 StartSession(string presentation_url)
77 => (PresentationSessionInfo? sessionInfo, PresentationError? error);
79 // Called when joinSession() is called by the frame. The result callback
80 // works the same as for the method above. JoinSession will join a known
81 // session (i.e. when the page navigates or the user opens another tab)
82 // silently and without user action.
83 JoinSession(string presentation_url, string? presentation_id)
84 => (PresentationSessionInfo? sessionInfo, PresentationError? error);
86 // Called when send() is called by the frame. The true in the
87 // result callback notifies that the service is ready for next message.
88 // The false in the result callback notifies the renderer to stop sending
89 // the send requests and invalidate all pending requests. This occurs
90 // for eg., when frame is deleted or navigated away.
91 SendSessionMessage(PresentationSessionInfo sessionInfo, SessionMessage message_request) => (bool success);
93 // Called when closeSession() is called by the frame.
94 CloseSession(string presentation_url, string presentation_id);
96 // Starts listening for state changes for sessions created on this frame.
97 // When state change occurs, PresentationServiceClient::OnSessionStateChanged
98 // will be invoked with the session and its new state.
99 // This is called after a presentation session is created.
100 ListenForSessionStateChange();
102 // Starts listening for messages for session with |sessionInfo|.
103 // Messages will be received in
104 // PresentationServiceClient::OnSessionMessagesReceived.
105 // This is called after a presentation session is created.
106 ListenForSessionMessages(PresentationSessionInfo sessionInfo);
109 interface PresentationServiceClient {
110 // Called when the client tries to listen for screen availability changes for
111 // presentation of |url| but it is not supported by the device or underlying
112 // platform. This can also be called if the device is currently in a mode
113 // where it can't do screen discoveries (eg. low battery).
114 OnScreenAvailabilityNotSupported(string url);
116 // Called when the client is listening for screen availability for
117 // presentation of |url| and the state changes. When the client starts to
118 // listen for screen availability, this method will always be called to give
119 // the current known state. It will then be called to notify of state updates.
120 OnScreenAvailabilityUpdated(string url, bool available);
122 // See PresentationService::ListenForSessionStateChange.
123 OnSessionStateChanged(PresentationSessionInfo sessionInfo,
124 PresentationSessionState newState);
126 // See PresentationService::ListenForSessionMessages.
127 OnSessionMessagesReceived(PresentationSessionInfo sessionInfo, array<SessionMessage> messages);