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

Unified Diff: Source/modules/navigatorconnect/ServicePort.cpp

Issue 1191393003: Update client side navigator.connect API to use ServicePortCollection [1/3] (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@serviceport
Patch Set: address more comments Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/modules/navigatorconnect/ServicePort.h ('k') | Source/modules/navigatorconnect/ServicePort.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/navigatorconnect/ServicePort.cpp
diff --git a/Source/modules/navigatorconnect/ServicePort.cpp b/Source/modules/navigatorconnect/ServicePort.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..49b95ca3cade80aba6da391717c3a47b48d2904a
--- /dev/null
+++ b/Source/modules/navigatorconnect/ServicePort.cpp
@@ -0,0 +1,86 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "modules/navigatorconnect/ServicePort.h"
+
+#include "bindings/core/v8/ScriptValue.h"
+#include "bindings/core/v8/SerializedScriptValueFactory.h"
+#include "core/dom/MessagePort.h"
+#include "modules/navigatorconnect/ServicePortCollection.h"
+#include "public/platform/Platform.h"
+#include "public/platform/modules/navigator_services/WebServicePortProvider.h"
+
+namespace blink {
+
+ServicePort* ServicePort::create(ServicePortCollection* collection, const WebServicePort& port)
+{
+ return new ServicePort(collection, port);
+}
+
+ServicePort::~ServicePort()
+{
+}
+
+String ServicePort::targetURL() const
+{
+ return m_port.targetUrl.string();
+}
+
+String ServicePort::name() const
+{
+ return m_port.name;
+}
+
+ScriptValue ServicePort::data(ScriptState* scriptState) const
+{
+ if (!m_serializedData)
+ return ScriptValue::createNull(scriptState);
+
+ return ScriptValue(scriptState, m_serializedData->deserialize(scriptState->isolate()));
+}
+
+void ServicePort::postMessage(ExecutionContext* executionContext, PassRefPtr<SerializedScriptValue> message, const MessagePortArray* ports, ExceptionState& exceptionState)
+{
+ OwnPtr<MessagePortChannelArray> channels;
+ if (ports) {
+ channels = MessagePort::disentanglePorts(executionContext, ports, exceptionState);
+ if (exceptionState.hadException())
+ return;
+ }
+
+ WebString messageString = message->toWireString();
+ OwnPtr<WebMessagePortChannelArray> webChannels = MessagePort::toWebMessagePortChannelArray(channels.release());
+ if (m_collection) {
+ WebServicePortProvider* provider = m_collection->provider();
+ provider->postMessage(m_port.id, messageString, webChannels.leakPtr());
+ }
+}
+
+void ServicePort::close()
+{
+ // TODO(mek): Figure out if this should throw instead of just quietly fail.
+ if (!m_isOpen)
+ return;
+
+ m_collection->closePort(this);
+ m_collection = nullptr;
+ m_isOpen = false;
+}
+
+DEFINE_TRACE(ServicePort)
+{
+ visitor->trace(m_collection);
+}
+
+ServicePort::ServicePort(ServicePortCollection* collection, const WebServicePort& port)
+ : m_isOpen(true), m_port(port), m_collection(collection)
+{
+ if (!m_port.data.isEmpty()) {
+ m_serializedData = SerializedScriptValueFactory::instance().createFromWire(m_port.data);
+ }
+}
+
+} // namespace blink
+
« no previous file with comments | « Source/modules/navigatorconnect/ServicePort.h ('k') | Source/modules/navigatorconnect/ServicePort.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698