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