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 10 : std::unique_ptr<protocol::DictionaryValue> ConsoleMessage::toValue() const
80 : {
81 10 : 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 10 : 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 10 : 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(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 3406 : DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend, bool fallThroughForNotFound)
162 : : DispatcherBase(frontendChannel)
163 : , m_backend(backend)
164 10218 : , m_fallThroughForNotFound(fallThroughForNotFound) {
165 10218 : m_dispatchMap["Console.enable"] = &DispatcherImpl::enable;
166 10218 : m_dispatchMap["Console.disable"] = &DispatcherImpl::disable;
167 10218 : m_dispatchMap["Console.clearMessages"] = &DispatcherImpl::clearMessages;
168 3406 : }
169 10218 : ~DispatcherImpl() override { }
170 : DispatchResponse::Status dispatch(int callId, const String& method, std::unique_ptr<protocol::DictionaryValue> messageObject) override;
171 : HashMap<String, String>& redirects() { return m_redirects; }
172 :
173 : protected:
174 : using CallHandler = DispatchResponse::Status (DispatcherImpl::*)(int callId, std::unique_ptr<DictionaryValue> messageObject, ErrorSupport* errors);
175 : using DispatchMap = protocol::HashMap<String, CallHandler>;
176 : DispatchMap m_dispatchMap;
177 : HashMap<String, String> m_redirects;
178 :
179 : DispatchResponse::Status enable(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
180 : DispatchResponse::Status disable(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
181 : DispatchResponse::Status clearMessages(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport*);
182 :
183 : Backend* m_backend;
184 : bool m_fallThroughForNotFound;
185 : };
186 :
187 5 : DispatchResponse::Status DispatcherImpl::dispatch(int callId, const String& method, std::unique_ptr<protocol::DictionaryValue> messageObject)
188 : {
189 : protocol::HashMap<String, CallHandler>::iterator it = m_dispatchMap.find(method);
190 5 : if (it == m_dispatchMap.end()) {
191 0 : if (m_fallThroughForNotFound)
192 : return DispatchResponse::kFallThrough;
193 0 : reportProtocolError(callId, DispatchResponse::kMethodNotFound, "'" + method + "' wasn't found", nullptr);
194 0 : return DispatchResponse::kError;
195 : }
196 :
197 5 : protocol::ErrorSupport errors;
198 15 : return (this->*(it->second))(callId, std::move(messageObject), &errors);
199 : }
200 :
201 :
202 5 : DispatchResponse::Status DispatcherImpl::enable(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
203 : {
204 :
205 5 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
206 5 : DispatchResponse response = m_backend->enable();
207 5 : if (response.status() == DispatchResponse::kFallThrough)
208 : return response.status();
209 5 : if (weak->get())
210 5 : weak->get()->sendResponse(callId, response);
211 5 : return response.status();
212 : }
213 :
214 0 : DispatchResponse::Status DispatcherImpl::disable(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
215 : {
216 :
217 0 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
218 0 : DispatchResponse response = m_backend->disable();
219 0 : if (response.status() == DispatchResponse::kFallThrough)
220 : return response.status();
221 0 : if (weak->get())
222 0 : weak->get()->sendResponse(callId, response);
223 0 : return response.status();
224 : }
225 :
226 0 : DispatchResponse::Status DispatcherImpl::clearMessages(int callId, std::unique_ptr<DictionaryValue> requestMessageObject, ErrorSupport* errors)
227 : {
228 :
229 0 : std::unique_ptr<DispatcherBase::WeakPtr> weak = weakPtr();
230 0 : DispatchResponse response = m_backend->clearMessages();
231 0 : if (response.status() == DispatchResponse::kFallThrough)
232 : return response.status();
233 0 : if (weak->get())
234 0 : weak->get()->sendResponse(callId, response);
235 0 : return response.status();
236 : }
237 :
238 : // static
239 3406 : void Dispatcher::wire(UberDispatcher* uber, Backend* backend)
240 : {
241 3406 : std::unique_ptr<DispatcherImpl> dispatcher(new DispatcherImpl(uber->channel(), backend, uber->fallThroughForNotFound()));
242 3406 : uber->setupRedirects(dispatcher->redirects());
243 10218 : uber->registerBackend("Console", std::move(dispatcher));
244 3406 : }
245 :
246 : } // Console
247 : } // namespace v8_inspector
248 : } // namespace protocol
|