Merge remote-tracking branch 'origin/master' into custom

This commit is contained in:
Roy Tam 2020-02-07 08:01:35 +08:00
commit c9f0b81b06
259 changed files with 14813 additions and 39387 deletions

View file

@ -36,9 +36,6 @@ if ('MOZ_OFFICIAL_BRANDING' in listConfig) or (strBrandingDirectory.endswith("br
'MOZ_SYSTEM_JPEG',
'MOZ_SYSTEM_ZLIB',
'MOZ_SYSTEM_BZ2',
'MOZ_SYSTEM_PNG',
'MOZ_SYSTEM_LIBVPX',
'MOZ_SYSTEM_SQLITE',
'MOZ_SYSTEM_JEMALLOC'
]

View file

@ -234,7 +234,6 @@ def old_configure_options(*options):
'--enable-system-cairo',
'--enable-system-extension-dirs',
'--enable-system-pixman',
'--enable-system-sqlite',
'--enable-tasktracer',
'--enable-tests',
'--enable-thread-sanitizer',
@ -289,11 +288,6 @@ def old_configure_options(*options):
'--with-soft-float',
'--with-system-bz2',
'--with-system-jpeg',
'--with-system-libevent',
'--with-system-libvpx',
'--with-system-nspr',
'--with-system-nss',
'--with-system-png',
'--with-system-zlib',
'--with-thumb',
'--with-thumb-interwork',

View file

@ -44,9 +44,7 @@ export:: $(export-preqs)
-DMOZ_SYSTEM_HUNSPELL=$(MOZ_SYSTEM_HUNSPELL) \
-DMOZ_SYSTEM_BZ2=$(MOZ_SYSTEM_BZ2) \
-DMOZ_SYSTEM_ZLIB=$(MOZ_SYSTEM_ZLIB) \
-DMOZ_SYSTEM_PNG=$(MOZ_SYSTEM_PNG) \
-DMOZ_SYSTEM_JPEG=$(MOZ_SYSTEM_JPEG) \
-DMOZ_SYSTEM_LIBVPX=$(MOZ_SYSTEM_LIBVPX) \
$(srcdir)/system-headers $(srcdir)/stl-headers | $(PERL) $(topsrcdir)/nsprpub/config/make-system-wrappers.pl system_wrappers
$(INSTALL) system_wrappers $(DIST)

View file

@ -30,14 +30,12 @@ if CONFIG['MOZ_TREMOR']:
if CONFIG['MOZ_WEBM_ENCODER']:
external_dirs += ['media/libmkv']
if not CONFIG['MOZ_SYSTEM_LIBVPX']:
external_dirs += ['media/libvpx']
external_dirs += ['media/libvpx']
if CONFIG['MOZ_AV1']:
external_dirs += ['media/libaom']
if not CONFIG['MOZ_SYSTEM_PNG']:
external_dirs += ['media/libpng']
external_dirs += ['media/libpng']
external_dirs += ['media/libwebp']

View file

@ -119,7 +119,6 @@ DEFAULT_GMAKE_FLAGS += NSS_ENABLE_TLS_1_3=1
ifeq ($(OS_ARCH)_$(GNU_CC),WINNT_1)
DEFAULT_GMAKE_FLAGS += OS_DLLFLAGS='-static-libgcc' NSPR31_LIB_PREFIX=lib
endif
ifndef MOZ_SYSTEM_SQLITE
ifdef MOZ_FOLD_LIBS
DEFAULT_GMAKE_FLAGS += SQLITE_LIB_NAME=nss3
else
@ -127,7 +126,6 @@ DEFAULT_GMAKE_FLAGS += SQLITE_LIB_NAME=mozsqlite3
DEFAULT_GMAKE_FLAGS += SQLITE_LIB_DIR=$(ABS_DIST)/../config/external/sqlite
endif # MOZ_FOLD_LIBS
DEFAULT_GMAKE_FLAGS += SQLITE_INCLUDE_DIR=$(ABS_DIST)/include
endif
ifdef NSS_DISABLE_DBM
DEFAULT_GMAKE_FLAGS += NSS_DISABLE_DBM=1
endif

View file

@ -4,19 +4,15 @@
# 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/.
if CONFIG['MOZ_SYSTEM_SQLITE']:
DIRS += ['../../../db/sqlite3/src']
if CONFIG['MOZ_FOLD_LIBS']:
Library('sqlite')
OS_LIBS += CONFIG['SQLITE_LIBS']
# When folding libraries, sqlite is actually in the nss library.
USE_LIBS += [
'nss',
]
else:
DIRS += ['../../../db/sqlite3/src']
if CONFIG['MOZ_FOLD_LIBS']:
Library('sqlite')
# When folding libraries, sqlite is actually in the nss library.
USE_LIBS += [
'nss',
]
else:
SharedLibrary('sqlite')
SHARED_LIBRARY_NAME = 'mozsqlite3'
SharedLibrary('sqlite')
SHARED_LIBRARY_NAME = 'mozsqlite3'
SYMBOLS_FILE = '/db/sqlite3/src/sqlite.symbols'
SYMBOLS_FILE = '/db/sqlite3/src/sqlite.symbols'

View file

@ -1253,9 +1253,6 @@ soundtouch/SoundTouchFactory.h
#if MOZ_LIBAV_FFT==1
libavcodec/avfft.h
#endif
#if MOZ_SYSTEM_PNG==1
png.h
#endif
#if MOZ_SYSTEM_ZLIB==1
zlib.h
#endif
@ -1291,15 +1288,6 @@ QtSparql/qsparqlresult.h
#if MOZ_TREE_PIXMAN!=1
pixman.h
#endif
#if MOZ_SYSTEM_LIBVPX==1
vpx/svc_context.h
vpx/vpx_codec.h
vpx/vpx_decoder.h
vpx/vpx_encoder.h
vpx/vp8cx.h
vpx/vp8dx.h
vpx_mem/vpx_mem.h
#endif
gst/gst.h
gst/app/gstappsink.h
gst/app/gstappsrc.h

View file

@ -11,9 +11,9 @@ Our own managed and maintained code should adhere to this guide where possible o
## General formatting rules
The following formatting rules apply to all code:
- Always use spaces for indentation, never use tabs!
- Put a space between a keyword and parenthesis, e.g. `if (`.
- Put a space between a keyword and parenthesis, e.g. `if (`. Do _not_ put a space between a function/type-assignment name and its parenthesis, e.g. `function(somevar)` or `int32_t(somevar)`.
- Put a space between variables and operators, e.g. `a == b`.
- Put a space after a comma or semicolon in variable lists, e.g. `function (a, b, c)` or `for (i = 1; i < 10; i++)`.
- Put a space after a comma or semicolon in variable lists, e.g. `function(a, b, c)` or `for (i = 1; i < 10; i++)`.
- Indentation of scopes is 2 spaces.
- Indentation of long lines is variable-aligned or expression-aligned (see "long line wrapping")
- Conditional defines are always placed on column 1. This is also true for nested defines.
@ -236,4 +236,4 @@ ExMSw4MzQ2MjYwNDksLTE5MDMyNzE5OTYsLTEwMTIwMjc3ODMs
LTE4MzgzODM5MDIsODA5MjEzNTEyLC01Mzg0MjM4MDAsMzgyNj
I3NDYzLDIwODYwMjIwODUsLTE1MjU5MjE2MjIsLTY1OTMzMTA0
MCwtNzQwOTE5MDQ1LDE4Njc1NTQxNDJdfQ==
-->
-->

View file

@ -40,7 +40,6 @@
#include "mozilla/dom/FlyWebPublishedServer.h"
#include "mozilla/dom/FlyWebService.h"
#include "mozilla/dom/Permissions.h"
#include "mozilla/dom/Presentation.h"
#include "mozilla/dom/ServiceWorkerContainer.h"
#include "mozilla/dom/StorageManager.h"
#include "mozilla/dom/TCPSocket.h"
@ -67,8 +66,6 @@
#include "nsIAppsService.h"
#include "mozIApplication.h"
#include "WidgetUtils.h"
#include "nsIPresentationService.h"
#include "mozilla/dom/MediaDevices.h"
#include "MediaManager.h"
@ -218,7 +215,6 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Navigator)
#ifdef MOZ_EME
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMediaKeySystemAccessManager)
#endif
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPresentation)
#ifdef MOZ_GAMEPAD
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGamepadServiceTest)
#endif
@ -284,10 +280,6 @@ Navigator::Invalidate()
mTimeManager = nullptr;
}
if (mPresentation) {
mPresentation = nullptr;
}
mServiceWorkerContainer = nullptr;
#ifdef MOZ_EME
@ -1931,19 +1923,5 @@ Navigator::RequestMediaKeySystemAccess(const nsAString& aKeySystem,
}
#endif
Presentation*
Navigator::GetPresentation(ErrorResult& aRv)
{
if (!mPresentation) {
if (!mWindow) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
mPresentation = Presentation::Create(mWindow);
}
return mPresentation;
}
} // namespace dom
} // namespace mozilla

View file

@ -74,7 +74,6 @@ class Connection;
} // namespace network
class PowerManager;
class Presentation;
class LegacyMozTCPSocket;
class StorageManager;
@ -210,8 +209,6 @@ public:
system::AudioChannelManager* GetMozAudioChannelManager(ErrorResult& aRv);
#endif // MOZ_AUDIO_CHANNEL_MANAGER
Presentation* GetPresentation(ErrorResult& aRv);
bool SendBeacon(const nsAString& aUrl,
const Nullable<ArrayBufferViewOrBlobOrStringOrFormData>& aData,
ErrorResult& aRv);
@ -288,7 +285,6 @@ private:
RefPtr<time::TimeManager> mTimeManager;
RefPtr<ServiceWorkerContainer> mServiceWorkerContainer;
nsCOMPtr<nsPIDOMWindowInner> mWindow;
RefPtr<Presentation> mPresentation;
#ifdef MOZ_GAMEPAD
RefPtr<GamepadServiceTest> mGamepadServiceTest;
#endif

View file

@ -1526,6 +1526,40 @@ nsAttrValue::ParseIntWithFallback(const nsAString& aString, int32_t aDefault,
SetIntValueAndType(val, eInteger, nonStrict ? &aString : nullptr);
}
void
nsAttrValue::ParseClampedNonNegativeInt(const nsAString& aString,
int32_t aDefault, int32_t aMin,
int32_t aMax)
{
ResetIfSet();
nsContentUtils::ParseHTMLIntegerResultFlags result;
int32_t val = nsContentUtils::ParseHTMLInteger(aString, &result);
bool nonStrict = (result & nsContentUtils::eParseHTMLInteger_IsPercent) ||
(result & nsContentUtils::eParseHTMLInteger_NonStandard) ||
(result & nsContentUtils::eParseHTMLInteger_DidNotConsumeAllInput);
if (result & nsContentUtils::eParseHTMLInteger_ErrorOverflow) {
if (result & nsContentUtils::eParseHTMLInteger_Negative) {
val = aDefault;
} else {
val = aMax;
}
nonStrict = true;
} else if ((result & nsContentUtils::eParseHTMLInteger_Error) || val < 0) {
val = aDefault;
nonStrict = true;
} else if (val < aMin) {
val = aMin;
nonStrict = true;
} else if (val > aMax) {
val = aMax;
nonStrict = true;
}
SetIntValueAndType(val, eInteger, nonStrict ? &aString : nullptr);
}
bool
nsAttrValue::ParseNonNegativeIntValue(const nsAString& aString)
{

View file

@ -362,6 +362,19 @@ public:
*/
bool ParseNonNegativeIntValue(const nsAString& aString);
/**
* Parse a string value into a clamped non-negative integer.
* This method follows the rules for parsing non-negative integer from:
* https://html.spec.whatwg.org/multipage/infrastructure.html#clamped-to-the-range
*
* @param aString the string to parse
* @param aDefault value to return for negative or invalid values
* @param aMin minimum value
* @param aMax maximum value
*/
void ParseClampedNonNegativeInt(const nsAString& aString, int32_t aDefault,
int32_t aMin, int32_t aMax);
/**
* Parse a string value into a positive integer.
* This method follows the rules for parsing non-negative integer from:

View file

@ -1088,6 +1088,7 @@ nsContentUtils::ParseHTMLInteger(const nsAString& aValue,
int sign = 1;
if (*iter == char16_t('-')) {
sign = -1;
result |= eParseHTMLInteger_Negative;
++iter;
} else if (*iter == char16_t('+')) {
result |= eParseHTMLInteger_NonStandard;

View file

@ -445,7 +445,9 @@ public:
// Set if one or more error flags were set.
eParseHTMLInteger_Error = 1 << 3,
eParseHTMLInteger_ErrorNoValue = 1 << 4,
eParseHTMLInteger_ErrorOverflow = 1 << 5
eParseHTMLInteger_ErrorOverflow = 1 << 5,
// Use this flag to detect the difference between overflow and underflow
eParseHTMLInteger_Negative = 1 << 6,
};
static int32_t ParseHTMLInteger(const nsAString& aValue,
ParseHTMLIntegerResultFlags *aResult);

View file

@ -1871,6 +1871,20 @@ nsresult HTMLMediaElement::LoadResource()
// Set the media element's CORS mode only when loading a resource
mCORSMode = AttrValueToCORSMode(GetParsedAttr(nsGkAtoms::crossorigin));
#ifdef MOZ_EME
bool isBlob = false;
if (mMediaKeys &&
Preferences::GetBool("media.eme.mse-only", true) &&
// We only want mediaSource URLs, but they are BlobURL, so we have to
// check the schema and abort if they are not MediaStream or real Blob.
(NS_FAILED(mLoadingSrc->SchemeIs(BLOBURI_SCHEME, &isBlob)) ||
!isBlob ||
IsMediaStreamURI(mLoadingSrc) ||
IsBlobURI(mLoadingSrc))) {
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
}
#endif
HTMLMediaElement* other = LookupMediaElementURITable(mLoadingSrc);
if (other && other->mDecoder) {
// Clone it.
@ -4000,7 +4014,6 @@ nsresult HTMLMediaElement::FinishDecoderSetup(MediaDecoder* aDecoder,
return NS_ERROR_FAILURE;
}
}
#endif
MediaEventSource<void>* waitingForKeyProducer = mDecoder->WaitingForKeyEvent();
// Not every decoder will produce waitingForKey events, only add ones that can
@ -4008,6 +4021,7 @@ nsresult HTMLMediaElement::FinishDecoderSetup(MediaDecoder* aDecoder,
mWaitingForKeyListener = waitingForKeyProducer->Connect(
AbstractThread::MainThread(), this, &HTMLMediaElement::CannotDecryptWaitingForKey);
}
#endif
if (mChannelLoader) {
mChannelLoader->Done();
@ -6476,7 +6490,6 @@ HTMLMediaElement::GetTopLevelPrincipal()
principal = doc->NodePrincipal();
return principal.forget();
}
#endif //MOZ_EME
void
HTMLMediaElement::CannotDecryptWaitingForKey()
@ -6495,6 +6508,7 @@ HTMLMediaElement::CannotDecryptWaitingForKey()
UpdateReadyStateInternal();
}
}
#endif //MOZ_EME
NS_IMETHODIMP HTMLMediaElement::WindowAudioCaptureChanged(bool aCapture)
{

View file

@ -390,26 +390,16 @@ HTMLTableCellElement::ParseAttribute(int32_t aNamespaceID,
return aResult.ParseIntWithBounds(aValue, 0);
}
if (aAttribute == nsGkAtoms::colspan) {
bool res = aResult.ParseIntWithBounds(aValue, -1);
if (res) {
int32_t val = aResult.GetIntegerValue();
// reset large colspan values as IE and opera do
if (val > MAX_COLSPAN || val <= 0) {
aResult.SetTo(1, &aValue);
}
}
return res;
aResult.ParseClampedNonNegativeInt(aValue, 1, 1, MAX_COLSPAN);
return true;
}
if (aAttribute == nsGkAtoms::rowspan) {
bool res = aResult.ParseIntWithBounds(aValue, -1, MAX_ROWSPAN);
if (res) {
int32_t val = aResult.GetIntegerValue();
// quirks mode does not honor the special html 4 value of 0
if (val < 0 || (0 == val && InNavQuirksMode(OwnerDoc()))) {
aResult.ParseClampedNonNegativeInt(aValue, 1, 0, MAX_ROWSPAN);
// quirks mode does not honor the special html 4 value of 0
if (aResult.GetIntegerValue() == 0 && InNavQuirksMode(OwnerDoc())) {
aResult.SetTo(1, &aValue);
}
}
return res;
return true;
}
if (aAttribute == nsGkAtoms::height) {
return aResult.ParseSpecialIntValue(aValue);

View file

@ -37,7 +37,7 @@ public:
}
void SetColSpan(uint32_t aColSpan, ErrorResult& aError)
{
SetHTMLIntAttr(nsGkAtoms::colspan, aColSpan, aError);
SetUnsignedIntAttr(nsGkAtoms::colspan, aColSpan, 1, aError);
}
uint32_t RowSpan() const
{
@ -45,7 +45,7 @@ public:
}
void SetRowSpan(uint32_t aRowSpan, ErrorResult& aError)
{
SetHTMLIntAttr(nsGkAtoms::rowspan, aRowSpan, aError);
SetUnsignedIntAttr(nsGkAtoms::rowspan, aRowSpan, 1, aError);
}
//already_AddRefed<nsDOMTokenList> Headers() const;
void GetHeaders(DOMString& aHeaders)

View file

@ -150,8 +150,6 @@
#endif
#include "mozilla/dom/File.h"
#include "mozilla/dom/PPresentationChild.h"
#include "mozilla/dom/PresentationIPCService.h"
#include "mozilla/ipc/InputStreamUtils.h"
#ifdef MOZ_WEBSPEECH
@ -1417,20 +1415,6 @@ ContentChild::SendPBlobConstructor(PBlobChild* aActor,
return PContentChild::SendPBlobConstructor(aActor, aParams);
}
PPresentationChild*
ContentChild::AllocPPresentationChild()
{
MOZ_CRASH("We should never be manually allocating PPresentationChild actors");
return nullptr;
}
bool
ContentChild::DeallocPPresentationChild(PPresentationChild* aActor)
{
delete aActor;
return true;
}
PFlyWebPublishedServerChild*
ContentChild::AllocPFlyWebPublishedServerChild(const nsString& name,
const FlyWebPublishOptions& params)
@ -1447,35 +1431,6 @@ ContentChild::DeallocPFlyWebPublishedServerChild(PFlyWebPublishedServerChild* aA
return true;
}
bool
ContentChild::RecvNotifyPresentationReceiverLaunched(PBrowserChild* aIframe,
const nsString& aSessionId)
{
nsCOMPtr<nsIDocShell> docShell =
do_GetInterface(static_cast<TabChild*>(aIframe)->WebNavigation());
NS_WARNING_ASSERTION(docShell, "WebNavigation failed");
nsCOMPtr<nsIPresentationService> service =
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
NS_WARNING_ASSERTION(service, "presentation service is missing");
Unused << NS_WARN_IF(NS_FAILED(static_cast<PresentationIPCService*>(service.get())->MonitorResponderLoading(aSessionId, docShell)));
return true;
}
bool
ContentChild::RecvNotifyPresentationReceiverCleanUp(const nsString& aSessionId)
{
nsCOMPtr<nsIPresentationService> service =
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
NS_WARNING_ASSERTION(service, "presentation service is missing");
Unused << NS_WARN_IF(NS_FAILED(service->UntrackSessionInfo(aSessionId, nsIPresentationService::ROLE_RECEIVER)));
return true;
}
bool
ContentChild::RecvNotifyEmptyHTTPCache()
{

View file

@ -297,23 +297,12 @@ public:
virtual bool DeallocPStorageChild(PStorageChild* aActor) override;
virtual PPresentationChild* AllocPPresentationChild() override;
virtual bool DeallocPPresentationChild(PPresentationChild* aActor) override;
virtual PFlyWebPublishedServerChild*
AllocPFlyWebPublishedServerChild(const nsString& name,
const FlyWebPublishOptions& params) override;
virtual bool DeallocPFlyWebPublishedServerChild(PFlyWebPublishedServerChild* aActor) override;
virtual bool
RecvNotifyPresentationReceiverLaunched(PBrowserChild* aIframe,
const nsString& aSessionId) override;
virtual bool
RecvNotifyPresentationReceiverCleanUp(const nsString& aSessionId) override;
virtual bool RecvNotifyEmptyHTTPCache() override;
virtual PSpeechSynthesisChild* AllocPSpeechSynthesisChild() override;

View file

@ -51,8 +51,6 @@
#include "mozilla/dom/ServiceWorkerRegistrar.h"
#include "mozilla/dom/power/PowerManagerService.h"
#include "mozilla/dom/Permissions.h"
#include "mozilla/dom/PresentationParent.h"
#include "mozilla/dom/PPresentationParent.h"
#include "mozilla/dom/PushNotifier.h"
#include "mozilla/dom/FlyWebPublishedServerIPC.h"
#include "mozilla/dom/quota/QuotaManagerService.h"
@ -3123,27 +3121,6 @@ ContentParent::DeallocPStorageParent(PStorageParent* aActor)
return true;
}
PPresentationParent*
ContentParent::AllocPPresentationParent()
{
RefPtr<PresentationParent> actor = new PresentationParent();
return actor.forget().take();
}
bool
ContentParent::DeallocPPresentationParent(PPresentationParent* aActor)
{
RefPtr<PresentationParent> actor =
dont_AddRef(static_cast<PresentationParent*>(aActor));
return true;
}
bool
ContentParent::RecvPPresentationConstructor(PPresentationParent* aActor)
{
return static_cast<PresentationParent*>(aActor)->Init(mChildID);
}
PFlyWebPublishedServerParent*
ContentParent::AllocPFlyWebPublishedServerParent(const nsString& name,
const FlyWebPublishOptions& params)

View file

@ -800,12 +800,6 @@ private:
virtual bool DeallocPStorageParent(PStorageParent* aActor) override;
virtual PPresentationParent* AllocPPresentationParent() override;
virtual bool DeallocPPresentationParent(PPresentationParent* aActor) override;
virtual bool RecvPPresentationConstructor(PPresentationParent* aActor) override;
virtual PFlyWebPublishedServerParent*
AllocPFlyWebPublishedServerParent(const nsString& name,
const FlyWebPublishOptions& params) override;

View file

@ -43,7 +43,6 @@ include protocol PJavaScript;
include protocol PRemoteSpellcheckEngine;
include protocol PWebBrowserPersistDocument;
include protocol PWebrtcGlobal;
include protocol PPresentation;
include protocol PVideoDecoderManager;
include protocol PFlyWebPublishedServer;
include DOMTypes;
@ -260,7 +259,6 @@ nested(upto inside_cpow) sync protocol PContent
manages PRemoteSpellcheckEngine;
manages PWebBrowserPersistDocument;
manages PWebrtcGlobal;
manages PPresentation;
manages PFlyWebPublishedServer;
both:
@ -480,18 +478,6 @@ child:
*/
async UpdateWindow(uintptr_t aChildId);
/**
* Notify the child that presentation receiver has been launched with the
* correspondent iframe.
*/
async NotifyPresentationReceiverLaunched(PBrowser aIframe, nsString aSessionId);
/**
* Notify the child that the info about a presentation receiver needs to be
* cleaned up.
*/
async NotifyPresentationReceiverCleanUp(nsString aSessionId);
/**
* Notify the child that cache is emptied.
*/
@ -682,8 +668,6 @@ parent:
async PWebrtcGlobal();
async PPresentation();
async PFlyWebPublishedServer(nsString name, FlyWebPublishOptions params);
// Services remoting

View file

@ -31,7 +31,9 @@ class MediaResource;
class ReentrantMonitor;
class VideoFrameContainer;
class MediaDecoderOwner;
#ifdef MOZ_EME
class CDMProxy;
#endif
typedef nsDataHashtable<nsCStringHashKey, nsCString> MetadataTags;

View file

@ -387,7 +387,9 @@ MediaDecoder::MediaDecoder(MediaDecoderOwner* aOwner)
, mLogicalPosition(0.0)
, mDuration(std::numeric_limits<double>::quiet_NaN())
, mResourceCallback(new ResourceCallback())
#ifdef MOZ_EME
, mCDMProxyPromise(mCDMProxyPromiseHolder.Ensure(__func__))
#endif
, mIgnoreProgressData(false)
, mInfiniteStream(false)
, mOwner(aOwner)
@ -472,7 +474,9 @@ MediaDecoder::Shutdown()
mResourceCallback->Disconnect();
#ifdef MOZ_EME
mCDMProxyPromiseHolder.RejectIfExists(true, __func__);
#endif
DiscardOngoingSeekIfExists();
@ -1537,6 +1541,7 @@ MediaDecoder::CanPlayThrough()
return GetStatistics().CanPlayThrough();
}
#ifdef MOZ_EME
RefPtr<MediaDecoder::CDMProxyPromise>
MediaDecoder::RequestCDMProxy() const
{
@ -1551,6 +1556,7 @@ MediaDecoder::SetCDMProxy(CDMProxy* aProxy)
mCDMProxyPromiseHolder.ResolveIfExists(aProxy, __func__);
}
#endif
bool
MediaDecoder::IsOpusEnabled()

View file

@ -8,7 +8,11 @@
#define MediaDecoder_h_
#include "mozilla/Atomics.h"
#ifdef MOZ_EME
#include "mozilla/CDMProxy.h"
#endif
#include "mozilla/MozPromise.h"
#include "mozilla/ReentrantMonitor.h"
#include "mozilla/StateMirroring.h"
@ -432,6 +436,7 @@ private:
MediaDecoderOwner* GetOwner() const override;
#ifdef MOZ_EME
typedef MozPromise<RefPtr<CDMProxy>, bool /* aIgnored */, /* IsExclusive = */ true> CDMProxyPromise;
// Resolved when a CDMProxy is available and the capabilities are known or
@ -439,6 +444,7 @@ private:
RefPtr<CDMProxyPromise> RequestCDMProxy() const;
void SetCDMProxy(CDMProxy* aProxy);
#endif
static bool IsOggEnabled();
static bool IsOpusEnabled();
@ -589,8 +595,10 @@ private:
RefPtr<ResourceCallback> mResourceCallback;
#ifdef MOZ_EME
MozPromiseHolder<CDMProxyPromise> mCDMProxyPromiseHolder;
RefPtr<CDMProxyPromise> mCDMProxyPromise;
#endif
protected:
// The promise resolving/rejection is queued as a "micro-task" which will be

View file

@ -24,7 +24,9 @@
namespace mozilla {
#ifdef MOZ_EME
class CDMProxy;
#endif
class MediaDecoderReader;
struct WaitForDataRejectValue
@ -186,7 +188,9 @@ public:
// when to call SetIdle().
virtual void SetIdle() {}
#ifdef MOZ_EME
virtual void SetCDMProxy(CDMProxy* aProxy) {}
#endif
// Tell the reader that the data decoded are not for direct playback, so it
// can accept more files, in particular those which have more channels than

View file

@ -113,7 +113,9 @@ public:
return mReader->CanonicalBuffered();
}
#ifdef MOZ_EME
void SetCDMProxy(CDMProxy* aProxy) { mReader->SetCDMProxy(aProxy); }
#endif
void SetVideoBlankDecode(bool aIsBlankDecode);

View file

