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