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 #ifndef CHROME_BROWSER_MEDIA_ROUTER_RECEIVER_PRESENTATION_SERVICE_DELEGATE_IMPL_
H_ |
| 6 #define CHROME_BROWSER_MEDIA_ROUTER_RECEIVER_PRESENTATION_SERVICE_DELEGATE_IMPL_
H_ |
| 7 |
| 8 #include <map> |
| 9 |
| 10 #include "base/observer_list.h" |
| 11 #include "chrome/browser/media/router/offscreen_presentation_manager.h" |
| 12 #include "chrome/browser/media/router/offscreen_presentation_manager_factory.h" |
| 13 #include "chrome/browser/media/router/render_frame_host_id.h" |
| 14 #include "content/public/browser/presentation_service_delegate.h" |
| 15 #include "content/public/browser/web_contents_user_data.h" |
| 16 |
| 17 namespace content { |
| 18 class RenderFrameHost; |
| 19 class WebContents; |
| 20 struct PresentationSessionInfo; |
| 21 struct PresentationSessionMessage; |
| 22 } // namespace content |
| 23 |
| 24 namespace media_router { |
| 25 |
| 26 // Implements the receiver side of presentation API for offscreen presentations. |
| 27 // Created under the offscreen tab WebContents when the tab is created for an |
| 28 // offscreen presentation. Each instance is tied to a single offscreen |
| 29 // presentation whose ID is given during construction. As such, the receiver |
| 30 // APIs are contextual with the offscreen presentation. |
| 31 // Only the main frame of the offscreen tab is allowed to make receiver |
| 32 // Presentation API requests; requests made from any other frame will be |
| 33 // rejected. |
| 34 class ReceiverPresentationServiceDelegateImpl |
| 35 : public content::WebContentsUserData< |
| 36 ReceiverPresentationServiceDelegateImpl>, |
| 37 public content::PresentationServiceDelegate { |
| 38 public: |
| 39 // Creates an instance of ReceiverPresentationServiceDelegateImpl under |
| 40 // |web_contents| and registers it as the receiver of the offscreen |
| 41 // presentation |presentation_id| with OffscreenPresentationManager. |
| 42 // No-op if a ReceiverPresentationServiceDelegateImpl instance already |
| 43 // exists under |web_contents|. |
| 44 static void CreateForWebContents(content::WebContents* web_contents, |
| 45 const std::string& presentation_id); |
| 46 |
| 47 ~ReceiverPresentationServiceDelegateImpl() override; |
| 48 |
| 49 // content::PresentationServiceDelegate implementation. |
| 50 void AddObserver( |
| 51 int render_process_id, |
| 52 int render_frame_id, |
| 53 content::PresentationServiceDelegate::Observer* observer) override; |
| 54 void RemoveObserver(int render_process_id, int render_frame_id) override; |
| 55 bool AddScreenAvailabilityListener( |
| 56 int render_process_id, |
| 57 int render_frame_id, |
| 58 content::PresentationScreenAvailabilityListener* listener) override; |
| 59 void RemoveScreenAvailabilityListener( |
| 60 int render_process_id, |
| 61 int render_frame_id, |
| 62 content::PresentationScreenAvailabilityListener* listener) override; |
| 63 void Reset(int render_process_id, int render_frame_id) override; |
| 64 void SetDefaultPresentationUrls( |
| 65 int render_process_id, |
| 66 int render_frame_id, |
| 67 const std::vector<std::string>& default_presentation_urls, |
| 68 const content::PresentationSessionStartedCallback& callback) override; |
| 69 void StartSession( |
| 70 int render_process_id, |
| 71 int render_frame_id, |
| 72 const std::vector<std::string>& presentation_urls, |
| 73 const content::PresentationSessionStartedCallback& success_cb, |
| 74 const content::PresentationSessionErrorCallback& error_cb) override; |
| 75 void JoinSession( |
| 76 int render_process_id, |
| 77 int render_frame_id, |
| 78 const std::vector<std::string>& presentation_urls, |
| 79 const std::string& presentation_id, |
| 80 const content::PresentationSessionStartedCallback& success_cb, |
| 81 const content::PresentationSessionErrorCallback& error_cb) override; |
| 82 void CloseConnection(int render_process_id, |
| 83 int render_frame_id, |
| 84 const std::string& presentation_id) override; |
| 85 void Terminate(int render_process_id, |
| 86 int render_frame_id, |
| 87 const std::string& presentation_id) override; |
| 88 void ListenForSessionMessages( |
| 89 int render_process_id, |
| 90 int render_frame_id, |
| 91 const content::PresentationSessionInfo& session_info, |
| 92 const content::PresentationSessionMessageCallback& message_cb) override; |
| 93 void SendMessage(int render_process_id, |
| 94 int render_frame_id, |
| 95 const content::PresentationSessionInfo& session_info, |
| 96 std::unique_ptr<content::PresentationSessionMessage> message, |
| 97 const SendMessageCallback& send_message_cb) override; |
| 98 void ListenForConnectionStateChange( |
| 99 int render_process_id, |
| 100 int render_frame_id, |
| 101 const content::PresentationSessionInfo& connection, |
| 102 const content::PresentationConnectionStateChangedCallback& |
| 103 state_changed_cb) override; |
| 104 |
| 105 void RegisterOffscreenPresentationReceiver( |
| 106 content::OffscreenPresentationClient*) override; |
| 107 |
| 108 void UnregisterOffscreenPresentationReceiver( |
| 109 content::OffscreenPresentationClient*) override; |
| 110 |
| 111 void RegisterOffscreenPresentationController( |
| 112 const std::string& presentation_id, |
| 113 content::OffscreenPresentationClient*) override {} |
| 114 |
| 115 void UnregisterOffscreenPresentationController( |
| 116 const std::string& presentation_id, |
| 117 content::OffscreenPresentationClient*) override {} |
| 118 |
| 119 private: |
| 120 friend class content::WebContentsUserData< |
| 121 ReceiverPresentationServiceDelegateImpl>; |
| 122 |
| 123 explicit ReceiverPresentationServiceDelegateImpl( |
| 124 content::WebContents* web_contents, |
| 125 const std::string& presentation_id); |
| 126 |
| 127 // Reference to the WebContents that owns this instance. |
| 128 content::WebContents* const web_contents_; |
| 129 |
| 130 const std::string presentation_id_; |
| 131 OffscreenPresentationManager* const offscreen_presentation_manager_; |
| 132 std::map<RenderFrameHostId, content::PresentationServiceDelegate::Observer*> |
| 133 observers_; |
| 134 |
| 135 // Set to the current main frame of the owning WebContents on first request, |
| 136 // and unset when Reset() is called with current main frame. When this is |
| 137 // set, incoming requests except Reset() will be rejected if it does not match |
| 138 // the incoming frame. |
| 139 RenderFrameHostId current_frame_id_; |
| 140 |
| 141 DISALLOW_COPY_AND_ASSIGN(ReceiverPresentationServiceDelegateImpl); |
| 142 }; |
| 143 |
| 144 } // namespace media_router |
| 145 |
| 146 #endif // CHROME_BROWSER_MEDIA_ROUTER_RECEIVER_PRESENTATION_SERVICE_DELEGATE_IM
PL_H_ |
OLD | NEW |