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 "modules/navigatorconnect/ServicePortCollection.h" | 5 #include "modules/navigatorconnect/ServicePortCollection.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptPromiseResolver.h" | 7 #include "bindings/core/v8/ScriptPromiseResolver.h" |
8 #include "bindings/core/v8/SerializedScriptValueFactory.h" | 8 #include "bindings/core/v8/SerializedScriptValueFactory.h" |
9 #include "core/dom/DOMException.h" | 9 #include "core/dom/DOMException.h" |
10 #include "core/dom/ExceptionCode.h" | 10 #include "core/dom/ExceptionCode.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 ConnectCallbacks(ScriptPromiseResolver* resolver, ServicePortCollection* col
lection, const KURL& targetUrl, const String& portName, const String& serialized
PortData) | 28 ConnectCallbacks(ScriptPromiseResolver* resolver, ServicePortCollection* col
lection, const KURL& targetUrl, const String& portName, const String& serialized
PortData) |
29 : m_resolver(resolver), m_collection(collection), m_targetUrl(targetUrl)
, m_portName(portName), m_serializedPortData(serializedPortData) | 29 : m_resolver(resolver), m_collection(collection), m_targetUrl(targetUrl)
, m_portName(portName), m_serializedPortData(serializedPortData) |
30 { | 30 { |
31 ASSERT(m_resolver); | 31 ASSERT(m_resolver); |
32 } | 32 } |
33 | 33 |
34 ~ConnectCallbacks() override { } | 34 ~ConnectCallbacks() override { } |
35 | 35 |
36 void onSuccess(WebServicePortID portId) override | 36 void onSuccess(WebServicePortID portId) override |
37 { | 37 { |
38 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) { | 38 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex
t()->activeDOMObjectsAreStopped()) { |
39 return; | 39 return; |
40 } | 40 } |
41 WebServicePort webPort; | 41 WebServicePort webPort; |
42 webPort.id = portId; | 42 webPort.id = portId; |
43 webPort.targetUrl = m_targetUrl; | 43 webPort.targetUrl = m_targetUrl; |
44 webPort.name = m_portName; | 44 webPort.name = m_portName; |
45 webPort.data = m_serializedPortData; | 45 webPort.data = m_serializedPortData; |
46 ServicePort* port = ServicePort::create(m_collection, webPort); | 46 ServicePort* port = ServicePort::create(m_collection, webPort); |
47 m_collection->addPort(port); | 47 m_collection->addPort(port); |
48 m_resolver->resolve(port); | 48 m_resolver->resolve(port); |
49 } | 49 } |
50 | 50 |
51 void onError() override | 51 void onError() override |
52 { | 52 { |
53 // TODO(mek): Pass actual error code back. | 53 // TODO(mek): Pass actual error code back. |
54 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) { | 54 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex
t()->activeDOMObjectsAreStopped()) { |
55 return; | 55 return; |
56 } | 56 } |
57 m_resolver->reject(DOMException::create(AbortError)); | 57 m_resolver->reject(DOMException::create(AbortError)); |
58 } | 58 } |
59 | 59 |
60 private: | 60 private: |
61 Persistent<ScriptPromiseResolver> m_resolver; | 61 Persistent<ScriptPromiseResolver> m_resolver; |
62 Persistent<ServicePortCollection> m_collection; | 62 Persistent<ServicePortCollection> m_collection; |
63 KURL m_targetUrl; | 63 KURL m_targetUrl; |
64 String m_portName; | 64 String m_portName; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); | 96 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); |
97 | 97 |
98 RefPtr<SerializedScriptValue> portData; | 98 RefPtr<SerializedScriptValue> portData; |
99 if (options.hasData()) { | 99 if (options.hasData()) { |
100 portData = SerializedScriptValueFactory::instance().create(options.data(
).isolate(), options.data(), nullptr, exceptionState); | 100 portData = SerializedScriptValueFactory::instance().create(options.data(
).isolate(), options.data(), nullptr, exceptionState); |
101 if (exceptionState.hadException()) | 101 if (exceptionState.hadException()) |
102 return exceptionState.reject(scriptState); | 102 return exceptionState.reject(scriptState); |
103 } | 103 } |
104 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 104 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
105 ScriptPromise promise = resolver->promise(); | 105 ScriptPromise promise = resolver->promise(); |
106 KURL targetUrl = scriptState->executionContext()->completeURL(url); | 106 KURL targetUrl = scriptState->getExecutionContext()->completeURL(url); |
107 m_provider->connect( | 107 m_provider->connect( |
108 targetUrl, | 108 targetUrl, |
109 scriptState->executionContext()->securityOrigin()->toString(), | 109 scriptState->getExecutionContext()->getSecurityOrigin()->toString(), |
110 new ConnectCallbacks(resolver, this, targetUrl, options.name(), portData
? portData->toWireString() : String())); | 110 new ConnectCallbacks(resolver, this, targetUrl, options.name(), portData
? portData->toWireString() : String())); |
111 return promise; | 111 return promise; |
112 } | 112 } |
113 | 113 |
114 ScriptPromise ServicePortCollection::match(ScriptState* scriptState, const Servi
cePortMatchOptions& options) | 114 ScriptPromise ServicePortCollection::match(ScriptState* scriptState, const Servi
cePortMatchOptions& options) |
115 { | 115 { |
116 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea
te(NotSupportedError)); | 116 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea
te(NotSupportedError)); |
117 } | 117 } |
118 | 118 |
119 ScriptPromise ServicePortCollection::matchAll(ScriptState* scriptState, const Se
rvicePortMatchOptions& options) | 119 ScriptPromise ServicePortCollection::matchAll(ScriptState* scriptState, const Se
rvicePortMatchOptions& options) |
120 { | 120 { |
121 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea
te(NotSupportedError)); | 121 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea
te(NotSupportedError)); |
122 } | 122 } |
123 | 123 |
124 const AtomicString& ServicePortCollection::interfaceName() const | 124 const AtomicString& ServicePortCollection::interfaceName() const |
125 { | 125 { |
126 return EventTargetNames::ServicePortCollection; | 126 return EventTargetNames::ServicePortCollection; |
127 } | 127 } |
128 | 128 |
129 ExecutionContext* ServicePortCollection::executionContext() const | 129 ExecutionContext* ServicePortCollection::getExecutionContext() const |
130 { | 130 { |
131 return ContextLifecycleObserver::executionContext(); | 131 return ContextLifecycleObserver::getExecutionContext(); |
132 } | 132 } |
133 | 133 |
134 void ServicePortCollection::postMessage(WebServicePortID portId, const WebString
& messageString, const WebMessagePortChannelArray& webChannels) | 134 void ServicePortCollection::postMessage(WebServicePortID portId, const WebString
& messageString, const WebMessagePortChannelArray& webChannels) |
135 { | 135 { |
136 OwnPtr<MessagePortChannelArray> channels; | 136 OwnPtr<MessagePortChannelArray> channels; |
137 if (webChannels.size()) { | 137 if (webChannels.size()) { |
138 channels = adoptPtr(new MessagePortChannelArray(webChannels.size())); | 138 channels = adoptPtr(new MessagePortChannelArray(webChannels.size())); |
139 for (size_t i = 0; i < webChannels.size(); ++i) | 139 for (size_t i = 0; i < webChannels.size(); ++i) |
140 (*channels)[i] = adoptPtr(webChannels[i]); | 140 (*channels)[i] = adoptPtr(webChannels[i]); |
141 } | 141 } |
142 RefPtr<SerializedScriptValue> message = SerializedScriptValueFactory::instan
ce().createFromWire(messageString); | 142 RefPtr<SerializedScriptValue> message = SerializedScriptValueFactory::instan
ce().createFromWire(messageString); |
143 | 143 |
144 MessagePortArray* ports = MessagePort::entanglePorts(*executionContext(), ch
annels.release()); | 144 MessagePortArray* ports = MessagePort::entanglePorts(*getExecutionContext(),
channels.release()); |
145 RefPtrWillBeRawPtr<Event> evt = MessageEvent::create(ports, message.release(
)); | 145 RefPtrWillBeRawPtr<Event> evt = MessageEvent::create(ports, message.release(
)); |
146 // TODO(mek): Lookup ServicePort and set events source attribute. | 146 // TODO(mek): Lookup ServicePort and set events source attribute. |
147 dispatchEvent(evt.release()); | 147 dispatchEvent(evt.release()); |
148 } | 148 } |
149 | 149 |
150 void ServicePortCollection::dispatchConnectEvent(PassOwnPtr<WebServicePortConnec
tEventCallbacks> callbacks, const WebURL& targetURL, const WebString& origin, We
bServicePortID portID) | 150 void ServicePortCollection::dispatchConnectEvent(PassOwnPtr<WebServicePortConnec
tEventCallbacks> callbacks, const WebURL& targetURL, const WebString& origin, We
bServicePortID portID) |
151 { | 151 { |
152 AcceptConnectionObserver* observer = AcceptConnectionObserver::create(this,
callbacks, portID, targetURL); | 152 AcceptConnectionObserver* observer = AcceptConnectionObserver::create(this,
callbacks, portID, targetURL); |
153 ServicePortConnectEventInit init; | 153 ServicePortConnectEventInit init; |
154 init.setTargetURL(targetURL.string()); | 154 init.setTargetURL(targetURL.string()); |
(...skipping 10 matching lines...) Expand all Loading... |
165 ContextLifecycleObserver::trace(visitor); | 165 ContextLifecycleObserver::trace(visitor); |
166 } | 166 } |
167 | 167 |
168 ServicePortCollection::ServicePortCollection(ExecutionContext* context) | 168 ServicePortCollection::ServicePortCollection(ExecutionContext* context) |
169 : ContextLifecycleObserver(context) | 169 : ContextLifecycleObserver(context) |
170 , m_provider(adoptPtr(Platform::current()->createServicePortProvider(this))) | 170 , m_provider(adoptPtr(Platform::current()->createServicePortProvider(this))) |
171 { | 171 { |
172 } | 172 } |
173 | 173 |
174 } // namespace blink | 174 } // namespace blink |
OLD | NEW |