2017-10-27 01:08:41 +03: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: */
|
2015-05-21 06:06:00 +03:00
|
|
|
/* 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 "MulticastDNSDeviceProvider.h"
|
2016-08-26 05:59:27 +03:00
|
|
|
|
|
|
|
#include "DeviceProviderHelpers.h"
|
2015-09-09 00:42:00 +03:00
|
|
|
#include "MainThreadUtils.h"
|
2016-12-16 06:16:31 +03:00
|
|
|
#include "mozilla/IntegerPrintfMacros.h"
|
2015-05-21 06:06:00 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2015-07-30 19:40:00 +03:00
|
|
|
#include "mozilla/Preferences.h"
|
2016-08-23 07:09:32 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2015-05-21 06:06:00 +03:00
|
|
|
#include "nsComponentManagerUtils.h"
|
2015-07-30 19:40:00 +03:00
|
|
|
#include "nsIObserverService.h"
|
2016-05-27 02:22:27 +03:00
|
|
|
#include "nsIWritablePropertyBag2.h"
|
2015-05-21 06:06:00 +03:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2016-04-28 10:05:53 +03:00
|
|
|
#include "nsTCPDeviceInfo.h"
|
2015-11-03 03:04:00 +03:00
|
|
|
#include "nsThreadUtils.h"
|
2015-05-21 06:06:00 +03:00
|
|
|
|
2015-10-20 11:47:56 +03:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
# include "nsIPropertyBag2.h"
|
|
|
|
#endif // MOZ_WIDGET_ANDROID
|
|
|
|
|
2015-07-30 19:40:00 +03:00
|
|
|
#define PREF_PRESENTATION_DISCOVERY "dom.presentation.discovery.enabled"
|
2015-10-01 00:55:00 +03:00
|
|
|
#define PREF_PRESENTATION_DISCOVERY_TIMEOUT_MS \
|
|
|
|
"dom.presentation.discovery.timeout_ms"
|
2015-07-30 19:40:00 +03:00
|
|
|
#define PREF_PRESENTATION_DISCOVERABLE "dom.presentation.discoverable"
|
2016-07-26 05:59:52 +03:00
|
|
|
#define PREF_PRESENTATION_DISCOVERABLE_ENCRYPTED \
|
|
|
|
"dom.presentation.discoverable.encrypted"
|
2016-08-02 05:48:22 +03:00
|
|
|
#define PREF_PRESENTATION_DISCOVERABLE_RETRY_MS \
|
|
|
|
"dom.presentation.discoverable.retry_ms"
|
2015-07-30 19:40:00 +03:00
|
|
|
#define PREF_PRESENTATION_DEVICE_NAME "dom.presentation.device.name"
|
|
|
|
|
2016-05-27 02:22:27 +03:00
|
|
|
#define SERVICE_TYPE "_presentation-ctrl._tcp"
|
|
|
|
#define PROTOCOL_VERSION_TAG "version"
|
2016-07-18 13:45:07 +03:00
|
|
|
#define CERT_FINGERPRINT_TAG "certFingerprint"
|
2015-07-30 19:40:00 +03:00
|
|
|
|
2015-11-03 03:04:00 +03:00
|
|
|
static mozilla::LazyLogModule sMulticastDNSProviderLogModule(
|
|
|
|
"MulticastDNSDeviceProvider");
|
|
|
|
|
2015-05-21 06:06:00 +03:00
|
|
|
#undef LOG_I
|
2015-11-03 03:04:00 +03:00
|
|
|
#define LOG_I(...) \
|
|
|
|
MOZ_LOG(sMulticastDNSProviderLogModule, mozilla::LogLevel::Debug, \
|
|
|
|
(__VA_ARGS__))
|
2015-05-21 06:06:00 +03:00
|
|
|
#undef LOG_E
|
2015-11-03 03:04:00 +03:00
|
|
|
#define LOG_E(...) \
|
|
|
|
MOZ_LOG(sMulticastDNSProviderLogModule, mozilla::LogLevel::Error, \
|
|
|
|
(__VA_ARGS__))
|
2015-05-21 06:06:00 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
namespace presentation {
|
|
|
|
|
2015-07-30 19:40:00 +03:00
|
|
|
static const char* kObservedPrefs[] = {
|
2015-10-01 00:55:00 +03:00
|
|
|
PREF_PRESENTATION_DISCOVERY, PREF_PRESENTATION_DISCOVERY_TIMEOUT_MS,
|
2015-07-30 19:40:00 +03:00
|
|
|
PREF_PRESENTATION_DISCOVERABLE, PREF_PRESENTATION_DEVICE_NAME, nullptr};
|
|
|
|
|
2015-10-19 05:44:59 +03:00
|
|
|
namespace {
|
|
|
|
|
2015-10-20 11:47:56 +03:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
static void GetAndroidDeviceName(nsACString& aRetVal) {
|
|
|
|
nsCOMPtr<nsIPropertyBag2> infoService =
|
|
|
|
do_GetService("@mozilla.org/system-info;1");
|
|
|
|
MOZ_ASSERT(infoService, "Could not find a system info service");
|
|
|
|
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << NS_WARN_IF(NS_FAILED(infoService->GetPropertyAsACString(
|
2015-10-20 11:47:56 +03:00
|
|
|
NS_LITERAL_STRING("device"), aRetVal)));
|
|
|
|
}
|
|
|
|
#endif // MOZ_WIDGET_ANDROID
|
|
|
|
|
2015-10-19 05:44:59 +03:00
|
|
|
} // anonymous namespace
|
|
|
|
|
2015-05-21 06:06:00 +03:00
|
|
|
/**
|
|
|
|
* This wrapper is used to break circular-reference problem.
|
|
|
|
*/
|
|
|
|
class DNSServiceWrappedListener final
|
|
|
|
: public nsIDNSServiceDiscoveryListener,
|
|
|
|
public nsIDNSRegistrationListener,
|
|
|
|
public nsIDNSServiceResolveListener,
|
2016-05-20 09:53:30 +03:00
|
|
|
public nsIPresentationControlServerListener {
|
2015-05-21 06:06:00 +03:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_FORWARD_SAFE_NSIDNSSERVICEDISCOVERYLISTENER(mListener)
|
|
|
|
NS_FORWARD_SAFE_NSIDNSREGISTRATIONLISTENER(mListener)
|
|
|
|
NS_FORWARD_SAFE_NSIDNSSERVICERESOLVELISTENER(mListener)
|
2016-05-20 09:53:30 +03:00
|
|
|
NS_FORWARD_SAFE_NSIPRESENTATIONCONTROLSERVERLISTENER(mListener)
|
2015-05-21 06:06:00 +03:00
|
|
|
|
|
|
|
explicit DNSServiceWrappedListener() = default;
|
|
|
|
|
|
|
|
nsresult SetListener(MulticastDNSDeviceProvider* aListener) {
|
|
|
|
mListener = aListener;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~DNSServiceWrappedListener() = default;
|
|
|
|
|
|
|
|
MulticastDNSDeviceProvider* mListener = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(DNSServiceWrappedListener, nsIDNSServiceDiscoveryListener,
|
|
|
|
nsIDNSRegistrationListener, nsIDNSServiceResolveListener,
|
2016-05-20 09:53:30 +03:00
|
|
|
nsIPresentationControlServerListener)
|
2015-05-21 06:06:00 +03:00
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(MulticastDNSDeviceProvider, nsIPresentationDeviceProvider,
|
|
|
|
nsIDNSServiceDiscoveryListener, nsIDNSRegistrationListener,
|
|
|
|
nsIDNSServiceResolveListener,
|
2016-05-20 09:53:30 +03:00
|
|
|
nsIPresentationControlServerListener, nsIObserver)
|
2015-05-21 06:06:00 +03:00
|
|
|
|
2019-01-24 02:45:56 +03:00
|
|
|
MulticastDNSDeviceProvider::MulticastDNSDeviceProvider() {}
|
2015-05-21 06:06:00 +03:00
|
|
|
MulticastDNSDeviceProvider::~MulticastDNSDeviceProvider() { Uninit(); }
|
|
|
|
|
|
|
|
nsresult MulticastDNSDeviceProvider::Init() {
|
2015-09-09 00:42:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-05-21 06:06:00 +03:00
|
|
|
if (mInitialized) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
mMulticastDNS = do_GetService(DNSSERVICEDISCOVERY_CONTRACT_ID, &rv);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
mWrappedListener = new DNSServiceWrappedListener();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv = mWrappedListener->SetListener(this)))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2016-05-20 09:53:30 +03:00
|
|
|
mPresentationService =
|
|
|
|
do_CreateInstance(PRESENTATION_CONTROL_SERVICE_CONTACT_ID, &rv);
|
2015-05-21 06:06:00 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2017-10-16 09:15:40 +03:00
|
|
|
mDiscoveryTimer = NS_NewTimer();
|
|
|
|
if (NS_WARN_IF(!mDiscoveryTimer)) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2015-10-01 00:55:00 +03:00
|
|
|
}
|
|
|
|
|
2017-10-16 09:15:40 +03:00
|
|
|
mServerRetryTimer = NS_NewTimer();
|
|
|
|
if (NS_WARN_IF(!mServerRetryTimer)) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2016-08-02 05:48:22 +03:00
|
|
|
}
|
2015-07-30 19:40:00 +03:00
|
|
|
Preferences::AddStrongObservers(this, kObservedPrefs);
|
|
|
|
|
|
|
|
mDiscoveryEnabled = Preferences::GetBool(PREF_PRESENTATION_DISCOVERY);
|
2016-06-01 04:45:16 +03:00
|
|
|
mDiscoveryTimeoutMs =
|
|
|
|
Preferences::GetUint(PREF_PRESENTATION_DISCOVERY_TIMEOUT_MS);
|
2015-07-30 19:40:00 +03:00
|
|
|
mDiscoverable = Preferences::GetBool(PREF_PRESENTATION_DISCOVERABLE);
|
2016-07-26 05:59:52 +03:00
|
|
|
mDiscoverableEncrypted =
|
|
|
|
Preferences::GetBool(PREF_PRESENTATION_DISCOVERABLE_ENCRYPTED);
|
2016-08-02 05:48:22 +03:00
|
|
|
mServerRetryMs =
|
|
|
|
Preferences::GetUint(PREF_PRESENTATION_DISCOVERABLE_RETRY_MS);
|
2017-07-31 07:28:48 +03:00
|
|
|
mServiceName.Truncate();
|
|
|
|
Preferences::GetCString(PREF_PRESENTATION_DEVICE_NAME, mServiceName);
|
2015-07-30 19:40:00 +03:00
|
|
|
|
2015-10-20 11:47:56 +03:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
|
|
|
// FIXME: Bug 1185806 - Provide a common device name setting.
|
|
|
|
if (mServiceName.IsEmpty()) {
|
|
|
|
GetAndroidDeviceName(mServiceName);
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << Preferences::SetCString(PREF_PRESENTATION_DEVICE_NAME,
|
|
|
|
mServiceName);
|
2015-10-20 11:47:56 +03:00
|
|
|
}
|
|
|
|
#endif // MOZ_WIDGET_ANDROID
|
|
|
|
|
2016-05-20 09:53:30 +03:00
|
|
|
Unused << mPresentationService->SetId(mServiceName);
|
2015-10-20 11:47:56 +03:00
|
|
|
|
2015-07-30 19:40:00 +03:00
|
|
|
if (mDiscoveryEnabled && NS_WARN_IF(NS_FAILED(rv = ForceDiscovery()))) {
|
2015-05-21 06:06:00 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2016-07-26 05:59:52 +03:00
|
|
|
if (mDiscoverable && NS_WARN_IF(NS_FAILED(rv = StartServer()))) {
|
2015-05-21 06:06:00 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
mInitialized = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult MulticastDNSDeviceProvider::Uninit() {
|
2015-09-09 00:42:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-05-21 06:06:00 +03:00
|
|
|
if (!mInitialized) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-09-30 02:48:00 +03:00
|
|
|
ClearDevices();
|
|
|
|
|
2015-07-30 19:40:00 +03:00
|
|
|
Preferences::RemoveObservers(this, kObservedPrefs);
|
|
|
|
|
|
|
|
StopDiscovery(NS_OK);
|
2016-07-26 05:59:52 +03:00
|
|
|
StopServer();
|
2015-05-21 06:06:00 +03:00
|
|
|
|
|
|
|
mMulticastDNS = nullptr;
|
|
|
|
|
|
|
|
if (mWrappedListener) {
|
|
|
|
mWrappedListener->SetListener(nullptr);
|
|
|
|
mWrappedListener = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
mInitialized = false;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-07-26 05:59:52 +03:00
|
|
|
nsresult MulticastDNSDeviceProvider::StartServer() {
|
|
|
|
LOG_I("StartServer: %s (%d)", mServiceName.get(), mDiscoverable);
|
2015-09-09 00:42:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-07-30 19:40:00 +03:00
|
|
|
|
|
|
|
if (!mDiscoverable) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-05-21 06:06:00 +03:00
|
|
|
nsresult rv;
|
2015-11-03 03:04:00 +03:00
|
|
|
|
2015-07-30 19:40:00 +03:00
|
|
|
uint16_t servicePort;
|
2016-05-20 09:53:30 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv = mPresentationService->GetPort(&servicePort)))) {
|
2015-07-30 19:40:00 +03:00
|
|
|
return rv;
|
|
|
|
}
|
2015-05-21 06:06:00 +03:00
|
|
|
|
2015-11-03 03:04:00 +03:00
|
|
|
/**
|
2016-07-26 05:59:52 +03:00
|
|
|
* If |servicePort| is non-zero, it means PresentationControlService is
|
2015-11-03 03:04:00 +03:00
|
|
|
* running. Otherwise, we should make it start serving.
|
|
|
|
*/
|
2016-07-26 05:59:52 +03:00
|
|
|
if (servicePort) {
|
|
|
|
return RegisterMDNSService();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(
|
|
|
|
rv = mPresentationService->SetListener(mWrappedListener)))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2016-08-02 05:48:22 +03:00
|
|
|
AbortServerRetry();
|
|
|
|
|
2016-07-26 05:59:52 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(
|
|
|
|
rv = mPresentationService->StartServer(mDiscoverableEncrypted, 0)))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult MulticastDNSDeviceProvider::StopServer() {
|
|
|
|
LOG_I("StopServer: %s", mServiceName.get());
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
UnregisterMDNSService(NS_OK);
|
|
|
|
|
2016-08-02 05:48:22 +03:00
|
|
|
AbortServerRetry();
|
|
|
|
|
2016-07-26 05:59:52 +03:00
|
|
|
if (mPresentationService) {
|
|
|
|
mPresentationService->SetListener(nullptr);
|
|
|
|
mPresentationService->Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-08-02 05:48:22 +03:00
|
|
|
void MulticastDNSDeviceProvider::AbortServerRetry() {
|
|
|
|
if (mIsServerRetrying) {
|
|
|
|
mIsServerRetrying = false;
|
|
|
|
mServerRetryTimer->Cancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-26 05:59:52 +03:00
|
|
|
nsresult MulticastDNSDeviceProvider::RegisterMDNSService() {
|
|
|
|
LOG_I("RegisterMDNSService: %s", mServiceName.get());
|
|
|
|
|
|
|
|
if (!mDiscoverable) {
|
|
|
|
return NS_OK;
|
2015-11-03 03:04:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Cancel on going service registration.
|
2016-07-26 05:59:52 +03:00
|
|
|
UnregisterMDNSService(NS_OK);
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
uint16_t servicePort;
|
|
|
|
if (NS_FAILED(rv = mPresentationService->GetPort(&servicePort)) ||
|
|
|
|
!servicePort) {
|
|
|
|
// Abort service registration if server port is not available.
|
|
|
|
return rv;
|
2015-11-03 03:04:00 +03:00
|
|
|
}
|
|
|
|
|
2015-07-30 19:40:00 +03:00
|
|
|
/**
|
|
|
|
* Register the presentation control channel server as an mDNS service.
|
|
|
|
*/
|
|
|
|
nsCOMPtr<nsIDNSServiceInfo> serviceInfo =
|
|
|
|
do_CreateInstance(DNSSERVICEINFO_CONTRACT_ID, &rv);
|
2015-05-21 06:06:00 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2015-07-30 19:40:00 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv = serviceInfo->SetServiceType(
|
|
|
|
NS_LITERAL_CSTRING(SERVICE_TYPE))))) {
|
2015-05-21 06:06:00 +03:00
|
|
|
return rv;
|
|
|
|
}
|
2015-07-30 19:40:00 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv = serviceInfo->SetServiceName(mServiceName)))) {
|
2015-05-21 06:06:00 +03:00
|
|
|
return rv;
|
|
|
|
}
|
2015-07-30 19:40:00 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv = serviceInfo->SetPort(servicePort)))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2016-05-27 02:22:27 +03:00
|
|
|
nsCOMPtr<nsIWritablePropertyBag2> propBag =
|
|
|
|
do_CreateInstance("@mozilla.org/hash-property-bag;1");
|
|
|
|
MOZ_ASSERT(propBag);
|
|
|
|
|
|
|
|
uint32_t version;
|
|
|
|
rv = mPresentationService->GetVersion(&version);
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
|
|
|
|
|
|
|
rv = propBag->SetPropertyAsUint32(NS_LITERAL_STRING(PROTOCOL_VERSION_TAG),
|
|
|
|
version);
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
2016-07-26 05:59:52 +03:00
|
|
|
|
|
|
|
if (mDiscoverableEncrypted) {
|
|
|
|
nsAutoCString certFingerprint;
|
|
|
|
rv = mPresentationService->GetCertFingerprint(certFingerprint);
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
|
|
|
|
|
|
|
rv = propBag->SetPropertyAsACString(NS_LITERAL_STRING(CERT_FINGERPRINT_TAG),
|
|
|
|
certFingerprint);
|
|
|
|
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
|
|
|
}
|
|
|
|
|
2016-05-27 02:22:27 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv = serviceInfo->SetAttributes(propBag)))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2015-07-30 19:40:00 +03:00
|
|
|
return mMulticastDNS->RegisterService(serviceInfo, mWrappedListener,
|
|
|
|
getter_AddRefs(mRegisterRequest));
|
|
|
|
}
|
2015-05-21 06:06:00 +03:00
|
|
|
|
2016-07-26 05:59:52 +03:00
|
|
|
nsresult MulticastDNSDeviceProvider::UnregisterMDNSService(nsresult aReason) {
|
2016-12-16 06:16:31 +03:00
|
|
|
LOG_I("UnregisterMDNSService: %s (0x%08" PRIx32 ")", mServiceName.get(),
|
|
|
|
static_cast<uint32_t>(aReason));
|
2015-09-09 00:42:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-05-21 06:06:00 +03:00
|
|
|
if (mRegisterRequest) {
|
2015-07-30 19:40:00 +03:00
|
|
|
mRegisterRequest->Cancel(aReason);
|
2015-05-21 06:06:00 +03:00
|
|
|
mRegisterRequest = nullptr;
|
|
|
|
}
|
2015-07-30 19:40:00 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult MulticastDNSDeviceProvider::StopDiscovery(nsresult aReason) {
|
2016-12-16 06:16:31 +03:00
|
|
|
LOG_I("StopDiscovery (0x%08" PRIx32 ")", static_cast<uint32_t>(aReason));
|
2015-09-30 02:48:00 +03:00
|
|
|
|
2015-09-09 00:42:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-10-01 00:55:00 +03:00
|
|
|
MOZ_ASSERT(mDiscoveryTimer);
|
|
|
|
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << mDiscoveryTimer->Cancel();
|
2015-09-09 00:42:00 +03:00
|
|
|
|
2015-07-30 19:40:00 +03:00
|
|
|
if (mDiscoveryRequest) {
|
|
|
|
mDiscoveryRequest->Cancel(aReason);
|
|
|
|
mDiscoveryRequest = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2015-05-21 06:06:00 +03:00
|
|
|
}
|
|
|
|
|
2016-07-04 13:12:04 +03:00
|
|
|
nsresult MulticastDNSDeviceProvider::Connect(
|
|
|
|
Device* aDevice, nsIPresentationControlChannel** aRetVal) {
|
2015-10-19 05:44:59 +03:00
|
|
|
MOZ_ASSERT(aDevice);
|
2016-05-20 09:53:30 +03:00
|
|
|
MOZ_ASSERT(mPresentationService);
|
2015-10-19 05:44:59 +03:00
|
|
|
|
|
|
|
RefPtr<TCPDeviceInfo> deviceInfo =
|
|
|
|
new TCPDeviceInfo(aDevice->Id(), aDevice->Address(), aDevice->Port(),
|
2016-07-18 13:45:07 +03:00
|
|
|
aDevice->CertFingerprint());
|
2015-10-19 05:44:59 +03:00
|
|
|
|
2016-07-04 13:12:04 +03:00
|
|
|
return mPresentationService->Connect(deviceInfo, aRetVal);
|
2015-10-19 05:44:59 +03:00
|
|
|
}
|
|
|
|
|
2016-05-27 02:22:27 +03:00
|
|
|
bool MulticastDNSDeviceProvider::IsCompatibleServer(
|
|
|
|
nsIDNSServiceInfo* aServiceInfo) {
|
|
|
|
MOZ_ASSERT(aServiceInfo);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPropertyBag2> propBag;
|
|
|
|
if (NS_WARN_IF(
|
|
|
|
NS_FAILED(aServiceInfo->GetAttributes(getter_AddRefs(propBag)))) ||
|
|
|
|
!propBag) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t remoteVersion;
|
|
|
|
if (NS_WARN_IF(NS_FAILED(propBag->GetPropertyAsUint32(
|
|
|
|
NS_LITERAL_STRING(PROTOCOL_VERSION_TAG), &remoteVersion)))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isCompatible = false;
|
|
|
|
Unused << NS_WARN_IF(NS_FAILED(
|
|
|
|
mPresentationService->IsCompatibleServer(remoteVersion, &isCompatible)));
|
|
|
|
|
|
|
|
return isCompatible;
|
|
|
|
}
|
|
|
|
|
2015-10-21 03:54:00 +03:00
|
|
|
nsresult MulticastDNSDeviceProvider::AddDevice(
|
|
|
|
const nsACString& aId, const nsACString& aServiceName,
|
2015-09-30 02:48:00 +03:00
|
|
|
const nsACString& aServiceType, const nsACString& aAddress,
|
2016-07-18 13:45:07 +03:00
|
|
|
const uint16_t aPort, const nsACString& aCertFingerprint) {
|
2015-09-30 02:48:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2016-05-20 09:53:30 +03:00
|
|
|
MOZ_ASSERT(mPresentationService);
|
2015-09-30 02:48:00 +03:00
|
|
|
|
2015-10-21 03:54:00 +03:00
|
|
|
RefPtr<Device> device =
|
|
|
|
new Device(aId, /* ID */
|
2016-07-18 13:45:07 +03:00
|
|
|
aServiceName, aServiceType, aAddress, aPort, aCertFingerprint,
|
2015-10-19 05:44:59 +03:00
|
|
|
DeviceState::eActive, this);
|
2015-09-30 02:48:00 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPresentationDeviceListener> listener;
|
|
|
|
if (NS_SUCCEEDED(GetListener(getter_AddRefs(listener))) && listener) {
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << listener->AddDevice(device);
|
2015-09-30 02:48:00 +03:00
|
|
|
}
|
|
|
|
|
2015-10-19 05:44:59 +03:00
|
|
|
mDevices.AppendElement(device);
|
2015-09-30 02:48:00 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult MulticastDNSDeviceProvider::UpdateDevice(
|
|
|
|
const uint32_t aIndex, const nsACString& aServiceName,
|
|
|
|
const nsACString& aServiceType, const nsACString& aAddress,
|
2016-07-18 13:45:07 +03:00
|
|
|
const uint16_t aPort, const nsACString& aCertFingerprint) {
|
2015-09-30 02:48:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2016-05-20 09:53:30 +03:00
|
|
|
MOZ_ASSERT(mPresentationService);
|
2015-09-30 02:48:00 +03:00
|
|
|
|
|
|
|
if (NS_WARN_IF(aIndex >= mDevices.Length())) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2015-10-19 05:44:59 +03:00
|
|
|
RefPtr<Device> device = mDevices[aIndex];
|
2016-07-18 13:45:07 +03:00
|
|
|
device->Update(aServiceName, aServiceType, aAddress, aPort, aCertFingerprint);
|
2015-10-19 05:44:59 +03:00
|
|
|
device->ChangeState(DeviceState::eActive);
|
2015-09-30 02:48:00 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPresentationDeviceListener> listener;
|
|
|
|
if (NS_SUCCEEDED(GetListener(getter_AddRefs(listener))) && listener) {
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << listener->UpdateDevice(device);
|
2015-09-30 02:48:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult MulticastDNSDeviceProvider::RemoveDevice(const uint32_t aIndex) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2016-05-20 09:53:30 +03:00
|
|
|
MOZ_ASSERT(mPresentationService);
|
2015-09-30 02:48:00 +03:00
|
|
|
|
|
|
|
if (NS_WARN_IF(aIndex >= mDevices.Length())) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2015-10-19 05:44:59 +03:00
|
|
|
RefPtr<Device> device = mDevices[aIndex];
|
2015-09-30 02:48:00 +03:00
|
|
|
|
2015-10-19 05:44:59 +03:00
|
|
|
LOG_I("RemoveDevice: %s", device->Id().get());
|
|
|
|
mDevices.RemoveElementAt(aIndex);
|
2015-09-30 02:48:00 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPresentationDeviceListener> listener;
|
|
|
|
if (NS_SUCCEEDED(GetListener(getter_AddRefs(listener))) && listener) {
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << listener->RemoveDevice(device);
|
2015-09-30 02:48:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-10-19 05:44:59 +03:00
|
|
|
bool MulticastDNSDeviceProvider::FindDeviceById(const nsACString& aId,
|
|
|
|
uint32_t& aIndex) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
RefPtr<Device> device = new Device(aId,
|
|
|
|
/* aName = */ EmptyCString(),
|
|
|
|
/* aType = */ EmptyCString(),
|
|
|
|
/* aHost = */ EmptyCString(),
|
|
|
|
/* aPort = */ 0,
|
2016-07-18 13:45:07 +03:00
|
|
|
/* aCertFingerprint */ EmptyCString(),
|
2015-10-19 05:44:59 +03:00
|
|
|
/* aState = */ DeviceState::eUnknown,
|
|
|
|
/* aProvider = */ nullptr);
|
|
|
|
size_t index = mDevices.IndexOf(device, 0, DeviceIdComparator());
|
|
|
|
|
|
|
|
if (index == mDevices.NoIndex) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aIndex = index;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-10-21 03:54:00 +03:00
|
|
|
bool MulticastDNSDeviceProvider::FindDeviceByAddress(const nsACString& aAddress,
|
|
|
|
uint32_t& aIndex) {
|
2015-09-30 02:48:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-10-19 05:44:59 +03:00
|
|
|
RefPtr<Device> device = new Device(/* aId = */ EmptyCString(),
|
|
|
|
/* aName = */ EmptyCString(),
|
|
|
|
/* aType = */ EmptyCString(), aAddress,
|
|
|
|
/* aPort = */ 0,
|
2016-07-18 13:45:07 +03:00
|
|
|
/* aCertFingerprint */ EmptyCString(),
|
2015-10-19 05:44:59 +03:00
|
|
|
/* aState = */ DeviceState::eUnknown,
|
|
|
|
/* aProvider = */ nullptr);
|
2015-10-21 03:54:00 +03:00
|
|
|
size_t index = mDevices.IndexOf(device, 0, DeviceAddressComparator());
|
2015-09-30 02:48:00 +03:00
|
|
|
|
|
|
|
if (index == mDevices.NoIndex) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
aIndex = index;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MulticastDNSDeviceProvider::MarkAllDevicesUnknown() {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
for (auto& device : mDevices) {
|
2015-10-19 05:44:59 +03:00
|
|
|
device->ChangeState(DeviceState::eUnknown);
|
2015-09-30 02:48:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MulticastDNSDeviceProvider::ClearUnknownDevices() {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
size_t i = mDevices.Length();
|
|
|
|
while (i > 0) {
|
|
|
|
--i;
|
2015-10-19 05:44:59 +03:00
|
|
|
if (mDevices[i]->State() == DeviceState::eUnknown) {
|
2016-09-02 10:12:24 +03:00
|
|
|
Unused << NS_WARN_IF(NS_FAILED(RemoveDevice(i)));
|
2015-09-30 02:48:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MulticastDNSDeviceProvider::ClearDevices() {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
size_t i = mDevices.Length();
|
|
|
|
while (i > 0) {
|
|
|
|
--i;
|
2016-09-02 10:12:24 +03:00
|
|
|
Unused << NS_WARN_IF(NS_FAILED(RemoveDevice(i)));
|
2015-09-30 02:48:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-21 06:06:00 +03:00
|
|
|
// nsIPresentationDeviceProvider
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MulticastDNSDeviceProvider::GetListener(
|
|
|
|
nsIPresentationDeviceListener** aListener) {
|
2015-09-09 00:42:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-05-21 06:06:00 +03:00
|
|
|
if (NS_WARN_IF(!aListener)) {
|
|
|
|
return NS_ERROR_INVALID_POINTER;
|
|
|
|
}
|
|
|
|
|
2015-09-30 02:48:00 +03:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIPresentationDeviceListener> listener =
|
|
|
|
do_QueryReferent(mDeviceListener, &rv);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2015-05-21 06:06:00 +03:00
|
|
|
listener.forget(aListener);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MulticastDNSDeviceProvider::SetListener(
|
|
|
|
nsIPresentationDeviceListener* aListener) {
|
2015-09-09 00:42:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-05-21 06:06:00 +03:00
|
|
|
mDeviceListener = do_GetWeakReference(aListener);
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
if (mDeviceListener) {
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv = Init()))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv = Uninit()))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MulticastDNSDeviceProvider::ForceDiscovery() {
|
2015-07-30 19:40:00 +03:00
|
|
|
LOG_I("ForceDiscovery (%d)", mDiscoveryEnabled);
|
2015-09-09 00:42:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-07-30 19:40:00 +03:00
|
|
|
|
|
|
|
if (!mDiscoveryEnabled) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-09-30 02:48:00 +03:00
|
|
|
MOZ_ASSERT(mDiscoveryTimer);
|
2015-05-21 06:06:00 +03:00
|
|
|
MOZ_ASSERT(mMulticastDNS);
|
|
|
|
|
2015-09-30 02:48:00 +03:00
|
|
|
// if it's already discovering, extend existing discovery timeout.
|
2015-12-10 09:56:00 +03:00
|
|
|
nsresult rv;
|
2015-09-30 02:48:00 +03:00
|
|
|
if (mIsDiscovering) {
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << mDiscoveryTimer->Cancel();
|
2015-09-30 02:48:00 +03:00
|
|
|
|
2015-12-10 09:56:00 +03:00
|
|
|
if (NS_WARN_IF(
|
|
|
|
NS_FAILED(rv = mDiscoveryTimer->Init(this, mDiscoveryTimeoutMs,
|
|
|
|
nsITimer::TYPE_ONE_SHOT)))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2015-09-30 02:48:00 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-07-30 19:40:00 +03:00
|
|
|
StopDiscovery(NS_OK);
|
2015-05-21 06:06:00 +03:00
|
|
|
|
|
|
|
if (NS_WARN_IF(
|
|
|
|
NS_FAILED(rv = mMulticastDNS->StartDiscovery(
|
|
|
|
NS_LITERAL_CSTRING(SERVICE_TYPE), mWrappedListener,
|
|
|
|
getter_AddRefs(mDiscoveryRequest))))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIDNSServiceDiscoveryListener
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MulticastDNSDeviceProvider::OnDiscoveryStarted(const nsACString& aServiceType) {
|
|
|
|
LOG_I("OnDiscoveryStarted");
|
2015-09-09 00:42:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-10-01 00:55:00 +03:00
|
|
|
MOZ_ASSERT(mDiscoveryTimer);
|
|
|
|
|
2015-09-30 02:48:00 +03:00
|
|
|
MarkAllDevicesUnknown();
|
|
|
|
|
2015-10-01 00:55:00 +03:00
|
|
|
nsresult rv;
|
|
|
|
if (NS_WARN_IF(
|
|
|
|
NS_FAILED(rv = mDiscoveryTimer->Init(this, mDiscoveryTimeoutMs,
|
|
|
|
nsITimer::TYPE_ONE_SHOT)))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2015-09-09 00:42:00 +03:00
|
|
|
|
2015-09-30 02:48:00 +03:00
|
|
|
mIsDiscovering = true;
|
|
|
|
|
2015-05-21 06:06:00 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MulticastDNSDeviceProvider::OnDiscoveryStopped(const nsACString& aServiceType) {
|
|
|
|
LOG_I("OnDiscoveryStopped");
|
2015-09-09 00:42:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-09-30 02:48:00 +03:00
|
|
|
ClearUnknownDevices();
|
|
|
|
|
|
|
|
mIsDiscovering = false;
|
|
|
|
|
2015-05-21 06:06:00 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MulticastDNSDeviceProvider::OnServiceFound(nsIDNSServiceInfo* aServiceInfo) {
|
2015-09-09 00:42:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-05-21 06:06:00 +03:00
|
|
|
if (NS_WARN_IF(!aServiceInfo)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsAutoCString serviceName;
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv = aServiceInfo->GetServiceName(serviceName)))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_I("OnServiceFound: %s", serviceName.get());
|
|
|
|
|
|
|
|
if (mMulticastDNS) {
|
2015-07-30 19:40:00 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv = mMulticastDNS->ResolveService(
|
|
|
|
aServiceInfo, mWrappedListener)))) {
|
2015-05-21 06:06:00 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MulticastDNSDeviceProvider::OnServiceLost(nsIDNSServiceInfo* aServiceInfo) {
|
2015-09-09 00:42:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-05-21 06:06:00 +03:00
|
|
|
if (NS_WARN_IF(!aServiceInfo)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsAutoCString serviceName;
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv = aServiceInfo->GetServiceName(serviceName)))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_I("OnServiceLost: %s", serviceName.get());
|
|
|
|
|
2015-09-30 02:48:00 +03:00
|
|
|
nsAutoCString host;
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv = aServiceInfo->GetHost(host)))) {
|
|
|
|
return rv;
|
2015-05-21 06:06:00 +03:00
|
|
|
}
|
|
|
|
|
2015-09-30 02:48:00 +03:00
|
|
|
uint32_t index;
|
2015-10-19 05:44:59 +03:00
|
|
|
if (!FindDeviceById(host, index)) {
|
2015-09-30 02:48:00 +03:00
|
|
|
// given device was not found
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2015-05-21 06:06:00 +03:00
|
|
|
|
2015-09-30 02:48:00 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv = RemoveDevice(index)))) {
|
|
|
|
return rv;
|
2015-05-21 06:06:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2015-07-30 19:40:00 +03:00
|
|
|
MulticastDNSDeviceProvider::OnStartDiscoveryFailed(
|
|
|
|
const nsACString& aServiceType, int32_t aErrorCode) {
|
2015-05-21 06:06:00 +03:00
|
|
|
LOG_E("OnStartDiscoveryFailed: %d", aErrorCode);
|
2015-09-09 00:42:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-05-21 06:06:00 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2015-07-30 19:40:00 +03:00
|
|
|
MulticastDNSDeviceProvider::OnStopDiscoveryFailed(
|
|
|
|
const nsACString& aServiceType, int32_t aErrorCode) {
|
2015-05-21 06:06:00 +03:00
|
|
|
LOG_E("OnStopDiscoveryFailed: %d", aErrorCode);
|
2015-09-09 00:42:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-05-21 06:06:00 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIDNSRegistrationListener
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MulticastDNSDeviceProvider::OnServiceRegistered(
|
|
|
|
nsIDNSServiceInfo* aServiceInfo) {
|
2015-09-09 00:42:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-05-21 06:06:00 +03:00
|
|
|
if (NS_WARN_IF(!aServiceInfo)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsAutoCString name;
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv = aServiceInfo->GetServiceName(name)))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_I("OnServiceRegistered (%s)", name.get());
|
|
|
|
mRegisteredName = name;
|
|
|
|
|
2015-10-21 08:09:00 +03:00
|
|
|
if (mMulticastDNS) {
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv = mMulticastDNS->ResolveService(
|
|
|
|
aServiceInfo, mWrappedListener)))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2015-05-21 06:06:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MulticastDNSDeviceProvider::OnServiceUnregistered(
|
|
|
|
nsIDNSServiceInfo* aServiceInfo) {
|
|
|
|
LOG_I("OnServiceUnregistered");
|
2015-09-09 00:42:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-05-21 06:06:00 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2015-07-30 19:40:00 +03:00
|
|
|
MulticastDNSDeviceProvider::OnRegistrationFailed(
|
|
|
|
nsIDNSServiceInfo* aServiceInfo, int32_t aErrorCode) {
|
2015-05-21 06:06:00 +03:00
|
|
|
LOG_E("OnRegistrationFailed: %d", aErrorCode);
|
2015-09-09 00:42:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-05-21 06:06:00 +03:00
|
|
|
|
2015-07-30 19:40:00 +03:00
|
|
|
mRegisterRequest = nullptr;
|
|
|
|
|
2015-05-21 06:06:00 +03:00
|
|
|
if (aErrorCode == nsIDNSRegistrationListener::ERROR_SERVICE_NOT_RUNNING) {
|
2017-06-12 22:34:10 +03:00
|
|
|
return NS_DispatchToMainThread(NewRunnableMethod(
|
|
|
|
"dom::presentation::MulticastDNSDeviceProvider::RegisterMDNSService",
|
|
|
|
this, &MulticastDNSDeviceProvider::RegisterMDNSService));
|
2015-05-21 06:06:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2015-07-30 19:40:00 +03:00
|
|
|
MulticastDNSDeviceProvider::OnUnregistrationFailed(
|
|
|
|
nsIDNSServiceInfo* aServiceInfo, int32_t aErrorCode) {
|
2015-05-21 06:06:00 +03:00
|
|
|
LOG_E("OnUnregistrationFailed: %d", aErrorCode);
|
2015-09-09 00:42:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-05-21 06:06:00 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIDNSServiceResolveListener
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MulticastDNSDeviceProvider::OnServiceResolved(nsIDNSServiceInfo* aServiceInfo) {
|
2015-09-09 00:42:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-05-21 06:06:00 +03:00
|
|
|
if (NS_WARN_IF(!aServiceInfo)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsAutoCString serviceName;
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv = aServiceInfo->GetServiceName(serviceName)))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_I("OnServiceResolved: %s", serviceName.get());
|
|
|
|
|
|
|
|
nsAutoCString host;
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv = aServiceInfo->GetHost(host)))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2015-10-21 08:09:00 +03:00
|
|
|
if (mRegisteredName == serviceName) {
|
|
|
|
LOG_I("ignore self");
|
|
|
|
|
2016-05-20 09:53:30 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv = mPresentationService->SetId(host)))) {
|
2015-10-21 08:09:00 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-05-27 02:22:27 +03:00
|
|
|
if (!IsCompatibleServer(aServiceInfo)) {
|
|
|
|
LOG_I("ignore incompatible service: %s", serviceName.get());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-10-21 03:54:00 +03:00
|
|
|
nsAutoCString address;
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv = aServiceInfo->GetAddress(address)))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2015-05-21 06:06:00 +03:00
|
|
|
uint16_t port;
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv = aServiceInfo->GetPort(&port)))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString serviceType;
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv = aServiceInfo->GetServiceType(serviceType)))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2016-07-18 13:45:07 +03:00
|
|
|
nsCOMPtr<nsIPropertyBag2> propBag;
|
|
|
|
if (NS_WARN_IF(
|
|
|
|
NS_FAILED(aServiceInfo->GetAttributes(getter_AddRefs(propBag)))) ||
|
|
|
|
!propBag) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString certFingerprint;
|
|
|
|
Unused << propBag->GetPropertyAsACString(
|
|
|
|
NS_LITERAL_STRING(CERT_FINGERPRINT_TAG), certFingerprint);
|
|
|
|
|
2015-09-30 02:48:00 +03:00
|
|
|
uint32_t index;
|
2015-10-19 05:44:59 +03:00
|
|
|
if (FindDeviceById(host, index)) {
|
2015-09-30 02:48:00 +03:00
|
|
|
return UpdateDevice(index, serviceName, serviceType, address, port,
|
2016-07-18 13:45:07 +03:00
|
|
|
certFingerprint);
|
2015-09-30 02:48:00 +03:00
|
|
|
} else {
|
2015-10-21 03:54:00 +03:00
|
|
|
return AddDevice(host, serviceName, serviceType, address, port,
|
2016-07-18 13:45:07 +03:00
|
|
|
certFingerprint);
|
2015-05-21 06:06:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2015-07-30 19:40:00 +03:00
|
|
|
MulticastDNSDeviceProvider::OnResolveFailed(nsIDNSServiceInfo* aServiceInfo,
|
|
|
|
int32_t aErrorCode) {
|
2015-05-21 06:06:00 +03:00
|
|
|
LOG_E("OnResolveFailed: %d", aErrorCode);
|
2015-09-09 00:42:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-05-21 06:06:00 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-05-20 09:53:30 +03:00
|
|
|
// nsIPresentationControlServerListener
|
2015-05-21 06:06:00 +03:00
|
|
|
NS_IMETHODIMP
|
2016-07-26 05:59:52 +03:00
|
|
|
MulticastDNSDeviceProvider::OnServerReady(uint16_t aPort,
|
|
|
|
const nsACString& aCertFingerprint) {
|
|
|
|
LOG_I("OnServerReady: %d, %s", aPort,
|
|
|
|
PromiseFlatCString(aCertFingerprint).get());
|
2015-09-09 00:42:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-05-21 06:06:00 +03:00
|
|
|
|
2015-11-03 03:04:00 +03:00
|
|
|
if (mDiscoverable) {
|
2016-07-26 05:59:52 +03:00
|
|
|
RegisterMDNSService();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MulticastDNSDeviceProvider::OnServerStopped(nsresult aResult) {
|
2016-12-16 06:16:31 +03:00
|
|
|
LOG_I("OnServerStopped: (0x%08" PRIx32 ")", static_cast<uint32_t>(aResult));
|
2016-07-26 05:59:52 +03:00
|
|
|
|
|
|
|
UnregisterMDNSService(aResult);
|
|
|
|
|
|
|
|
// Try restart server if it is stopped abnormally.
|
|
|
|
if (NS_FAILED(aResult) && mDiscoverable) {
|
2016-08-02 05:48:22 +03:00
|
|
|
mIsServerRetrying = true;
|
|
|
|
mServerRetryTimer->Init(this, mServerRetryMs, nsITimer::TYPE_ONE_SHOT);
|
2015-07-30 19:40:00 +03:00
|
|
|
}
|
2015-05-21 06:06:00 +03:00
|
|
|
|
2015-10-19 05:44:59 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-08-02 20:10:00 +03:00
|
|
|
// Create a new device if we were unable to find one with the address.
|
|
|
|
already_AddRefed<MulticastDNSDeviceProvider::Device>
|
|
|
|
MulticastDNSDeviceProvider::GetOrCreateDevice(nsITCPDeviceInfo* aDeviceInfo) {
|
2015-10-21 03:54:00 +03:00
|
|
|
nsAutoCString address;
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << aDeviceInfo->GetAddress(address);
|
2015-10-19 05:44:59 +03:00
|
|
|
|
|
|
|
RefPtr<Device> device;
|
|
|
|
uint32_t index;
|
2015-10-21 03:54:00 +03:00
|
|
|
if (FindDeviceByAddress(address, index)) {
|
2015-10-19 05:44:59 +03:00
|
|
|
device = mDevices[index];
|
|
|
|
} else {
|
2016-08-02 20:10:00 +03:00
|
|
|
// Create a one-time device object for non-discoverable controller.
|
|
|
|
// This device will not be in the list of available devices and cannot
|
2015-10-19 05:44:59 +03:00
|
|
|
// be used for requesting session.
|
|
|
|
nsAutoCString id;
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << aDeviceInfo->GetId(id);
|
2015-10-19 05:44:59 +03:00
|
|
|
uint16_t port;
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << aDeviceInfo->GetPort(&port);
|
2015-10-19 05:44:59 +03:00
|
|
|
|
|
|
|
device =
|
|
|
|
new Device(id,
|
|
|
|
/* aName = */ id,
|
|
|
|
/* aType = */ EmptyCString(), address, port,
|
2016-07-18 13:45:07 +03:00
|
|
|
/* aCertFingerprint */ EmptyCString(), DeviceState::eActive,
|
2015-10-19 05:44:59 +03:00
|
|
|
/* aProvider = */ nullptr);
|
|
|
|
}
|
|
|
|
|
2016-08-02 20:10:00 +03:00
|
|
|
return device.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MulticastDNSDeviceProvider::OnSessionRequest(
|
|
|
|
nsITCPDeviceInfo* aDeviceInfo, const nsAString& aUrl,
|
|
|
|
const nsAString& aPresentationId,
|
|
|
|
nsIPresentationControlChannel* aControlChannel) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
nsAutoCString address;
|
|
|
|
Unused << aDeviceInfo->GetAddress(address);
|
|
|
|
|
|
|
|
LOG_I("OnSessionRequest: %s", address.get());
|
|
|
|
|
|
|
|
RefPtr<Device> device = GetOrCreateDevice(aDeviceInfo);
|
2015-10-19 05:44:59 +03:00
|
|
|
nsCOMPtr<nsIPresentationDeviceListener> listener;
|
|
|
|
if (NS_SUCCEEDED(GetListener(getter_AddRefs(listener))) && listener) {
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << listener->OnSessionRequest(device, aUrl, aPresentationId,
|
2015-10-19 05:44:59 +03:00
|
|
|
aControlChannel);
|
2015-07-30 19:40:00 +03:00
|
|
|
}
|
2015-05-21 06:06:00 +03:00
|
|
|
|
2015-07-30 19:40:00 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-05-27 02:22:27 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
MulticastDNSDeviceProvider::OnTerminateRequest(
|
|
|
|
nsITCPDeviceInfo* aDeviceInfo, const nsAString& aPresentationId,
|
|
|
|
nsIPresentationControlChannel* aControlChannel, bool aIsFromReceiver) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
nsAutoCString address;
|
|
|
|
Unused << aDeviceInfo->GetAddress(address);
|
|
|
|
|
|
|
|
LOG_I("OnTerminateRequest: %s", address.get());
|
|
|
|
|
2016-08-02 20:10:00 +03:00
|
|
|
RefPtr<Device> device = GetOrCreateDevice(aDeviceInfo);
|
2016-05-27 02:22:27 +03:00
|
|
|
nsCOMPtr<nsIPresentationDeviceListener> listener;
|
|
|
|
if (NS_SUCCEEDED(GetListener(getter_AddRefs(listener))) && listener) {
|
|
|
|
Unused << listener->OnTerminateRequest(device, aPresentationId,
|
|
|
|
aControlChannel, aIsFromReceiver);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-08-02 20:10:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
MulticastDNSDeviceProvider::OnReconnectRequest(
|
|
|
|
nsITCPDeviceInfo* aDeviceInfo, const nsAString& aUrl,
|
|
|
|
const nsAString& aPresentationId,
|
|
|
|
nsIPresentationControlChannel* aControlChannel) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
nsAutoCString address;
|
|
|
|
Unused << aDeviceInfo->GetAddress(address);
|
|
|
|
|
|
|
|
LOG_I("OnReconnectRequest: %s", address.get());
|
|
|
|
|
|
|
|
RefPtr<Device> device = GetOrCreateDevice(aDeviceInfo);
|
|
|
|
nsCOMPtr<nsIPresentationDeviceListener> listener;
|
|
|
|
if (NS_SUCCEEDED(GetListener(getter_AddRefs(listener))) && listener) {
|
|
|
|
Unused << listener->OnReconnectRequest(device, aUrl, aPresentationId,
|
|
|
|
aControlChannel);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-07-30 19:40:00 +03:00
|
|
|
// nsIObserver
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MulticastDNSDeviceProvider::Observe(nsISupports* aSubject, const char* aTopic,
|
|
|
|
const char16_t* aData) {
|
2015-09-09 00:42:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-07-30 19:40:00 +03:00
|
|
|
NS_ConvertUTF16toUTF8 data(aData);
|
|
|
|
LOG_I("Observe: topic = %s, data = %s", aTopic, data.get());
|
|
|
|
|
|
|
|
if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) {
|
|
|
|
if (data.EqualsLiteral(PREF_PRESENTATION_DISCOVERY)) {
|
|
|
|
OnDiscoveryChanged(Preferences::GetBool(PREF_PRESENTATION_DISCOVERY));
|
2015-10-01 00:55:00 +03:00
|
|
|
} else if (data.EqualsLiteral(PREF_PRESENTATION_DISCOVERY_TIMEOUT_MS)) {
|
|
|
|
OnDiscoveryTimeoutChanged(
|
|
|
|
Preferences::GetUint(PREF_PRESENTATION_DISCOVERY_TIMEOUT_MS));
|
2015-07-30 19:40:00 +03:00
|
|
|
} else if (data.EqualsLiteral(PREF_PRESENTATION_DISCOVERABLE)) {
|
|
|
|
OnDiscoverableChanged(
|
|
|
|
Preferences::GetBool(PREF_PRESENTATION_DISCOVERABLE));
|
|
|
|
} else if (data.EqualsLiteral(PREF_PRESENTATION_DEVICE_NAME)) {
|
2017-07-31 07:28:48 +03:00
|
|
|
nsAutoCString newServiceName;
|
|
|
|
Preferences::GetCString(PREF_PRESENTATION_DEVICE_NAME, newServiceName);
|
2015-10-20 11:47:56 +03:00
|
|
|
if (!mServiceName.Equals(newServiceName)) {
|
|
|
|
OnServiceNameChanged(newServiceName);
|
|
|
|
}
|
2015-05-21 06:06:00 +03:00
|
|
|
}
|
2015-10-01 00:55:00 +03:00
|
|
|
} else if (!strcmp(aTopic, NS_TIMER_CALLBACK_TOPIC)) {
|
2016-08-02 05:48:22 +03:00
|
|
|
nsCOMPtr<nsITimer> timer = do_QueryInterface(aSubject);
|
|
|
|
if (!timer) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (timer == mDiscoveryTimer) {
|
|
|
|
StopDiscovery(NS_OK);
|
|
|
|
} else if (timer == mServerRetryTimer) {
|
|
|
|
mIsServerRetrying = false;
|
|
|
|
StartServer();
|
|
|
|
}
|
2015-05-21 06:06:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-07-30 19:40:00 +03:00
|
|
|
nsresult MulticastDNSDeviceProvider::OnDiscoveryChanged(bool aEnabled) {
|
|
|
|
LOG_I("DiscoveryEnabled = %d\n", aEnabled);
|
2015-09-09 00:42:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-07-30 19:40:00 +03:00
|
|
|
|
|
|
|
mDiscoveryEnabled = aEnabled;
|
|
|
|
|
|
|
|
if (mDiscoveryEnabled) {
|
|
|
|
return ForceDiscovery();
|
|
|
|
}
|
|
|
|
|
|
|
|
return StopDiscovery(NS_OK);
|
|
|
|
}
|
|
|
|
|
2015-10-01 00:55:00 +03:00
|
|
|
nsresult MulticastDNSDeviceProvider::OnDiscoveryTimeoutChanged(
|
|
|
|
uint32_t aTimeoutMs) {
|
|
|
|
LOG_I("OnDiscoveryTimeoutChanged = %d\n", aTimeoutMs);
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2016-06-01 04:45:16 +03:00
|
|
|
mDiscoveryTimeoutMs = aTimeoutMs;
|
2015-10-01 00:55:00 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-07-30 19:40:00 +03:00
|
|
|
nsresult MulticastDNSDeviceProvider::OnDiscoverableChanged(bool aEnabled) {
|
|
|
|
LOG_I("Discoverable = %d\n", aEnabled);
|
2015-09-09 00:42:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-07-30 19:40:00 +03:00
|
|
|
|
|
|
|
mDiscoverable = aEnabled;
|
|
|
|
|
|
|
|
if (mDiscoverable) {
|
2016-07-26 05:59:52 +03:00
|
|
|
return StartServer();
|
2015-07-30 19:40:00 +03:00
|
|
|
}
|
|
|
|
|
2016-07-26 05:59:52 +03:00
|
|
|
return StopServer();
|
2015-07-30 19:40:00 +03:00
|
|
|
}
|
|
|
|
|
2015-09-30 02:48:00 +03:00
|
|
|
nsresult MulticastDNSDeviceProvider::OnServiceNameChanged(
|
|
|
|
const nsACString& aServiceName) {
|
|
|
|
LOG_I("serviceName = %s\n", PromiseFlatCString(aServiceName).get());
|
2015-09-09 00:42:00 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-07-30 19:40:00 +03:00
|
|
|
|
|
|
|
mServiceName = aServiceName;
|
|
|
|
|
|
|
|
nsresult rv;
|
2016-07-26 05:59:52 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv = UnregisterMDNSService(NS_OK)))) {
|
2015-07-30 19:40:00 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mDiscoverable) {
|
2016-07-26 05:59:52 +03:00
|
|
|
return RegisterMDNSService();
|
2015-07-30 19:40:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-10-19 05:44:59 +03:00
|
|
|
// MulticastDNSDeviceProvider::Device
|
|
|
|
NS_IMPL_ISUPPORTS(MulticastDNSDeviceProvider::Device, nsIPresentationDevice)
|
|
|
|
|
|
|
|
// nsIPresentationDevice
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MulticastDNSDeviceProvider::Device::GetId(nsACString& aId) {
|
|
|
|
aId = mId;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MulticastDNSDeviceProvider::Device::GetName(nsACString& aName) {
|
|
|
|
aName = mName;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MulticastDNSDeviceProvider::Device::GetType(nsACString& aType) {
|
|
|
|
aType = mType;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-07-04 13:12:04 +03:00
|
|
|
MulticastDNSDeviceProvider::Device::EstablishControlChannel(
|
|
|
|
nsIPresentationControlChannel** aRetVal) {
|
2015-10-19 05:44:59 +03:00
|
|
|
if (!mProvider) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2016-07-04 13:12:04 +03:00
|
|
|
return mProvider->Connect(this, aRetVal);
|
2015-10-19 05:44:59 +03:00
|
|
|
}
|
|
|
|
|
2016-04-28 10:05:16 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
MulticastDNSDeviceProvider::Device::Disconnect() {
|
2016-04-28 10:05:25 +03:00
|
|
|
// No need to do anything when disconnect.
|
2016-04-28 10:05:16 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-08-26 05:59:27 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
MulticastDNSDeviceProvider::Device::IsRequestedUrlSupported(
|
|
|
|
const nsAString& aRequestedUrl, bool* aRetVal) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
if (!aRetVal) {
|
|
|
|
return NS_ERROR_INVALID_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TV 2.6 also supports presentation Apps and HTTP/HTTPS hosted receiver page.
|
|
|
|
if (DeviceProviderHelpers::IsFxTVSupportedAppUrl(aRequestedUrl) ||
|
|
|
|
DeviceProviderHelpers::IsCommonlySupportedScheme(aRequestedUrl)) {
|
|
|
|
*aRetVal = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-05-21 06:06:00 +03:00
|
|
|
} // namespace presentation
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|