Bug 998872 - [Stingray] TV Manager API. Part 1 - DOM API & WebIDL bindings. r=ehsan, r=baku

--HG--
rename : dom/datastore/tests/file_app.sjs => dom/tv/test/file_app.sjs
This commit is contained in:
Sean Lin 2014-08-21 17:15:18 +08:00
parent c4f0c21bfa
commit d12e06f1df
36 changed files with 1468 additions and 0 deletions

View File

@ -1042,3 +1042,6 @@ pref("dom.mapped_arraybuffer.enabled", true);
// UDPSocket API
pref("dom.udpsocket.enabled", true);
// Enable TV Manager API
pref("dom.tv.enabled", true);

View File

@ -493,6 +493,11 @@ this.PermissionsTable = { geolocation: {
trusted: DENY_ACTION,
privileged: DENY_ACTION,
certified: ALLOW_ACTION
},
"tv": {
app: DENY_ACTION,
privileged: DENY_ACTION,
certified: ALLOW_ACTION
}
};

View File

@ -39,6 +39,7 @@
#include "mozilla/dom/ServiceWorkerContainer.h"
#include "mozilla/dom/Telephony.h"
#include "mozilla/dom/Voicemail.h"
#include "mozilla/dom/TVManager.h"
#include "mozilla/Hal.h"
#include "nsISiteSpecificUserAgent.h"
#include "mozilla/ClearOnShutdown.h"
@ -172,6 +173,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(Navigator)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMobileMessageManager)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTelephony)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mVoicemail)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTVManager)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mConnection)
#ifdef MOZ_B2G_RIL
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMobileConnections)
@ -255,6 +257,10 @@ Navigator::Invalidate()
mVoicemail = nullptr;
}
if (mTVManager) {
mTVManager = nullptr;
}
if (mConnection) {
mConnection->Shutdown();
mConnection = nullptr;
@ -1563,6 +1569,19 @@ Navigator::GetMozTelephony(ErrorResult& aRv)
return mTelephony;
}
TVManager*
Navigator::GetTv()
{
if (!mTVManager) {
if (!mWindow) {
return nullptr;
}
mTVManager = new TVManager(mWindow);
}
return mTVManager;
}
#ifdef MOZ_B2G
already_AddRefed<Promise>
Navigator::GetMobileIdAssertion(const MobileIdOptions& aOptions,
@ -2307,6 +2326,37 @@ Navigator::HasMobileIdSupport(JSContext* aCx, JSObject* aGlobal)
}
#endif
/* static */
bool
Navigator::HasTVSupport(JSContext* aCx, JSObject* aGlobal)
{
JS::Rooted<JSObject*> global(aCx, aGlobal);
nsCOMPtr<nsPIDOMWindow> win = GetWindowFromGlobal(global);
if (!win) {
return false;
}
// Just for testing, we can enable TV for any kind of app.
if (Preferences::GetBool("dom.testing.tv_enabled_for_hosted_apps", false)) {
return true;
}
nsIDocument* doc = win->GetExtantDoc();
if (!doc || !doc->NodePrincipal()) {
return false;
}
nsIPrincipal* principal = doc->NodePrincipal();
uint16_t status;
if (NS_FAILED(principal->GetAppStatus(&status))) {
return false;
}
// Only support TV Manager API for certified apps for now.
return status == nsIPrincipal::APP_STATUS_CERTIFIED;
}
/* static */
already_AddRefed<nsPIDOMWindow>
Navigator::GetWindowFromGlobal(JSObject* aGlobal)

View File