@ -1238,7 +1238,12 @@ DecodeMetadataState::OnMetadataRead(MetadataHolder* aMetadata)
// feeding in the CDM, which we need to decode the first frame (and
// thus get the metadata). We could fix this if we could compute the start
// time by demuxing without necessaring decoding.
bool waitingForCDM = Info().IsEncrypted() && !mMaster->mCDMProxy;
bool waitingForCDM =
#ifdef MOZ_EME
mMaster->Info().IsEncrypted() && !mMaster->mCDMProxy;
#else
false;
#endif
mMaster->mNotifyMetadataBeforeFirstFrame =
mMaster->mDuration.Ref().isSome() || waitingForCDM;
@ -1262,7 +1267,9 @@ DormantState::HandlePlayStateChanged(MediaDecoder::PlayState aPlayState)
{
if (aPlayState == MediaDecoder::PLAY_STATE_PLAYING) {
// Exit dormant when the user wants to play.
#ifdef MOZ_EME
MOZ_ASSERT(!Info().IsEncrypted() || mMaster->mCDMProxy);
#endif
MOZ_ASSERT(mMaster->mSentFirstFrameLoadedEvent);
SetState<SeekingState>(Move(mPendingSeek), EventVisibility::Suppressed);
}
@ -1575,7 +1582,9 @@ ShutdownState::Enter()
// dispose of the timer.
master->mVideoDecodeSuspendTimer.Reset();
#ifdef MOZ_EME
master->mCDMProxyPromise.DisconnectIfExists();
#endif
if (master->IsPlaying()) {
master->StopPlayback();
@ -2129,10 +2138,12 @@ nsresult MediaDecoderStateMachine::Init(MediaDecoder* aDecoder)
mMediaSink = CreateMediaSink(mAudioCaptured);
#ifdef MOZ_EME
mCDMProxyPromise.Begin(aDecoder->RequestCDMProxy()->Then(
OwnerThread(), __func__, this,
&MediaDecoderStateMachine::OnCDMProxyReady,
&MediaDecoderStateMachine::OnCDMProxyNotReady));
#endif
nsresult rv = mReader->Init();
NS_ENSURE_SUCCESS(rv, rv);
@ -3108,6 +3119,7 @@ void MediaDecoderStateMachine::OnMediaSinkAudioError(nsresult aResult)
DecodeError(MediaResult(NS_ERROR_DOM_MEDIA_MEDIASINK_ERR, __func__));
}
#ifdef MOZ_EME
void
MediaDecoderStateMachine::OnCDMProxyReady(RefPtr<CDMProxy> aProxy)
{
@ -3124,6 +3136,7 @@ MediaDecoderStateMachine::OnCDMProxyNotReady()
MOZ_ASSERT(OnTaskQueue());
mCDMProxyPromise.Complete();
}
#endif
void
MediaDecoderStateMachine::SetAudioCaptured(bool aCaptured)

View file

@ -768,10 +768,12 @@ private:
// Playback will not start when audio is offloading.
bool mAudioOffloading;
#ifdef MOZ_EME
void OnCDMProxyReady(RefPtr<CDMProxy> aProxy);
void OnCDMProxyNotReady();
RefPtr<CDMProxy> mCDMProxy;
MozPromiseRequestHolder<MediaDecoder::CDMProxyPromise> mCDMProxyPromise;
#endif
private:
// The buffered range. Mirrored from the decoder thread.

View file

@ -4,7 +4,10 @@
* 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/. */
#ifdef MOZ_EME
#include "mozilla/CDMProxy.h"
#endif
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/dom/HTMLMediaElement.h"
#include "mozilla/Preferences.h"
@ -611,7 +614,6 @@ private:
nsTArray<uint8_t> mInitData;
nsString mInitDataType;
};
#endif
void
MediaFormatReader::SetCDMProxy(CDMProxy* aProxy)
@ -624,6 +626,7 @@ MediaFormatReader::SetCDMProxy(CDMProxy* aProxy)
});
OwnerThread()->Dispatch(r.forget());
}
#endif // MOZ_EME
bool
MediaFormatReader::IsWaitingOnCDMResource() {

View file

@ -20,7 +20,9 @@
namespace mozilla {
#ifdef MOZ_EME
class CDMProxy;
#endif
class MediaFormatReader final : public MediaDecoderReader
{
@ -91,7 +93,9 @@ public:
return mTrackDemuxersMayBlock;
}
#ifdef MOZ_EME
void SetCDMProxy(CDMProxy* aProxy) override;
#endif
// Returns a string describing the state of the decoder data.
// Used for debugging purposes.
@ -584,7 +588,9 @@ private:
RefPtr<VideoFrameContainer> mVideoFrameContainer;
layers::ImageContainer* GetImageContainer();
#ifdef MOZ_EME
RefPtr<CDMProxy> mCDMProxy;
#endif
RefPtr<GMPCrashHelper> mCrashHelper;

View file

@ -13,8 +13,6 @@ XPCOMUtils.defineLazyModuleGetter(this, "PeerConnectionIdp",
"resource://gre/modules/media/PeerConnectionIdp.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "convertToRTCStatsReport",
"resource://gre/modules/media/RTCStatsReport.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "AppConstants",
"resource://gre/modules/AppConstants.jsm");
const PC_CONTRACT = "@mozilla.org/dom/peerconnection;1";
const PC_OBS_CONTRACT = "@mozilla.org/dom/peerconnectionobserver;1";

View file

@ -10,7 +10,9 @@
#include "MP4Demuxer.h"
#include "mozilla/Preferences.h"
#include "nsCharSeparatedTokenizer.h"
#ifdef MOZ_EME
#include "mozilla/CDMProxy.h"
#endif
#include "mozilla/Logging.h"
#include "mozilla/SharedThreadPool.h"
#include "nsMimeTypes.h"

View file

@ -22,7 +22,9 @@
#include "GMPUtils.h"
#include "prio.h"
#include "base/task.h"
#ifdef MOZ_EME
#include "widevine-adapter/WidevineAdapter.h"
#endif
using namespace mozilla::ipc;
@ -254,9 +256,13 @@ GMPChild::AnswerStartPlugin(const nsString& aAdapter)
return false;
}
#ifdef MOZ_EME
bool isWidevine = aAdapter.EqualsLiteral("widevine");
GMPAdapter* adapter = (isWidevine) ? new WidevineAdapter() : nullptr;
#else
GMPAdapter* adapter = nullptr;
#endif
if (!mGMPLoader->Load(libPath.get(),
libPath.Length(),
mNodeId.BeginWriting(),

View file

@ -43,11 +43,13 @@ GMPDecryptorParent::~GMPDecryptorParent()
bool
GMPDecryptorParent::RecvSetDecryptorId(const uint32_t& aId)
{
#ifdef MOZ_EME
if (!mIsOpen) {
NS_WARNING("Trying to use a dead GMP decrypter!");
return false;
}
mCallback->SetDecryptorId(aId);
#endif
return true;
}
@ -202,6 +204,7 @@ bool
GMPDecryptorParent::RecvSetSessionId(const uint32_t& aCreateSessionId,
const nsCString& aSessionId)
{
#ifdef MOZ_EME
LOGD(("GMPDecryptorParent[%p]::RecvSetSessionId(token=%u, sessionId='%s')",
this, aCreateSessionId, aSessionId.get()));
@ -210,6 +213,7 @@ GMPDecryptorParent::RecvSetSessionId(const uint32_t& aCreateSessionId,
return false;
}
mCallback->SetSessionId(aCreateSessionId, aSessionId);
#endif
return true;
}
@ -217,6 +221,7 @@ bool
GMPDecryptorParent::RecvResolveLoadSessionPromise(const uint32_t& aPromiseId,
const bool& aSuccess)
{
#ifdef MOZ_EME
LOGD(("GMPDecryptorParent[%p]::RecvResolveLoadSessionPromise(promiseId=%u)",
this, aPromiseId));
@ -225,12 +230,14 @@ GMPDecryptorParent::RecvResolveLoadSessionPromise(const uint32_t& aPromiseId,
return false;
}
mCallback->ResolveLoadSessionPromise(aPromiseId, aSuccess);
#endif
return true;
}
bool
GMPDecryptorParent::RecvResolvePromise(const uint32_t& aPromiseId)
{
#ifdef MOZ_EME
LOGD(("GMPDecryptorParent[%p]::RecvResolvePromise(promiseId=%u)",
this, aPromiseId));
@ -239,6 +246,7 @@ GMPDecryptorParent::RecvResolvePromise(const uint32_t& aPromiseId)
return false;
}
mCallback->ResolvePromise(aPromiseId);
#endif
return true;
}
@ -266,6 +274,7 @@ GMPDecryptorParent::RecvRejectPromise(const uint32_t& aPromiseId,
const GMPDOMException& aException,
const nsCString& aMessage)
{
#ifdef MOZ_EME
LOGD(("GMPDecryptorParent[%p]::RecvRejectPromise(promiseId=%u, exception=%d, msg='%s')",
this, aPromiseId, aException, aMessage.get()));
@ -274,10 +283,11 @@ GMPDecryptorParent::RecvRejectPromise(const uint32_t& aPromiseId,
return false;
}
mCallback->RejectPromise(aPromiseId, GMPExToNsresult(aException), aMessage);
#endif
return true;
}
#ifdef MOZ_EME
static dom::MediaKeyMessageType
ToMediaKeyMessageType(GMPSessionMessageType aMessageType) {
switch (aMessageType) {
@ -288,12 +298,14 @@ ToMediaKeyMessageType(GMPSessionMessageType aMessageType) {
default: return dom::MediaKeyMessageType::License_request;
};
};
#endif
bool
GMPDecryptorParent::RecvSessionMessage(const nsCString& aSessionId,
const GMPSessionMessageType& aMessageType,
nsTArray<uint8_t>&& aMessage)
{
#ifdef MOZ_EME
LOGD(("GMPDecryptorParent[%p]::RecvSessionMessage(sessionId='%s', type=%d, msg='%s')",
this, aSessionId.get(), aMessageType, ToBase64(aMessage).get()));
@ -302,6 +314,7 @@ GMPDecryptorParent::RecvSessionMessage(const nsCString& aSessionId,
return false;
}
mCallback->SessionMessage(aSessionId, ToMediaKeyMessageType(aMessageType), aMessage);
#endif
return true;
}
@ -309,6 +322,7 @@ bool
GMPDecryptorParent::RecvExpirationChange(const nsCString& aSessionId,
const double& aExpiryTime)
{
#ifdef MOZ_EME
LOGD(("GMPDecryptorParent[%p]::RecvExpirationChange(sessionId='%s', expiry=%lf)",
this, aSessionId.get(), aExpiryTime));
@ -317,12 +331,14 @@ GMPDecryptorParent::RecvExpirationChange(const nsCString& aSessionId,
return false;
}
mCallback->ExpirationChange(aSessionId, aExpiryTime);
#endif
return true;
}
bool
GMPDecryptorParent::RecvSessionClosed(const nsCString& aSessionId)
{
#ifdef MOZ_EME
LOGD(("GMPDecryptorParent[%p]::RecvSessionClosed(sessionId='%s')",
this, aSessionId.get()));
@ -331,6 +347,7 @@ GMPDecryptorParent::RecvSessionClosed(const nsCString& aSessionId)
return false;
}
mCallback->SessionClosed(aSessionId);
#endif
return true;
}
@ -340,6 +357,7 @@ GMPDecryptorParent::RecvSessionError(const nsCString& aSessionId,
const uint32_t& aSystemCode,
const nsCString& aMessage)
{
#ifdef MOZ_EME
LOGD(("GMPDecryptorParent[%p]::RecvSessionError(sessionId='%s', exception=%d, sysCode=%d, msg='%s')",
this, aSessionId.get(),
aException, aSystemCode, aMessage.get()));
@ -352,9 +370,11 @@ GMPDecryptorParent::RecvSessionError(const nsCString& aSessionId,
GMPExToNsresult(aException),
aSystemCode,
aMessage);
#endif
return true;
}
#ifdef MOZ_EME
static dom::MediaKeyStatus
ToMediaKeyStatus(GMPMediaKeyStatus aStatus) {
switch (aStatus) {
@ -368,11 +388,13 @@ ToMediaKeyStatus(GMPMediaKeyStatus aStatus) {
default: return dom::MediaKeyStatus::Internal_error;
}
}
#endif
bool
GMPDecryptorParent::RecvBatchedKeyStatusChanged(const nsCString& aSessionId,
InfallibleTArray<GMPKeyInformation>&& aKeyInfos)
{
#ifdef MOZ_EME
LOGD(("GMPDecryptorParent[%p]::RecvBatchedKeyStatusChanged(sessionId='%s', KeyInfos len='%d')",
this, aSessionId.get(), aKeyInfos.Length()));
@ -392,9 +414,11 @@ GMPDecryptorParent::RecvBatchedKeyStatusChanged(const nsCString& aSessionId,
}
mCallback->BatchedKeyStatusChanged(aSessionId, cdmKeyInfos);
}
#endif
return true;
}
#ifdef MOZ_EME
DecryptStatus
ToDecryptStatus(GMPErr aError)
{
@ -405,12 +429,14 @@ ToDecryptStatus(GMPErr aError)
default: return GenericErr;
}
}
#endif
bool
GMPDecryptorParent::RecvDecrypted(const uint32_t& aId,
const GMPErr& aErr,
InfallibleTArray<uint8_t>&& aBuffer)
{
#ifdef MOZ_EME
LOGV(("GMPDecryptorParent[%p]::RecvDecrypted(id=%d, err=%d)",
this, aId, aErr));
@ -419,6 +445,7 @@ GMPDecryptorParent::RecvDecrypted(const uint32_t& aId,
return false;
}
mCallback->Decrypted(aId, ToDecryptStatus(aErr), aBuffer);
#endif
return true;
}

View file

@ -6,7 +6,9 @@
#ifndef GMPDecryptorProxy_h_
#define GMPDecryptorProxy_h_
#ifdef MOZ_EME
#include "mozilla/DecryptorProxyCallback.h"
#endif
#include "GMPCallbackBase.h"
#include "gmp-decryption.h"
#include "nsString.h"
@ -15,8 +17,13 @@ namespace mozilla {
class CryptoSample;
} // namespace mozilla
#ifdef MOZ_EME
class GMPDecryptorProxyCallback : public DecryptorProxyCallback,
public GMPCallbackBase {
#else
class GMPDecryptorProxyCallback : public GMPCallbackBase {
#endif
public:
virtual ~GMPDecryptorProxyCallback() {}
};

View file

@ -30,8 +30,10 @@ using mozilla::ipc::GeckoChildProcessHost;
#include "WMFDecoderModule.h"
#endif
#ifdef MOZ_EME
#include "mozilla/dom/WidevineCDMManifestBinding.h"
#include "widevine-adapter/WidevineAdapter.h"
#endif
namespace mozilla {
@ -654,6 +656,7 @@ GMPParent::ReadGMPMetaData()
return ReadGMPInfoFile(infoFile);
}
#ifdef MOZ_EME
// Maybe this is the Widevine adapted plugin?
nsCOMPtr<nsIFile> manifestFile;
rv = mDirectory->Clone(getter_AddRefs(manifestFile));
@ -662,6 +665,9 @@ GMPParent::ReadGMPMetaData()
}
manifestFile->AppendRelativePath(NS_LITERAL_STRING("manifest.json"));
return ReadChromiumManifestFile(manifestFile);
#else
return GenericPromise::CreateAndReject(NS_ERROR_FAILURE, __func__);
#endif
}
RefPtr<GenericPromise>
@ -764,6 +770,7 @@ GMPParent::ReadChromiumManifestFile(nsIFile* aFile)
RefPtr<GenericPromise>
GMPParent::ParseChromiumManifest(nsString aJSON)
{
#ifdef MOZ_EME
LOGD("%s: for '%s'", __FUNCTION__, NS_LossyConvertUTF16toASCII(aJSON).get());
MOZ_ASSERT(NS_IsMainThread());
@ -801,6 +808,10 @@ GMPParent::ParseChromiumManifest(nsString aJSON)
#endif
return GenericPromise::CreateAndResolve(true, __func__);
#else // !MOZ_EME
MOZ_ASSERT_UNREACHABLE("don't call me if EME isn't enabled");
return GenericPromise::CreateAndReject(NS_ERROR_FAILURE, __func__);
#endif // !MOZ_EME
}
bool

View file

