Bug 1192101 - Part 3 - Support PresentationRequest / PresentationAvailability / getSession(s). Part 3 - Adjust errors. r=smaug
authorSean Lin <selin@mozilla.com>
Wed, 09 Sep 2015 16:38:26 +0800
changeset 294909 c1e3a179f4f3364fb621e308fd84be657a1da902
parent 294908 4de2bdb67cd103148678f73b35a700c38f870af3
child 294910 2fe2431a5f083a1aa4e003f5e571c091a4ba9291
push id5245
push userraliiev@mozilla.com
push dateThu, 29 Oct 2015 11:30:51 +0000
treeherdermozilla-beta@dac831dc1bd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1192101
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1192101 - Part 3 - Support PresentationRequest / PresentationAvailability / getSession(s). Part 3 - Adjust errors. r=smaug
dom/presentation/PresentationCallbacks.cpp
dom/presentation/PresentationService.cpp
dom/presentation/PresentationSessionInfo.cpp
--- a/dom/presentation/PresentationCallbacks.cpp
+++ b/dom/presentation/PresentationCallbacks.cpp
@@ -47,17 +47,17 @@ PresentationRequesterCallback::NotifySuc
   MOZ_ASSERT(NS_IsMainThread());
 
   // At the sender side, this function must get called after the transport
   // channel is ready. So we simply set the session state as connected.
   nsRefPtr<PresentationSession> session =
     PresentationSession::Create(mRequest->GetOwner(), mSessionId,
                                 PresentationSessionState::Connected);
   if (NS_WARN_IF(!session)) {
-    mPromise->MaybeReject(NS_ERROR_DOM_ABORT_ERR);
+    mPromise->MaybeReject(NS_ERROR_DOM_OPERATION_ERR);
     return NS_OK;
   }
 
   mPromise->MaybeResolve(session);
 
   return mRequest->DispatchSessionConnectEvent(session);
 }
 
--- a/dom/presentation/PresentationService.cpp
+++ b/dom/presentation/PresentationService.cpp
@@ -103,23 +103,23 @@ PresentationDeviceRequest::Select(nsIPre
   }
   info->SetDevice(aDevice);
 
   // Establish a control channel. If we failed to do so, the callback is called
   // with an error message.
   nsCOMPtr<nsIPresentationControlChannel> ctrlChannel;
   nsresult rv = aDevice->EstablishControlChannel(mRequestUrl, mId, getter_AddRefs(ctrlChannel));
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return info->ReplyError(NS_ERROR_DOM_NETWORK_ERR);
+    return info->ReplyError(NS_ERROR_DOM_OPERATION_ERR);
   }
 
   // Initialize the session info with the control channel.
   rv = info->Init(ctrlChannel);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return info->ReplyError(NS_ERROR_DOM_NETWORK_ERR);
+    return info->ReplyError(NS_ERROR_DOM_OPERATION_ERR);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PresentationDeviceRequest::Cancel()
 {
@@ -130,17 +130,17 @@ PresentationDeviceRequest::Cancel()
   }
 
   nsRefPtr<PresentationSessionInfo> info =
     static_cast<PresentationService*>(service.get())->GetSessionInfo(mId);
   if (NS_WARN_IF(!info)) {
     return NS_ERROR_NOT_AVAILABLE;
   }
 
-  return info->ReplyError(NS_ERROR_DOM_PROP_ACCESS_DENIED);
+  return info->ReplyError(NS_ERROR_DOM_ABORT_ERR);
 }
 
 /*
  * Implementation of PresentationService
  */
 
 NS_IMPL_ISUPPORTS(PresentationService, nsIPresentationService, nsIObserver)
 
@@ -262,85 +262,85 @@ PresentationService::HandleSessionReques
   nsresult rv = aRequest->GetControlChannel(getter_AddRefs(ctrlChannel));
   if (NS_WARN_IF(NS_FAILED(rv) || !ctrlChannel)) {
     return rv;
   }
 
   nsAutoString url;
   rv = aRequest->GetUrl(url);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    ctrlChannel->Close(NS_ERROR_DOM_ABORT_ERR);