@ -92,6 +92,7 @@ class PowerManager;
class CellBroadcast;
class Telephony;
class Voicemail;
class TVManager;
namespace time {
class TimeManager;
@ -222,6 +223,7 @@ public:
MobileMessageManager* GetMozMobileMessage();
Telephony* GetMozTelephony(ErrorResult& aRv);
Voicemail* GetMozVoicemail(ErrorResult& aRv);
TVManager* GetTv();
network::Connection* GetConnection(ErrorResult& aRv);
nsDOMCameraManager* GetMozCameras(ErrorResult& aRv);
void MozSetMessageHandler(const nsAString& aType,
@ -303,6 +305,8 @@ public:
static bool HasMobileIdSupport(JSContext* aCx, JSObject* aGlobal);
#endif
static bool HasTVSupport(JSContext* aCx, JSObject* aGlobal);
nsPIDOMWindow* GetParentObject() const
{
return GetWindow();
@ -332,6 +336,7 @@ private:
nsRefPtr<MobileMessageManager> mMobileMessageManager;
nsRefPtr<Telephony> mTelephony;
nsRefPtr<Voicemail> mVoicemail;
nsRefPtr<TVManager> mTVManager;
nsRefPtr<network::Connection> mConnection;
#ifdef MOZ_B2G_RIL
nsRefPtr<MobileConnectionArray> mMobileConnections;

View File

@ -707,6 +707,8 @@ GK_ATOM(onconnected, "onconnected")
GK_ATOM(onconnecting, "onconnecting")
GK_ATOM(oncontextmenu, "oncontextmenu")
GK_ATOM(oncopy, "oncopy")
GK_ATOM(oncurrentchannelchanged, "oncurrentchannelchanged")
GK_ATOM(oncurrentsourcechanged, "oncurrentsourcechanged")
GK_ATOM(oncut, "oncut")
GK_ATOM(ondatachange, "ondatachange")
GK_ATOM(ondataerror, "ondataerror")
@ -746,6 +748,7 @@ GK_ATOM(ondragleave, "ondragleave")
GK_ATOM(ondragover, "ondragover")
GK_ATOM(ondragstart, "ondragstart")
GK_ATOM(ondrop, "ondrop")
GK_ATOM(oneitbroadcasted, "oneitbroadcasted")
GK_ATOM(onenabled, "onenabled")
GK_ATOM(onenterpincodereq, "onenterpincodereq")
GK_ATOM(onemergencycbmodechange, "onemergencycbmodechange")
@ -848,6 +851,7 @@ GK_ATOM(onreset, "onreset")
GK_ATOM(onresuming, "onresuming")
GK_ATOM(onresize, "onresize")
GK_ATOM(onrtchange, "onrtchange")
GK_ATOM(onscanningstatechanged, "onscanningstatechanged")
GK_ATOM(onscostatuschanged, "onscostatuschanged")
GK_ATOM(onscroll, "onscroll")
GK_ATOM(onselect, "onselect")

View File

@ -472,6 +472,38 @@ const kEventConstructors = {
return new TransitionEvent(aName, aProps);
},
},
TVCurrentChannelChangedEvent: { create: function (aName, aProps) {
return new TVCurrentChannelChangedEvent(aName, aProps);
},
},
TVCurrentProgramChangedEvent: { create: function (aName, aProps) {
return new TVCurrentProgramChangedEvent(aName, aProps);
},
},
TVCurrentSourceChangedEvent: { create: function (aName, aProps) {
return new TVCurrentSourceChangedEvent(aName, aProps);
},
},
TVEITBroadcastedEvent: { create: function (aName, aProps) {
return new TVEITBroadcastedEvent(aName, aProps);
},
},
TVParentalControlChangedEvent: { create: function (aName, aProps) {
return new TVParentalControlChangedEvent(aName, aProps);
},
},
TVProtectionStateChangedEvent: { create: function (aName, aProps) {
return new TVProtectionStateChangedEvent(aName, aProps);
},
},
TVScanningStateChangedEvent: { create: function (aName, aProps) {
return new TVScanningStateChangedEvent(aName, aProps);
},
},
TVTunerChangedEvent: { create: function (aName, aProps) {
return new TVTunerChangedEvent(aName, aProps);
},
},
UIEvent: { create: function (aName, aProps) {
return new UIEvent(aName, aProps);
},

View File

@ -93,6 +93,7 @@ DIRS += [
'promise',
'smil',
'telephony',
'tv',
'voicemail',
'inputmethod',
'webidl',

View File

@ -1231,6 +1231,24 @@ var interfaceNamesInGlobalScope =
{name: "TreeSelection", xbl: true},
// IMPORTANT: Do not change this list without review from a DOM peer!
"TreeWalker",
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "TVChannel", b2g: true, pref: "dom.tv.enabled", permission: "tv"},
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "TVCurrentChannelChangedEvent", b2g: true, pref: "dom.tv.enabled", permission: "tv"},
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "TVCurrentSourceChangedEvent", b2g: true, pref: "dom.tv.enabled", permission: "tv"},
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "TVEITBroadcastedEvent", b2g: true, pref: "dom.tv.enabled", permission: "tv"},
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "TVManager", b2g: true, pref: "dom.tv.enabled", permission: "tv"},
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "TVProgram", b2g: true, pref: "dom.tv.enabled", permission: "tv"},
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "TVScanningStateChangedEvent", b2g: true, pref: "dom.tv.enabled", permission: "tv"},
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "TVSource", b2g: true, pref: "dom.tv.enabled", permission: "tv"},
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "TVTuner", b2g: true, pref: "dom.tv.enabled", permission: "tv"},
// IMPORTANT: Do not change this list without review from a DOM peer!
{name: "UDPMessageEvent", pref: "dom.udpsocket.enabled", permission: "udp-socket"},
// IMPORTANT: Do not change this list without review from a DOM peer!

135
dom/tv/TVChannel.cpp Normal file
View File

