[Payment Request] PaymentResponse should be a ContextDestructionObserver
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Oct 2018 19:37:17 +0000 (19:37 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 15 Oct 2018 19:37:17 +0000 (19:37 +0000)
https://bugs.webkit.org/show_bug.cgi?id=190558

Reviewed by Alex Christensen.

Make PaymentResponse a ContextDestructionObserver so it has a ScriptExecutionContext to
return for its override of EventTarget::scriptExecutionContext(). Do this instead of
downcasting m_request to an ActiveDOMObject to ask for its context.

* Modules/paymentrequest/PaymentRequest.cpp:
(WebCore::PaymentRequest::accept):
* Modules/paymentrequest/PaymentResponse.cpp:
(WebCore::PaymentResponse::PaymentResponse):
(WebCore::PaymentResponse::scriptExecutionContext const): Deleted.
* Modules/paymentrequest/PaymentResponse.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237133 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp
Source/WebCore/Modules/paymentrequest/PaymentResponse.cpp
Source/WebCore/Modules/paymentrequest/PaymentResponse.h

index 644abfd..f82117f 100644 (file)
@@ -1,5 +1,23 @@
 2018-10-15  Andy Estes  <aestes@apple.com>
 
+        [Payment Request] PaymentResponse should be a ContextDestructionObserver
+        https://bugs.webkit.org/show_bug.cgi?id=190558
+
+        Reviewed by Alex Christensen.
+
+        Make PaymentResponse a ContextDestructionObserver so it has a ScriptExecutionContext to
+        return for its override of EventTarget::scriptExecutionContext(). Do this instead of
+        downcasting m_request to an ActiveDOMObject to ask for its context.
+
+        * Modules/paymentrequest/PaymentRequest.cpp:
+        (WebCore::PaymentRequest::accept):
+        * Modules/paymentrequest/PaymentResponse.cpp:
+        (WebCore::PaymentResponse::PaymentResponse):
+        (WebCore::PaymentResponse::scriptExecutionContext const): Deleted.
+        * Modules/paymentrequest/PaymentResponse.h:
+
+2018-10-15  Andy Estes  <aestes@apple.com>
+
         [Payment Request] Use a PendingActivity token rather than calling (un)setPendingActivity
         https://bugs.webkit.org/show_bug.cgi?id=190557
 
index d9aac0c..88ee0bd 100644 (file)
@@ -681,7 +681,7 @@ void PaymentRequest::accept(const String& methodName, PaymentResponse::DetailsFu
 {
     ASSERT(m_state == State::Interactive);
 
-    auto response = PaymentResponse::create(*this, WTFMove(detailsFunction));
+    auto response = PaymentResponse::create(scriptExecutionContext(), *this, WTFMove(detailsFunction));
     response->setRequestId(m_details.id);
     response->setMethodName(methodName);
 
index 8287d7b..cf0ac4f 100644 (file)
@@ -34,8 +34,9 @@
 
 namespace WebCore {
 
-PaymentResponse::PaymentResponse(PaymentRequest& request, DetailsFunction&& detailsFunction)
-    : m_request { request }
+PaymentResponse::PaymentResponse(ScriptExecutionContext* context, PaymentRequest& request, DetailsFunction&& detailsFunction)
+    : ContextDestructionObserver { context }
+    , m_request { request }
     , m_detailsFunction { WTFMove(detailsFunction) }
 {
     ASSERT(m_detailsFunction);
@@ -61,11 +62,6 @@ void PaymentResponse::retry(PaymentValidationErrors&&, DOMPromiseDeferred<void>&
     promise.reject(Exception { NotSupportedError });
 }
 
-ScriptExecutionContext* PaymentResponse::scriptExecutionContext() const
-{
-    return static_cast<ActiveDOMObject&>(m_request.get()).scriptExecutionContext();
-}
-
 } // namespace WebCore
 
 #endif // ENABLE(PAYMENT_REQUEST)
index 449eff0..c365dfa 100644 (file)
@@ -27,6 +27,7 @@
 
 #if ENABLE(PAYMENT_REQUEST)
 
+#include "ContextDestructionObserver.h"
 #include "EventTarget.h"
 #include "JSDOMPromiseDeferred.h"
 #include "JSValueInWrappedObject.h"
@@ -39,13 +40,13 @@ class Document;
 class PaymentRequest;
 struct PaymentValidationErrors;
 
-class PaymentResponse final : public RefCounted<PaymentResponse>, public EventTargetWithInlineData {
+class PaymentResponse final : public ContextDestructionObserver, public EventTargetWithInlineData, public RefCounted<PaymentResponse> {
 public:
     using DetailsFunction = Function<JSC::Strong<JSC::JSObject>(JSC::ExecState&)>;
 
-    static Ref<PaymentResponse> create(PaymentRequest& request, DetailsFunction&& detailsFunction)
+    static Ref<PaymentResponse> create(ScriptExecutionContext* context, PaymentRequest& request, DetailsFunction&& detailsFunction)
     {
-        return adoptRef(*new PaymentResponse(request, WTFMove(detailsFunction)));
+        return adoptRef(*new PaymentResponse(context, request, WTFMove(detailsFunction)));
     }
 
     ~PaymentResponse();
@@ -81,11 +82,11 @@ public:
     using RefCounted<PaymentResponse>::deref;
 
 private:
-    PaymentResponse(PaymentRequest&, DetailsFunction&&);
+    PaymentResponse(ScriptExecutionContext*, PaymentRequest&, DetailsFunction&&);
 
     // EventTarget
     EventTargetInterface eventTargetInterface() const final { return PaymentResponseEventTargetInterfaceType; }
-    ScriptExecutionContext* scriptExecutionContext() const final;
+    ScriptExecutionContext* scriptExecutionContext() const final { return ContextDestructionObserver::scriptExecutionContext(); }
     void refEventTarget() final { ref(); }
     void derefEventTarget() final { deref(); }