Bug 1442453 - Fix nits and get rid of needless QIs. r=baku draft
authorBlake Kaplan <mrbkap@gmail.com>
Wed, 30 May 2018 14:13:07 -0700
changeset 808271 12f586dd6cf294f6c92178655f59be4f0845a8b2
parent 808270 9718d0d139089f755823471041632b7d4a7cbecd
child 808272 2a427d066ab0cff8aeba151a6fd93af983397dd4
push id113333
push userbmo:mrbkap@mozilla.com
push dateMon, 18 Jun 2018 22:37:33 +0000
reviewersbaku
bugs1442453
milestone62.0a1
Bug 1442453 - Fix nits and get rid of needless QIs. r=baku This removes some hard tabs that crept in and combines two if branches into a single statement in order to avoid a bit of duplication. The existing code here seems to treat any sort of upcast as needing a QI. That is needlessly wasteful and causes a bunch of unneeded virtual calls. MozReview-Commit-ID: 7WshYm9C4Xb
dom/payments/PaymentActionRequest.cpp
dom/payments/PaymentRequest.cpp
dom/payments/PaymentRequestData.cpp
dom/payments/PaymentRequestManager.cpp
dom/payments/PaymentRequestService.cpp
dom/payments/PaymentResponse.cpp
dom/payments/ipc/PaymentRequestParent.cpp
--- a/dom/payments/PaymentActionRequest.cpp
+++ b/dom/payments/PaymentActionRequest.cpp
@@ -74,17 +74,17 @@ PaymentCreateActionRequest::PaymentCreat
 NS_IMETHODIMP
 PaymentCreateActionRequest::InitRequest(const nsAString& aRequestId,
                                         nsIPaymentActionCallback* aCallback,
                                         const uint64_t aTabId,
                                         nsIPrincipal* aTopLevelPrincipal,
                                         nsIArray* aMethodData,
                                         nsIPaymentDetails* aDetails,
                                         nsIPaymentOptions* aOptions,
-					const nsAString& aShippingOption)
+                                        const nsAString& aShippingOption)
 {
   NS_ENSURE_ARG_POINTER(aCallback);
   NS_ENSURE_ARG_POINTER(aTopLevelPrincipal);
   NS_ENSURE_ARG_POINTER(aMethodData);
   NS_ENSURE_ARG_POINTER(aDetails);
   NS_ENSURE_ARG_POINTER(aOptions);
   nsresult rv = Init(aRequestId, nsIPaymentActionRequest::CREATE_ACTION, aCallback);
   if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -208,17 +208,17 @@ PaymentUpdateActionRequest::GetShippingO
   aShippingOption = mShippingOption;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PaymentUpdateActionRequest::InitRequest(const nsAString& aRequestId,
                                         nsIPaymentActionCallback* aCallback,
                                         nsIPaymentDetails* aDetails,
-					const nsAString& aShippingOption)
+                                        const nsAString& aShippingOption)
 {
   NS_ENSURE_ARG_POINTER(aCallback);
   NS_ENSURE_ARG_POINTER(aDetails);
   nsresult rv = Init(aRequestId, nsIPaymentActionRequest::UPDATE_ACTION, aCallback);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   mDetails = aDetails;
--- a/dom/payments/PaymentRequest.cpp
+++ b/dom/payments/PaymentRequest.cpp
@@ -645,17 +645,17 @@ PaymentRequest::CanMakePayment(ErrorResu
     return nullptr;
   }
 
   if (mResultPromise) {
     aRv.Throw(NS_ERROR_DOM_NOT_ALLOWED_ERR);
     return nullptr;
   }
 
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
+  nsCOMPtr<nsIGlobalObject> global = GetOwnerGlobal();
   ErrorResult result;
   RefPtr<Promise> promise = Promise::Create(global, result);
   if (result.Failed()) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
 
   RefPtr<PaymentRequestManager> manager = PaymentRequestManager::GetSingleton();
@@ -689,17 +689,17 @@ PaymentRequest::Show(const Optional<Owni
     return nullptr;
   }
 
   if (!EventStateManager::IsHandlingUserInput()) {
     aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
     return nullptr;
   }
 
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
+  nsCOMPtr<nsIGlobalObject> global = GetOwnerGlobal();
   ErrorResult result;
   RefPtr<Promise> promise = Promise::Create(global, result);
   if (result.Failed()) {
     mState = eClosed;
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
 
@@ -789,17 +789,17 @@ PaymentRequest::Abort(ErrorResult& aRv)
     return nullptr;
   }
 
   if (mAbortPromise) {
     aRv.Throw(NS_ERROR_DOM_NOT_ALLOWED_ERR);
     return nullptr;
   }
 
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
+  nsCOMPtr<nsIGlobalObject> global = GetOwnerGlobal();
   ErrorResult result;
   RefPtr<Promise> promise = Promise::Create(global, result);
   if (result.Failed()) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
 
   RefPtr<PaymentRequestManager> manager = PaymentRequestManager::GetSingleton();
--- a/dom/payments/PaymentRequestData.cpp
+++ b/dom/payments/PaymentRequestData.cpp
@@ -629,17 +629,17 @@ NS_IMPL_ISUPPORTS(PaymentRequest,
                   nsIPaymentRequest)
 
 PaymentRequest::PaymentRequest(const uint64_t aTabId,
                                const nsAString& aRequestId,
                                nsIPrincipal* aTopLevelPrincipal,
                                nsIArray* aPaymentMethods,
                                nsIPaymentDetails* aPaymentDetails,
                                nsIPaymentOptions* aPaymentOptions,
-			       const nsAString& aShippingOption)
+                               const nsAString& aShippingOption)
   : mTabId(aTabId)
   , mRequestId(aRequestId)
   , mTopLevelPrincipal(aTopLevelPrincipal)
   , mPaymentMethods(aPaymentMethods)
   , mPaymentDetails(aPaymentDetails)
   , mPaymentOptions(aPaymentOptions)
   , mShippingOption(aShippingOption)
 {
--- a/dom/payments/PaymentRequestManager.cpp
+++ b/dom/payments/PaymentRequestManager.cpp
@@ -453,17 +453,17 @@ PaymentRequestManager::CreatePayment(JSC
   IPCPaymentOptions options;
   ConvertOptions(aOptions, options);
 
   IPCPaymentCreateActionRequest action(internalId,
                                        IPC::Principal(aTopLevelPrincipal),
                                        methodData,
                                        details,
                                        options,
-				       shippingOption);
+                                       shippingOption);
 
   rv = SendRequestPayment(request, action, true);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   mRequestQueue.AppendElement(request);
   request.forget(aRequest);
   return NS_OK;
--- a/dom/payments/PaymentRequestService.cpp
+++ b/dom/payments/PaymentRequestService.cpp
@@ -52,22 +52,18 @@ PaymentRequestEnumerator::GetNext(nsISup
   if (NS_WARN_IF(!gPaymentService)) {
     return NS_ERROR_FAILURE;
   }
   nsCOMPtr<nsIPaymentRequest> request =
     gPaymentService->GetPaymentRequestByIndex(mIndex);
   if (NS_WARN_IF(!request)) {
     return NS_ERROR_FAILURE;
   }
-  nsCOMPtr<nsISupports> item = do_QueryInterface(request);
-  if (NS_WARN_IF(!item)) {
-    return NS_ERROR_FAILURE;
-  }
   mIndex++;
-  item.forget(aItem);
+  request.forget(aItem);
   return NS_OK;
 }
 
 } // end of anonymous namespace
 
 /* PaymentRequestService */
 
 NS_IMPL_ISUPPORTS(PaymentRequestService,
@@ -265,27 +261,23 @@ PaymentRequestService::RequestPayment(ns
         return NS_ERROR_OUT_OF_MEMORY;
       }
       break;
     }
     case nsIPaymentActionRequest::CANMAKE_ACTION: {
       nsCOMPtr<nsIPaymentCanMakeActionResponse> canMakeResponse =
         do_CreateInstance(NS_PAYMENT_CANMAKE_ACTION_RESPONSE_CONTRACT_ID);
       MOZ_ASSERT(canMakeResponse);
-      if (CanMakePayment(requestId)) {
-        rv = canMakeResponse->Init(requestId, true);
-      } else {
-        rv = canMakeResponse->Init(requestId, false);
-      }
+
+      rv = canMakeResponse->Init(requestId, CanMakePayment(requestId));
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
-      nsCOMPtr<nsIPaymentActionResponse> response = do_QueryInterface(canMakeResponse);
-      MOZ_ASSERT(response);
-      rv = RespondPayment(response);
+
+      rv = RespondPayment(canMakeResponse.get());
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return rv;
       }
       break;
     }
     case nsIPaymentActionRequest::SHOW_ACTION: {
       if (mShowingRequest || !CanMakePayment(requestId)) {
         uint32_t responseStatus;
@@ -299,19 +291,17 @@ PaymentRequestService::RequestPayment(ns
         MOZ_ASSERT(showResponse);
         rv = showResponse->Init(requestId,
                                 responseStatus,
                                 EmptyString(),
                                 nullptr,
                                 EmptyString(),
                                 EmptyString(),
                                 EmptyString());
-        nsCOMPtr<nsIPaymentActionResponse> response = do_QueryInterface(showResponse);
-        MOZ_ASSERT(response);
-        rv = RespondPayment(response);
+        rv = RespondPayment(showResponse.get());
         if (NS_WARN_IF(NS_FAILED(rv))) {
           return rv;
         }
       } else {
         rv = GetPaymentRequestById(requestId, getter_AddRefs(mShowingRequest));
         if (NS_WARN_IF(NS_FAILED(rv))) {
           return NS_ERROR_FAILURE;
         }
--- a/dom/payments/PaymentResponse.cpp
+++ b/dom/payments/PaymentResponse.cpp
@@ -131,17 +131,17 @@ PaymentResponse::GetShippingAddress() co
 already_AddRefed<Promise>
 PaymentResponse::Complete(PaymentComplete result, ErrorResult& aRv)
 {
   if (mCompleteCalled) {
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return nullptr;
   }
 
-  nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(mOwner);
+  nsIGlobalObject* global = mOwner->AsGlobal();
   ErrorResult errResult;
   RefPtr<Promise> promise = Promise::Create(global, errResult);
   if (errResult.Failed()) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
 
   mCompleteCalled = true;
--- a/dom/payments/ipc/PaymentRequestParent.cpp
+++ b/dom/payments/ipc/PaymentRequestParent.cpp
@@ -27,18 +27,16 @@ PaymentRequestParent::PaymentRequestPare
 
 mozilla::ipc::IPCResult
 PaymentRequestParent::RecvRequestPayment(const IPCPaymentActionRequest& aRequest)
 {
   if (!mActorAlive) {
     return IPC_FAIL_NO_REASON(this);
   }
   nsCOMPtr<nsIPaymentActionRequest> action;
-  nsCOMPtr<nsIPaymentActionCallback> callback = do_QueryInterface(this);
-  MOZ_ASSERT(callback);
   nsresult rv;
   switch (aRequest.type()) {
     case IPCPaymentActionRequest::TIPCPaymentCreateActionRequest: {
       const IPCPaymentCreateActionRequest& request = aRequest;
 
       nsCOMPtr<nsIMutableArray> methodData = do_CreateInstance(NS_ARRAY_CONTRACTID);
       MOZ_ASSERT(methodData);
       for (IPCPaymentMethodData data : request.methodData()) {
@@ -66,23 +64,23 @@ PaymentRequestParent::RecvRequestPayment
       }
 
       nsCOMPtr<nsIPaymentCreateActionRequest> createAction =
         do_CreateInstance(NS_PAYMENT_CREATE_ACTION_REQUEST_CONTRACT_ID);
       if (NS_WARN_IF(!createAction)) {
         return IPC_FAIL_NO_REASON(this);
       }
       rv = createAction->InitRequest(request.requestId(),
-                                     callback,
+                                     this,
                                      mTabId,
                                      request.topLevelPrincipal(),
                                      methodData,
                                      details,
                                      options,
-				     request.shippingOption());
+                                     request.shippingOption());
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return IPC_FAIL_NO_REASON(this);
       }
 
       action = do_QueryInterface(createAction);
       MOZ_ASSERT(action);
       break;
     }
@@ -116,17 +114,17 @@ PaymentRequestParent::RecvRequestPayment
       }
       break;
     }
     case IPCPaymentActionRequest::TIPCPaymentCompleteActionRequest: {
       const IPCPaymentCompleteActionRequest& request = aRequest;
       nsCOMPtr<nsIPaymentCompleteActionRequest> completeAction =
         do_CreateInstance(NS_PAYMENT_COMPLETE_ACTION_REQUEST_CONTRACT_ID);
       rv = completeAction->InitRequest(request.requestId(),
-                                       callback,
+                                       this,
                                        request.completeStatus());
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return IPC_FAIL_NO_REASON(this);
       }
       action = do_QueryInterface(completeAction);
       MOZ_ASSERT(action);
       break;
     }
@@ -137,19 +135,19 @@ PaymentRequestParent::RecvRequestPayment
       rv = payments::PaymentDetails::Create(request.details(), getter_AddRefs(details));
       if (NS_WARN_IF(NS_FAILED(rv))) {
         return IPC_FAIL_NO_REASON(this);
       }
 
       nsCOMPtr<nsIPaymentUpdateActionRequest> updateAction =
         do_CreateInstance(NS_PAYMENT_UPDATE_ACTION_REQUEST_CONTRACT_ID);
       rv = updateAction->InitRequest(request.requestId(),
-                                     callback,
+                                     this,
                                      details,
-				     request.shippingOption());
+                                     request.shippingOption());
       action = do_QueryInterface(updateAction);
       MOZ_ASSERT(action);
       break;
     }
     default: {
       return IPC_FAIL(this, "Unexpected request type");
     }
   }