@ -0,0 +1,135 @@
/* -*- 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 "mozilla/dom/Promise.h"
#include "TVChannel.h"
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_CLASS(TVChannel)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(TVChannel,
DOMEventTargetHelper)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(TVChannel,
DOMEventTargetHelper)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_ADDREF_INHERITED(TVChannel, DOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(TVChannel, DOMEventTargetHelper)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(TVChannel)
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
TVChannel::TVChannel(nsPIDOMWindow* aWindow)
: DOMEventTargetHelper(aWindow)
{
}
TVChannel::~TVChannel()
{
}
/* virtual */ JSObject*
TVChannel::WrapObject(JSContext* aCx)
{
return TVChannelBinding::Wrap(aCx, this);
}
already_AddRefed<Promise>
TVChannel::GetPrograms(const TVGetProgramsOptions& aOptions, ErrorResult& aRv)
{
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
MOZ_ASSERT(global);
nsRefPtr<Promise> promise = Promise::Create(global, aRv);
if (aRv.Failed()) {
return nullptr;
}
// TODO Resolve/reject the promise in follow-up patches.
return promise.forget();
}
void
TVChannel::GetNetworkId(nsAString& aNetworkId) const
{
// TODO Implement in follow-up patches.
}
void
TVChannel::GetTransportStreamId(nsAString& aTransportStreamId) const
{
// TODO Implement in follow-up patches.
}
void
TVChannel::GetServiceId(nsAString& aServiceId) const
{
// TODO Implement in follow-up patches.
}
already_AddRefed<TVSource>
TVChannel::Source() const
{
// TODO Implement in follow-up patches.
return nullptr;
}
TVChannelType
TVChannel::Type() const
{
// TODO Implement in follow-up patches.
return TVChannelType::Tv;
}
void
TVChannel::GetName(nsAString& aName) const
{
// TODO Implement in follow-up patches.
}
void
TVChannel::GetNumber(nsAString& aNumber) const
{
// TODO Implement in follow-up patches.
}
bool
TVChannel::IsEmergency() const
{
// TODO Implement in follow-up patches.
return false;
}
bool
TVChannel::IsFree() const
{
// TODO Implement in follow-up patches.
return false;
}
already_AddRefed<Promise>
TVChannel::GetCurrentProgram(ErrorResult& aRv)
{
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
MOZ_ASSERT(global);
nsRefPtr<Promise> promise = Promise::Create(global, aRv);
if (aRv.Failed()) {
return nullptr;
}
// TODO Resolve/reject the promise in follow-up patches.
return promise.forget();
}
} // namespace dom
} // namespace mozilla

66
dom/tv/TVChannel.h Normal file
View File

@ -0,0 +1,66 @@
/* -*- 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_TVChannel_h__
#define mozilla_dom_TVChannel_h__
#include "mozilla/DOMEventTargetHelper.h"
// Include TVChannelBinding.h since enum TVChannelType can't be forward declared.
#include "mozilla/dom/TVChannelBinding.h"
namespace mozilla {
namespace dom {
class Promise;
class TVProgram;
class TVSource;
class TVChannel MOZ_FINAL : public DOMEventTargetHelper
{
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TVChannel, DOMEventTargetHelper)
explicit TVChannel(nsPIDOMWindow* aWindow);
// WebIDL (internal functions)
virtual JSObject* WrapObject(JSContext *aCx) MOZ_OVERRIDE;
// WebIDL (public APIs)
already_AddRefed<Promise> GetPrograms(const TVGetProgramsOptions& aOptions,
ErrorResult& aRv);
already_AddRefed<Promise> GetCurrentProgram(ErrorResult& aRv);
void GetNetworkId(nsAString& aNetworkId) const;
void GetTransportStreamId(nsAString& aTransportStreamId) const;
void GetServiceId(nsAString& aServiceId) const;
already_AddRefed<TVSource> Source() const;
TVChannelType Type() const;
void GetName(nsAString& aName) const;
void GetNumber(nsAString& aNumber) const;
bool IsEmergency() const;
bool IsFree() const;
private:
~TVChannel();
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_TVChannel_h__

62
dom/tv/TVManager.cpp Normal file
View File

@ -0,0 +1,62 @@
/* -*- 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 "mozilla/dom/Promise.h"
#include "mozilla/dom/TVManagerBinding.h"
#include "TVManager.h"
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_CLASS(TVManager)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(TVManager,
DOMEventTargetHelper)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(TVManager,
DOMEventTargetHelper)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_ADDREF_INHERITED(TVManager, DOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(TVManager, DOMEventTargetHelper)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(TVManager)
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
TVManager::TVManager(nsPIDOMWindow* aWindow)
: DOMEventTargetHelper(aWindow)
{
}
TVManager::~TVManager()
{
}
/* virtual */ JSObject*
TVManager::WrapObject(JSContext* aCx)
{
return TVManagerBinding::Wrap(aCx, this);
}
already_AddRefed<Promise>
TVManager::GetTuners(ErrorResult& aRv)
{
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
MOZ_ASSERT(global);
nsRefPtr<Promise> promise = Promise::Create(global, aRv);
if (aRv.Failed()) {
return nullptr;
}
// TODO Resolve/reject the promise in follow-up patches.
return promise.forget();
}
} // namespace dom
} // namespace mozilla

41
dom/tv/TVManager.h Normal file
View File

