blob: 2682188e58e24915f953669f391e56b5d49256d1 [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"
20#include "net/url_request/url_fetcher_delegate.h"
21
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;
37 virtual ~ShellDevToolsDelegate(){};
38};
39
40class WebContents;
41
42class ShellDevToolsBindings : public WebContentsObserver,
43 public DevToolsAgentHostClient,
44 public net::URLFetcherDelegate {
45 public:
46 ShellDevToolsBindings(WebContents* devtools_contents,
47 WebContents* inspected_contents,
48 ShellDevToolsDelegate* delegate);
49
50 void InspectElementAt(int x, int y);
Will Chen8bbdf20f2017-12-12 21:09:5451 virtual void Attach();
chenwilliamfed5bda2017-03-24 02:01:0652
53 void CallClientFunction(const std::string& function_name,
54 const base::Value* arg1,
55 const base::Value* arg2,
56 const base::Value* arg3);
57 ~ShellDevToolsBindings() override;
58
Pavel Feldmanff74cd62017-11-11 00:20:5259 WebContents* inspected_contents() { return inspected_contents_; }
60
Will Chen197be822017-12-22 23:03:5861 private:
chenwilliamfed5bda2017-03-24 02:01:0662 // content::DevToolsAgentHostClient implementation.
Pavel Feldmana344d932017-10-31 20:24:5263 void AgentHostClosed(DevToolsAgentHost* agent_host) override;
chenwilliamfed5bda2017-03-24 02:01:0664 void DispatchProtocolMessage(DevToolsAgentHost* agent_host,
65 const std::string& message) override;
66
Will Chen197be822017-12-22 23:03:5867 void HandleMessageFromDevToolsFrontend(const std::string& message);
chenwilliamfed5bda2017-03-24 02:01:0668
chenwilliamfed5bda2017-03-24 02:01:0669 // WebContentsObserver overrides
Pavel Feldmanad5aa4eb2017-06-13 21:13:5970 void ReadyToCommitNavigation(NavigationHandle* navigation_handle) override;
chenwilliamfed5bda2017-03-24 02:01:0671 void WebContentsDestroyed() override;
72
73 // net::URLFetcherDelegate overrides.
74 void OnURLFetchComplete(const net::URLFetcher* source) override;
75
76 void SendMessageAck(int request_id, const base::Value* arg1);
77
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
86 using PendingRequestsMap = std::map<const net::URLFetcher*, int>;
87 PendingRequestsMap pending_requests_;
Andrey Kosyakov942286d42018-03-22 02:12:3888
89 class NetworkResourceLoader;
90 std::set<std::unique_ptr<NetworkResourceLoader>, base::UniquePtrComparator>
91 loaders_;
92
chenwilliamfed5bda2017-03-24 02:01:0693 base::DictionaryValue preferences_;
Andrey Kosyakov942286d42018-03-22 02:12:3894
Pavel Feldmanad5aa4eb2017-06-13 21:13:5995 using ExtensionsAPIs = std::map<std::string, std::string>;
96 ExtensionsAPIs extensions_api_;
chenwilliamfed5bda2017-03-24 02:01:0697 base::WeakPtrFactory<ShellDevToolsBindings> weak_factory_;
98
99 DISALLOW_COPY_AND_ASSIGN(ShellDevToolsBindings);
100};
101
102} // namespace content
103
104#endif // CONTENT_SHELL_BROWSER_SHELL_DEVTOOLS_BINDINGS_H_