summaryrefslogtreecommitdiffstats
path: root/components/html_viewer/devtools_agent_impl.h
blob: 19989284d3d64505944ac8cac6f307d6dd492560 (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
// Copyright 2015 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 COMPONENTS_HTML_VIEWER_DEVTOOLS_AGENT_IMPL_H_
#define COMPONENTS_HTML_VIEWER_DEVTOOLS_AGENT_IMPL_H_

#include "base/macros.h"
#include "components/devtools_service/public/interfaces/devtools_service.mojom.h"
#include "third_party/WebKit/public/web/WebDevToolsAgentClient.h"
#include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h"

namespace blink {
class WebLocalFrame;
}

namespace mojo {
class Shell;
}

namespace html_viewer {

class DevToolsAgentImpl : public devtools_service::DevToolsAgent,
                          public blink::WebDevToolsAgentClient {
 public:
  // |frame| must outlive this object.
  DevToolsAgentImpl(blink::WebLocalFrame* frame, mojo::Shell* shell);
  ~DevToolsAgentImpl() override;

  blink::WebLocalFrame* frame() const { return frame_; }

  // Returns whether a "Page.navigate" command is being handled.
  bool handling_page_navigate_request() const {
    return handling_page_navigate_request_;
  }

 private:
  // devtools_service::DevToolsAgent implementation.
  void SetClient(devtools_service::DevToolsAgentClientPtr client,
                 const mojo::String& client_id) override;
  void DispatchProtocolMessage(const mojo::String& message) override;

  // blink::WebDevToolsAgentClient implementation.
  void sendProtocolMessage(int call_id,
                           const blink::WebString& response,
                           const blink::WebString& state);

  void OnConnectionError();

  blink::WebLocalFrame* const frame_;
  mojo::Binding<DevToolsAgent> binding_;
  devtools_service::DevToolsAgentClientPtr client_;

  bool handling_page_navigate_request_;

  DISALLOW_COPY_AND_ASSIGN(DevToolsAgentImpl);
};

}  // namespace html_viewer

#endif  // COMPONENTS_HTML_VIEWER_DEVTOOLS_AGENT_IMPL_H_