@ -0,0 +1,41 @@
/* -*- 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_TVManager_h__
#define mozilla_dom_TVManager_h__
#include "mozilla/DOMEventTargetHelper.h"
namespace mozilla {
namespace dom {
class Promise;
class TVManager MOZ_FINAL : public DOMEventTargetHelper
{
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TVManager, DOMEventTargetHelper)
explicit TVManager(nsPIDOMWindow* aWindow);
// WebIDL (internal functions)
virtual JSObject* WrapObject(JSContext *aCx) MOZ_OVERRIDE;
// WebIDL (public APIs)
already_AddRefed<Promise> GetTuners(ErrorResult& aRv);
private:
~TVManager();
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_TVManager_h__

96
dom/tv/TVProgram.cpp Normal file
View File

@ -0,0 +1,96 @@
/* -*- 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 "mozilla/dom/TVProgramBinding.h"
#include "TVProgram.h"
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(TVProgram, mOwner)
NS_IMPL_CYCLE_COLLECTING_ADDREF(TVProgram)
NS_IMPL_CYCLE_COLLECTING_RELEASE(TVProgram)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TVProgram)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
TVProgram::TVProgram(nsISupports* aOwner)
: mOwner(aOwner)
{
}
TVProgram::~TVProgram()
{
}
/* virtual */ JSObject*
TVProgram::WrapObject(JSContext* aCx)
{
return TVProgramBinding::Wrap(aCx, this);
}
void
TVProgram::GetAudioLanguages(nsTArray<nsString>& aLanguages) const
{
// TODO Implement in follow-up patches.
}
void
TVProgram::GetSubtitleLanguages(nsTArray<nsString>& aLanguages) const
{
// TODO Implement in follow-up patches.
}
void
TVProgram::GetEventId(nsAString& aEventId) const
{
// TODO Implement in follow-up patches.
}
already_AddRefed<TVChannel>
TVProgram::Channel() const
{
// TODO Implement in follow-up patches.
return nullptr;
}
void
TVProgram::GetTitle(nsAString& aTitle) const
{
// TODO Implement in follow-up patches.
}
uint64_t
TVProgram::StartTime() const
{
// TODO Implement in follow-up patches.
return 0;
}
uint64_t
TVProgram::Duration() const
{
// TODO Implement in follow-up patches.
return 0;
}
void
TVProgram::GetDescription(nsAString& aDescription) const
{
// TODO Implement in follow-up patches.
}
void
TVProgram::GetRating(nsAString& aRating) const
{
// TODO Implement in follow-up patches.
}
} // namespace dom
} // namespace mozilla

64
dom/tv/TVProgram.h Normal file
View File

@ -0,0 +1,64 @@
/* -*- 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_TVProgram_h__
#define mozilla_dom_TVProgram_h__
#include "nsWrapperCache.h"
namespace mozilla {
namespace dom {
class TVChannel;
class TVProgram MOZ_FINAL : public nsISupports
, public nsWrapperCache
{
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(TVProgram)
explicit TVProgram(nsISupports* aOwner);
// WebIDL (internal functions)
nsISupports* GetParentObject() const
{
return mOwner;
}
virtual JSObject* WrapObject(JSContext *aCx) MOZ_OVERRIDE;
// WebIDL (public APIs)
void GetAudioLanguages(nsTArray<nsString>& aLanguages) const;
void GetSubtitleLanguages(nsTArray<nsString>& aLanguages) const;
void GetEventId(nsAString& aEventId) const;
already_AddRefed<TVChannel> Channel() const;
void GetTitle(nsAString& aTitle) const;
uint64_t StartTime() const;
uint64_t Duration() const;
void GetDescription(nsAString& aDescription) const;
void GetRating(nsAString& aRating) const;
private:
~TVProgram();
nsCOMPtr<nsISupports> mOwner;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_TVProgram_h__

138
dom/tv/TVSource.cpp Normal file
View File

@ -0,0 +1,138 @@
/* -*- 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 "mozilla/dom/Promise.h"
#include "TVSource.h"
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_CLASS(TVSource)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(TVSource,
DOMEventTargetHelper)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(TVSource,
DOMEventTargetHelper)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_ADDREF_INHERITED(TVSource, DOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(TVSource, DOMEventTargetHelper)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(TVSource)
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
TVSource::TVSource(nsPIDOMWindow* aWindow)
: DOMEventTargetHelper(aWindow)
{
}
TVSource::~TVSource()
{
}
/* virtual */ JSObject*
TVSource::WrapObject(JSContext* aCx)
{
return TVSourceBinding::Wrap(aCx, this);
}
already_AddRefed<Promise>
TVSource::GetChannels(ErrorResult& aRv)
{
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
MOZ_ASSERT(global);
nsRefPtr<Promise> promise = Promise::Create(global, aRv);
if (aRv.Failed()) {
return nullptr;
}
// TODO Resolve/reject the promise in follow-up patches.
return promise.forget();
}
already_AddRefed<Promise>
TVSource::SetCurrentChannel(const nsAString& aChannelNumber, ErrorResult& aRv)
{
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
MOZ_ASSERT(global);
nsRefPtr<Promise> promise = Promise::Create(global, aRv);
if (aRv.Failed()) {
return nullptr;
}
// TODO Resolve/reject the promise in follow-up patches.
return promise.forget();
}
already_AddRefed<Promise>
TVSource::StartScanning(const TVStartScanningOptions& aOptions,
ErrorResult& aRv)
{
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
MOZ_ASSERT(global);
nsRefPtr<Promise> promise = Promise::Create(global, aRv);
if (aRv.Failed()) {
return nullptr;
}
// TODO Resolve/reject the promise in follow-up patches.
return promise.forget();
}
already_AddRefed<Promise>
TVSource::StopScanning(ErrorResult& aRv)
{
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
MOZ_ASSERT(global);
nsRefPtr<Promise> promise = Promise::Create(global, aRv);
if (aRv.Failed()) {
return nullptr;
}
// TODO Resolve/reject the promise in follow-up patches.
return promise.forget();
}
already_AddRefed<TVTuner>
TVSource::Tuner() const
{
// TODO Implement in follow-up patches.
return nullptr;
}
TVSourceType
TVSource::Type() const
{
// TODO Implement in follow-up patches.
return TVSourceType::Dvb_t;
}
bool
TVSource::IsScanning() const
{
// TODO Implement in follow-up patches.
return false;
}
already_AddRefed<TVChannel>
TVSource::GetCurrentChannel() const
{
// TODO Implement in follow-up patches.
return nullptr;
}
} // namespace dom
} // namespace mozilla

