chenwilliam | fed5bda | 2017-03-24 02:01:06 | [diff] [blame] | 1 | // 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 Kosyakov | 942286d4 | 2018-03-22 02:12:38 | [diff] [blame] | 9 | #include <set> |
chenwilliam | fed5bda | 2017-03-24 02:01:06 | [diff] [blame] | 10 | |
| 11 | #include "base/compiler_specific.h" |
Andrey Kosyakov | 942286d4 | 2018-03-22 02:12:38 | [diff] [blame] | 12 | #include "base/containers/unique_ptr_adapters.h" |
chenwilliam | fed5bda | 2017-03-24 02:01:06 | [diff] [blame] | 13 | #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 | |
| 26 | namespace base { |
| 27 | class Value; |
| 28 | } |
| 29 | |
| 30 | namespace content { |
| 31 | |
Pavel Feldman | ad5aa4eb | 2017-06-13 21:13:59 | [diff] [blame] | 32 | class NavigationHandle; |
| 33 | |
chenwilliam | fed5bda | 2017-03-24 02:01:06 | [diff] [blame] | 34 | class ShellDevToolsDelegate { |
| 35 | public: |
| 36 | virtual void Close() = 0; |
| 37 | virtual ~ShellDevToolsDelegate(){}; |
| 38 | }; |
| 39 | |
| 40 | class WebContents; |
| 41 | |
| 42 | class 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 Chen | 8bbdf20f | 2017-12-12 21:09:54 | [diff] [blame] | 51 | virtual void Attach(); |
chenwilliam | fed5bda | 2017-03-24 02:01:06 | [diff] [blame] | 52 | |
| 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 Feldman | ff74cd6 | 2017-11-11 00:20:52 | [diff] [blame] | 59 | WebContents* inspected_contents() { return inspected_contents_; } |
| 60 | |
Will Chen | 197be82 | 2017-12-22 23:03:58 | [diff] [blame] | 61 | private: |
chenwilliam | fed5bda | 2017-03-24 02:01:06 | [diff] [blame] | 62 | // content::DevToolsAgentHostClient implementation. |
Pavel Feldman | a344d93 | 2017-10-31 20:24:52 | [diff] [blame] | 63 | void AgentHostClosed(DevToolsAgentHost* agent_host) override; |
chenwilliam | fed5bda | 2017-03-24 02:01:06 | [diff] [blame] | 64 | void DispatchProtocolMessage(DevToolsAgentHost* agent_host, |
| 65 | const std::string& message) override; |
| 66 | |
Will Chen | 197be82 | 2017-12-22 23:03:58 | [diff] [blame] | 67 | void HandleMessageFromDevToolsFrontend(const std::string& message); |
chenwilliam | fed5bda | 2017-03-24 02:01:06 | [diff] [blame] | 68 | |
chenwilliam | fed5bda | 2017-03-24 02:01:06 | [diff] [blame] | 69 | // WebContentsObserver overrides |
Pavel Feldman | ad5aa4eb | 2017-06-13 21:13:59 | [diff] [blame] | 70 | void ReadyToCommitNavigation(NavigationHandle* navigation_handle) override; |
chenwilliam | fed5bda | 2017-03-24 02:01:06 | [diff] [blame] | 71 | 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 Kosyakov | 942286d4 | 2018-03-22 02:12:38 | [diff] [blame] | 88 | |
| 89 | class NetworkResourceLoader; |
| 90 | std::set<std::unique_ptr<NetworkResourceLoader>, base::UniquePtrComparator> |
| 91 | loaders_; |
| 92 | |
chenwilliam | fed5bda | 2017-03-24 02:01:06 | [diff] [blame] | 93 | base::DictionaryValue preferences_; |
Andrey Kosyakov | 942286d4 | 2018-03-22 02:12:38 | [diff] [blame] | 94 | |
Pavel Feldman | ad5aa4eb | 2017-06-13 21:13:59 | [diff] [blame] | 95 | using ExtensionsAPIs = std::map<std::string, std::string>; |
| 96 | ExtensionsAPIs extensions_api_; |
chenwilliam | fed5bda | 2017-03-24 02:01:06 | [diff] [blame] | 97 | 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_ |