blob: f98ac8c070ad7b40b14a8fb3f7fc4cd977363a14 [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
Gabriel Charettea6b6f552021-03-22 15:50:3511#include "base/callback_helpers.h"
chenwilliamfed5bda2017-03-24 02:01:0612#include "base/compiler_specific.h"
Johannes Henkel21e194012019-12-20 03:23:1713#include "base/containers/span.h"
Andrey Kosyakov942286d42018-03-22 02:12:3814#include "base/containers/unique_ptr_adapters.h"
chenwilliamfed5bda2017-03-24 02:01:0615#include "base/macros.h"
16#include "base/memory/ref_counted.h"
17#include "base/memory/weak_ptr.h"
18#include "base/values.h"
19#include "content/public/browser/devtools_agent_host.h"
20#include "content/public/browser/devtools_frontend_host.h"
21#include "content/public/browser/web_contents_observer.h"
chenwilliamfed5bda2017-03-24 02:01:0622
23#if !defined(OS_ANDROID)
24#include "content/public/browser/devtools_frontend_host.h"
25#endif
26
27namespace base {
28class Value;
29}
30
31namespace content {
32
Pavel Feldmanad5aa4eb2017-06-13 21:13:5933class NavigationHandle;
34
chenwilliamfed5bda2017-03-24 02:01:0635class ShellDevToolsDelegate {
36 public:
37 virtual void Close() = 0;
Nico Weberc191bf92019-02-11 18:52:3738 virtual ~ShellDevToolsDelegate() {}
chenwilliamfed5bda2017-03-24 02:01:0639};
40
41class WebContents;
42
43class ShellDevToolsBindings : public WebContentsObserver,
Mario Sanchez Prada670a5832018-09-25 11:56:1444 public DevToolsAgentHostClient {
chenwilliamfed5bda2017-03-24 02:01:0645 public:
46 ShellDevToolsBindings(WebContents* devtools_contents,
47 WebContents* inspected_contents,
48 ShellDevToolsDelegate* delegate);
49
Adithya Srinivasan5d50d1e2019-10-09 00:27:4850 static std::vector<ShellDevToolsBindings*> GetInstancesForWebContents(
51 WebContents* web_contents);
52
chenwilliamfed5bda2017-03-24 02:01:0653 void InspectElementAt(int x, int y);
Will Chen8bbdf20f2017-12-12 21:09:5454 virtual void Attach();
Adithya Srinivasanb7204c82020-08-17 14:26:3355 void UpdateInspectedWebContents(WebContents* new_contents,
56 base::OnceCallback<void()> callback);
chenwilliamfed5bda2017-03-24 02:01:0657
Adithya Srinivasanb7204c82020-08-17 14:26:3358 void CallClientFunction(
Maksim Sadymbf905d82020-10-08 10:59:4959 const std::string& object_name,
60 const std::string& method_name,
61 const base::Value arg1 = {},
62 const base::Value arg2 = {},
63 const base::Value arg3 = {},
Adithya Srinivasanb7204c82020-08-17 14:26:3364 base::OnceCallback<void(base::Value)> cb = base::NullCallback());
chenwilliamfed5bda2017-03-24 02:01:0665 ~ShellDevToolsBindings() override;
66
Pavel Feldmanff74cd62017-11-11 00:20:5267 WebContents* inspected_contents() { return inspected_contents_; }
68
Will Chen197be822017-12-22 23:03:5869 private:
chenwilliamfed5bda2017-03-24 02:01:0670 // content::DevToolsAgentHostClient implementation.
Pavel Feldmana344d932017-10-31 20:24:5271 void AgentHostClosed(DevToolsAgentHost* agent_host) override;
chenwilliamfed5bda2017-03-24 02:01:0672 void DispatchProtocolMessage(DevToolsAgentHost* agent_host,
Johannes Henkel21e194012019-12-20 03:23:1773 base::span<const uint8_t> message) override;
chenwilliamfed5bda2017-03-24 02:01:0674
Sigurd Schneiderce925072021-04-22 08:01:5075 void HandleMessageFromDevToolsFrontend(base::Value);
chenwilliamfed5bda2017-03-24 02:01:0676
chenwilliamfed5bda2017-03-24 02:01:0677 // WebContentsObserver overrides
Pavel Feldmanad5aa4eb2017-06-13 21:13:5978 void ReadyToCommitNavigation(NavigationHandle* navigation_handle) override;
chenwilliamfed5bda2017-03-24 02:01:0679 void WebContentsDestroyed() override;
80
Maksim Sadymbf905d82020-10-08 10:59:4981 void SendMessageAck(int request_id, const base::Value arg);
Adithya Srinivasan5d50d1e2019-10-09 00:27:4882 void AttachInternal();
chenwilliamfed5bda2017-03-24 02:01:0683
84 WebContents* inspected_contents_;
85 ShellDevToolsDelegate* delegate_;
86 scoped_refptr<DevToolsAgentHost> agent_host_;
87 int inspect_element_at_x_;
88 int inspect_element_at_y_;
89#if !defined(OS_ANDROID)
90 std::unique_ptr<DevToolsFrontendHost> frontend_host_;
91#endif
Andrey Kosyakov942286d42018-03-22 02:12:3892
93 class NetworkResourceLoader;
94 std::set<std::unique_ptr<NetworkResourceLoader>, base::UniquePtrComparator>
95 loaders_;
96
chenwilliamfed5bda2017-03-24 02:01:0697 base::DictionaryValue preferences_;
Andrey Kosyakov942286d42018-03-22 02:12:3898
Pavel Feldmanad5aa4eb2017-06-13 21:13:5999 using ExtensionsAPIs = std::map<std::string, std::string>;
100 ExtensionsAPIs extensions_api_;
Jeremy Roman3bca4bf2019-07-11 03:41:25101 base::WeakPtrFactory<ShellDevToolsBindings> weak_factory_{this};
chenwilliamfed5bda2017-03-24 02:01:06102
103 DISALLOW_COPY_AND_ASSIGN(ShellDevToolsBindings);
104};
105
106} // namespace content
107
108#endif // CONTENT_SHELL_BROWSER_SHELL_DEVTOOLS_BINDINGS_H_