Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 #include "modules/navigatorconnect/ServicePort.h" | |
| 7 | |
| 8 #include "bindings/core/v8/ScriptValue.h" | |
| 9 #include "bindings/core/v8/SerializedScriptValueFactory.h" | |
| 10 #include "core/dom/MessagePort.h" | |
| 11 #include "modules/navigatorconnect/ServicePortCollection.h" | |
| 12 #include "public/platform/Platform.h" | |
| 13 #include "public/platform/modules/navigator_services/WebServicePortProvider.h" | |
| 14 | |
| 15 namespace blink { | |
| 16 | |
| 17 ServicePort* ServicePort::create(ServicePortCollection* collection, const WebSer vicePort& port) | |
| 18 { | |
| 19 return new ServicePort(collection, port); | |
| 20 } | |
| 21 | |
| 22 ServicePort::~ServicePort() | |
| 23 { | |
| 24 } | |
| 25 | |
| 26 String ServicePort::targetURL() const | |
| 27 { | |
| 28 return m_port.targetUrl.string(); | |
| 29 } | |
| 30 | |
| 31 String ServicePort::name() const | |
| 32 { | |
| 33 return m_port.name; | |
| 34 } | |
| 35 | |
| 36 ScriptValue ServicePort::data(ScriptState* scriptState) const | |
| 37 { | |
| 38 if (!m_serializedData) | |
| 39 return ScriptValue::createNull(scriptState); | |
| 40 | |
| 41 return ScriptValue(scriptState, m_serializedData->deserialize(scriptState->i solate())); | |
|
haraken
2015/06/25 01:21:40
binding team: desrialize should take a ScriptState
| |
| 42 } | |
| 43 | |
| 44 void ServicePort::postMessage(ExecutionContext* executionContext, PassRefPtr<Ser ializedScriptValue> message, const MessagePortArray* ports, ExceptionState& exce ptionState) | |
| 45 { | |
| 46 OwnPtr<MessagePortChannelArray> channels; | |
| 47 if (ports) { | |
| 48 channels = MessagePort::disentanglePorts(executionContext, ports, except ionState); | |
| 49 if (exceptionState.hadException()) | |
| 50 return; | |
| 51 } | |
| 52 | |
| 53 WebString messageString = message->toWireString(); | |
| 54 OwnPtr<WebMessagePortChannelArray> webChannels = MessagePort::toWebMessagePo rtChannelArray(channels.release()); | |
| 55 if (m_collection) { | |
| 56 WebServicePortProvider* provider = m_collection->provider(); | |
| 57 provider->postMessage(m_port.id, messageString, webChannels.leakPtr()); | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 void ServicePort::close() | |
| 62 { | |
| 63 // TODO(mek): Figure out if this should throw instead of just quietly fail. | |
| 64 if (!m_isOpen) | |
| 65 return; | |
| 66 | |
| 67 if (m_collection) { | |
|
haraken
2015/06/25 01:21:40
This null check won't be needed.
Marijn Kruisselbrink
2015/06/25 02:18:55
Done
| |
| 68 m_collection->closePort(this); | |
| 69 m_collection = nullptr; | |
| 70 } | |
| 71 m_isOpen = false; | |
| 72 } | |
| 73 | |
| 74 DEFINE_TRACE(ServicePort) | |
| 75 { | |
| 76 visitor->trace(m_collection); | |
| 77 } | |
| 78 | |
| 79 ServicePort::ServicePort(ServicePortCollection* collection, const WebServicePort & port) | |
| 80 : m_isOpen(true), m_port(port), m_collection(collection) | |
| 81 { | |
| 82 if (!m_port.data.isEmpty()) { | |
| 83 m_serializedData = SerializedScriptValueFactory::instance().createFromWi re(m_port.data); | |
| 84 } | |
| 85 } | |
| 86 | |
| 87 } // namespace blink | |
| 88 | |
| OLD | NEW |