Bug 1599612 - Various dom/presentation code is infallible. r=kershaw

More could be cleaned up still, but this code seems disabled.

Differential Revision: https://phabricator.services.mozilla.com/D55320

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Emilio Cobos Álvarez 2019-12-02 13:07:57 +00:00
parent ab1b33c97a
commit 0a82336910
9 changed files with 79 additions and 97 deletions

View File

@ -289,7 +289,9 @@ PresentationService::Observe(nsISupports* aSubject, const char* aTopic,
if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) {
HandleShutdown();
return NS_OK;
} else if (!strcmp(aTopic, PRESENTATION_DEVICE_CHANGE_TOPIC)) {
}
if (!strcmp(aTopic, PRESENTATION_DEVICE_CHANGE_TOPIC)) {
// Ignore the "update" case here, since we only care about the arrival and
// removal of the device.
if (!NS_strcmp(aData, u"add")) {
@ -298,13 +300,16 @@ PresentationService::Observe(nsISupports* aSubject, const char* aTopic,
return NS_ERROR_FAILURE;
}
return HandleDeviceAdded(device);
} else if (!NS_strcmp(aData, u"remove")) {
return HandleDeviceRemoved();
HandleDeviceAdded(device);
return NS_OK;
}
if (!NS_strcmp(aData, u"remove")) {
return HandleDeviceRemoved();
}
return NS_OK;
} else if (!strcmp(aTopic, PRESENTATION_SESSION_REQUEST_TOPIC)) {
}
if (!strcmp(aTopic, PRESENTATION_SESSION_REQUEST_TOPIC)) {
nsCOMPtr<nsIPresentationSessionRequest> request(
do_QueryInterface(aSubject));
if (NS_WARN_IF(!request)) {
@ -312,7 +317,8 @@ PresentationService::Observe(nsISupports* aSubject, const char* aTopic,
}
return HandleSessionRequest(request);
} else if (!strcmp(aTopic, PRESENTATION_TERMINATE_REQUEST_TOPIC)) {
}
if (!strcmp(aTopic, PRESENTATION_TERMINATE_REQUEST_TOPIC)) {
nsCOMPtr<nsIPresentationTerminateRequest> request(
do_QueryInterface(aSubject));
if (NS_WARN_IF(!request)) {
@ -320,7 +326,8 @@ PresentationService::Observe(nsISupports* aSubject, const char* aTopic,
}
return HandleTerminateRequest(request);
} else if (!strcmp(aTopic, PRESENTATION_RECONNECT_REQUEST_TOPIC)) {
}
if (!strcmp(aTopic, PRESENTATION_RECONNECT_REQUEST_TOPIC)) {
nsCOMPtr<nsIPresentationSessionRequest> request(
do_QueryInterface(aSubject));
if (NS_WARN_IF(!request)) {
@ -328,12 +335,12 @@ PresentationService::Observe(nsISupports* aSubject, const char* aTopic,
}
return HandleReconnectRequest(request);
} else if (!strcmp(aTopic, "profile-after-change")) {
}
if (!strcmp(aTopic, "profile-after-change")) {
// It's expected since we add and entry to |kLayoutCategories| in
// |nsLayoutModule.cpp| to launch this service earlier.
return NS_OK;
}
MOZ_ASSERT(false, "Unexpected topic for PresentationService");
return NS_ERROR_UNEXPECTED;
}
@ -357,13 +364,9 @@ void PresentationService::HandleShutdown() {
}
}
nsresult PresentationService::HandleDeviceAdded(
nsIPresentationDevice* aDevice) {
void PresentationService::HandleDeviceAdded(nsIPresentationDevice* aDevice) {
PRES_DEBUG("%s\n", __func__);
if (!aDevice) {
MOZ_ASSERT(false, "aDevice shoud no be null.");
return NS_ERROR_INVALID_ARG;
}
MOZ_ASSERT(aDevice);
// Query for only unavailable URLs while device added.
nsTArray<nsString> unavailableUrls;
@ -379,11 +382,9 @@ nsresult PresentationService::HandleDeviceAdded(
}
if (!supportedAvailabilityUrl.IsEmpty()) {
return mAvailabilityManager.DoNotifyAvailableChange(
supportedAvailabilityUrl, true);
mAvailabilityManager.DoNotifyAvailableChange(supportedAvailabilityUrl,
true);
}
return NS_OK;
}
nsresult PresentationService::HandleDeviceRemoved() {
@ -430,12 +431,12 @@ nsresult PresentationService::UpdateAvailabilityUrlChange(
}
if (supportedAvailabilityUrl.IsEmpty()) {
return mAvailabilityManager.DoNotifyAvailableChange(aAvailabilityUrls,
false);
mAvailabilityManager.DoNotifyAvailableChange(aAvailabilityUrls, false);
} else {
mAvailabilityManager.DoNotifyAvailableChange(supportedAvailabilityUrl,
true);
}
return mAvailabilityManager.DoNotifyAvailableChange(supportedAvailabilityUrl,
true);
return NS_OK;
}
nsresult PresentationService::HandleSessionRequest(
@ -566,7 +567,8 @@ nsresult PresentationService::HandleTerminateRequest(
PRES_DEBUG("%s:handle termination:id[%s], receiver[%d]\n", __func__,
NS_ConvertUTF16toUTF8(sessionId).get(), isFromReceiver);
return info->OnTerminate(ctrlChannel);
info->OnTerminate(ctrlChannel);
return NS_OK;
}
nsresult PresentationService::HandleReconnectRequest(
@ -1077,7 +1079,8 @@ NS_IMETHODIMP
PresentationService::UpdateWindowIdBySessionId(const nsAString& aSessionId,
uint8_t aRole,
const uint64_t aWindowId) {
return UpdateWindowIdBySessionIdInternal(aSessionId, aRole, aWindowId);
UpdateWindowIdBySessionIdInternal(aSessionId, aRole, aWindowId);
return NS_OK;
}
bool PresentationService::IsSessionAccessible(const nsAString& aSessionId,

View File

@ -43,7 +43,7 @@ class PresentationService final
virtual ~PresentationService();
void HandleShutdown();
nsresult HandleDeviceAdded(nsIPresentationDevice* aDevice);
void HandleDeviceAdded(nsIPresentationDevice* aDevice);
nsresult HandleDeviceRemoved();
nsresult HandleSessionRequest(nsIPresentationSessionRequest* aRequest);
nsresult HandleTerminateRequest(nsIPresentationTerminateRequest* aRequest);

View File

@ -15,6 +15,8 @@
#include "nsRefPtrHashtable.h"
#include "nsString.h"
#include "nsTArray.h"
#include "nsDataHashtable.h"
#include "nsThread.h"
namespace mozilla {
namespace dom {
@ -103,13 +105,11 @@ class PresentationServiceBase {
}
}
nsresult UpdateWindowId(const nsAString& aSessionId,
const uint64_t aWindowId) {
void UpdateWindowId(const nsAString& aSessionId, const uint64_t aWindowId) {
MOZ_ASSERT(NS_IsMainThread());
RemoveSessionId(aSessionId);
AddSessionId(aWindowId, aSessionId);
return NS_OK;
}
void Clear() {
@ -213,8 +213,8 @@ class PresentationServiceBase {
}
}
nsresult DoNotifyAvailableChange(
const nsTArray<nsString>& aAvailabilityUrls, bool aAvailable) {
void DoNotifyAvailableChange(const nsTArray<nsString>& aAvailabilityUrls,
bool aAvailable) {
typedef nsClassHashtable<nsISupportsHashKey, nsTArray<nsString>>
ListenerToUrlsMap;
ListenerToUrlsMap availabilityListenerTable;
@ -245,7 +245,6 @@ class PresentationServiceBase {
Unused << NS_WARN_IF(NS_FAILED(
listener->NotifyAvailableChange(*it.UserData(), aAvailable)));
}
return NS_OK;
}
void GetAvailbilityUrlByAvailability(nsTArray<nsString>& aOutArray,
@ -319,17 +318,17 @@ class PresentationServiceBase {
}
}
nsresult UpdateWindowIdBySessionIdInternal(const nsAString& aSessionId,
uint8_t aRole,
const uint64_t aWindowId) {
void UpdateWindowIdBySessionIdInternal(const nsAString& aSessionId,
uint8_t aRole,
const uint64_t aWindowId) {
MOZ_ASSERT(aRole == nsIPresentationService::ROLE_CONTROLLER ||
aRole == nsIPresentationService::ROLE_RECEIVER);
if (aRole == nsIPresentationService::ROLE_CONTROLLER) {
return mControllerSessionIdManager.UpdateWindowId(aSessionId, aWindowId);
mControllerSessionIdManager.UpdateWindowId(aSessionId, aWindowId);
} else {
mReceiverSessionIdManager.UpdateWindowId(aSessionId, aWindowId);
}
return mReceiverSessionIdManager.UpdateWindowId(aSessionId, aWindowId);
}
// Store the responding listener based on the window ID of the (in-process or

View File

@ -319,13 +319,11 @@ nsresult PresentationSessionInfo::Close(nsresult aReason, uint32_t aState) {
return NS_OK;
}
nsresult PresentationSessionInfo::OnTerminate(
void PresentationSessionInfo::OnTerminate(
nsIPresentationControlChannel* aControlChannel) {
mIsOnTerminating = true; // Mark for terminating transport channel
SetStateWithReason(nsIPresentationSessionListener::STATE_TERMINATED, NS_OK);
SetControlChannel(aControlChannel);
return NS_OK;
}
nsresult PresentationSessionInfo::ReplySuccess() {

View File

@ -90,7 +90,7 @@ class PresentationSessionInfo
nsresult Close(nsresult aReason, uint32_t aState);
nsresult OnTerminate(nsIPresentationControlChannel* aControlChannel);
void OnTerminate(nsIPresentationControlChannel* aControlChannel);
nsresult ReplyError(nsresult aReason);

View File

@ -67,11 +67,11 @@ PresentationIPCService::StartSession(
nsGlobalWindowInner::GetInnerWindowWithId(aWindowId);
TabId tabId = BrowserParent::GetTabIdFrom(window->GetDocShell());
return SendRequest(
aCallback,
StartSessionRequest(aUrls, nsString(aSessionId), nsString(aOrigin),
nsString(aDeviceId), aWindowId, tabId,
IPC::Principal(aPrincipal)));
SendRequest(aCallback, StartSessionRequest(
aUrls, nsString(aSessionId), nsString(aOrigin),
nsString(aDeviceId), aWindowId, tabId,
IPC::Principal(aPrincipal)));
return NS_OK;
}
NS_IMETHODIMP
@ -88,9 +88,9 @@ PresentationIPCService::SendSessionMessage(const nsAString& aSessionId,
return info->Send(aData);
}
return SendRequest(
nullptr,
SendSessionMessageRequest(nsString(aSessionId), aRole, nsString(aData)));
SendRequest(nullptr, SendSessionMessageRequest(nsString(aSessionId), aRole,
nsString(aData)));
return NS_OK;
}
NS_IMETHODIMP
@ -137,11 +137,8 @@ PresentationIPCService::CloseSession(const nsAString& aSessionId, uint8_t aRole,
uint8_t aClosedReason) {
MOZ_ASSERT(!aSessionId.IsEmpty());
nsresult rv = SendRequest(
nullptr, CloseSessionRequest(nsString(aSessionId), aRole, aClosedReason));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
SendRequest(nullptr,
CloseSessionRequest(nsString(aSessionId), aRole, aClosedReason));
RefPtr<PresentationContentSessionInfo> info =
GetSessionInfo(aSessionId, aRole);
@ -157,11 +154,7 @@ PresentationIPCService::TerminateSession(const nsAString& aSessionId,
uint8_t aRole) {
MOZ_ASSERT(!aSessionId.IsEmpty());
nsresult rv = SendRequest(
nullptr, TerminateSessionRequest(nsString(aSessionId), aRole));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
SendRequest(nullptr, TerminateSessionRequest(nsString(aSessionId), aRole));
RefPtr<PresentationContentSessionInfo> info =
GetSessionInfo(aSessionId, aRole);
@ -183,8 +176,9 @@ PresentationIPCService::ReconnectSession(
return NS_ERROR_INVALID_ARG;
}
return SendRequest(
aCallback, ReconnectSessionRequest(aUrls, nsString(aSessionId), aRole));
SendRequest(aCallback,
ReconnectSessionRequest(aUrls, nsString(aSessionId), aRole));
return NS_OK;
}
NS_IMETHODIMP
@ -197,11 +191,11 @@ PresentationIPCService::BuildTransport(const nsAString& aSessionId,
return NS_ERROR_INVALID_ARG;
}
return SendRequest(nullptr,
BuildTransportRequest(nsString(aSessionId), aRole));
SendRequest(nullptr, BuildTransportRequest(nsString(aSessionId), aRole));
return NS_OK;
}
nsresult PresentationIPCService::SendRequest(
void PresentationIPCService::SendRequest(
nsIPresentationServiceCallback* aCallback,
const PresentationIPCRequest& aRequest) {
if (sPresentationChild) {
@ -210,7 +204,6 @@ nsresult PresentationIPCService::SendRequest(
!sPresentationChild->SendPPresentationRequestConstructor(actor,
aRequest));
}
return NS_OK;
}
NS_IMETHODIMP
@ -339,7 +332,8 @@ NS_IMETHODIMP
PresentationIPCService::UpdateWindowIdBySessionId(const nsAString& aSessionId,
uint8_t aRole,
const uint64_t aWindowId) {
return UpdateWindowIdBySessionIdInternal(aSessionId, aRole, aWindowId);
UpdateWindowIdBySessionIdInternal(aSessionId, aRole, aWindowId);
return NS_OK;
}
nsresult PresentationIPCService::NotifySessionStateChange(
@ -393,8 +387,8 @@ nsresult PresentationIPCService::NotifySessionConnect(
NS_IMETHODIMP
PresentationIPCService::NotifyAvailableChange(
const nsTArray<nsString>& aAvailabilityUrls, bool aAvailable) {
return mAvailabilityManager.DoNotifyAvailableChange(aAvailabilityUrls,
aAvailable);
mAvailabilityManager.DoNotifyAvailableChange(aAvailabilityUrls, aAvailable);
return NS_OK;
}
NS_IMETHODIMP

View File

@ -55,8 +55,8 @@ class PresentationIPCService final
private:
virtual ~PresentationIPCService();
nsresult SendRequest(nsIPresentationServiceCallback* aCallback,
const PresentationIPCRequest& aRequest);
void SendRequest(nsIPresentationServiceCallback* aCallback,
const PresentationIPCRequest& aRequest);
nsRefPtrHashtable<nsStringHashKey, nsIPresentationSessionListener>
mSessionListeners;

View File

@ -182,11 +182,11 @@ nsresult MulticastDNSDeviceProvider::Init() {
return NS_OK;
}
nsresult MulticastDNSDeviceProvider::Uninit() {
void MulticastDNSDeviceProvider::Uninit() {
MOZ_ASSERT(NS_IsMainThread());
if (!mInitialized) {
return NS_OK;
return;
}
ClearDevices();
@ -204,7 +204,6 @@ nsresult MulticastDNSDeviceProvider::Uninit() {
}
mInitialized = false;
return NS_OK;
}
nsresult MulticastDNSDeviceProvider::StartServer() {
@ -245,7 +244,7 @@ nsresult MulticastDNSDeviceProvider::StartServer() {
return NS_OK;
}
nsresult MulticastDNSDeviceProvider::StopServer() {
void MulticastDNSDeviceProvider::StopServer() {
LOG_I("StopServer: %s", mServiceName.get());
MOZ_ASSERT(NS_IsMainThread());
@ -257,8 +256,6 @@ nsresult MulticastDNSDeviceProvider::StopServer() {
mPresentationService->SetListener(nullptr);
mPresentationService->Close();
}
return NS_OK;
}
void MulticastDNSDeviceProvider::AbortServerRetry() {
@ -336,7 +333,7 @@ nsresult MulticastDNSDeviceProvider::RegisterMDNSService() {
getter_AddRefs(mRegisterRequest));
}
nsresult MulticastDNSDeviceProvider::UnregisterMDNSService(nsresult aReason) {
void MulticastDNSDeviceProvider::UnregisterMDNSService(nsresult aReason) {
LOG_I("UnregisterMDNSService: %s (0x%08" PRIx32 ")", mServiceName.get(),
static_cast<uint32_t>(aReason));
MOZ_ASSERT(NS_IsMainThread());
@ -345,8 +342,6 @@ nsresult MulticastDNSDeviceProvider::UnregisterMDNSService(nsresult aReason) {
mRegisterRequest->Cancel(aReason);
mRegisterRequest = nullptr;
}
return NS_OK;
}
nsresult MulticastDNSDeviceProvider::StopDiscovery(nsresult aReason) {
@ -575,9 +570,7 @@ MulticastDNSDeviceProvider::SetListener(
return rv;
}
} else {
if (NS_WARN_IF(NS_FAILED(rv = Uninit()))) {
return rv;
}
Uninit();
}
return NS_OK;
@ -865,12 +858,9 @@ MulticastDNSDeviceProvider::OnServiceResolved(nsIDNSServiceInfo* aServiceInfo) {
if (FindDeviceById(host, index)) {
return UpdateDevice(index, serviceName, serviceType, address, port,
certFingerprint);
} else {
return AddDevice(host, serviceName, serviceType, address, port,
certFingerprint);
}
return NS_OK;
return AddDevice(host, serviceName, serviceType, address, port,
certFingerprint);
}
NS_IMETHODIMP
@ -1082,7 +1072,8 @@ nsresult MulticastDNSDeviceProvider::OnDiscoverableChanged(bool aEnabled) {
return StartServer();
}
return StopServer();
StopServer();
return NS_OK;
}
nsresult MulticastDNSDeviceProvider::OnServiceNameChanged(
@ -1092,10 +1083,7 @@ nsresult MulticastDNSDeviceProvider::OnServiceNameChanged(
mServiceName = aServiceName;
nsresult rv;
if (NS_WARN_IF(NS_FAILED(rv = UnregisterMDNSService(NS_OK)))) {
return rv;
}
UnregisterMDNSService(NS_OK);
if (mDiscoverable) {
return RegisterMDNSService();

View File

@ -47,7 +47,7 @@ class MulticastDNSDeviceProvider final
explicit MulticastDNSDeviceProvider();
nsresult Init();
nsresult Uninit();
void Uninit();
private:
enum class DeviceState : uint32_t { eUnknown, eActive };
@ -119,10 +119,10 @@ class MulticastDNSDeviceProvider final
virtual ~MulticastDNSDeviceProvider();
nsresult StartServer();
nsresult StopServer();
void StopServer();
void AbortServerRetry();
nsresult RegisterMDNSService();
nsresult UnregisterMDNSService(nsresult aReason);
void UnregisterMDNSService(nsresult aReason);
nsresult StopDiscovery(nsresult aReason);
nsresult Connect(Device* aDevice, nsIPresentationControlChannel** aRetVal);
bool IsCompatibleServer(nsIDNSServiceInfo* aServiceInfo);