blob: 09c3b6f2db7c134a2637a0e0f2b28f58a0514c9d [file] [log] [blame]
chenwilliamfed5bda2017-03-24 02:01:061// Copyright 2017 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CONTENT_SHELL_BROWSER_SHELL_DEVTOOLS_BINDINGS_H_
6#define CONTENT_SHELL_BROWSER_SHELL_DEVTOOLS_BINDINGS_H_
7
8#include <memory>
Andrey Kosyakov942286d42018-03-22 02:12:389#include <set>
chenwilliamfed5bda2017-03-24 02:01:0610
11#include "base/compiler_specific.h"
Johannes Henkel21e194012019-12-20 03:23:1712#include "base/containers/span.h"
Andrey Kosyakov942286d42018-03-22 02:12:3813#include "base/containers/unique_ptr_adapters.h"
chenwilliamfed5bda2017-03-24 02:01:0614#include "base/macros.h"
15#include "base/memory/ref_counted.h"
16#include "base/memory/weak_ptr.h"
17#include "base/values.h"
18#include "content/public/browser/devtools_agent_host.h"
19#include "content/public/browser/devtools_frontend_host.h"
20#include "content/public/browser/web_contents_observer.h"
chenwilliamfed5bda2017-03-24 02:01:0621
22#if !defined(OS_ANDROID)
23#include "content/public/browser/devtools_frontend_host.h"
24#endif
25
26namespace base {
27class Value;
28}
29
30namespace content {
31
Pavel Feldmanad5aa4eb2017-06-13 21:13:5932class NavigationHandle;
33
chenwilliamfed5bda2017-03-24 02:01:0634class ShellDevToolsDelegate {
35 public:
36 virtual void Close() = 0;
Nico Weberc191bf92019-02-11 18:52:3737 virtual ~ShellDevToolsDelegate() {}
chenwilliamfed5bda2017-03-24 02:01:0638};
39
40class WebContents;
41
42class ShellDevToolsBindings : public WebContentsObserver,
Mario Sanchez Prada670a5832018-09-25 11:56:1443 public DevToolsAgentHostClient {
chenwilliamfed5bda2017-03-24 02:01:0644 public:
45 ShellDevToolsBindings(WebContents* devtools_contents,
46 WebContents* inspected_contents,
47 ShellDevToolsDelegate* delegate);
48
Adithya Srinivasan5d50d1e2019-10-09 00:27:4849 static std::vector<ShellDevToolsBindings*> GetInstancesForWebContents(
50 WebContents* web_contents);
51
chenwilliamfed5bda2017-03-24 02:01:0652 void InspectElementAt(int x, int y);
Will Chen8bbdf20f2017-12-12 21:09:5453 virtual void Attach();
Adithya Srinivasan5d50d1e2019-10-09 00:27:4854 void UpdateInspectedWebContents(WebContents* new_contents);
chenwilliamfed5bda2017-03-24 02:01:0655
56 void CallClientFunction(const std::string& function_name,
57 const base::Value* arg1,
58 const base::Value* arg2,
59 const base::Value* arg3);
60 ~ShellDevToolsBindings() override;
61
Pavel Feldmanff74cd62017-11-11 00:20:5262 WebContents* inspected_contents() { return inspected_contents_; }
63
Will Chen197be822017-12-22 23:03:5864 private:
chenwilliamfed5bda2017-03-24 02:01:0665 // content::DevToolsAgentHostClient implementation.
Pavel Feldmana344d932017-10-31 20:24:5266 void AgentHostClosed(DevToolsAgentHost* agent_host) override;
chenwilliamfed5bda2017-03-24 02:01:0667 void DispatchProtocolMessage(DevToolsAgentHost* agent_host,
Johannes Henkel21e194012019-12-20 03:23:1768 base::span<const uint8_t> message) override;
chenwilliamfed5bda2017-03-24 02:01:0669
Will Chen197be822017-12-22 23:03:5870 void HandleMessageFromDevToolsFrontend(const std::string& message);
chenwilliamfed5bda2017-03-24 02:01:0671
chenwilliamfed5bda2017-03-24 02:01:0672 // WebContentsObserver overrides
Pavel Feldmanad5aa4eb2017-06-13 21:13:5973 void ReadyToCommitNavigation(NavigationHandle* navigation_handle) override;
chenwilliamfed5bda2017-03-24 02:01:0674 void WebContentsDestroyed() override;
75
chenwilliamfed5bda2017-03-24 02:01:0676 void SendMessageAck(int request_id, const base::Value* arg1);
Adithya Srinivasan5d50d1e2019-10-09 00:27:4877 void AttachInternal();
chenwilliamfed5bda2017-03-24 02:01:0678
79 WebContents* inspected_contents_;
80 ShellDevToolsDelegate* delegate_;
81 scoped_refptr<DevToolsAgentHost> agent_host_;
82 int inspect_element_at_x_;
83 int inspect_element_at_y_;
84#if !defined(OS_ANDROID)
85 std::unique_ptr<DevToolsFrontendHost> frontend_host_;
86#endif
Andrey Kosyakov942286d42018-03-22 02:12:3887
88 class NetworkResourceLoader;
89 std::set<std::unique_ptr<NetworkResourceLoader>, base::UniquePtrComparator>
90 loaders_;
91
chenwilliamfed5bda2017-03-24 02:01:0692 base::DictionaryValue preferences_;
Andrey Kosyakov942286d42018-03-22 02:12:3893
Pavel Feldmanad5aa4eb2017-06-13 21:13:5994 using ExtensionsAPIs = std::map<std::string, std::string>;
95 ExtensionsAPIs extensions_api_;
Jeremy Roman3bca4bf2019-07-11 03:41:2596 base::WeakPtrFactory<ShellDevToolsBindings> weak_factory_{this};
chenwilliamfed5bda2017-03-24 02:01:0697
98 DISALLOW_COPY_AND_ASSIGN(ShellDevToolsBindings);
99};
100
101} // namespace content
102
103#endif // CONTENT_SHELL_BROWSER_SHELL_DEVTOOLS_BINDINGS_H_