| 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 <memory> | 7 #include <memory> |
| 8 #include "bindings/core/v8/ScriptPromiseResolver.h" | 8 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 9 #include "core/dom/DOMArrayBuffer.h" | 9 #include "core/dom/DOMArrayBuffer.h" |
| 10 #include "core/dom/DOMArrayBufferView.h" | 10 #include "core/dom/DOMArrayBufferView.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 const String& id, | 149 const String& id, |
| 150 const KURL& url) | 150 const KURL& url) |
| 151 : ContextClient(frame), | 151 : ContextClient(frame), |
| 152 id_(id), | 152 id_(id), |
| 153 url_(url), | 153 url_(url), |
| 154 state_(WebPresentationConnectionState::kConnecting), | 154 state_(WebPresentationConnectionState::kConnecting), |
| 155 binary_type_(kBinaryTypeArrayBuffer), | 155 binary_type_(kBinaryTypeArrayBuffer), |
| 156 proxy_(nullptr) {} | 156 proxy_(nullptr) {} |
| 157 | 157 |
| 158 PresentationConnection::~PresentationConnection() { | 158 PresentationConnection::~PresentationConnection() { |
| 159 ASSERT(!blob_loader_); | 159 DCHECK(!blob_loader_); |
| 160 } | 160 } |
| 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 proxy_ = std::move(proxy); | 165 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 WebPresentationInfo& presentation_info, | 171 const WebPresentationInfo& presentation_info, |
| 172 PresentationRequest* request) { | 172 PresentationRequest* request) { |
| 173 ASSERT(resolver); | 173 DCHECK(resolver); |
| 174 ASSERT(request); | 174 DCHECK(request); |
| 175 ASSERT(resolver->GetExecutionContext()->IsDocument()); | 175 DCHECK(resolver->GetExecutionContext()->IsDocument()); |
| 176 | 176 |
| 177 Document* document = ToDocument(resolver->GetExecutionContext()); | 177 Document* document = ToDocument(resolver->GetExecutionContext()); |
| 178 if (!document->GetFrame()) | 178 if (!document->GetFrame()) |
| 179 return nullptr; | 179 return nullptr; |
| 180 | 180 |
| 181 PresentationController* controller = | 181 PresentationController* controller = |
| 182 PresentationController::From(*document->GetFrame()); | 182 PresentationController::From(*document->GetFrame()); |
| 183 if (!controller) | 183 if (!controller) |
| 184 return nullptr; | 184 return nullptr; |
| 185 | 185 |
| 186 return Take(controller, presentation_info, request); | 186 return Take(controller, presentation_info, 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 WebPresentationInfo& presentation_info, | 192 const WebPresentationInfo& presentation_info, |
| 193 PresentationRequest* request) { | 193 PresentationRequest* request) { |
| 194 ASSERT(controller); | 194 DCHECK(controller); |
| 195 ASSERT(request); | 195 DCHECK(request); |
| 196 | 196 |
| 197 PresentationConnection* connection = new PresentationConnection( | 197 PresentationConnection* connection = new PresentationConnection( |
| 198 controller->GetFrame(), presentation_info.id, presentation_info.url); | 198 controller->GetFrame(), presentation_info.id, presentation_info.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::kPresentation, request->GetExecutionContext()) | 204 TaskRunnerHelper::Get(TaskType::kPresentation, request->GetExecutionContext()) |
| 205 ->PostTask(BLINK_FROM_HERE, | 205 ->PostTask(BLINK_FROM_HERE, |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 ExceptionState& exception_state) { | 287 ExceptionState& exception_state) { |
| 288 DCHECK(array_buffer_view); | 288 DCHECK(array_buffer_view); |
| 289 if (!CanSendMessage(exception_state)) | 289 if (!CanSendMessage(exception_state)) |
| 290 return; | 290 return; |
| 291 | 291 |
| 292 messages_.push_back(new Message(array_buffer_view.View()->buffer())); | 292 messages_.push_back(new Message(array_buffer_view.View()->buffer())); |
| 293 HandleMessageQueue(); | 293 HandleMessageQueue(); |
| 294 } | 294 } |
| 295 | 295 |
| 296 void PresentationConnection::send(Blob* data, ExceptionState& exception_state) { | 296 void PresentationConnection::send(Blob* data, ExceptionState& exception_state) { |
| 297 ASSERT(data); | 297 DCHECK(data); |
| 298 if (!CanSendMessage(exception_state)) | 298 if (!CanSendMessage(exception_state)) |
| 299 return; | 299 return; |
| 300 | 300 |
| 301 messages_.push_back(new Message(data->GetBlobDataHandle())); | 301 messages_.push_back(new Message(data->GetBlobDataHandle())); |
| 302 HandleMessageQueue(); | 302 HandleMessageQueue(); |
| 303 } | 303 } |
| 304 | 304 |
| 305 bool PresentationConnection::CanSendMessage(ExceptionState& exception_state) { | 305 bool PresentationConnection::CanSendMessage(ExceptionState& exception_state) { |
| 306 if (state_ != WebPresentationConnectionState::kConnected) { | 306 if (state_ != WebPresentationConnectionState::kConnected) { |
| 307 ThrowPresentationDisconnectedError(exception_state); | 307 ThrowPresentationDisconnectedError(exception_state); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 325 messages_.pop_front(); | 325 messages_.pop_front(); |
| 326 break; | 326 break; |
| 327 case kMessageTypeArrayBuffer: | 327 case kMessageTypeArrayBuffer: |
| 328 client->SendArrayBuffer( | 328 client->SendArrayBuffer( |
| 329 url_, id_, | 329 url_, id_, |
| 330 static_cast<const uint8_t*>(message->array_buffer->Data()), | 330 static_cast<const uint8_t*>(message->array_buffer->Data()), |
| 331 message->array_buffer->ByteLength(), proxy_.get()); | 331 message->array_buffer->ByteLength(), proxy_.get()); |
| 332 messages_.pop_front(); | 332 messages_.pop_front(); |
| 333 break; | 333 break; |
| 334 case kMessageTypeBlob: | 334 case kMessageTypeBlob: |
| 335 ASSERT(!blob_loader_); | 335 DCHECK(!blob_loader_); |
| 336 blob_loader_ = new BlobLoader(message->blob_data_handle, this); | 336 blob_loader_ = new BlobLoader(message->blob_data_handle, this); |
| 337 break; | 337 break; |
| 338 } | 338 } |
| 339 } | 339 } |
| 340 } | 340 } |
| 341 | 341 |
| 342 String PresentationConnection::binaryType() const { | 342 String PresentationConnection::binaryType() const { |
| 343 switch (binary_type_) { | 343 switch (binary_type_) { |
| 344 case kBinaryTypeBlob: | 344 case kBinaryTypeBlob: |
| 345 return "blob"; | 345 return "blob"; |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 void PresentationConnection::TearDown() { | 518 void PresentationConnection::TearDown() { |
| 519 // Cancel current Blob loading if any. | 519 // Cancel current Blob loading if any. |
| 520 if (blob_loader_) { | 520 if (blob_loader_) { |
| 521 blob_loader_->Cancel(); | 521 blob_loader_->Cancel(); |
| 522 blob_loader_.Clear(); | 522 blob_loader_.Clear(); |
| 523 } | 523 } |
| 524 messages_.clear(); | 524 messages_.clear(); |
| 525 } | 525 } |
| 526 | 526 |
| 527 } // namespace blink | 527 } // namespace blink |
| OLD | NEW |