2014-08-21 13:15:18 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "mozilla/dom/Promise.h"
|
2014-08-22 09:53:39 +04:00
|
|
|
#include "mozilla/dom/TVServiceCallbacks.h"
|
|
|
|
#include "mozilla/dom/TVServiceFactory.h"
|
|
|
|
#include "mozilla/dom/TVSource.h"
|
|
|
|
#include "mozilla/dom/TVTuner.h"
|
|
|
|
#include "mozilla/dom/TVUtils.h"
|
|
|
|
#include "nsITVService.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
2014-08-21 13:15:18 +04:00
|
|
|
#include "TVChannel.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-08-22 09:53:39 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(TVChannel, DOMEventTargetHelper,
|
|
|
|
mTVService, mSource)
|
2014-08-21 13:15:18 +04:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
TVChannel::TVChannel(nsPIDOMWindowInner* aWindow,
|
2014-08-22 09:53:39 +04:00
|
|
|
TVSource* aSource)
|
2014-08-21 13:15:18 +04:00
|
|
|
: DOMEventTargetHelper(aWindow)
|
2014-08-22 09:53:39 +04:00
|
|
|
, mSource(aSource)
|
2014-08-21 13:15:18 +04:00
|
|
|
{
|
2014-08-22 09:53:39 +04:00
|
|
|
MOZ_ASSERT(mSource);
|
2014-08-21 13:15:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
TVChannel::~TVChannel()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-08-22 09:53:39 +04:00
|
|
|
/* static */ already_AddRefed<TVChannel>
|
2016-01-30 20:05:36 +03:00
|
|
|
TVChannel::Create(nsPIDOMWindowInner* aWindow,
|
2014-08-22 09:53:39 +04:00
|
|
|
TVSource* aSource,
|
|
|
|
nsITVChannelData* aData)
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TVChannel> channel = new TVChannel(aWindow, aSource);
|
2014-08-22 09:53:39 +04:00
|
|
|
return (channel->Init(aData)) ? channel.forget() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
TVChannel::Init(nsITVChannelData* aData)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(aData, false);
|
|
|
|
|
|
|
|
nsString channelType;
|
|
|
|
aData->GetType(channelType);
|
|
|
|
mType = ToTVChannelType(channelType);
|
|
|
|
if (NS_WARN_IF(mType == TVChannelType::EndGuard_)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aData->GetNetworkId(mNetworkId);
|
|
|
|
aData->GetTransportStreamId(mTransportStreamId);
|
|
|
|
aData->GetServiceId(mServiceId);
|
|
|
|
aData->GetName(mName);
|
|
|
|
aData->GetNumber(mNumber);
|
2016-08-12 08:19:29 +03:00
|
|
|
mIsEmergency = aData->GetIsEmergency();
|
|
|
|
mIsFree = aData->GetIsFree();
|
2014-08-22 09:53:39 +04:00
|
|
|
|
|
|
|
mTVService = TVServiceFactory::AutoCreateTVService();
|
|
|
|
NS_ENSURE_TRUE(mTVService, false);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-08-21 13:15:18 +04:00
|
|
|
/* virtual */ JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
TVChannel::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2014-08-21 13:15:18 +04:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
return TVChannelBinding::Wrap(aCx, this, aGivenProto);
|
2014-08-21 13:15:18 +04:00
|
|
|
}
|
|
|
|
|
2014-08-22 09:53:39 +04:00
|
|
|
nsresult
|
|
|
|
TVChannel::DispatchTVEvent(nsIDOMEvent* aEvent)
|
|
|
|
{
|
|
|
|
return DispatchTrustedEvent(aEvent);
|
|
|
|
}
|
|
|
|
|
2014-08-21 13:15:18 +04:00
|
|
|
already_AddRefed<Promise>
|
|
|
|
TVChannel::GetPrograms(const TVGetProgramsOptions& aOptions, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
|
|
|
|
MOZ_ASSERT(global);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Promise> promise = Promise::Create(global, aRv);
|
2014-08-22 09:53:39 +04:00
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
2014-08-21 13:15:18 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TVTuner> tuner = mSource->Tuner();
|
2014-08-22 09:53:39 +04:00
|
|
|
nsString tunerId;
|
|
|
|
tuner->GetId(tunerId);
|
|
|
|
|
|
|
|
uint64_t startTime = aOptions.mStartTime.WasPassed() ?
|
|
|
|
aOptions.mStartTime.Value() :
|
|
|
|
PR_Now();
|
|
|
|
uint64_t endTime = aOptions.mDuration.WasPassed() ?
|
|
|
|
(startTime + aOptions.mDuration.Value()) :
|
|
|
|
std::numeric_limits<uint64_t>::max();
|
|
|
|
nsCOMPtr<nsITVServiceCallback> callback =
|
|
|
|
new TVServiceProgramGetterCallback(this, promise, false);
|
|
|
|
nsresult rv =
|
|
|
|
mTVService->GetPrograms(tunerId,
|
|
|
|
ToTVSourceTypeStr(mSource->Type()),
|
|
|
|
mNumber,
|
|
|
|
startTime,
|
|
|
|
endTime,
|
|
|
|
callback);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
promise->MaybeReject(NS_ERROR_DOM_ABORT_ERR);
|
|
|
|
}
|
2014-08-21 13:15:18 +04:00
|
|
|
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TVChannel::GetNetworkId(nsAString& aNetworkId) const
|
|
|
|
{
|
2014-08-22 09:53:39 +04:00
|
|
|
aNetworkId = mNetworkId;
|
2014-08-21 13:15:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TVChannel::GetTransportStreamId(nsAString& aTransportStreamId) const
|
|
|
|
{
|
2014-08-22 09:53:39 +04:00
|
|
|
aTransportStreamId = mTransportStreamId;
|
2014-08-21 13:15:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TVChannel::GetServiceId(nsAString& aServiceId) const
|
|
|
|
{
|
2014-08-22 09:53:39 +04:00
|
|
|
aServiceId = mServiceId;
|
2014-08-21 13:15:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<TVSource>
|
|
|
|
TVChannel::Source() const
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TVSource> source = mSource;
|
2014-08-22 09:53:39 +04:00
|
|
|
return source.forget();
|
2014-08-21 13:15:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
TVChannelType
|
|
|
|
TVChannel::Type() const
|
|
|
|
{
|
2014-08-22 09:53:39 +04:00
|
|
|
return mType;
|
2014-08-21 13:15:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TVChannel::GetName(nsAString& aName) const
|
|
|
|
{
|
2014-08-22 09:53:39 +04:00
|
|
|
aName = mName;
|
2014-08-21 13:15:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TVChannel::GetNumber(nsAString& aNumber) const
|
|
|
|
{
|
2014-08-22 09:53:39 +04:00
|
|
|
aNumber = mNumber;
|
2014-08-21 13:15:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
TVChannel::IsEmergency() const
|
|
|
|
{
|
2014-08-22 09:53:39 +04:00
|
|
|
return mIsEmergency;
|
2014-08-21 13:15:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
TVChannel::IsFree() const
|
|
|
|
{
|
2014-08-22 09:53:39 +04:00
|
|
|
return mIsFree;
|
2014-08-21 13:15:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<Promise>
|
|
|
|
TVChannel::GetCurrentProgram(ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
|
|
|
|
MOZ_ASSERT(global);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Promise> promise = Promise::Create(global, aRv);
|
2014-08-21 13:15:18 +04:00
|
|
|
if (aRv.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TVTuner> tuner = mSource->Tuner();
|
2014-08-22 09:53:39 +04:00
|
|
|
nsString tunerId;
|
|
|
|
tuner->GetId(tunerId);
|
|
|
|
|
|
|
|
// Get only one program from now on.
|
|
|
|
nsCOMPtr<nsITVServiceCallback> callback =
|
|
|
|
new TVServiceProgramGetterCallback(this, promise, true);
|
|
|
|
nsresult rv =
|
|
|
|
mTVService->GetPrograms(tunerId,
|
|
|
|
ToTVSourceTypeStr(mSource->Type()),
|
|
|
|
mNumber,
|
|
|
|
PR_Now(),
|
|
|
|
std::numeric_limits<uint64_t>::max(),
|
|
|
|
callback);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
promise->MaybeReject(NS_ERROR_DOM_ABORT_ERR);
|
|
|
|
}
|
2014-08-21 13:15:18 +04:00
|
|
|
|
|
|
|
return promise.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|