@ -35,8 +35,6 @@ EXPORTS += [
'GMPAudioDecoderProxy.h',
'GMPAudioHost.h',
'GMPCallbackBase.h',
'GMPCDMCallbackProxy.h',
'GMPCDMProxy.h',
'GMPChild.h',
'GMPContentChild.h',
'GMPContentParent.h',
@ -73,6 +71,12 @@ EXPORTS += [
'GMPVideoPlaneImpl.h',
]
if CONFIG['MOZ_EME']:
EXPORTS += [
'GMPCDMCallbackProxy.h',
'GMPCDMProxy.h',
]
# We link GMPLoader into xul on B2G/Fennec as its code does not need to be
# covered by a DRM vendor's voucher.
if CONFIG['OS_TARGET'] == 'Android':
@ -87,8 +91,6 @@ UNIFIED_SOURCES += [
'GMPAudioDecoderChild.cpp',
'GMPAudioDecoderParent.cpp',
'GMPAudioHost.cpp',
'GMPCDMCallbackProxy.cpp',
'GMPCDMProxy.cpp',
'GMPChild.cpp',
'GMPContentChild.cpp',
'GMPContentParent.cpp',
@ -120,10 +122,16 @@ UNIFIED_SOURCES += [
'GMPVideoPlaneImpl.cpp',
]
DIRS += [
'rlz',
'widevine-adapter',
]
if CONFIG['MOZ_EME']:
UNIFIED_SOURCES += [
'GMPCDMCallbackProxy.cpp',
'GMPCDMProxy.cpp',
]
DIRS += ['rlz']
if CONFIG['MOZ_EME']:
DIRS += ['widevine-adapter']
IPDL_SOURCES += [
'GMPTypes.ipdlh',

View file

@ -28,6 +28,11 @@ UNIFIED_SOURCES += [
'TestWebMBuffered.cpp',
]
if CONFIG['MOZ_EME']:
UNIFIED_SOURCES += [
'TestEME.cpp',
]
if CONFIG['MOZ_WEBM_ENCODER']:
UNIFIED_SOURCES += [
'TestVideoTrackEncoder.cpp',

View file

@ -84,7 +84,7 @@ private:
nsTArray<uint8_t> mInitData;
nsString mInitDataType;
};
#endif
#endif // MOZ_EME
TrackBuffersManager::TrackBuffersManager(MediaSourceDecoder* aParentDecoder,
const nsACString& aType)

View file

@ -20,7 +20,6 @@ with Files('GetUserMedia*'):
BUG_COMPONENT = component_av
DIRS += [
'eme',
'encoder',
'flac',
'gmp',
@ -49,6 +48,9 @@ if CONFIG['MOZ_FMP4']:
if CONFIG['MOZ_WEBRTC']:
DIRS += ['bridge']
if CONFIG['MOZ_EME']:
DIRS += ['eme']
TEST_DIRS += [
'gtest',
]

View file

@ -24,7 +24,6 @@
#endif
#include "GMPDecoderModule.h"
#include "mozilla/CDMProxy.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/SharedThreadPool.h"
#include "mozilla/StaticPtr.h"
@ -37,7 +36,11 @@
#include "H264Converter.h"
#include "AgnosticDecoderModule.h"
#ifdef MOZ_EME
#include "mozilla/CDMProxy.h"
#include "EMEDecoderModule.h"
#endif
#include "DecoderDoctorDiagnostics.h"
@ -463,11 +466,13 @@ PDMFactory::GetDecoder(const TrackInfo& aTrackInfo,
return pdm.forget();
}
#ifdef MOZ_EME
void
PDMFactory::SetCDMProxy(CDMProxy* aProxy)
{
RefPtr<PDMFactory> m = new PDMFactory();
mEMEPDM = new EMEDecoderModule(aProxy, m);
}
#endif
} // namespace mozilla

View file

@ -11,7 +11,9 @@
#include "mozilla/Function.h"
#include "mozilla/StaticMutex.h"
#ifdef MOZ_EME
class CDMProxy;
#endif
namespace mozilla {
@ -38,12 +40,14 @@ public:
bool Supports(const TrackInfo& aTrackInfo,
DecoderDoctorDiagnostics* aDiagnostics) const;
#ifdef MOZ_EME
// Creates a PlatformDecoderModule that uses a CDMProxy to decrypt or
// decrypt-and-decode EME encrypted content. If the CDM only decrypts and
// does not decode, we create a PDM and use that to create MediaDataDecoders
// that we use on on aTaskQueue to decode the decrypted stream.
// This is called on the decode task queue.
void SetCDMProxy(CDMProxy* aProxy);
#endif
static constexpr int kYUV400 = 0;
static constexpr int kYUV420 = 1;

View file

@ -30,11 +30,13 @@ UNIFIED_SOURCES += [
]
DIRS += [
'agnostic/eme',
'agnostic/gmp',
'omx'
]
if CONFIG['MOZ_EME']:
DIRS += ['agnostic/eme']
if CONFIG['MOZ_WMF']:
DIRS += [ 'wmf' ];

View file

@ -107,8 +107,6 @@ if CONFIG['OS_ARCH'] == 'WINNT':
if CONFIG['MOZ_SECUREELEMENT']:
DIRS += ['secureelement']
DIRS += ['presentation']
TEST_DIRS += [
'tests',
'imptests',

View file

@ -1,99 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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/. */
#include "AvailabilityCollection.h"
#include "mozilla/ClearOnShutdown.h"
#include "PresentationAvailability.h"
namespace mozilla {
namespace dom {
/* static */
StaticAutoPtr<AvailabilityCollection>
AvailabilityCollection::sSingleton;
static bool gOnceAliveNowDead = false;
/* static */ AvailabilityCollection*
AvailabilityCollection::GetSingleton()
{
MOZ_ASSERT(NS_IsMainThread());
if (!sSingleton && !gOnceAliveNowDead) {
sSingleton = new AvailabilityCollection();
ClearOnShutdown(&sSingleton);
}
return sSingleton;
}
AvailabilityCollection::AvailabilityCollection()
{
MOZ_COUNT_CTOR(AvailabilityCollection);
}
AvailabilityCollection::~AvailabilityCollection()
{
MOZ_COUNT_DTOR(AvailabilityCollection);
gOnceAliveNowDead = true;
}
void
AvailabilityCollection::Add(PresentationAvailability* aAvailability)
{
MOZ_ASSERT(NS_IsMainThread());
if (!aAvailability) {
return;
}
WeakPtr<PresentationAvailability> availability = aAvailability;
if (mAvailabilities.Contains(aAvailability)) {
return;
}
mAvailabilities.AppendElement(aAvailability);
}
void
AvailabilityCollection::Remove(PresentationAvailability* aAvailability)
{
MOZ_ASSERT(NS_IsMainThread());
if (!aAvailability) {
return;
}
WeakPtr<PresentationAvailability> availability = aAvailability;
mAvailabilities.RemoveElement(availability);
}
already_AddRefed<PresentationAvailability>
AvailabilityCollection::Find(const uint64_t aWindowId, const nsTArray<nsString>& aUrls)
{
MOZ_ASSERT(NS_IsMainThread());
// Loop backwards to allow removing elements in the loop.
for (int i = mAvailabilities.Length() - 1; i >= 0; --i) {
WeakPtr<PresentationAvailability> availability = mAvailabilities[i];
if (!availability) {
// The availability object was destroyed. Remove it from the list.
mAvailabilities.RemoveElementAt(i);
continue;
}
if (availability->Equals(aWindowId, aUrls)) {
RefPtr<PresentationAvailability> matchedAvailability = availability.get();
return matchedAvailability.forget();
}
}
return nullptr;
}
} // namespace dom
} // namespace mozilla

View file

@ -1,45 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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_AvailabilityCollection_h
#define mozilla_dom_AvailabilityCollection_h
#include "mozilla/StaticPtr.h"
#include "mozilla/WeakPtr.h"
#include "nsString.h"
#include "nsTArray.h"
namespace mozilla {
namespace dom {
class PresentationAvailability;
class AvailabilityCollection final
{
public:
static AvailabilityCollection* GetSingleton();
void Add(PresentationAvailability* aAvailability);
void Remove(PresentationAvailability* aAvailability);
already_AddRefed<PresentationAvailability>
Find(const uint64_t aWindowId, const nsTArray<nsString>& aUrls);
private:
friend class StaticAutoPtr<AvailabilityCollection>;
AvailabilityCollection();
virtual ~AvailabilityCollection();
static StaticAutoPtr<AvailabilityCollection> sSingleton;
nsTArray<WeakPtr<PresentationAvailability>> mAvailabilities;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_AvailabilityCollection_h

View file

@ -1,116 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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/. */
#include "ControllerConnectionCollection.h"
#include "mozilla/ClearOnShutdown.h"
#include "nsIPresentationService.h"
#include "PresentationConnection.h"
namespace mozilla {
namespace dom {
/* static */
StaticAutoPtr<ControllerConnectionCollection>
ControllerConnectionCollection::sSingleton;
/* static */ ControllerConnectionCollection*
ControllerConnectionCollection::GetSingleton()
{
MOZ_ASSERT(NS_IsMainThread());
if (!sSingleton) {
sSingleton = new ControllerConnectionCollection();
ClearOnShutdown(&sSingleton);
}
return sSingleton;
}
ControllerConnectionCollection::ControllerConnectionCollection()
{
MOZ_COUNT_CTOR(ControllerConnectionCollection);
}
ControllerConnectionCollection::~ControllerConnectionCollection()
{
MOZ_COUNT_DTOR(ControllerConnectionCollection);
}
void
ControllerConnectionCollection::AddConnection(
PresentationConnection* aConnection,
const uint8_t aRole)
{
MOZ_ASSERT(NS_IsMainThread());
if (aRole != nsIPresentationService::ROLE_CONTROLLER) {
MOZ_ASSERT(false, "This is allowed only to be called at controller side.");
return;
}
if (!aConnection) {
return;
}
WeakPtr<PresentationConnection> connection = aConnection;
if (mConnections.Contains(connection)) {
return;
}
mConnections.AppendElement(connection);
}
void
ControllerConnectionCollection::RemoveConnection(
PresentationConnection* aConnection,
const uint8_t aRole)
{
MOZ_ASSERT(NS_IsMainThread());
if (aRole != nsIPresentationService::ROLE_CONTROLLER) {
MOZ_ASSERT(false, "This is allowed only to be called at controller side.");
return;
}
if (!aConnection) {
return;
}
WeakPtr<PresentationConnection> connection = aConnection;
mConnections.RemoveElement(connection);
}
already_AddRefed<PresentationConnection>
ControllerConnectionCollection::FindConnection(
uint64_t aWindowId,
const nsAString& aId,
const uint8_t aRole)
{
MOZ_ASSERT(NS_IsMainThread());
if (aRole != nsIPresentationService::ROLE_CONTROLLER) {
MOZ_ASSERT(false, "This is allowed only to be called at controller side.");
return nullptr;
}
// Loop backwards to allow removing elements in the loop.
for (int i = mConnections.Length() - 1; i >= 0; --i) {
WeakPtr<PresentationConnection> connection = mConnections[i];
if (!connection) {
// The connection was destroyed. Remove it from the list.
mConnections.RemoveElementAt(i);
continue;
}
if (connection->Equals(aWindowId, aId)) {
RefPtr<PresentationConnection> matchedConnection = connection.get();
return matchedConnection.forget();
}
}
return nullptr;
}
} // namespace dom
} // namespace mozilla

View file

@ -1,49 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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_ControllerConnectionCollection_h
#define mozilla_dom_ControllerConnectionCollection_h
#include "mozilla/StaticPtr.h"
#include "mozilla/WeakPtr.h"
#include "nsString.h"
#include "nsTArray.h"
namespace mozilla {
namespace dom {
class PresentationConnection;
class ControllerConnectionCollection final
{
public:
static ControllerConnectionCollection* GetSingleton();
void AddConnection(PresentationConnection* aConnection,
const uint8_t aRole);
void RemoveConnection(PresentationConnection* aConnection,
const uint8_t aRole);
already_AddRefed<PresentationConnection>
FindConnection(uint64_t aWindowId,
const nsAString& aId,
const uint8_t aRole);
private:
friend class StaticAutoPtr<ControllerConnectionCollection>;
ControllerConnectionCollection();
virtual ~ControllerConnectionCollection();
static StaticAutoPtr<ControllerConnectionCollection> sSingleton;
nsTArray<WeakPtr<PresentationConnection>> mConnections;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_ControllerConnectionCollection_h

View file

@ -1,46 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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/. */
#include "DCPresentationChannelDescription.h"
namespace mozilla {
namespace dom {
NS_IMPL_ISUPPORTS(DCPresentationChannelDescription,
nsIPresentationChannelDescription)
NS_IMETHODIMP
DCPresentationChannelDescription::GetType(uint8_t* aRetVal)
{
if (NS_WARN_IF(!aRetVal)) {
return NS_ERROR_INVALID_POINTER;
}
*aRetVal = nsIPresentationChannelDescription::TYPE_DATACHANNEL;
return NS_OK;
}
NS_IMETHODIMP
DCPresentationChannelDescription::GetTcpAddress(nsIArray** aRetVal)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
DCPresentationChannelDescription::GetTcpPort(uint16_t* aRetVal)
{
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
DCPresentationChannelDescription::GetDataChannelSDP(nsAString& aDataChannelSDP)
{
aDataChannelSDP = mSDP;
return NS_OK;
}
} // namespace dom
} // namespace mozilla

View file

@ -1,37 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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_DCPresentationChannelDescription_h
#define mozilla_dom_DCPresentationChannelDescription_h
#include "nsIPresentationControlChannel.h"
#include "nsString.h"
namespace mozilla {
namespace dom {
// PresentationChannelDescription for Data Channel
class DCPresentationChannelDescription final : public nsIPresentationChannelDescription
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIPRESENTATIONCHANNELDESCRIPTION
explicit DCPresentationChannelDescription(const nsAString& aSDP)
: mSDP(aSDP)
{
}
private:
virtual ~DCPresentationChannelDescription() = default;
nsString mSDP;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_DCPresentationChannelDescription_h

View file

@ -1,182 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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/. */
#include "Presentation.h"
#include <ctype.h>
#include "mozilla/dom/PresentationBinding.h"
#include "mozilla/dom/Promise.h"
#include "nsContentUtils.h"
#include "nsCycleCollectionParticipant.h"
#include "nsIDocShell.h"
#include "nsIPresentationService.h"
#include "nsIScriptSecurityManager.h"
#include "nsJSUtils.h"
#include "nsNetUtil.h"
#include "nsPIDOMWindow.h"
#include "nsSandboxFlags.h"
#include "nsServiceManagerUtils.h"
#include "PresentationReceiver.h"
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(Presentation,
mWindow,
mDefaultRequest, mReceiver)
NS_IMPL_CYCLE_COLLECTING_ADDREF(Presentation)
NS_IMPL_CYCLE_COLLECTING_RELEASE(Presentation)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Presentation)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
/* static */ already_AddRefed<Presentation>
Presentation::Create(nsPIDOMWindowInner* aWindow)
{
RefPtr<Presentation> presentation = new Presentation(aWindow);
return presentation.forget();
}
Presentation::Presentation(nsPIDOMWindowInner* aWindow)
: mWindow(aWindow)
{
}
Presentation::~Presentation()
{
}
/* virtual */ JSObject*
Presentation::WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto)
{
return PresentationBinding::Wrap(aCx, this, aGivenProto);
}
void
Presentation::SetDefaultRequest(PresentationRequest* aRequest)
{
nsCOMPtr<nsIDocument> doc = mWindow ? mWindow->GetExtantDoc() : nullptr;
if (NS_WARN_IF(!doc)) {
return;
}
if (doc->GetSandboxFlags() & SANDBOXED_PRESENTATION) {
return;
}
mDefaultRequest = aRequest;
}
already_AddRefed<PresentationRequest>
Presentation::GetDefaultRequest() const
{
RefPtr<PresentationRequest> request = mDefaultRequest;
return request.forget();
}
already_AddRefed<PresentationReceiver>
Presentation::GetReceiver()
{
// return the same receiver if already created
if (mReceiver) {
RefPtr<PresentationReceiver> receiver = mReceiver;
return receiver.forget();
}
if (!HasReceiverSupport() || !IsInPresentedContent()) {
return nullptr;
}
mReceiver = PresentationReceiver::Create(mWindow);
if (NS_WARN_IF(!mReceiver)) {
MOZ_ASSERT(mReceiver);
return nullptr;
}
RefPtr<PresentationReceiver> receiver = mReceiver;
return receiver.forget();
}
void
Presentation::SetStartSessionUnsettled(bool aIsUnsettled)
{
mStartSessionUnsettled = aIsUnsettled;
}
bool
Presentation::IsStartSessionUnsettled() const
{
return mStartSessionUnsettled;
}
bool
Presentation::HasReceiverSupport() const
{
if (!mWindow) {
return false;
}
// Grant access to browser receiving pages and their same-origin iframes. (App
// pages should be controlled by "presentation" permission in app manifests.)
nsCOMPtr<nsIDocShell> docShell = mWindow->GetDocShell();
if (!docShell) {
return false;
}
if (!Preferences::GetBool("dom.presentation.testing.simulate-receiver") &&
!docShell->GetIsInMozBrowserOrApp() &&
!docShell->GetIsTopLevelContentDocShell()) {
return false;
}
nsAutoString presentationURL;
nsContentUtils::GetPresentationURL(docShell, presentationURL);
if (presentationURL.IsEmpty()) {
return false;
}
nsCOMPtr<nsIScriptSecurityManager> securityManager =
nsContentUtils::GetSecurityManager();
if (!securityManager) {
return false;
}
nsCOMPtr<nsIURI> presentationURI;
nsresult rv = NS_NewURI(getter_AddRefs(presentationURI), presentationURL);
if (NS_FAILED(rv)) {
return false;
}
nsCOMPtr<nsIURI> docURI = mWindow->GetDocumentURI();
return NS_SUCCEEDED(securityManager->CheckSameOriginURI(presentationURI,
docURI,
false));
}
bool
Presentation::IsInPresentedContent() const
{
if (!mWindow) {
return false;
}
nsCOMPtr<nsIDocShell> docShell = mWindow->GetDocShell();
MOZ_ASSERT(docShell);
nsAutoString presentationURL;
nsContentUtils::GetPresentationURL(docShell, presentationURL);
return !presentationURL.IsEmpty();
}
} // namespace dom
} // namespace mozilla

View file

@ -1,70 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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_Presentation_h
#define mozilla_dom_Presentation_h
#include "nsCOMPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsISupportsImpl.h"
#include "nsWrapperCache.h"
class nsPIDOMWindowInner;
namespace mozilla {
namespace dom {
class Promise;
class PresentationReceiver;
class PresentationRequest;
class Presentation final : public nsISupports
, public nsWrapperCache
{
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Presentation)
static already_AddRefed<Presentation> Create(nsPIDOMWindowInner* aWindow);
virtual JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
nsPIDOMWindowInner* GetParentObject() const
{
return mWindow;
}
// WebIDL (public APIs)
void SetDefaultRequest(PresentationRequest* aRequest);
already_AddRefed<PresentationRequest> GetDefaultRequest() const;
already_AddRefed<PresentationReceiver> GetReceiver();
// For bookkeeping unsettled start session request
void SetStartSessionUnsettled(bool aIsUnsettled);
bool IsStartSessionUnsettled() const;
private:
explicit Presentation(nsPIDOMWindowInner* aWindow);
virtual ~Presentation();
bool HasReceiverSupport() const;
bool IsInPresentedContent() const;
RefPtr<PresentationRequest> mDefaultRequest;
RefPtr<PresentationReceiver> mReceiver;
nsCOMPtr<nsPIDOMWindowInner> mWindow;
bool mStartSessionUnsettled = false;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_Presentation_h

View file

@ -1,206 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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/. */
#include "PresentationAvailability.h"
#include "mozilla/dom/PresentationAvailabilityBinding.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/Unused.h"
#include "nsCycleCollectionParticipant.h"
#include "nsIPresentationDeviceManager.h"
#include "nsIPresentationService.h"
#include "nsServiceManagerUtils.h"
#include "PresentationLog.h"
using namespace mozilla;
using namespace mozilla::dom;
NS_IMPL_CYCLE_COLLECTION_CLASS(PresentationAvailability)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(PresentationAvailability, DOMEventTargetHelper)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPromises)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(PresentationAvailability, DOMEventTargetHelper)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPromises);
tmp->Shutdown();
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_ADDREF_INHERITED(PresentationAvailability, DOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(PresentationAvailability, DOMEventTargetHelper)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(PresentationAvailability)
NS_INTERFACE_MAP_ENTRY(nsIPresentationAvailabilityListener)
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
/* static */ already_AddRefed<PresentationAvailability>
PresentationAvailability::Create(nsPIDOMWindowInner* aWindow,
const nsTArray<nsString>& aUrls,
RefPtr<Promise>& aPromise)
{
RefPtr<PresentationAvailability> availability =
new PresentationAvailability(aWindow, aUrls);
return NS_WARN_IF(!availability->Init(aPromise)) ? nullptr
: availability.forget();
}
PresentationAvailability::PresentationAvailability(nsPIDOMWindowInner* aWindow,
const nsTArray<nsString>& aUrls)
: DOMEventTargetHelper(aWindow)
, mIsAvailable(false)
, mUrls(aUrls)
{
for (uint32_t i = 0; i < mUrls.Length(); ++i) {
mAvailabilityOfUrl.AppendElement(false);
}
}
PresentationAvailability::~PresentationAvailability()
{
Shutdown();
}
bool
PresentationAvailability::Init(RefPtr<Promise>& aPromise)
{
nsCOMPtr<nsIPresentationService> service =
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
if (NS_WARN_IF(!service)) {
return false;
}
nsresult rv = service->RegisterAvailabilityListener(mUrls, this);
if (NS_WARN_IF(NS_FAILED(rv))) {
// If the user agent is unable to monitor available device,
// Resolve promise with |value| set to false.
mIsAvailable = false;
aPromise->MaybeResolve(this);
return true;
}
EnqueuePromise(aPromise);
AvailabilityCollection* collection = AvailabilityCollection::GetSingleton();
if (collection) {
collection->Add(this);
}
return true;
}
void PresentationAvailability::Shutdown()
{
AvailabilityCollection* collection = AvailabilityCollection::GetSingleton();
if (collection ) {
collection->Remove(this);
}
nsCOMPtr<nsIPresentationService> service =
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
if (NS_WARN_IF(!service)) {
return;
}
Unused <<
NS_WARN_IF(NS_FAILED(service->UnregisterAvailabilityListener(mUrls,
this)));
}
/* virtual */ void
PresentationAvailability::DisconnectFromOwner()
{
Shutdown();
DOMEventTargetHelper::DisconnectFromOwner();
}
/* virtual */ JSObject*
PresentationAvailability::WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto)
{
return PresentationAvailabilityBinding::Wrap(aCx, this, aGivenProto);
}
bool
PresentationAvailability::Equals(const uint64_t aWindowID,
const nsTArray<nsString>& aUrls) const
{
if (GetOwner() && GetOwner()->WindowID() == aWindowID &&
mUrls.Length() == aUrls.Length()) {
for (const auto& url : aUrls) {
if (!mUrls.Contains(url)) {
return false;
}
}
return true;
}
return false;
}
bool
PresentationAvailability::IsCachedValueReady()
{
// All pending promises will be solved when cached value is ready and
// no promise should be enqueued afterward.
return mPromises.IsEmpty();
}
void
PresentationAvailability::EnqueuePromise(RefPtr<Promise>& aPromise)
{
mPromises.AppendElement(aPromise);
}
bool
PresentationAvailability::Value() const
{
return mIsAvailable;
}
NS_IMETHODIMP
PresentationAvailability::NotifyAvailableChange(const nsTArray<nsString>& aAvailabilityUrls,
bool aIsAvailable)
{
bool available = false;
for (uint32_t i = 0; i < mUrls.Length(); ++i) {
if (aAvailabilityUrls.Contains(mUrls[i])) {
mAvailabilityOfUrl[i] = aIsAvailable;
}
available |= mAvailabilityOfUrl[i];
}
return NS_DispatchToCurrentThread(NewRunnableMethod
<bool>(this,
&PresentationAvailability::UpdateAvailabilityAndDispatchEvent,
available));
}
void
PresentationAvailability::UpdateAvailabilityAndDispatchEvent(bool aIsAvailable)
{
PRES_DEBUG("%s\n", __func__);
bool isChanged = (aIsAvailable != mIsAvailable);
mIsAvailable = aIsAvailable;
if (!mPromises.IsEmpty()) {
// Use the first availability change notification to resolve promise.
do {
nsTArray<RefPtr<Promise>> promises = Move(mPromises);
for (auto& promise : promises) {
promise->MaybeResolve(this);
}
// more promises may have been added to mPromises, at least in theory
} while (!mPromises.IsEmpty());
return;
}
if (isChanged) {
Unused <<
NS_WARN_IF(NS_FAILED(DispatchTrustedEvent(NS_LITERAL_STRING("change"))));
}
}

View file

@ -1,74 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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_PresentationAvailability_h
#define mozilla_dom_PresentationAvailability_h
#include "mozilla/DOMEventTargetHelper.h"
#include "nsIPresentationListener.h"
#include "nsTArray.h"
namespace mozilla {
namespace dom {
class Promise;
class PresentationAvailability final : public DOMEventTargetHelper
, public nsIPresentationAvailabilityListener
, public SupportsWeakPtr<PresentationAvailability>
{
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PresentationAvailability,
DOMEventTargetHelper)
NS_DECL_NSIPRESENTATIONAVAILABILITYLISTENER
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(PresentationAvailability)
static already_AddRefed<PresentationAvailability>
Create(nsPIDOMWindowInner* aWindow,
const nsTArray<nsString>& aUrls,
RefPtr<Promise>& aPromise);
virtual void DisconnectFromOwner() override;
virtual JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
bool Equals(const uint64_t aWindowID, const nsTArray<nsString>& aUrls) const;
bool IsCachedValueReady();
void EnqueuePromise(RefPtr<Promise>& aPromise);
// WebIDL (public APIs)
bool Value() const;
IMPL_EVENT_HANDLER(change);
private:
explicit PresentationAvailability(nsPIDOMWindowInner* aWindow,
const nsTArray<nsString>& aUrls);
virtual ~PresentationAvailability();
bool Init(RefPtr<Promise>& aPromise);
void Shutdown();
void UpdateAvailabilityAndDispatchEvent(bool aIsAvailable);
bool mIsAvailable;
nsTArray<RefPtr<Promise>> mPromises;
nsTArray<nsString> mUrls;
nsTArray<bool> mAvailabilityOfUrl;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_PresentationAvailability_h

View file

@ -1,282 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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/. */
#include "mozilla/dom/Promise.h"
#include "nsIDocShell.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIPresentationService.h"
#include "nsIWebProgress.h"
#include "nsServiceManagerUtils.h"
#include "nsThreadUtils.h"
#include "PresentationCallbacks.h"
#include "PresentationRequest.h"
#include "PresentationConnection.h"
#include "PresentationTransportBuilderConstructor.h"
using namespace mozilla;
using namespace mozilla::dom;
/*
* Implementation of PresentationRequesterCallback
*/
NS_IMPL_ISUPPORTS(PresentationRequesterCallback, nsIPresentationServiceCallback)
PresentationRequesterCallback::PresentationRequesterCallback(PresentationRequest* aRequest,
const nsAString& aSessionId,
Promise* aPromise)
: mRequest(aRequest)
, mSessionId(aSessionId)
, mPromise(aPromise)
{
MOZ_ASSERT(mRequest);
MOZ_ASSERT(mPromise);
MOZ_ASSERT(!mSessionId.IsEmpty());
}
PresentationRequesterCallback::~PresentationRequesterCallback()
{
}
// nsIPresentationServiceCallback
NS_IMETHODIMP
PresentationRequesterCallback::NotifySuccess(const nsAString& aUrl)
{
MOZ_ASSERT(NS_IsMainThread());
if (aUrl.IsEmpty()) {
return NotifyError(NS_ERROR_DOM_OPERATION_ERR);
}
RefPtr<PresentationConnection> connection =
PresentationConnection::Create(mRequest->GetOwner(), mSessionId, aUrl,
nsIPresentationService::ROLE_CONTROLLER);
if (NS_WARN_IF(!connection)) {
return NotifyError(NS_ERROR_DOM_OPERATION_ERR);
}
mRequest->NotifyPromiseSettled();
mPromise->MaybeResolve(connection);
return mRequest->DispatchConnectionAvailableEvent(connection);
}
NS_IMETHODIMP
PresentationRequesterCallback::NotifyError(nsresult aError)
{
MOZ_ASSERT(NS_IsMainThread());
mRequest->NotifyPromiseSettled();
mPromise->MaybeReject(aError);
return NS_OK;
}
/*
* Implementation of PresentationRequesterCallback
*/
NS_IMPL_ISUPPORTS_INHERITED0(PresentationReconnectCallback,
PresentationRequesterCallback)
PresentationReconnectCallback::PresentationReconnectCallback(
PresentationRequest* aRequest,
const nsAString& aSessionId,
Promise* aPromise,
PresentationConnection* aConnection)
: PresentationRequesterCallback(aRequest, aSessionId, aPromise)
, mConnection(aConnection)
{
}
PresentationReconnectCallback::~PresentationReconnectCallback()
{
}
NS_IMETHODIMP
PresentationReconnectCallback::NotifySuccess(const nsAString& aUrl)
{
MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIPresentationService> service =
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
if (NS_WARN_IF(!service)) {
return NS_ERROR_NOT_AVAILABLE;
}
nsresult rv = NS_OK;
// We found a matched connection with the same window ID, URL, and
// the session ID. Resolve the promise with this connection and dispatch
// the event.
if (mConnection) {
mConnection->NotifyStateChange(
mSessionId,
nsIPresentationSessionListener::STATE_CONNECTING,
NS_OK);
mPromise->MaybeResolve(mConnection);
rv = mRequest->DispatchConnectionAvailableEvent(mConnection);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
} else {
// Use |PresentationRequesterCallback::NotifySuccess| to create a new
// connection since we don't find one that can be reused.
rv = PresentationRequesterCallback::NotifySuccess(aUrl);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = service->UpdateWindowIdBySessionId(mSessionId,
nsIPresentationService::ROLE_CONTROLLER,
mRequest->GetOwner()->WindowID());
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
}
nsString sessionId = nsString(mSessionId);
return NS_DispatchToMainThread(
NS_NewRunnableFunction([sessionId, service]() -> void {
service->BuildTransport(sessionId,
nsIPresentationService::ROLE_CONTROLLER);
}));
}
NS_IMETHODIMP
PresentationReconnectCallback::NotifyError(nsresult aError)
{
if (mConnection) {
mConnection->NotifyStateChange(
mSessionId,
nsIPresentationSessionListener::STATE_CLOSED,
aError);
}
return PresentationRequesterCallback::NotifyError(aError);
}
NS_IMPL_ISUPPORTS(PresentationResponderLoadingCallback,
nsIWebProgressListener,
nsISupportsWeakReference)
PresentationResponderLoadingCallback::PresentationResponderLoadingCallback(const nsAString& aSessionId)
: mSessionId(aSessionId)
{
}
PresentationResponderLoadingCallback::~PresentationResponderLoadingCallback()
{
if (mProgress) {
mProgress->RemoveProgressListener(this);
mProgress = nullptr;
}
}
nsresult
PresentationResponderLoadingCallback::Init(nsIDocShell* aDocShell)
{
mProgress = do_GetInterface(aDocShell);
if (NS_WARN_IF(!mProgress)) {
return NS_ERROR_NOT_AVAILABLE;
}
uint32_t busyFlags = nsIDocShell::BUSY_FLAGS_NONE;
nsresult rv = aDocShell->GetBusyFlags(&busyFlags);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
if ((busyFlags == nsIDocShell::BUSY_FLAGS_NONE) ||
(busyFlags & nsIDocShell::BUSY_FLAGS_PAGE_LOADING)) {
// The docshell has finished loading or is receiving data (|STATE_TRANSFERRING|
// has already been fired), so the page is ready for presentation use.
return NotifyReceiverReady(/* isLoading = */ true);
}
// Start to listen to document state change event |STATE_TRANSFERRING|.
return mProgress->AddProgressListener(this, nsIWebProgress::NOTIFY_STATE_DOCUMENT);
}
nsresult
PresentationResponderLoadingCallback::NotifyReceiverReady(bool aIsLoading)
{
nsCOMPtr<nsPIDOMWindowOuter> window = do_GetInterface(mProgress);
if (NS_WARN_IF(!window || !window->GetCurrentInnerWindow())) {
return NS_ERROR_NOT_AVAILABLE;
}
uint64_t windowId = window->GetCurrentInnerWindow()->WindowID();
nsCOMPtr<nsIPresentationService> service =
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
if (NS_WARN_IF(!service)) {
return NS_ERROR_NOT_AVAILABLE;
}
nsCOMPtr<nsIPresentationTransportBuilderConstructor> constructor =
PresentationTransportBuilderConstructor::Create();
return service->NotifyReceiverReady(mSessionId,
windowId,aIsLoading,
constructor);
}
// nsIWebProgressListener
NS_IMETHODIMP
PresentationResponderLoadingCallback::OnStateChange(nsIWebProgress* aWebProgress,
nsIRequest* aRequest,
uint32_t aStateFlags,
nsresult aStatus)
{
MOZ_ASSERT(NS_IsMainThread());
if (aStateFlags & (nsIWebProgressListener::STATE_TRANSFERRING |
nsIWebProgressListener::STATE_STOP)) {
mProgress->RemoveProgressListener(this);
bool isLoading = aStateFlags & nsIWebProgressListener::STATE_TRANSFERRING;
return NotifyReceiverReady(isLoading);
}
return NS_OK;
}
NS_IMETHODIMP
PresentationResponderLoadingCallback::OnProgressChange(nsIWebProgress* aWebProgress,
nsIRequest* aRequest,
int32_t aCurSelfProgress,
int32_t aMaxSelfProgress,
int32_t aCurTotalProgress,
int32_t aMaxTotalProgress)
{
// Do nothing.
return NS_OK;
}
NS_IMETHODIMP
PresentationResponderLoadingCallback::OnLocationChange(nsIWebProgress* aWebProgress,
nsIRequest* aRequest,
nsIURI* aURI,
uint32_t aFlags)
{
// Do nothing.
return NS_OK;
}
NS_IMETHODIMP
PresentationResponderLoadingCallback::OnStatusChange(nsIWebProgress* aWebProgress,
nsIRequest* aRequest,
nsresult aStatus,
const char16_t* aMessage)
{
// Do nothing.
return NS_OK;
}
NS_IMETHODIMP
PresentationResponderLoadingCallback::OnSecurityChange(nsIWebProgress* aWebProgress,
nsIRequest* aRequest,
uint32_t state)
{
// Do nothing.
return NS_OK;
}

View file

@ -1,85 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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_PresentationCallbacks_h
#define mozilla_dom_PresentationCallbacks_h
#include "mozilla/RefPtr.h"
#include "nsCOMPtr.h"
#include "nsIPresentationService.h"
#include "nsIWebProgressListener.h"
#include "nsString.h"
#include "nsWeakReference.h"
class nsIDocShell;
class nsIWebProgress;
namespace mozilla {
namespace dom {
class PresentationConnection;
class PresentationRequest;
class Promise;
class PresentationRequesterCallback : public nsIPresentationServiceCallback
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIPRESENTATIONSERVICECALLBACK
PresentationRequesterCallback(PresentationRequest* aRequest,
const nsAString& aSessionId,
Promise* aPromise);
protected:
virtual ~PresentationRequesterCallback();
RefPtr<PresentationRequest> mRequest;
nsString mSessionId;
RefPtr<Promise> mPromise;
};
class PresentationReconnectCallback final : public PresentationRequesterCallback
{
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIPRESENTATIONSERVICECALLBACK
PresentationReconnectCallback(PresentationRequest* aRequest,
const nsAString& aSessionId,
Promise* aPromise,
PresentationConnection* aConnection);
private:
virtual ~PresentationReconnectCallback();
RefPtr<PresentationConnection> mConnection;
};
class PresentationResponderLoadingCallback final : public nsIWebProgressListener
, public nsSupportsWeakReference
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIWEBPROGRESSLISTENER
explicit PresentationResponderLoadingCallback(const nsAString& aSessionId);
nsresult Init(nsIDocShell* aDocShell);
private:
~PresentationResponderLoadingCallback();
nsresult NotifyReceiverReady(bool aIsLoading);
nsString mSessionId;
nsCOMPtr<nsIWebProgress> mProgress;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_PresentationCallbacks_h

View file

@ -1,763 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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/. */
#include "PresentationConnection.h"
#include "ControllerConnectionCollection.h"
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/dom/DOMException.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/MessageEvent.h"
#include "mozilla/dom/MessageEventBinding.h"
#include "mozilla/dom/PresentationConnectionCloseEvent.h"
#include "mozilla/ErrorNames.h"
#include "mozilla/DebugOnly.h"
#include "nsContentUtils.h"
#include "nsCycleCollectionParticipant.h"
#include "nsIPresentationService.h"
#include "nsServiceManagerUtils.h"
#include "nsStringStream.h"
#include "PresentationConnectionList.h"
#include "PresentationLog.h"
using namespace mozilla;
using namespace mozilla::dom;
NS_IMPL_CYCLE_COLLECTION_CLASS(PresentationConnection)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(PresentationConnection, DOMEventTargetHelper)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOwningConnectionList)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(PresentationConnection, DOMEventTargetHelper)
tmp->Shutdown();
NS_IMPL_CYCLE_COLLECTION_UNLINK(mOwningConnectionList)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_ADDREF_INHERITED(PresentationConnection, DOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(PresentationConnection, DOMEventTargetHelper)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(PresentationConnection)
NS_INTERFACE_MAP_ENTRY(nsIPresentationSessionListener)
NS_INTERFACE_MAP_ENTRY(nsIRequest)
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
PresentationConnection::PresentationConnection(nsPIDOMWindowInner* aWindow,
const nsAString& aId,
const nsAString& aUrl,
const uint8_t aRole,
PresentationConnectionList* aList)
: DOMEventTargetHelper(aWindow)
, mId(aId)
, mUrl(aUrl)
, mState(PresentationConnectionState::Connecting)
, mOwningConnectionList(aList)
, mBinaryType(PresentationConnectionBinaryType::Arraybuffer)
{
MOZ_ASSERT(aRole == nsIPresentationService::ROLE_CONTROLLER ||
aRole == nsIPresentationService::ROLE_RECEIVER);
mRole = aRole;
}
/* virtual */ PresentationConnection::~PresentationConnection()
{
}
/* static */ already_AddRefed<PresentationConnection>
PresentationConnection::Create(nsPIDOMWindowInner* aWindow,
const nsAString& aId,
const nsAString& aUrl,
const uint8_t aRole,
PresentationConnectionList* aList)
{
MOZ_ASSERT(aRole == nsIPresentationService::ROLE_CONTROLLER ||
aRole == nsIPresentationService::ROLE_RECEIVER);
RefPtr<PresentationConnection> connection =
new PresentationConnection(aWindow, aId, aUrl, aRole, aList);
if (NS_WARN_IF(!connection->Init())) {
return nullptr;
}
if (aRole == nsIPresentationService::ROLE_CONTROLLER) {
ControllerConnectionCollection::GetSingleton()->AddConnection(connection,
aRole);
}
return connection.forget();
}
bool
PresentationConnection::Init()
{
if (NS_WARN_IF(mId.IsEmpty())) {
return false;
}
nsCOMPtr<nsIPresentationService> service =
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
if(NS_WARN_IF(!service)) {
return false;
}
nsresult rv = service->RegisterSessionListener(mId, mRole, this);
if(NS_WARN_IF(NS_FAILED(rv))) {
return false;
}
rv = AddIntoLoadGroup();
if(NS_WARN_IF(NS_FAILED(rv))) {
return false;
}
return true;
}
void
PresentationConnection::Shutdown()
{
PRES_DEBUG("connection shutdown:id[%s], role[%d]\n",
NS_ConvertUTF16toUTF8(mId).get(), mRole);
nsCOMPtr<nsIPresentationService> service =
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
if (NS_WARN_IF(!service)) {
return;
}
DebugOnly<nsresult> rv = service->UnregisterSessionListener(mId, mRole);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "UnregisterSessionListener failed");
DebugOnly<nsresult> rv2 = RemoveFromLoadGroup();
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv2), "RemoveFromLoadGroup failed");
if (mRole == nsIPresentationService::ROLE_CONTROLLER) {
ControllerConnectionCollection::GetSingleton()->RemoveConnection(this,
mRole);
}
}
/* virtual */ void
PresentationConnection::DisconnectFromOwner()
{
Unused << NS_WARN_IF(NS_FAILED(ProcessConnectionWentAway()));
DOMEventTargetHelper::DisconnectFromOwner();
}
/* virtual */ JSObject*
PresentationConnection::WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto)
{
return PresentationConnectionBinding::Wrap(aCx, this, aGivenProto);
}
void
PresentationConnection::GetId(nsAString& aId) const
{
aId = mId;
}
void
PresentationConnection::GetUrl(nsAString& aUrl) const
{
aUrl = mUrl;
}
PresentationConnectionState
PresentationConnection::State() const
{
return mState;
}
PresentationConnectionBinaryType
PresentationConnection::BinaryType() const
{
return mBinaryType;
}
void
PresentationConnection::SetBinaryType(PresentationConnectionBinaryType aType)
{
mBinaryType = aType;
}
void
PresentationConnection::Send(const nsAString& aData,
ErrorResult& aRv)
{
// Sending is not allowed if the session is not connected.
if (NS_WARN_IF(mState != PresentationConnectionState::Connected)) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return;
}
nsCOMPtr<nsIPresentationService> service =
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
if(NS_WARN_IF(!service)) {
AsyncCloseConnectionWithErrorMsg(
NS_LITERAL_STRING("Unable to send message due to an internal error."));
return;
}
nsresult rv = service->SendSessionMessage(mId, mRole, aData);
if(NS_WARN_IF(NS_FAILED(rv))) {
const uint32_t kMaxMessageLength = 256;
nsAutoString data(Substring(aData, 0, kMaxMessageLength));
AsyncCloseConnectionWithErrorMsg(
NS_LITERAL_STRING("Unable to send message: \"") + data +
NS_LITERAL_STRING("\""));
}
}
void
PresentationConnection::Send(Blob& aData,
ErrorResult& aRv)
{
if (NS_WARN_IF(mState != PresentationConnectionState::Connected)) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return;
}
nsCOMPtr<nsIPresentationService> service =
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
if(NS_WARN_IF(!service)) {
AsyncCloseConnectionWithErrorMsg(
NS_LITERAL_STRING("Unable to send message due to an internal error."));
return;
}
nsresult rv = service->SendSessionBlob(mId, mRole, &aData);
if(NS_WARN_IF(NS_FAILED(rv))) {
AsyncCloseConnectionWithErrorMsg(
NS_LITERAL_STRING("Unable to send binary message for Blob message."));
}
}
void
PresentationConnection::Send(const ArrayBuffer& aData,
ErrorResult& aRv)
{
if (NS_WARN_IF(mState != PresentationConnectionState::Connected)) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return;
}
nsCOMPtr<nsIPresentationService> service =
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
if(NS_WARN_IF(!service)) {
AsyncCloseConnectionWithErrorMsg(
NS_LITERAL_STRING("Unable to send message due to an internal error."));
return;
}
aData.ComputeLengthAndData();
static_assert(sizeof(*aData.Data()) == 1, "byte-sized data required");
uint32_t length = aData.Length();
char* data = reinterpret_cast<char*>(aData.Data());
nsDependentCSubstring msgString(data, length);
nsresult rv = service->SendSessionBinaryMsg(mId, mRole, msgString);
if(NS_WARN_IF(NS_FAILED(rv))) {
AsyncCloseConnectionWithErrorMsg(
NS_LITERAL_STRING("Unable to send binary message for ArrayBuffer message."));
}
}
void
PresentationConnection::Send(const ArrayBufferView& aData,
ErrorResult& aRv)
{
if (NS_WARN_IF(mState != PresentationConnectionState::Connected)) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return;
}
nsCOMPtr<nsIPresentationService> service =
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
if(NS_WARN_IF(!service)) {
AsyncCloseConnectionWithErrorMsg(
NS_LITERAL_STRING("Unable to send message due to an internal error."));
return;
}
aData.ComputeLengthAndData();
static_assert(sizeof(*aData.Data()) == 1, "byte-sized data required");
uint32_t length = aData.Length();
char* data = reinterpret_cast<char*>(aData.Data());
nsDependentCSubstring msgString(data, length);
nsresult rv = service->SendSessionBinaryMsg(mId, mRole, msgString);
if(NS_WARN_IF(NS_FAILED(rv))) {
AsyncCloseConnectionWithErrorMsg(
NS_LITERAL_STRING("Unable to send binary message for ArrayBufferView message."));
}
}
void
PresentationConnection::Close(ErrorResult& aRv)
{
// It only works when the state is CONNECTED or CONNECTING.
if (NS_WARN_IF(mState != PresentationConnectionState::Connected &&
mState != PresentationConnectionState::Connecting)) {
return;
}
nsCOMPtr<nsIPresentationService> service =
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
if(NS_WARN_IF(!service)) {
aRv.Throw(NS_ERROR_DOM_OPERATION_ERR);
return;
}
Unused << NS_WARN_IF(NS_FAILED(
service->CloseSession(mId,
mRole,
nsIPresentationService::CLOSED_REASON_CLOSED)));
}
void
PresentationConnection::Terminate(ErrorResult& aRv)
{
// It only works when the state is CONNECTED.
if (NS_WARN_IF(mState != PresentationConnectionState::Connected)) {
return;
}
nsCOMPtr<nsIPresentationService> service =
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
if(NS_WARN_IF(!service)) {
aRv.Throw(NS_ERROR_DOM_OPERATION_ERR);
return;
}
Unused << NS_WARN_IF(NS_FAILED(service->TerminateSession(mId, mRole)));
}
bool
PresentationConnection::Equals(uint64_t aWindowId,
const nsAString& aId)
{
return GetOwner() &&
aWindowId == GetOwner()->WindowID() &&
mId.Equals(aId);
}
NS_IMETHODIMP
PresentationConnection::NotifyStateChange(const nsAString& aSessionId,
uint16_t aState,
nsresult aReason)
{
PRES_DEBUG("connection state change:id[%s], state[%x], reason[%x], role[%d]\n",
NS_ConvertUTF16toUTF8(aSessionId).get(), aState,
aReason, mRole);
if (!aSessionId.Equals(mId)) {
return NS_ERROR_INVALID_ARG;
}
// A terminated connection should always remain in terminated.
if (mState == PresentationConnectionState::Terminated) {
return NS_OK;
}
PresentationConnectionState state;
switch (aState) {
case nsIPresentationSessionListener::STATE_CONNECTING:
state = PresentationConnectionState::Connecting;
break;
case nsIPresentationSessionListener::STATE_CONNECTED:
state = PresentationConnectionState::Connected;
break;
case nsIPresentationSessionListener::STATE_CLOSED:
state = PresentationConnectionState::Closed;
break;
case nsIPresentationSessionListener::STATE_TERMINATED:
state = PresentationConnectionState::Terminated;
break;
default:
NS_WARNING("Unknown presentation session state.");
return NS_ERROR_INVALID_ARG;
}
if (mState == state) {
return NS_OK;
}
mState = state;
nsresult rv = ProcessStateChanged(aReason);
if(NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
if (mOwningConnectionList) {
mOwningConnectionList->NotifyStateChange(aSessionId, this);
}
return NS_OK;
}
nsresult
PresentationConnection::ProcessStateChanged(nsresult aReason)
{
switch (mState) {
case PresentationConnectionState::Connecting:
return NS_OK;
case PresentationConnectionState::Connected: {
RefPtr<AsyncEventDispatcher> asyncDispatcher =
new AsyncEventDispatcher(this, NS_LITERAL_STRING("connect"), false);
return asyncDispatcher->PostDOMEvent();
}
case PresentationConnectionState::Closed: {
PresentationConnectionClosedReason reason =
PresentationConnectionClosedReason::Closed;
nsString errorMsg;
if (NS_FAILED(aReason)) {
reason = PresentationConnectionClosedReason::Error;
nsCString name, message;
// If aReason is not a DOM error, use error name as message.
if (NS_FAILED(NS_GetNameAndMessageForDOMNSResult(aReason,
name,
message))) {
mozilla::GetErrorName(aReason, message);
message.InsertLiteral("Internal error: ", 0);
}
CopyUTF8toUTF16(message, errorMsg);
}
Unused <<
NS_WARN_IF(NS_FAILED(DispatchConnectionCloseEvent(reason, errorMsg)));
return RemoveFromLoadGroup();
}
case PresentationConnectionState::Terminated: {
// Ensure onterminate event is fired.
RefPtr<AsyncEventDispatcher> asyncDispatcher =
new AsyncEventDispatcher(this, NS_LITERAL_STRING("terminate"), false);
Unused << NS_WARN_IF(NS_FAILED(asyncDispatcher->PostDOMEvent()));
nsCOMPtr<nsIPresentationService> service =
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
if (NS_WARN_IF(!service)) {
return NS_ERROR_NOT_AVAILABLE;
}
nsresult rv = service->UnregisterSessionListener(mId, mRole);
if(NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return RemoveFromLoadGroup();
}
default:
MOZ_CRASH("Unknown presentation session state.");
return NS_ERROR_INVALID_ARG;
}
}
NS_IMETHODIMP
PresentationConnection::NotifyMessage(const nsAString& aSessionId,
const nsACString& aData,
bool aIsBinary)
{
PRES_DEBUG("connection %s:id[%s], data[%s], role[%d]\n", __func__,
NS_ConvertUTF16toUTF8(aSessionId).get(),
nsPromiseFlatCString(aData).get(), mRole);
if (!aSessionId.Equals(mId)) {
return NS_ERROR_INVALID_ARG;
}
// No message should be expected when the session is not connected.
if (NS_WARN_IF(mState != PresentationConnectionState::Connected)) {
return NS_ERROR_DOM_INVALID_STATE_ERR;
}
if (NS_WARN_IF(NS_FAILED(DoReceiveMessage(aData, aIsBinary)))) {
AsyncCloseConnectionWithErrorMsg(
NS_LITERAL_STRING("Unable to receive a message."));
return NS_ERROR_FAILURE;
}
return NS_OK;
}
nsresult
PresentationConnection::DoReceiveMessage(const nsACString& aData, bool aIsBinary)
{
// Transform the data.
AutoJSAPI jsapi;
if (!jsapi.Init(GetOwner())) {
return NS_ERROR_FAILURE;
}
JSContext* cx = jsapi.cx();
JS::Rooted<JS::Value> jsData(cx);
nsresult rv;
if (aIsBinary) {
if (mBinaryType == PresentationConnectionBinaryType::Blob) {
RefPtr<Blob> blob =
Blob::CreateStringBlob(GetOwner(), aData, EmptyString());
MOZ_ASSERT(blob);
if (!ToJSValue(cx, blob, &jsData)) {
return NS_ERROR_FAILURE;
}
} else if (mBinaryType == PresentationConnectionBinaryType::Arraybuffer) {
JS::Rooted<JSObject*> arrayBuf(cx);
rv = nsContentUtils::CreateArrayBuffer(cx, aData, arrayBuf.address());
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
jsData.setObject(*arrayBuf);
} else {
NS_RUNTIMEABORT("Unknown binary type!");
return NS_ERROR_UNEXPECTED;
}
} else {
NS_ConvertUTF8toUTF16 utf16Data(aData);
if(NS_WARN_IF(!ToJSValue(cx, utf16Data, &jsData))) {
return NS_ERROR_FAILURE;
}
}
return DispatchMessageEvent(jsData);
}
nsresult
PresentationConnection::DispatchConnectionCloseEvent(
PresentationConnectionClosedReason aReason,
const nsAString& aMessage,
bool aDispatchNow)
{
if (mState != PresentationConnectionState::Closed) {
MOZ_ASSERT(false, "The connection state should be closed.");
return NS_ERROR_FAILURE;
}
PresentationConnectionCloseEventInit init;
init.mReason = aReason;
init.mMessage = aMessage;
RefPtr<PresentationConnectionCloseEvent> closedEvent =
PresentationConnectionCloseEvent::Constructor(this,
NS_LITERAL_STRING("close"),
init);
closedEvent->SetTrusted(true);
if (aDispatchNow) {
bool ignore;
return DOMEventTargetHelper::DispatchEvent(closedEvent, &ignore);
}
RefPtr<AsyncEventDispatcher> asyncDispatcher =
new AsyncEventDispatcher(this, static_cast<Event*>(closedEvent));
return asyncDispatcher->PostDOMEvent();
}
nsresult
PresentationConnection::DispatchMessageEvent(JS::Handle<JS::Value> aData)
{
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
if (NS_WARN_IF(!global)) {
return NS_ERROR_NOT_AVAILABLE;
}
// Get the origin.
nsAutoString origin;
nsresult rv = nsContentUtils::GetUTFOrigin(global->PrincipalOrNull(), origin);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
RefPtr<MessageEvent> messageEvent = new MessageEvent(this, nullptr, nullptr);
messageEvent->InitMessageEvent(nullptr,
NS_LITERAL_STRING("message"),
false, false, aData, origin,
EmptyString(), nullptr,
Sequence<OwningNonNull<MessagePort>>());
messageEvent->SetTrusted(true);
RefPtr<AsyncEventDispatcher> asyncDispatcher =
new AsyncEventDispatcher(this, static_cast<Event*>(messageEvent));
return asyncDispatcher->PostDOMEvent();
}
nsresult
PresentationConnection::ProcessConnectionWentAway()
{
if (mState != PresentationConnectionState::Connected &&
mState != PresentationConnectionState::Connecting) {
// If the state is not connected or connecting, do not need to
// close the session.
return NS_OK;
}
mState = PresentationConnectionState::Terminated;
nsCOMPtr<nsIPresentationService> service =
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
if (NS_WARN_IF(!service)) {
return NS_ERROR_NOT_AVAILABLE;
}
return service->CloseSession(
mId, mRole, nsIPresentationService::CLOSED_REASON_WENTAWAY);
}
NS_IMETHODIMP
PresentationConnection::GetName(nsACString &aResult)
{
aResult.AssignLiteral("about:presentation-connection");
return NS_OK;
}
NS_IMETHODIMP
PresentationConnection::IsPending(bool* aRetval)
{
*aRetval = true;
return NS_OK;
}
NS_IMETHODIMP
PresentationConnection::GetStatus(nsresult* aStatus)
{
*aStatus = NS_OK;
return NS_OK;
}
NS_IMETHODIMP
PresentationConnection::Cancel(nsresult aStatus)
{
nsCOMPtr<nsIRunnable> event =
NewRunnableMethod(this, &PresentationConnection::ProcessConnectionWentAway);
return NS_DispatchToCurrentThread(event);
}
NS_IMETHODIMP
PresentationConnection::Suspend(void)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
PresentationConnection::Resume(void)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
PresentationConnection::GetLoadGroup(nsILoadGroup** aLoadGroup)
{
*aLoadGroup = nullptr;
nsCOMPtr<nsIDocument> doc = GetOwner() ? GetOwner()->GetExtantDoc() : nullptr;
if (!doc) {
return NS_ERROR_FAILURE;
}
*aLoadGroup = doc->GetDocumentLoadGroup().take();
return NS_OK;
}
NS_IMETHODIMP
PresentationConnection::SetLoadGroup(nsILoadGroup * aLoadGroup)
{
return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
PresentationConnection::GetLoadFlags(nsLoadFlags* aLoadFlags)
{
*aLoadFlags = nsIRequest::LOAD_BACKGROUND;
return NS_OK;
}
NS_IMETHODIMP
PresentationConnection::SetLoadFlags(nsLoadFlags aLoadFlags)
{
return NS_OK;
}
nsresult
PresentationConnection::AddIntoLoadGroup()
{
// Avoid adding to loadgroup multiple times
if (mWeakLoadGroup) {
return NS_OK;
}
nsCOMPtr<nsILoadGroup> loadGroup;
nsresult rv = GetLoadGroup(getter_AddRefs(loadGroup));
if(NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = loadGroup->AddRequest(this, nullptr);
if(NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
mWeakLoadGroup = do_GetWeakReference(loadGroup);
return NS_OK;
}
nsresult
PresentationConnection::RemoveFromLoadGroup()
{
if (!mWeakLoadGroup) {
return NS_OK;
}
nsCOMPtr<nsILoadGroup> loadGroup = do_QueryReferent(mWeakLoadGroup);
if (loadGroup) {
mWeakLoadGroup = nullptr;
return loadGroup->RemoveRequest(this, nullptr, NS_OK);
}
return NS_OK;
}
void
PresentationConnection::AsyncCloseConnectionWithErrorMsg(const nsAString& aMessage)
{
if (mState == PresentationConnectionState::Terminated) {
return;
}
nsString message = nsString(aMessage);
RefPtr<PresentationConnection> self = this;
nsCOMPtr<nsIRunnable> r =
NS_NewRunnableFunction([self, message]() -> void {
// Set |mState| to |PresentationConnectionState::Closed| here to avoid
// calling |ProcessStateChanged|.
self->mState = PresentationConnectionState::Closed;
// Make sure dispatching the event and closing the connection are invoked
// at the same time by setting |aDispatchNow| to true.
Unused << NS_WARN_IF(NS_FAILED(
self->DispatchConnectionCloseEvent(PresentationConnectionClosedReason::Error,
message,
true)));
nsCOMPtr<nsIPresentationService> service =
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
if(NS_WARN_IF(!service)) {
return;
}
Unused << NS_WARN_IF(NS_FAILED(
service->CloseSession(self->mId,
self->mRole,
nsIPresentationService::CLOSED_REASON_ERROR)));
});
Unused << NS_WARN_IF(NS_FAILED(NS_DispatchToMainThread(r)));
}

View file

@ -1,128 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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_PresentationConnection_h
#define mozilla_dom_PresentationConnection_h
#include "mozilla/DOMEventTargetHelper.h"
#include "mozilla/dom/TypedArray.h"
#include "mozilla/WeakPtr.h"
#include "mozilla/dom/PresentationConnectionBinding.h"
#include "mozilla/dom/PresentationConnectionCloseEventBinding.h"
#include "nsIPresentationListener.h"
#include "nsIRequest.h"
#include "nsWeakReference.h"
namespace mozilla {
namespace dom {
class Blob;
class PresentationConnectionList;
class PresentationConnection final : public DOMEventTargetHelper
, public nsIPresentationSessionListener
, public nsIRequest
, public SupportsWeakPtr<PresentationConnection>
{
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PresentationConnection,
DOMEventTargetHelper)
NS_DECL_NSIPRESENTATIONSESSIONLISTENER
NS_DECL_NSIREQUEST
MOZ_DECLARE_WEAKREFERENCE_TYPENAME(PresentationConnection)
static already_AddRefed<PresentationConnection>
Create(nsPIDOMWindowInner* aWindow,
const nsAString& aId,
const nsAString& aUrl,
const uint8_t aRole,
PresentationConnectionList* aList = nullptr);
virtual void DisconnectFromOwner() override;
virtual JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
// WebIDL (public APIs)
void GetId(nsAString& aId) const;
void GetUrl(nsAString& aUrl) const;
PresentationConnectionState State() const;
PresentationConnectionBinaryType BinaryType() const;
void SetBinaryType(PresentationConnectionBinaryType aType);
void Send(const nsAString& aData,
ErrorResult& aRv);
void Send(Blob& aData,
ErrorResult& aRv);
void Send(const ArrayBuffer& aData,
ErrorResult& aRv);
void Send(const ArrayBufferView& aData,
ErrorResult& aRv);
void Close(ErrorResult& aRv);
void Terminate(ErrorResult& aRv);
bool
Equals(uint64_t aWindowId, const nsAString& aId);
IMPL_EVENT_HANDLER(connect);
IMPL_EVENT_HANDLER(close);
IMPL_EVENT_HANDLER(terminate);
IMPL_EVENT_HANDLER(message);
private:
PresentationConnection(nsPIDOMWindowInner* aWindow,
const nsAString& aId,
const nsAString& aUrl,
const uint8_t aRole,
PresentationConnectionList* aList);
~PresentationConnection();
bool Init();
void Shutdown();
nsresult ProcessStateChanged(nsresult aReason);
nsresult DispatchConnectionCloseEvent(PresentationConnectionClosedReason aReason,
const nsAString& aMessage,
bool aDispatchNow = false);
nsresult DispatchMessageEvent(JS::Handle<JS::Value> aData);
nsresult ProcessConnectionWentAway();
nsresult AddIntoLoadGroup();
nsresult RemoveFromLoadGroup();
void AsyncCloseConnectionWithErrorMsg(const nsAString& aMessage);
nsresult DoReceiveMessage(const nsACString& aData, bool aIsBinary);
nsString mId;
nsString mUrl;
uint8_t mRole;
PresentationConnectionState mState;
RefPtr<PresentationConnectionList> mOwningConnectionList;
nsWeakPtr mWeakLoadGroup;
PresentationConnectionBinaryType mBinaryType;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_PresentationConnection_h

View file

@ -1,125 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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/. */
#include "PresentationConnectionList.h"
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/dom/PresentationConnectionAvailableEvent.h"
#include "mozilla/dom/PresentationConnectionListBinding.h"
#include "mozilla/dom/Promise.h"
#include "PresentationConnection.h"
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_INHERITED(PresentationConnectionList, DOMEventTargetHelper,
mGetConnectionListPromise,
mConnections)
NS_IMPL_ADDREF_INHERITED(PresentationConnectionList, DOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(PresentationConnectionList, DOMEventTargetHelper)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(PresentationConnectionList)
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
PresentationConnectionList::PresentationConnectionList(nsPIDOMWindowInner* aWindow,
Promise* aPromise)
: DOMEventTargetHelper(aWindow)
, mGetConnectionListPromise(aPromise)
{
MOZ_ASSERT(aWindow);
MOZ_ASSERT(aPromise);
}
/* virtual */ JSObject*
PresentationConnectionList::WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto)
{
return PresentationConnectionListBinding::Wrap(aCx, this, aGivenProto);
}
void
PresentationConnectionList::GetConnections(
nsTArray<RefPtr<PresentationConnection>>& aConnections) const
{
aConnections = mConnections;
}
nsresult
PresentationConnectionList::DispatchConnectionAvailableEvent(
PresentationConnection* aConnection)
{
PresentationConnectionAvailableEventInit init;
init.mConnection = aConnection;
RefPtr<PresentationConnectionAvailableEvent> event =
PresentationConnectionAvailableEvent::Constructor(
this,
NS_LITERAL_STRING("connectionavailable"),
init);
if (NS_WARN_IF(!event)) {
return NS_ERROR_FAILURE;
}
event->SetTrusted(true);
RefPtr<AsyncEventDispatcher> asyncDispatcher =
new AsyncEventDispatcher(this, event);
return asyncDispatcher->PostDOMEvent();
}
PresentationConnectionList::ConnectionArrayIndex
PresentationConnectionList::FindConnectionById(
const nsAString& aId)
{
for (ConnectionArrayIndex i = 0; i < mConnections.Length(); i++) {
nsAutoString id;
mConnections[i]->GetId(id);
if (id == nsAutoString(aId)) {
return i;
}
}
return mConnections.NoIndex;
}
void
PresentationConnectionList::NotifyStateChange(const nsAString& aSessionId,
PresentationConnection* aConnection)
{
if (!aConnection) {
MOZ_ASSERT(false, "PresentationConnection can not be null.");
return;
}
bool connectionFound =
FindConnectionById(aSessionId) != mConnections.NoIndex ? true : false;
PresentationConnectionListBinding::ClearCachedConnectionsValue(this);
switch (aConnection->State()) {
case PresentationConnectionState::Connected:
if (!connectionFound) {
mConnections.AppendElement(aConnection);
if (mGetConnectionListPromise) {
mGetConnectionListPromise->MaybeResolve(this);
mGetConnectionListPromise = nullptr;
return;
}
}
DispatchConnectionAvailableEvent(aConnection);
break;
case PresentationConnectionState::Terminated:
if (connectionFound) {
mConnections.RemoveElement(aConnection);
}
break;
default:
break;
}
}
} // namespace dom
} // namespace mozilla

View file

@ -1,57 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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_PresentationConnectionList_h
#define mozilla_dom_PresentationConnectionList_h
#include "mozilla/DOMEventTargetHelper.h"
#include "nsTArray.h"
namespace mozilla {
namespace dom {
class PresentationConnection;
class Promise;
class PresentationConnectionList final : public DOMEventTargetHelper
{
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PresentationConnectionList,
DOMEventTargetHelper)
PresentationConnectionList(nsPIDOMWindowInner* aWindow,
Promise* aPromise);
virtual JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
void GetConnections(nsTArray<RefPtr<PresentationConnection>>& aConnections) const;
void NotifyStateChange(const nsAString& aSessionId, PresentationConnection* aConnection);
IMPL_EVENT_HANDLER(connectionavailable);
private:
virtual ~PresentationConnectionList() = default;
nsresult DispatchConnectionAvailableEvent(PresentationConnection* aConnection);
typedef nsTArray<RefPtr<PresentationConnection>> ConnectionArray;
typedef ConnectionArray::index_type ConnectionArrayIndex;
ConnectionArrayIndex FindConnectionById(const nsAString& aId);
RefPtr<Promise> mGetConnectionListPromise;
// This array stores only non-terminsted connections.
ConnectionArray mConnections;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_PresentationConnectionList_h

View file

@ -1,378 +0,0 @@
/* 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/. */
"use strict";
const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
// Bug 1228209 - plan to remove this eventually
function log(aMsg) {
//dump("-*- PresentationDataChannelSessionTransport.js : " + aMsg + "\n");
}
const PRESENTATIONTRANSPORT_CID = Components.ID("{dd2bbf2f-3399-4389-8f5f-d382afb8b2d6}");
const PRESENTATIONTRANSPORT_CONTRACTID = "mozilla.org/presentation/datachanneltransport;1";
const PRESENTATIONTRANSPORTBUILDER_CID = Components.ID("{215b2f62-46e2-4004-a3d1-6858e56c20f3}");
const PRESENTATIONTRANSPORTBUILDER_CONTRACTID = "mozilla.org/presentation/datachanneltransportbuilder;1";
function PresentationDataChannelDescription(aDataChannelSDP) {
this._dataChannelSDP = JSON.stringify(aDataChannelSDP);
}
PresentationDataChannelDescription.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIPresentationChannelDescription]),
get type() {
return Ci.nsIPresentationChannelDescription.TYPE_DATACHANNEL;
},
get tcpAddress() {
return null;
},
get tcpPort() {
return null;
},
get dataChannelSDP() {
return this._dataChannelSDP;
}
};
function PresentationTransportBuilder() {
log("PresentationTransportBuilder construct");
this._isControlChannelNeeded = true;
}
PresentationTransportBuilder.prototype = {
classID: PRESENTATIONTRANSPORTBUILDER_CID,
contractID: PRESENTATIONTRANSPORTBUILDER_CONTRACTID,
QueryInterface: XPCOMUtils.generateQI([Ci.nsIPresentationSessionTransportBuilder,
Ci.nsIPresentationDataChannelSessionTransportBuilder,
Ci.nsITimerCallback]),
buildDataChannelTransport: function(aRole, aWindow, aListener) {
if (!aRole || !aWindow || !aListener) {
log("buildDataChannelTransport with illegal parameters");
throw Cr.NS_ERROR_ILLEGAL_VALUE;
}
if (this._window) {
log("buildDataChannelTransport has started.");
throw Cr.NS_ERROR_UNEXPECTED;
}
log("buildDataChannelTransport with role " + aRole);
this._role = aRole;
this._window = aWindow;
this._listener = aListener.QueryInterface(Ci.nsIPresentationSessionTransportBuilderListener);
// TODO bug 1227053 set iceServers from |nsIPresentationDevice|
this._peerConnection = new this._window.RTCPeerConnection();
// |this._listener == null| will throw since the control channel is
// abnormally closed.
this._peerConnection.onicecandidate = aEvent => aEvent.candidate &&
this._listener.sendIceCandidate(JSON.stringify(aEvent.candidate));
this._peerConnection.onnegotiationneeded = () => {
log("onnegotiationneeded with role " + this._role);
if (!this._peerConnection) {
log("ignoring negotiationneeded without PeerConnection");
return;
}
this._peerConnection.createOffer()
.then(aOffer => this._peerConnection.setLocalDescription(aOffer))
.then(() => this._listener
.sendOffer(new PresentationDataChannelDescription(this._peerConnection.localDescription)))
.catch(e => this._reportError(e));
}
switch (this._role) {
case Ci.nsIPresentationService.ROLE_CONTROLLER:
this._dataChannel = this._peerConnection.createDataChannel("presentationAPI");
this._setDataChannel();
break;
case Ci.nsIPresentationService.ROLE_RECEIVER:
this._peerConnection.ondatachannel = aEvent => {
this._dataChannel = aEvent.channel;
// Ensure the binaryType of dataChannel is blob.
this._dataChannel.binaryType = "blob";
this._setDataChannel();
}
break;
default:
throw Cr.NS_ERROR_ILLEGAL_VALUE;
}
// TODO bug 1228235 we should have a way to let device providers customize
// the time-out duration.
let timeout = Services.prefs.getIntPref("presentation.receiver.loading.timeout", 10000);
// The timer is to check if the negotiation finishes on time.
this._timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
this._timer.initWithCallback(this, timeout, this._timer.TYPE_ONE_SHOT);
},
notify: function() {
if (!this._sessionTransport) {
this._cleanup(Cr.NS_ERROR_NET_TIMEOUT);
}
},
_reportError: function(aError) {
log("report Error " + aError.name + ":" + aError.message);
this._cleanup(Cr.NS_ERROR_FAILURE);
},
_setDataChannel: function() {
this._dataChannel.onopen = () => {
log("data channel is open, notify the listener, role " + this._role);
// Handoff the ownership of _peerConnection and _dataChannel to
// _sessionTransport
this._sessionTransport = new PresentationTransport();
this._sessionTransport.init(this._peerConnection, this._dataChannel, this._window);
this._peerConnection.onicecandidate = null;
this._peerConnection.onnegotiationneeded = null;
this._peerConnection = this._dataChannel = null;
this._listener.onSessionTransport(this._sessionTransport);
this._sessionTransport.callback.notifyTransportReady();
this._cleanup(Cr.NS_OK);
};
this._dataChannel.onerror = aError => {
log("data channel onerror " + aError.name + ":" + aError.message);
this._cleanup(Cr.NS_ERROR_FAILURE);
}
},
_cleanup: function(aReason) {
if (aReason != Cr.NS_OK) {
this._listener.onError(aReason);
}
if (this._dataChannel) {
this._dataChannel.close();
this._dataChannel = null;
}
if (this._peerConnection) {
this._peerConnection.close();
this._peerConnection = null;
}
this._role = null;
this._window = null;
this._listener = null;
this._sessionTransport = null;
if (this._timer) {
this._timer.cancel();
this._timer = null;
}
},
// nsIPresentationControlChannelListener
onOffer: function(aOffer) {
if (this._role !== Ci.nsIPresentationService.ROLE_RECEIVER ||
this._sessionTransport) {
log("onOffer status error");
this._cleanup(Cr.NS_ERROR_FAILURE);
}
log("onOffer: " + aOffer.dataChannelSDP + " with role " + this._role);
let offer = new this._window
.RTCSessionDescription(JSON.parse(aOffer.dataChannelSDP));
this._peerConnection.setRemoteDescription(offer)
.then(() => this._peerConnection.signalingState == "stable" ||
this._peerConnection.createAnswer())
.then(aAnswer => this._peerConnection.setLocalDescription(aAnswer))
.then(() => {
this._isControlChannelNeeded = false;
this._listener
.sendAnswer(new PresentationDataChannelDescription(this._peerConnection.localDescription))
}).catch(e => this._reportError(e));
},
onAnswer: function(aAnswer) {
if (this._role !== Ci.nsIPresentationService.ROLE_CONTROLLER ||
this._sessionTransport) {
log("onAnswer status error");
this._cleanup(Cr.NS_ERROR_FAILURE);
}
log("onAnswer: " + aAnswer.dataChannelSDP + " with role " + this._role);
let answer = new this._window
.RTCSessionDescription(JSON.parse(aAnswer.dataChannelSDP));
this._peerConnection.setRemoteDescription(answer).catch(e => this._reportError(e));
this._isControlChannelNeeded = false;
},
onIceCandidate: function(aCandidate) {
log("onIceCandidate: " + aCandidate + " with role " + this._role);
if (!this._window || !this._peerConnection) {
log("ignoring ICE candidate after connection");
return;
}
let candidate = new this._window.RTCIceCandidate(JSON.parse(aCandidate));
this._peerConnection.addIceCandidate(candidate).catch(e => this._reportError(e));
},
notifyDisconnected: function(aReason) {
log("notifyDisconnected reason: " + aReason);
if (aReason != Cr.NS_OK) {
this._cleanup(aReason);
} else if (this._isControlChannelNeeded) {
this._cleanup(Cr.NS_ERROR_FAILURE);
}
},
};
function PresentationTransport() {
this._messageQueue = [];
this._closeReason = Cr.NS_OK;
}
PresentationTransport.prototype = {
classID: PRESENTATIONTRANSPORT_CID,
contractID: PRESENTATIONTRANSPORT_CONTRACTID,
QueryInterface: XPCOMUtils.generateQI([Ci.nsIPresentationSessionTransport]),
init: function(aPeerConnection, aDataChannel, aWindow) {
log("initWithDataChannel");
this._enableDataNotification = false;
this._dataChannel = aDataChannel;
this._peerConnection = aPeerConnection;
this._window = aWindow;
this._dataChannel.onopen = () => {
log("data channel reopen. Should never touch here");
};
this._dataChannel.onclose = () => {
log("data channel onclose");
if (this._callback) {
this._callback.notifyTransportClosed(this._closeReason);
}
this._cleanup();
}
this._dataChannel.onmessage = aEvent => {
log("data channel onmessage " + aEvent.data);
if (!this._enableDataNotification || !this._callback) {
log("queue message");
this._messageQueue.push(aEvent.data);
return;
}
this._doNotifyData(aEvent.data);
};
this._dataChannel.onerror = aError => {
log("data channel onerror " + aError.name + ":" + aError.message);
if (this._callback) {
this._callback.notifyTransportClosed(Cr.NS_ERROR_FAILURE);
}
this._cleanup();
}
},
// nsIPresentationTransport
get selfAddress() {
throw NS_ERROR_NOT_AVAILABLE;
},
get callback() {
return this._callback;
},
set callback(aCallback) {
this._callback = aCallback;
},
send: function(aData) {
log("send " + aData);
this._dataChannel.send(aData);
},
sendBinaryMsg: function(aData) {
log("sendBinaryMsg");
let array = new Uint8Array(aData.length);
for (let i = 0; i < aData.length; i++) {
array[i] = aData.charCodeAt(i);
}
this._dataChannel.send(array);
},
sendBlob: function(aBlob) {
log("sendBlob");
this._dataChannel.send(aBlob);
},
enableDataNotification: function() {
log("enableDataNotification");
if (this._enableDataNotification) {
return;
}
if (!this._callback) {
throw NS_ERROR_NOT_AVAILABLE;
}
this._enableDataNotification = true;
this._messageQueue.forEach(aData => this._doNotifyData(aData));
this._messageQueue = [];
},
close: function(aReason) {
this._closeReason = aReason;
this._dataChannel.close();
},
_cleanup: function() {
this._dataChannel = null;
if (this._peerConnection) {
this._peerConnection.close();
this._peerConnection = null;
}
this._callback = null;
this._messageQueue = [];
this._window = null;
},
_doNotifyData: function(aData) {
if (!this._callback) {
throw NS_ERROR_NOT_AVAILABLE;
}
if (aData instanceof this._window.Blob) {
let reader = new this._window.FileReader();
reader.addEventListener("load", (aEvent) => {
this._callback.notifyData(aEvent.target.result, true);
});
reader.readAsBinaryString(aData);
} else {
this._callback.notifyData(aData, false);
}
},
};
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([PresentationTransportBuilder,
PresentationTransport]);

View file

@ -1,6 +0,0 @@
# PresentationDataChannelSessionTransport.js
component {dd2bbf2f-3399-4389-8f5f-d382afb8b2d6} PresentationDataChannelSessionTransport.js
contract @mozilla.org/presentation/datachanneltransport;1 {dd2bbf2f-3399-4389-8f5f-d382afb8b2d6}
component {215b2f62-46e2-4004-a3d1-6858e56c20f3} PresentationDataChannelSessionTransport.js
contract @mozilla.org/presentation/datachanneltransportbuilder;1 {215b2f62-46e2-4004-a3d1-6858e56c20f3}

View file

@ -1,119 +0,0 @@
/* 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/. */
"use strict";
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/DOMRequestHelper.jsm");
function log(aMsg) {
//dump("-*- PresentationDeviceInfoManager.js : " + aMsg + "\n");
}
const PRESENTATIONDEVICEINFOMANAGER_CID = Components.ID("{1bd66bef-f643-4be3-b690-0c656353eafd}");
const PRESENTATIONDEVICEINFOMANAGER_CONTRACTID = "@mozilla.org/presentation-device/deviceInfo;1";
XPCOMUtils.defineLazyServiceGetter(this, "cpmm",
"@mozilla.org/childprocessmessagemanager;1",
"nsIMessageSender");
function PresentationDeviceInfoManager() {}
PresentationDeviceInfoManager.prototype = {
__proto__: DOMRequestIpcHelper.prototype,
classID: PRESENTATIONDEVICEINFOMANAGER_CID,
contractID: PRESENTATIONDEVICEINFOMANAGER_CONTRACTID,
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupportsWeakReference,
Ci.nsIObserver,
Ci.nsIDOMGlobalPropertyInitializer]),
receiveMessage: function(aMsg) {
if (!aMsg || !aMsg.data) {
return;
}
let data = aMsg.data;
log("receive aMsg: " + aMsg.name);
switch (aMsg.name) {
case "PresentationDeviceInfoManager:OnDeviceChange": {
let detail = {
detail: {
type: data.type,
deviceInfo: data.deviceInfo,
}
};
let event = new this._window.CustomEvent("devicechange", Cu.cloneInto(detail, this._window));
this.__DOM_IMPL__.dispatchEvent(event);
break;
}
case "PresentationDeviceInfoManager:GetAll:Result:Ok": {
let resolver = this.takePromiseResolver(data.requestId);
if (!resolver) {
return;
}
resolver.resolve(Cu.cloneInto(data.devices, this._window));
break;
}
case "PresentationDeviceInfoManager:GetAll:Result:Error": {
let resolver = this.takePromiseResolver(data.requestId);
if (!resolver) {
return;
}
resolver.reject(data.error);
break;
}
}
},
init: function(aWin) {
log("init");
this.initDOMRequestHelper(aWin, [
{name: "PresentationDeviceInfoManager:OnDeviceChange", weakRef: true},
{name: "PresentationDeviceInfoManager:GetAll:Result:Ok", weakRef: true},
{name: "PresentationDeviceInfoManager:GetAll:Result:Error", weakRef: true},
]);
},
uninit: function() {
log("uninit");
let self = this;
this.forEachPromiseResolver(function(aKey) {
self.takePromiseResolver(aKey).reject("PresentationDeviceInfoManager got destroyed");
});
},
get ondevicechange() {
return this.__DOM_IMPL__.getEventHandler("ondevicechange");
},
set ondevicechange(aHandler) {
this.__DOM_IMPL__.setEventHandler("ondevicechange", aHandler);
},
getAll: function() {
log("getAll");
let self = this;
return this.createPromiseWithId(function(aResolverId) {
cpmm.sendAsyncMessage("PresentationDeviceInfoManager:GetAll", {
requestId: aResolverId,
});
});
},
forceDiscovery: function() {
cpmm.sendAsyncMessage("PresentationDeviceInfoManager:ForceDiscovery");
},
};
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([PresentationDeviceInfoManager]);

View file

@ -1,104 +0,0 @@
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- /
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
/* 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/. */
"use strict";
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
this.EXPORTED_SYMBOLS = ["PresentationDeviceInfoService"];
function log(aMsg) {
//dump("PresentationDeviceInfoManager.jsm: " + aMsg + "\n");
}
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
XPCOMUtils.defineLazyServiceGetter(this, "presentationDeviceManager",
"@mozilla.org/presentation-device/manager;1",
"nsIPresentationDeviceManager");
XPCOMUtils.defineLazyServiceGetter(this, "ppmm",
"@mozilla.org/parentprocessmessagemanager;1",
"nsIMessageBroadcaster");
this.PresentationDeviceInfoService = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIMessageListener,
Ci.nsIObserver]),
init: function() {
log("init");
ppmm.addMessageListener("PresentationDeviceInfoManager:GetAll", this);
ppmm.addMessageListener("PresentationDeviceInfoManager:ForceDiscovery", this);
Services.obs.addObserver(this, "presentation-device-change", false);
},
getAll: function(aData, aMm) {
log("getAll");
let deviceArray = presentationDeviceManager.getAvailableDevices().QueryInterface(Ci.nsIArray);
if (!deviceArray) {
aData.error = "DataError";
aMm.sendAsyncMessage("PresentationDeviceInfoManager:GetAll:Result:Error", aData);
return;
}
aData.devices = [];
for (let i = 0; i < deviceArray.length; i++) {
let device = deviceArray.queryElementAt(i, Ci.nsIPresentationDevice);
aData.devices.push({
id: device.id,
name: device.name,
type: device.type,
});
}
aMm.sendAsyncMessage("PresentationDeviceInfoManager:GetAll:Result:Ok", aData);
},
forceDiscovery: function() {
log("forceDiscovery");
presentationDeviceManager.forceDiscovery();
},
observe: function(aSubject, aTopic, aData) {
log("observe: " + aTopic);
let device = aSubject.QueryInterface(Ci.nsIPresentationDevice);
let data = {
type: aData,
deviceInfo: {
id: device.id,
name: device.name,
type: device.type,
},
};
ppmm.broadcastAsyncMessage("PresentationDeviceInfoManager:OnDeviceChange", data);
},
receiveMessage: function(aMessage) {
if (!aMessage.target.assertPermission("presentation-device-manage")) {
debug("receive message " + aMessage.name +
" from a content process with no 'presentation-device-manage' privileges.");
return null;
}
let msg = aMessage.data || {};
let mm = aMessage.target;
log("receiveMessage: " + aMessage.name);
switch (aMessage.name) {
case "PresentationDeviceInfoManager:GetAll": {
this.getAll(msg, mm);
break;
}
case "PresentationDeviceInfoManager:ForceDiscovery": {
this.forceDiscovery();
break;
}
}
},
};
this.PresentationDeviceInfoService.init();

View file

@ -1,3 +0,0 @@
# PresentationDeviceInfoManager.js
component {1bd66bef-f643-4be3-b690-0c656353eafd} PresentationDeviceInfoManager.js
contract @mozilla.org/presentation-device/deviceInfo;1 {1bd66bef-f643-4be3-b690-0c656353eafd}

View file

@ -1,336 +0,0 @@
/* -*- 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/. */
#include "PresentationDeviceManager.h"
#include "mozilla/Services.h"
#include "MainThreadUtils.h"
#include "nsArrayUtils.h"
#include "nsCategoryCache.h"
#include "nsCOMPtr.h"
#include "nsIMutableArray.h"
#include "nsIObserverService.h"
#include "nsXULAppAPI.h"
#include "PresentationSessionRequest.h"
#include "PresentationTerminateRequest.h"
namespace mozilla {
namespace dom {
NS_IMPL_ISUPPORTS(PresentationDeviceManager,
nsIPresentationDeviceManager,
nsIPresentationDeviceListener,
nsIObserver,
nsISupportsWeakReference)
PresentationDeviceManager::PresentationDeviceManager()
{
}
PresentationDeviceManager::~PresentationDeviceManager()
{
UnloadDeviceProviders();
mDevices.Clear();
}
void
PresentationDeviceManager::Init()
{
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
if (obs) {
obs->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
}
LoadDeviceProviders();
}
void
PresentationDeviceManager::Shutdown()
{
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
if (obs) {
obs->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
}
UnloadDeviceProviders();
}
void
PresentationDeviceManager::LoadDeviceProviders()
{
MOZ_ASSERT(mProviders.IsEmpty());
nsCategoryCache<nsIPresentationDeviceProvider> providerCache(PRESENTATION_DEVICE_PROVIDER_CATEGORY);
providerCache.GetEntries(mProviders);
for (uint32_t i = 0; i < mProviders.Length(); ++i) {
mProviders[i]->SetListener(this);
}
}
void
PresentationDeviceManager::UnloadDeviceProviders()
{
for (uint32_t i = 0; i < mProviders.Length(); ++i) {
mProviders[i]->SetListener(nullptr);
}
mProviders.Clear();
}
void
PresentationDeviceManager::NotifyDeviceChange(nsIPresentationDevice* aDevice,
const char16_t* aType)
{
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
if (obs) {
obs->NotifyObservers(aDevice,
PRESENTATION_DEVICE_CHANGE_TOPIC,
aType);
}
}
// nsIPresentationDeviceManager
NS_IMETHODIMP
PresentationDeviceManager::ForceDiscovery()
{
MOZ_ASSERT(NS_IsMainThread());
for (uint32_t i = 0; i < mProviders.Length(); ++i) {
mProviders[i]->ForceDiscovery();
}
return NS_OK;
}
NS_IMETHODIMP
PresentationDeviceManager::AddDeviceProvider(nsIPresentationDeviceProvider* aProvider)
{
NS_ENSURE_ARG(aProvider);
MOZ_ASSERT(NS_IsMainThread());
if (NS_WARN_IF(mProviders.Contains(aProvider))) {
return NS_OK;
}
mProviders.AppendElement(aProvider);
aProvider->SetListener(this);
return NS_OK;
}
NS_IMETHODIMP
PresentationDeviceManager::RemoveDeviceProvider(nsIPresentationDeviceProvider* aProvider)
{
NS_ENSURE_ARG(aProvider);
MOZ_ASSERT(NS_IsMainThread());
if (NS_WARN_IF(!mProviders.RemoveElement(aProvider))) {
return NS_ERROR_FAILURE;
}
aProvider->SetListener(nullptr);
return NS_OK;
}
NS_IMETHODIMP
PresentationDeviceManager::GetDeviceAvailable(bool* aRetVal)
{
NS_ENSURE_ARG_POINTER(aRetVal);
MOZ_ASSERT(NS_IsMainThread());
*aRetVal = !mDevices.IsEmpty();
return NS_OK;
}
NS_IMETHODIMP
PresentationDeviceManager::GetAvailableDevices(nsIArray* aPresentationUrls, nsIArray** aRetVal)
{
NS_ENSURE_ARG_POINTER(aRetVal);
MOZ_ASSERT(NS_IsMainThread());
// Bug 1194049: some providers may discontinue discovery after timeout.
// Call |ForceDiscovery()| here to make sure device lists are updated.
NS_DispatchToMainThread(
NewRunnableMethod(this, &PresentationDeviceManager::ForceDiscovery));
nsTArray<nsString> presentationUrls;
if (aPresentationUrls) {
uint32_t length;
nsresult rv = aPresentationUrls->GetLength(&length);
if (NS_SUCCEEDED(rv)) {
for (uint32_t i = 0; i < length; ++i) {
nsCOMPtr<nsISupportsString> isupportStr =
do_QueryElementAt(aPresentationUrls, i);
nsAutoString presentationUrl;
rv = isupportStr->GetData(presentationUrl);
if (NS_WARN_IF(NS_FAILED(rv))) {
continue;
}
presentationUrls.AppendElement(presentationUrl);
}
}
}
nsCOMPtr<nsIMutableArray> devices = do_CreateInstance(NS_ARRAY_CONTRACTID);
for (uint32_t i = 0; i < mDevices.Length(); ++i) {
if (presentationUrls.IsEmpty()) {
devices->AppendElement(mDevices[i], false);
continue;
}
for (uint32_t j = 0; j < presentationUrls.Length(); ++j) {
bool isSupported;
if (NS_SUCCEEDED(mDevices[i]->IsRequestedUrlSupported(presentationUrls[j],
&isSupported)) &&
isSupported) {
devices->AppendElement(mDevices[i], false);
break;
}
}
}
devices.forget(aRetVal);
return NS_OK;
}
// nsIPresentationDeviceListener
NS_IMETHODIMP
PresentationDeviceManager::AddDevice(nsIPresentationDevice* aDevice)
{
NS_ENSURE_ARG(aDevice);
MOZ_ASSERT(NS_IsMainThread());
if (NS_WARN_IF(mDevices.Contains(aDevice))) {
return NS_ERROR_FAILURE;
}
mDevices.AppendElement(aDevice);
NotifyDeviceChange(aDevice, u"add");
return NS_OK;
}
NS_IMETHODIMP
PresentationDeviceManager::RemoveDevice(nsIPresentationDevice* aDevice)
{
NS_ENSURE_ARG(aDevice);
MOZ_ASSERT(NS_IsMainThread());
int32_t index = mDevices.IndexOf(aDevice);
if (NS_WARN_IF(index < 0)) {
return NS_ERROR_FAILURE;
}
mDevices.RemoveElementAt(index);
NotifyDeviceChange(aDevice, u"remove");
return NS_OK;
}
NS_IMETHODIMP
PresentationDeviceManager::UpdateDevice(nsIPresentationDevice* aDevice)
{
NS_ENSURE_ARG(aDevice);
MOZ_ASSERT(NS_IsMainThread());
if (NS_WARN_IF(!mDevices.Contains(aDevice))) {
return NS_ERROR_FAILURE;
}
NotifyDeviceChange(aDevice, u"update");
return NS_OK;
}
NS_IMETHODIMP
PresentationDeviceManager::OnSessionRequest(nsIPresentationDevice* aDevice,
const nsAString& aUrl,
const nsAString& aPresentationId,
nsIPresentationControlChannel* aControlChannel)
{
NS_ENSURE_ARG(aDevice);
NS_ENSURE_ARG(aControlChannel);
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
NS_ENSURE_TRUE(obs, NS_ERROR_FAILURE);
RefPtr<PresentationSessionRequest> request =
new PresentationSessionRequest(aDevice, aUrl, aPresentationId, aControlChannel);
obs->NotifyObservers(request,
PRESENTATION_SESSION_REQUEST_TOPIC,
nullptr);
return NS_OK;
}
NS_IMETHODIMP
PresentationDeviceManager::OnTerminateRequest(nsIPresentationDevice* aDevice,
const nsAString& aPresentationId,
nsIPresentationControlChannel* aControlChannel,
bool aIsFromReceiver)
{
NS_ENSURE_ARG(aDevice);
NS_ENSURE_ARG(aControlChannel);
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
NS_ENSURE_TRUE(obs, NS_ERROR_FAILURE);
RefPtr<PresentationTerminateRequest> request =
new PresentationTerminateRequest(aDevice, aPresentationId,
aControlChannel, aIsFromReceiver);
obs->NotifyObservers(request,
PRESENTATION_TERMINATE_REQUEST_TOPIC,
nullptr);
return NS_OK;
}
NS_IMETHODIMP
PresentationDeviceManager::OnReconnectRequest(nsIPresentationDevice* aDevice,
const nsAString& aUrl,
const nsAString& aPresentationId,
nsIPresentationControlChannel* aControlChannel)
{
NS_ENSURE_ARG(aDevice);
NS_ENSURE_ARG(aControlChannel);
nsCOMPtr<nsIObserverService> obs = services::GetObserverService();
NS_ENSURE_TRUE(obs, NS_ERROR_FAILURE);
RefPtr<PresentationSessionRequest> request =
new PresentationSessionRequest(aDevice, aUrl, aPresentationId, aControlChannel);
obs->NotifyObservers(request,
PRESENTATION_RECONNECT_REQUEST_TOPIC,
nullptr);
return NS_OK;
}
// nsIObserver
NS_IMETHODIMP
PresentationDeviceManager::Observe(nsISupports *aSubject,
const char *aTopic,
const char16_t *aData)
{
if (!strcmp(aTopic, "profile-after-change")) {
Init();
} else if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
Shutdown();
}
return NS_OK;
}
} // namespace dom
} // namespace mozilla

View file

@ -1,54 +0,0 @@
/* -*- 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_PresentationDeviceManager_h__
#define mozilla_dom_PresentationDeviceManager_h__
#include "nsIObserver.h"
#include "nsIPresentationDevice.h"
#include "nsIPresentationDeviceManager.h"
#include "nsIPresentationDeviceProvider.h"
#include "nsCOMArray.h"
#include "nsWeakReference.h"
namespace mozilla {
namespace dom {
class PresentationDeviceManager final : public nsIPresentationDeviceManager
, public nsIPresentationDeviceListener
, public nsIObserver
, public nsSupportsWeakReference
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIPRESENTATIONDEVICEMANAGER
NS_DECL_NSIPRESENTATIONDEVICELISTENER
NS_DECL_NSIOBSERVER
PresentationDeviceManager();
private:
virtual ~PresentationDeviceManager();
void Init();
void Shutdown();
void LoadDeviceProviders();
void UnloadDeviceProviders();
void NotifyDeviceChange(nsIPresentationDevice* aDevice,
const char16_t* aType);
nsCOMArray<nsIPresentationDeviceProvider> mProviders;
nsCOMArray<nsIPresentationDevice> mDevices;
};
} // namespace dom
} // namespace mozilla
#endif /* mozilla_dom_PresentationDeviceManager_h__ */

View file

@ -1,26 +0,0 @@
/* -*- 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_PresentationLog_h
#define mozilla_dom_PresentationLog_h
/*
* MOZ_LOG=Presentation:5
* For detail, see PresentationService.cpp
*/
namespace mozilla {
namespace dom {
extern mozilla::LazyLogModule gPresentationLog;
}
}
#undef PRES_ERROR
#define PRES_ERROR(...) MOZ_LOG(mozilla::dom::gPresentationLog, mozilla::LogLevel::Error, (__VA_ARGS__))
#undef PRES_DEBUG
#define PRES_DEBUG(...) MOZ_LOG(mozilla::dom::gPresentationLog, mozilla::LogLevel::Debug, (__VA_ARGS__))
#endif // mozilla_dom_PresentationLog_h

View file

@ -1,28 +0,0 @@
// -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
/* 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/. */
"use strict";
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
Cu.import("resource://gre/modules/Messaging.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
const NETWORKHELPER_CID = Components.ID("{5fb96caa-6d49-4f6b-9a4b-65dd0d51f92d}");
function PresentationNetworkHelper() {}
PresentationNetworkHelper.prototype = {
classID: NETWORKHELPER_CID,
QueryInterface: XPCOMUtils.generateQI([Ci.nsIPresentationNetworkHelper]),
getWifiIPAddress: function(aListener) {
Messaging.sendRequestForResult({type: "Wifi:GetIPAddress"})
.then(result => aListener.onGetWifiIPAddress(result),
err => aListener.onError(err));
}
};
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([PresentationNetworkHelper]);

View file

@ -1,3 +0,0 @@
# PresentationNetworkHelper.js
component {5fb96caa-6d49-4f6b-9a4b-65dd0d51f92d} PresentationNetworkHelper.js
contract @mozilla.org/presentation-device/networkHelper;1 {5fb96caa-6d49-4f6b-9a4b-65dd0d51f92d}

View file

@ -1,179 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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/. */
#include "PresentationReceiver.h"
#include "mozilla/dom/PresentationReceiverBinding.h"
#include "mozilla/dom/Promise.h"
#include "nsContentUtils.h"
#include "nsIPresentationService.h"
#include "nsPIDOMWindow.h"
#include "nsServiceManagerUtils.h"
#include "nsThreadUtils.h"
#include "PresentationConnection.h"
#include "PresentationConnectionList.h"
#include "PresentationLog.h"
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(PresentationReceiver,
mOwner,
mGetConnectionListPromise,
mConnectionList)
NS_IMPL_CYCLE_COLLECTING_ADDREF(PresentationReceiver)
NS_IMPL_CYCLE_COLLECTING_RELEASE(PresentationReceiver)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PresentationReceiver)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsIPresentationRespondingListener)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
/* static */ already_AddRefed<PresentationReceiver>
PresentationReceiver::Create(nsPIDOMWindowInner* aWindow)
{
RefPtr<PresentationReceiver> receiver = new PresentationReceiver(aWindow);
return NS_WARN_IF(!receiver->Init()) ? nullptr : receiver.forget();
}
PresentationReceiver::PresentationReceiver(nsPIDOMWindowInner* aWindow)
: mOwner(aWindow)
{
MOZ_ASSERT(aWindow);
}
PresentationReceiver::~PresentationReceiver()
{
Shutdown();
}
bool
PresentationReceiver::Init()
{
if (NS_WARN_IF(!mOwner)) {
return false;
}
mWindowId = mOwner->WindowID();
nsCOMPtr<nsIDocShell> docShell = mOwner->GetDocShell();
MOZ_ASSERT(docShell);
nsContentUtils::GetPresentationURL(docShell, mUrl);
return !mUrl.IsEmpty();
}
void PresentationReceiver::Shutdown()
{
PRES_DEBUG("receiver shutdown:windowId[%d]\n", mWindowId);
// Unregister listener for incoming sessions.
nsCOMPtr<nsIPresentationService> service =
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
if (NS_WARN_IF(!service)) {
return;
}
Unused <<
NS_WARN_IF(NS_FAILED(service->UnregisterRespondingListener(mWindowId)));
}
/* virtual */ JSObject*
PresentationReceiver::WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto)
{
return PresentationReceiverBinding::Wrap(aCx, this, aGivenProto);
}
NS_IMETHODIMP
PresentationReceiver::NotifySessionConnect(uint64_t aWindowId,
const nsAString& aSessionId)
{
PRES_DEBUG("receiver session connect:id[%s], windowId[%x]\n",
NS_ConvertUTF16toUTF8(aSessionId).get(), aWindowId);
if (NS_WARN_IF(!mOwner)) {
return NS_ERROR_FAILURE;
}
if (NS_WARN_IF(aWindowId != mWindowId)) {
return NS_ERROR_INVALID_ARG;
}
if (NS_WARN_IF(!mConnectionList)) {
return NS_ERROR_FAILURE;
}
RefPtr<PresentationConnection> connection =
PresentationConnection::Create(mOwner, aSessionId, mUrl,
nsIPresentationService::ROLE_RECEIVER,
mConnectionList);
if (NS_WARN_IF(!connection)) {
return NS_ERROR_NOT_AVAILABLE;
}
return NS_OK;
}
already_AddRefed<Promise>
PresentationReceiver::GetConnectionList(ErrorResult& aRv)
{
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(mOwner);
if (NS_WARN_IF(!global)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
if (!mGetConnectionListPromise) {
mGetConnectionListPromise = Promise::Create(global, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
RefPtr<PresentationReceiver> self = this;
nsresult rv =
NS_DispatchToMainThread(NS_NewRunnableFunction([self] () -> void {
self->CreateConnectionList();
}));
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
}
}
RefPtr<Promise> promise = mGetConnectionListPromise;
return promise.forget();
}
void
PresentationReceiver::CreateConnectionList()
{
MOZ_ASSERT(mGetConnectionListPromise);
if (mConnectionList) {
return;
}
mConnectionList = new PresentationConnectionList(mOwner,
mGetConnectionListPromise);
// Register listener for incoming sessions.
nsCOMPtr<nsIPresentationService> service =
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
if (NS_WARN_IF(!service)) {
mGetConnectionListPromise->MaybeReject(NS_ERROR_DOM_OPERATION_ERR);
return;
}
nsresult rv = service->RegisterRespondingListener(mWindowId, this);
if (NS_WARN_IF(NS_FAILED(rv))) {
mGetConnectionListPromise->MaybeReject(rv);
}
}
} // namespace dom
} // namespace mozilla