65
dom/tv/TVSource.h Normal file
View File

@ -0,0 +1,65 @@
/* -*- 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_TVSource_h__
#define mozilla_dom_TVSource_h__
#include "mozilla/DOMEventTargetHelper.h"
// Include TVSourceBinding.h since enum TVSourceType can't be forward declared.
#include "mozilla/dom/TVSourceBinding.h"
namespace mozilla {
namespace dom {
class Promise;
class TVChannel;
class TVTuner;
class TVSource MOZ_FINAL : public DOMEventTargetHelper
{
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TVSource, DOMEventTargetHelper)
explicit TVSource(nsPIDOMWindow* aWindow);
// WebIDL (internal functions)
virtual JSObject* WrapObject(JSContext *aCx) MOZ_OVERRIDE;
// WebIDL (public APIs)
already_AddRefed<Promise> GetChannels(ErrorResult& aRv);
already_AddRefed<Promise> SetCurrentChannel(const nsAString& aChannelNumber,
ErrorResult& aRv);
already_AddRefed<Promise> StartScanning(const TVStartScanningOptions& aOptions,
ErrorResult& aRv);
already_AddRefed<Promise> StopScanning(ErrorResult& aRv);
already_AddRefed<TVTuner> Tuner() const;
TVSourceType Type() const;
bool IsScanning() const;
already_AddRefed<TVChannel> GetCurrentChannel() const;
IMPL_EVENT_HANDLER(currentchannelchanged);
IMPL_EVENT_HANDLER(eitbroadcasted);
IMPL_EVENT_HANDLER(scanningstatechanged);
private:
~TVSource();
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_TVSource_h__

104
dom/tv/TVTuner.cpp Normal file
View File

@ -0,0 +1,104 @@
/* -*- 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 "mozilla/dom/Promise.h"
#include "TVTuner.h"
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_CLASS(TVTuner)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(TVTuner,
DOMEventTargetHelper)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(TVTuner,
DOMEventTargetHelper)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_ADDREF_INHERITED(TVTuner, DOMEventTargetHelper)
NS_IMPL_RELEASE_INHERITED(TVTuner, DOMEventTargetHelper)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(TVTuner)
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
TVTuner::TVTuner(nsPIDOMWindow* aWindow)
: DOMEventTargetHelper(aWindow)
{
}
TVTuner::~TVTuner()
{
}
/* virtual */ JSObject*
TVTuner::WrapObject(JSContext* aCx)
{
return TVTunerBinding::Wrap(aCx, this);
}
void
TVTuner::GetSupportedSourceTypes(nsTArray<TVSourceType>& aSourceTypes,
ErrorResult& aRv) const
{
// TODO Implement in follow-up patches.
}
already_AddRefed<Promise>
TVTuner::GetSources(ErrorResult& aRv)
{
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
MOZ_ASSERT(global);
nsRefPtr<Promise> promise = Promise::Create(global, aRv);
if (aRv.Failed()) {
return nullptr;
}
// TODO Resolve/reject the promise in follow-up patches.
return promise.forget();
}
already_AddRefed<Promise>
TVTuner::SetCurrentSource(const TVSourceType aSourceType, ErrorResult& aRv)
{
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
MOZ_ASSERT(global);
nsRefPtr<Promise> promise = Promise::Create(global, aRv);
if (aRv.Failed()) {
return nullptr;
}
// TODO Resolve/reject the promise in follow-up patches.
return promise.forget();
}
void
TVTuner::GetId(nsAString& aId) const
{
// TODO Implement in follow-up patches.
}
already_AddRefed<TVSource>
TVTuner::GetCurrentSource() const
{
// TODO Implement in follow-up patches.
return nullptr;
}
already_AddRefed<DOMMediaStream>
TVTuner::GetStream() const
{
// TODO Implement in follow-up patches.
return nullptr;
}
} // namespace dom
} // namespace mozilla

61
dom/tv/TVTuner.h Normal file
View File

