| 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/AcceptConnectionObserver.h" |
| 16 #include "modules/navigatorconnect/ServicePort.h" | 16 #include "modules/navigatorconnect/ServicePort.h" |
| 17 #include "modules/navigatorconnect/ServicePortConnectEvent.h" | 17 #include "modules/navigatorconnect/ServicePortConnectEvent.h" |
| 18 #include "modules/navigatorconnect/ServicePortConnectEventInit.h" | 18 #include "modules/navigatorconnect/ServicePortConnectEventInit.h" |
| 19 #include "modules/navigatorconnect/ServicePortConnectOptions.h" | 19 #include "modules/navigatorconnect/ServicePortConnectOptions.h" |
| 20 #include "public/platform/Platform.h" | 20 #include "public/platform/Platform.h" |
| 21 #include "public/platform/modules/navigator_services/WebServicePortProvider.h" | 21 #include "public/platform/modules/navigator_services/WebServicePortProvider.h" |
| 22 | 22 |
| 23 namespace blink { | 23 namespace blink { |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 class ConnectCallbacks : public WebServicePortConnectCallbacks { | 27 class ConnectCallbacks : public WebServicePortConnectCallbacks { |
| 28 public: | 28 public: |
| 29 ConnectCallbacks(PassRefPtrWillBeRawPtr<ScriptPromiseResolver> resolver, Ser
vicePortCollection* collection, const KURL& targetUrl, const String& portName, c
onst String& serializedPortData) | 29 ConnectCallbacks(ScriptPromiseResolver* resolver, ServicePortCollection* col
lection, const KURL& targetUrl, const String& portName, const String& serialized
PortData) |
| 30 : m_resolver(resolver), m_collection(collection), m_targetUrl(targetUrl)
, m_portName(portName), m_serializedPortData(serializedPortData) | 30 : m_resolver(resolver), m_collection(collection), m_targetUrl(targetUrl)
, m_portName(portName), m_serializedPortData(serializedPortData) |
| 31 { | 31 { |
| 32 ASSERT(m_resolver); | 32 ASSERT(m_resolver); |
| 33 } | 33 } |
| 34 | 34 |
| 35 ~ConnectCallbacks() override { } | 35 ~ConnectCallbacks() override { } |
| 36 | 36 |
| 37 void onSuccess(WebServicePortID* portIdRaw) override | 37 void onSuccess(WebServicePortID* portIdRaw) override |
| 38 { | 38 { |
| 39 OwnPtr<WebServicePortID> webPortId = adoptPtr(portIdRaw); | 39 OwnPtr<WebServicePortID> webPortId = adoptPtr(portIdRaw); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 53 void onError() override | 53 void onError() override |
| 54 { | 54 { |
| 55 // TODO(mek): Pass actual error code back. | 55 // TODO(mek): Pass actual error code back. |
| 56 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) { | 56 if (!m_resolver->executionContext() || m_resolver->executionContext()->a
ctiveDOMObjectsAreStopped()) { |
| 57 return; | 57 return; |
| 58 } | 58 } |
| 59 m_resolver->reject(DOMException::create(AbortError)); | 59 m_resolver->reject(DOMException::create(AbortError)); |
| 60 } | 60 } |
| 61 | 61 |
| 62 private: | 62 private: |
| 63 RefPtrWillBePersistent<ScriptPromiseResolver> m_resolver; | 63 Persistent<ScriptPromiseResolver> m_resolver; |
| 64 Persistent<ServicePortCollection> m_collection; | 64 Persistent<ServicePortCollection> m_collection; |
| 65 KURL m_targetUrl; | 65 KURL m_targetUrl; |
| 66 String m_portName; | 66 String m_portName; |
| 67 String m_serializedPortData; | 67 String m_serializedPortData; |
| 68 | 68 |
| 69 WTF_MAKE_NONCOPYABLE(ConnectCallbacks); | 69 WTF_MAKE_NONCOPYABLE(ConnectCallbacks); |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 } // namespace | 72 } // namespace |
| 73 | 73 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 96 { | 96 { |
| 97 if (!m_provider) | 97 if (!m_provider) |
| 98 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); | 98 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::
create(NotSupportedError)); |
| 99 | 99 |
| 100 RefPtr<SerializedScriptValue> portData; | 100 RefPtr<SerializedScriptValue> portData; |
| 101 if (options.hasData()) { | 101 if (options.hasData()) { |
| 102 portData = SerializedScriptValueFactory::instance().create(options.data(
).isolate(), options.data(), nullptr, exceptionState); | 102 portData = SerializedScriptValueFactory::instance().create(options.data(
).isolate(), options.data(), nullptr, exceptionState); |
| 103 if (exceptionState.hadException()) | 103 if (exceptionState.hadException()) |
| 104 return exceptionState.reject(scriptState); | 104 return exceptionState.reject(scriptState); |
| 105 } | 105 } |
| 106 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::
create(scriptState); | 106 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 107 ScriptPromise promise = resolver->promise(); | 107 ScriptPromise promise = resolver->promise(); |
| 108 KURL targetUrl = scriptState->executionContext()->completeURL(url); | 108 KURL targetUrl = scriptState->executionContext()->completeURL(url); |
| 109 m_provider->connect( | 109 m_provider->connect( |
| 110 targetUrl, | 110 targetUrl, |
| 111 scriptState->executionContext()->securityOrigin()->toString(), | 111 scriptState->executionContext()->securityOrigin()->toString(), |
| 112 new ConnectCallbacks(resolver, this, targetUrl, options.name(), portData
? portData->toWireString() : String())); | 112 new ConnectCallbacks(resolver, this, targetUrl, options.name(), portData
? portData->toWireString() : String())); |
| 113 return promise; | 113 return promise; |
| 114 } | 114 } |
| 115 | 115 |
| 116 ScriptPromise ServicePortCollection::match(ScriptState* scriptState, const Servi
cePortMatchOptions& options) | 116 ScriptPromise ServicePortCollection::match(ScriptState* scriptState, const Servi
cePortMatchOptions& options) |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 ContextLifecycleObserver::trace(visitor); | 167 ContextLifecycleObserver::trace(visitor); |
| 168 } | 168 } |
| 169 | 169 |
| 170 ServicePortCollection::ServicePortCollection(ExecutionContext* context) | 170 ServicePortCollection::ServicePortCollection(ExecutionContext* context) |
| 171 : ContextLifecycleObserver(context) | 171 : ContextLifecycleObserver(context) |
| 172 , m_provider(adoptPtr(Platform::current()->createServicePortProvider(this))) | 172 , m_provider(adoptPtr(Platform::current()->createServicePortProvider(this))) |
| 173 { | 173 { |
| 174 } | 174 } |
| 175 | 175 |
| 176 } // namespace blink | 176 } // namespace blink |
| OLD | NEW |