diff --git a/browser/installer/package-manifest.in b/browser/installer/package-manifest.in index 003a42e1c111..ba802dc07852 100644 --- a/browser/installer/package-manifest.in +++ b/browser/installer/package-manifest.in @@ -552,6 +552,9 @@ @RESPATH@/components/SlowScriptDebug.manifest @RESPATH@/components/SlowScriptDebug.js +@RESPATH@/components/TVSimulatorService.js +@RESPATH@/components/TVSimulatorService.manifest + #ifndef RELEASE_BUILD @RESPATH@/components/InterAppComm.manifest @RESPATH@/components/InterAppCommService.js diff --git a/dom/tv/FakeTVService.cpp b/dom/tv/FakeTVService.cpp deleted file mode 100644 index a62620b33807..000000000000 --- a/dom/tv/FakeTVService.cpp +++ /dev/null @@ -1,532 +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 "mozilla/dom/TVServiceRunnables.h" -#include "mozilla/dom/TVTypes.h" -#include "nsCOMPtr.h" -#include "nsIMutableArray.h" -#include "nsITimer.h" -#include "nsServiceManagerUtils.h" -#include "prtime.h" -#include "FakeTVService.h" - -namespace mozilla { -namespace dom { - -NS_IMPL_CYCLE_COLLECTION_CLASS(FakeTVService) - -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(FakeTVService) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSourceListener) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTuners) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChannels) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPrograms) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mEITBroadcastedTimer) - NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mScanCompleteTimer) -NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END - -NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(FakeTVService) - tmp->Shutdown(); - NS_IMPL_CYCLE_COLLECTION_UNLINK(mSourceListener) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mTuners) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mChannels) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mPrograms) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mEITBroadcastedTimer) - NS_IMPL_CYCLE_COLLECTION_UNLINK(mScanCompleteTimer) -NS_IMPL_CYCLE_COLLECTION_UNLINK_END - -NS_IMPL_CYCLE_COLLECTING_ADDREF(FakeTVService) -NS_IMPL_CYCLE_COLLECTING_RELEASE(FakeTVService) - -NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FakeTVService) - NS_INTERFACE_MAP_ENTRY(nsITVService) - NS_INTERFACE_MAP_ENTRY(nsISupports) -NS_INTERFACE_MAP_END - -FakeTVService::FakeTVService() -{ - Init(); -} - -FakeTVService::~FakeTVService() -{ - Shutdown(); -} - -void -FakeTVService::Init() -{ - const char* sourceTypes1[2] = {"dvb-t", "dvb-c"}; - nsCOMPtr tunerData1 = MockTuner(NS_LITERAL_STRING("1"), 2, sourceTypes1); - mTuners.AppendElement(tunerData1); - const char* sourceTypes2[1] = {"dvb-s"}; - nsCOMPtr tunerData2 = MockTuner(NS_LITERAL_STRING("2"), 1, sourceTypes2); - mTuners.AppendElement(tunerData2); - - nsCOMPtr channelData1 = - MockChannel(NS_LITERAL_STRING("networkId1"), NS_LITERAL_STRING("transportStreamId1"), - NS_LITERAL_STRING("serviceId1"), NS_LITERAL_STRING("tv"), - NS_LITERAL_STRING("1"), NS_LITERAL_STRING("name1"), true, true); - mChannels.AppendElement(channelData1); - nsCOMPtr channelData2 = - MockChannel(NS_LITERAL_STRING("networkId2"), NS_LITERAL_STRING("transportStreamId2"), - NS_LITERAL_STRING("serviceId2"), NS_LITERAL_STRING("radio"), - NS_LITERAL_STRING("2"), NS_LITERAL_STRING("name2"), true, true); - mChannels.AppendElement(channelData2); - - uint64_t now = PR_Now(); - const char* audioLanguages1[2] = {"eng", "jpn"}; - const char* subtitleLanguages1[2] = {"fre", "spa"}; - nsCOMPtr programData1 = - MockProgram(NS_LITERAL_STRING("eventId1"), NS_LITERAL_STRING("title1"), - now - 1, 3600000, - NS_LITERAL_STRING("description1"), NS_LITERAL_STRING("rating1"), - 2, audioLanguages1, 2, subtitleLanguages1); - mPrograms.AppendElement(programData1); - nsCOMPtr programData2 = - MockProgram(NS_LITERAL_STRING("eventId2"), NS_LITERAL_STRING("title2"), - now + 3600000 , 3600000, - NS_LITERAL_STRING(""), NS_LITERAL_STRING(""), - 0, nullptr, 0, nullptr); - mPrograms.AppendElement(programData2); -} - -void -FakeTVService::Shutdown() -{ - if (mEITBroadcastedTimer) { - mEITBroadcastedTimer->Cancel(); - } - if (mScanCompleteTimer) { - mScanCompleteTimer->Cancel(); - } -} - -/* virtual */ NS_IMETHODIMP -FakeTVService::GetSourceListener(nsITVSourceListener** aSourceListener) -{ - if (!mSourceListener) { - *aSourceListener = nullptr; - return NS_OK; - } - - *aSourceListener = mSourceListener; - NS_ADDREF(*aSourceListener); - return NS_OK; -} - -/* virtual */ NS_IMETHODIMP -FakeTVService::SetSourceListener(nsITVSourceListener* aSourceListener) -{ - mSourceListener = aSourceListener; - return NS_OK; -} - -/* virtual */ NS_IMETHODIMP -FakeTVService::GetTuners(nsITVServiceCallback* aCallback) -{ - if (!aCallback) { - return NS_ERROR_INVALID_ARG; - } - - nsCOMPtr tunerDataList = do_CreateInstance(NS_ARRAY_CONTRACTID); - if (!tunerDataList) { - return NS_ERROR_OUT_OF_MEMORY; - } - - for (uint32_t i = 0; i < mTuners.Length(); i++) { - tunerDataList->AppendElement(mTuners[i], false); - } - - nsCOMPtr runnable = - new TVServiceNotifyRunnable(aCallback, tunerDataList); - return NS_DispatchToCurrentThread(runnable); -} - -/* virtual */ NS_IMETHODIMP -FakeTVService::SetSource(const nsAString& aTunerId, - const nsAString& aSourceType, - nsITVServiceCallback* aCallback) -{ - if (!aCallback) { - return NS_ERROR_INVALID_ARG; - } - - for (uint32_t i = 0; i < mTuners.Length(); i++) { - nsString tunerId; - mTuners[i]->GetId(tunerId); - if (aTunerId.Equals(tunerId)) { - uint32_t sourceTypeCount; - char** sourceTypes; - mTuners[i]->GetSupportedSourceTypes(&sourceTypeCount, &sourceTypes); - for (uint32_t j = 0; j < sourceTypeCount; j++) { - nsString sourceType; - sourceType.AssignASCII(sourceTypes[j]); - if (aSourceType.Equals(sourceType)) { - NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(sourceTypeCount, sourceTypes); - nsCOMPtr runnable = - new TVServiceNotifyRunnable(aCallback, nullptr); - return NS_DispatchToCurrentThread(runnable); - } - } - NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(sourceTypeCount, sourceTypes); - } - } - - nsCOMPtr runnable = - new TVServiceNotifyRunnable(aCallback, nullptr, nsITVServiceCallback::TV_ERROR_FAILURE); - return NS_DispatchToCurrentThread(runnable); -} - -class EITBroadcastedCallback final : public nsITimerCallback -{ -public: - NS_DECL_ISUPPORTS - - EITBroadcastedCallback(const nsAString& aTunerId, - const nsAString& aSourceType, - nsITVSourceListener* aSourceListener, - nsITVChannelData* aChannelData) - : mTunerId(aTunerId) - , mSourceType(aSourceType) - , mSourceListener(aSourceListener) - , mChannelData(aChannelData) - {} - - NS_IMETHODIMP - Notify(nsITimer* aTimer) override - { - // Notify mock EIT broadcasting. - nsITVProgramData** programDataList = - static_cast(moz_xmalloc(1 * sizeof(nsITVProgramData*))); - programDataList[0] = new TVProgramData(); - programDataList[0]->SetEventId(NS_LITERAL_STRING("eventId")); - programDataList[0]->SetTitle(NS_LITERAL_STRING("title")); - programDataList[0]->SetStartTime(PR_Now() + 3600000); - programDataList[0]->SetDuration(3600000); - programDataList[0]->SetDescription(NS_LITERAL_STRING("description")); - programDataList[0]->SetRating(NS_LITERAL_STRING("rating")); - programDataList[0]->SetAudioLanguages(0, nullptr); - programDataList[0]->SetSubtitleLanguages(0, nullptr); - nsresult rv = mSourceListener->NotifyEITBroadcasted(mTunerId, mSourceType, - mChannelData, - programDataList, 1); - NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(1, programDataList); - return rv; - } - -private: - ~EITBroadcastedCallback() {} - - nsString mTunerId; - nsString mSourceType; - nsCOMPtr mSourceListener; - nsCOMPtr mChannelData; -}; - -NS_IMPL_ISUPPORTS(EITBroadcastedCallback, nsITimerCallback) - -class ScanCompleteCallback final : public nsITimerCallback -{ -public: - NS_DECL_ISUPPORTS - - ScanCompleteCallback(const nsAString& aTunerId, - const nsAString& aSourceType, - nsITVSourceListener* aSourceListener) - : mTunerId(aTunerId) - , mSourceType(aSourceType) - , mSourceListener(aSourceListener) - {} - - NS_IMETHODIMP - Notify(nsITimer* aTimer) override - { - return mSourceListener->NotifyChannelScanComplete(mTunerId, mSourceType); - } - -private: - ~ScanCompleteCallback() {} - - nsString mTunerId; - nsString mSourceType; - nsCOMPtr mSourceListener; -}; - -NS_IMPL_ISUPPORTS(ScanCompleteCallback, nsITimerCallback) - -/* virtual */ NS_IMETHODIMP -FakeTVService::StartScanningChannels(const nsAString& aTunerId, - const nsAString& aSourceType, - nsITVServiceCallback* aCallback) -{ - if (!aCallback) { - return NS_ERROR_INVALID_ARG; - } - - nsCOMPtr runnable = - new TVServiceNotifyRunnable(aCallback, nullptr); - nsresult rv = NS_DispatchToCurrentThread(runnable); - NS_ENSURE_SUCCESS(rv, rv); - - if (IsAllowed(aTunerId, aSourceType)) { - rv = mSourceListener->NotifyChannelScanned(aTunerId, aSourceType, mChannels[0]); - NS_ENSURE_SUCCESS(rv, rv); - - // Set a timer. |notifyEITBroadcasted| will be called after the timer - // fires (10ms). (The timer could be canceled if |StopScanningChannels| gets - // called before firing.) - mEITBroadcastedTimer = do_CreateInstance(NS_TIMER_CONTRACTID); - NS_ENSURE_TRUE(mEITBroadcastedTimer, NS_ERROR_OUT_OF_MEMORY); - RefPtr eitBroadcastedCb = - new EITBroadcastedCallback(aTunerId, aSourceType, mSourceListener, mChannels[0]); - rv = mEITBroadcastedTimer->InitWithCallback(eitBroadcastedCb, 10, - nsITimer::TYPE_ONE_SHOT); - NS_ENSURE_SUCCESS(rv, rv); - - // Set a timer. |notifyChannelScanComplete| will be called after the timer - // fires (20ms). (The timer could be canceled if |StopScanningChannels| gets - // called before firing.) - mScanCompleteTimer = do_CreateInstance(NS_TIMER_CONTRACTID); - NS_ENSURE_TRUE(mScanCompleteTimer, NS_ERROR_OUT_OF_MEMORY); - RefPtr scanCompleteCb = - new ScanCompleteCallback(aTunerId, aSourceType, mSourceListener); - rv = mScanCompleteTimer->InitWithCallback(scanCompleteCb, 20, - nsITimer::TYPE_ONE_SHOT); - NS_ENSURE_SUCCESS(rv, rv); - } - - return NS_OK; -} - -/* virtual */ NS_IMETHODIMP -FakeTVService::StopScanningChannels(const nsAString& aTunerId, - const nsAString& aSourceType, - nsITVServiceCallback* aCallback) -{ - if (!aCallback) { - return NS_ERROR_INVALID_ARG; - } - - if (mEITBroadcastedTimer) { - mEITBroadcastedTimer->Cancel(); - mEITBroadcastedTimer = nullptr; - } - if (mScanCompleteTimer) { - mScanCompleteTimer->Cancel(); - mScanCompleteTimer = nullptr; - } - nsresult rv = mSourceListener->NotifyChannelScanStopped(aTunerId, aSourceType); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr runnable = - new TVServiceNotifyRunnable(aCallback, nullptr); - return NS_DispatchToCurrentThread(runnable); -} - -/* virtual */ NS_IMETHODIMP -FakeTVService::ClearScannedChannelsCache() -{ - // Fake service doesn't support channel cache, so there's nothing to do here. - return NS_OK; -} - -/* virtual */ NS_IMETHODIMP -FakeTVService::SetChannel(const nsAString& aTunerId, - const nsAString& aSourceType, - const nsAString& aChannelNumber, - nsITVServiceCallback* aCallback) -{ - if (!aCallback) { - return NS_ERROR_INVALID_ARG; - } - - nsCOMPtr channelDataList = do_CreateInstance(NS_ARRAY_CONTRACTID); - if (!channelDataList) { - return NS_ERROR_OUT_OF_MEMORY; - } - - if (IsAllowed(aTunerId, aSourceType)) { - for (uint32_t i = 0; i < mChannels.Length(); i++) { - nsString channelNumber; - mChannels[i]->GetNumber(channelNumber); - if (aChannelNumber.Equals(channelNumber)) { - channelDataList->AppendElement(mChannels[i], false); - break; - } - } - } - - uint32_t length; - nsresult rv = channelDataList->GetLength(&length); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr runnable = new TVServiceNotifyRunnable( - aCallback, - (length == 1) ? channelDataList : nullptr, - (length == 1) ? nsITVServiceCallback::TV_ERROR_OK : nsITVServiceCallback::TV_ERROR_FAILURE - ); - return NS_DispatchToCurrentThread(runnable); -} - -/* virtual */ NS_IMETHODIMP -FakeTVService::GetChannels(const nsAString& aTunerId, - const nsAString& aSourceType, - nsITVServiceCallback* aCallback) -{ - if (!aCallback) { - return NS_ERROR_INVALID_ARG; - } - - nsCOMPtr channelDataList = do_CreateInstance(NS_ARRAY_CONTRACTID); - if (!channelDataList) { - return NS_ERROR_OUT_OF_MEMORY; - } - - if (IsAllowed(aTunerId, aSourceType)) { - for (uint32_t i = 0; i < mChannels.Length(); i++) { - channelDataList->AppendElement(mChannels[i], false); - } - } - - nsCOMPtr runnable = - new TVServiceNotifyRunnable(aCallback, channelDataList); - return NS_DispatchToCurrentThread(runnable); -} - -/* virtual */ NS_IMETHODIMP -FakeTVService::GetPrograms(const nsAString& aTunerId, - const nsAString& aSourceType, - const nsAString& aChannelNumber, - uint64_t startTime, - uint64_t endTime, - nsITVServiceCallback* aCallback) -{ - if (!aCallback) { - return NS_ERROR_INVALID_ARG; - } - - nsCOMPtr programDataList = do_CreateInstance(NS_ARRAY_CONTRACTID); - if (!programDataList) { - return NS_ERROR_OUT_OF_MEMORY; - } - - // Only return mock programs for the first channel. - nsString channelNumber; - mChannels[0]->GetNumber(channelNumber); - if (IsAllowed(aTunerId, aSourceType) && aChannelNumber.Equals(channelNumber)) { - for (uint32_t i = 0; i < mPrograms.Length(); i++) { - programDataList->AppendElement(mPrograms[i], false); - } - } - - nsCOMPtr runnable = - new TVServiceNotifyRunnable(aCallback, programDataList); - return NS_DispatchToCurrentThread(runnable); -} - -/* virtual */ NS_IMETHODIMP -FakeTVService::GetOverlayId(const nsAString& aTunerId, - nsITVServiceCallback* aCallback) -{ - if (!aCallback) { - return NS_ERROR_INVALID_ARG; - } - - nsCOMPtr overlayIds = do_CreateInstance(NS_ARRAY_CONTRACTID); - if (!overlayIds) { - return NS_ERROR_OUT_OF_MEMORY; - } - - // TODO Implement in follow-up patches. - - nsCOMPtr runnable = - new TVServiceNotifyRunnable(aCallback, overlayIds); - return NS_DispatchToCurrentThread(runnable); -} - -bool -FakeTVService::IsAllowed(const nsAString& aTunerId, - const nsAString& aSourceType) -{ - // Only allow for the first source of the first tuner. - nsString tunerId; - mTuners[0]->GetId(tunerId); - if (!aTunerId.Equals(tunerId)) { - return false; - } - - uint32_t sourceTypeCount; - char** sourceTypes; - mTuners[0]->GetSupportedSourceTypes(&sourceTypeCount, &sourceTypes); - nsString sourceType; - sourceType.AssignASCII(sourceTypes[0]); - NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(sourceTypeCount, sourceTypes); - if (!aSourceType.Equals(sourceType)) { - return false; - } - - return true; -} - -already_AddRefed -FakeTVService::MockTuner(const nsAString& aId, - uint32_t aSupportedSourceTypeCount, - const char** aSupportedSourceTypes) -{ - nsCOMPtr tunerData = new TVTunerData(); - tunerData->SetId(aId); - tunerData->SetSupportedSourceTypes(aSupportedSourceTypeCount, aSupportedSourceTypes); - return tunerData.forget(); -} - -already_AddRefed -FakeTVService::MockChannel(const nsAString& aNetworkId, - const nsAString& aTransportStreamId, - const nsAString& aServiceId, - const nsAString& aType, - const nsAString& aNumber, - const nsAString& aName, - bool aIsEmergency, - bool aIsFree) -{ - nsCOMPtr channelData = new TVChannelData(); - channelData->SetNetworkId(aNetworkId); - channelData->SetTransportStreamId(aTransportStreamId); - channelData->SetServiceId(aServiceId); - channelData->SetType(aType); - channelData->SetNumber(aNumber); - channelData->SetName(aName); - channelData->SetIsEmergency(aIsEmergency); - channelData->SetIsFree(aIsFree); - return channelData.forget(); -} - -already_AddRefed -FakeTVService::MockProgram(const nsAString& aEventId, - const nsAString& aTitle, - uint64_t aStartTime, - uint64_t aDuration, - const nsAString& aDescription, - const nsAString& aRating, - uint32_t aAudioLanguageCount, - const char** aAudioLanguages, - uint32_t aSubtitleLanguageCount, - const char** aSubtitleLanguages) -{ - nsCOMPtr programData = new TVProgramData(); - programData->SetEventId(aEventId); - programData->SetTitle(aTitle); - programData->SetStartTime(aStartTime); - programData->SetDuration(aDuration); - programData->SetDescription(aDescription); - programData->SetRating(aRating); - programData->SetAudioLanguages(aAudioLanguageCount, aAudioLanguages); - programData->SetSubtitleLanguages(aSubtitleLanguageCount, aSubtitleLanguages); - return programData.forget(); -} - -} // namespace dom -} // namespace mozilla diff --git a/dom/tv/FakeTVService.h b/dom/tv/FakeTVService.h deleted file mode 100644 index 5ab07108a3bc..000000000000 --- a/dom/tv/FakeTVService.h +++ /dev/null @@ -1,84 +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_FakeTVService_h -#define mozilla_dom_FakeTVService_h - -#include "nsCOMPtr.h" -#include "nsCycleCollectionParticipant.h" -#include "nsITVService.h" -#include "nsTArray.h" - -#define FAKE_TV_SERVICE_CONTRACTID \ - "@mozilla.org/tv/faketvservice;1" -#define FAKE_TV_SERVICE_CID \ - { 0x60fb3c53, 0x017f, 0x4340, { 0x91, 0x1b, 0xd5, 0x5c, 0x31, 0x28, 0x88, 0xb6 } } - -class nsITimer; -class nsITVTunerData; -class nsITVChannelData; -class nsITVProgramData; - -namespace mozilla { -namespace dom { - -class FakeTVService final : public nsITVService -{ -public: - NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_CLASS(FakeTVService) - NS_DECL_NSITVSERVICE - - FakeTVService(); - -private: - ~FakeTVService(); - - void Init(); - - void Shutdown(); - - bool IsAllowed(const nsAString& aTunerId, - const nsAString& aSourceType); - - already_AddRefed MockTuner(const nsAString& aId, - uint32_t aSupportedSourceTypeCount, - const char** aSupportedSourceTypes); - - already_AddRefed MockChannel(const nsAString& aNetworkId, - const nsAString& aTransportStreamId, - const nsAString& aServiceId, - const nsAString& aType, - const nsAString& aNumber, - const nsAString& aName, - bool aIsEmergency, - bool aIsFree); - - already_AddRefed MockProgram(const nsAString& aEventId, - const nsAString& aTitle, - uint64_t aStartTime, - uint64_t aDuration, - const nsAString& aDescription, - const nsAString& aRating, - uint32_t aAudioLanguageCount, - const char** aAudioLanguages, - uint32_t aSubtitleLanguageCount, - const char** aSubtitleLanguages); - - nsCOMPtr mSourceListener; - - // The real implementation may want to use more efficient data structures. - nsTArray> mTuners; - nsTArray> mChannels; - nsTArray> mPrograms; - nsCOMPtr mEITBroadcastedTimer; - nsCOMPtr mScanCompleteTimer; -}; - -} // namespace dom -} // namespace mozilla - -#endif // mozilla_dom_FakeTVService_h diff --git a/dom/tv/TVServiceFactory.cpp b/dom/tv/TVServiceFactory.cpp index 70979505b36a..2a2fda4463b1 100644 --- a/dom/tv/TVServiceFactory.cpp +++ b/dom/tv/TVServiceFactory.cpp @@ -4,7 +4,6 @@ * 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/FakeTVService.h" #include "mozilla/dom/TVListeners.h" #include "mozilla/Preferences.h" #include "nsITVService.h" @@ -15,26 +14,14 @@ namespace mozilla { namespace dom { -/* static */ already_AddRefed -TVServiceFactory::CreateFakeTVService() -{ - RefPtr service = new FakeTVService(); - return service.forget(); -} - /* static */ already_AddRefed TVServiceFactory::AutoCreateTVService() { - nsresult rv; + nsresult rv = NS_OK; nsCOMPtr service = do_CreateInstance(TV_SERVICE_CONTRACTID); if (!service) { - if (Preferences::GetBool("dom.ignore_webidl_scope_checks", false)) { - // Fallback to the fake service. - service = do_CreateInstance(FAKE_TV_SERVICE_CONTRACTID, &rv); - } else { - // Fallback to the TV Simulator Service - service = do_CreateInstance(TV_SIMULATOR_SERVICE_CONTRACTID, &rv); - } + // Fallback to the TV Simulator Service + service = do_CreateInstance(TV_SIMULATOR_SERVICE_CONTRACTID, &rv); if (NS_WARN_IF(NS_FAILED(rv))) { return nullptr; diff --git a/dom/tv/TVServiceFactory.h b/dom/tv/TVServiceFactory.h index 004bc7ae6f00..93e81a83391a 100644 --- a/dom/tv/TVServiceFactory.h +++ b/dom/tv/TVServiceFactory.h @@ -14,13 +14,9 @@ class nsITVService; namespace mozilla { namespace dom { -class FakeTVService; - class TVServiceFactory { public: - static already_AddRefed CreateFakeTVService(); - static already_AddRefed AutoCreateTVService(); }; diff --git a/dom/tv/TVSimulatorService.js b/dom/tv/TVSimulatorService.js index 785e9d8d2230..8b641e055fbb 100644 --- a/dom/tv/TVSimulatorService.js +++ b/dom/tv/TVSimulatorService.js @@ -13,9 +13,11 @@ const Ci = Components.interfaces; const Cr = Components.returnCode; Cu.importGlobalProperties(["File"]); +Cu.import("resource://gre/modules/Services.jsm"); -const TV_SIMULATOR_DUMMY_DIRECTORY = "dummy"; -const TV_SIMULATOR_DUMMY_FILE = "settings.json"; +const TV_SIMULATOR_DUMMY_DIRECTORY = "dummy"; +const TV_SIMULATOR_DUMMY_FILE = "settings.json"; +const TV_SIMULATOR_MOCK_DATA = Services.prefs.getCharPref("dom.testing.tv_mock_data"); // See http://seanyhlin.github.io/TV-Manager-API/#idl-def-TVSourceType const TV_SOURCE_TYPES = ["dvb-t","dvb-t2","dvb-c","dvb-c2","dvb-s", @@ -49,36 +51,16 @@ TVSimulatorService.prototype = { return; } - // Load the setting file from local JSON file. - // Synchrhronous File Reading. - let file = Cc["@mozilla.org/file/local;1"] - .createInstance(Ci.nsILocalFile); - - file.initWithPath(this._getFilePath(TV_SIMULATOR_DUMMY_FILE)); - - let fstream = Cc["@mozilla.org/network/file-input-stream;1"] - .createInstance(Ci.nsIFileInputStream); - let cstream = Cc["@mozilla.org/intl/converter-input-stream;1"] - .createInstance(Ci.nsIConverterInputStream); - let settingStr = ""; - try { - fstream.init(file, -1, 0, 0); - cstream.init(fstream, - "UTF-8", - 1024, - Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER); - - let str = {}; - while (cstream.readString(0xffffffff, str) != 0) { - settingStr += str.value; + if (TV_SIMULATOR_MOCK_DATA) { + settingStr = TV_SIMULATOR_MOCK_DATA; + } else { + settingStr = this._getDummyData(); } } catch(e) { debug("Error occurred : " + e ); return; - } finally { - cstream.close(); } let settingsObj; @@ -281,10 +263,11 @@ TVSimulatorService.prototype = { } this._scanCompleteTimer = null; + let notifyResult = this._sourceListener.notifyChannelScanComplete( + this._scanningWrapTunerData.tuner.id, + this._scanningWrapTunerData.sourceType); this._scanningWrapTunerData = null; - return this._sourceListener.notifyChannelScanComplete( - this._scanningWrapTunerData.tuner.id, - this._scanningWrapTunerData.sourceType); + return notifyResult; }, stopScanningChannels: function TVSimStopScanningChannels(aTunerId, aSourceType, aCallback) { @@ -434,6 +417,41 @@ TVSimulatorService.prototype = { return videoBlobURL; }, + _getDummyData : function TVSimGetDummyData() { + // Load the setting file from local JSON file. + // Synchrhronous File Reading. + let file = Cc["@mozilla.org/file/local;1"] + .createInstance(Ci.nsILocalFile); + + let fstream = Cc["@mozilla.org/network/file-input-stream;1"] + .createInstance(Ci.nsIFileInputStream); + let cstream = Cc["@mozilla.org/intl/converter-input-stream;1"] + .createInstance(Ci.nsIConverterInputStream); + + let settingsStr = ""; + + try { + file.initWithPath(this._getFilePath(TV_SIMULATOR_DUMMY_FILE)); + fstream.init(file, -1, 0, 0); + cstream.init(fstream, + "UTF-8", + 1024, + Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER); + + let str = {}; + while (cstream.readString(0xffffffff, str) != 0) { + settingsStr += str.value; + } + } catch(e) { + debug("Catch the Exception when reading the dummy file:" + e ); + throw e; + } finally { + cstream.close(); + } + + return settingsStr; + }, + _getTunerMapKey: function TVSimGetTunerMapKey(aTunerId, aSourceType) { return JSON.stringify({'tunerId': aTunerId, 'sourceType': aSourceType}); }, diff --git a/dom/tv/moz.build b/dom/tv/moz.build index 58a9ff9808e8..44bd63a03b54 100644 --- a/dom/tv/moz.build +++ b/dom/tv/moz.build @@ -5,7 +5,6 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. EXPORTS.mozilla.dom += [ - 'FakeTVService.h', 'TVChannel.h', 'TVListeners.h', 'TVManager.h', @@ -20,7 +19,6 @@ EXPORTS.mozilla.dom += [ ] UNIFIED_SOURCES += [ - 'FakeTVService.cpp', 'TVChannel.cpp', 'TVListeners.cpp', 'TVManager.cpp', diff --git a/dom/tv/test/mochitest/head.js b/dom/tv/test/mochitest/head.js index 3afe89296c62..27471e929d13 100644 --- a/dom/tv/test/mochitest/head.js +++ b/dom/tv/test/mochitest/head.js @@ -9,8 +9,20 @@ function setupPrefsAndPermissions(callback) { } function setupPrefs(callback) { - SpecialPowers.pushPrefEnv({"set": [["dom.tv.enabled", true], - ["dom.ignore_webidl_scope_checks", true]]}, function() { + let xhr = new XMLHttpRequest; + let data; + + xhr.open("GET", "./mock_data.json", false); + xhr.send(null); + if (xhr.status == 200) { + data = xhr.responseText; + } + + SpecialPowers.pushPrefEnv({"set": [ + ["dom.tv.enabled", true], + ["dom.ignore_webidl_scope_checks", true], + ["dom.testing.tv_mock_data", data] + ]}, function() { callback(); }); } diff --git a/dom/tv/test/mochitest/mochitest.ini b/dom/tv/test/mochitest/mochitest.ini index 8b58db1f9048..60df11a3026f 100644 --- a/dom/tv/test/mochitest/mochitest.ini +++ b/dom/tv/test/mochitest/mochitest.ini @@ -1,6 +1,8 @@ [DEFAULT] -support-files = head.js -skip-if = (os == 'mac' && debug) || asan # Bug 1125477 +support-files = + head.js + mock_data.json + [test_tv_non_permitted_app.html] [test_tv_permitted_app.html] [test_tv_get_tuners.html] diff --git a/dom/tv/test/mochitest/mock_data.json b/dom/tv/test/mochitest/mock_data.json new file mode 100644 index 000000000000..b2a4f8e73be6 --- /dev/null +++ b/dom/tv/test/mochitest/mock_data.json @@ -0,0 +1,99 @@ +{ + "tuners": [ + { + "id":"1", + "supportedType": ["dvb-t"], + "sources": [ + { + "type": "dvb-t", + "channels": [ + { + "networkId": "32112", + "transportStreamId": "32112", + "serviceId": "40960", + "type": "tv", + "name": "TV #1", + "number" : 1, + "isEmergency": false, + "isFree" : true, + "videoFilePath": "tv1.ogv", + "programs": [ + {"eventId":"734475972", "title":"News of Morning", "startTime":"1430686800", "duration":"10800", "description":"Morning News", "rating":"0", "audioLanguages":["eng"], "subtitleLanguages":["eng"]}, + {"eventId":"422158917", "title":"News of Midnight", "startTime":"1431266400", "duration":"3600", "description":"Summary of today news", "rating":"0", "audioLanguages":["eng"], "subtitleLanguages":["eng"]}, + {"eventId":"533612446", "title":"Entertainment Program", "startTime":"1431270000", "duration":"7200", "description":"Midnight entertainment program", "rating":"0", "audioLanguages":["eng"], "subtitleLanguages":["eng"]} + ] + }, + { + "_comment": "Channel Data", + "networkId": "32122", + "transportStreamId": "32122", + "serviceId": "40990", + "type": "tv", + "name": "TV #2", + "number" : 2, + "isEmergency": false, + "isFree" : true, + "videoFilePath": "tv2.ogv", + "programs": [ + {"eventId":"931109607","title":"News of Morning", "startTime":"1430686800", "duration":"10800", "description":"Provide news in morning", "rating":"0", "audioLanguages":["eng"], "subtitleLanguages":["eng"]}, + {"eventId":"297834220","title":"Weekly News", "startTime":"1431259200", "duration":"10800", "description":"Poopular Music program", "rating":"0", "audioLanguages":["eng"], "subtitleLanguages":["eng"]}, + {"eventId":"866886159","title":"Weekly news", "startTime":"1431270000", "duration":"7200", "description":"Information program on Monday", "rating":"0", "audioLanguages":["eng"], "subtitleLanguages":["eng"]} + ] + }, + { + "_comment": "Channel Data", + "networkId": "32132", + "transportStreamId": "32132", + "serviceId": "41020", + "type": "tv", + "name": "TV #3", + "number" : 3, + "isEmergency": false, + "isFree" : true, + "videoFilePath": "tv1.ogv", + "programs": [ + {"eventId":"734475972", "title":"News of Morning", "startTime":"1430686800", "duration":"10800", "description":"Morning News", "rating":"0", "audioLanguages":["eng"], "subtitleLanguages":["eng"]}, + {"eventId":"586216742", "title":"Information Program", "startTime":"1430697600", "duration":"7200", "description":"Provide program Information.", "rating":"0", "audioLanguages":["eng"], "subtitleLanguages":["eng"]}, + {"eventId":"533612446", "title":"Entertainment Program", "startTime":"1431270000", "duration":"7200", "description":"Midnight entertainment program", "rating":"0", "audioLanguages":["eng"], "subtitleLanguages":["eng"]} + ] + }, + { + "_comment": "Channel Data", + "networkId": "32142", + "transportStreamId": "32142", + "serviceId": "41040", + "type": "tv", + "name": "TV #5", + "number" : 4, + "isEmergency": false, + "isFree" : true, + "videoFilePath": "tv2.ogv", + "programs": [ + {"eventId":"931109607","title":"News of Morning", "startTime":"1430686800", "duration":"10800", "description":"Provide news in morning", "rating":"0", "audioLanguages":["eng"], "subtitleLanguages":["eng"]}, + {"eventId":"297834220","title":"Weekly News", "startTime":"1431259200", "duration":"10800", "description":"Poopular Music program", "rating":"0", "audioLanguages":["eng"], "subtitleLanguages":["eng"]}, + {"eventId":"866886159","title":"Weekly news", "startTime":"1431270000", "duration":"7200", "description":"Information program on Monday", "rating":"0", "audioLanguages":["eng"], "subtitleLanguages":["eng"]} + ] + }, + { + "_comment": "Channel Data", + "networkId": "32152", + "transportStreamId": "32152", + "serviceId": "41060", + "type": "tv", + "name": "TV #5", + "number" : 5, + "isEmergency": false, + "isFree" : true, + "videoFilePath": "tv1.ogv", + "programs": [ + {"eventId":"734475972", "title":"News of Morning", "startTime":"1430686800", "duration":"10800", "description":"Morning News", "rating":"0", "audioLanguages":["eng"], "subtitleLanguages":["eng"]}, + {"eventId":"586216742", "title":"Information Program", "startTime":"1430697600", "duration":"7200", "description":"Provide program Information.", "rating":"0", "audioLanguages":["eng"], "subtitleLanguages":["eng"]}, + {"eventId":"533612446", "title":"Entertainment Program", "startTime":"1431270000", "duration":"7200", "description":"Midnight entertainment program", "rating":"0", "audioLanguages":["eng"], "subtitleLanguages":["eng"]} + ] + } + ] + } + ] + } + ] +} \ No newline at end of file diff --git a/layout/build/nsLayoutModule.cpp b/layout/build/nsLayoutModule.cpp index 6d5ae658ea3f..3ac31e4178b9 100644 --- a/layout/build/nsLayoutModule.cpp +++ b/layout/build/nsLayoutModule.cpp @@ -240,7 +240,6 @@ static void Shutdown(); #include "nsITelephonyService.h" #include "nsIVoicemailService.h" -#include "mozilla/dom/FakeTVService.h" #include "mozilla/dom/TVServiceFactory.h" #include "mozilla/dom/TVTypes.h" #include "nsITVService.h" @@ -387,8 +386,6 @@ NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsITelephonyService, NS_CreateTelephonyService) NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIVoicemailService, NS_CreateVoicemailService) -NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(FakeTVService, - TVServiceFactory::CreateFakeTVService) NS_GENERIC_FACTORY_CONSTRUCTOR(TVTunerData) NS_GENERIC_FACTORY_CONSTRUCTOR(TVChannelData) NS_GENERIC_FACTORY_CONSTRUCTOR(TVProgramData) @@ -846,7 +843,6 @@ NS_DEFINE_NAMED_CID(NS_SYNTHVOICEREGISTRY_CID); #ifdef ACCESSIBILITY NS_DEFINE_NAMED_CID(NS_ACCESSIBILITY_SERVICE_CID); #endif -NS_DEFINE_NAMED_CID(FAKE_TV_SERVICE_CID); NS_DEFINE_NAMED_CID(TV_TUNER_DATA_CID); NS_DEFINE_NAMED_CID(TV_CHANNEL_DATA_CID); NS_DEFINE_NAMED_CID(TV_PROGRAM_DATA_CID); @@ -1149,7 +1145,6 @@ static const mozilla::Module::CIDEntry kLayoutCIDs[] = { { &kTELEPHONY_SERVICE_CID, false, nullptr, nsITelephonyServiceConstructor }, { &kNS_MOBILE_CONNECTION_SERVICE_CID, false, NULL, nsIMobileConnectionServiceConstructor }, { &kNS_VOICEMAIL_SERVICE_CID, false, nullptr, nsIVoicemailServiceConstructor }, - { &kFAKE_TV_SERVICE_CID, false, nullptr, FakeTVServiceConstructor }, { &kTV_TUNER_DATA_CID, false, nullptr, TVTunerDataConstructor }, { &kTV_CHANNEL_DATA_CID, false, nullptr, TVChannelDataConstructor }, { &kTV_PROGRAM_DATA_CID, false, nullptr, TVProgramDataConstructor }, @@ -1313,7 +1308,6 @@ static const mozilla::Module::ContractIDEntry kLayoutContracts[] = { { "@mozilla.org/accessibleRetrieval;1", &kNS_ACCESSIBILITY_SERVICE_CID }, #endif { TELEPHONY_SERVICE_CONTRACTID, &kTELEPHONY_SERVICE_CID }, - { FAKE_TV_SERVICE_CONTRACTID, &kFAKE_TV_SERVICE_CID }, { TV_TUNER_DATA_CONTRACTID, &kTV_TUNER_DATA_CID }, { TV_CHANNEL_DATA_CONTRACTID, &kTV_CHANNEL_DATA_CID }, { TV_PROGRAM_DATA_CONTRACTID, &kTV_PROGRAM_DATA_CID }, diff --git a/mobile/android/installer/package-manifest.in b/mobile/android/installer/package-manifest.in index 3e19d96ee8f6..560a0f27fea2 100644 --- a/mobile/android/installer/package-manifest.in +++ b/mobile/android/installer/package-manifest.in @@ -472,6 +472,9 @@ @BINPATH@/components/PACGenerator.js @BINPATH@/components/PACGenerator.manifest +@BINPATH@/components/TVSimulatorService.js +@BINPATH@/components/TVSimulatorService.manifest + ; Modules @BINPATH@/modules/*