@ -0,0 +1,61 @@
/* -*- 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_TVTuner_h__
#define mozilla_dom_TVTuner_h__
#include "mozilla/DOMEventTargetHelper.h"
// Include TVTunerBinding.h since enum TVSourceType can't be forward declared.
#include "mozilla/dom/TVTunerBinding.h"
namespace mozilla {
class DOMMediaStream;
namespace dom {
class Promise;
class TVSource;
class TVTuner MOZ_FINAL : public DOMEventTargetHelper
{
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TVTuner, DOMEventTargetHelper)
explicit TVTuner(nsPIDOMWindow* aWindow);
// WebIDL (internal functions)
virtual JSObject* WrapObject(JSContext *aCx) MOZ_OVERRIDE;
// WebIDL (public APIs)
void GetSupportedSourceTypes(nsTArray<TVSourceType>& aSourceTypes,
ErrorResult& aRv) const;
already_AddRefed<Promise> GetSources(ErrorResult& aRv);
already_AddRefed<Promise> SetCurrentSource(const TVSourceType aSourceType,
ErrorResult& aRv);
void GetId(nsAString& aId) const;
already_AddRefed<TVSource> GetCurrentSource() const;
already_AddRefed<DOMMediaStream> GetStream() const;
IMPL_EVENT_HANDLER(currentsourcechanged);
private:
~TVTuner();
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_TVTuner_h__

25
dom/tv/moz.build Normal file
View File

@ -0,0 +1,25 @@
# -*- Mode: python; c-basic-offset: 4; 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/.
TEST_DIRS += ['test']
EXPORTS.mozilla.dom += [
'TVChannel.h',
'TVManager.h',
'TVProgram.h',
'TVSource.h',
'TVTuner.h',
]
UNIFIED_SOURCES += [
'TVChannel.cpp',
'TVManager.cpp',
'TVProgram.cpp',
'TVSource.cpp',
'TVTuner.cpp',
]
FINAL_LIBRARY = 'xul'

56
dom/tv/test/file_app.sjs Normal file
View File

@ -0,0 +1,56 @@
var gBasePath = "tests/dom/tv/test/";
function handleRequest(request, response) {
var query = getQuery(request);
var testToken = '';
if ('testToken' in query) {
testToken = query.testToken;
}
var template = '';
if ('template' in query) {
template = query.template;
}
var template = gBasePath + template;
response.setHeader("Content-Type", "application/x-web-app-manifest+json", false);
response.write(readTemplate(template).replace(/TESTTOKEN/g, testToken));
}
// Copy-pasted incantations. There ought to be a better way to synchronously read
// a file into a string, but I guess we're trying to discourage that.
function readTemplate(path) {
var file = Components.classes["@mozilla.org/file/directory_service;1"].
getService(Components.interfaces.nsIProperties).
get("CurWorkD", Components.interfaces.nsILocalFile);
var fis = Components.classes['@mozilla.org/network/file-input-stream;1'].
createInstance(Components.interfaces.nsIFileInputStream);
var cis = Components.classes["@mozilla.org/intl/converter-input-stream;1"].
createInstance(Components.interfaces.nsIConverterInputStream);
var split = path.split("/");
for(var i = 0; i < split.length; ++i) {
file.append(split[i]);
}
fis.init(file, -1, -1, false);
cis.init(fis, "UTF-8", 0, 0);
var data = "";
let (str = {}) {
let read = 0;
do {
read = cis.readString(0xffffffff, str); // read as much as we can and put it in str.value
data += str.value;
} while (read != 0);
}
cis.close();
return data;
}
function getQuery(request) {
var query = {};
request.queryString.split('&').forEach(function (val) {
var [name, value] = val.split('=');
query[name] = unescape(value);
});
return query;
}

View File

@ -0,0 +1,6 @@
{
"name": "TV Test App (hosted)",
"description": "Hosted TV test app used for mochitest.",
"launch_path": "/tests/dom/tv/test/TESTTOKEN",
"icons": { "128": "default_icon" }
}

View File

@ -0,0 +1,24 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test the availability of TV Manager API for non-permitted Apps</title>
</head>
<body>
<div id="content"></div>
<script type="application/javascript;version=1.7">
function ok(a, msg) {
alert((a ? 'OK' : 'KO')+ ' ' + msg)
}
function finish() {
alert('DONE');
}
ok(!('tv' in navigator),
"navigator.tv should not exist for non-permitted app.");
finish();
</script>
</body>
</html>

View File

@ -0,0 +1,7 @@
[DEFAULT]
support-files =
file_app.sjs
file_app.template.webapp
file_tv_non_permitted_app.html
[test_tv_non_permitted_app.html]

7
dom/tv/test/moz.build Normal file
View File

@ -0,0 +1,7 @@
# -*- Mode: python; c-basic-offset: 4; 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/.
MOCHITEST_MANIFESTS += ['mochitest.ini']

View File

@ -0,0 +1,112 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test Non-Permitted Application for TV API</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test">
<script type="application/javascript">
"use strict";
var gHostedManifestURL = 'http://test/tests/dom/tv/test/file_app.sjs?testToken=file_tv_non_permitted_app.html&template=file_app.template.webapp';
var gApp;
function cbError(e) {
ok(false, "Error callback invoked: " + this.error.name);
SimpleTest.finish();
}
function installApp() {
var request = navigator.mozApps.install(gHostedManifestURL);
request.onerror = cbError;
request.onsuccess = function() {
gApp = request.result;
runTest();
}
}
function uninstallApp() {
var request = navigator.mozApps.mgmt.uninstall(gApp);
request.onerror = cbError;
request.onsuccess = function() {
// All done.
info("All done");
runTest();
}
}
function testApp() {
var ifr = document.createElement('iframe');
ifr.setAttribute('mozbrowser', 'true');
ifr.setAttribute('mozapp', gApp.manifestURL);
ifr.setAttribute('src', gApp.manifest.launch_path);
var domParent = document.getElementById('content');
// Set us up to listen for messages from the app.
var listener = function(e) {
var message = e.detail.message;
if (/^OK/.exec(message)) {
ok(true, "Message from app: " + message);
} else if (/KO/.exec(message)) {
ok(false, "Message from app: " + message);
} else if (/DONE/.exec(message)) {
ok(true, "Messaging from app complete");
ifr.removeEventListener('mozbrowsershowmodalprompt', listener);
domParent.removeChild(ifr);
runTest();
}
}
// This event is triggered when the app calls "alert".
ifr.addEventListener('mozbrowsershowmodalprompt', listener, false);
domParent.appendChild(ifr);
}
var tests = [
// Installing the app
installApp,
// Run tests in app
testApp,
// Uninstall the app
uninstallApp
];
function runTest() {
if (!tests.length) {
SimpleTest.finish();
return;
}
var test = tests.shift();
test();
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [["dom.tv.enabled", true]]}, function() {
SpecialPowers.pushPermissions(
[{ "type": "tv", "allow": true, "context": document },
{ "type": "browser", "allow": true, "context": document },
{ "type": "embed-apps", "allow": true, "context": document },
{ "type": "webapps-manage", "allow": true, "context": document }],
function(){
SpecialPowers.setAllAppsLaunchable(true);
SpecialPowers.setBoolPref("dom.mozBrowserFramesEnabled", true);
// No confirmation needed when an app is installed
SpecialPowers.autoConfirmAppInstall(() => {
SpecialPowers.autoConfirmAppUninstall(runTest);
});
});
});
</script>
</pre>
</body>
</html>

View File

@ -388,3 +388,8 @@ partial interface Navigator {
boolean sendBeacon(DOMString url,
optional (ArrayBufferView or Blob or DOMString or FormData)? data = null);
};
partial interface Navigator {
[Pref="dom.tv.enabled", CheckPermissions="tv", Func="Navigator::HasTVSupport"]
readonly attribute TVManager? tv;
};

View File

@ -0,0 +1,46 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*
* The origin of this IDL file is
* http://seanyhlin.github.io/TV-Manager-API/
*/
enum TVChannelType {
"tv",
"radio",
"data"
};
dictionary TVGetProgramsOptions {
unsigned long long startTime;
unsigned long long duration;
};
[Pref="dom.tv.enabled", CheckPermissions="tv", Func="Navigator::HasTVSupport"]
interface TVChannel : EventTarget {
[Throws]
Promise<sequence<TVProgram>> getPrograms(optional TVGetProgramsOptions options);
[Throws]
Promise<TVProgram> getCurrentProgram();
readonly attribute DOMString networkId;
readonly attribute DOMString transportStreamId;
readonly attribute DOMString serviceId;
readonly attribute TVSource source;
readonly attribute TVChannelType type;
readonly attribute DOMString name;
readonly attribute DOMString number;
readonly attribute boolean isEmergency;
readonly attribute boolean isFree;
};

