Commit a3731aaf authored by avayvod's avatar avayvod Committed by Commit bot

[Presentation API] Plumbing of |onstatechange| from the Mojo service to the public/platform

Removed PresentationSessionDispatcher since the session messages are going through the
PresentationService (to reduce the number of Mojo pipes used).

Depends on the Blink change: https://codereview.chromium.org/1020303004

BUG=459006

Review URL: https://codereview.chromium.org/1024903003

Cr-Commit-Position: refs/heads/master@{#322162}
parent c09e0886
...@@ -280,6 +280,11 @@ void PresentationServiceImpl::CloseSession( ...@@ -280,6 +280,11 @@ void PresentationServiceImpl::CloseSession(
NOTIMPLEMENTED(); NOTIMPLEMENTED();
} }
void PresentationServiceImpl::ListenForSessionStateChange(
const SessionStateCallback& callback) {
NOTIMPLEMENTED();
}
void PresentationServiceImpl::DidNavigateAnyFrame( void PresentationServiceImpl::DidNavigateAnyFrame(
content::RenderFrameHost* render_frame_host, content::RenderFrameHost* render_frame_host,
const content::LoadCommittedDetails& details, const content::LoadCommittedDetails& details,
......
...@@ -61,6 +61,9 @@ class CONTENT_EXPORT PresentationServiceImpl ...@@ -61,6 +61,9 @@ class CONTENT_EXPORT PresentationServiceImpl
presentation::PresentationErrorPtr)>; presentation::PresentationErrorPtr)>;
using DefaultSessionMojoCallback = using DefaultSessionMojoCallback =
mojo::Callback<void(presentation::PresentationSessionInfoPtr)>; mojo::Callback<void(presentation::PresentationSessionInfoPtr)>;
using SessionStateCallback =
mojo::Callback<void(presentation::PresentationSessionInfoPtr,
presentation::PresentationSessionState)>;
// A helper data class used by PresentationServiceImpl to do bookkeeping // A helper data class used by PresentationServiceImpl to do bookkeeping
// of currently registered screen availability listeners. // of currently registered screen availability listeners.
...@@ -166,6 +169,8 @@ class CONTENT_EXPORT PresentationServiceImpl ...@@ -166,6 +169,8 @@ class CONTENT_EXPORT PresentationServiceImpl
void CloseSession( void CloseSession(
const mojo::String& presentation_url, const mojo::String& presentation_url,
const mojo::String& presentation_id) override; const mojo::String& presentation_id) override;
void ListenForSessionStateChange(
const SessionStateCallback& callback) override;
// mojo::InterfaceImpl override. // mojo::InterfaceImpl override.
// Note that this is called when the RenderFrameHost is deleted. // Note that this is called when the RenderFrameHost is deleted.
......
...@@ -9,6 +9,11 @@ struct PresentationSessionInfo { ...@@ -9,6 +9,11 @@ struct PresentationSessionInfo {
string id; string id;
}; };
enum PresentationSessionState {
CONNECTED,
DISCONNECTED
};
enum PresentationErrorType { enum PresentationErrorType {
NO_AVAILABLE_SCREENS, NO_AVAILABLE_SCREENS,
SESSION_REQUEST_CANCELLED, SESSION_REQUEST_CANCELLED,
...@@ -72,4 +77,11 @@ interface PresentationService { ...@@ -72,4 +77,11 @@ interface PresentationService {
// Called when closeSession() is called by the frame. // Called when closeSession() is called by the frame.
CloseSession(string presentation_url, string presentation_id); CloseSession(string presentation_url, string presentation_id);
// Called when the frame is ready to process the next state change. Returns
// the last session state if it’s changed since the last time the callback
// was called. Might cause the event fired with the initial state change.
ListenForSessionStateChange()
=> (PresentationSessionInfo sessionInfo,
PresentationSessionState newState);
}; };
...@@ -320,8 +320,6 @@ ...@@ -320,8 +320,6 @@
'renderer/presentation/presentation_dispatcher.h', 'renderer/presentation/presentation_dispatcher.h',
'renderer/presentation/presentation_session_client.cc', 'renderer/presentation/presentation_session_client.cc',
'renderer/presentation/presentation_session_client.h', 'renderer/presentation/presentation_session_client.h',
'renderer/presentation/presentation_session_dispatcher.cc',
'renderer/presentation/presentation_session_dispatcher.h',
'renderer/push_messaging/push_messaging_dispatcher.cc', 'renderer/push_messaging/push_messaging_dispatcher.cc',
'renderer/push_messaging/push_messaging_dispatcher.h', 'renderer/push_messaging/push_messaging_dispatcher.h',
'renderer/render_font_warmup_win.cc', 'renderer/render_font_warmup_win.cc',
......
...@@ -33,6 +33,19 @@ blink::WebPresentationError::ErrorType GetWebPresentationErrorTypeFromMojo( ...@@ -33,6 +33,19 @@ blink::WebPresentationError::ErrorType GetWebPresentationErrorTypeFromMojo(
} }
} }
blink::WebPresentationSessionState GetWebPresentationSessionStateFromMojo(
presentation::PresentationSessionState mojoSessionState) {
switch (mojoSessionState) {
case presentation::PRESENTATION_SESSION_STATE_CONNECTED:
return blink::WebPresentationSessionState::Connected;
case presentation::PRESENTATION_SESSION_STATE_DISCONNECTED:
return blink::WebPresentationSessionState::Disconnected;
}
NOTREACHED();
return blink::WebPresentationSessionState::Disconnected;
}
GURL GetPresentationURLFromFrame(content::RenderFrame* frame) { GURL GetPresentationURLFromFrame(content::RenderFrame* frame) {
DCHECK(frame); DCHECK(frame);
...@@ -161,11 +174,8 @@ void PresentationDispatcher::OnDefaultSessionStarted( ...@@ -161,11 +174,8 @@ void PresentationDispatcher::OnDefaultSessionStarted(
base::Unretained(this))); base::Unretained(this)));
DCHECK(!session_info.is_null()); DCHECK(!session_info.is_null());
PresentationSessionDispatcher* session_dispatcher =
new PresentationSessionDispatcher(session_info.Pass());
presentation_session_dispatchers_.push_back(session_dispatcher);
controller_->didStartDefaultSession( controller_->didStartDefaultSession(
new PresentationSessionClient(session_dispatcher)); new PresentationSessionClient(session_info.Pass()));
} }
void PresentationDispatcher::OnSessionCreated( void PresentationDispatcher::OnSessionCreated(
...@@ -182,10 +192,23 @@ void PresentationDispatcher::OnSessionCreated( ...@@ -182,10 +192,23 @@ void PresentationDispatcher::OnSessionCreated(
} }
DCHECK(!session_info.is_null()); DCHECK(!session_info.is_null());
PresentationSessionDispatcher* session_dispatcher = callback->onSuccess(new PresentationSessionClient(session_info.Pass()));
new PresentationSessionDispatcher(session_info.Pass()); }
presentation_session_dispatchers_.push_back(session_dispatcher);
callback->onSuccess(new PresentationSessionClient(session_dispatcher)); void PresentationDispatcher::OnSessionStateChange(
presentation::PresentationSessionInfoPtr session_info,
presentation::PresentationSessionState session_state) {
if (!controller_)
return;
presentation_service_->ListenForSessionStateChange(base::Bind(
&PresentationDispatcher::OnSessionStateChange,
base::Unretained(this)));
DCHECK(!session_info.is_null());
controller_->didChangeSessionState(
new PresentationSessionClient(session_info.Pass()),
GetWebPresentationSessionStateFromMojo(session_state));
} }
void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() {
...@@ -197,6 +220,9 @@ void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() { ...@@ -197,6 +220,9 @@ void PresentationDispatcher::ConnectToPresentationServiceIfNeeded() {
presentation_service_->ListenForDefaultSessionStart(base::Bind( presentation_service_->ListenForDefaultSessionStart(base::Bind(
&PresentationDispatcher::OnDefaultSessionStarted, &PresentationDispatcher::OnDefaultSessionStarted,
base::Unretained(this))); base::Unretained(this)));
presentation_service_->ListenForSessionStateChange(base::Bind(
&PresentationDispatcher::OnSessionStateChange,
base::Unretained(this)));
} }
} // namespace content } // namespace content
...@@ -6,11 +6,9 @@ ...@@ -6,11 +6,9 @@
#define CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ #define CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/memory/scoped_vector.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "content/common/presentation/presentation_service.mojom.h" #include "content/common/presentation/presentation_service.mojom.h"
#include "content/public/renderer/render_frame_observer.h" #include "content/public/renderer/render_frame_observer.h"
#include "content/renderer/presentation/presentation_session_dispatcher.h"
#include "third_party/WebKit/public/platform/modules/presentation/WebPresentationClient.h" #include "third_party/WebKit/public/platform/modules/presentation/WebPresentationClient.h"
namespace blink { namespace blink {
...@@ -57,6 +55,9 @@ class CONTENT_EXPORT PresentationDispatcher ...@@ -57,6 +55,9 @@ class CONTENT_EXPORT PresentationDispatcher
presentation::PresentationErrorPtr error); presentation::PresentationErrorPtr error);
void OnDefaultSessionStarted( void OnDefaultSessionStarted(
presentation::PresentationSessionInfoPtr session_info); presentation::PresentationSessionInfoPtr session_info);
void OnSessionStateChange(
presentation::PresentationSessionInfoPtr session_info,
presentation::PresentationSessionState session_state);
void ConnectToPresentationServiceIfNeeded(); void ConnectToPresentationServiceIfNeeded();
...@@ -67,14 +68,6 @@ class CONTENT_EXPORT PresentationDispatcher ...@@ -67,14 +68,6 @@ class CONTENT_EXPORT PresentationDispatcher
// Used as a weak reference. Can be null since lifetime is bound to the frame. // Used as a weak reference. Can be null since lifetime is bound to the frame.
blink::WebPresentationController* controller_; blink::WebPresentationController* controller_;
presentation::PresentationServicePtr presentation_service_; presentation::PresentationServicePtr presentation_service_;
// Wrappers around the PresentationSessionPtr corresponding to each Javascript
// PresentationSession object passed back to the frame.
// TODO(avayvod): Switch to base::IDMap when the lookup by presentation id is
// needed.
using PresentationSessionDispatchers =
ScopedVector<PresentationSessionDispatcher>;
PresentationSessionDispatchers presentation_session_dispatchers_;
}; };
} // namespace content } // namespace content
......
...@@ -5,15 +5,14 @@ ...@@ -5,15 +5,14 @@
#include "content/renderer/presentation/presentation_session_client.h" #include "content/renderer/presentation/presentation_session_client.h"
#include "base/logging.h" #include "base/logging.h"
#include "content/renderer/presentation/presentation_session_dispatcher.h"
#include "third_party/WebKit/public/platform/WebString.h" #include "third_party/WebKit/public/platform/WebString.h"
namespace content { namespace content {
PresentationSessionClient::PresentationSessionClient( PresentationSessionClient::PresentationSessionClient(
PresentationSessionDispatcher* dispatcher) presentation::PresentationSessionInfoPtr session_info)
: url_(blink::WebString::fromUTF8(dispatcher->GetUrl())), : url_(blink::WebString::fromUTF8(session_info->url)),
id_(blink::WebString::fromUTF8(dispatcher->GetId())) { id_(blink::WebString::fromUTF8(session_info->id)) {
} }
PresentationSessionClient::~PresentationSessionClient() { PresentationSessionClient::~PresentationSessionClient() {
......
...@@ -7,18 +7,18 @@ ...@@ -7,18 +7,18 @@
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "content/common/presentation/presentation_service.mojom.h"
#include "third_party/WebKit/public/platform/modules/presentation/WebPresentationSessionClient.h" #include "third_party/WebKit/public/platform/modules/presentation/WebPresentationSessionClient.h"
namespace content { namespace content {
class PresentationSessionDispatcher;
// PresentationSessionClient is passed to the Blink layer if presentation // PresentationSessionClient is passed to the Blink layer if presentation
// session has been created successfully. Owned by the callback. // session has been created successfully. Owned by the callback.
class CONTENT_EXPORT PresentationSessionClient class CONTENT_EXPORT PresentationSessionClient
: public NON_EXPORTED_BASE(blink::WebPresentationSessionClient) { : public NON_EXPORTED_BASE(blink::WebPresentationSessionClient) {
public: public:
explicit PresentationSessionClient(PresentationSessionDispatcher* dispatcher); explicit PresentationSessionClient(
presentation::PresentationSessionInfoPtr session_info);
~PresentationSessionClient() override; ~PresentationSessionClient() override;
// WebPresentationSessionClient implementation. // WebPresentationSessionClient implementation.
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/renderer/presentation/presentation_session_dispatcher.h"
#include "base/logging.h"
namespace content {
PresentationSessionDispatcher::PresentationSessionDispatcher(
presentation::PresentationSessionInfoPtr session_info)
: session_info_(session_info.Pass()) {
}
PresentationSessionDispatcher::~PresentationSessionDispatcher() {
}
const mojo::String& PresentationSessionDispatcher::GetUrl() const {
DCHECK(!session_info_.is_null());
return session_info_->url;
}
const mojo::String& PresentationSessionDispatcher::GetId() const {
DCHECK(!session_info_.is_null());
return session_info_->id;
}
} // namespace content
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_RENDERER_PRESENTATION_PRESENTATION_SESSION_DISPATCHER_H_
#define CONTENT_RENDERER_PRESENTATION_PRESENTATION_SESSION_DISPATCHER_H_
#include "base/compiler_specific.h"
#include "content/common/content_export.h"
#include "content/common/presentation/presentation_service.mojom.h"
namespace content {
// A wrapper around the Mojo PresentationSession remote object.
class CONTENT_EXPORT PresentationSessionDispatcher {
public:
explicit PresentationSessionDispatcher(
presentation::PresentationSessionInfoPtr session_info);
~PresentationSessionDispatcher();
const mojo::String& GetUrl() const;
const mojo::String& GetId() const;
private:
presentation::PresentationSessionInfoPtr session_info_;
};
} // namespace content
#endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_SESSION_DISPATCHER_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment