Update V8 to version 4.6.61.
[chromium-blink-merge.git] / content / public / browser / presentation_service_delegate.h
blob90d0ce4b13343ce8853516d60d84c572d3d75769
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.
5 #ifndef CONTENT_PUBLIC_BROWSER_PRESENTATION_SERVICE_DELEGATE_H_
6 #define CONTENT_PUBLIC_BROWSER_PRESENTATION_SERVICE_DELEGATE_H_
8 #include <vector>
10 #include "base/callback.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/scoped_vector.h"
13 #include "content/common/content_export.h"
14 #include "content/public/browser/presentation_session.h"
15 #include "content/public/browser/presentation_session_message.h"
17 namespace content {
19 class PresentationScreenAvailabilityListener;
21 using SessionStateChangedCallback =
22 base::Callback<void(const PresentationSessionInfo&,
23 PresentationSessionState)>;
24 using PresentationSessionMessageCallback = base::Callback<void(
25 const ScopedVector<content::PresentationSessionMessage>&)>;
27 // An interface implemented by embedders to handle presentation API calls
28 // forwarded from PresentationServiceImpl.
29 class CONTENT_EXPORT PresentationServiceDelegate {
30 public:
31 // Observer interface to listen for changes to PresentationServiceDelegate.
32 class CONTENT_EXPORT Observer {
33 public:
34 // Called when the PresentationServiceDelegate is being destroyed.
35 virtual void OnDelegateDestroyed() = 0;
37 // Called when the default presentation has been started outside of a
38 // Presentation API context (e.g., browser action). This will not be called
39 // if the session was created as a result of Presentation API's
40 // StartSession()/JoinSession().
41 virtual void OnDefaultPresentationStarted(
42 const PresentationSessionInfo& session) = 0;
44 protected:
45 virtual ~Observer() {}
48 using PresentationSessionSuccessCallback =
49 base::Callback<void(const PresentationSessionInfo&)>;
50 using PresentationSessionErrorCallback =
51 base::Callback<void(const PresentationError&)>;
52 using SendMessageCallback = base::Callback<void(bool)>;
54 virtual ~PresentationServiceDelegate() {}
56 // Registers an observer associated with frame with |render_process_id|
57 // and |render_frame_id| with this class to listen for updates.
58 // This class does not own the observer.
59 // It is an error to add an observer if there is already an observer for that
60 // frame.
61 virtual void AddObserver(int render_process_id,
62 int render_frame_id,
63 Observer* observer) = 0;
65 // Unregisters the observer associated with the frame with |render_process_id|
66 // and |render_frame_id|.
67 // The observer will no longer receive updates.
68 virtual void RemoveObserver(int render_process_id, int render_frame_id) = 0;
70 // Registers |listener| to continuously listen for
71 // availability updates for a presentation URL, originated from the frame
72 // given by |render_process_id| and |render_frame_id|.
73 // This class does not own |listener|.
74 // Returns true on success.
75 // This call will return false if a listener with the same presentation URL
76 // from the same frame is already registered.
77 virtual bool AddScreenAvailabilityListener(
78 int render_process_id,
79 int render_frame_id,
80 PresentationScreenAvailabilityListener* listener) = 0;
82 // Unregisters |listener| originated from the frame given by
83 // |render_process_id| and |render_frame_id| from this class. The listener
84 // will no longer receive availability updates.
85 virtual void RemoveScreenAvailabilityListener(
86 int render_process_id,
87 int render_frame_id,
88 PresentationScreenAvailabilityListener* listener) = 0;
90 // Resets the presentation state for the frame given by |render_process_id|
91 // and |render_frame_id|.
92 // This unregisters all listeners associated with the given frame, and clears
93 // the default presentation URL and ID set for the frame.
94 virtual void Reset(
95 int render_process_id,
96 int render_frame_id) = 0;
98 // Sets the default presentation URL for frame given by |render_process_id|
99 // and |render_frame_id|.
100 // If |default_presentation_url| is empty, the default presentation URL will
101 // be cleared.
102 virtual void SetDefaultPresentationUrl(
103 int render_process_id,
104 int render_frame_id,
105 const std::string& default_presentation_url) = 0;
107 // Starts a new presentation session. The presentation id of the session will
108 // be the default presentation ID if any or a generated one otherwise.
109 // Typically, the embedder will allow the user to select a screen to show
110 // |presentation_url|.
111 // |render_process_id|, |render_frame_id|: ID of originating frame.
112 // |presentation_url|: URL of the presentation.
113 // |success_cb|: Invoked with session info, if presentation session started
114 // successfully.
115 // |error_cb|: Invoked with error reason, if presentation session did not
116 // start.
117 virtual void StartSession(
118 int render_process_id,
119 int render_frame_id,
120 const std::string& presentation_url,
121 const PresentationSessionSuccessCallback& success_cb,
122 const PresentationSessionErrorCallback& error_cb) = 0;
124 // Joins an existing presentation session. Unlike StartSession(), this
125 // does not bring a screen list UI.
126 // |render_process_id|, |render_frame_id|: ID for originating frame.
127 // |presentation_url|: URL of the presentation.
128 // |presentation_id|: The ID of the presentation to join.
129 // |success_cb|: Invoked with session info, if presentation session joined
130 // successfully.
131 // |error_cb|: Invoked with error reason, if joining failed.
132 virtual void JoinSession(
133 int render_process_id,
134 int render_frame_id,
135 const std::string& presentation_url,
136 const std::string& presentation_id,
137 const PresentationSessionSuccessCallback& success_cb,
138 const PresentationSessionErrorCallback& error_cb) = 0;
140 // Close an existing presentation session.
141 // |render_process_id|, |render_frame_id|: ID for originating frame.
142 // |presentation_id|: The ID of the presentation to close.
143 virtual void CloseSession(int render_process_id,
144 int render_frame_id,
145 const std::string& presentation_id) = 0;
147 // Listen for messages for a presentation session.
148 // |render_process_id|, |render_frame_id|: ID for originating frame.
149 // |session|: URL and ID of presentation session to listen for messages.
150 // |message_cb|: Invoked with a non-empty list of messages whenever there are
151 // messages.
152 virtual void ListenForSessionMessages(
153 int render_process_id,
154 int render_frame_id,
155 const content::PresentationSessionInfo& session,
156 const PresentationSessionMessageCallback& message_cb) = 0;
158 // Sends a message (string or binary data) to a presentation session.
159 // |render_process_id|, |render_frame_id|: ID of originating frame.
160 // |session|: The presentation session to send the message to.
161 // |message|: The message to send. The embedder takes ownership of |message|.
162 // Must not be null.
163 // |send_message_cb|: Invoked after handling the send message request.
164 virtual void SendMessage(int render_process_id,
165 int render_frame_id,
166 const content::PresentationSessionInfo& session,
167 scoped_ptr<PresentationSessionMessage> message,
168 const SendMessageCallback& send_message_cb) = 0;
170 // Continuously listen for presentation session state changes for a frame.
171 // |render_process_id|, |render_frame_id|: ID of frame.
172 // |state_changed_cb|: Invoked with the session and its new state whenever
173 // there is a state change.
174 virtual void ListenForSessionStateChange(
175 int render_process_id,
176 int render_frame_id,
177 const SessionStateChangedCallback& state_changed_cb) = 0;
180 } // namespace content
182 #endif // CONTENT_PUBLIC_BROWSER_PRESENTATION_SERVICE_DELEGATE_H_