1c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Copyright (c) 2009 The Chromium Authors. All rights reserved. 2c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Use of this source code is governed by a BSD-style license that can be 3c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// found in the LICENSE file. 4c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 5c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// This file declares the DebuggerRemoteServiceCommand struct and the 6c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// DebuggerRemoteService class which handles commands directed to the 7c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// "V8Debugger" tool. 8c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#ifndef CHROME_BROWSER_DEBUGGER_DEBUGGER_REMOTE_SERVICE_H_ 9c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#define CHROME_BROWSER_DEBUGGER_DEBUGGER_REMOTE_SERVICE_H_ 103345a6884c488ff3a535c2c9acdd33d74b37e311Iain Merrick#pragma once 11c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 12c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include <string> 13c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 14c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "base/basictypes.h" 15c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#include "chrome/browser/debugger/devtools_remote.h" 16c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 17c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass DevToolsProtocolHandler; 18c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass DevToolsRemoteMessage; 19c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass DictionaryValue; 20c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass Value; 21c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass TabContents; 22c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 23c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Contains constants for DebuggerRemoteService tool protocol commands 24c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// (V8-related only). 25c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochstruct DebuggerRemoteServiceCommand { 26c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch static const std::string kAttach; 27c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch static const std::string kDetach; 28c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch static const std::string kDebuggerCommand; 29c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch static const std::string kEvaluateJavascript; 30c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch static const std::string kFrameNavigate; // navigation event 31c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch static const std::string kTabClosed; // tab closing event 32c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch}; 33c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 34c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// Handles V8 debugger-related messages from the remote debugger (like 35c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// attach to V8 debugger, detach from V8 debugger, send command to V8 debugger) 36c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch// and proxies JSON messages from V8 debugger to the remote debugger. 37c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdochclass DebuggerRemoteService : public DevToolsRemoteListener { 38c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch public: 39c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // |delegate| (never NULL) is the protocol handler instance 40c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // which dispatches messages to this service. The responses from the 41c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // V8 VM debugger are routed back to |delegate|. 42c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // The ownership of |delegate| is NOT transferred to this class. 43c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch explicit DebuggerRemoteService(DevToolsProtocolHandler* delegate); 44c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 45c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Handles a JSON message from the tab_uid-associated V8 debugger. 46c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void DebuggerOutput(int32 tab_uid, const std::string& message); 47c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 48c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Handles a frame navigation event. 49c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void FrameNavigate(int32 tab_uid, const std::string& url); 50c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 51c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Handles a tab closing event. 52c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void TabClosed(int32 tab_uid); 53c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 54c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Detaches the remote debugger from the tab specified by |destination|. 55c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // It is public so that we can detach from the tab on the remote debugger 56c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // connection loss. 57c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // If |response| is not NULL, the operation result will be written 58c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // as the "result" field in |response|, otherwise the result 59c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // will not be propagated back to the caller. 60c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void DetachFromTab(const std::string& destination, 61c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch DictionaryValue* response); 62c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 63c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // DevToolsRemoteListener interface. 64c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 65c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Processes |message| from the remote debugger, where the tool is 66c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // "V8Debugger". Either sends the reply immediately or waits for an 67c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // asynchronous response from the V8 debugger. 68c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch virtual void HandleMessage(const DevToolsRemoteMessage& message); 69c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 70c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Gets invoked on the remote debugger [socket] connection loss. 71c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Notifies the InspectableTabProxy of the remote debugger detachment. 72c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch virtual void OnConnectionLost(); 73c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 74c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Specifies a tool name ("V8Debugger") handled by this class. 75c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch static const std::string kToolName; 76c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 77c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch private: 78c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Operation result returned in the "result" field. 79c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch typedef enum { 80c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch RESULT_OK = 0, 81c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch RESULT_ILLEGAL_TAB_STATE, 82c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch RESULT_UNKNOWN_TAB, 83c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch RESULT_DEBUGGER_ERROR, 84c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch RESULT_UNKNOWN_COMMAND 85c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch } Result; 86c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 87c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch virtual ~DebuggerRemoteService(); 88c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 89c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Attaches a remote debugger to the tab specified by |destination|. 90c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Writes the attachment result (one of Result enum values) into |response|. 91c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void AttachToTab(const std::string& destination, 92c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch DictionaryValue* response); 93c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 94c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Retrieves a WebContents instance for the specified |tab_uid| 95c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // or NULL if no such tab is found or no WebContents instance 96c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // corresponds to that tab. 97c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch TabContents* ToTabContents(int32 tab_uid); 98c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 99c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Sends a JSON message with the |response| to the remote debugger. 100c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // |tool| and |destination| are used as the respective header values. 101c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch void SendResponse(const Value& response, 102c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const std::string& tool, 103c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch const std::string& destination); 104c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 105c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Redirects a V8 debugger command from |content| to a V8 debugger associated 106c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // with the |tab_uid| and writes the result into |response| if it becomes 107c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // known immediately. 108c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch bool DispatchDebuggerCommand(int tab_uid, 109c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch DictionaryValue* content, 110c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch DictionaryValue* response); 111c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 112c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // Redirects a Javascript evaluation command from |content| to 113c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // a V8 debugger associated with the |tab_uid| and writes the result 114c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // into |response| if it becomes known immediately. 115c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch bool DispatchEvaluateJavascript(int tab_uid, 116c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch DictionaryValue* content, 117c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch DictionaryValue* response); 118c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 119c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch // The delegate is used to get an InspectableTabProxy instance. 120c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch DevToolsProtocolHandler* delegate_; 121c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch DISALLOW_COPY_AND_ASSIGN(DebuggerRemoteService); 122c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch}; 123c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch 124c407dc5cd9bdc5668497f21b26b09d988ab439deBen Murdoch#endif // CHROME_BROWSER_DEBUGGER_DEBUGGER_REMOTE_SERVICE_H_ 125