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 "config.h" | 5 #include "config.h" |
6 #include "modules/navigatorconnect/ServicePortCollection.h" | 6 #include "modules/navigatorconnect/ServicePortCollection.h" |
7 | 7 |
8 #include "bindings/core/v8/ScriptPromiseResolver.h" | 8 #include "bindings/core/v8/ScriptPromiseResolver.h" |
9 #include "bindings/core/v8/SerializedScriptValueFactory.h" | 9 #include "bindings/core/v8/SerializedScriptValueFactory.h" |
10 #include "core/dom/DOMException.h" | 10 #include "core/dom/DOMException.h" |
11 #include "core/dom/ExceptionCode.h" | 11 #include "core/dom/ExceptionCode.h" |
12 #include "core/dom/MessagePort.h" | 12 #include "core/dom/MessagePort.h" |
13 #include "core/events/MessageEvent.h" | 13 #include "core/events/MessageEvent.h" |
14 #include "modules/EventTargetModules.h" | 14 #include "modules/EventTargetModules.h" |
| 15 #include "modules/navigatorconnect/AcceptConnectionObserver.h" |
15 #include "modules/navigatorconnect/ServicePort.h" | 16 #include "modules/navigatorconnect/ServicePort.h" |
| 17 #include "modules/navigatorconnect/ServicePortConnectEvent.h" |
| 18 #include "modules/navigatorconnect/ServicePortConnectEventInit.h" |
16 #include "modules/navigatorconnect/ServicePortConnectOptions.h" | 19 #include "modules/navigatorconnect/ServicePortConnectOptions.h" |
17 #include "public/platform/Platform.h" | 20 #include "public/platform/Platform.h" |
18 #include "public/platform/modules/navigator_services/WebServicePortProvider.h" | 21 #include "public/platform/modules/navigator_services/WebServicePortProvider.h" |
19 | 22 |
20 namespace blink { | 23 namespace blink { |
21 | 24 |
22 namespace { | 25 namespace { |
23 | 26 |
24 class ConnectCallbacks : public WebServicePortConnectCallbacks { | 27 class ConnectCallbacks : public WebServicePortConnectCallbacks { |
25 public: | 28 public: |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 (*channels)[i] = adoptPtr(webChannels[i]); | 142 (*channels)[i] = adoptPtr(webChannels[i]); |
140 } | 143 } |
141 RefPtr<SerializedScriptValue> message = SerializedScriptValueFactory::instan
ce().createFromWire(messageString); | 144 RefPtr<SerializedScriptValue> message = SerializedScriptValueFactory::instan
ce().createFromWire(messageString); |
142 | 145 |
143 OwnPtrWillBeRawPtr<MessagePortArray> ports = MessagePort::entanglePorts(*exe
cutionContext(), channels.release()); | 146 OwnPtrWillBeRawPtr<MessagePortArray> ports = MessagePort::entanglePorts(*exe
cutionContext(), channels.release()); |
144 RefPtrWillBeRawPtr<Event> evt = MessageEvent::create(ports.release(), messag
e.release()); | 147 RefPtrWillBeRawPtr<Event> evt = MessageEvent::create(ports.release(), messag
e.release()); |
145 // TODO(mek): Lookup ServicePort and set events source attribute. | 148 // TODO(mek): Lookup ServicePort and set events source attribute. |
146 dispatchEvent(evt.release(), ASSERT_NO_EXCEPTION); | 149 dispatchEvent(evt.release(), ASSERT_NO_EXCEPTION); |
147 } | 150 } |
148 | 151 |
| 152 void ServicePortCollection::dispatchConnectEvent(PassOwnPtr<WebServicePortConnec
tEventCallbacks> callbacks, const WebURL& targetURL, const WebString& origin, We
bServicePortID portID) |
| 153 { |
| 154 AcceptConnectionObserver* observer = AcceptConnectionObserver::create(this,
callbacks, portID, targetURL); |
| 155 ServicePortConnectEventInit init; |
| 156 init.setTargetURL(targetURL.string()); |
| 157 init.setOrigin(origin); |
| 158 RefPtrWillBeRawPtr<Event> event = ServicePortConnectEvent::create(EventTypeN
ames::connect, init, observer); |
| 159 dispatchEvent(event.release()); |
| 160 observer->didDispatchEvent(); |
| 161 } |
| 162 |
149 DEFINE_TRACE(ServicePortCollection) | 163 DEFINE_TRACE(ServicePortCollection) |
150 { | 164 { |
151 visitor->trace(m_ports); | 165 visitor->trace(m_ports); |
152 EventTargetWithInlineData::trace(visitor); | 166 EventTargetWithInlineData::trace(visitor); |
153 ContextLifecycleObserver::trace(visitor); | 167 ContextLifecycleObserver::trace(visitor); |
154 } | 168 } |
155 | 169 |
156 ServicePortCollection::ServicePortCollection(ExecutionContext* context) | 170 ServicePortCollection::ServicePortCollection(ExecutionContext* context) |
157 : ContextLifecycleObserver(context) | 171 : ContextLifecycleObserver(context) |
158 , m_provider(adoptPtr(Platform::current()->createServicePortProvider(this))) | 172 , m_provider(adoptPtr(Platform::current()->createServicePortProvider(this))) |
159 { | 173 { |
160 } | 174 } |
161 | 175 |
162 } // namespace blink | 176 } // namespace blink |
OLD | NEW |