| OLD | NEW |
| 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 CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ | 5 #ifndef CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ |
| 6 #define CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ | 6 #define CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ |
| 7 | 7 |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/memory/linked_ptr.h" | 9 #include "base/memory/linked_ptr.h" |
| 10 #include "content/common/content_export.h" | 10 #include "content/common/content_export.h" |
| 11 #include "content/common/presentation/presentation_service.mojom.h" | 11 #include "content/common/presentation/presentation_service.mojom.h" |
| 12 #include "content/public/renderer/render_frame_observer.h" | 12 #include "content/public/renderer/render_frame_observer.h" |
| 13 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nClient.h" | 13 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nClient.h" |
| 14 | 14 |
| 15 namespace blink { | 15 namespace blink { |
| 16 class WebString; | 16 class WebString; |
| 17 } // namespace blink | 17 } // namespace blink |
| 18 | 18 |
| 19 namespace content { | 19 namespace content { |
| 20 | 20 |
| 21 // PresentationDispatcher is a delegate for Presentation API messages used by | 21 // PresentationDispatcher is a delegate for Presentation API messages used by |
| 22 // Blink. It forwards the calls to the Mojo PresentationService. | 22 // Blink. It forwards the calls to the Mojo PresentationService. |
| 23 class CONTENT_EXPORT PresentationDispatcher | 23 class CONTENT_EXPORT PresentationDispatcher |
| 24 : public RenderFrameObserver, | 24 : public RenderFrameObserver, |
| 25 public NON_EXPORTED_BASE(blink::WebPresentationClient) { | 25 public NON_EXPORTED_BASE(blink::WebPresentationClient), |
| 26 public NON_EXPORTED_BASE(presentation::PresentationServiceClient) { |
| 26 public: | 27 public: |
| 27 explicit PresentationDispatcher(RenderFrame* render_frame); | 28 explicit PresentationDispatcher(RenderFrame* render_frame); |
| 28 ~PresentationDispatcher() override; | 29 ~PresentationDispatcher() override; |
| 29 | 30 |
| 30 private: | 31 private: |
| 31 // WebPresentationClient implementation. | 32 // WebPresentationClient implementation. |
| 32 virtual void setController( | 33 virtual void setController( |
| 33 blink::WebPresentationController* controller); | 34 blink::WebPresentationController* controller); |
| 34 virtual void updateAvailableChangeWatched(bool watched); | 35 virtual void updateAvailableChangeWatched(bool watched); |
| 35 virtual void startSession( | 36 virtual void startSession( |
| (...skipping 16 matching lines...) Expand all Loading... |
| 52 virtual void closeSession( | 53 virtual void closeSession( |
| 53 const blink::WebString& presentationUrl, | 54 const blink::WebString& presentationUrl, |
| 54 const blink::WebString& presentationId); | 55 const blink::WebString& presentationId); |
| 55 | 56 |
| 56 // RenderFrameObserver implementation. | 57 // RenderFrameObserver implementation. |
| 57 void DidChangeDefaultPresentation() override; | 58 void DidChangeDefaultPresentation() override; |
| 58 void DidCommitProvisionalLoad( | 59 void DidCommitProvisionalLoad( |
| 59 bool is_new_navigation, | 60 bool is_new_navigation, |
| 60 bool is_same_page_navigation) override; | 61 bool is_same_page_navigation) override; |
| 61 | 62 |
| 62 void OnScreenAvailabilityChanged( | 63 // presentation::PresentationServiceClient |
| 63 const std::string& presentation_url, | 64 void OnScreenAvailabilityUpdated(bool available) override; |
| 64 bool available); | 65 |
| 65 void OnSessionCreated( | 66 void OnSessionCreated( |
| 66 blink::WebPresentationSessionClientCallbacks* callback, | 67 blink::WebPresentationSessionClientCallbacks* callback, |
| 67 presentation::PresentationSessionInfoPtr session_info, | 68 presentation::PresentationSessionInfoPtr session_info, |
| 68 presentation::PresentationErrorPtr error); | 69 presentation::PresentationErrorPtr error); |
| 69 void OnDefaultSessionStarted( | 70 void OnDefaultSessionStarted( |
| 70 presentation::PresentationSessionInfoPtr session_info); | 71 presentation::PresentationSessionInfoPtr session_info); |
| 71 void OnSessionStateChange( | 72 void OnSessionStateChange( |
| 72 presentation::PresentationSessionInfoPtr session_info, | 73 presentation::PresentationSessionInfoPtr session_info, |
| 73 presentation::PresentationSessionState session_state); | 74 presentation::PresentationSessionState session_state); |
| 74 void OnSessionMessagesReceived( | 75 void OnSessionMessagesReceived( |
| 75 mojo::Array<presentation::SessionMessagePtr> messages); | 76 mojo::Array<presentation::SessionMessagePtr> messages); |
| 77 void DoSendMessage(const presentation::SessionMessage& session_message); |
| 78 void HandleSendMessageRequests(bool success); |
| 76 | 79 |
| 77 void ConnectToPresentationServiceIfNeeded(); | 80 void ConnectToPresentationServiceIfNeeded(); |
| 78 | 81 |
| 79 void DoUpdateAvailableChangeWatched( | |
| 80 const std::string& presentation_url, | |
| 81 bool watched); | |
| 82 | |
| 83 void DoSendMessage(const presentation::SessionMessage& session_message); | |
| 84 void HandleSendMessageRequests(bool success); | |
| 85 | |
| 86 // Used as a weak reference. Can be null since lifetime is bound to the frame. | 82 // Used as a weak reference. Can be null since lifetime is bound to the frame. |
| 87 blink::WebPresentationController* controller_; | 83 blink::WebPresentationController* controller_; |
| 88 presentation::PresentationServicePtr presentation_service_; | 84 presentation::PresentationServicePtr presentation_service_; |
| 85 mojo::Binding<presentation::PresentationServiceClient> binding_; |
| 89 | 86 |
| 90 // Message requests are queued here and only one message at a time is sent | 87 // Message requests are queued here and only one message at a time is sent |
| 91 // over mojo channel. | 88 // over mojo channel. |
| 92 using MessageRequestQueue = | 89 using MessageRequestQueue = |
| 93 std::queue<linked_ptr<presentation::SessionMessage>>; | 90 std::queue<linked_ptr<presentation::SessionMessage>>; |
| 94 MessageRequestQueue message_request_queue_; | 91 MessageRequestQueue message_request_queue_; |
| 92 |
| 93 DISALLOW_COPY_AND_ASSIGN(PresentationDispatcher); |
| 95 }; | 94 }; |
| 96 | 95 |
| 97 } // namespace content | 96 } // namespace content |
| 98 | 97 |
| 99 #endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ | 98 #endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ |
| OLD | NEW |