| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/PresentationConnection.h" | 5 #include "modules/presentation/PresentationConnection.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptPromiseResolver.h" | 7 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 8 #include "core/dom/DOMArrayBuffer.h" | 8 #include "core/dom/DOMArrayBuffer.h" |
| 9 #include "core/dom/DOMArrayBufferView.h" | 9 #include "core/dom/DOMArrayBufferView.h" |
| 10 #include "core/dom/Document.h" | 10 #include "core/dom/Document.h" |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 | 161 |
| 162 void PresentationConnection::bindProxy( | 162 void PresentationConnection::bindProxy( |
| 163 std::unique_ptr<WebPresentationConnectionProxy> proxy) { | 163 std::unique_ptr<WebPresentationConnectionProxy> proxy) { |
| 164 DCHECK(proxy); | 164 DCHECK(proxy); |
| 165 m_proxy = std::move(proxy); | 165 m_proxy = std::move(proxy); |
| 166 } | 166 } |
| 167 | 167 |
| 168 // static | 168 // static |
| 169 PresentationConnection* PresentationConnection::take( | 169 PresentationConnection* PresentationConnection::take( |
| 170 ScriptPromiseResolver* resolver, | 170 ScriptPromiseResolver* resolver, |
| 171 const WebPresentationSessionInfo& sessionInfo, | 171 const WebPresentationInfo& presentationInfo, |
| 172 PresentationRequest* request) { | 172 PresentationRequest* request) { |
| 173 ASSERT(resolver); | 173 ASSERT(resolver); |
| 174 ASSERT(request); | 174 ASSERT(request); |
| 175 ASSERT(resolver->getExecutionContext()->isDocument()); | 175 ASSERT(resolver->getExecutionContext()->isDocument()); |
| 176 | 176 |
| 177 Document* document = toDocument(resolver->getExecutionContext()); | 177 Document* document = toDocument(resolver->getExecutionContext()); |
| 178 if (!document->frame()) | 178 if (!document->frame()) |
| 179 return nullptr; | 179 return nullptr; |
| 180 | 180 |
| 181 PresentationController* controller = | 181 PresentationController* controller = |
| 182 PresentationController::from(*document->frame()); | 182 PresentationController::from(*document->frame()); |
| 183 if (!controller) | 183 if (!controller) |
| 184 return nullptr; | 184 return nullptr; |
| 185 | 185 |
| 186 return take(controller, sessionInfo, request); | 186 return take(controller, presentationInfo, request); |
| 187 } | 187 } |
| 188 | 188 |
| 189 // static | 189 // static |
| 190 PresentationConnection* PresentationConnection::take( | 190 PresentationConnection* PresentationConnection::take( |
| 191 PresentationController* controller, | 191 PresentationController* controller, |
| 192 const WebPresentationSessionInfo& sessionInfo, | 192 const WebPresentationInfo& presentationInfo, |
| 193 PresentationRequest* request) { | 193 PresentationRequest* request) { |
| 194 ASSERT(controller); | 194 ASSERT(controller); |
| 195 ASSERT(request); | 195 ASSERT(request); |
| 196 | 196 |
| 197 PresentationConnection* connection = new PresentationConnection( | 197 PresentationConnection* connection = new PresentationConnection( |
| 198 controller->frame(), sessionInfo.id, sessionInfo.url); | 198 controller->frame(), presentationInfo.id, presentationInfo.url); |
| 199 controller->registerConnection(connection); | 199 controller->registerConnection(connection); |
| 200 | 200 |
| 201 // Fire onconnectionavailable event asynchronously. | 201 // Fire onconnectionavailable event asynchronously. |
| 202 auto* event = PresentationConnectionAvailableEvent::create( | 202 auto* event = PresentationConnectionAvailableEvent::create( |
| 203 EventTypeNames::connectionavailable, connection); | 203 EventTypeNames::connectionavailable, connection); |
| 204 TaskRunnerHelper::get(TaskType::Presentation, request->getExecutionContext()) | 204 TaskRunnerHelper::get(TaskType::Presentation, request->getExecutionContext()) |
| 205 ->postTask(BLINK_FROM_HERE, | 205 ->postTask(BLINK_FROM_HERE, |
| 206 WTF::bind(&PresentationConnection::dispatchEventAsync, | 206 WTF::bind(&PresentationConnection::dispatchEventAsync, |
| 207 wrapPersistent(request), wrapPersistent(event))); | 207 wrapPersistent(request), wrapPersistent(event))); |
| 208 | 208 |
| 209 return connection; | 209 return connection; |
| 210 } | 210 } |
| 211 | 211 |
| 212 // static | 212 // static |
| 213 PresentationConnection* PresentationConnection::take( | 213 PresentationConnection* PresentationConnection::take( |
| 214 PresentationReceiver* receiver, | 214 PresentationReceiver* receiver, |
| 215 const WebPresentationSessionInfo& sessionInfo) { | 215 const WebPresentationInfo& presentationInfo) { |
| 216 DCHECK(receiver); | 216 DCHECK(receiver); |
| 217 | 217 |
| 218 PresentationConnection* connection = new PresentationConnection( | 218 PresentationConnection* connection = new PresentationConnection( |
| 219 receiver->frame(), sessionInfo.id, sessionInfo.url); | 219 receiver->frame(), presentationInfo.id, presentationInfo.url); |
| 220 receiver->registerConnection(connection); | 220 receiver->registerConnection(connection); |
| 221 | 221 |
| 222 return connection; | 222 return connection; |
| 223 } | 223 } |
| 224 | 224 |
| 225 const AtomicString& PresentationConnection::interfaceName() const { | 225 const AtomicString& PresentationConnection::interfaceName() const { |
| 226 return EventTargetNames::PresentationConnection; | 226 return EventTargetNames::PresentationConnection; |
| 227 } | 227 } |
| 228 | 228 |
| 229 ExecutionContext* PresentationConnection::getExecutionContext() const { | 229 ExecutionContext* PresentationConnection::getExecutionContext() const { |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 return m_state; | 392 return m_state; |
| 393 } | 393 } |
| 394 | 394 |
| 395 void PresentationConnection::close() { | 395 void PresentationConnection::close() { |
| 396 if (m_state != WebPresentationConnectionState::Connecting && | 396 if (m_state != WebPresentationConnectionState::Connecting && |
| 397 m_state != WebPresentationConnectionState::Connected) { | 397 m_state != WebPresentationConnectionState::Connected) { |
| 398 return; | 398 return; |
| 399 } | 399 } |
| 400 WebPresentationClient* client = presentationClient(getExecutionContext()); | 400 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 401 if (client) | 401 if (client) |
| 402 client->closeSession(m_url, m_id, m_proxy.get()); | 402 client->closeConnection(m_url, m_id, m_proxy.get()); |
| 403 | 403 |
| 404 tearDown(); | 404 tearDown(); |
| 405 } | 405 } |
| 406 | 406 |
| 407 void PresentationConnection::terminate() { | 407 void PresentationConnection::terminate() { |
| 408 if (m_state != WebPresentationConnectionState::Connected) | 408 if (m_state != WebPresentationConnectionState::Connected) |
| 409 return; | 409 return; |
| 410 WebPresentationClient* client = presentationClient(getExecutionContext()); | 410 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 411 if (client) | 411 if (client) |
| 412 client->terminateConnection(m_url, m_id); | 412 client->terminatePresentation(m_url, m_id); |
| 413 | 413 |
| 414 tearDown(); | 414 tearDown(); |
| 415 } | 415 } |
| 416 | 416 |
| 417 bool PresentationConnection::matches( | 417 bool PresentationConnection::matches( |
| 418 const WebPresentationSessionInfo& sessionInfo) const { | 418 const WebPresentationInfo& presentationInfo) const { |
| 419 return m_url == KURL(sessionInfo.url) && m_id == String(sessionInfo.id); | 419 return m_url == KURL(presentationInfo.url) && |
| 420 m_id == String(presentationInfo.id); |
| 420 } | 421 } |
| 421 | 422 |
| 422 bool PresentationConnection::matches(const String& id, const KURL& url) const { | 423 bool PresentationConnection::matches(const String& id, const KURL& url) const { |
| 423 return m_url == url && m_id == id; | 424 return m_url == url && m_id == id; |
| 424 } | 425 } |
| 425 | 426 |
| 426 void PresentationConnection::didChangeState( | 427 void PresentationConnection::didChangeState( |
| 427 WebPresentationConnectionState state) { | 428 WebPresentationConnectionState state) { |
| 428 didChangeState(state, true /* shouldDispatchEvent */); | 429 didChangeState(state, true /* shouldDispatchEvent */); |
| 429 } | 430 } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 void PresentationConnection::tearDown() { | 517 void PresentationConnection::tearDown() { |
| 517 // Cancel current Blob loading if any. | 518 // Cancel current Blob loading if any. |
| 518 if (m_blobLoader) { | 519 if (m_blobLoader) { |
| 519 m_blobLoader->cancel(); | 520 m_blobLoader->cancel(); |
| 520 m_blobLoader.clear(); | 521 m_blobLoader.clear(); |
| 521 } | 522 } |
| 522 m_messages.clear(); | 523 m_messages.clear(); |
| 523 } | 524 } |
| 524 | 525 |
| 525 } // namespace blink | 526 } // namespace blink |
| OLD | NEW |