// This file is generated // Copyright (c) 2016 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "components/ui_devtools/Overlay.h" #include "components/ui_devtools/Protocol.h" namespace ui_devtools { namespace protocol { namespace Overlay { // ------------- Enum values from types. const char Metainfo::domainName[] = "Overlay"; const char Metainfo::commandPrefix[] = "Overlay."; const char Metainfo::version[] = "1.0"; std::unique_ptr HighlightConfig::fromValue(protocol::Value* value, ErrorSupport* errors) { if (!value || value->type() != protocol::Value::TypeObject) { errors->addError("object expected"); return nullptr; } std::unique_ptr result(new HighlightConfig()); protocol::DictionaryValue* object = DictionaryValue::cast(value); errors->push(); protocol::Value* showInfoValue = object->get("showInfo"); if (showInfoValue) { errors->setName("showInfo"); result->m_showInfo = ValueConversions::fromValue(showInfoValue, errors); } protocol::Value* showRulersValue = object->get("showRulers"); if (showRulersValue) { errors->setName("showRulers"); result->m_showRulers = ValueConversions::fromValue(showRulersValue, errors); } protocol::Value* showExtensionLinesValue = object->get("showExtensionLines"); if (showExtensionLinesValue) { errors->setName("showExtensionLines"); result->m_showExtensionLines = ValueConversions::fromValue(showExtensionLinesValue, errors); } protocol::Value* displayAsMaterialValue = object->get("displayAsMaterial"); if (displayAsMaterialValue) { errors->setName("displayAsMaterial"); result->m_displayAsMaterial = ValueConversions::fromValue(displayAsMaterialValue, errors); } protocol::Value* contentColorValue = object->get("contentColor"); if (contentColorValue) { errors->setName("contentColor"); result->m_contentColor = ValueConversions::fromValue(contentColorValue, errors); } protocol::Value* paddingColorValue = object->get("paddingColor"); if (paddingColorValue) { errors->setName("paddingColor"); result->m_paddingColor = ValueConversions::fromValue(paddingColorValue, errors); } protocol::Value* borderColorValue = object->get("borderColor"); if (borderColorValue) { errors->setName("borderColor"); result->m_borderColor = ValueConversions::fromValue(borderColorValue, errors); } protocol::Value* marginColorValue = object->get("marginColor"); if (marginColorValue) { errors->setName("marginColor"); result->m_marginColor = ValueConversions::fromValue(marginColorValue, errors); } protocol::Value* eventTargetColorValue = object->get("eventTargetColor"); if (eventTargetColorValue) { errors->setName("eventTargetColor"); result->m_eventTargetColor = ValueConversions::fromValue(eventTargetColorValue, errors); } protocol::Value* shapeColorValue = object->get("shapeColor"); if (shapeColorValue) { errors->setName("shapeColor"); result->m_shapeColor = ValueConversions::fromValue(shapeColorValue, errors); } protocol::Value* shapeMarginColorValue = object->get("shapeMarginColor"); if (shapeMarginColorValue) { errors->setName("shapeMarginColor"); result->m_shapeMarginColor = ValueConversions::fromValue(shapeMarginColorValue, errors); } protocol::Value* selectorListValue = object->get("selectorList"); if (selectorListValue) { errors->setName("selectorList"); result->m_selectorList = ValueConversions::fromValue(selectorListValue, errors); } errors->pop(); if (errors->hasErrors()) return nullptr; return result; } std::unique_ptr HighlightConfig::toValue() const { std::unique_ptr result = DictionaryValue::create(); if (m_showInfo.isJust()) result->setValue("showInfo", ValueConversions::toValue(m_showInfo.fromJust())); if (m_showRulers.isJust()) result->setValue("showRulers", ValueConversions::toValue(m_showRulers.fromJust())); if (m_showExtensionLines.isJust()) result->setValue("showExtensionLines", ValueConversions::toValue(m_showExtensionLines.fromJust())); if (m_displayAsMaterial.isJust()) result->setValue("displayAsMaterial", ValueConversions::toValue(m_displayAsMaterial.fromJust())); if (m_contentColor.isJust()) result->setValue("contentColor", ValueConversions::toValue(m_contentColor.fromJust())); if (m_paddingColor.isJust()) result->setValue("paddingColor", ValueConversions::toValue(m_paddingColor.fromJust())); if (m_borderColor.isJust()) result->setValue("borderColor", ValueConversions::toValue(m_borderColor.fromJust())); if (m_marginColor.isJust()) result->setValue("marginColor", ValueConversions::toValue(m_marginColor.fromJust())); if (m_eventTargetColor.isJust()) result->setValue("eventTargetColor", ValueConversions::toValue(m_eventTargetColor.fromJust())); if (m_shapeColor.isJust()) result->setValue("shapeColor", ValueConversions::toValue(m_shapeColor.fromJust())); if (m_shapeMarginColor.isJust()) result->setValue("shapeMarginColor", ValueConversions::toValue(m_shapeMarginColor.fromJust())); if (m_selectorList.isJust()) result->setValue("selectorList", ValueConversions::toValue(m_selectorList.fromJust())); return result; } std::unique_ptr HighlightConfig::clone() const { ErrorSupport errors; return fromValue(toValue().get(), &errors); } namespace InspectModeEnum { const char SearchForNode[] = "searchForNode"; const char SearchForUAShadowDOM[] = "searchForUAShadowDOM"; const char None[] = "none"; } // namespace InspectModeEnum std::unique_ptr NodeHighlightRequestedNotification::fromValue(protocol::Value* value, ErrorSupport* errors) { if (!value || value->type() != protocol::Value::TypeObject) { errors->addError("object expected"); return nullptr; } std::unique_ptr result(new NodeHighlightRequestedNotification()); protocol::DictionaryValue* object = DictionaryValue::cast(value); errors->push(); protocol::Value* nodeIdValue = object->get("nodeId"); errors->setName("nodeId"); result->m_nodeId = ValueConversions::fromValue(nodeIdValue, errors); errors->pop(); if (errors->hasErrors()) return nullptr; return result; } std::unique_ptr NodeHighlightRequestedNotification::toValue() const { std::unique_ptr result = DictionaryValue::create(); result->setValue("nodeId", ValueConversions::toValue(m_nodeId)); return result; } std::unique_ptr NodeHighlightRequestedNotification::clone() const { ErrorSupport errors; return fromValue(toValue().get(), &errors); } std::unique_ptr InspectNodeRequestedNotification::fromValue(protocol::Value* value, ErrorSupport* errors) { if (!value || value->type() != protocol::Value::TypeObject) { errors->addError("object expected"); return nullptr; } std::unique_ptr result(new InspectNodeRequestedNotification()); protocol::DictionaryValue* object = DictionaryValue::cast(value); errors->push(); protocol::Value* backendNodeIdValue = object->get("backendNodeId"); errors->setName("backendNodeId"); result->m_backendNodeId = ValueConversions::fromValue(backendNodeIdValue, errors); errors->pop(); if (errors->hasErrors()) return nullptr; return result; } std::unique_ptr InspectNodeRequestedNotification::toValue() const { std::unique_ptr result = DictionaryValue::create(); result->setValue("backendNodeId", ValueConversions::toValue(m_backendNodeId)); return result; } std::unique_ptr InspectNodeRequestedNotification::clone() const { ErrorSupport errors; return fromValue(toValue().get(), &errors); } // ------------- Enum values from params. // ------------- Frontend notifications. void Frontend::nodeHighlightRequested(int nodeId) { if (!m_frontendChannel) return; std::unique_ptr messageData = NodeHighlightRequestedNotification::create() .setNodeId(nodeId) .build(); m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("Overlay.nodeHighlightRequested", std::move(messageData))); } void Frontend::inspectNodeRequested(int backendNodeId) { if (!m_frontendChannel) return; std::unique_ptr messageData = InspectNodeRequestedNotification::create() .setBackendNodeId(backendNodeId) .build(); m_frontendChannel->sendProtocolNotification(InternalResponse::createNotification("Overlay.inspectNodeRequested", std::move(messageData))); } void Frontend::flush() { m_frontendChannel->flushProtocolNotifications(); } void Frontend::sendRawNotification(const String& notification) { m_frontendChannel->sendProtocolNotification(InternalRawNotification::create(notification)); } // --------------------- Dispatcher. class DispatcherImpl : public protocol::DispatcherBase { public: DispatcherImpl(FrontendChannel* frontendChannel, Backend* backend, bool fallThroughForNotFound) : DispatcherBase(frontendChannel) , m_backend(backend) , m_fallThroughForNotFound(fallThroughForNotFound) { m_dispatchMap["Overlay.enable"] = &DispatcherImpl::enable; m_dispatchMap["Overlay.disable"] = &DispatcherImpl::disable; m_dispatchMap["Overlay.highlightNode"] = &DispatcherImpl::highlightNode; m_dispatchMap["Overlay.hideHighlight"] = &DispatcherImpl::hideHighlight; m_dispatchMap["Overlay.setInspectMode"] = &DispatcherImpl::setInspectMode; } ~DispatcherImpl() override { } DispatchResponse::Status dispatch(int callId, const String& method, std::unique_ptr messageObject) override; HashMap& redirects() { return m_redirects; } protected: using CallHandler = DispatchResponse::Status (DispatcherImpl::*)(int callId, std::unique_ptr messageObject, ErrorSupport* errors); using DispatchMap = protocol::HashMap; DispatchMap m_dispatchMap; HashMap m_redirects; DispatchResponse::Status enable(int callId, std::unique_ptr requestMessageObject, ErrorSupport*); DispatchResponse::Status disable(int callId, std::unique_ptr requestMessageObject, ErrorSupport*); DispatchResponse::Status highlightNode(int callId, std::unique_ptr requestMessageObject, ErrorSupport*); DispatchResponse::Status hideHighlight(int callId, std::unique_ptr requestMessageObject, ErrorSupport*); DispatchResponse::Status setInspectMode(int callId, std::unique_ptr requestMessageObject, ErrorSupport*); Backend* m_backend; bool m_fallThroughForNotFound; }; DispatchResponse::Status DispatcherImpl::dispatch(int callId, const String& method, std::unique_ptr messageObject) { protocol::HashMap::iterator it = m_dispatchMap.find(method); if (it == m_dispatchMap.end()) { if (m_fallThroughForNotFound) return DispatchResponse::kFallThrough; reportProtocolError(callId, DispatchResponse::kMethodNotFound, "'" + method + "' wasn't found", nullptr); return DispatchResponse::kError; } protocol::ErrorSupport errors; return (this->*(it->second))(callId, std::move(messageObject), &errors); } DispatchResponse::Status DispatcherImpl::enable(int callId, std::unique_ptr requestMessageObject, ErrorSupport* errors) { std::unique_ptr weak = weakPtr(); DispatchResponse response = m_backend->enable(); if (response.status() == DispatchResponse::kFallThrough) return response.status(); if (weak->get()) weak->get()->sendResponse(callId, response); return response.status(); } DispatchResponse::Status DispatcherImpl::disable(int callId, std::unique_ptr requestMessageObject, ErrorSupport* errors) { std::unique_ptr weak = weakPtr(); DispatchResponse response = m_backend->disable(); if (response.status() == DispatchResponse::kFallThrough) return response.status(); if (weak->get()) weak->get()->sendResponse(callId, response); return response.status(); } DispatchResponse::Status DispatcherImpl::highlightNode(int callId, std::unique_ptr requestMessageObject, ErrorSupport* errors) { // Prepare input parameters. protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params")); errors->push(); protocol::Value* highlightConfigValue = object ? object->get("highlightConfig") : nullptr; errors->setName("highlightConfig"); std::unique_ptr in_highlightConfig = ValueConversions::fromValue(highlightConfigValue, errors); protocol::Value* nodeIdValue = object ? object->get("nodeId") : nullptr; Maybe in_nodeId; if (nodeIdValue) { errors->setName("nodeId"); in_nodeId = ValueConversions::fromValue(nodeIdValue, errors); } errors->pop(); if (errors->hasErrors()) { reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors); return DispatchResponse::kError; } std::unique_ptr weak = weakPtr(); DispatchResponse response = m_backend->highlightNode(std::move(in_highlightConfig), std::move(in_nodeId)); if (response.status() == DispatchResponse::kFallThrough) return response.status(); if (weak->get()) weak->get()->sendResponse(callId, response); return response.status(); } DispatchResponse::Status DispatcherImpl::hideHighlight(int callId, std::unique_ptr requestMessageObject, ErrorSupport* errors) { std::unique_ptr weak = weakPtr(); DispatchResponse response = m_backend->hideHighlight(); if (response.status() == DispatchResponse::kFallThrough) return response.status(); if (weak->get()) weak->get()->sendResponse(callId, response); return response.status(); } DispatchResponse::Status DispatcherImpl::setInspectMode(int callId, std::unique_ptr requestMessageObject, ErrorSupport* errors) { // Prepare input parameters. protocol::DictionaryValue* object = DictionaryValue::cast(requestMessageObject->get("params")); errors->push(); protocol::Value* modeValue = object ? object->get("mode") : nullptr; errors->setName("mode"); String in_mode = ValueConversions::fromValue(modeValue, errors); protocol::Value* highlightConfigValue = object ? object->get("highlightConfig") : nullptr; Maybe in_highlightConfig; if (highlightConfigValue) { errors->setName("highlightConfig"); in_highlightConfig = ValueConversions::fromValue(highlightConfigValue, errors); } errors->pop(); if (errors->hasErrors()) { reportProtocolError(callId, DispatchResponse::kInvalidParams, kInvalidParamsString, errors); return DispatchResponse::kError; } std::unique_ptr weak = weakPtr(); DispatchResponse response = m_backend->setInspectMode(in_mode, std::move(in_highlightConfig)); if (response.status() == DispatchResponse::kFallThrough) return response.status(); if (weak->get()) weak->get()->sendResponse(callId, response); return response.status(); } // static void Dispatcher::wire(UberDispatcher* uber, Backend* backend) { std::unique_ptr dispatcher(new DispatcherImpl(uber->channel(), backend, uber->fallThroughForNotFound())); uber->setupRedirects(dispatcher->redirects()); uber->registerBackend("Overlay", std::move(dispatcher)); } } // Overlay } // namespace ui_devtools } // namespace protocol