Line data Source code
1 : // This file is generated by TypeBuilder_cpp.template.
2 :
3 : // Copyright (c) 2016 The Chromium Authors. All rights reserved.
4 : // Use of this source code is governed by a BSD-style license that can be
5 : // found in the LICENSE file.
6 :
7 : #include "src/inspector/protocol/Console.h"
8 :
9 : #include "src/inspector/protocol/Protocol.h"
10 :
11 : namespace v8_inspector {
12 : namespace protocol {
13 : namespace Console {
14 :
15 : // ------------- Enum values from types.
16 :
17 : const char Metainfo::domainName[] = "Console";
18 : const char Metainfo::commandPrefix[] = "Console.";
19 : const char Metainfo::version[] = "1.3";
20 :
21 : const char* ConsoleMessage::SourceEnum::Xml = "xml";
22 : const char* ConsoleMessage::SourceEnum::Javascript = "javascript";
23 : const char* ConsoleMessage::SourceEnum::Network = "network";
24 : const char* ConsoleMessage::SourceEnum::ConsoleApi = "console-api";
25 : const char* ConsoleMessage::SourceEnum::Storage = "storage";
26 : const char* ConsoleMessage::SourceEnum::Appcache = "appcache";
27 : const char* ConsoleMessage::SourceEnum::Rendering = "rendering";
28 : const char* ConsoleMessage::SourceEnum::Security = "security";
29 : const char* ConsoleMessage::SourceEnum::Other = "other";
30 : const char* ConsoleMessage::SourceEnum::Deprecation = "deprecation";
31 : const char* ConsoleMessage::SourceEnum::Worker = "worker";
32 :
33 : const char* ConsoleMessage::LevelEnum::Log = "log";
34 : const char* ConsoleMessage::LevelEnum::Warning = "warning";
35 : const char* ConsoleMessage::LevelEnum::Error = "error";
36 : const char* ConsoleMessage::LevelEnum::Debug = "debug";
37 : const char* ConsoleMessage::LevelEnum::Info = "info";
38 :
39 0 : std::unique_ptr<ConsoleMessage> ConsoleMessage::fromValue(protocol::Value* value, ErrorSupport* errors)
40 : {
41 0 : if (!value || value->type() != protocol::Value::TypeObject) {
42 0 : errors->addError("object expected");
43 : return nullptr;
44 : }
45 :
46 0 : std::unique_ptr<ConsoleMessage> result(new ConsoleMessage());
47 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
48 0 : errors->push();
49 0 : protocol::Value* sourceValue = object->get("source");
50 0 : errors->setName("source");
51 0 : result->m_source = ValueConversions<String>::fromValue(sourceValue, errors);
52 0 : protocol::Value* levelValue = object->get("level");
53 0 : errors->setName("level");
54 0 : result->m_level = ValueConversions<String>::fromValue(levelValue, errors);
55 0 : protocol::Value* textValue = object->get("text");
56 0 : errors->setName("text");
57 0 : result->m_text = ValueConversions<String>::fromValue(textValue, errors);
58 0 : protocol::Value* urlValue = object->get("url");
59 0 : if (urlValue) {
60 0 : errors->setName("url");
61 0 : result->m_url = ValueConversions<String>::fromValue(urlValue, errors);
62 : }
63 0 : protocol::Value* lineValue = object->get("line");
64 0 : if (lineValue) {
65 0 : errors->setName("line");
66 0 : result->m_line = ValueConversions<int>::fromValue(lineValue, errors);
67 : }
68 0 : protocol::Value* columnValue = object->get("column");
69 0 : if (columnValue) {
70 0 : errors->setName("column");
71 0 : result->m_column = ValueConversions<int>::fromValue(columnValue, errors);
72 : }
73 0 : errors->pop();
74 0 : if (errors->hasErrors())
75 : return nullptr;
76 : return result;
77 : }
78 :
79 10 : std::unique_ptr<protocol::DictionaryValue> ConsoleMessage::toValue() const
80 : {
81 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
82 50 : result->setValue("source", ValueConversions<String>::toValue(m_source));
83 50 : result->setValue("level", ValueConversions<String>::toValue(m_level));
84 50 : result->setValue("text", ValueConversions<String>::toValue(m_text));
85 10 : if (m_url.isJust())
86 50 : result->setValue("url", ValueConversions<String>::toValue(m_url.fromJust()));
87 10 : if (m_line.isJust())
88 40 : result->setValue("line", ValueConversions<int>::toValue(m_line.fromJust()));
89 10 : if (m_column.isJust())
90 40 : result->setValue("column", ValueConversions<int>::toValue(m_column.fromJust()));
91 10 : return result;
92 : }
93 :
94 0 : std::unique_ptr<ConsoleMessage> ConsoleMessage::clone() const
95 : {
96 0 : ErrorSupport errors;
97 0 : return fromValue(toValue().get(), &errors);
98 : }
99 :
100 0 : std::unique_ptr<MessageAddedNotification> MessageAddedNotification::fromValue(protocol::Value* value, ErrorSupport* errors)
101 : {
102 0 : if (!value || value->type() != protocol::Value::TypeObject) {
103 0 : errors->addError("object expected");
104 : return nullptr;
105 : }
106 :
107 0 : std::unique_ptr<MessageAddedNotification> result(new MessageAddedNotification());
108 : protocol::DictionaryValue* object = DictionaryValue::cast(value);
109 0 : errors->push();
110 0 : protocol::Value* messageValue = object->get("message");
111 0 : errors->setName("message");
112 0 : result->m_message = ValueConversions<protocol::Console::ConsoleMessage>::fromValue(messageValue, errors);
113 0 : errors->pop();
114 0 : if (errors->hasErrors())
115 : return nullptr;
116 : return result;
117 : }
118 :
119 10 : std::unique_ptr<protocol::DictionaryValue> MessageAddedNotification::toValue() const
120 : {
121 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
122 40 : result->setValue("message", ValueConversions<protocol::Console::ConsoleMessage>::toValue(m_message.get()));
123 10 : return result;
124 : }
125 :
126 0 : std::unique_ptr<MessageAddedNotification> MessageAddedNotification::clone() const
127 : {
128 0 : ErrorSupport errors;
129 0 : return fromValue(toValue().get(), &errors);
130 : }
131 :
132 : // ------------- Enum values from params.
133 :
134 :
135 : // ------------- Frontend notifications.
136 :
137 10 : void Frontend::messageAdded(std::unique_ptr<protocol::Console::ConsoleMessage> message)
138 : {
139 10 : if (!m_frontendChannel)
140 : return;
141 : std::unique_ptr<MessageAddedNotification> messageData = MessageAddedNotification::create()
142 : .setMessage(std::move(message))
143 : .build();
144 70 : m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("Console.messageAdded", std::move(messageData)));
145 : }
146 :
147 10 : void Frontend::flush()
148 : {
149 10 : m_frontendChannel->flushProtocolNotifications();
150 10 : }
151 :
152 0 : void Frontend::sendRawNotification(String notification)
153 : {
154 0 : m_frontendChannel->sendProtocolNotification(InternalRawNotification::fromJSON(std::move(notification)));
155 0 : }
156 :
157 0 : void Frontend::sendRawNotification(std::vector<uint8_t> notification)
158 : {
159 0 : m_frontendChannel->sendProtocolNotification(InternalRawNotification::fromBinary(std::move(notification)));
160 0 : }
161 :
162 : // --------------------- Dispatcher.
163 :
164 : class DispatcherImpl : public protocol::DispatcherBase {
165 : public:
166 3879 : DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend)
167 : : DispatcherBase(frontendChannel)
168 7758 : , m_backend(backend) {
169 11637 : m_dispatchMap["Console.clearMessages"] = &DispatcherImpl::clearMessages;
170 11637 : m_dispatchMap["Console.disable"] = &DispatcherImpl::disable;
171 11637 : m_dispatchMap["Console.enable"] = &DispatcherImpl::enable;
172 3879 : }
173 11637 : ~DispatcherImpl() override { }
174 : bool canDispatch(const String& method) override;
175 : void dispatch(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<protocol::DictionaryValue> messageObject) override;
176 3879 : std::unordered_map<String, String>& redirects() { return m_redirects; }
177 :
178 : protected:
179 : using CallHandler = void (DispatcherImpl::*)(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> messageObject, ErrorSupport* errors);
180 : using DispatchMap = std::unordered_map<String, CallHandler>;
181 : DispatchMap m_dispatchMap;
182 : std::unordered_map<String, String> m_redirects;
183 :
184 : void clearMessages(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
185 : void disable(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
186 : void enable(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
187 :
188 : Backend* m_backend;
189 : };
190 :
191 5 : bool DispatcherImpl::canDispatch(const String& method) {
192 5 : return m_dispatchMap.find(method) != m_dispatchMap.end();
193 : }
194 :
195 5 : void DispatcherImpl::dispatch(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<protocol::DictionaryValue> messageObject)
196 : {
197 : std::unordered_map<String, CallHandler>::iterator it = m_dispatchMap.find(method);
198 : DCHECK(it != m_dispatchMap.end());
199 10 : protocol::ErrorSupport errors;
200 15 : (this->*(it->second))(callId, method, message, std::move(messageObject), &errors);
201 5 : }
202 :
203 :
204 0 : void DispatcherImpl::clearMessages(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
205 : {
206 :
207 0 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
208 0 : DispatchResponse response = m_backend->clearMessages();
209 0 : if (response.status() == DispatchResponse::kFallThrough) {
210 0 : channel()->fallThrough(callId, method, message);
211 0 : return;
212 : }
213 0 : if (weak->get())
214 0 : weak->get()->sendResponse(callId, response);
215 : return;
216 : }
217 :
218 0 : void DispatcherImpl::disable(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
219 : {
220 :
221 0 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
222 0 : DispatchResponse response = m_backend->disable();
223 0 : if (response.status() == DispatchResponse::kFallThrough) {
224 0 : channel()->fallThrough(callId, method, message);
225 0 : return;
226 : }
227 0 : if (weak->get())
228 0 : weak->get()->sendResponse(callId, response);
229 : return;
230 : }
231 :
232 5 : void DispatcherImpl::enable(int callId, const String& method, const ProtocolMessage& message, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
233 : {
234 :
235 10 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
236 5 : DispatchResponse response = m_backend->enable();
237 5 : if (response.status() == DispatchResponse::kFallThrough) {
238 0 : channel()->fallThrough(callId, method, message);
239 0 : return;
240 : }
241 5 : if (weak->get())
242 5 : weak->get()->sendResponse(callId, response);
243 : return;
244 : }
245 :
246 : // static
247 3879 : void Dispatcher::wire(UberDispatcher* uber, Backend* backend)
248 : {
249 3879 : std::unique_ptr<DispatcherImpl> dispatcher(new DispatcherImpl(uber->channel(), backend));
250 3879 : uber->setupRedirects(dispatcher->redirects());
251 11637 : uber->registerBackend("Console", std::move(dispatcher));
252 3879 : }
253 :
254 : } // Console
255 : } // namespace v8_inspector
256 : } // namespace protocol
|