summaryrefslogtreecommitdiffstats
path: root/content/browser/devtools/protocol/devtools_protocol_client.h
blob: 9297187f21c1778752372a2881912ab4c1bbe380 (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
69
70
71
72
73
74
// Copyright 2014 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_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_CLIENT_H_
#define CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_CLIENT_H_

#include "base/callback.h"
#include "base/values.h"

namespace content {

using DevToolsCommandId = int;
class DevToolsProtocolHandler;
class DevToolsProtocolDispatcher;

class DevToolsProtocolClient {
 public:
  typedef base::Callback<void(const std::string& message)>
      RawMessageCallback;
  static const DevToolsCommandId kNoId;

  struct Response {
   public:
    static Response FallThrough();
    static Response OK();
    static Response InvalidParams(const std::string& param);
    static Response InternalError(const std::string& message);
    static Response ServerError(const std::string& message);

    int status() const;
    const std::string& message() const;

    bool IsFallThrough() const;

   private:
    friend class DevToolsProtocolHandler;

    explicit Response(int status);
    Response(int status, const std::string& message);

    int status_;
    std::string message_;
  };

  bool SendError(DevToolsCommandId command_id,
                 const Response& response);

  // Sends message to client, the caller is presumed to properly
  // format the message. Do not use unless you must.
  void SendRawMessage(const std::string& message);

  explicit DevToolsProtocolClient(
      const RawMessageCallback& raw_message_callback);
  virtual ~DevToolsProtocolClient();

 protected:
  void SendSuccess(DevToolsCommandId command_id,
                   scoped_ptr<base::DictionaryValue> params);
  void SendNotification(const std::string& method,
                        scoped_ptr<base::DictionaryValue> params);

 private:
  friend class DevToolsProtocolDispatcher;

  void SendMessage(const base::DictionaryValue& message);

  RawMessageCallback raw_message_callback_;
  DISALLOW_COPY_AND_ASSIGN(DevToolsProtocolClient);
};

}  // namespace content

#endif  // CONTENT_BROWSER_DEVTOOLS_PROTOCOL_DEVTOOLS_PROTOCOL_CLIENT_H_