blob: 03adda59af903a3d0f679fc7ef5321475b96169a [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"
Andrey Kosyakov942286d42018-03-22 02:12:3812#include "base/containers/unique_ptr_adapters.h"
chenwilliamfed5bda2017-03-24 02:01:0613#include "base/macros.h"
14#include "base/memory/ref_counted.h"
15#include "base/memory/weak_ptr.h"
16#include "base/values.h"
17#include "content/public/browser/devtools_agent_host.h"
18#include "content/public/browser/devtools_frontend_host.h"
19#include "content/public/browser/web_contents_observer.h"
chenwilliamfed5bda2017-03-24 02:01:0620
21#if !defined(OS_ANDROID)
22#include "content/public/browser/devtools_frontend_host.h"
23#endif
24
25namespace base {
26class Value;
27}
28
29namespace content {
30
Pavel Feldmanad5aa4eb2017-06-13 21:13:5931class NavigationHandle;
32
chenwilliamfed5bda2017-03-24 02:01:0633class ShellDevToolsDelegate {
34 public:
35 virtual void Close() = 0;
Nico Weberc191bf92019-02-11 18:52:3736 virtual ~ShellDevToolsDelegate() {}
chenwilliamfed5bda2017-03-24 02:01:0637};
38
39class WebContents;
40
41class ShellDevToolsBindings : public WebContentsObserver,
Mario Sanchez Prada670a5832018-09-25 11:56:1442 public DevToolsAgentHostClient {
chenwilliamfed5bda2017-03-24 02:01:0643 public:
44 ShellDevToolsBindings(WebContents* devtools_contents,
45 WebContents* inspected_contents,
46 ShellDevToolsDelegate* delegate);
47
Adithya Srinivasan5d50d1e2019-10-09 00:27:4848 static std::vector<ShellDevToolsBindings*> GetInstancesForWebContents(
49 WebContents* web_contents);
50
chenwilliamfed5bda2017-03-24 02:01:0651 void InspectElementAt(int x, int y);
Will Chen8bbdf20f2017-12-12 21:09:5452 virtual void Attach();
Adithya Srinivasan5d50d1e2019-10-09 00:27:4853 void UpdateInspectedWebContents(WebContents* new_contents);
chenwilliamfed5bda2017-03-24 02:01:0654
55 void CallClientFunction(const std::string& function_name,
56 const base::Value* arg1,
57 const base::Value* arg2,
58 const base::Value* arg3);
59 ~ShellDevToolsBindings() override;
60
Pavel Feldmanff74cd62017-11-11 00:20:5261 WebContents* inspected_contents() { return inspected_contents_; }
62
Will Chen197be822017-12-22 23:03:5863 private:
chenwilliamfed5bda2017-03-24 02:01:0664 // content::DevToolsAgentHostClient implementation.
Pavel Feldmana344d932017-10-31 20:24:5265 void AgentHostClosed(DevToolsAgentHost* agent_host) override;
chenwilliamfed5bda2017-03-24 02:01:0666 void DispatchProtocolMessage(DevToolsAgentHost* agent_host,
67 const std::string& message) override;
68
Will Chen197be822017-12-22 23:03:5869 void HandleMessageFromDevToolsFrontend(const std::string& message);
chenwilliamfed5bda2017-03-24 02:01:0670
chenwilliamfed5bda2017-03-24 02:01:0671 // WebContentsObserver overrides
Pavel Feldmanad5aa4eb2017-06-13 21:13:5972 void ReadyToCommitNavigation(NavigationHandle* navigation_handle) override;
chenwilliamfed5bda2017-03-24 02:01:0673 void WebContentsDestroyed() override;
74
chenwilliamfed5bda2017-03-24 02:01:0675 void SendMessageAck(int request_id, const base::Value* arg1);
Adithya Srinivasan5d50d1e2019-10-09 00:27:4876 void AttachInternal();
chenwilliamfed5bda2017-03-24 02:01:0677
78 WebContents* inspected_contents_;
79 ShellDevToolsDelegate* delegate_;
80 scoped_refptr<DevToolsAgentHost> agent_host_;
81 int inspect_element_at_x_;
82 int inspect_element_at_y_;
83#if !defined(OS_ANDROID)
84 std::unique_ptr<DevToolsFrontendHost> frontend_host_;
85#endif
Andrey Kosyakov942286d42018-03-22 02:12:3886
87 class NetworkResourceLoader;
88 std::set<std::unique_ptr<NetworkResourceLoader>, base::UniquePtrComparator>
89 loaders_;
90
chenwilliamfed5bda2017-03-24 02:01:0691 base::DictionaryValue preferences_;
Andrey Kosyakov942286d42018-03-22 02:12:3892
Pavel Feldmanad5aa4eb2017-06-13 21:13:5993 using ExtensionsAPIs = std::map<std::string, std::string>;
94 ExtensionsAPIs extensions_api_;
Jeremy Roman3bca4bf2019-07-11 03:41:2595 base::WeakPtrFactory<ShellDevToolsBindings> weak_factory_{this};
chenwilliamfed5bda2017-03-24 02:01:0696
97 DISALLOW_COPY_AND_ASSIGN(ShellDevToolsBindings);
98};
99
100} // namespace content
101
102#endif // CONTENT_SHELL_BROWSER_SHELL_DEVTOOLS_BINDINGS_H_