summaryrefslogtreecommitdiffstats
path: root/content/browser/debugger/devtools_browser_target.h
blob: 14e141fe4e8fd30d93d05178149f73c9dc2b8880 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) 2012 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 CONTENT_BROWSER_DEBUGGER_DEVTOOLS_BROWSER_TARGET_H_
#define CONTENT_BROWSER_DEBUGGER_DEVTOOLS_BROWSER_TARGET_H_

#include <map>
#include <string>

#include "base/basictypes.h"

namespace base {

class DictionaryValue;
class Value;

}  // namespace base

namespace content {

// This class handles the "Browser" target for remote debugging.
class DevToolsBrowserTarget {
 public:
  class Handler {
   public:
    virtual ~Handler() {}

    // Returns the domain name for this handler.
    virtual std::string Domain() = 0;

    // |return_value| and |error_message_out| ownership is transferred to the
    // caller.
    virtual base::Value* OnProtocolCommand(
        const std::string& method,
        const base::DictionaryValue* params,
        base::Value** error_message_out) = 0;
  };

  explicit DevToolsBrowserTarget(int connection_id);
  ~DevToolsBrowserTarget();

  int connection_id() const { return connection_id_; }

  // Takes ownership of |handler|.
  void RegisterHandler(Handler* handler);

  std::string HandleMessage(const std::string& data);

 private:
  const int connection_id_;

  typedef std::map<std::string, Handler*> HandlersMap;
  HandlersMap handlers_;

  // Takes ownership of |error_object|.
  std::string SerializeErrorResponse(int request_id, base::Value* error_object);

  base::Value* CreateErrorObject(int error_code, const std::string& message);

  std::string SerializeResponse(int request_id, base::Value* response);

  DISALLOW_COPY_AND_ASSIGN(DevToolsBrowserTarget);
};

}  // namespace content

#endif  // CONTENT_BROWSER_DEBUGGER_DEVTOOLS_BROWSER_TARGET_H_