Line data Source code
1 : // This file is generated
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.2";
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 12 : std::unique_ptr<protocol::DictionaryValue> ConsoleMessage::toValue() const
80 : {
81 12 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
82 60 : result->setValue("source", ValueConversions<String>::toValue(m_source));
83 60 : result->setValue("level", ValueConversions<String>::toValue(m_level));
84 60 : result->setValue("text", ValueConversions<String>::toValue(m_text));
85 12 : if (m_url.isJust())
86 60 : result->setValue("url", ValueConversions<String>::toValue(m_url.fromJust()));
87 12 : if (m_line.isJust())
88 48 : result->setValue("line", ValueConversions<int>::toValue(m_line.fromJust()));
89 12 : if (m_column.isJust())
90 48 : result->setValue("column", ValueConversions<int>::toValue(m_column.fromJust()));
91 12 : 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 12 : std::unique_ptr<protocol::DictionaryValue> MessageAddedNotification::toValue() const
120 : {
121 12 : std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create();
122 48 : result->setValue("message", ValueConversions<protocol::Console::ConsoleMessage>::toValue(m_message.get()));
123 12 : 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 12 : void Frontend::messageAdded(std::unique_ptr<protocol::Console::ConsoleMessage> message)
138 : {
139 12 : if (!m_frontendChannel)
140 12 : return;
141 : std::unique_ptr<MessageAddedNotification> messageData = MessageAddedNotification::create()
142 : .setMessage(std::move(message))
143 : .build();
144 84 : m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("Console.messageAdded", std::move(messageData)));
145 : }
146 :
147 12 : void Frontend::flush()
148 : {
149 12 : m_frontendChannel->flushProtocolNotifications();
150 12 : }
151 :
152 0 : void Frontend::sendRawNotification(const String& notification)
153 : {
154 0 : m_frontendChannel->sendProtocolNotification(InternalRawNotification::create(notification));
155 0 : }
156 :
157 : // --------------------- Dispatcher.
158 :
159 : class DispatcherImpl : public protocol::DispatcherBase {
160 : public:
161 4573 : DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend, bool fallThroughForNotFound)
162 : : DispatcherBase(frontendChannel)
163 : , m_backend(backend)
164 9146 : , m_fallThroughForNotFound(fallThroughForNotFound) {
165 13719 : m_dispatchMap["Console.enable"] = &DispatcherImpl::enable;
166 13719 : m_dispatchMap["Console.disable"] = &DispatcherImpl::disable;
167 13719 : m_dispatchMap["Console.clearMessages"] = &DispatcherImpl::clearMessages;
168 4573 : }
169 13719 : ~DispatcherImpl() override { }
170 : DispatchResponse::Status dispatch(int callId, const String& method, std::unique_ptr<protocol::DictionaryValue> messageObject) override;
171 :
172 : protected:
173 : using CallHandler = DispatchResponse::Status (DispatcherImpl::*)(int callId, std::unique_ptr<DictionaryValue> messageObject, ErrorSupport* errors);
174 : using DispatchMap = protocol::HashMap<String, CallHandler>;
175 : DispatchMap m_dispatchMap;
176 :
177 : DispatchResponse::Status enable(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
178 : DispatchResponse::Status disable(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
179 : DispatchResponse::Status clearMessages(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
180 :
181 : Backend* m_backend;
182 : bool m_fallThroughForNotFound;
183 : };
184 :
185 6 : DispatchResponse::Status DispatcherImpl::dispatch(int callId, const String& method, std::unique_ptr<protocol::DictionaryValue> messageObject)
186 : {
187 : protocol::HashMap<String, CallHandler>::iterator it = m_dispatchMap.find(method);
188 6 : if (it == m_dispatchMap.end()) {
189 0 : if (m_fallThroughForNotFound)
190 : return DispatchResponse::kFallThrough;
191 0 : reportProtocolError(callId, DispatchResponse::kMethodNotFound, "'" + method + "' wasn't found", nullptr);
192 0 : return DispatchResponse::kError;
193 : }
194 :
195 6 : protocol::ErrorSupport errors;
196 18 : return (this->*(it->second))(callId, std::move(messageObject), &errors);
197 : }
198 :
199 :
200 6 : DispatchResponse::Status DispatcherImpl::enable(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
201 : {
202 :
203 6 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
204 6 : DispatchResponse response = m_backend->enable();
205 6 : if (weak->get())
206 6 : weak->get()->sendResponse(callId, response);
207 12 : return response.status();
208 : }
209 :
210 0 : DispatchResponse::Status DispatcherImpl::disable(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
211 : {
212 :
213 0 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
214 0 : DispatchResponse response = m_backend->disable();
215 0 : if (weak->get())
216 0 : weak->get()->sendResponse(callId, response);
217 0 : return response.status();
218 : }
219 :
220 0 : DispatchResponse::Status DispatcherImpl::clearMessages(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
221 : {
222 :
223 0 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
224 0 : DispatchResponse response = m_backend->clearMessages();
225 0 : if (weak->get())
226 0 : weak->get()->sendResponse(callId, response);
227 0 : return response.status();
228 : }
229 :
230 : // static
231 4573 : void Dispatcher::wire(UberDispatcher* dispatcher, Backend* backend)
232 : {
233 18292 : dispatcher->registerBackend("Console", std::unique_ptr<protocol::DispatcherBase>(new DispatcherImpl(dispatcher->channel(), backend, dispatcher->fallThroughForNotFound())));
234 4573 : }
235 :
236 : } // Console
237 : } // namespace v8_inspector
238 : } // namespace protocol
|