| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/presentation/PresentationConnectionCallbacks.h" | 5 #include "modules/presentation/PresentationConnectionCallbacks.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include "bindings/core/v8/ScriptPromiseResolver.h" | 8 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 9 #include "core/dom/DOMException.h" | 9 #include "core/dom/DOMException.h" |
| 10 #include "modules/presentation/PresentationConnection.h" | 10 #include "modules/presentation/PresentationConnection.h" |
| 11 #include "modules/presentation/PresentationError.h" | 11 #include "modules/presentation/PresentationError.h" |
| 12 #include "modules/presentation/PresentationRequest.h" | 12 #include "modules/presentation/PresentationRequest.h" |
| 13 #include "platform/wtf/PtrUtil.h" | 13 #include "platform/wtf/PtrUtil.h" |
| 14 #include "public/platform/modules/presentation/WebPresentationError.h" | 14 #include "public/platform/modules/presentation/WebPresentationError.h" |
| 15 | 15 |
| 16 namespace blink { | 16 namespace blink { |
| 17 | 17 |
| 18 PresentationConnectionCallbacks::PresentationConnectionCallbacks( | 18 PresentationConnectionCallbacks::PresentationConnectionCallbacks( |
| 19 ScriptPromiseResolver* resolver, | 19 ScriptPromiseResolver* resolver, |
| 20 PresentationRequest* request) | 20 PresentationRequest* request) |
| 21 : resolver_(resolver), request_(request), connection_(nullptr) { | 21 : resolver_(resolver), request_(request), connection_(nullptr) { |
| 22 ASSERT(resolver_); | 22 DCHECK(resolver_); |
| 23 ASSERT(request_); | 23 DCHECK(request_); |
| 24 } | 24 } |
| 25 | 25 |
| 26 void PresentationConnectionCallbacks::OnSuccess( | 26 void PresentationConnectionCallbacks::OnSuccess( |
| 27 const WebPresentationInfo& presentation_info) { | 27 const WebPresentationInfo& presentation_info) { |
| 28 if (!resolver_->GetExecutionContext() || | 28 if (!resolver_->GetExecutionContext() || |
| 29 resolver_->GetExecutionContext()->IsContextDestroyed()) { | 29 resolver_->GetExecutionContext()->IsContextDestroyed()) { |
| 30 return; | 30 return; |
| 31 } | 31 } |
| 32 | 32 |
| 33 connection_ = PresentationConnection::Take(resolver_.Get(), presentation_info, | 33 connection_ = PresentationConnection::Take(resolver_.Get(), presentation_info, |
| 34 request_); | 34 request_); |
| 35 resolver_->Resolve(connection_); | 35 resolver_->Resolve(connection_); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void PresentationConnectionCallbacks::OnError( | 38 void PresentationConnectionCallbacks::OnError( |
| 39 const WebPresentationError& error) { | 39 const WebPresentationError& error) { |
| 40 if (!resolver_->GetExecutionContext() || | 40 if (!resolver_->GetExecutionContext() || |
| 41 resolver_->GetExecutionContext()->IsContextDestroyed()) { | 41 resolver_->GetExecutionContext()->IsContextDestroyed()) { |
| 42 return; | 42 return; |
| 43 } | 43 } |
| 44 resolver_->Reject(PresentationError::Take(error)); | 44 resolver_->Reject(PresentationError::Take(error)); |
| 45 connection_ = nullptr; | 45 connection_ = nullptr; |
| 46 } | 46 } |
| 47 | 47 |
| 48 WebPresentationConnection* PresentationConnectionCallbacks::GetConnection() { | 48 WebPresentationConnection* PresentationConnectionCallbacks::GetConnection() { |
| 49 return connection_ ? connection_.Get() : nullptr; | 49 return connection_ ? connection_.Get() : nullptr; |
| 50 } | 50 } |
| 51 | 51 |
| 52 } // namespace blink | 52 } // namespace blink |
| OLD | NEW |