blob: 8b79f54128a99cdd2a4e12ed4ed3b51ba70cdddd [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;
36 virtual ~ShellDevToolsDelegate(){};
37};
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
48 void InspectElementAt(int x, int y);
Will Chen8bbdf20f2017-12-12 21:09:5449 virtual void Attach();
chenwilliamfed5bda2017-03-24 02:01:0650
51 void CallClientFunction(const std::string& function_name,
52 const base::Value* arg1,
53 const base::Value* arg2,
54 const base::Value* arg3);
55 ~ShellDevToolsBindings() override;
56
Pavel Feldmanff74cd62017-11-11 00:20:5257 WebContents* inspected_contents() { return inspected_contents_; }
58
Will Chen197be822017-12-22 23:03:5859 private:
chenwilliamfed5bda2017-03-24 02:01:0660 // content::DevToolsAgentHostClient implementation.
Pavel Feldmana344d932017-10-31 20:24:5261 void AgentHostClosed(DevToolsAgentHost* agent_host) override;
chenwilliamfed5bda2017-03-24 02:01:0662 void DispatchProtocolMessage(DevToolsAgentHost* agent_host,
63 const std::string& message) override;
64
Will Chen197be822017-12-22 23:03:5865 void HandleMessageFromDevToolsFrontend(const std::string& message);
chenwilliamfed5bda2017-03-24 02:01:0666
chenwilliamfed5bda2017-03-24 02:01:0667 // WebContentsObserver overrides
Pavel Feldmanad5aa4eb2017-06-13 21:13:5968 void ReadyToCommitNavigation(NavigationHandle* navigation_handle) override;
chenwilliamfed5bda2017-03-24 02:01:0669 void WebContentsDestroyed() override;
70
chenwilliamfed5bda2017-03-24 02:01:0671 void SendMessageAck(int request_id, const base::Value* arg1);
72
73 WebContents* inspected_contents_;
74 ShellDevToolsDelegate* delegate_;
75 scoped_refptr<DevToolsAgentHost> agent_host_;
76 int inspect_element_at_x_;
77 int inspect_element_at_y_;
78#if !defined(OS_ANDROID)
79 std::unique_ptr<DevToolsFrontendHost> frontend_host_;
80#endif
Andrey Kosyakov942286d42018-03-22 02:12:3881
82 class NetworkResourceLoader;
83 std::set<std::unique_ptr<NetworkResourceLoader>, base::UniquePtrComparator>
84 loaders_;
85
chenwilliamfed5bda2017-03-24 02:01:0686 base::DictionaryValue preferences_;
Andrey Kosyakov942286d42018-03-22 02:12:3887
Pavel Feldmanad5aa4eb2017-06-13 21:13:5988 using ExtensionsAPIs = std::map<std::string, std::string>;
89 ExtensionsAPIs extensions_api_;
chenwilliamfed5bda2017-03-24 02:01:0690 base::WeakPtrFactory<ShellDevToolsBindings> weak_factory_;
91
92 DISALLOW_COPY_AND_ASSIGN(ShellDevToolsBindings);
93};
94
95} // namespace content
96
97#endif // CONTENT_SHELL_BROWSER_SHELL_DEVTOOLS_BINDINGS_H_