From 5efd9a92bf63048d87042bb969e2be9503f7d4ee Mon Sep 17 00:00:00 2001 From: avayvod Date: Fri, 13 Mar 2015 08:41:02 -0700 Subject: [PATCH] [Presentation API] Tracking the default presentation URL defined by the frame. BUG=459001 Receiving the notification about the default presentation URL changing from Blink side and passing it on to the PresentationService Mojo service. Depends on the Blink change: https://codereview.chromium.org/997903003 Review URL: https://codereview.chromium.org/1002573002 Cr-Commit-Position: refs/heads/master@{#320505} --- .../presentation/presentation_service_impl.cc | 10 ++++++++- .../presentation/presentation_service_impl.h | 6 +++++- .../common/presentation/presentation_service.mojom | 10 +++++++-- content/public/renderer/render_frame_observer.h | 1 + .../presentation/presentation_dispatcher.cc | 25 ++++++++++++++++++++-- .../presentation/presentation_dispatcher.h | 3 +++ content/renderer/render_frame_impl.cc | 8 +++++++ content/renderer/render_frame_impl.h | 1 + 8 files changed, 58 insertions(+), 6 deletions(-) diff --git a/content/browser/presentation/presentation_service_impl.cc b/content/browser/presentation/presentation_service_impl.cc index 824dbc210848..8e39317f1484 100644 --- a/content/browser/presentation/presentation_service_impl.cc +++ b/content/browser/presentation/presentation_service_impl.cc @@ -60,6 +60,13 @@ void PresentationServiceImpl::OnConnectionError() { << render_frame_host_->GetRoutingID(); } +void PresentationServiceImpl::SetDefaultPresentationURL( + const mojo::String& presentation_url, + const mojo::String& presentation_id) { + NOTIMPLEMENTED(); +} + + void PresentationServiceImpl::GetScreenAvailability( const mojo::String& presentation_url, const ScreenAvailabilityMojoCallback& callback) { @@ -95,7 +102,8 @@ void PresentationServiceImpl::GetScreenAvailability( it->second->CallbackReceived(callback); } -void PresentationServiceImpl::OnScreenAvailabilityListenerRemoved() { +void PresentationServiceImpl::OnScreenAvailabilityListenerRemoved( + const mojo::String& presentation_url) { NOTIMPLEMENTED(); } diff --git a/content/browser/presentation/presentation_service_impl.h b/content/browser/presentation/presentation_service_impl.h index 3688d25a8e13..bc1e0ef9ce9b 100644 --- a/content/browser/presentation/presentation_service_impl.h +++ b/content/browser/presentation/presentation_service_impl.h @@ -78,10 +78,14 @@ class CONTENT_EXPORT PresentationServiceImpl PresentationServiceDelegate* delegate); // PresentationService implementation. + void SetDefaultPresentationURL( + const mojo::String& presentation_url, + const mojo::String& presentation_id) override; void GetScreenAvailability( const mojo::String& presentation_url, const ScreenAvailabilityMojoCallback& callback) override; - void OnScreenAvailabilityListenerRemoved() override; + void OnScreenAvailabilityListenerRemoved( + const mojo::String& presentation_url) override; void ListenForDefaultSessionStart( const DefaultSessionMojoCallback& callback) override; void StartSession( diff --git a/content/common/presentation/presentation_service.mojom b/content/common/presentation/presentation_service.mojom index c81c687391c7..e672ad14ad6b 100644 --- a/content/common/presentation/presentation_service.mojom +++ b/content/common/presentation/presentation_service.mojom @@ -25,6 +25,12 @@ struct PresentationError { }; interface PresentationService { + // Called when the frame sets or changes the default presentation URL or + // presentation ID. + SetDefaultPresentationURL( + string default_presentation_url, + string? default_presentation_id); + // Returns the last screen availability state if it’s changed since the last // time the method was called. The client has to call this method again when // handling the result (provided via Mojo callback) to get the next update @@ -37,7 +43,7 @@ interface PresentationService { // Called when the frame no longer listens to the // |availablechange| event. - OnScreenAvailabilityListenerRemoved(); + OnScreenAvailabilityListenerRemoved(string? presentation_url); // Called when the renderer is ready to receive the browser initiated // session. If the default session is started by the embedder before this @@ -57,7 +63,7 @@ interface PresentationService { // rather than get a new one. An empty presentation id means that the // UA will generate the presentation id. StartSession(string presentation_url, string? presentation_id) - => (PresentationSessionInfo? sessionInfo, PresentationError? error); + => (PresentationSessionInfo? sessionInfo, PresentationError? error); // Called when joinSession() is called by the frame. The result callback // works the same as for the method above. JoinSession will join a known diff --git a/content/public/renderer/render_frame_observer.h b/content/public/renderer/render_frame_observer.h index 85319b202bfc..79957c4f96c4 100644 --- a/content/public/renderer/render_frame_observer.h +++ b/content/public/renderer/render_frame_observer.h @@ -56,6 +56,7 @@ class CONTENT_EXPORT RenderFrameObserver : public IPC::Listener, int world_id) {} virtual void DidClearWindowObject() {} virtual void DidChangeManifest() {} + virtual void DidChangeDefaultPresentation() {} virtual void DidChangeScrollOffset() {} virtual void WillSendSubmitEvent(const blink::WebFormElement& form) {} virtual void WillSubmitForm(const blink::WebFormElement& form) {} diff --git a/content/renderer/presentation/presentation_dispatcher.cc b/content/renderer/presentation/presentation_dispatcher.cc index b4b952c518a5..839b5103d3cf 100644 --- a/content/renderer/presentation/presentation_dispatcher.cc +++ b/content/renderer/presentation/presentation_dispatcher.cc @@ -12,6 +12,9 @@ #include "third_party/WebKit/public/platform/WebString.h" #include "third_party/WebKit/public/platform/modules/presentation/WebPresentationController.h" #include "third_party/WebKit/public/platform/modules/presentation/WebPresentationError.h" +#include "third_party/WebKit/public/web/WebDocument.h" +#include "third_party/WebKit/public/web/WebLocalFrame.h" +#include "url/gurl.h" namespace { @@ -30,6 +33,13 @@ blink::WebPresentationError::ErrorType GetWebPresentationErrorTypeFromMojo( } } +GURL GetPresentationURLFromFrame(content::RenderFrame* frame) { + DCHECK(frame); + + GURL url(frame->GetWebFrame()->document().defaultPresentationURL()); + return url.is_valid() ? url : GURL(); +} + } // namespace namespace content { @@ -56,14 +66,17 @@ void PresentationDispatcher::setController( } void PresentationDispatcher::updateAvailableChangeWatched(bool watched) { + GURL presentation_url(GetPresentationURLFromFrame(render_frame())); + ConnectToPresentationServiceIfNeeded(); if (watched) { presentation_service_->GetScreenAvailability( - mojo::String(), + presentation_url.spec(), base::Bind(&PresentationDispatcher::OnScreenAvailabilityChanged, base::Unretained(this))); } else { - presentation_service_->OnScreenAvailabilityListenerRemoved(); + presentation_service_->OnScreenAvailabilityListenerRemoved( + presentation_url.spec()); } } @@ -103,6 +116,14 @@ void PresentationDispatcher::joinSession( base::Owned(callback))); } +void PresentationDispatcher::DidChangeDefaultPresentation() { + GURL presentation_url(GetPresentationURLFromFrame(render_frame())); + + ConnectToPresentationServiceIfNeeded(); + presentation_service_->SetDefaultPresentationURL( + presentation_url.spec(), mojo::String()); +} + void PresentationDispatcher::OnScreenAvailabilityChanged(bool available) { if (!controller_) return; diff --git a/content/renderer/presentation/presentation_dispatcher.h b/content/renderer/presentation/presentation_dispatcher.h index db04be435961..e17d72ac0e6e 100644 --- a/content/renderer/presentation/presentation_dispatcher.h +++ b/content/renderer/presentation/presentation_dispatcher.h @@ -42,6 +42,9 @@ class CONTENT_EXPORT PresentationDispatcher const blink::WebString& presentationId, blink::WebPresentationSessionClientCallbacks* callback); + // RenderFrameObserver + void DidChangeDefaultPresentation() override; + void OnScreenAvailabilityChanged(bool available); void OnSessionCreated( blink::WebPresentationSessionClientCallbacks* callback, diff --git a/content/renderer/render_frame_impl.cc b/content/renderer/render_frame_impl.cc index aae437eccf67..437e8c98be93 100644 --- a/content/renderer/render_frame_impl.cc +++ b/content/renderer/render_frame_impl.cc @@ -3597,6 +3597,14 @@ void RenderFrameImpl::didChangeManifest(blink::WebLocalFrame* frame) { FOR_EACH_OBSERVER(RenderFrameObserver, observers_, DidChangeManifest()); } +void RenderFrameImpl::didChangeDefaultPresentation( + blink::WebLocalFrame* frame) { + DCHECK(!frame_ || frame_ == frame); + + FOR_EACH_OBSERVER( + RenderFrameObserver, observers_, DidChangeDefaultPresentation()); +} + bool RenderFrameImpl::enterFullscreen() { Send(new FrameHostMsg_ToggleFullscreen(routing_id_, true)); return true; diff --git a/content/renderer/render_frame_impl.h b/content/renderer/render_frame_impl.h index 8ee3df8ec5eb..4863460d6fa0 100644 --- a/content/renderer/render_frame_impl.h +++ b/content/renderer/render_frame_impl.h @@ -515,6 +515,7 @@ class CONTENT_EXPORT RenderFrameImpl const blink::WebAXObject& end_object, int end_offset); virtual void didChangeManifest(blink::WebLocalFrame*); + virtual void didChangeDefaultPresentation(blink::WebLocalFrame*); virtual bool enterFullscreen(); virtual bool exitFullscreen(); void suddenTerminationDisablerChanged( -- 2.11.4.GIT