View file

@ -1,71 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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_PresentationReceiver_h
#define mozilla_dom_PresentationReceiver_h
#include "mozilla/ErrorResult.h"
#include "nsCOMPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsIPresentationListener.h"
#include "nsWrapperCache.h"
#include "nsString.h"
class nsPIDOMWindowInner;
namespace mozilla {
namespace dom {
class PresentationConnection;
class PresentationConnectionList;
class Promise;
class PresentationReceiver final : public nsIPresentationRespondingListener
, public nsWrapperCache
{
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(PresentationReceiver)
NS_DECL_NSIPRESENTATIONRESPONDINGLISTENER
static already_AddRefed<PresentationReceiver> Create(nsPIDOMWindowInner* aWindow);
virtual JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
nsPIDOMWindowInner* GetParentObject() const
{
return mOwner;
}
// WebIDL (public APIs)
already_AddRefed<Promise> GetConnectionList(ErrorResult& aRv);
private:
explicit PresentationReceiver(nsPIDOMWindowInner* aWindow);
virtual ~PresentationReceiver();
MOZ_IS_CLASS_INIT bool Init();
void Shutdown();
void CreateConnectionList();
// Store the inner window ID for |UnregisterRespondingListener| call in
// |Shutdown| since the inner window may not exist at that moment.
uint64_t mWindowId;
nsCOMPtr<nsPIDOMWindowInner> mOwner;
nsString mUrl;
RefPtr<Promise> mGetConnectionListPromise;
RefPtr<PresentationConnectionList> mConnectionList;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_PresentationReceiver_h

View file

@ -1,563 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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/. */
#include "PresentationRequest.h"
#include "AvailabilityCollection.h"
#include "ControllerConnectionCollection.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/dom/Navigator.h"
#include "mozilla/dom/PresentationRequestBinding.h"
#include "mozilla/dom/PresentationConnectionAvailableEvent.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/Move.h"
#include "mozIThirdPartyUtil.h"
#include "nsContentSecurityManager.h"
#include "nsCycleCollectionParticipant.h"
#include "nsGlobalWindow.h"
#include "nsIDocument.h"
#include "nsIPresentationService.h"
#include "nsIURI.h"
#include "nsIUUIDGenerator.h"
#include "nsNetUtil.h"
#include "nsSandboxFlags.h"
#include "nsServiceManagerUtils.h"
#include "Presentation.h"
#include "PresentationAvailability.h"
#include "PresentationCallbacks.h"
#include "PresentationLog.h"
#include "PresentationTransportBuilderConstructor.h"
using namespace mozilla;
using namespace mozilla::dom;
NS_IMPL_ADDREF_INHERITED(PresentationRequest, DOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(PresentationRequest, DOMEventTargetHelper)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(PresentationRequest)
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
static nsresult
GetAbsoluteURL(const nsAString& aUrl,
nsIURI* aBaseUri,
nsIDocument* aDocument,
nsAString& aAbsoluteUrl)
{
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri),
aUrl,
aDocument ? aDocument->GetDocumentCharacterSet().get()
: nullptr,
aBaseUri);
if (NS_FAILED(rv)) {
return rv;
}
nsAutoCString spec;
uri->GetSpec(spec);
aAbsoluteUrl = NS_ConvertUTF8toUTF16(spec);
return NS_OK;
}
/* static */ already_AddRefed<PresentationRequest>
PresentationRequest::Constructor(const GlobalObject& aGlobal,
const nsAString& aUrl,
ErrorResult& aRv)
{
Sequence<nsString> urls;
urls.AppendElement(aUrl, fallible);
return Constructor(aGlobal, urls, aRv);
}
/* static */ already_AddRefed<PresentationRequest>
PresentationRequest::Constructor(const GlobalObject& aGlobal,
const Sequence<nsString>& aUrls,
ErrorResult& aRv)
{
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aGlobal.GetAsSupports());
if (!window) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
if (aUrls.IsEmpty()) {
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
return nullptr;
}
// Resolve relative URL to absolute URL
nsCOMPtr<nsIURI> baseUri = window->GetDocBaseURI();
nsTArray<nsString> urls;
for (const auto& url : aUrls) {
nsAutoString absoluteUrl;
nsresult rv =
GetAbsoluteURL(url, baseUri, window->GetExtantDoc(), absoluteUrl);
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
return nullptr;
}
urls.AppendElement(absoluteUrl);
}
RefPtr<PresentationRequest> request =
new PresentationRequest(window, Move(urls));
return NS_WARN_IF(!request->Init()) ? nullptr : request.forget();
}
PresentationRequest::PresentationRequest(nsPIDOMWindowInner* aWindow,
nsTArray<nsString>&& aUrls)
: DOMEventTargetHelper(aWindow)
, mUrls(Move(aUrls))
{
}
PresentationRequest::~PresentationRequest()
{
}
bool
PresentationRequest::Init()
{
return true;
}
/* virtual */ JSObject*
PresentationRequest::WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto)
{
return PresentationRequestBinding::Wrap(aCx, this, aGivenProto);
}
already_AddRefed<Promise>
PresentationRequest::Start(ErrorResult& aRv)
{
return StartWithDevice(NullString(), aRv);
}
already_AddRefed<Promise>
PresentationRequest::StartWithDevice(const nsAString& aDeviceId,
ErrorResult& aRv)
{
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
if (NS_WARN_IF(!global)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
// Get the origin.
nsAutoString origin;
nsresult rv = nsContentUtils::GetUTFOrigin(global->PrincipalOrNull(), origin);
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.Throw(rv);
return nullptr;
}
nsCOMPtr<nsIDocument> doc = GetOwner()->GetExtantDoc();
if (NS_WARN_IF(!doc)) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
RefPtr<Promise> promise = Promise::Create(global, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
if (IsProhibitMixedSecurityContexts(doc) &&
!IsAllURLAuthenticated()) {
promise->MaybeReject(NS_ERROR_DOM_SECURITY_ERR);
return promise.forget();
}
if (doc->GetSandboxFlags() & SANDBOXED_PRESENTATION) {
promise->MaybeReject(NS_ERROR_DOM_SECURITY_ERR);
return promise.forget();
}
RefPtr<Navigator> navigator =
nsGlobalWindow::Cast(GetOwner())->GetNavigator(aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
RefPtr<Presentation> presentation = navigator->GetPresentation(aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
if (presentation->IsStartSessionUnsettled()) {
promise->MaybeReject(NS_ERROR_DOM_OPERATION_ERR);
return promise.forget();
}
// Generate a session ID.
nsCOMPtr<nsIUUIDGenerator> uuidgen =
do_GetService("@mozilla.org/uuid-generator;1");
if(NS_WARN_IF(!uuidgen)) {
promise->MaybeReject(NS_ERROR_DOM_OPERATION_ERR);
return promise.forget();
}
nsID uuid;
uuidgen->GenerateUUIDInPlace(&uuid);
char buffer[NSID_LENGTH];
uuid.ToProvidedString(buffer);
nsAutoString id;
CopyASCIItoUTF16(buffer, id);
nsCOMPtr<nsIPresentationService> service =
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
if(NS_WARN_IF(!service)) {
promise->MaybeReject(NS_ERROR_DOM_OPERATION_ERR);
return promise.forget();
}
presentation->SetStartSessionUnsettled(true);
// Get xul:browser element in parent process or nsWindowRoot object in child
// process. If it's in child process, the corresponding xul:browser element
// will be obtained at PresentationRequestParent::DoRequest in its parent
// process.
nsCOMPtr<nsIDOMEventTarget> handler =
do_QueryInterface(GetOwner()->GetChromeEventHandler());
nsCOMPtr<nsIPrincipal> principal = doc->NodePrincipal();
nsCOMPtr<nsIPresentationServiceCallback> callback =
new PresentationRequesterCallback(this, id, promise);
nsCOMPtr<nsIPresentationTransportBuilderConstructor> constructor =
PresentationTransportBuilderConstructor::Create();
rv = service->StartSession(mUrls,
id,
origin,
aDeviceId,
GetOwner()->WindowID(),
handler,
principal,
callback,
constructor);
if (NS_WARN_IF(NS_FAILED(rv))) {
promise->MaybeReject(NS_ERROR_DOM_OPERATION_ERR);
NotifyPromiseSettled();
}
return promise.forget();
}
already_AddRefed<Promise>
PresentationRequest::Reconnect(const nsAString& aPresentationId,
ErrorResult& aRv)
{
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
if (NS_WARN_IF(!global)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
nsCOMPtr<nsIDocument> doc = GetOwner()->GetExtantDoc();
if (NS_WARN_IF(!doc)) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
RefPtr<Promise> promise = Promise::Create(global, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
if (IsProhibitMixedSecurityContexts(doc) &&
!IsAllURLAuthenticated()) {
promise->MaybeReject(NS_ERROR_DOM_SECURITY_ERR);
return promise.forget();
}
if (doc->GetSandboxFlags() & SANDBOXED_PRESENTATION) {
promise->MaybeReject(NS_ERROR_DOM_SECURITY_ERR);
return promise.forget();
}
nsString presentationId = nsString(aPresentationId);
nsCOMPtr<nsIRunnable> r =
NewRunnableMethod<nsString, RefPtr<Promise>>(
this,
&PresentationRequest::FindOrCreatePresentationConnection,
presentationId,
promise);
if (NS_WARN_IF(NS_FAILED(NS_DispatchToMainThread(r)))) {
promise->MaybeReject(NS_ERROR_DOM_OPERATION_ERR);
}
return promise.forget();
}
void
PresentationRequest::FindOrCreatePresentationConnection(
const nsAString& aPresentationId,
Promise* aPromise)
{
MOZ_ASSERT(aPromise);
if (NS_WARN_IF(!GetOwner())) {
aPromise->MaybeReject(NS_ERROR_DOM_OPERATION_ERR);
return;
}
RefPtr<PresentationConnection> connection =
ControllerConnectionCollection::GetSingleton()->FindConnection(
GetOwner()->WindowID(),
aPresentationId,
nsIPresentationService::ROLE_CONTROLLER);
if (connection) {
nsAutoString url;
connection->GetUrl(url);
if (mUrls.Contains(url)) {
switch (connection->State()) {
case PresentationConnectionState::Closed:
// We found the matched connection.
break;
case PresentationConnectionState::Connecting:
case PresentationConnectionState::Connected:
aPromise->MaybeResolve(connection);
return;
case PresentationConnectionState::Terminated:
// A terminated connection cannot be reused.
connection = nullptr;
break;
default:
MOZ_CRASH("Unknown presentation session state.");
return;
}
} else {
connection = nullptr;
}
}
nsCOMPtr<nsIPresentationService> service =
do_GetService(PRESENTATION_SERVICE_CONTRACTID);
if(NS_WARN_IF(!service)) {
aPromise->MaybeReject(NS_ERROR_DOM_OPERATION_ERR);
return;
}
nsCOMPtr<nsIPresentationServiceCallback> callback =
new PresentationReconnectCallback(this,
aPresentationId,
aPromise,
connection);
nsresult rv =
service->ReconnectSession(mUrls,
aPresentationId,
nsIPresentationService::ROLE_CONTROLLER,
callback);
if (NS_WARN_IF(NS_FAILED(rv))) {
aPromise->MaybeReject(NS_ERROR_DOM_OPERATION_ERR);
}
}
already_AddRefed<Promise>
PresentationRequest::GetAvailability(ErrorResult& aRv)
{
PRES_DEBUG("%s\n", __func__);
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
if (NS_WARN_IF(!global)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
nsCOMPtr<nsIDocument> doc = GetOwner()->GetExtantDoc();
if (NS_WARN_IF(!doc)) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
RefPtr<Promise> promise = Promise::Create(global, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
if (IsProhibitMixedSecurityContexts(doc) &&
!IsAllURLAuthenticated()) {
promise->MaybeReject(NS_ERROR_DOM_SECURITY_ERR);
return promise.forget();
}
if (doc->GetSandboxFlags() & SANDBOXED_PRESENTATION) {
promise->MaybeReject(NS_ERROR_DOM_SECURITY_ERR);
return promise.forget();
}
FindOrCreatePresentationAvailability(promise);
return promise.forget();
}
void
PresentationRequest::FindOrCreatePresentationAvailability(RefPtr<Promise>& aPromise)
{
MOZ_ASSERT(aPromise);
if (NS_WARN_IF(!GetOwner())) {
aPromise->MaybeReject(NS_ERROR_DOM_OPERATION_ERR);
return;
}
AvailabilityCollection* collection = AvailabilityCollection::GetSingleton();
if (NS_WARN_IF(!collection)) {
aPromise->MaybeReject(NS_ERROR_DOM_OPERATION_ERR);
return;
}
RefPtr<PresentationAvailability> availability =
collection->Find(GetOwner()->WindowID(), mUrls);
if (!availability) {
availability = PresentationAvailability::Create(GetOwner(), mUrls, aPromise);
} else {
PRES_DEBUG(">resolve with same object\n");
// Fetching cached available devices is asynchronous in our implementation,
// we need to ensure the promise is resolved in order.
if (availability->IsCachedValueReady()) {
aPromise->MaybeResolve(availability);
return;
}
availability->EnqueuePromise(aPromise);
}
if (!availability) {
aPromise->MaybeReject(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
return;
}
}
nsresult
PresentationRequest::DispatchConnectionAvailableEvent(PresentationConnection* aConnection)
{
PresentationConnectionAvailableEventInit init;
init.mConnection = aConnection;
RefPtr<PresentationConnectionAvailableEvent> event =
PresentationConnectionAvailableEvent::Constructor(this,
NS_LITERAL_STRING("connectionavailable"),
init);
if (NS_WARN_IF(!event)) {
return NS_ERROR_FAILURE;
}
event->SetTrusted(true);
RefPtr<AsyncEventDispatcher> asyncDispatcher =
new AsyncEventDispatcher(this, event);
return asyncDispatcher->PostDOMEvent();
}
void
PresentationRequest::NotifyPromiseSettled()
{
PRES_DEBUG("%s\n", __func__);
if (!GetOwner()) {
return;
}
ErrorResult rv;
RefPtr<Navigator> navigator =
nsGlobalWindow::Cast(GetOwner())->GetNavigator(rv);
if (!navigator) {
return;
}
RefPtr<Presentation> presentation = navigator->GetPresentation(rv);
if (presentation) {
presentation->SetStartSessionUnsettled(false);
}
}
bool
PresentationRequest::IsProhibitMixedSecurityContexts(nsIDocument* aDocument)
{
MOZ_ASSERT(aDocument);
if (nsContentUtils::IsChromeDoc(aDocument)) {
return true;
}
nsCOMPtr<nsIDocument> doc = aDocument;
while (doc && !nsContentUtils::IsChromeDoc(doc)) {
if (nsContentUtils::HttpsStateIsModern(doc)) {
return true;
}
doc = doc->GetParentDocument();
}
return false;
}
bool
PresentationRequest::IsPrioriAuthenticatedURL(const nsAString& aUrl)
{
nsCOMPtr<nsIURI> uri;
if (NS_FAILED(NS_NewURI(getter_AddRefs(uri), aUrl))) {
return false;
}
nsAutoCString scheme;
nsresult rv = uri->GetScheme(scheme);
if (NS_WARN_IF(NS_FAILED(rv))) {
return false;
}
if (scheme.EqualsLiteral("data")) {
return true;
}
nsAutoCString uriSpec;
rv = uri->GetSpec(uriSpec);
if (NS_WARN_IF(NS_FAILED(rv))) {
return false;
}
if (uriSpec.EqualsLiteral("about:blank") ||
uriSpec.EqualsLiteral("about:srcdoc")) {
return true;
}
PrincipalOriginAttributes attrs;
nsCOMPtr<nsIPrincipal> principal =
BasePrincipal::CreateCodebasePrincipal(uri, attrs);
if (NS_WARN_IF(!principal)) {
return false;
}
nsCOMPtr<nsIContentSecurityManager> csm =
do_GetService(NS_CONTENTSECURITYMANAGER_CONTRACTID);
if (NS_WARN_IF(!csm)) {
return false;
}
bool isTrustworthyOrigin = false;
csm->IsOriginPotentiallyTrustworthy(principal, &isTrustworthyOrigin);
return isTrustworthyOrigin;
}
bool
PresentationRequest::IsAllURLAuthenticated()
{
for (const auto& url : mUrls) {
if (!IsPrioriAuthenticatedURL(url)) {
return false;
}
}
return true;
}

View file

@ -1,84 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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_PresentationRequest_h
#define mozilla_dom_PresentationRequest_h
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/DOMEventTargetHelper.h"
class nsIDocument;
namespace mozilla {
namespace dom {
class Promise;
class PresentationAvailability;
class PresentationConnection;
class PresentationRequest final : public DOMEventTargetHelper
{
public:
NS_DECL_ISUPPORTS_INHERITED
static already_AddRefed<PresentationRequest> Constructor(
const GlobalObject& aGlobal,
const nsAString& aUrl,
ErrorResult& aRv);
static already_AddRefed<PresentationRequest> Constructor(
const GlobalObject& aGlobal,
const Sequence<nsString>& aUrls,
ErrorResult& aRv);
virtual JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
// WebIDL (public APIs)
already_AddRefed<Promise> Start(ErrorResult& aRv);
already_AddRefed<Promise> StartWithDevice(const nsAString& aDeviceId,
ErrorResult& aRv);
already_AddRefed<Promise> Reconnect(const nsAString& aPresentationId,
ErrorResult& aRv);
already_AddRefed<Promise> GetAvailability(ErrorResult& aRv);
IMPL_EVENT_HANDLER(connectionavailable);
nsresult DispatchConnectionAvailableEvent(PresentationConnection* aConnection);
void NotifyPromiseSettled();
private:
PresentationRequest(nsPIDOMWindowInner* aWindow,
nsTArray<nsString>&& aUrls);
~PresentationRequest();
bool Init();
void FindOrCreatePresentationConnection(const nsAString& aPresentationId,
Promise* aPromise);
void FindOrCreatePresentationAvailability(RefPtr<Promise>& aPromise);
// Implement https://w3c.github.io/webappsec-mixed-content/#categorize-settings-object
bool IsProhibitMixedSecurityContexts(nsIDocument* aDocument);
// Implement https://w3c.github.io/webappsec-mixed-content/#a-priori-authenticated-url
bool IsPrioriAuthenticatedURL(const nsAString& aUrl);
bool IsAllURLAuthenticated();
nsTArray<nsString> mUrls;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_PresentationRequest_h

File diff suppressed because it is too large Load diff

View file

@ -1,68 +0,0 @@
/* -*- 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_PresentationService_h
#define mozilla_dom_PresentationService_h
#include "nsCOMPtr.h"
#include "nsIObserver.h"
#include "PresentationServiceBase.h"
#include "PresentationSessionInfo.h"
class nsIPresentationSessionRequest;
class nsIPresentationTerminateRequest;
class nsIURI;
class nsIPresentationSessionTransportBuilder;
namespace mozilla {
namespace dom {
class PresentationDeviceRequest;
class PresentationRespondingInfo;
class PresentationService final
: public nsIPresentationService
, public nsIObserver
, public PresentationServiceBase<PresentationSessionInfo>
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
NS_DECL_NSIPRESENTATIONSERVICE
PresentationService();
bool Init();
bool IsSessionAccessible(const nsAString& aSessionId,
const uint8_t aRole,
base::ProcessId aProcessId);
private:
friend class PresentationDeviceRequest;
virtual ~PresentationService();
void HandleShutdown();
nsresult HandleDeviceAdded(nsIPresentationDevice* aDevice);
nsresult HandleDeviceRemoved();
nsresult HandleSessionRequest(nsIPresentationSessionRequest* aRequest);
nsresult HandleTerminateRequest(nsIPresentationTerminateRequest* aRequest);
nsresult HandleReconnectRequest(nsIPresentationSessionRequest* aRequest);
// This is meant to be called by PresentationDeviceRequest.
already_AddRefed<PresentationSessionInfo>
CreateControllingSessionInfo(const nsAString& aUrl,
const nsAString& aSessionId,
uint64_t aWindowId);
// Emumerate all devices to get the availability of each input Urls.
nsresult UpdateAvailabilityUrlChange(
const nsTArray<nsString>& aAvailabilityUrls);
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_PresentationService_h

View file

@ -1,401 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set sw=2 ts=8 et ft=cpp : */
/* 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_PresentationServiceBase_h
#define mozilla_dom_PresentationServiceBase_h
#include "mozilla/Unused.h"
#include "nsClassHashtable.h"
#include "nsCOMArray.h"
#include "nsIPresentationListener.h"
#include "nsIPresentationService.h"
#include "nsRefPtrHashtable.h"
#include "nsString.h"
#include "nsTArray.h"
namespace mozilla {
namespace dom {
template<class T>
class PresentationServiceBase
{
public:
PresentationServiceBase() = default;
already_AddRefed<T>
GetSessionInfo(const nsAString& aSessionId, const uint8_t aRole)
{
MOZ_ASSERT(aRole == nsIPresentationService::ROLE_CONTROLLER ||
aRole == nsIPresentationService::ROLE_RECEIVER);
RefPtr<T> info;
if (aRole == nsIPresentationService::ROLE_CONTROLLER) {
return mSessionInfoAtController.Get(aSessionId, getter_AddRefs(info)) ?
info.forget() : nullptr;
} else {
return mSessionInfoAtReceiver.Get(aSessionId, getter_AddRefs(info)) ?
info.forget() : nullptr;
}
}
protected:
class SessionIdManager final
{
public:
explicit SessionIdManager()
{
MOZ_COUNT_CTOR(SessionIdManager);
}
~SessionIdManager()
{
MOZ_COUNT_DTOR(SessionIdManager);
}
nsresult GetWindowId(const nsAString& aSessionId, uint64_t* aWindowId)
{
MOZ_ASSERT(NS_IsMainThread());
if (mRespondingWindowIds.Get(aSessionId, aWindowId)) {
return NS_OK;
}
return NS_ERROR_NOT_AVAILABLE;
}
nsresult GetSessionIds(uint64_t aWindowId, nsTArray<nsString>& aSessionIds)
{
MOZ_ASSERT(NS_IsMainThread());
nsTArray<nsString>* sessionIdArray;
if (!mRespondingSessionIds.Get(aWindowId, &sessionIdArray)) {
return NS_ERROR_INVALID_ARG;
}
aSessionIds.Assign(*sessionIdArray);
return NS_OK;
}
void AddSessionId(uint64_t aWindowId, const nsAString& aSessionId)
{
MOZ_ASSERT(NS_IsMainThread());
if (NS_WARN_IF(aWindowId == 0)) {
return;
}
nsTArray<nsString>* sessionIdArray;
if (!mRespondingSessionIds.Get(aWindowId, &sessionIdArray)) {
sessionIdArray = new nsTArray<nsString>();
mRespondingSessionIds.Put(aWindowId, sessionIdArray);
}
sessionIdArray->AppendElement(nsString(aSessionId));
mRespondingWindowIds.Put(aSessionId, aWindowId);
}
void RemoveSessionId(const nsAString& aSessionId)
{
MOZ_ASSERT(NS_IsMainThread());
uint64_t windowId = 0;
if (mRespondingWindowIds.Get(aSessionId, &windowId)) {
mRespondingWindowIds.Remove(aSessionId);
nsTArray<nsString>* sessionIdArray;
if (mRespondingSessionIds.Get(windowId, &sessionIdArray)) {
sessionIdArray->RemoveElement(nsString(aSessionId));
if (sessionIdArray->IsEmpty()) {
mRespondingSessionIds.Remove(windowId);
}
}
}
}
nsresult UpdateWindowId(const nsAString& aSessionId, const uint64_t aWindowId)
{
MOZ_ASSERT(NS_IsMainThread());
RemoveSessionId(aSessionId);
AddSessionId(aWindowId, aSessionId);
return NS_OK;
}
void Clear()
{
mRespondingSessionIds.Clear();
mRespondingWindowIds.Clear();
}
private:
nsClassHashtable<nsUint64HashKey, nsTArray<nsString>> mRespondingSessionIds;
nsDataHashtable<nsStringHashKey, uint64_t> mRespondingWindowIds;
};
class AvailabilityManager final
{
public:
explicit AvailabilityManager()
{
MOZ_COUNT_CTOR(AvailabilityManager);
}
~AvailabilityManager()
{
MOZ_COUNT_DTOR(AvailabilityManager);
}
void AddAvailabilityListener(
const nsTArray<nsString>& aAvailabilityUrls,
nsIPresentationAvailabilityListener* aListener)
{
nsTArray<nsString> dummy;
AddAvailabilityListener(aAvailabilityUrls, aListener, dummy);
}
void AddAvailabilityListener(
const nsTArray<nsString>& aAvailabilityUrls,
nsIPresentationAvailabilityListener* aListener,
nsTArray<nsString>& aAddedUrls)
{
if (!aListener) {
MOZ_ASSERT(false, "aListener should not be null.");
return;
}
if (aAvailabilityUrls.IsEmpty()) {
MOZ_ASSERT(false, "aAvailabilityUrls should not be empty.");
return;
}
aAddedUrls.Clear();
nsTArray<nsString> knownAvailableUrls;
for (const auto& url : aAvailabilityUrls) {
AvailabilityEntry* entry;
if (!mAvailabilityUrlTable.Get(url, &entry)) {
entry = new AvailabilityEntry();
mAvailabilityUrlTable.Put(url, entry);
aAddedUrls.AppendElement(url);
}
if (!entry->mListeners.Contains(aListener)) {
entry->mListeners.AppendElement(aListener);
}
if (entry->mAvailable) {
knownAvailableUrls.AppendElement(url);
}
}
if (!knownAvailableUrls.IsEmpty()) {
Unused <<
NS_WARN_IF(
NS_FAILED(aListener->NotifyAvailableChange(knownAvailableUrls,
true)));
} else {
// If we can't find any known available url and there is no newly
// added url, we still need to notify the listener of the result.
// So, the promise returned by |getAvailability| can be resolved.
if (aAddedUrls.IsEmpty()) {
Unused <<
NS_WARN_IF(
NS_FAILED(aListener->NotifyAvailableChange(aAvailabilityUrls,
false)));
}
}
}
void RemoveAvailabilityListener(
const nsTArray<nsString>& aAvailabilityUrls,
nsIPresentationAvailabilityListener* aListener)
{
nsTArray<nsString> dummy;
RemoveAvailabilityListener(aAvailabilityUrls, aListener, dummy);
}
void RemoveAvailabilityListener(
const nsTArray<nsString>& aAvailabilityUrls,
nsIPresentationAvailabilityListener* aListener,
nsTArray<nsString>& aRemovedUrls)
{
if (!aListener) {
MOZ_ASSERT(false, "aListener should not be null.");
return;
}
if (aAvailabilityUrls.IsEmpty()) {
MOZ_ASSERT(false, "aAvailabilityUrls should not be empty.");
return;
}
aRemovedUrls.Clear();
for (const auto& url : aAvailabilityUrls) {
AvailabilityEntry* entry;
if (mAvailabilityUrlTable.Get(url, &entry)) {
entry->mListeners.RemoveElement(aListener);
if (entry->mListeners.IsEmpty()) {
mAvailabilityUrlTable.Remove(url);
aRemovedUrls.AppendElement(url);
}
}
}
}
nsresult DoNotifyAvailableChange(const nsTArray<nsString>& aAvailabilityUrls,
bool aAvailable)
{
typedef nsClassHashtable<nsISupportsHashKey,
nsTArray<nsString>> ListenerToUrlsMap;
ListenerToUrlsMap availabilityListenerTable;
// Create a mapping from nsIPresentationAvailabilityListener to
// availabilityUrls.
for (auto it = mAvailabilityUrlTable.ConstIter(); !it.Done(); it.Next()) {
if (aAvailabilityUrls.Contains(it.Key())) {
AvailabilityEntry* entry = it.UserData();
entry->mAvailable = aAvailable;
for (uint32_t i = 0; i < entry->mListeners.Length(); ++i) {
nsIPresentationAvailabilityListener* listener =
entry->mListeners.ObjectAt(i);
nsTArray<nsString>* urlArray;
if (!availabilityListenerTable.Get(listener, &urlArray)) {
urlArray = new nsTArray<nsString>();
availabilityListenerTable.Put(listener, urlArray);
}
urlArray->AppendElement(it.Key());
}
}
}
for (auto it = availabilityListenerTable.Iter(); !it.Done(); it.Next()) {
auto listener =
static_cast<nsIPresentationAvailabilityListener*>(it.Key());
Unused <<
NS_WARN_IF(NS_FAILED(listener->NotifyAvailableChange(*it.UserData(),
aAvailable)));
}
return NS_OK;
}
void GetAvailbilityUrlByAvailability(nsTArray<nsString>& aOutArray,
bool aAvailable)
{
aOutArray.Clear();
for (auto it = mAvailabilityUrlTable.ConstIter(); !it.Done(); it.Next()) {
if (it.UserData()->mAvailable == aAvailable) {
aOutArray.AppendElement(it.Key());
}
}
}
void Clear()
{
mAvailabilityUrlTable.Clear();
}
private:
struct AvailabilityEntry
{
explicit AvailabilityEntry()
: mAvailable(false)
{}
bool mAvailable;
nsCOMArray<nsIPresentationAvailabilityListener> mListeners;
};
nsClassHashtable<nsStringHashKey, AvailabilityEntry> mAvailabilityUrlTable;
};
virtual ~PresentationServiceBase() = default;
void Shutdown()
{
mRespondingListeners.Clear();
mControllerSessionIdManager.Clear();
mReceiverSessionIdManager.Clear();
}
nsresult GetWindowIdBySessionIdInternal(const nsAString& aSessionId,
uint8_t aRole,
uint64_t* aWindowId)
{
MOZ_ASSERT(aRole == nsIPresentationService::ROLE_CONTROLLER ||
aRole == nsIPresentationService::ROLE_RECEIVER);
if (NS_WARN_IF(!aWindowId)) {
return NS_ERROR_INVALID_POINTER;
}
if (aRole == nsIPresentationService::ROLE_CONTROLLER) {
return mControllerSessionIdManager.GetWindowId(aSessionId, aWindowId);
}
return mReceiverSessionIdManager.GetWindowId(aSessionId, aWindowId);
}
void AddRespondingSessionId(uint64_t aWindowId,
const nsAString& aSessionId,
uint8_t aRole)
{
MOZ_ASSERT(aRole == nsIPresentationService::ROLE_CONTROLLER ||
aRole == nsIPresentationService::ROLE_RECEIVER);
if (aRole == nsIPresentationService::ROLE_CONTROLLER) {
mControllerSessionIdManager.AddSessionId(aWindowId, aSessionId);
} else {
mReceiverSessionIdManager.AddSessionId(aWindowId, aSessionId);
}
}
void RemoveRespondingSessionId(const nsAString& aSessionId,
uint8_t aRole)
{
MOZ_ASSERT(aRole == nsIPresentationService::ROLE_CONTROLLER ||
aRole == nsIPresentationService::ROLE_RECEIVER);
if (aRole == nsIPresentationService::ROLE_CONTROLLER) {
mControllerSessionIdManager.RemoveSessionId(aSessionId);
} else {
mReceiverSessionIdManager.RemoveSessionId(aSessionId);
}
}
nsresult UpdateWindowIdBySessionIdInternal(const nsAString& aSessionId,
uint8_t aRole,
const uint64_t aWindowId)
{
MOZ_ASSERT(aRole == nsIPresentationService::ROLE_CONTROLLER ||
aRole == nsIPresentationService::ROLE_RECEIVER);
if (aRole == nsIPresentationService::ROLE_CONTROLLER) {
return mControllerSessionIdManager.UpdateWindowId(aSessionId, aWindowId);
}
return mReceiverSessionIdManager.UpdateWindowId(aSessionId, aWindowId);
}
// Store the responding listener based on the window ID of the (in-process or
// OOP) receiver page.
nsRefPtrHashtable<nsUint64HashKey, nsIPresentationRespondingListener>
mRespondingListeners;
// Store the mapping between the window ID of the in-process and OOP page and the ID
// of the responding session. It's used for both controller and receiver page
// to retrieve the correspondent session ID. Besides, also keep the mapping
// between the responding session ID and the window ID to help look up the
// window ID.
SessionIdManager mControllerSessionIdManager;
SessionIdManager mReceiverSessionIdManager;
nsRefPtrHashtable<nsStringHashKey, T> mSessionInfoAtController;
nsRefPtrHashtable<nsStringHashKey, T> mSessionInfoAtReceiver;
AvailabilityManager mAvailabilityManager;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_PresentationServiceBase_h

File diff suppressed because it is too large Load diff

View file

@ -1,304 +0,0 @@
/* -*- 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
#include "base/process.h"
#include "mozilla/dom/nsIContentParent.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/PromiseNativeHandler.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/RefPtr.h"
#include "nsCOMPtr.h"
#include "nsINetworkInfoService.h"
#include "nsIPresentationControlChannel.h"
#include "nsIPresentationDevice.h"
#include "nsIPresentationListener.h"
#include "nsIPresentationService.h"
#include "nsIPresentationSessionTransport.h"
#include "nsIPresentationSessionTransportBuilder.h"
#include "nsIServerSocket.h"
#include "nsITimer.h"
#include "nsString.h"
#include "PresentationCallbacks.h"
namespace mozilla {
namespace dom {
class PresentationSessionInfo : public nsIPresentationSessionTransportCallback
, public nsIPresentationControlChannelListener
, public nsIPresentationSessionTransportBuilderListener
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIPRESENTATIONSESSIONTRANSPORTCALLBACK
NS_DECL_NSIPRESENTATIONSESSIONTRANSPORTBUILDERLISTENER
PresentationSessionInfo(const nsAString& aUrl,
const nsAString& aSessionId,
const uint8_t aRole)
: mUrl(aUrl)
, mSessionId(aSessionId)
, mIsResponderReady(false)
, mIsTransportReady(false)
, mState(nsIPresentationSessionListener::STATE_CONNECTING)
, mReason(NS_OK)
{
MOZ_ASSERT(!mUrl.IsEmpty());
MOZ_ASSERT(!mSessionId.IsEmpty());
MOZ_ASSERT(aRole == nsIPresentationService::ROLE_CONTROLLER ||
aRole == nsIPresentationService::ROLE_RECEIVER);
mRole = aRole;
}
virtual nsresult Init(nsIPresentationControlChannel* aControlChannel);
const nsAString& GetUrl() const
{
return mUrl;
}
const nsAString& GetSessionId() const
{
return mSessionId;
}
uint8_t GetRole() const
{
return mRole;
}
nsresult SetListener(nsIPresentationSessionListener* aListener);
void SetDevice(nsIPresentationDevice* aDevice)
{
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(const nsAString& aData);
nsresult SendBinaryMsg(const nsACString& aData);
nsresult SendBlob(nsIDOMBlob* aBlob);
nsresult Close(nsresult aReason,
uint32_t aState);
nsresult OnTerminate(nsIPresentationControlChannel* aControlChannel);
nsresult ReplyError(nsresult aReason);
virtual bool IsAccessible(base::ProcessId aProcessId);
void SetTransportBuilderConstructor(
nsIPresentationTransportBuilderConstructor* aBuilderConstructor)
{
mBuilderConstructor = aBuilderConstructor;
}
protected:
virtual ~PresentationSessionInfo()
{
Shutdown(NS_OK);
}
virtual void Shutdown(nsresult aReason);
nsresult ReplySuccess();
bool IsSessionReady()
{
return mIsResponderReady && mIsTransportReady;
}
virtual nsresult UntrackFromService();
void SetStateWithReason(uint32_t aState, nsresult aReason)
{
if (mState == aState) {
return;
}
mState = aState;
mReason = aReason;
// Notify session state change.
if (mListener) {
DebugOnly<nsresult> rv =
mListener->NotifyStateChange(mSessionId, mState, aReason);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "NotifyStateChanged");
}
}
void ContinueTermination();
void ResetBuilder()
{
mBuilder = nullptr;
}
// Should be nsIPresentationChannelDescription::TYPE_TCP/TYPE_DATACHANNEL
uint8_t mTransportType = 0;
nsPIDOMWindowInner* GetWindow();
nsString mUrl;
nsString mSessionId;
// mRole should be nsIPresentationService::ROLE_CONTROLLER
// or nsIPresentationService::ROLE_RECEIVER.
uint8_t mRole;
bool mIsResponderReady;
bool mIsTransportReady;
bool mIsOnTerminating = false;
uint32_t mState; // CONNECTED, CLOSED, TERMINATED
nsresult mReason;
nsCOMPtr<nsIPresentationSessionListener> mListener;
nsCOMPtr<nsIPresentationDevice> mDevice;
nsCOMPtr<nsIPresentationSessionTransport> mTransport;
nsCOMPtr<nsIPresentationControlChannel> mControlChannel;
nsCOMPtr<nsIPresentationSessionTransportBuilder> mBuilder;
nsCOMPtr<nsIPresentationTransportBuilderConstructor> mBuilderConstructor;
};
// Session info with controlling browsing context (sender side) behaviors.
class PresentationControllingInfo final : public PresentationSessionInfo
, public nsIServerSocketListener
, public nsIListNetworkAddressesListener
{
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIPRESENTATIONCONTROLCHANNELLISTENER
NS_DECL_NSISERVERSOCKETLISTENER
NS_DECL_NSILISTNETWORKADDRESSESLISTENER
NS_DECL_NSIPRESENTATIONSESSIONTRANSPORTCALLBACK
PresentationControllingInfo(const nsAString& aUrl,
const nsAString& aSessionId)
: PresentationSessionInfo(aUrl,
aSessionId,
nsIPresentationService::ROLE_CONTROLLER)
{}
nsresult Init(nsIPresentationControlChannel* aControlChannel) override;
nsresult Reconnect(nsIPresentationServiceCallback* aCallback);
nsresult BuildTransport();
private:
~PresentationControllingInfo()
{
Shutdown(NS_OK);
}
void Shutdown(nsresult aReason) override;
nsresult GetAddress();
nsresult OnGetAddress(const nsACString& aAddress);
nsresult ContinueReconnect();
nsresult NotifyReconnectResult(nsresult aStatus);
nsCOMPtr<nsIServerSocket> mServerSocket;
nsCOMPtr<nsIPresentationServiceCallback> mReconnectCallback;
bool mIsReconnecting = false;
bool mDoReconnectAfterClose = false;
};
// Session info with presenting browsing context (receiver side) behaviors.
class PresentationPresentingInfo final : public PresentationSessionInfo
, public PromiseNativeHandler
, public nsITimerCallback
{
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIPRESENTATIONCONTROLCHANNELLISTENER
NS_DECL_NSITIMERCALLBACK
PresentationPresentingInfo(const nsAString& aUrl,
const nsAString& aSessionId,
nsIPresentationDevice* aDevice)
: PresentationSessionInfo(aUrl,
aSessionId,
nsIPresentationService::ROLE_RECEIVER)
{
MOZ_ASSERT(aDevice);
SetDevice(aDevice);
}
nsresult Init(nsIPresentationControlChannel* aControlChannel) override;
nsresult NotifyResponderReady();
nsresult NotifyResponderFailure();
NS_IMETHODIMP OnSessionTransport(nsIPresentationSessionTransport* transport) override;
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);
}
bool IsAccessible(base::ProcessId aProcessId) override;
nsresult DoReconnect();
private:
~PresentationPresentingInfo()
{
Shutdown(NS_OK);
}
void Shutdown(nsresult aReason) override;
nsresult InitTransportAndSendAnswer();
nsresult UntrackFromService() override;
NS_IMETHODIMP
FlushPendingEvents(nsIPresentationDataChannelSessionTransportBuilder* builder);
bool mHasFlushPendingEvents = false;
RefPtr<PresentationResponderLoadingCallback> mLoadingCallback;
nsCOMPtr<nsITimer> mTimer;
nsCOMPtr<nsIPresentationChannelDescription> mRequesterDescription;
nsTArray<nsString> mPendingCandidates;
RefPtr<Promise> mPromise;
// The content parent communicating with the content process which the OOP
// receiver page belongs to.
nsCOMPtr<nsIContentParent> mContentParent;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_PresentationSessionInfo_h

View file

@ -1,72 +0,0 @@
/* -*- 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/. */
#include "PresentationSessionRequest.h"
#include "nsIPresentationControlChannel.h"
#include "nsIPresentationDevice.h"
namespace mozilla {
namespace dom {
NS_IMPL_ISUPPORTS(PresentationSessionRequest, nsIPresentationSessionRequest)
PresentationSessionRequest::PresentationSessionRequest(nsIPresentationDevice* aDevice,
const nsAString& aUrl,
const nsAString& aPresentationId,
nsIPresentationControlChannel* aControlChannel)
: mUrl(aUrl)
, mPresentationId(aPresentationId)
, mDevice(aDevice)
, mControlChannel(aControlChannel)
{
}
PresentationSessionRequest::~PresentationSessionRequest()
{
}
// nsIPresentationSessionRequest
NS_IMETHODIMP
PresentationSessionRequest::GetDevice(nsIPresentationDevice** aRetVal)
{
NS_ENSURE_ARG_POINTER(aRetVal);
nsCOMPtr<nsIPresentationDevice> device = mDevice;
device.forget(aRetVal);
return NS_OK;
}
NS_IMETHODIMP
PresentationSessionRequest::GetUrl(nsAString& aRetVal)
{
aRetVal = mUrl;
return NS_OK;
}
NS_IMETHODIMP
PresentationSessionRequest::GetPresentationId(nsAString& aRetVal)
{
aRetVal = mPresentationId;
return NS_OK;
}
NS_IMETHODIMP
PresentationSessionRequest::GetControlChannel(nsIPresentationControlChannel** aRetVal)
{
NS_ENSURE_ARG_POINTER(aRetVal);
nsCOMPtr<nsIPresentationControlChannel> controlChannel = mControlChannel;
controlChannel.forget(aRetVal);
return NS_OK;
}
} // namespace dom
} // namespace mozilla

View file

@ -1,41 +0,0 @@
/* -*- 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_PresentationSessionRequest_h__
#define mozilla_dom_PresentationSessionRequest_h__
#include "nsIPresentationSessionRequest.h"
#include "nsCOMPtr.h"
#include "nsString.h"
namespace mozilla {
namespace dom {
class PresentationSessionRequest final : public nsIPresentationSessionRequest
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIPRESENTATIONSESSIONREQUEST
PresentationSessionRequest(nsIPresentationDevice* aDevice,
const nsAString& aUrl,
const nsAString& aPresentationId,
nsIPresentationControlChannel* aControlChannel);
private:
virtual ~PresentationSessionRequest();
nsString mUrl;
nsString mPresentationId;
nsCOMPtr<nsIPresentationDevice> mDevice;
nsCOMPtr<nsIPresentationControlChannel> mControlChannel;
};
} // namespace dom
} // namespace mozilla
#endif /* mozilla_dom_PresentationSessionRequest_h__ */

View file

@ -1,589 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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/. */
#include "nsArrayUtils.h"
#include "nsIAsyncStreamCopier.h"
#include "nsIInputStreamPump.h"
#include "nsIMultiplexInputStream.h"
#include "nsIMutableArray.h"
#include "nsIOutputStream.h"
#include "nsIPresentationControlChannel.h"
#include "nsIScriptableInputStream.h"
#include "nsISocketTransport.h"
#include "nsISocketTransportService.h"
#include "nsISupportsPrimitives.h"
#include "nsNetUtil.h"
#include "nsQueryObject.h"
#include "nsServiceManagerUtils.h"
#include "nsStreamUtils.h"
#include "nsThreadUtils.h"
#include "PresentationLog.h"
#include "PresentationTCPSessionTransport.h"
#define BUFFER_SIZE 65536
using namespace mozilla;
using namespace mozilla::dom;
class CopierCallbacks final : public nsIRequestObserver
{
public:
explicit CopierCallbacks(PresentationTCPSessionTransport* aTransport)
: mOwner(aTransport)
{}
NS_DECL_ISUPPORTS
NS_DECL_NSIREQUESTOBSERVER
private:
~CopierCallbacks() {}
RefPtr<PresentationTCPSessionTransport> mOwner;
};
NS_IMPL_ISUPPORTS(CopierCallbacks, nsIRequestObserver)
NS_IMETHODIMP
CopierCallbacks::OnStartRequest(nsIRequest* aRequest, nsISupports* aContext)
{
return NS_OK;
}
NS_IMETHODIMP
CopierCallbacks::OnStopRequest(nsIRequest* aRequest, nsISupports* aContext, nsresult aStatus)
{
mOwner->NotifyCopyComplete(aStatus);
return NS_OK;
}
NS_IMPL_CYCLE_COLLECTION(PresentationTCPSessionTransport, mTransport,
mSocketInputStream, mSocketOutputStream,
mInputStreamPump, mInputStreamScriptable,
mMultiplexStream, mMultiplexStreamCopier, mCallback)
NS_IMPL_CYCLE_COLLECTING_ADDREF(PresentationTCPSessionTransport)
NS_IMPL_CYCLE_COLLECTING_RELEASE(PresentationTCPSessionTransport)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PresentationTCPSessionTransport)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIPresentationSessionTransport)
NS_INTERFACE_MAP_ENTRY(nsIInputStreamCallback)
NS_INTERFACE_MAP_ENTRY(nsIPresentationSessionTransport)
NS_INTERFACE_MAP_ENTRY(nsIPresentationSessionTransportBuilder)
NS_INTERFACE_MAP_ENTRY(nsIPresentationTCPSessionTransportBuilder)
NS_INTERFACE_MAP_ENTRY(nsIRequestObserver)
NS_INTERFACE_MAP_ENTRY(nsIStreamListener)
NS_INTERFACE_MAP_ENTRY(nsITransportEventSink)
NS_INTERFACE_MAP_END
PresentationTCPSessionTransport::PresentationTCPSessionTransport()
: mReadyState(ReadyState::CLOSED)
, mAsyncCopierActive(false)
, mCloseStatus(NS_OK)
, mDataNotificationEnabled(false)
{
}
PresentationTCPSessionTransport::~PresentationTCPSessionTransport()
{
}
NS_IMETHODIMP
PresentationTCPSessionTransport::BuildTCPSenderTransport(nsISocketTransport* aTransport,
nsIPresentationSessionTransportBuilderListener* aListener)
{
if (NS_WARN_IF(!aTransport)) {
return NS_ERROR_INVALID_ARG;
}
mTransport = aTransport;
if (NS_WARN_IF(!aListener)) {
return NS_ERROR_INVALID_ARG;
}
mListener = aListener;
nsresult rv = CreateStream();
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
mRole = nsIPresentationService::ROLE_CONTROLLER;
nsCOMPtr<nsIPresentationSessionTransport> sessionTransport = do_QueryObject(this);
nsCOMPtr<nsIRunnable> onSessionTransportRunnable =
NewRunnableMethod
<nsIPresentationSessionTransport*>(mListener,
&nsIPresentationSessionTransportBuilderListener::OnSessionTransport,
sessionTransport);
NS_DispatchToCurrentThread(onSessionTransportRunnable.forget());
nsCOMPtr<nsIRunnable> setReadyStateRunnable =
NewRunnableMethod<ReadyState>(this,
&PresentationTCPSessionTransport::SetReadyState,
ReadyState::OPEN);
return NS_DispatchToCurrentThread(setReadyStateRunnable.forget());
}
NS_IMETHODIMP
PresentationTCPSessionTransport::BuildTCPReceiverTransport(nsIPresentationChannelDescription* aDescription,
nsIPresentationSessionTransportBuilderListener* aListener)
{
if (NS_WARN_IF(!aDescription)) {
return NS_ERROR_INVALID_ARG;
}
if (NS_WARN_IF(!aListener)) {
return NS_ERROR_INVALID_ARG;
}
mListener = aListener;
uint16_t serverPort;
nsresult rv = aDescription->GetTcpPort(&serverPort);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
nsCOMPtr<nsIArray> serverHosts;
rv = aDescription->GetTcpAddress(getter_AddRefs(serverHosts));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
// TODO bug 1228504 Take all IP addresses in PresentationChannelDescription
// into account. And at the first stage Presentation API is only exposed on
// Firefox OS where the first IP appears enough for most scenarios.
nsCOMPtr<nsISupportsCString> supportStr = do_QueryElementAt(serverHosts, 0);
if (NS_WARN_IF(!supportStr)) {
return NS_ERROR_INVALID_ARG;
}
nsAutoCString serverHost;
supportStr->GetData(serverHost);
if (serverHost.IsEmpty()) {
return NS_ERROR_INVALID_ARG;
}
PRES_DEBUG("%s:ServerHost[%s],ServerPort[%d]\n", __func__, serverHost.get(), serverPort);
SetReadyState(ReadyState::CONNECTING);
nsCOMPtr<nsISocketTransportService> sts =
do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID);
if (NS_WARN_IF(!sts)) {
return NS_ERROR_NOT_AVAILABLE;
}
rv = sts->CreateTransport(nullptr, 0, serverHost, serverPort, nullptr,
getter_AddRefs(mTransport));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
nsCOMPtr<nsIThread> mainThread;
NS_GetMainThread(getter_AddRefs(mainThread));
mTransport->SetEventSink(this, mainThread);
rv = CreateStream();
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
mRole = nsIPresentationService::ROLE_RECEIVER;
nsCOMPtr<nsIPresentationSessionTransport> sessionTransport = do_QueryObject(this);
nsCOMPtr<nsIRunnable> runnable =
NewRunnableMethod
<nsIPresentationSessionTransport*>(mListener,
&nsIPresentationSessionTransportBuilderListener::OnSessionTransport,
sessionTransport);
return NS_DispatchToCurrentThread(runnable.forget());
}
nsresult
PresentationTCPSessionTransport::CreateStream()
{
nsresult rv = mTransport->OpenInputStream(0, 0, 0, getter_AddRefs(mSocketInputStream));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = mTransport->OpenOutputStream(nsITransport::OPEN_UNBUFFERED, 0, 0, getter_AddRefs(mSocketOutputStream));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
// If the other side is not listening, we will get an |onInputStreamReady|
// callback where |available| raises to indicate the connection was refused.
nsCOMPtr<nsIAsyncInputStream> asyncStream = do_QueryInterface(mSocketInputStream);
if (NS_WARN_IF(!asyncStream)) {
return NS_ERROR_NOT_AVAILABLE;
}
nsCOMPtr<nsIThread> mainThread;
NS_GetMainThread(getter_AddRefs(mainThread));
rv = asyncStream->AsyncWait(this, nsIAsyncInputStream::WAIT_CLOSURE_ONLY, 0, mainThread);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
mInputStreamScriptable = do_CreateInstance("@mozilla.org/scriptableinputstream;1", &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = mInputStreamScriptable->Init(mSocketInputStream);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
mMultiplexStream = do_CreateInstance("@mozilla.org/io/multiplex-input-stream;1", &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
mMultiplexStreamCopier = do_CreateInstance("@mozilla.org/network/async-stream-copier;1", &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
nsCOMPtr<nsISocketTransportService> sts =
do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID);
if (NS_WARN_IF(!sts)) {
return NS_ERROR_NOT_AVAILABLE;
}
nsCOMPtr<nsIEventTarget> target = do_QueryInterface(sts);
rv = mMultiplexStreamCopier->Init(mMultiplexStream,
mSocketOutputStream,
target,
true, /* source buffered */
false, /* sink buffered */
BUFFER_SIZE,
false, /* close source */
false); /* close sink */
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
nsresult
PresentationTCPSessionTransport::CreateInputStreamPump()
{
if (NS_WARN_IF(mInputStreamPump)) {
return NS_OK;
}
nsresult rv;
mInputStreamPump = do_CreateInstance(NS_INPUTSTREAMPUMP_CONTRACTID, &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = mInputStreamPump->Init(mSocketInputStream, -1, -1, 0, 0, false);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
rv = mInputStreamPump->AsyncRead(this, nullptr);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
return NS_OK;
}
NS_IMETHODIMP
PresentationTCPSessionTransport::EnableDataNotification()
{
if (NS_WARN_IF(!mCallback)) {
return NS_ERROR_DOM_INVALID_STATE_ERR;
}
if (mDataNotificationEnabled) {
return NS_OK;
}
mDataNotificationEnabled = true;
if (IsReadyToNotifyData()) {
return CreateInputStreamPump();
}
return NS_OK;
}
// nsIPresentationSessionTransportBuilderListener
NS_IMETHODIMP
PresentationTCPSessionTransport::GetCallback(nsIPresentationSessionTransportCallback** aCallback)
{
nsCOMPtr<nsIPresentationSessionTransportCallback> callback = mCallback;
callback.forget(aCallback);
return NS_OK;
}
NS_IMETHODIMP
PresentationTCPSessionTransport::SetCallback(nsIPresentationSessionTransportCallback* aCallback)
{
mCallback = aCallback;
if (!!mCallback && ReadyState::OPEN == mReadyState) {
// Notify the transport channel is ready.
Unused << NS_WARN_IF(NS_FAILED(mCallback->NotifyTransportReady()));
}
return NS_OK;
}
NS_IMETHODIMP
PresentationTCPSessionTransport::GetSelfAddress(nsINetAddr** aSelfAddress)
{
if (NS_WARN_IF(!mTransport)) {
return NS_ERROR_DOM_INVALID_STATE_ERR;
}
return mTransport->GetScriptableSelfAddr(aSelfAddress);
}
void
PresentationTCPSessionTransport::EnsureCopying()
{
if (mAsyncCopierActive) {
return;
}
mAsyncCopierActive = true;
RefPtr<CopierCallbacks> callbacks = new CopierCallbacks(this);
Unused << NS_WARN_IF(NS_FAILED(mMultiplexStreamCopier->AsyncCopy(callbacks, nullptr)));
}
void
PresentationTCPSessionTransport::NotifyCopyComplete(nsresult aStatus)
{
mAsyncCopierActive = false;
mMultiplexStream->RemoveStream(0);
if (NS_WARN_IF(NS_FAILED(aStatus))) {
if (mReadyState != ReadyState::CLOSED) {
mCloseStatus = aStatus;
SetReadyState(ReadyState::CLOSED);
}
return;
}
uint32_t count;
nsresult rv = mMultiplexStream->GetCount(&count);
if (NS_WARN_IF(NS_FAILED(rv))) {
return;
}
if (count) {
EnsureCopying();
return;
}
if (mReadyState == ReadyState::CLOSING) {
mSocketOutputStream->Close();
mCloseStatus = NS_OK;
SetReadyState(ReadyState::CLOSED);
}
}
NS_IMETHODIMP
PresentationTCPSessionTransport::Send(const nsAString& aData)
{
if (NS_WARN_IF(mReadyState != ReadyState::OPEN)) {
return NS_ERROR_DOM_INVALID_STATE_ERR;
}
nsresult rv;
nsCOMPtr<nsIStringInputStream> stream =
do_CreateInstance(NS_STRINGINPUTSTREAM_CONTRACTID, &rv);
if(NS_WARN_IF(NS_FAILED(rv))) {
return NS_ERROR_DOM_INVALID_STATE_ERR;
}
NS_ConvertUTF16toUTF8 msgString(aData);
rv = stream->SetData(msgString.BeginReading(), msgString.Length());
if(NS_WARN_IF(NS_FAILED(rv))) {
return NS_ERROR_DOM_INVALID_STATE_ERR;
}
mMultiplexStream->AppendStream(stream);
EnsureCopying();
return NS_OK;
}
NS_IMETHODIMP
PresentationTCPSessionTransport::SendBinaryMsg(const nsACString& aData)
{
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
}
NS_IMETHODIMP
PresentationTCPSessionTransport::SendBlob(nsIDOMBlob* aBlob)
{
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
}
NS_IMETHODIMP
PresentationTCPSessionTransport::Close(nsresult aReason)
{
PRES_DEBUG("%s:reason[%x]\n", __func__, aReason);
if (mReadyState == ReadyState::CLOSED || mReadyState == ReadyState::CLOSING) {
return NS_OK;
}
mCloseStatus = aReason;
SetReadyState(ReadyState::CLOSING);
uint32_t count = 0;
mMultiplexStream->GetCount(&count);
if (!count) {
mSocketOutputStream->Close();
}
mSocketInputStream->Close();
mDataNotificationEnabled = false;
mListener = nullptr;
return NS_OK;
}
void
PresentationTCPSessionTransport::SetReadyState(ReadyState aReadyState)
{
mReadyState = aReadyState;
if (mReadyState == ReadyState::OPEN) {
if (IsReadyToNotifyData()) {
CreateInputStreamPump();
}
if (NS_WARN_IF(!mCallback)) {
return;
}
// Notify the transport channel is ready.
Unused << NS_WARN_IF(NS_FAILED(mCallback->NotifyTransportReady()));
} else if (mReadyState == ReadyState::CLOSED && mCallback) {
if (NS_WARN_IF(!mCallback)) {
return;
}
// Notify the transport channel has been shut down.
Unused <<
NS_WARN_IF(NS_FAILED(mCallback->NotifyTransportClosed(mCloseStatus)));
mCallback = nullptr;
}
}
// nsITransportEventSink
NS_IMETHODIMP
PresentationTCPSessionTransport::OnTransportStatus(nsITransport* aTransport,
nsresult aStatus,
int64_t aProgress,
int64_t aProgressMax)
{
PRES_DEBUG("%s:aStatus[%x]\n", __func__, aStatus);
MOZ_ASSERT(NS_IsMainThread());
if (aStatus != NS_NET_STATUS_CONNECTED_TO) {
return NS_OK;
}
SetReadyState(ReadyState::OPEN);
return NS_OK;
}
// nsIInputStreamCallback
NS_IMETHODIMP
PresentationTCPSessionTransport::OnInputStreamReady(nsIAsyncInputStream* aStream)
{
MOZ_ASSERT(NS_IsMainThread());
// Only used for detecting if the connection was refused.
uint64_t dummy;
nsresult rv = aStream->Available(&dummy);
if (NS_WARN_IF(NS_FAILED(rv))) {
if (mReadyState != ReadyState::CLOSED) {
mCloseStatus = NS_ERROR_CONNECTION_REFUSED;
SetReadyState(ReadyState::CLOSED);
}
}
return NS_OK;
}
// nsIRequestObserver
NS_IMETHODIMP
PresentationTCPSessionTransport::OnStartRequest(nsIRequest* aRequest,
nsISupports* aContext)
{
// Do nothing.
return NS_OK;
}
NS_IMETHODIMP
PresentationTCPSessionTransport::OnStopRequest(nsIRequest* aRequest,
nsISupports* aContext,
nsresult aStatusCode)
{
PRES_DEBUG("%s:aStatusCode[%x]\n", __func__, aStatusCode);
MOZ_ASSERT(NS_IsMainThread());
uint32_t count;
nsresult rv = mMultiplexStream->GetCount(&count);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
mInputStreamPump = nullptr;
if (count != 0 && NS_SUCCEEDED(aStatusCode)) {
// If we have some buffered output still, and status is not an error, the
// other side has done a half-close, but we don't want to be in the close
// state until we are done sending everything that was buffered. We also
// don't want to call |NotifyTransportClosed| yet.
return NS_OK;
}
// We call this even if there is no error.
if (mReadyState != ReadyState::CLOSED) {
mCloseStatus = aStatusCode;
SetReadyState(ReadyState::CLOSED);
}
return NS_OK;
}
// nsIStreamListener
NS_IMETHODIMP
PresentationTCPSessionTransport::OnDataAvailable(nsIRequest* aRequest,
nsISupports* aContext,
nsIInputStream* aStream,
uint64_t aOffset,
uint32_t aCount)
{
MOZ_ASSERT(NS_IsMainThread());
if (NS_WARN_IF(!mCallback)) {
return NS_ERROR_NOT_AVAILABLE;
}
nsCString data;
nsresult rv = mInputStreamScriptable->ReadBytes(aCount, data);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
// Pass the incoming data to the listener.
return mCallback->NotifyData(data, false);
}

View file

@ -1,110 +0,0 @@
/* -*- 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_PresentationSessionTransport_h
#define mozilla_dom_PresentationSessionTransport_h
#include "mozilla/RefPtr.h"
#include "nsCOMPtr.h"
#include "nsIAsyncInputStream.h"
#include "nsIPresentationSessionTransport.h"
#include "nsIPresentationSessionTransportBuilder.h"
#include "nsIStreamListener.h"
#include "nsISupportsImpl.h"
#include "nsITransport.h"
class nsISocketTransport;
class nsIInputStreamPump;
class nsIScriptableInputStream;
class nsIMultiplexInputStream;
class nsIAsyncStreamCopier;
class nsIInputStream;
namespace mozilla {
namespace dom {
/*
* App-to-App transport channel for the presentation session. It's usually
* initialized with an |InitWithSocketTransport| call if at the presenting sender
* side; whereas it's initialized with an |InitWithChannelDescription| if at the
* presenting receiver side. The lifetime is managed in either
* |PresentationControllingInfo| (sender side) or |PresentationPresentingInfo|
* (receiver side) in PresentationSessionInfo.cpp.
*/
class PresentationTCPSessionTransport final : public nsIPresentationSessionTransport
, public nsIPresentationTCPSessionTransportBuilder
, public nsITransportEventSink
, public nsIInputStreamCallback
, public nsIStreamListener
{
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(PresentationTCPSessionTransport,
nsIPresentationSessionTransport)
NS_DECL_NSIPRESENTATIONSESSIONTRANSPORT
NS_DECL_NSIPRESENTATIONSESSIONTRANSPORTBUILDER
NS_DECL_NSIPRESENTATIONTCPSESSIONTRANSPORTBUILDER
NS_DECL_NSITRANSPORTEVENTSINK
NS_DECL_NSIINPUTSTREAMCALLBACK
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER
PresentationTCPSessionTransport();
void NotifyCopyComplete(nsresult aStatus);
private:
~PresentationTCPSessionTransport();
nsresult CreateStream();
nsresult CreateInputStreamPump();
void EnsureCopying();
enum class ReadyState {
CONNECTING,
OPEN,
CLOSING,
CLOSED
};
void SetReadyState(ReadyState aReadyState);
bool IsReadyToNotifyData()
{
return mDataNotificationEnabled && mReadyState == ReadyState::OPEN;
}
ReadyState mReadyState;
bool mAsyncCopierActive;
nsresult mCloseStatus;
bool mDataNotificationEnabled;
uint8_t mRole = 0;
// Raw socket streams
nsCOMPtr<nsISocketTransport> mTransport;
nsCOMPtr<nsIInputStream> mSocketInputStream;
nsCOMPtr<nsIOutputStream> mSocketOutputStream;
// Input stream machinery
nsCOMPtr<nsIInputStreamPump> mInputStreamPump;
nsCOMPtr<nsIScriptableInputStream> mInputStreamScriptable;
// Output stream machinery
nsCOMPtr<nsIMultiplexInputStream> mMultiplexStream;
nsCOMPtr<nsIAsyncStreamCopier> mMultiplexStreamCopier;
nsCOMPtr<nsIPresentationSessionTransportCallback> mCallback;
nsCOMPtr<nsIPresentationSessionTransportBuilderListener> mListener;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_PresentationSessionTransport_h

View file

@ -1,73 +0,0 @@
/* -*- 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/. */
#include "PresentationTerminateRequest.h"
#include "nsIPresentationControlChannel.h"
#include "nsIPresentationDevice.h"
namespace mozilla {
namespace dom {
NS_IMPL_ISUPPORTS(PresentationTerminateRequest, nsIPresentationTerminateRequest)
PresentationTerminateRequest::PresentationTerminateRequest(
nsIPresentationDevice* aDevice,
const nsAString& aPresentationId,
nsIPresentationControlChannel* aControlChannel,
bool aIsFromReceiver)
: mPresentationId(aPresentationId)
, mDevice(aDevice)
, mControlChannel(aControlChannel)
, mIsFromReceiver(aIsFromReceiver)
{
}
PresentationTerminateRequest::~PresentationTerminateRequest()
{
}
// nsIPresentationTerminateRequest
NS_IMETHODIMP
PresentationTerminateRequest::GetDevice(nsIPresentationDevice** aRetVal)
{
NS_ENSURE_ARG_POINTER(aRetVal);
nsCOMPtr<nsIPresentationDevice> device = mDevice;
device.forget(aRetVal);
return NS_OK;
}
NS_IMETHODIMP
PresentationTerminateRequest::GetPresentationId(nsAString& aRetVal)
{
aRetVal = mPresentationId;
return NS_OK;
}
NS_IMETHODIMP
PresentationTerminateRequest::GetControlChannel(
nsIPresentationControlChannel** aRetVal)
{
NS_ENSURE_ARG_POINTER(aRetVal);
nsCOMPtr<nsIPresentationControlChannel> controlChannel = mControlChannel;
controlChannel.forget(aRetVal);
return NS_OK;
}
NS_IMETHODIMP
PresentationTerminateRequest::GetIsFromReceiver(bool* aRetVal)
{
*aRetVal = mIsFromReceiver;
return NS_OK;
}
} // namespace dom
} // namespace mozilla

View file

@ -1,41 +0,0 @@
/* -*- 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_PresentationTerminateRequest_h__
#define mozilla_dom_PresentationTerminateRequest_h__
#include "nsIPresentationTerminateRequest.h"
#include "nsCOMPtr.h"
#include "nsString.h"
namespace mozilla {
namespace dom {
class PresentationTerminateRequest final : public nsIPresentationTerminateRequest
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIPRESENTATIONTERMINATEREQUEST
PresentationTerminateRequest(nsIPresentationDevice* aDevice,
const nsAString& aPresentationId,
nsIPresentationControlChannel* aControlChannel,
bool aIsFromReceiver);
private:
virtual ~PresentationTerminateRequest();
nsString mPresentationId;
nsCOMPtr<nsIPresentationDevice> mDevice;
nsCOMPtr<nsIPresentationControlChannel> mControlChannel;
bool mIsFromReceiver;
};
} // namespace dom
} // namespace mozilla
#endif /* mozilla_dom_PresentationTerminateRequest_h__ */

View file

@ -1,85 +0,0 @@
/* -*- 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/. */
#include "PresentationTransportBuilderConstructor.h"
#include "nsComponentManagerUtils.h"
#include "nsIPresentationControlChannel.h"
#include "nsIPresentationSessionTransport.h"
#include "nsXULAppAPI.h"
namespace mozilla {
namespace dom {
NS_IMPL_ISUPPORTS(DummyPresentationTransportBuilderConstructor,
nsIPresentationTransportBuilderConstructor)
NS_IMETHODIMP
DummyPresentationTransportBuilderConstructor::CreateTransportBuilder(
uint8_t aType,
nsIPresentationSessionTransportBuilder** aRetval)
{
MOZ_ASSERT(false, "Unexpected to be invoked.");
return NS_OK;
}
NS_IMPL_ISUPPORTS_INHERITED0(PresentationTransportBuilderConstructor,
DummyPresentationTransportBuilderConstructor)
/* static */ already_AddRefed<nsIPresentationTransportBuilderConstructor>
PresentationTransportBuilderConstructor::Create()
{
nsCOMPtr<nsIPresentationTransportBuilderConstructor> constructor;
if (XRE_IsContentProcess()) {
constructor = new DummyPresentationTransportBuilderConstructor();
} else {
constructor = new PresentationTransportBuilderConstructor();
}
return constructor.forget();
}
NS_IMETHODIMP
PresentationTransportBuilderConstructor::CreateTransportBuilder(
uint8_t aType,
nsIPresentationSessionTransportBuilder** aRetval)
{
if (NS_WARN_IF(!aRetval)) {
return NS_ERROR_INVALID_ARG;
}
*aRetval = nullptr;
if (NS_WARN_IF(aType != nsIPresentationChannelDescription::TYPE_TCP &&
aType != nsIPresentationChannelDescription::TYPE_DATACHANNEL)) {
return NS_ERROR_INVALID_ARG;
}
if (XRE_IsContentProcess()) {
MOZ_ASSERT(false,
"CreateTransportBuilder can only be invoked in parent process.");
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIPresentationSessionTransportBuilder> builder;
if (aType == nsIPresentationChannelDescription::TYPE_TCP) {
builder =
do_CreateInstance(PRESENTATION_TCP_SESSION_TRANSPORT_CONTRACTID);
} else {
builder =
do_CreateInstance("@mozilla.org/presentation/datachanneltransportbuilder;1");
}
if (NS_WARN_IF(!builder)) {
return NS_ERROR_DOM_OPERATION_ERR;
}
builder.forget(aRetval);
return NS_OK;
}
} // namespace dom
} // namespace mozilla

View file

@ -1,48 +0,0 @@
/* -*- 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_PresentationTransportBuilderConstructor_h
#define mozilla_dom_PresentationTransportBuilderConstructor_h
#include "nsCOMPtr.h"
#include "nsIPresentationSessionTransportBuilder.h"
#include "nsISupportsImpl.h"
namespace mozilla {
namespace dom {
class DummyPresentationTransportBuilderConstructor :
public nsIPresentationTransportBuilderConstructor
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIPRESENTATIONTRANSPORTBUILDERCONSTRUCTOR
DummyPresentationTransportBuilderConstructor() = default;
protected:
virtual ~DummyPresentationTransportBuilderConstructor() = default;
};
class PresentationTransportBuilderConstructor final :
public DummyPresentationTransportBuilderConstructor
{
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIPRESENTATIONTRANSPORTBUILDERCONSTRUCTOR
static already_AddRefed<nsIPresentationTransportBuilderConstructor>
Create();
private:
PresentationTransportBuilderConstructor() = default;
virtual ~PresentationTransportBuilderConstructor() = default;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_PresentationTransportBuilderConstructor_h

View file

@ -1,30 +0,0 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.
XPIDL_SOURCES += [
'nsIPresentationControlChannel.idl',
'nsIPresentationControlService.idl',
'nsIPresentationDevice.idl',
'nsIPresentationDeviceManager.idl',
'nsIPresentationDevicePrompt.idl',
'nsIPresentationDeviceProvider.idl',
'nsIPresentationListener.idl',
'nsIPresentationLocalDevice.idl',
'nsIPresentationRequestUIGlue.idl',
'nsIPresentationService.idl',
'nsIPresentationSessionRequest.idl',
'nsIPresentationSessionTransport.idl',
'nsIPresentationSessionTransportBuilder.idl',
'nsIPresentationTerminateRequest.idl',
]
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
XPIDL_SOURCES += [
'nsIPresentationNetworkHelper.idl',
]
XPIDL_MODULE = 'dom_presentation'

View file

@ -1,139 +0,0 @@
/* 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/. */
#include "nsISupports.idl"
interface nsIArray;
interface nsIInputStream;
[scriptable, uuid(ae318e05-2a4e-4f85-95c0-e8b191ad812c)]
interface nsIPresentationChannelDescription: nsISupports
{
const unsigned short TYPE_TCP = 1;
const unsigned short TYPE_DATACHANNEL = 2;
// Type of transport channel.
readonly attribute uint8_t type;
// Addresses for TCP channel (as a list of nsISupportsCString).
// Should only be used while type == TYPE_TCP.
readonly attribute nsIArray tcpAddress;
// Port number for TCP channel.
// Should only be used while type == TYPE_TCP.
readonly attribute uint16_t tcpPort;
// SDP for Data Channel.
// Should only be used while type == TYPE_DATACHANNEL.
readonly attribute DOMString dataChannelSDP;
};
/*
* The callbacks for events on control channel.
*/
[scriptable, uuid(96dd548f-7d0f-43c1-b1ad-28e666cf1e82)]
interface nsIPresentationControlChannelListener: nsISupports
{
/*
* Callback for receiving offer from remote endpoint.
* @param offer The received offer.
*/
void onOffer(in nsIPresentationChannelDescription offer);
/*
* Callback for receiving answer from remote endpoint.
* @param answer The received answer.
*/
void onAnswer(in nsIPresentationChannelDescription answer);
/*
* Callback for receiving ICE candidate from remote endpoint.
* @param answer The received answer.
*/
void onIceCandidate(in DOMString candidate);
/*
* The callback for notifying channel connected. This should be async called
* after nsIPresentationDevice::establishControlChannel.
*/
void notifyConnected();
/*
* The callback for notifying channel disconnected.
* @param reason The reason of channel close, NS_OK represents normal close.
*/
void notifyDisconnected(in nsresult reason);
/*
* The callback for notifying the reconnect command is acknowledged.
*/
void notifyReconnected();
};
/*
* The control channel for establishing RTCPeerConnection for a presentation
* session. SDP Offer/Answer will be exchanged through this interface. The
* control channel should be in-order.
*/
[scriptable, uuid(e60e208c-a9f5-4bc6-9a3e-47f3e4ae9c57)]
interface nsIPresentationControlChannel: nsISupports
{
// The listener for handling events of this control channel.
// All the events should be pending until listener is assigned.
attribute nsIPresentationControlChannelListener listener;
/*
* Send offer to remote endpoint. |onOffer| should be invoked on remote
* endpoint.
* @param offer The offer to send.
* @throws NS_ERROR_FAILURE on failure
*/
void sendOffer(in nsIPresentationChannelDescription offer);
/*
* Send answer to remote endpoint. |onAnswer| should be invoked on remote
* endpoint.
* @param answer The answer to send.
* @throws NS_ERROR_FAILURE on failure
*/
void sendAnswer(in nsIPresentationChannelDescription answer);
/*
* Send ICE candidate to remote endpoint. |onIceCandidate| should be invoked
* on remote endpoint.
* @param candidate The candidate to send
* @throws NS_ERROR_FAILURE on failure
*/
void sendIceCandidate(in DOMString candidate);
/*
* Launch a presentation on remote endpoint.
* @param presentationId The Id for representing this session.
* @param url The URL requested to open by remote device.
* @throws NS_ERROR_FAILURE on failure
*/
void launch(in DOMString presentationId, in DOMString url);
/*
* Terminate a presentation on remote endpoint.
* @param presentationId The Id for representing this session.
* @throws NS_ERROR_FAILURE on failure
*/
void terminate(in DOMString presentationId);
/*
* Disconnect the control channel.
* @param reason The reason of disconnecting channel; NS_OK represents normal.
*/
void disconnect(in nsresult reason);
/*
* Reconnect a presentation on remote endpoint.
* Note that only controller is allowed to reconnect a session.
* @param presentationId The Id for representing this session.
* @param url The URL requested to open by remote device.
* @throws NS_ERROR_FAILURE on failure
*/
void reconnect(in DOMString presentationId, in DOMString url);
};

View file

@ -1,156 +0,0 @@
/* 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/. */
#include "nsISupports.idl"
interface nsIPresentationControlChannel;
%{C++
#define PRESENTATION_CONTROL_SERVICE_CONTACT_ID \
"@mozilla.org/presentation/control-service;1"
%}
/*
* The device information required for establishing control channel.
*/
[scriptable, uuid(296fd171-e4d0-4de0-99ff-ad8ed52ddef3)]
interface nsITCPDeviceInfo: nsISupports
{
readonly attribute AUTF8String id;
readonly attribute AUTF8String address;
readonly attribute uint16_t port;
// SHA-256 fingerprint of server certificate. Empty string represents
// server doesn't support TLS or not available.
readonly attribute AUTF8String certFingerprint;
};
[scriptable, uuid(09bddfaf-fcc2-4dc9-b33e-a509a1c2fb6d)]
interface nsIPresentationControlServerListener: nsISupports
{
/**
* Callback while the server is ready or restarted.
* @param aPort
* The port of the server socket.
* @param aCertFingerprint
* The SHA-256 fingerprint of TLS server certificate.
* Empty string represents server started without encryption.
*/
void onServerReady(in uint16_t aPort, in AUTF8String aCertFingerprint);
/**
* Callback while the server is stopped or fails to start.
* @param aResult
* The error cause of server stopped or the reason of
* start failure.
* NS_OK means the server is stopped by close.
*/
void onServerStopped(in nsresult aResult);
/**
* Callback while the remote host is requesting to start a presentation session.
* @param aDeviceInfo The device information related to the remote host.
* @param aUrl The URL requested to open by remote device.
* @param aPresentationId The Id for representing this session.
* @param aControlChannel The control channel for this session.
*/
void onSessionRequest(in nsITCPDeviceInfo aDeviceInfo,
in DOMString aUrl,
in DOMString aPresentationId,
in nsIPresentationControlChannel aControlChannel);
/**
* Callback while the remote host is requesting to terminate a presentation session.
* @param aDeviceInfo The device information related to the remote host.
* @param aPresentationId The Id for representing this session.
* @param aControlChannel The control channel for this session.
* @param aIsFromReceiver true if termination is initiated by receiver.
*/
void onTerminateRequest(in nsITCPDeviceInfo aDeviceInfo,
in DOMString aPresentationId,
in nsIPresentationControlChannel aControlChannel,
in boolean aIsFromReceiver);
/**
* Callback while the remote host is requesting to reconnect a presentation session.
* @param aDeviceInfo The device information related to the remote host.
* @param aUrl The URL requested to open by remote device.
* @param aPresentationId The Id for representing this session.
* @param aControlChannel The control channel for this session.
*/
void onReconnectRequest(in nsITCPDeviceInfo aDeviceInfo,
in DOMString url,
in DOMString aPresentationId,
in nsIPresentationControlChannel aControlChannel);
};
/**
* Presentation control service which can be used for both presentation
* control client and server.
*/
[scriptable, uuid(55d6b605-2389-4aae-a8fe-60d4440540ea)]
interface nsIPresentationControlService: nsISupports
{
/**
* This method initializes server socket. Caller should set listener and
* monitor onServerReady event to get the correct server info.
* @param aEncrypted
* True for using TLS control channel.
* @param aPort
* The port of the server socket. Pass 0 or opt-out to indicate no
* preference, and a port will be selected automatically.
* @throws NS_ERROR_FAILURE if the server socket has been inited or the
* server socket can not be inited.
*/
void startServer(in boolean aEncrypted, [optional] in uint16_t aPort);
/**
* Request connection to designated remote presentation control receiver.
* @param aDeviceInfo
* The remtoe device info for establish connection.
* @returns The control channel for this session.
* @throws NS_ERROR_FAILURE if the Id hasn't been inited.
*/
nsIPresentationControlChannel connect(in nsITCPDeviceInfo aDeviceInfo);
/**
* Check the compatibility to remote presentation control server.
* @param aVersion
* The version of remote server.
*/
boolean isCompatibleServer(in uint32_t aVersion);
/**
* Close server socket and call |listener.onClose(NS_OK)|
*/
void close();
/**
* Get the listen port of the TCP socket, valid after the server is ready.
* 0 indicates the server socket is not ready or is closed.
*/
readonly attribute uint16_t port;
/**
* The protocol version implemented by this server.
*/
readonly attribute uint32_t version;
/**
* The id of the TCP presentation server. |requestSession| won't
* work until the |id| is set.
*/
attribute AUTF8String id;
/**
* The fingerprint of the TLS server certificate.
* Empty string indicates the server is not ready or not encrypted.
*/
attribute AUTF8String certFingerprint;
/**
* The listener for handling events of this presentation control server.
* Listener must be provided before invoke |startServer| and |close|.
*/
attribute nsIPresentationControlServerListener listener;
};

View file

@ -1,43 +0,0 @@
/* 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/. */
#include "nsISupports.idl"
interface nsIPresentationControlChannel;
/*
* Remote device.
*/
[scriptable, uuid(b1e0a7af-5936-4066-8f2e-f789fb9a7e8f)]
interface nsIPresentationDevice : nsISupports
{
// The unique Id for the device. UUID is recommanded.
readonly attribute AUTF8String id;
// The human-readable name of this device.
readonly attribute AUTF8String name;
// TODO expose more info in order to fulfill UX spec
// The category of this device, could be "wifi", "bluetooth", "hdmi", etc.
readonly attribute AUTF8String type;
/*
* Establish a control channel to this device.
* @returns The control channel for this session.
* @throws NS_ERROR_FAILURE if the establishment fails
*/
nsIPresentationControlChannel establishControlChannel();
// Do something when presentation session is disconnected.
void disconnect();
/*
* Query if requested presentation URL is supported.
* @params requestedUrl the designated URL for a presentation request.
* @returns true if designated URL is supported.
*/
boolean isRequestedUrlSupported(in DOMString requestedUrl);
};

View file

@ -1,51 +0,0 @@
/* 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/. */
#include "nsISupports.idl"
interface nsIArray;
interface nsIPresentationDeviceProvider;
%{C++
#define PRESENTATION_DEVICE_MANAGER_CONTRACTID "@mozilla.org/presentation-device/manager;1"
#define PRESENTATION_DEVICE_CHANGE_TOPIC "presentation-device-change"
%}
/*
* Manager for the device availability. User can observe "presentation-device-change"
* for any update of the available devices.
*/
[scriptable, uuid(beb61db5-3d5f-454f-a15a-dbfa0337c569)]
interface nsIPresentationDeviceManager : nsISupports
{
// true if there is any device available.
readonly attribute boolean deviceAvailable;
/*
* Register a device provider manually.
* @param provider The device provider to add.
*/
void addDeviceProvider(in nsIPresentationDeviceProvider provider);
/*
* Unregister a device provider manually.
* @param provider The device provider to remove.
*/
void removeDeviceProvider(in nsIPresentationDeviceProvider provider);
/*
* Force all registered device providers to update device information.
*/
void forceDiscovery();
/*
* Retrieve all available devices or all available devices that supports
* designated presentation URLs, return a list of nsIPresentationDevice.
* The returned list is a cached device list and could be out-of-date.
* Observe device change events to get following updates.
* @param presentationUrls the target presentation URLs for device filtering
*/
nsIArray getAvailableDevices([optional] in nsIArray presentationUrls);
};

View file

@ -1,58 +0,0 @@
/* 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/. */
#include "nsISupports.idl"
interface nsIArray;
interface nsIDOMEventTarget;
interface nsIPresentationDevice;
interface nsIPrincipal;
%{C++
#define PRESENTATION_DEVICE_PROMPT_CONTRACTID "@mozilla.org/presentation-device/prompt;1"
%}
/*
* The information and callbacks for device selection
*/
[scriptable, uuid(b2aa7f6a-9448-446a-bba4-9c29638b0ed4)]
interface nsIPresentationDeviceRequest : nsISupports
{
// The origin which initiate the request.
readonly attribute DOMString origin;
// The array of candidate URLs.
readonly attribute nsIArray requestURLs;
// The XUL browser element that the request was originated in.
readonly attribute nsIDOMEventTarget chromeEventHandler;
// The principal of the request.
readonly attribute nsIPrincipal principal;
/*
* Callback after selecting a device
* @param device The selected device.
*/
void select(in nsIPresentationDevice device);
/*
* Callback after selection failed or canceled by user.
* @param reason The error cause for canceling this request.
*/
void cancel(in nsresult reason);
};
/*
* UI prompt for device selection.
*/
[scriptable, uuid(ac1a7e44-de86-454f-a9f1-276de2539831)]
interface nsIPresentationDevicePrompt : nsISupports
{
/*
* Request a device selection.
* @param request The information and callbacks of this selection request.
*/
void promptDeviceSelection(in nsIPresentationDeviceRequest request);
};

View file

@ -1,75 +0,0 @@
/* 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/. */
#include "nsISupports.idl"
interface nsIPresentationDevice;
interface nsIPresentationControlChannel;
%{C++
#define PRESENTATION_DEVICE_PROVIDER_CATEGORY "presentation-device-provider"
%}
/*
* The callbacks for any device updates and session request.
*/
[scriptable, uuid(46fd372b-2e40-4179-9b36-0478d141e440)]
interface nsIPresentationDeviceListener: nsISupports
{
void addDevice(in nsIPresentationDevice device);
void removeDevice(in nsIPresentationDevice device);
void updateDevice(in nsIPresentationDevice device);
/*
* Callback while the remote device is requesting to start a presentation session.
* @param device The remote device that sent session request.
* @param url The URL requested to open by remote device.
* @param presentationId The Id for representing this session.
* @param controlChannel The control channel for this session.
*/
void onSessionRequest(in nsIPresentationDevice device,
in DOMString url,
in DOMString presentationId,
in nsIPresentationControlChannel controlChannel);
/*
* Callback while the remote device is requesting to terminate a presentation session.
* @param device The remote device that sent session request.
* @param presentationId The Id for representing this session.
* @param controlChannel The control channel for this session.
* @param aIsFromReceiver true if termination is initiated by receiver.
*/
void onTerminateRequest(in nsIPresentationDevice device,
in DOMString presentationId,
in nsIPresentationControlChannel controlChannel,
in boolean aIsFromReceiver);
/*
* Callback while the remote device is requesting to reconnect a presentation session.
* @param device The remote device that sent session request.
* @param aUrl The URL requested to open by remote device.
* @param presentationId The Id for representing this session.
* @param controlChannel The control channel for this session.
*/
void onReconnectRequest(in nsIPresentationDevice device,
in DOMString url,
in DOMString presentationId,
in nsIPresentationControlChannel controlChannel);
};
/*
* Device provider for any device protocol, can be registered as default
* providers by adding its contractID to category "presentation-device-provider".
*/
[scriptable, uuid(3db2578a-0f50-44ad-b01b-28427b71b7bf)]
interface nsIPresentationDeviceProvider: nsISupports
{
// The listener for handling any device update.
attribute nsIPresentationDeviceListener listener;
/*
* Force to update device information.
*/
void forceDiscovery();
};

View file

@ -1,50 +0,0 @@
/* 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/. */
#include "nsISupports.idl"
[ref] native URLArrayRef(const nsTArray<nsString>);
[uuid(0105f837-4279-4715-9d5b-2dc3f8b65353)]
interface nsIPresentationAvailabilityListener : nsISupports
{
/*
* Called when device availability changes.
*/
[noscript] void notifyAvailableChange(in URLArrayRef urls,
in bool available);
};
[scriptable, uuid(7dd48df8-8f8c-48c7-ac37-7b9fd1acf2f8)]
interface nsIPresentationSessionListener : nsISupports
{
const unsigned short STATE_CONNECTING = 0;
const unsigned short STATE_CONNECTED = 1;
const unsigned short STATE_CLOSED = 2;
const unsigned short STATE_TERMINATED = 3;
/*
* Called when session state changes.
*/
void notifyStateChange(in DOMString sessionId,
in unsigned short state,
in nsresult reason);
/*
* Called when receive messages.
*/
void notifyMessage(in DOMString sessionId,
in ACString data,
in boolean isBinary);
};
[scriptable, uuid(27f101d7-9ed1-429e-b4f8-43b00e8e111c)]
interface nsIPresentationRespondingListener : nsISupports
{
/*
* Called when an incoming session connects.
*/
void notifySessionConnect(in unsigned long long windowId,
in DOMString sessionId);
};

View file

@ -1,17 +0,0 @@
/* 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/. */
#include "nsIPresentationDevice.idl"
/*
* Local device.
* This device is used for 1-UA use case. The result for display is rendered by
* this host device.
*/
[scriptable, uuid(dd239720-cab6-4fb5-9025-cba23f1bbc2d)]
interface nsIPresentationLocalDevice : nsIPresentationDevice
{
// (1-UA only) The property is used to get the window ID of 1-UA device.
readonly attribute AUTF8String windowId;
};

View file

@ -1,36 +0,0 @@
/* 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/. */
#include "nsISupports.idl"
%{C++
#define PRESENTATION_NETWORK_HELPER_CONTRACTID \
"@mozilla.org/presentation-device/networkHelper;1"
%}
[scriptable, uuid(0a7e134f-ff80-4e73-91e6-12b3134fe568)]
interface nsIPresentationNetworkHelperListener : nsISupports
{
/**
* Called when error occurs.
* @param aReason error message.
*/
void onError(in AUTF8String aReason);
/**
* Called when get Wi-Fi IP address.
* @param aIPAddress the IP address of Wi-Fi interface.
*/
void onGetWifiIPAddress(in AUTF8String aIPAddress);
};
[scriptable, uuid(650dc16b-3d9c-49a6-9037-1d6f2d18c90c)]
interface nsIPresentationNetworkHelper : nsISupports
{
/**
* Get IP address of Wi-Fi interface.
* @param aListener the callback interface.
*/
void getWifiIPAddress(in nsIPresentationNetworkHelperListener aListener);
};

View file

@ -1,29 +0,0 @@
/* 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/. */
#include "nsISupports.idl"
interface nsIPresentationDevice;
%{C++
#define PRESENTATION_REQUEST_UI_GLUE_CONTRACTID \
"@mozilla.org/presentation/requestuiglue;1"
%}
[scriptable, uuid(faa45119-6fb5-496c-aa4c-f740177a38b5)]
interface nsIPresentationRequestUIGlue : nsISupports
{
/*
* This method is called to open the responding app/page when
* a presentation request comes in at receiver side.
*
* @param url The url of the request.
* @param sessionId The session ID of the request.
*
* @return A promise that resolves to the opening frame.
*/
nsISupports sendRequest(in DOMString url,
in DOMString sessionId,
in nsIPresentationDevice device);
};

View file

@ -1,275 +0,0 @@
/* 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/. */
#include "nsISupports.idl"
interface nsIDOMBlob;
interface nsIDOMEventTarget;
interface nsIInputStream;
interface nsIPresentationAvailabilityListener;
interface nsIPresentationRespondingListener;
interface nsIPresentationSessionListener;
interface nsIPresentationTransportBuilderConstructor;
interface nsIPrincipal;
%{C++
#define PRESENTATION_SERVICE_CID \
{ 0x1d9bb10c, 0xc0ab, 0x4fe8, \
{ 0x9e, 0x4f, 0x40, 0x58, 0xb8, 0x51, 0x98, 0x32 } }
#define PRESENTATION_SERVICE_CONTRACTID \
"@mozilla.org/presentation/presentationservice;1"
#include "nsTArray.h"
class nsString;
%}
[ref] native URLArrayRef(const nsTArray<nsString>);
[scriptable, uuid(12073206-0065-4b10-9488-a6eb9b23e65b)]
interface nsIPresentationServiceCallback : nsISupports
{
/*
* Called when the operation succeeds.
*
* @param url: the selected request url used to start or reconnect a session.
*/
void notifySuccess(in DOMString url);
/*
* Called when the operation fails.
*
* @param error: error message.
*/
void notifyError(in nsresult error);
};
[scriptable, uuid(de42b741-5619-4650-b961-c2cebb572c95)]
interface nsIPresentationService : nsISupports
{
const unsigned short ROLE_CONTROLLER = 0x1;
const unsigned short ROLE_RECEIVER = 0x2;
const unsigned short CLOSED_REASON_ERROR = 0x1;
const unsigned short CLOSED_REASON_CLOSED = 0x2;
const unsigned short CLOSED_REASON_WENTAWAY = 0x3;
/*
* Start a new presentation session and display a prompt box which asks users
* to select a device.
*
* @param urls: The candidate Urls of presenting page. Only one url would be used.
* @param sessionId: An ID to identify presentation session.
* @param origin: The url of requesting page.
* @param deviceId: The specified device of handling this request, null string
* for prompt device selection dialog.
* @param windowId: The inner window ID associated with the presentation
* session. (0 implies no window ID since no actual window
* uses 0 as its ID. Generally it's the case the window is
* located in different process from this service)
* @param eventTarget: The chrome event handler, in particular XUL browser
* element in parent process, that the request was
* originated in.
* @param principal: The principal that initiated the session.
* @param callback: Invoke the callback when the operation is completed.
* NotifySuccess() is called with |id| if a session is
* established successfully with the selected device.
* Otherwise, NotifyError() is called with a error message.
* @param constructor: The constructor for creating a transport builder.
*/
[noscript] void startSession(in URLArrayRef urls,
in DOMString sessionId,
in DOMString origin,
in DOMString deviceId,
in unsigned long long windowId,
in nsIDOMEventTarget eventTarget,
in nsIPrincipal principal,
in nsIPresentationServiceCallback callback,
in nsIPresentationTransportBuilderConstructor constructor);
/*
* Send the message to the session.
*
* @param sessionId: An ID to identify presentation session.
* @param role: Identify the function called by controller or receiver.
* @param data: the message being sent out.
*/
void sendSessionMessage(in DOMString sessionId,
in uint8_t role,
in DOMString data);
/*
* Send the binary message to the session.
*
* @param sessionId: An ID to identify presentation session.
* @param role: Identify the function called by controller or receiver.
* @param data: the message being sent out.
*/
void sendSessionBinaryMsg(in DOMString sessionId,
in uint8_t role,
in ACString data);
/*
* Send the blob to the session.
*
* @param sessionId: An ID to identify presentation session.
* @param role: Identify the function called by controller or receiver.
* @param blob: The input blob to be sent.
*/
void sendSessionBlob(in DOMString sessionId,
in uint8_t role,
in nsIDOMBlob blob);
/*
* Close the session.
*
* @param sessionId: An ID to identify presentation session.
* @param role: Identify the function called by controller or receiver.
*/
void closeSession(in DOMString sessionId,
in uint8_t role,
in uint8_t closedReason);
/*
* Terminate the session.
*
* @param sessionId: An ID to identify presentation session.
* @param role: Identify the function called by controller or receiver.
*/
void terminateSession(in DOMString sessionId,
in uint8_t role);
/*
* Reconnect the session.
*
* @param url: The request Urls.
* @param sessionId: An ID to identify presentation session.
* @param role: Identify the function called by controller or receiver.
* @param callback: NotifySuccess() is called when a control channel
* is opened successfully.
* Otherwise, NotifyError() is called with a error message.
*/
[noscript] void reconnectSession(in URLArrayRef urls,
in DOMString sessionId,
in uint8_t role,
in nsIPresentationServiceCallback callback);
/*
* Register an availability listener. Must be called from the main thread.
*
* @param availabilityUrls: The Urls that this listener is interested in.
* @param listener: The listener to register.
*/
[noscript] void registerAvailabilityListener(
in URLArrayRef availabilityUrls,
in nsIPresentationAvailabilityListener listener);
/*
* Unregister an availability listener. Must be called from the main thread.
*
* @param availabilityUrls: The Urls that are registered before.
* @param listener: The listener to unregister.
*/
[noscript] void unregisterAvailabilityListener(
in URLArrayRef availabilityUrls,
in nsIPresentationAvailabilityListener listener);
/*
* Register a session listener. Must be called from the main thread.
*
* @param sessionId: An ID to identify presentation session.
* @param role: Identify the function called by controller or receiver.
* @param listener: The listener to register.
*/
void registerSessionListener(in DOMString sessionId,
in uint8_t role,
in nsIPresentationSessionListener listener);
/*
* Unregister a session listener. Must be called from the main thread.
*
* @param sessionId: An ID to identify presentation session.
* @param role: Identify the function called by controller or receiver.
*/
void unregisterSessionListener(in DOMString sessionId,
in uint8_t role);
/*
* Register a responding listener. Must be called from the main thread.
*
* @param windowId: The window ID associated with the listener.
* @param listener: The listener to register.
*/
void registerRespondingListener(in unsigned long long windowId,
in nsIPresentationRespondingListener listener);
/*
* Unregister a responding listener. Must be called from the main thread.
* @param windowId: The window ID associated with the listener.
*/
void unregisterRespondingListener(in unsigned long long windowId);
/*
* Notify the receiver page is ready for presentation use.
*
* @param sessionId An ID to identify presentation session.
* @param windowId The inner window ID associated with the presentation
* session.
* @param isLoading true if receiver page is loading successfully.
* @param constructor: The constructor for creating a transport builder.
*/
void notifyReceiverReady(in DOMString sessionId,
in unsigned long long windowId,
in boolean isLoading,
in nsIPresentationTransportBuilderConstructor constructor);
/*
* Notify the transport is closed
*
* @param sessionId: An ID to identify presentation session.
* @param role: Identify the function called by controller or receiver.
* @param reason: the error message. NS_OK indicates it is closed normally.
*/
void NotifyTransportClosed(in DOMString sessionId,
in uint8_t role,
in nsresult reason);
/*
* Untrack the relevant info about the presentation session if there's any.
*
* @param sessionId: An ID to identify presentation session.
* @param role: Identify the function called by controller or receiver.
*/
void untrackSessionInfo(in DOMString sessionId, in uint8_t role);
/*
* The windowId for building RTCDataChannel session transport
*
* @param sessionId: An ID to identify presentation session.
* @param role: Identify the function called by controller or receiver.
*/
unsigned long long getWindowIdBySessionId(in DOMString sessionId,
in uint8_t role);
/*
* Update the mapping of the session ID and window ID.
*
* @param sessionId: An ID to identify presentation session.
* @param role: Identify the function called by controller or receiver.
* @param windowId: The inner window ID associated with the presentation
* session.
*/
void updateWindowIdBySessionId(in DOMString sessionId,
in uint8_t role,
in unsigned long long windowId);
/*
* To build the session transport.
* NOTE: This function should be only called at controller side.
*
* @param sessionId: An ID to identify presentation session.
* @param role: Identify the function called by controller or receiver.
*/
void buildTransport(in DOMString sessionId, in uint8_t role);
};

Some files were not shown because too many files have changed in this diff Show more