@@ -162,18 +160,17 @@ PaymentRequestParent::RecvRequestPayment
   }
   return IPC_OK();
 }
 
 NS_IMETHODIMP
 PaymentRequestParent::RespondPayment(nsIPaymentActionResponse* aResponse)
 {
   if (!NS_IsMainThread()) {
-    nsCOMPtr<nsIPaymentActionCallback> self = do_QueryInterface(this);
-    MOZ_ASSERT(self);
+    nsCOMPtr<nsIPaymentActionCallback> self = this;
     nsCOMPtr<nsIPaymentActionResponse> response = aResponse;
     nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction("PaymentRequestParent::RespondPayment",
                                                      [self, response] ()
     {
       self->RespondPayment(response);
     });
     return NS_DispatchToMainThread(r);
   }
@@ -382,36 +379,32 @@ PaymentRequestParent::Recv__delete__()
 
 void
 PaymentRequestParent::ActorDestroy(ActorDestroyReason aWhy)
 {
   mActorAlive = false;
   nsCOMPtr<nsIPaymentRequestService> service =
     do_GetService(NS_PAYMENT_REQUEST_SERVICE_CONTRACT_ID);
   MOZ_ASSERT(service);
-  nsCOMPtr<nsIPaymentActionCallback> callback = do_QueryInterface(this);
-  MOZ_ASSERT(callback);
-  nsresult rv = service->RemoveActionCallback(callback);
+  nsresult rv = service->RemoveActionCallback(this);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     MOZ_ASSERT(false);
   }
 }
 
 nsresult
 PaymentRequestParent::CreateActionRequest(const nsAString& aRequestId,
                                           uint32_t aActionType,
                                           nsIPaymentActionRequest** aAction)
 {
   NS_ENSURE_ARG_POINTER(aAction);
   nsCOMPtr<nsIPaymentActionRequest> action =
     do_CreateInstance(NS_PAYMENT_ACTION_REQUEST_CONTRACT_ID);
   MOZ_ASSERT(action);
-  nsCOMPtr<nsIPaymentActionCallback> callback = do_QueryInterface(this);
-  MOZ_ASSERT(callback);
-  nsresult rv = action->Init(aRequestId, aActionType, callback);
+  nsresult rv = action->Init(aRequestId, aActionType, this);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
   action.forget(aAction);
   return NS_OK;
 }
 
 } // end of namespace dom