View File

@ -0,0 +1,20 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*
* The origin of this IDL file is
* http://seanyhlin.github.io/TV-Manager-API/
*/
dictionary TVCurrentChannelChangedEventInit : EventInit {
TVChannel? channel = null;
};
[Pref="dom.tv.enabled",
CheckPermissions="tv",
Func="Navigator::HasTVSupport",
Constructor(DOMString type, optional TVCurrentChannelChangedEventInit eventInitDict)]
interface TVCurrentChannelChangedEvent : Event {
readonly attribute TVChannel? channel;
};

View File

@ -0,0 +1,20 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*
* The origin of this IDL file is
* http://seanyhlin.github.io/TV-Manager-API/
*/
dictionary TVCurrentSourceChangedEventInit : EventInit {
TVSource? source = null;
};
[Pref="dom.tv.enabled",
CheckPermissions="tv",
Func="Navigator::HasTVSupport",
Constructor(DOMString type, optional TVCurrentSourceChangedEventInit eventInitDict)]
interface TVCurrentSourceChangedEvent : Event {
readonly attribute TVSource? source;
};

View File

@ -0,0 +1,20 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*
* The origin of this IDL file is
* http://seanyhlin.github.io/TV-Manager-API/
*/
dictionary TVEITBroadcastedEventInit : EventInit {
sequence<TVProgram> programs = [];
};
[Pref="dom.tv.enabled",
CheckPermissions="tv",
Func="Navigator::HasTVSupport",
Constructor(DOMString type, optional TVEITBroadcastedEventInit eventInitDict)]
interface TVEITBroadcastedEvent : Event {
[Pure, Cached] readonly attribute sequence<TVProgram> programs;
};