+    ctrlChannel->Close(rv);
     return rv;
   }
 
   nsAutoString sessionId;
   rv = aRequest->GetPresentationId(sessionId);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    ctrlChannel->Close(NS_ERROR_DOM_ABORT_ERR);
+    ctrlChannel->Close(rv);
     return rv;
   }
 
   nsCOMPtr<nsIPresentationDevice> device;
   rv = aRequest->GetDevice(getter_AddRefs(device));
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    ctrlChannel->Close(NS_ERROR_DOM_ABORT_ERR);
+    ctrlChannel->Close(rv);
     return rv;
   }
 
 #ifdef MOZ_WIDGET_GONK
   // Verify the existence of the app if necessary.
   nsCOMPtr<nsIURI> uri;
   rv = NS_NewURI(getter_AddRefs(uri), url);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     ctrlChannel->Close(NS_ERROR_DOM_BAD_URI);
     return rv;
   }
 
   bool isApp;
   rv = uri->SchemeIs("app", &isApp);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    ctrlChannel->Close(NS_ERROR_DOM_ABORT_ERR);
+    ctrlChannel->Close(rv);
     return rv;
   }
 
   if (NS_WARN_IF(isApp && !IsAppInstalled(uri))) {
     ctrlChannel->Close(NS_ERROR_DOM_NOT_FOUND_ERR);
     return NS_OK;
   }
 #endif
 
   // Create or reuse session info.
   nsRefPtr<PresentationSessionInfo> info = GetSessionInfo(sessionId);
   if (NS_WARN_IF(info)) {
-    // TODO Update here after session resumption becomes supported.
-    ctrlChannel->Close(NS_ERROR_DOM_ABORT_ERR);
+    // TODO Bug 1195605. Update here after session join/resume becomes supported.
+    ctrlChannel->Close(NS_ERROR_DOM_OPERATION_ERR);
     return NS_ERROR_DOM_ABORT_ERR;
   }
 
   info = new PresentationResponderInfo(url, sessionId, device);
   rv = info->Init(ctrlChannel);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    ctrlChannel->Close(NS_ERROR_DOM_ABORT_ERR);
+    ctrlChannel->Close(rv);
     return rv;
   }
 
   mSessionInfo.Put(sessionId, info);
 
   // Notify the receiver to launch.
   nsCOMPtr<nsIPresentationRequestUIGlue> glue =
     do_CreateInstance(PRESENTATION_REQUEST_UI_GLUE_CONTRACTID);
   if (NS_WARN_IF(!glue)) {
-    ctrlChannel->Close(NS_ERROR_DOM_ABORT_ERR);
-    return info->ReplyError(NS_ERROR_NOT_AVAILABLE);
+    ctrlChannel->Close(NS_ERROR_DOM_OPERATION_ERR);
+    return info->ReplyError(NS_ERROR_DOM_OPERATION_ERR);
   }
   nsCOMPtr<nsISupports> promise;
   rv = glue->SendRequest(url, sessionId, getter_AddRefs(promise));
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    ctrlChannel->Close(NS_ERROR_DOM_ABORT_ERR);
-    return info->ReplyError(rv);
+    ctrlChannel->Close(rv);
+    return info->ReplyError(NS_ERROR_DOM_OPERATION_ERR);
   }
   nsCOMPtr<Promise> realPromise = do_QueryInterface(promise);
   static_cast<PresentationResponderInfo*>(info.get())->SetPromise(realPromise);
 
   return NS_OK;
 }
 
 void
