2015-03-25 04:47:56 -07: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-03-30 00:48:11 -07:00
|
|
|
#include "mozilla/dom/Promise.h"
|
|
|
|
#include "mozilla/dom/PromiseNativeHandler.h"
|
2015-03-25 04:47:56 -07:00
|
|
|
#include "mozilla/nsRefPtr.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2015-03-29 23:27:27 -07:00
|
|
|
#include "nsIPresentationControlChannel.h"
|
|
|
|
#include "nsIPresentationDevice.h"
|
2015-03-25 04:47:56 -07:00
|
|
|
#include "nsIPresentationListener.h"
|
|
|
|
#include "nsIPresentationService.h"
|
2015-03-29 23:27:27 -07:00
|
|
|
#include "nsIPresentationSessionTransport.h"
|
|
|
|
#include "nsIServerSocket.h"
|
2015-03-30 00:46:11 -07:00
|
|
|
#include "nsITimer.h"
|
2015-03-25 04:47:56 -07:00
|
|
|
#include "nsString.h"
|
2015-03-30 00:46:11 -07:00
|
|
|
#include "PresentationCallbacks.h"
|
2015-03-25 04:47:56 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2015-03-29 23:27:27 -07:00
|
|
|
class PresentationSessionInfo : public nsIPresentationSessionTransportCallback
|
|
|
|
, public nsIPresentationControlChannelListener
|
2015-03-25 04:47:56 -07:00
|
|
|
{
|
|
|
|
public:
|
2015-03-29 23:27:27 -07:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIPRESENTATIONSESSIONTRANSPORTCALLBACK
|
|
|
|
|
2015-03-25 04:47:56 -07:00
|
|
|
PresentationSessionInfo(const nsAString& aUrl,
|
|
|
|
const nsAString& aSessionId,
|
|
|
|
nsIPresentationServiceCallback* aCallback)
|
|
|
|
: mUrl(aUrl)
|
|
|
|
, mSessionId(aSessionId)
|
2015-03-29 23:27:27 -07:00
|
|
|
, mIsResponderReady(false)
|
|
|
|
, mIsTransportReady(false)
|
2015-03-25 04:47:56 -07:00
|
|
|
, mCallback(aCallback)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mUrl.IsEmpty());
|
|
|
|
MOZ_ASSERT(!mSessionId.IsEmpty());
|
|
|
|
}
|
|
|
|
|
2015-03-29 23:27:27 -07:00
|
|
|
virtual nsresult Init(nsIPresentationControlChannel* aControlChannel);
|
|
|
|
|
2015-03-25 04:47:56 -07:00
|
|
|
const nsAString& GetUrl() const
|
|
|
|
{
|
|
|
|
return mUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsAString& GetSessionId() const
|
|
|
|
{
|
|
|
|
return mSessionId;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetCallback(nsIPresentationServiceCallback* aCallback)
|
|
|
|
{
|
|
|
|
mCallback = aCallback;
|
|
|
|
}
|
|
|
|
|
2015-03-29 23:27:27 -07:00
|
|
|
nsresult SetListener(nsIPresentationSessionListener* aListener);
|
|
|
|
|
|
|
|
void SetDevice(nsIPresentationDevice* aDevice)
|
2015-03-25 04:47:56 -07:00
|
|
|
{
|
2015-03-29 23:27:27 -07: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);
|
|
|
|
|
|
|
|
nsresult Close(nsresult aReason);
|
|
|
|
|
|
|
|
nsresult ReplyError(nsresult aReason);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~PresentationSessionInfo()
|
|
|
|
{
|
|
|
|
Shutdown(NS_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void Shutdown(nsresult aReason);
|
|
|
|
|
|
|
|
nsresult ReplySuccess();
|
|
|
|
|
|
|
|
bool IsSessionReady()
|
|
|
|
{
|
|
|
|
return mIsResponderReady && mIsTransportReady;
|
2015-03-25 04:47:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsString mUrl;
|
|
|
|
nsString mSessionId;
|
2015-03-29 23:27:27 -07:00
|
|
|
bool mIsResponderReady;
|
|
|
|
bool mIsTransportReady;
|
2015-03-25 04:47:56 -07:00
|
|
|
nsCOMPtr<nsIPresentationServiceCallback> mCallback;
|
|
|
|
nsCOMPtr<nsIPresentationSessionListener> mListener;
|
2015-03-29 23:27:27 -07:00
|
|
|
nsCOMPtr<nsIPresentationDevice> mDevice;
|
|
|
|
nsCOMPtr<nsIPresentationSessionTransport> mTransport;
|
|
|
|
nsCOMPtr<nsIPresentationControlChannel> mControlChannel;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Session info with sender side behaviors.
|
|
|
|
class PresentationRequesterInfo final : public PresentationSessionInfo
|
|
|
|
, public nsIServerSocketListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_NSIPRESENTATIONCONTROLCHANNELLISTENER
|
|
|
|
NS_DECL_NSISERVERSOCKETLISTENER
|
|
|
|
|
|
|
|
PresentationRequesterInfo(const nsAString& aUrl,
|
|
|
|
const nsAString& aSessionId,
|
|
|
|
nsIPresentationServiceCallback* aCallback)
|
|
|
|
: PresentationSessionInfo(aUrl, aSessionId, aCallback)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mCallback);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult Init(nsIPresentationControlChannel* aControlChannel) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
~PresentationRequesterInfo()
|
|
|
|
{
|
|
|
|
Shutdown(NS_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Shutdown(nsresult aReason) override;
|
|
|
|
|
2015-04-22 01:01:38 -07:00
|
|
|
nsresult GetAddress(nsACString& aAddress);
|
|
|
|
|
2015-03-29 23:27:27 -07:00
|
|
|
nsCOMPtr<nsIServerSocket> mServerSocket;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Session info with receiver side behaviors.
|
|
|
|
class PresentationResponderInfo final : public PresentationSessionInfo
|
2015-03-30 00:48:11 -07:00
|
|
|
, public PromiseNativeHandler
|
2015-03-30 00:46:11 -07:00
|
|
|
, public nsITimerCallback
|
2015-03-29 23:27:27 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_NSIPRESENTATIONCONTROLCHANNELLISTENER
|
2015-03-30 00:46:11 -07:00
|
|
|
NS_DECL_NSITIMERCALLBACK
|
2015-03-29 23:27:27 -07:00
|
|
|
|
|
|
|
PresentationResponderInfo(const nsAString& aUrl,
|
|
|
|
const nsAString& aSessionId,
|
|
|
|
nsIPresentationDevice* aDevice)
|
|
|
|
: PresentationSessionInfo(aUrl, aSessionId, nullptr)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aDevice);
|
|
|
|
|
|
|
|
SetDevice(aDevice);
|
|
|
|
}
|
|
|
|
|
2015-03-30 00:46:11 -07:00
|
|
|
nsresult Init(nsIPresentationControlChannel* aControlChannel) override;
|
|
|
|
|
|
|
|
nsresult NotifyResponderReady();
|
2015-03-29 23:27:27 -07:00
|
|
|
|
2015-03-30 00:48:11 -07: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-03-29 23:27:27 -07:00
|
|
|
private:
|
2015-03-30 00:46:11 -07:00
|
|
|
~PresentationResponderInfo()
|
|
|
|
{
|
|
|
|
Shutdown(NS_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Shutdown(nsresult aReason) override;
|
|
|
|
|
|
|
|
nsresult InitTransportAndSendAnswer();
|
|
|
|
|
|
|
|
nsRefPtr<PresentationResponderLoadingCallback> mLoadingCallback;
|
|
|
|
nsCOMPtr<nsITimer> mTimer;
|
|
|
|
nsCOMPtr<nsIPresentationChannelDescription> mRequesterDescription;
|
2015-03-30 00:48:11 -07:00
|
|
|
nsRefPtr<Promise> mPromise;
|
2015-03-25 04:47:56 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_PresentationSessionInfo_h
|