diff options
author | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-10 13:52:30 +0000 |
---|---|---|
committer | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-10 13:52:30 +0000 |
commit | 98f5f88b53f774cee109503b0225a5bfb9deb550 (patch) | |
tree | 32af75ae9784181c85e577327d8020192658c519 /chrome/browser/debugger/devtools_remote_message.h | |
parent | 198d8d43c5ccff8d0d48bbd3fef31917aa9d3db6 (diff) | |
download | chromium_src-98f5f88b53f774cee109503b0225a5bfb9deb550.zip chromium_src-98f5f88b53f774cee109503b0225a5bfb9deb550.tar.gz chromium_src-98f5f88b53f774cee109503b0225a5bfb9deb550.tar.bz2 |
DevTools. Add V8 Application Remote Debugging Protocol support by apavlov. Original CL: http://codereview.chromium.org/56109
Review URL: http://codereview.chromium.org/66031
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13502 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/debugger/devtools_remote_message.h')
-rw-r--r-- | chrome/browser/debugger/devtools_remote_message.h | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/chrome/browser/debugger/devtools_remote_message.h b/chrome/browser/debugger/devtools_remote_message.h new file mode 100644 index 0000000..7665269 --- /dev/null +++ b/chrome/browser/debugger/devtools_remote_message.h @@ -0,0 +1,134 @@ +// Copyright (c) 2009 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. + +#ifndef CHROME_BROWSER_DEBUGGER_DEVTOOLS_REMOTE_MESSAGE_H_ +#define CHROME_BROWSER_DEBUGGER_DEVTOOLS_REMOTE_MESSAGE_H_ + +#include <string> + +#include "base/basictypes.h" +#include "base/hash_tables.h" +#include "base/logging.h" + +// Contains DevTools protocol message header names +// and the Flags header bit field constants. +struct DevToolsRemoteMessageHeaders { + // The content length in decimal. + static const char kContentLength[]; + // The tool that should handle the message. + static const char kTool[]; + // The destination (inspected) object identifier (if any), like a TabID. + static const char kDestination[]; +}; + +// Represents a Chrome remote debugging protocol message transferred +// over the wire between the remote debugger and a Chrome instance. +// Consider using DevToolsRemoteMessageBuilder (see end of this file) for easy +// construction of outbound (Chrome -> remote debugger) messages. +class DevToolsRemoteMessage { + public: + typedef base::hash_map<std::string, std::string> HeaderMap; + + // Use this as the second parameter in a |GetHeader| call to use + // an empty string as the default value. + static const char kEmptyValue[]; + + // Constructs an empty message with no content or headers. + DevToolsRemoteMessage() {} + DevToolsRemoteMessage(const HeaderMap& headers, const std::string& content) + : header_map_(headers), + content_(content) {} + virtual ~DevToolsRemoteMessage() {} + + const HeaderMap& headers() const { + return header_map_; + } + + const std::string& content() const { + return content_; + } + + const int content_length() const { + return content_.size(); + } + + const std::string tool() const { + return GetHeaderWithEmptyDefault(DevToolsRemoteMessageHeaders::kTool); + } + + const std::string destination() const { + return GetHeaderWithEmptyDefault( + DevToolsRemoteMessageHeaders::kDestination); + } + + // Returns the header value providing default_value if the header is absent. + const std::string GetHeader(const std::string& header_name, + const std::string& default_value) const; + + // Returns the header value providing an empty string if the header is absent. + const std::string GetHeaderWithEmptyDefault( + const std::string& header_name) const; + + // Returns a string representation of the message useful for the transfer to + // the remote debugger. + const std::string ToString() const; + + private: + HeaderMap header_map_; + std::string content_; + // Cannot DISALLOW_COPY_AND_ASSIGN(DevToolsRemoteMessage) since it is passed + // as an IPC message argument and needs to be copied. +}; + +// Facilitates easy construction of outbound (Chrome -> remote debugger) +// DevToolsRemote messages. +class DevToolsRemoteMessageBuilder { + public: + class IdGenerator { + public: + virtual ~IdGenerator() {} + virtual int32 NextId() = 0; + }; + // A singleton instance getter. + static DevToolsRemoteMessageBuilder& instance(); + // Creates a message given the certain header values and a payload. + DevToolsRemoteMessage* Create(const std::string& tool, + const std::string& destination, + const std::string& payload); + // Sets a message ID generator instance. The builder then owns this instance + // and deletes it upon termination. + void set_id_generator(IdGenerator* id_generator) { + if (id_generator_ != NULL) { + delete id_generator_; + id_generator_ = id_generator; + } else { + NOTREACHED(); + } + } + + private: + class IdGeneratorImpl : public IdGenerator { + public: + IdGeneratorImpl() : id_(1) {} + virtual int32 NextId() { + return id_++; + } + private: + int32 id_; + }; + + explicit DevToolsRemoteMessageBuilder(IdGenerator* id_generator) + : id_generator_(id_generator) {} + ~DevToolsRemoteMessageBuilder() { + delete id_generator_; + } + int32 NextMessageId() { + return id_generator_->NextId(); + } + + IdGenerator* id_generator_; + DISALLOW_COPY_AND_ASSIGN(DevToolsRemoteMessageBuilder); +}; + +#endif // CHROME_BROWSER_DEBUGGER_DEVTOOLS_REMOTE_MESSAGE_H_ |