Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: third_party/WebKit/Source/modules/presentation/PresentationReceiver.cpp

Issue 2340433003: [Presentation API] 1-UA: notify receiver page when receiver connection becomes available (blink sid… (Closed)
Patch Set: resolve code review comments from dcheng Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/PresentationReceiver.h" 5 #include "modules/presentation/PresentationReceiver.h"
6 6
7 #include "bindings/core/v8/ScriptPromise.h" 7 #include "bindings/core/v8/ScriptPromise.h"
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 "core/dom/Document.h" 10 #include "core/dom/Document.h"
11 #include "core/dom/ExceptionCode.h" 11 #include "core/dom/ExceptionCode.h"
12 #include "core/frame/LocalFrame.h" 12 #include "core/frame/LocalFrame.h"
13 #include "modules/presentation/PresentationConnection.h" 13 #include "modules/presentation/PresentationConnection.h"
14 #include "modules/presentation/PresentationConnectionList.h" 14 #include "modules/presentation/PresentationConnectionList.h"
15 #include "public/platform/modules/presentation/WebPresentationClient.h"
15 16
16 namespace blink { 17 namespace blink {
17 18
18 PresentationReceiver::PresentationReceiver(LocalFrame* frame) 19 PresentationReceiver::PresentationReceiver(LocalFrame* frame, WebPresentationCli ent* client)
19 : DOMWindowProperty(frame) 20 : DOMWindowProperty(frame)
20 { 21 {
21 m_connectionList = new PresentationConnectionList(frame->document()); 22 m_connectionList = new PresentationConnectionList(frame->document());
23
24 if (client)
25 client->setReceiver(this);
22 } 26 }
23 27
24 ScriptPromise PresentationReceiver::connectionList(ScriptState* scriptState) 28 ScriptPromise PresentationReceiver::connectionList(ScriptState* scriptState)
25 { 29 {
26 if (!m_connectionListProperty) 30 if (!m_connectionListProperty)
27 m_connectionListProperty = new ConnectionListProperty(scriptState->getEx ecutionContext(), this, ConnectionListProperty::Ready); 31 m_connectionListProperty = new ConnectionListProperty(scriptState->getEx ecutionContext(), this, ConnectionListProperty::Ready);
28 32
29 if (!m_connectionList->isEmpty() && m_connectionListProperty->getState() == ScriptPromisePropertyBase::Pending) 33 if (!m_connectionList->isEmpty() && m_connectionListProperty->getState() == ScriptPromisePropertyBase::Pending)
30 m_connectionListProperty->resolve(m_connectionList); 34 m_connectionListProperty->resolve(m_connectionList);
31 35
32 return m_connectionListProperty->promise(scriptState->world()); 36 return m_connectionListProperty->promise(scriptState->world());
33 } 37 }
34 38
35 void PresentationReceiver::onConnectionReceived(WebPresentationConnectionClient* connectionClient) 39 void PresentationReceiver::onReceiverConnectionAvailable(WebPresentationConnecti onClient* connectionClient)
36 { 40 {
37 DCHECK(connectionClient); 41 DCHECK(connectionClient);
38 // take() will call PresentationReceiver::registerConnection() 42 // take() will call PresentationReceiver::registerConnection()
39 // and register the connection. 43 // and register the connection.
40 auto connection = PresentationConnection::take(this, wrapUnique(connectionCl ient)); 44 auto connection = PresentationConnection::take(this, wrapUnique(connectionCl ient));
41 45
42 // receiver.connectionList property not accessed 46 // receiver.connectionList property not accessed
43 if (!m_connectionListProperty) 47 if (!m_connectionListProperty)
44 return; 48 return;
45 49
46 if (m_connectionListProperty->getState() == ScriptPromisePropertyBase::Pendi ng) 50 if (m_connectionListProperty->getState() == ScriptPromisePropertyBase::Pendi ng)
47 m_connectionListProperty->resolve(m_connectionList); 51 m_connectionListProperty->resolve(m_connectionList);
48 else if (m_connectionListProperty->getState() == ScriptPromisePropertyBase:: Resolved) 52 else if (m_connectionListProperty->getState() == ScriptPromisePropertyBase:: Resolved)
49 m_connectionList->dispatchConnectionAvailableEvent(connection); 53 m_connectionList->dispatchConnectionAvailableEvent(connection);
50 } 54 }
51 55
52 void PresentationReceiver::registerConnection(PresentationConnection* connection ) 56 void PresentationReceiver::registerConnection(PresentationConnection* connection )
53 { 57 {
54 DCHECK(m_connectionList); 58 DCHECK(m_connectionList);
55 m_connectionList->addConnection(connection); 59 m_connectionList->addConnection(connection);
56 } 60 }
57 61
58 DEFINE_TRACE(PresentationReceiver) 62 DEFINE_TRACE(PresentationReceiver)
59 { 63 {
60 visitor->trace(m_connectionList); 64 visitor->trace(m_connectionList);
61 visitor->trace(m_connectionListProperty); 65 visitor->trace(m_connectionListProperty);
62 DOMWindowProperty::trace(visitor); 66 DOMWindowProperty::trace(visitor);
63 } 67 }
64 } // namespace blink 68 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698