Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: chrome/browser/media/router/presentation_service_delegate_impl.h

Issue 1436703002: Revert of [Presentation API / Media Router] Clean up default pres URL logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_PRESENTATION_SERVICE_DELEGATE_IMPL_H_ 5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_PRESENTATION_SERVICE_DELEGATE_IMPL_H_
6 #define CHROME_BROWSER_MEDIA_ROUTER_PRESENTATION_SERVICE_DELEGATE_IMPL_H_ 6 #define CHROME_BROWSER_MEDIA_ROUTER_PRESENTATION_SERVICE_DELEGATE_IMPL_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/observer_list.h" 16 #include "base/observer_list.h"
17 #include "chrome/browser/media/router/media_router.h" 17 #include "chrome/browser/media/router/media_router.h"
18 #include "chrome/browser/media/router/media_source.h" 18 #include "chrome/browser/media/router/media_source.h"
19 #include "chrome/browser/media/router/presentation_request.h"
20 #include "chrome/browser/media/router/render_frame_host_id.h"
21 #include "content/public/browser/presentation_service_delegate.h" 19 #include "content/public/browser/presentation_service_delegate.h"
22 #include "content/public/browser/web_contents_observer.h" 20 #include "content/public/browser/web_contents_observer.h"
23 #include "content/public/browser/web_contents_user_data.h" 21 #include "content/public/browser/web_contents_user_data.h"
24 22
25 namespace content { 23 namespace content {
26 class RenderFrameHost; 24 class RenderFrameHost;
27 class PresentationScreenAvailabilityListener; 25 class PresentationScreenAvailabilityListener;
28 class WebContents; 26 class WebContents;
29 struct PresentationSessionInfo; 27 struct PresentationSessionInfo;
30 struct PresentationSessionMessage; 28 struct PresentationSessionMessage;
31 } // namespace content 29 } // namespace content
32 30
33 namespace media_router { 31 namespace media_router {
34 32
35 class MediaRoute; 33 class MediaRoute;
36 class MediaSinksObserver; 34 class MediaSinksObserver;
37 class PresentationFrameManager; 35 class PresentationFrameManager;
38 class PresentationSessionStateObserver; 36 class PresentationSessionStateObserver;
39 37
38 using RenderFrameHostId = std::pair<int, int>;
39
40 // Implementation of PresentationServiceDelegate that interfaces an 40 // Implementation of PresentationServiceDelegate that interfaces an
41 // instance of WebContents with the Chrome Media Router. It uses the Media 41 // instance of WebContents with the Chrome Media Router. It uses the Media
42 // Router to handle presentation API calls forwarded from 42 // Router to handle presentation API calls forwarded from
43 // PresentationServiceImpl. In addition, it also 43 // PresentationServiceImpl. In addition, it also
44 // provides default presentation URL that is required for creating 44 // provides default presentation URL that is required for creating
45 // browser-initiated sessions. 45 // browser-initiated sessions.
46 // It is scoped to the lifetime of a WebContents, and is managed by the 46 // It is scoped to the lifetime of a WebContents, and is managed by the
47 // associated WebContents. 47 // associated WebContents.
48 class PresentationServiceDelegateImpl 48 class PresentationServiceDelegateImpl
49 : public content::WebContentsUserData<PresentationServiceDelegateImpl>, 49 : public content::WebContentsUserData<PresentationServiceDelegateImpl>,
50 public content::PresentationServiceDelegate { 50 public content::PresentationServiceDelegate {
51 public: 51 public:
52 // Observer interface for listening to default presentation request
53 // changes for the WebContents.
54 class DefaultPresentationRequestObserver {
55 public:
56 virtual ~DefaultPresentationRequestObserver() = default;
57
58 // Called when default presentation request for the corresponding
59 // WebContents is set or changed.
60 // |default_presentation_info|: New default presentation request.
61 virtual void OnDefaultPresentationChanged(
62 const PresentationRequest& default_presentation_request) = 0;
63
64 // Called when default presentation request for the corresponding
65 // WebContents has been removed.
66 virtual void OnDefaultPresentationRemoved() = 0;
67 };
68
69 // Retrieves the instance of PresentationServiceDelegateImpl that was attached 52 // Retrieves the instance of PresentationServiceDelegateImpl that was attached
70 // to the specified WebContents. If no instance was attached, creates one, 53 // to the specified WebContents. If no instance was attached, creates one,
71 // and attaches it to the specified WebContents. 54 // and attaches it to the specified WebContents.
72 static PresentationServiceDelegateImpl* GetOrCreateForWebContents( 55 static PresentationServiceDelegateImpl* GetOrCreateForWebContents(
73 content::WebContents* web_contents); 56 content::WebContents* web_contents);
74 57
75 ~PresentationServiceDelegateImpl() override; 58 ~PresentationServiceDelegateImpl() override;
76 59
77 // content::PresentationServiceDelegate implementation. 60 // content::PresentationServiceDelegate implementation.
78 void AddObserver( 61 void AddObserver(
79 int render_process_id, 62 int render_process_id,
80 int render_frame_id, 63 int render_frame_id,
81 content::PresentationServiceDelegate::Observer* observer) override; 64 content::PresentationServiceDelegate::Observer* observer) override;
82 void RemoveObserver(int render_process_id, int render_frame_id) override; 65 void RemoveObserver(int render_process_id, int render_frame_id) override;
83 bool AddScreenAvailabilityListener( 66 bool AddScreenAvailabilityListener(
84 int render_process_id, 67 int render_process_id,
85 int render_frame_id, 68 int render_frame_id,
86 content::PresentationScreenAvailabilityListener* listener) override; 69 content::PresentationScreenAvailabilityListener* listener) override;
87 void RemoveScreenAvailabilityListener( 70 void RemoveScreenAvailabilityListener(
88 int render_process_id, 71 int render_process_id,
89 int render_frame_id, 72 int render_frame_id,
90 content::PresentationScreenAvailabilityListener* listener) override; 73 content::PresentationScreenAvailabilityListener* listener) override;
91 void Reset(int render_process_id, int render_frame_id) override; 74 void Reset(int render_process_id, int render_frame_id) override;
92 void SetDefaultPresentationUrl( 75 void SetDefaultPresentationUrl(
93 int render_process_id, 76 int render_process_id,
94 int render_frame_id, 77 int render_frame_id,
95 const std::string& default_presentation_url, 78 const std::string& default_presentation_url) override;
96 const content::PresentationSessionStartedCallback& callback) override; 79 void StartSession(int render_process_id,
97 void StartSession( 80 int render_frame_id,
98 int render_process_id, 81 const std::string& presentation_url,
99 int render_frame_id, 82 const PresentationSessionSuccessCallback& success_cb,
100 const std::string& presentation_url, 83 const PresentationSessionErrorCallback& error_cb) override;
101 const content::PresentationSessionStartedCallback& success_cb, 84 void JoinSession(int render_process_id,
102 const content::PresentationSessionErrorCallback& error_cb) override; 85 int render_frame_id,
103 void JoinSession( 86 const std::string& presentation_url,
104 int render_process_id, 87 const std::string& presentation_id,
105 int render_frame_id, 88 const PresentationSessionSuccessCallback& success_cb,
106 const std::string& presentation_url, 89 const PresentationSessionErrorCallback& error_cb) override;
107 const std::string& presentation_id,
108 const content::PresentationSessionStartedCallback& success_cb,
109 const content::PresentationSessionErrorCallback& error_cb) override;
110 void CloseSession(int render_process_id, 90 void CloseSession(int render_process_id,
111 int render_frame_id, 91 int render_frame_id,
112 const std::string& presentation_id) override; 92 const std::string& presentation_id) override;
113 void ListenForSessionMessages( 93 void ListenForSessionMessages(
114 int render_process_id, 94 int render_process_id,
115 int render_frame_id, 95 int render_frame_id,
116 const content::PresentationSessionInfo& session, 96 const content::PresentationSessionInfo& session,
117 const content::PresentationSessionMessageCallback& message_cb) override; 97 const content::PresentationSessionMessageCallback& message_cb) override;
118 void SendMessage(int render_process_id, 98 void SendMessage(int render_process_id,
119 int render_frame_id, 99 int render_frame_id,
120 const content::PresentationSessionInfo& session, 100 const content::PresentationSessionInfo& session,
121 scoped_ptr<content::PresentationSessionMessage> message, 101 scoped_ptr<content::PresentationSessionMessage> message,
122 const SendMessageCallback& send_message_cb) override; 102 const SendMessageCallback& send_message_cb) override;
123 void ListenForSessionStateChange( 103 void ListenForSessionStateChange(
124 int render_process_id, 104 int render_process_id,
125 int render_frame_id, 105 int render_frame_id,
126 const content::SessionStateChangedCallback& state_changed_cb) override; 106 const content::SessionStateChangedCallback& state_changed_cb) override;
127 107
128 // Callback invoked when a default PresentationRequest is started from a 108 // Callback invoked when there is a route response from CreateRoute/JoinRoute
129 // browser-initiated dialog. 109 // outside of a Presentation API request. This could be due to
130 void OnRouteResponse(const PresentationRequest& request, 110 // browser action (e.g., browser initiated media router dialog) or
131 const MediaRoute* route, 111 // a media route provider (e.g., autojoin).
112 void OnRouteResponse(const MediaRoute* route,
132 const std::string& presentation_id, 113 const std::string& presentation_id,
133 const std::string& error); 114 const std::string& error);
134 115
135 // Adds / removes an observer for listening to default PresentationRequest 116 // Returns the default MediaSource for this tab if there is one.
136 // changes. This class does not own |observer|. When |observer| is about to 117 // Returns an empty MediaSource otherwise.
137 // be destroyed, |RemoveDefaultPresentationRequestObserver| must be called. 118 MediaSource default_source() const { return default_source_; }
138 void AddDefaultPresentationRequestObserver(
139 DefaultPresentationRequestObserver* observer);
140 void RemoveDefaultPresentationRequestObserver(
141 DefaultPresentationRequestObserver* observer);
142 119
143 // Gets the default presentation request for the owning tab WebContents. It 120 content::WebContents* web_contents() const { return web_contents_; }
144 // is an error to call this method if the default presentation request does 121 const GURL& default_frame_url() const { return default_frame_url_; }
145 // not exist.
146 PresentationRequest GetDefaultPresentationRequest() const;
147 122
148 // Returns true if there is a default presentation request for the owning tab 123 // Observer interface for listening to default MediaSource changes for the
149 // WebContents. 124 // WebContents.
150 bool HasDefaultPresentationRequest() const; 125 class DefaultMediaSourceObserver {
126 public:
127 virtual ~DefaultMediaSourceObserver() {}
151 128
152 // Returns the WebContents that owns this instance. 129 // Called when default media source for the corresponding WebContents has
153 content::WebContents* web_contents() const { return web_contents_; } 130 // changed.
131 // |source|: New default MediaSource, or empty if default was removed.
132 // |frame_url|: URL of the frame that contains the default media
133 // source, or empty if there is no default media source.
134 virtual void OnDefaultMediaSourceChanged(const MediaSource& source,
135 const GURL& frame_url) = 0;
136 };
154 137
155 base::WeakPtr<PresentationServiceDelegateImpl> GetWeakPtr(); 138 // Adds / removes an observer for listening to default MediaSource changes.
139 void AddDefaultMediaSourceObserver(DefaultMediaSourceObserver* observer);
140 void RemoveDefaultMediaSourceObserver(DefaultMediaSourceObserver* observer);
156 141
157 void SetMediaRouterForTest(MediaRouter* router); 142 void SetMediaRouterForTest(MediaRouter* router);
158 bool HasScreenAvailabilityListenerForTest( 143 bool HasScreenAvailabilityListenerForTest(
159 int render_process_id, 144 int render_process_id,
160 int render_frame_id, 145 int render_frame_id,
161 const MediaSource::Id& source_id) const; 146 const MediaSource::Id& source_id) const;
162 147
148 base::WeakPtr<PresentationServiceDelegateImpl> GetWeakPtr();
149
163 private: 150 private:
164 friend class content::WebContentsUserData<PresentationServiceDelegateImpl>; 151 friend class content::WebContentsUserData<PresentationServiceDelegateImpl>;
165 FRIEND_TEST_ALL_PREFIXES(PresentationServiceDelegateImplTest, 152 FRIEND_TEST_ALL_PREFIXES(PresentationServiceDelegateImplTest,
166 DelegateObservers); 153 DelegateObservers);
167 FRIEND_TEST_ALL_PREFIXES(PresentationServiceDelegateImplTest,
168 SetDefaultPresentationUrl);
169 FRIEND_TEST_ALL_PREFIXES(PresentationServiceDelegateImplTest,
170 DefaultPresentationRequestObserver);
171 FRIEND_TEST_ALL_PREFIXES(PresentationServiceDelegateImplTest,
172 DefaultPresentationUrlCallback);
173 154
174 explicit PresentationServiceDelegateImpl(content::WebContents* web_contents); 155 explicit PresentationServiceDelegateImpl(content::WebContents* web_contents);
175 156
176 // Returns |listener|'s presentation URL as a MediaSource. If |listener| does 157 // Returns |listener|'s presentation URL as a MediaSource. If |listener| does
177 // not have a persentation URL, returns the tab mirroring MediaSource. 158 // not have a persentation URL, returns the tab mirroring MediaSource.
178 MediaSource GetMediaSourceFromListener( 159 MediaSource GetMediaSourceFromListener(
179 content::PresentationScreenAvailabilityListener* listener); 160 content::PresentationScreenAvailabilityListener* listener);
180 161
181 void OnJoinRouteResponse( 162 void OnJoinRouteResponse(int render_process_id,
182 int render_process_id, 163 int render_frame_id,
183 int render_frame_id, 164 const content::PresentationSessionInfo& session,
184 const content::PresentationSessionInfo& session, 165 const PresentationSessionSuccessCallback& success_cb,
185 const content::PresentationSessionStartedCallback& success_cb, 166 const PresentationSessionErrorCallback& error_cb,
186 const content::PresentationSessionErrorCallback& error_cb, 167 const MediaRoute* route,
187 const MediaRoute* route, 168 const std::string& presentation_id,
188 const std::string& presentation_id, 169 const std::string& error_text);
189 const std::string& error_text);
190 170
191 void OnStartSessionSucceeded( 171 void OnStartSessionSucceeded(
192 int render_process_id, 172 int render_process_id,
193 int render_frame_id, 173 int render_frame_id,
194 const content::PresentationSessionStartedCallback& success_cb, 174 const PresentationSessionSuccessCallback& success_cb,
195 const content::PresentationSessionInfo& new_session, 175 const content::PresentationSessionInfo& new_session,
196 const MediaRoute::Id& route_id); 176 const MediaRoute::Id& route_id);
197 177
178 // Returns |true| if the frame is the main frame of |web_contents_|.
179 bool IsMainFrame(int render_process_id, int render_frame_id) const;
180
181 // Updates tab-level default MediaSource, default frame URL, and the
182 // originating frame. If the source or frame URL changed, notify the
183 // observers.
184 void UpdateDefaultMediaSourceAndNotifyObservers(
185 const RenderFrameHostId& render_frame_host_id,
186 const MediaSource& new_default_source,
187 const GURL& new_default_frame_url);
188
189 // ID of RenderFrameHost that contains the default presentation.
190 RenderFrameHostId default_presentation_render_frame_host_id_;
191 // Default MediaSource for the tab associated with this instance.
192 MediaSource default_source_;
193 // URL of the frame that contains the default MediaSource.
194 GURL default_frame_url_;
195
196 // References to the observers listening for changes to default media source.
197 base::ObserverList<
198 DefaultMediaSourceObserver> default_media_source_observers_;
199
198 // References to the WebContents that owns this instance, and associated 200 // References to the WebContents that owns this instance, and associated
199 // browser profile's MediaRouter instance. 201 // browser profile's MediaRouter instance.
200 content::WebContents* const web_contents_; 202 content::WebContents* web_contents_;
201 MediaRouter* router_; 203 MediaRouter* router_;
202 204
203 scoped_ptr<PresentationFrameManager> frame_manager_; 205 scoped_ptr<PresentationFrameManager> frame_manager_;
204 206
205 base::WeakPtrFactory<PresentationServiceDelegateImpl> weak_factory_; 207 base::WeakPtrFactory<PresentationServiceDelegateImpl> weak_factory_;
206 208
207 DISALLOW_COPY_AND_ASSIGN(PresentationServiceDelegateImpl); 209 DISALLOW_COPY_AND_ASSIGN(PresentationServiceDelegateImpl);
208 }; 210 };
209 211
210 } // namespace media_router 212 } // namespace media_router
211 213
212 #endif // CHROME_BROWSER_MEDIA_ROUTER_PRESENTATION_SERVICE_DELEGATE_IMPL_H_ 214 #endif // CHROME_BROWSER_MEDIA_ROUTER_PRESENTATION_SERVICE_DELEGATE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698