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

Side by Side 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 unified diff | Download patch
OLDNEW
(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()));
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 m_collection->closePort(this);
68 m_collection = nullptr;
69 m_isOpen = false;
70 }
71
72 DEFINE_TRACE(ServicePort)
73 {
74 visitor->trace(m_collection);
75 }
76
77 ServicePort::ServicePort(ServicePortCollection* collection, const WebServicePort & port)
78 : m_isOpen(true), m_port(port), m_collection(collection)
79 {
80 if (!m_port.data.isEmpty()) {
81 m_serializedData = SerializedScriptValueFactory::instance().createFromWi re(m_port.data);
82 }
83 }
84
85 } // namespace blink
86
OLDNEW
« 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