@@ -395,23 +395,23 @@ PresentationService::StartSession(const 
   nsRefPtr<PresentationRequesterInfo> info =
     new PresentationRequesterInfo(aUrl, aSessionId, aCallback);
   mSessionInfo.Put(aSessionId, info);
 
   // Pop up a prompt and ask user to select a device.
   nsCOMPtr<nsIPresentationDevicePrompt> prompt =
     do_GetService(PRESENTATION_DEVICE_PROMPT_CONTRACTID);
   if (NS_WARN_IF(!prompt)) {
-    return info->ReplyError(NS_ERROR_DOM_ABORT_ERR);
+    return info->ReplyError(NS_ERROR_DOM_OPERATION_ERR);
   }
   nsCOMPtr<nsIPresentationDeviceRequest> request =
     new PresentationDeviceRequest(aUrl, aSessionId, aOrigin);
   nsresult rv = prompt->PromptDeviceSelection(request);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return info->ReplyError(NS_ERROR_DOM_ABORT_ERR);
+    return info->ReplyError(NS_ERROR_DOM_OPERATION_ERR);
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PresentationService::SendSessionMessage(const nsAString& aSessionId,
                                         nsIInputStream* aStream)
--- a/dom/presentation/PresentationSessionInfo.cpp
+++ b/dom/presentation/PresentationSessionInfo.cpp
@@ -137,16 +137,18 @@ PresentationSessionInfo::Init(nsIPresent
 {
   SetControlChannel(aControlChannel);
   return NS_OK;
 }
 
 /* virtual */ void
 PresentationSessionInfo::Shutdown(nsresult aReason)
 {
+  NS_WARN_IF(NS_FAILED(aReason));
+
   // Close the control channel if any.
   if (mControlChannel) {
     NS_WARN_IF(NS_FAILED(mControlChannel->Close(aReason)));
   }
 
   // Close the data transport channel if any.
   if (mTransport) {
     // |mIsTransportReady| will be unset once |NotifyTransportClosed| is called.
@@ -293,19 +295,19 @@ PresentationSessionInfo::NotifyTransport
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   // Nullify |mTransport| here so it won't try to re-close |mTransport| in
   // potential subsequent |Shutdown| calls.
   mTransport->SetCallback(nullptr);
   mTransport = nullptr;
 
-  if (!IsSessionReady()) {
+  if (NS_WARN_IF(!IsSessionReady())) {
     // It happens before the session is ready. Reply the callback.
-    return ReplyError(aReason);
+    return ReplyError(NS_ERROR_DOM_OPERATION_ERR);
   }
 
   // Unset |mIsTransportReady| here so it won't affect |IsSessionReady()| above.
   mIsTransportReady = false;
 
   Shutdown(aReason);
 
   uint16_t state = (NS_WARN_IF(NS_FAILED(aReason))) ?
@@ -370,17 +372,17 @@ nsresult
 PresentationRequesterInfo::Init(nsIPresentationControlChannel* aControlChannel)
 {
   PresentationSessionInfo::Init(aControlChannel);
 
   // Initialize |mServerSocket| for bootstrapping the data transport channel and
   // use |this| as the listener.
   mServerSocket = do_CreateInstance(NS_SERVERSOCKET_CONTRACTID);
   if (NS_WARN_IF(!mServerSocket)) {
-    return ReplyError(NS_ERROR_NOT_AVAILABLE);
+    return ReplyError(NS_ERROR_DOM_OPERATION_ERR);
   }
 
   nsresult rv = mServerSocket->Init(-1, false, -1);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   rv = mServerSocket->AsyncListen(this);
@@ -459,17 +461,17 @@ PresentationRequesterInfo::OnOffer(nsIPr
 NS_IMETHODIMP
 PresentationRequesterInfo::OnAnswer(nsIPresentationChannelDescription* aDescription)
 {
   mIsResponderReady = true;
 
   // Close the control channel since it's no longer needed.
   nsresult rv = mControlChannel->Close(NS_OK);
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    return ReplyError(rv);
+    return ReplyError(NS_ERROR_DOM_OPERATION_ERR);
   }
 
   // Session might not be ready at this moment (waiting for the establishment of
   // the data transport channel).
   if (IsSessionReady()){
     return ReplySuccess();
   }
 
@@ -510,33 +512,33 @@ PresentationRequesterInfo::NotifyClosed(
     if (mListener) {
       // The presentation session instance at receiver side may already exist.
       // Change the state to TERMINATED since it never succeeds.
       return mListener->NotifyStateChange(mSessionId,
                                           nsIPresentationSessionListener::STATE_TERMINATED);
     }
 
     // Reply error for an abnormal close.
-    return ReplyError(aReason);
+    return ReplyError(NS_ERROR_DOM_OPERATION_ERR);
   }
 
   return NS_OK;
 }
 
 // nsIServerSocketListener
 NS_IMETHODIMP
 PresentationRequesterInfo::OnSocketAccepted(nsIServerSocket* aServerSocket,
                                             nsISocketTransport* aTransport)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   // Initialize |mTransport| and use |this| as the callback.
   mTransport = do_CreateInstance(PRESENTATION_SESSION_TRANSPORT_CONTRACTID);
   if (NS_WARN_IF(!mTransport)) {
-    return ReplyError(NS_ERROR_NOT_AVAILABLE);
+    return ReplyError(NS_ERROR_DOM_OPERATION_ERR);
   }
 
   nsresult rv = mTransport->InitWithSocketTransport(aTransport, this);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
 
   // Enable data notification if the listener has been registered.
@@ -554,19 +556,19 @@ PresentationRequesterInfo::OnStopListeni
   MOZ_ASSERT(NS_IsMainThread());
 
   if (aStatus == NS_BINDING_ABORTED) { // The server socket was manually closed.
     return NS_OK;
   }
 
   Shutdown(aStatus);
 
-  if (!IsSessionReady()) {
+  if (NS_WARN_IF(!IsSessionReady())) {
     // It happens before the session is ready. Reply the callback.
-    return ReplyError(aStatus);
+    return ReplyError(NS_ERROR_DOM_OPERATION_ERR);
   }
 
   // It happens after the session is ready. Notify session state change.
   if (mListener) {
     return mListener->NotifyStateChange(mSessionId,
                                         nsIPresentationSessionListener::STATE_DISCONNECTED);
   }
 
@@ -715,39 +717,39 @@ PresentationResponderInfo::NotifyRespond
 
   mIsResponderReady = true;
 
   // Initialize |mTransport| and send the answer to the sender if sender's
   // description is already offered.
   if (mRequesterDescription) {
     nsresult rv = InitTransportAndSendAnswer();
     if (NS_WARN_IF(NS_FAILED(rv))) {
-      return ReplyError(rv);
+      return ReplyError(NS_ERROR_DOM_OPERATION_ERR);
     }
   }
 
   return NS_OK;
 }
 
 // nsIPresentationControlChannelListener
 NS_IMETHODIMP
 PresentationResponderInfo::OnOffer(nsIPresentationChannelDescription* aDescription)
 {
   if (NS_WARN_IF(!aDescription)) {
-    return ReplyError(NS_ERROR_INVALID_ARG);
+    return ReplyError(NS_ERROR_DOM_OPERATION_ERR);
   }
 
   mRequesterDescription = aDescription;
 
   // Initialize |mTransport| and send the answer to the sender if the receiver
   // page is ready for presentation use.
   if (mIsResponderReady) {
     nsresult rv = InitTransportAndSendAnswer();
     if (NS_WARN_IF(NS_FAILED(rv))) {
-      return ReplyError(rv);
+      return ReplyError(NS_ERROR_DOM_OPERATION_ERR);
     }
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PresentationResponderInfo::OnAnswer(nsIPresentationChannelDescription* aDescription)
@@ -776,17 +778,17 @@ PresentationResponderInfo::NotifyClosed(
     if (mListener) {
       // The presentation session instance at receiver side may already exist.
       // Change the state to TERMINATED since it never succeeds.
       return mListener->NotifyStateChange(mSessionId,
                                           nsIPresentationSessionListener::STATE_TERMINATED);
     }
 
     // Reply error for an abnormal close.
-    return ReplyError(aReason);
+    return ReplyError(NS_ERROR_DOM_OPERATION_ERR);
   }
 
   return NS_OK;
 }
 
 // nsITimerCallback
 NS_IMETHODIMP
 PresentationResponderInfo::Notify(nsITimer* aTimer)
@@ -801,68 +803,68 @@ PresentationResponderInfo::Notify(nsITim
 // PromiseNativeHandler
 void
 PresentationResponderInfo::ResolvedCallback(JSContext* aCx,
                                             JS::Handle<JS::Value> aValue)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (NS_WARN_IF(!aValue.isObject())) {
-    ReplyError(NS_ERROR_NOT_AVAILABLE);
+    ReplyError(NS_ERROR_DOM_OPERATION_ERR);
     return;
   }
 
   JS::Rooted<JSObject*> obj(aCx, &aValue.toObject());
   if (NS_WARN_IF(!obj)) {
-    ReplyError(NS_ERROR_NOT_AVAILABLE);
+    ReplyError(NS_ERROR_DOM_OPERATION_ERR);
     return;
   }
 
   // Start to listen to document state change event |STATE_TRANSFERRING|.
   HTMLIFrameElement* frame = nullptr;
   nsresult rv = UNWRAP_OBJECT(HTMLIFrameElement, obj, frame);
   if (NS_WARN_IF(!frame)) {
-    ReplyError(NS_ERROR_NOT_AVAILABLE);
+    ReplyError(NS_ERROR_DOM_OPERATION_ERR);
     return;
   }
 
   nsCOMPtr<nsIFrameLoaderOwner> owner = do_QueryInterface((nsIFrameLoaderOwner*) frame);
   if (NS_WARN_IF(!owner)) {
-    ReplyError(NS_ERROR_NOT_AVAILABLE);
+    ReplyError(NS_ERROR_DOM_OPERATION_ERR);
     return;
   }
 
   nsCOMPtr<nsIFrameLoader> frameLoader;
   rv = owner->GetFrameLoader(getter_AddRefs(frameLoader));
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    ReplyError(rv);
+    ReplyError(NS_ERROR_DOM_OPERATION_ERR);
     return;
   }
 
   nsRefPtr<TabParent> tabParent = TabParent::GetFrom(frameLoader);
   if (tabParent) {
     // OOP frame
     // Notify the content process that a receiver page has launched, so it can
     // start monitoring the loading progress.
     mContentParent = tabParent->Manager();
     NS_WARN_IF(!static_cast<ContentParent*>(mContentParent.get())->SendNotifyPresentationReceiverLaunched(tabParent, mSessionId));
   } else {
     // In-process frame
     nsCOMPtr<nsIDocShell> docShell;
     rv = frameLoader->GetDocShell(getter_AddRefs(docShell));
     if (NS_WARN_IF(NS_FAILED(rv))) {
-      ReplyError(rv);
+      ReplyError(NS_ERROR_DOM_OPERATION_ERR);
       return;
     }
 
     // Keep an eye on the loading progress of the receiver page.
     mLoadingCallback = new PresentationResponderLoadingCallback(mSessionId);
     rv = mLoadingCallback->Init(docShell);
     if (NS_WARN_IF(NS_FAILED(rv))) {
-      ReplyError(rv);
+      ReplyError(NS_ERROR_DOM_OPERATION_ERR);
       return;
     }
   }
 }
 
 void
 PresentationResponderInfo::RejectedCallback(JSContext* aCx,
                                             JS::Handle<JS::Value> aValue)
@@ -870,10 +872,10 @@ PresentationResponderInfo::RejectedCallb
   MOZ_ASSERT(NS_IsMainThread());
   NS_WARNING("Launching the receiver page has been rejected.");
 
   if (mTimer) {
     mTimer->Cancel();
     mTimer = nullptr;
   }
 
-  ReplyError(NS_ERROR_DOM_ABORT_ERR);
+  ReplyError(NS_ERROR_DOM_OPERATION_ERR);
 }