| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 // TODO(crbug.com/647290): Rename "Session" to "Connection" | |
| 6 | |
| 7 module blink.mojom; | |
| 8 | |
| 9 import "url/mojo/url.mojom"; | |
| 10 | |
| 11 struct PresentationSessionInfo { | |
| 12 url.mojom.Url url; | |
| 13 string id; | |
| 14 }; | |
| 15 | |
| 16 enum PresentationConnectionState { | |
| 17 CONNECTING, | |
| 18 CONNECTED, | |
| 19 CLOSED, | |
| 20 TERMINATED | |
| 21 }; | |
| 22 | |
| 23 enum PresentationConnectionCloseReason { | |
| 24 CONNECTION_ERROR, | |
| 25 CLOSED, | |
| 26 WENT_AWAY | |
| 27 }; | |
| 28 | |
| 29 enum PresentationErrorType { | |
| 30 NO_AVAILABLE_SCREENS, | |
| 31 SESSION_REQUEST_CANCELLED, | |
| 32 NO_PRESENTATION_FOUND, | |
| 33 UNKNOWN, | |
| 34 }; | |
| 35 | |
| 36 struct PresentationError { | |
| 37 PresentationErrorType error_type; | |
| 38 string message; | |
| 39 }; | |
| 40 | |
| 41 enum PresentationMessageType { | |
| 42 TEXT, | |
| 43 BINARY, | |
| 44 }; | |
| 45 | |
| 46 struct ConnectionMessage { | |
| 47 PresentationMessageType type; | |
| 48 // Used when message type is TEXT. | |
| 49 string? message; | |
| 50 // Used when message type is BINARY. | |
| 51 // TODO(lethalantidote): Make this a mojo union. | |
| 52 // See https://crbug.com/632623. | |
| 53 array<uint8>? data; | |
| 54 }; | |
| 55 | |
| 56 interface PresentationConnection { | |
| 57 // TODO(zhaobin): migrate SendConnectionMessage from PresentationService => | |
| 58 // PresentationConnection.Send(). http://crbug.com/658474 | |
| 59 | |
| 60 // Called when a message is sent by the target connection. | |
| 61 OnMessage(ConnectionMessage message) => (bool success); | |
| 62 | |
| 63 // Called when target connection notifies connection state change. | |
| 64 DidChangeState(PresentationConnectionState state); | |
| 65 }; | |
| 66 | |
| 67 interface PresentationService { | |
| 68 // Sets the PresentationServiceClient. | |
| 69 SetClient(PresentationServiceClient client); | |
| 70 | |
| 71 ///////////// Functions here are for the controller part of the API. ///////// | |
| 72 | |
| 73 // Called when the frame sets or changes the default presentation URLs. | |
| 74 // When the default presentation is started on this frame, | |
| 75 // PresentationServiceClient::OnDefaultSessionStarted will be invoked. | |
| 76 SetDefaultPresentationUrls(array<url.mojom.Url> presentation_urls); | |
| 77 | |
| 78 // Starts listening for screen availability for presentation of | |
| 79 // |availability_url|. Availability results will be returned to the client via | |
| 80 // PresentationServiceClient::OnScreenAvailabilityUpdated. | |
| 81 ListenForScreenAvailability(url.mojom.Url availability_url); | |
| 82 | |
| 83 // Stops listening for screen availability for the presentation of |url|. The | |
| 84 // PresentationServiceClient will stop receiving availability updates for | |
| 85 // |url|. | |
| 86 StopListeningForScreenAvailability(url.mojom.Url availability_url); | |
| 87 | |
| 88 // Called when startSession() is called by the frame. The result callback | |
| 89 // will return a non-null and valid PresentationSessionInfo if starting the | |
| 90 // session succeeded, or null with a PresentationError if starting the | |
| 91 // session failed. | |
| 92 // The presentation id returned in |sessionInfo| on success is generated by | |
| 93 // the UA. | |
| 94 // If the UA identifies a matching session (same presentation url), the user | |
| 95 // may choose this existing session and the page will join it rather than get | |
| 96 // a new one. | |
| 97 StartSession(array<url.mojom.Url> presentation_urls) | |
| 98 => (PresentationSessionInfo? sessionInfo, PresentationError? error); | |
| 99 | |
| 100 // Called when joinSession() is called by the frame. The result callback | |
| 101 // works the same as for the method above. JoinSession will join a known | |
| 102 // session (i.e. when the page navigates or the user opens another tab) | |
| 103 // silently and without user action. | |
| 104 JoinSession(array<url.mojom.Url> presentation_urls, string? presentation_id) | |
| 105 => (PresentationSessionInfo? sessionInfo, PresentationError? error); | |
| 106 | |
| 107 // Called in StartSession's callback function for offscreen presentation only. | |
| 108 // It passes in controlling frame's PresentationConnection and | |
| 109 // PresentationConnectionRequest to PresentationService. | |
| 110 SetPresentationConnection( | |
| 111 PresentationSessionInfo sessionInfo, | |
| 112 PresentationConnection controller_connection_ptr, | |
| 113 PresentationConnection& receiver_connection_request); | |
| 114 | |
| 115 ////////////////////////////////////////////////////////////////////////////// | |
| 116 | |
| 117 // Called when send() is called by the frame. The true in the | |
| 118 // result callback notifies that the service is ready for next message. | |
| 119 // The false in the result callback notifies the renderer to stop sending | |
| 120 // the send requests and invalidate all pending requests. This occurs | |
| 121 // for eg., when frame is deleted or navigated away. | |
| 122 SendConnectionMessage(PresentationSessionInfo sessionInfo, | |
| 123 ConnectionMessage message_request) => (bool success); | |
| 124 | |
| 125 // Called when close() is called by the frame. | |
| 126 CloseConnection(url.mojom.Url presentation_url, string presentation_id); | |
| 127 | |
| 128 // Called when terminate() is called by the frame. | |
| 129 Terminate(url.mojom.Url presentation_url, string presentation_id); | |
| 130 | |
| 131 // Starts listening for messages for session with |sessionInfo|. | |
| 132 // Messages will be received in | |
| 133 // PresentationServiceClient::OnConnectionMessagesReceived. | |
| 134 // This is called after a presentation session is created. | |
| 135 ListenForConnectionMessages(PresentationSessionInfo sessionInfo); | |
| 136 }; | |
| 137 | |
| 138 interface PresentationServiceClient { | |
| 139 | |
| 140 ////////////Functions here are called only on the controlling page./////////// | |
| 141 | |
| 142 // Called when the client tries to listen for screen availability changes for | |
| 143 // presentation of |url| but it is not supported by the device or underlying | |
| 144 // platform. This can also be called if the device is currently in a mode | |
| 145 // where it can't do screen discoveries (eg. low battery). | |
| 146 OnScreenAvailabilityNotSupported(url.mojom.Url url); | |
| 147 | |
| 148 // Called when the client is listening for screen availability for | |
| 149 // presentation of |url| and the state changes. When the client starts to | |
| 150 // listen for screen availability, this method will always be called to give | |
| 151 // the current known state. It will then be called to notify of state updates. | |
| 152 OnScreenAvailabilityUpdated(url.mojom.Url url, bool available); | |
| 153 | |
| 154 // See PresentationService::SetDefaultPresentationURL. | |
| 155 OnDefaultSessionStarted(PresentationSessionInfo sessionInfo); | |
| 156 | |
| 157 ////////////////////////////////////////////////////////////////////////////// | |
| 158 | |
| 159 // Called when the state of PresentationConnection |connection| started on | |
| 160 // this frame has changed to |newState|. | |
| 161 OnConnectionStateChanged(PresentationSessionInfo connection, | |
| 162 PresentationConnectionState newState); | |
| 163 | |
| 164 // Caled when the state of |connection| started on this frame has changed to | |
| 165 // CLOSED. | |
| 166 OnConnectionClosed(PresentationSessionInfo connection, | |
| 167 PresentationConnectionCloseReason reason, | |
| 168 string message); | |
| 169 | |
| 170 // See PresentationService::ListenForConnectionMessages. | |
| 171 OnConnectionMessagesReceived(PresentationSessionInfo sessionInfo, | |
| 172 array<ConnectionMessage> messages); | |
| 173 | |
| 174 // Called on a presentation receiver when presentation connection is available | |
| 175 // from the controlling page. | |
| 176 OnReceiverConnectionAvailable( | |
| 177 PresentationSessionInfo sessionInfo, | |
| 178 PresentationConnection controller_connection_ptr, | |
| 179 PresentationConnection& receiver_connection_request); | |
| 180 }; | |
| OLD | NEW |