View File

@ -0,0 +1,14 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*
* The origin of this IDL file is
* http://seanyhlin.github.io/TV-Manager-API/
*/
[Pref="dom.tv.enabled", CheckPermissions="tv", Func="Navigator::HasTVSupport"]
interface TVManager : EventTarget {
[Throws]
Promise<sequence<TVTuner>> getTuners();
};

View File

@ -0,0 +1,29 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*
* The origin of this IDL file is
* http://seanyhlin.github.io/TV-Manager-API/
*/
[Pref="dom.tv.enabled", CheckPermissions="tv", Func="Navigator::HasTVSupport"]
interface TVProgram {
sequence<DOMString> getAudioLanguages();
sequence<DOMString> getSubtitleLanguages();
readonly attribute DOMString eventId;
readonly attribute TVChannel channel;
readonly attribute DOMString title;
readonly attribute unsigned long long startTime;
readonly attribute unsigned long long duration;
readonly attribute DOMString? description;
readonly attribute DOMString? rating;
};

View File

@ -0,0 +1,29 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*
* The origin of this IDL file is
* http://seanyhlin.github.io/TV-Manager-API/
*/
enum TVScanningState {
"cleared",
"scanned",
"completed",
"stopped"
};
dictionary TVScanningStateChangedEventInit : EventInit {
TVScanningState state = "cleared";
TVChannel? channel = null;
};
[Pref="dom.tv.enabled",
CheckPermissions="tv",
Func="Navigator::HasTVSupport",
Constructor(DOMString type, optional TVScanningStateChangedEventInit eventInitDict)]
interface TVScanningStateChangedEvent : Event {
readonly attribute TVScanningState state;
readonly attribute TVChannel? channel;
};

View File

@ -0,0 +1,61 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*
* The origin of this IDL file is
* http://seanyhlin.github.io/TV-Manager-API/
*/
enum TVSourceType {
"dvb-t",
"dvb-t2",
"dvb-c",
"dvb-c2",
"dvb-s",
"dvb-s2",
"dvb-h",
"dvb-sh",
"atsc",
"atsc-m/h",
"isdb-t",
"isdb-tb",
"isdb-s",
"isdb-c",
"1seg",
"dtmb",
"cmmb",
"t-dmb",
"s-dmb"
};
dictionary TVStartScanningOptions {
boolean isRescanned;
};
[Pref="dom.tv.enabled", CheckPermissions="tv", Func="Navigator::HasTVSupport"]
interface TVSource : EventTarget {
[Throws]
Promise<sequence<TVChannel>> getChannels();
[Throws]
Promise<void> setCurrentChannel(DOMString channelNumber);
[Throws]
Promise<void> startScanning(optional TVStartScanningOptions options);
[Throws]
Promise<void> stopScanning();
readonly attribute TVTuner tuner;
readonly attribute TVSourceType type;
readonly attribute boolean isScanning;
readonly attribute TVChannel? currentChannel;
attribute EventHandler oncurrentchannelchanged;
attribute EventHandler oneitbroadcasted;
attribute EventHandler onscanningstatechanged;
};

28
dom/webidl/TVTuner.webidl Normal file
View File

@ -0,0 +1,28 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*
* The origin of this IDL file is
* http://seanyhlin.github.io/TV-Manager-API/
*/
[Pref="dom.tv.enabled", CheckPermissions="tv", Func="Navigator::HasTVSupport"]
interface TVTuner : EventTarget {
[Throws]
sequence<TVSourceType> getSupportedSourceTypes();
[Throws]
Promise<sequence<TVSource>> getSources();
[Throws]
Promise<void> setCurrentSource(TVSourceType sourceType);
readonly attribute DOMString id;
readonly attribute TVSource? currentSource;
readonly attribute MediaStream? stream;
attribute EventHandler oncurrentsourcechanged;
};

View File

@ -502,6 +502,11 @@ WEBIDL_FILES = [
'TreeColumn.webidl',
'TreeColumns.webidl',
'TreeWalker.webidl',
'TVChannel.webidl',
'TVManager.webidl',
'TVProgram.webidl',
'TVSource.webidl',
'TVTuner.webidl',
'UDPMessageEvent.webidl',
'UDPSocket.webidl',
'UIEvent.webidl',
@ -717,6 +722,10 @@ GENERATED_EVENTS_WEBIDL_FILES = [
'StyleSheetApplicableStateChangeEvent.webidl',
'StyleSheetChangeEvent.webidl',
'TrackEvent.webidl',
'TVCurrentChannelChangedEvent.webidl',
'TVCurrentSourceChangedEvent.webidl',
'TVEITBroadcastedEvent.webidl',
'TVScanningStateChangedEvent.webidl',
'UDPMessageEvent.webidl',
'UserProximityEvent.webidl',
'USSDReceivedEvent.webidl',