blob: 01e5197c99f15d008a4296e8b19994379405c534 [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>
9
10#include "base/compiler_specific.h"
11#include "base/macros.h"
12#include "base/memory/ref_counted.h"
13#include "base/memory/weak_ptr.h"
14#include "base/values.h"
15#include "content/public/browser/devtools_agent_host.h"
16#include "content/public/browser/devtools_frontend_host.h"
17#include "content/public/browser/web_contents_observer.h"
18#include "net/url_request/url_fetcher_delegate.h"
19
20#if !defined(OS_ANDROID)
21#include "content/public/browser/devtools_frontend_host.h"
22#endif
23
24namespace base {
25class Value;
26}
27
28namespace content {
29
Pavel Feldmanad5aa4eb2017-06-13 21:13:5930class NavigationHandle;
31
chenwilliamfed5bda2017-03-24 02:01:0632class ShellDevToolsDelegate {
33 public:
34 virtual void Close() = 0;
35 virtual ~ShellDevToolsDelegate(){};
36};
37
38class WebContents;
39
40class ShellDevToolsBindings : public WebContentsObserver,
41 public DevToolsAgentHostClient,
42 public net::URLFetcherDelegate {
43 public:
44 ShellDevToolsBindings(WebContents* devtools_contents,
45 WebContents* inspected_contents,
46 ShellDevToolsDelegate* delegate);
47
48 void InspectElementAt(int x, int y);
49
50 void CallClientFunction(const std::string& function_name,
51 const base::Value* arg1,
52 const base::Value* arg2,
53 const base::Value* arg3);
54 ~ShellDevToolsBindings() override;
55
56 protected:
57 // content::DevToolsAgentHostClient implementation.
Pavel Feldmana344d932017-10-31 20:24:5258 void AgentHostClosed(DevToolsAgentHost* agent_host) override;
chenwilliamfed5bda2017-03-24 02:01:0659 void DispatchProtocolMessage(DevToolsAgentHost* agent_host,
60 const std::string& message) override;
61
62 void SetPreferences(const std::string& json);
63 virtual void HandleMessageFromDevToolsFrontend(const std::string& message);
chenwilliamfed5bda2017-03-24 02:01:0664
65 private:
66 // WebContentsObserver overrides
Pavel Feldmanad5aa4eb2017-06-13 21:13:5967 void ReadyToCommitNavigation(NavigationHandle* navigation_handle) override;
chenwilliamfed5bda2017-03-24 02:01:0668 void DocumentAvailableInMainFrame() override;
69 void WebContentsDestroyed() override;
70
71 // net::URLFetcherDelegate overrides.
72 void OnURLFetchComplete(const net::URLFetcher* source) override;
73
74 void SendMessageAck(int request_id, const base::Value* arg1);
75
76 WebContents* inspected_contents_;
77 ShellDevToolsDelegate* delegate_;
78 scoped_refptr<DevToolsAgentHost> agent_host_;
79 int inspect_element_at_x_;
80 int inspect_element_at_y_;
81#if !defined(OS_ANDROID)
82 std::unique_ptr<DevToolsFrontendHost> frontend_host_;
83#endif
84 using PendingRequestsMap = std::map<const net::URLFetcher*, int>;
85 PendingRequestsMap pending_requests_;
86 base::DictionaryValue preferences_;
Pavel Feldmanad5aa4eb2017-06-13 21:13:5987 using ExtensionsAPIs = std::map<std::string, std::string>;
88 ExtensionsAPIs extensions_api_;
chenwilliamfed5bda2017-03-24 02:01:0689 base::WeakPtrFactory<ShellDevToolsBindings> weak_factory_;
90
91 DISALLOW_COPY_AND_ASSIGN(ShellDevToolsBindings);
92};
93
94} // namespace content
95
96#endif // CONTENT_SHELL_BROWSER_SHELL_DEVTOOLS_BINDINGS_H_