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