2015-03-25 14:47:56 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_PresentationSessionInfo_h
|
|
|
|
#define mozilla_dom_PresentationSessionInfo_h
|
|
|
|
|
2015-08-31 08:24:35 +03:00
|
|
|
#include "base/process.h"
|
2015-03-30 10:48:11 +03:00
|
|
|
#include "mozilla/dom/Promise.h"
|
|
|
|
#include "mozilla/dom/PromiseNativeHandler.h"
|
2015-10-18 08:24:48 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2015-03-25 14:47:56 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2015-03-30 09:27:27 +03:00
|
|
|
#include "nsIPresentationControlChannel.h"
|
|
|
|
#include "nsIPresentationDevice.h"
|
2015-03-25 14:47:56 +03:00
|
|
|
#include "nsIPresentationListener.h"
|
|
|
|
#include "nsIPresentationService.h"
|
2015-03-30 09:27:27 +03:00
|
|
|
#include "nsIPresentationSessionTransport.h"
|
|
|
|
#include "nsIServerSocket.h"
|
2015-03-30 10:46:11 +03:00
|
|
|
#include "nsITimer.h"
|
2015-03-25 14:47:56 +03:00
|
|
|
#include "nsString.h"
|
2015-03-30 10:46:11 +03:00
|
|
|
#include "PresentationCallbacks.h"
|
2015-03-25 14:47:56 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2015-03-30 09:27:27 +03:00
|
|
|
class PresentationSessionInfo : public nsIPresentationSessionTransportCallback
|
|
|
|
, public nsIPresentationControlChannelListener
|
2015-03-25 14:47:56 +03:00
|
|
|
{
|
|
|
|
public:
|
2015-03-30 09:27:27 +03:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIPRESENTATIONSESSIONTRANSPORTCALLBACK
|
|
|
|
|
2015-03-25 14:47:56 +03:00
|
|
|
PresentationSessionInfo(const nsAString& aUrl,
|
|
|
|
const nsAString& aSessionId,
|
|
|
|
nsIPresentationServiceCallback* aCallback)
|
|
|
|
: mUrl(aUrl)
|
|
|
|
, mSessionId(aSessionId)
|
2015-03-30 09:27:27 +03:00
|
|
|
, mIsResponderReady(false)
|
|
|
|
, mIsTransportReady(false)
|
2015-10-08 13:11:10 +03:00
|
|
|
, mState(nsIPresentationSessionListener::STATE_CLOSED)
|
2015-03-25 14:47:56 +03:00
|
|
|
, mCallback(aCallback)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mUrl.IsEmpty());
|
|
|
|
MOZ_ASSERT(!mSessionId.IsEmpty());
|
|
|
|
}
|
|
|
|
|
2015-03-30 09:27:27 +03:00
|
|
|
virtual nsresult Init(nsIPresentationControlChannel* aControlChannel);
|
|
|
|
|
2015-03-25 14:47:56 +03:00
|
|
|
const nsAString& GetUrl() const
|
|
|
|
{
|
|
|
|
return mUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsAString& GetSessionId() const
|
|
|
|
{
|
|
|
|
return mSessionId;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetCallback(nsIPresentationServiceCallback* aCallback)
|
|
|
|
{
|
|
|
|
mCallback = aCallback;
|
|
|
|
}
|
|
|
|
|
2015-03-30 09:27:27 +03:00
|
|
|
nsresult SetListener(nsIPresentationSessionListener* aListener);
|
|
|
|
|
|
|
|
void SetDevice(nsIPresentationDevice* aDevice)
|
2015-03-25 14:47:56 +03:00
|
|
|
{
|
2015-03-30 09:27:27 +03:00
|
|
|
mDevice = aDevice;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIPresentationDevice> GetDevice() const
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPresentationDevice> device = mDevice;
|
|
|
|
return device.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetControlChannel(nsIPresentationControlChannel* aControlChannel)
|
|
|
|
{
|
|
|
|
if (mControlChannel) {
|
|
|
|
mControlChannel->SetListener(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
mControlChannel = aControlChannel;
|
|
|
|
if (mControlChannel) {
|
|
|
|
mControlChannel->SetListener(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult Send(nsIInputStream* aData);
|
|
|
|
|
2015-10-08 13:11:10 +03:00
|
|
|
nsresult Close(nsresult aReason,
|
|
|
|
uint32_t aState);
|
2015-03-30 09:27:27 +03:00
|
|
|
|
|
|
|
nsresult ReplyError(nsresult aReason);
|
|
|
|
|
2015-08-31 08:24:35 +03:00
|
|
|
virtual bool IsAccessible(base::ProcessId aProcessId);
|
|
|
|
|
2015-03-30 09:27:27 +03:00
|
|
|
protected:
|
|
|
|
virtual ~PresentationSessionInfo()
|
|
|
|
{
|
|
|
|
Shutdown(NS_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Shutdown(nsresult aReason);
|
|
|
|
|
|
|
|
nsresult ReplySuccess();
|
|
|
|
|
|
|
|
bool IsSessionReady()
|
|
|
|
{
|
|
|
|
return mIsResponderReady && mIsTransportReady;
|
2015-03-25 14:47:56 +03:00
|
|
|
}
|
|
|
|
|
2015-08-31 08:24:35 +03:00
|
|
|
virtual nsresult UntrackFromService();
|
|
|
|
|
2015-10-08 13:11:10 +03:00
|
|
|
void SetState(uint32_t aState)
|
|
|
|
{
|
|
|
|
if (mState == aState) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mState = aState;
|
|
|
|
|
|
|
|
// Notify session state change.
|
|
|
|
if (mListener) {
|
|
|
|
nsresult rv = mListener->NotifyStateChange(mSessionId, mState);
|
|
|
|
NS_WARN_IF(NS_FAILED(rv));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-25 14:47:56 +03:00
|
|
|
nsString mUrl;
|
|
|
|
nsString mSessionId;
|
2015-03-30 09:27:27 +03:00
|
|
|
bool mIsResponderReady;
|
|
|
|
bool mIsTransportReady;
|
2015-10-08 13:11:10 +03:00
|
|
|
uint32_t mState; // CONNECTED, CLOSED, TERMINATED
|
2015-03-25 14:47:56 +03:00
|
|
|
nsCOMPtr<nsIPresentationServiceCallback> mCallback;
|
|
|
|
nsCOMPtr<nsIPresentationSessionListener> mListener;
|
2015-03-30 09:27:27 +03:00
|
|
|
nsCOMPtr<nsIPresentationDevice> mDevice;
|
|
|
|
nsCOMPtr<nsIPresentationSessionTransport> mTransport;
|
|
|
|
nsCOMPtr<nsIPresentationControlChannel> mControlChannel;
|
|
|
|
};
|
|
|
|
|
2015-09-09 12:41:55 +03:00
|
|
|
// Session info with controlling browsing context (sender side) behaviors.
|
|
|
|
class PresentationControllingInfo final : public PresentationSessionInfo
|
|
|
|
, public nsIServerSocketListener
|
2015-03-30 09:27:27 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_NSIPRESENTATIONCONTROLCHANNELLISTENER
|
|
|
|
NS_DECL_NSISERVERSOCKETLISTENER
|
|
|
|
|
2015-09-09 12:41:55 +03:00
|
|
|
PresentationControllingInfo(const nsAString& aUrl,
|
|
|
|
const nsAString& aSessionId,
|
|
|
|
nsIPresentationServiceCallback* aCallback)
|
2015-03-30 09:27:27 +03:00
|
|
|
: PresentationSessionInfo(aUrl, aSessionId, aCallback)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mCallback);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult Init(nsIPresentationControlChannel* aControlChannel) override;
|
|
|
|
|
|
|
|
private:
|
2015-09-09 12:41:55 +03:00
|
|
|
~PresentationControllingInfo()
|
2015-03-30 09:27:27 +03:00
|
|
|
{
|
|
|
|
Shutdown(NS_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Shutdown(nsresult aReason) override;
|
|
|
|
|
2015-10-21 08:53:00 +03:00
|
|
|
nsresult GetAddress();
|
|
|
|
|
|
|
|
nsresult OnGetAddress(const nsACString& aAddress);
|
2015-04-22 11:01:38 +03:00
|
|
|
|
2015-03-30 09:27:27 +03:00
|
|
|
nsCOMPtr<nsIServerSocket> mServerSocket;
|
|
|
|
};
|
|
|
|
|
2015-09-09 12:41:55 +03:00
|
|
|
// Session info with presenting browsing context (receiver side) behaviors.
|
|
|
|
class PresentationPresentingInfo final : public PresentationSessionInfo
|
|
|
|
, public PromiseNativeHandler
|
|
|
|
, public nsITimerCallback
|
2015-03-30 09:27:27 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_NSIPRESENTATIONCONTROLCHANNELLISTENER
|
2015-03-30 10:46:11 +03:00
|
|
|
NS_DECL_NSITIMERCALLBACK
|
2015-03-30 09:27:27 +03:00
|
|
|
|
2015-09-09 12:41:55 +03:00
|
|
|
PresentationPresentingInfo(const nsAString& aUrl,
|
|
|
|
const nsAString& aSessionId,
|
|
|
|
nsIPresentationDevice* aDevice)
|
2015-03-30 09:27:27 +03:00
|
|
|
: PresentationSessionInfo(aUrl, aSessionId, nullptr)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aDevice);
|
|
|
|
|
|
|
|
SetDevice(aDevice);
|
|
|
|
}
|
|
|
|
|
2015-03-30 10:46:11 +03:00
|
|
|
nsresult Init(nsIPresentationControlChannel* aControlChannel) override;
|
|
|
|
|
|
|
|
nsresult NotifyResponderReady();
|
2015-03-30 09:27:27 +03:00
|
|
|
|
2015-03-30 10:48:11 +03:00
|
|
|
void ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) override;
|
|
|
|
|
|
|
|
void RejectedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) override;
|
|
|
|
|
|
|
|
void SetPromise(Promise* aPromise)
|
|
|
|
{
|
|
|
|
mPromise = aPromise;
|
|
|
|
mPromise->AppendNativeHandler(this);
|
|
|
|
}
|
|
|
|
|
2015-08-31 08:24:35 +03:00
|
|
|
bool IsAccessible(base::ProcessId aProcessId) override;
|
|
|
|
|
2015-03-30 09:27:27 +03:00
|
|
|
private:
|
2015-09-09 12:41:55 +03:00
|
|
|
~PresentationPresentingInfo()
|
2015-03-30 10:46:11 +03:00
|
|
|
{
|
|
|
|
Shutdown(NS_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Shutdown(nsresult aReason) override;
|
|
|
|
|
|
|
|
nsresult InitTransportAndSendAnswer();
|
|
|
|
|
2015-08-31 08:24:35 +03:00
|
|
|
nsresult UntrackFromService() override;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<PresentationResponderLoadingCallback> mLoadingCallback;
|
2015-03-30 10:46:11 +03:00
|
|
|
nsCOMPtr<nsITimer> mTimer;
|
|
|
|
nsCOMPtr<nsIPresentationChannelDescription> mRequesterDescription;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Promise> mPromise;
|
2015-08-31 08:24:35 +03:00
|
|
|
|
|
|
|
// The content parent communicating with the content process which the OOP
|
|
|
|
// receiver page belongs to.
|
|
|
|
nsCOMPtr<nsIContentParent> mContentParent;
|
2015-03-25 14:47:56 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_PresentationSessionInfo_h
|