Chromium Code Reviews| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 | 135 |
| 136 void cancel() { m_loader->cancel(); } | 136 void cancel() { m_loader->cancel(); } |
| 137 | 137 |
| 138 DEFINE_INLINE_TRACE() { visitor->trace(m_PresentationConnection); } | 138 DEFINE_INLINE_TRACE() { visitor->trace(m_PresentationConnection); } |
| 139 | 139 |
| 140 private: | 140 private: |
| 141 Member<PresentationConnection> m_PresentationConnection; | 141 Member<PresentationConnection> m_PresentationConnection; |
| 142 std::unique_ptr<FileReaderLoader> m_loader; | 142 std::unique_ptr<FileReaderLoader> m_loader; |
| 143 }; | 143 }; |
| 144 | 144 |
| 145 PresentationConnection::PresentationConnection(LocalFrame* frame, | 145 PresentationConnection::PresentationConnection( |
| 146 const String& id, | 146 LocalFrame* frame, |
| 147 const KURL& url) | 147 const String& id, |
| 148 const KURL& url, | |
| 149 std::unique_ptr<WebPresentationConnectionProxy> proxy) | |
| 148 : DOMWindowProperty(frame), | 150 : DOMWindowProperty(frame), |
| 149 m_id(id), | 151 m_id(id), |
| 150 m_url(url), | 152 m_url(url), |
| 151 m_state(WebPresentationConnectionState::Connected), | 153 m_state(WebPresentationConnectionState::Connected), |
| 152 m_binaryType(BinaryTypeBlob) {} | 154 m_binaryType(BinaryTypeBlob) { |
| 155 // proxy != nullptr if presentation connection is | |
|
mark a. foltz
2016/10/21 00:53:03
Can you wrap this comment at 80 columns?
zhaobin
2016/10/22 02:44:13
Done.
| |
| 156 // offscreen presentation connection (1-UA); | |
| 157 // proxy == nullptr in other cases. | |
| 158 if (!proxy) | |
|
mark a. foltz
2016/10/21 00:53:03
Since the proxy is optional, I have a slight prefe
zhaobin
2016/10/22 02:44:13
Done.
| |
| 159 return; | |
| 160 | |
| 161 m_proxy = std::move(proxy); | |
| 162 m_proxy->SetSourceConnection(this); | |
| 163 } | |
| 153 | 164 |
| 154 PresentationConnection::~PresentationConnection() { | 165 PresentationConnection::~PresentationConnection() { |
| 155 ASSERT(!m_blobLoader); | 166 ASSERT(!m_blobLoader); |
| 156 } | 167 } |
| 157 | 168 |
| 158 // static | 169 // static |
| 159 PresentationConnection* PresentationConnection::take( | 170 PresentationConnection* PresentationConnection::take( |
| 160 ScriptPromiseResolver* resolver, | 171 ScriptPromiseResolver* resolver, |
| 161 std::unique_ptr<WebPresentationConnectionClient> client, | 172 std::unique_ptr<WebPresentationConnectionClient> client, |
| 162 PresentationRequest* request) { | 173 PresentationRequest* request) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 178 } | 189 } |
| 179 | 190 |
| 180 // static | 191 // static |
| 181 PresentationConnection* PresentationConnection::take( | 192 PresentationConnection* PresentationConnection::take( |
| 182 PresentationController* controller, | 193 PresentationController* controller, |
| 183 std::unique_ptr<WebPresentationConnectionClient> client, | 194 std::unique_ptr<WebPresentationConnectionClient> client, |
| 184 PresentationRequest* request) { | 195 PresentationRequest* request) { |
| 185 ASSERT(controller); | 196 ASSERT(controller); |
| 186 ASSERT(request); | 197 ASSERT(request); |
| 187 | 198 |
| 188 PresentationConnection* connection = new PresentationConnection( | 199 PresentationConnection* connection = |
| 189 controller->frame(), client->getId(), client->getUrl()); | 200 new PresentationConnection(controller->frame(), client->getId(), |
| 201 client->getUrl(), client->getProxy()); | |
| 190 controller->registerConnection(connection); | 202 controller->registerConnection(connection); |
| 191 request->dispatchEvent(PresentationConnectionAvailableEvent::create( | 203 request->dispatchEvent(PresentationConnectionAvailableEvent::create( |
| 192 EventTypeNames::connectionavailable, connection)); | 204 EventTypeNames::connectionavailable, connection)); |
| 193 | 205 |
| 194 return connection; | 206 return connection; |
| 195 } | 207 } |
| 196 | 208 |
| 197 // static | 209 // static |
| 198 PresentationConnection* PresentationConnection::take( | 210 PresentationConnection* PresentationConnection::take( |
| 199 PresentationReceiver* receiver, | 211 PresentationReceiver* receiver, |
| 200 std::unique_ptr<WebPresentationConnectionClient> client) { | 212 std::unique_ptr<WebPresentationConnectionClient> client) { |
| 201 DCHECK(receiver); | 213 DCHECK(receiver); |
| 202 DCHECK(client); | 214 DCHECK(client); |
| 203 | 215 |
| 204 PresentationConnection* connection = new PresentationConnection( | 216 PresentationConnection* connection = new PresentationConnection( |
| 205 receiver->frame(), client->getId(), client->getUrl()); | 217 receiver->frame(), client->getId(), client->getUrl(), client->getProxy()); |
| 206 receiver->registerConnection(connection); | 218 receiver->registerConnection(connection); |
| 207 | 219 |
| 208 return connection; | 220 return connection; |
| 209 } | 221 } |
| 210 | 222 |
| 211 const AtomicString& PresentationConnection::interfaceName() const { | 223 const AtomicString& PresentationConnection::interfaceName() const { |
| 212 return EventTargetNames::PresentationConnection; | 224 return EventTargetNames::PresentationConnection; |
| 213 } | 225 } |
| 214 | 226 |
| 215 ExecutionContext* PresentationConnection::getExecutionContext() const { | 227 ExecutionContext* PresentationConnection::getExecutionContext() const { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 | 309 |
| 298 void PresentationConnection::handleMessageQueue() { | 310 void PresentationConnection::handleMessageQueue() { |
| 299 WebPresentationClient* client = presentationClient(getExecutionContext()); | 311 WebPresentationClient* client = presentationClient(getExecutionContext()); |
| 300 if (!client) | 312 if (!client) |
| 301 return; | 313 return; |
| 302 | 314 |
| 303 while (!m_messages.isEmpty() && !m_blobLoader) { | 315 while (!m_messages.isEmpty() && !m_blobLoader) { |
| 304 Message* message = m_messages.first().get(); | 316 Message* message = m_messages.first().get(); |
| 305 switch (message->type) { | 317 switch (message->type) { |
| 306 case MessageTypeText: | 318 case MessageTypeText: |
| 319 if (m_proxy) | |
| 320 m_proxy->SendString(message->text); | |
|
mark a. foltz
2016/10/21 00:53:03
Do we want to send the string to both |m_proxy| an
zhaobin
2016/10/22 02:44:14
Done.
| |
| 307 client->sendString(m_url, m_id, message->text); | 321 client->sendString(m_url, m_id, message->text); |
| 308 m_messages.removeFirst(); | 322 m_messages.removeFirst(); |
| 309 break; | 323 break; |
| 310 case MessageTypeArrayBuffer: | 324 case MessageTypeArrayBuffer: |
| 325 if (m_proxy) { | |
| 326 m_proxy->SendArrayBuffer( | |
|
mark a. foltz
2016/10/21 00:53:03
Same comment applies here.
zhaobin
2016/10/22 02:44:14
Done.
| |
| 327 static_cast<const uint8_t*>(message->arrayBuffer->data()), | |
| 328 message->arrayBuffer->byteLength()); | |
| 329 } | |
| 311 client->sendArrayBuffer(m_url, m_id, static_cast<const uint8_t*>( | 330 client->sendArrayBuffer(m_url, m_id, static_cast<const uint8_t*>( |
| 312 message->arrayBuffer->data()), | 331 message->arrayBuffer->data()), |
| 313 message->arrayBuffer->byteLength()); | 332 message->arrayBuffer->byteLength()); |
| 314 m_messages.removeFirst(); | 333 m_messages.removeFirst(); |
| 315 break; | 334 break; |
| 316 case MessageTypeBlob: | 335 case MessageTypeBlob: |
| 317 ASSERT(!m_blobLoader); | 336 ASSERT(!m_blobLoader); |
| 318 m_blobLoader = new BlobLoader(message->blobDataHandle, this); | 337 m_blobLoader = new BlobLoader(message->blobDataHandle, this); |
| 319 break; | 338 break; |
| 320 } | 339 } |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 337 m_binaryType = BinaryTypeBlob; | 356 m_binaryType = BinaryTypeBlob; |
| 338 return; | 357 return; |
| 339 } | 358 } |
| 340 if (binaryType == "arraybuffer") { | 359 if (binaryType == "arraybuffer") { |
| 341 m_binaryType = BinaryTypeArrayBuffer; | 360 m_binaryType = BinaryTypeArrayBuffer; |
| 342 return; | 361 return; |
| 343 } | 362 } |
| 344 ASSERT_NOT_REACHED(); | 363 ASSERT_NOT_REACHED(); |
| 345 } | 364 } |
| 346 | 365 |
| 347 void PresentationConnection::didReceiveTextMessage(const String& message) { | 366 void PresentationConnection::didReceiveTextMessage(const WebString& message) { |
| 348 if (m_state != WebPresentationConnectionState::Connected) | 367 if (m_state != WebPresentationConnectionState::Connected) |
| 349 return; | 368 return; |
| 350 | 369 |
| 351 dispatchEvent(MessageEvent::create(message)); | 370 dispatchEvent(MessageEvent::create(message)); |
| 352 } | 371 } |
| 353 | 372 |
| 354 void PresentationConnection::didReceiveBinaryMessage(const uint8_t* data, | 373 void PresentationConnection::didReceiveBinaryMessage(const uint8_t* data, |
| 355 size_t length) { | 374 size_t length) { |
| 356 if (m_state != WebPresentationConnectionState::Connected) | 375 if (m_state != WebPresentationConnectionState::Connected) |
| 357 return; | 376 return; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 458 void PresentationConnection::tearDown() { | 477 void PresentationConnection::tearDown() { |
| 459 // Cancel current Blob loading if any. | 478 // Cancel current Blob loading if any. |
| 460 if (m_blobLoader) { | 479 if (m_blobLoader) { |
| 461 m_blobLoader->cancel(); | 480 m_blobLoader->cancel(); |
| 462 m_blobLoader.clear(); | 481 m_blobLoader.clear(); |
| 463 } | 482 } |
| 464 m_messages.clear(); | 483 m_messages.clear(); |
| 465 } | 484 } |
| 466 | 485 |
| 467 } // namespace blink | 486 } // namespace blink |
| OLD | NEW |