OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef HEADLESS_LIB_BROWSER_HEADLESS_DEVTOOLS_MANAGER_DELEGATE_H_ | 5 #ifndef HEADLESS_LIB_BROWSER_HEADLESS_DEVTOOLS_MANAGER_DELEGATE_H_ |
6 #define HEADLESS_LIB_BROWSER_HEADLESS_DEVTOOLS_MANAGER_DELEGATE_H_ | 6 #define HEADLESS_LIB_BROWSER_HEADLESS_DEVTOOLS_MANAGER_DELEGATE_H_ |
7 | 7 |
8 #include "content/public/browser/devtools_manager_delegate.h" | 8 #include "content/public/browser/devtools_manager_delegate.h" |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 #include <memory> | 11 #include <memory> |
12 #include <string> | 12 #include <string> |
13 | 13 |
| 14 #include "base/memory/weak_ptr.h" |
14 #include "base/values.h" | 15 #include "base/values.h" |
15 | 16 |
16 namespace headless { | 17 namespace headless { |
17 class HeadlessBrowserImpl; | 18 class HeadlessBrowserImpl; |
18 class HeadlessBrowserContext; | 19 class HeadlessBrowserContext; |
19 class HeadlessWebContentsImpl; | 20 class HeadlessWebContentsImpl; |
20 | 21 |
21 class HeadlessDevToolsManagerDelegate | 22 class HeadlessDevToolsManagerDelegate |
22 : public content::DevToolsManagerDelegate { | 23 : public content::DevToolsManagerDelegate { |
23 public: | 24 public: |
24 explicit HeadlessDevToolsManagerDelegate(HeadlessBrowserImpl* browser); | 25 explicit HeadlessDevToolsManagerDelegate(HeadlessBrowserImpl* browser); |
25 ~HeadlessDevToolsManagerDelegate() override; | 26 ~HeadlessDevToolsManagerDelegate() override; |
26 | 27 |
27 // DevToolsManagerDelegate implementation: | 28 // DevToolsManagerDelegate implementation: |
28 void Inspect(content::BrowserContext* browser_context, | 29 void Inspect(content::BrowserContext* browser_context, |
29 content::DevToolsAgentHost* agent_host) override {} | 30 content::DevToolsAgentHost* agent_host) override {} |
30 void DevToolsAgentStateChanged(content::DevToolsAgentHost* agent_host, | 31 void DevToolsAgentStateChanged(content::DevToolsAgentHost* agent_host, |
31 bool attached) override{}; | 32 bool attached) override{}; |
32 base::DictionaryValue* HandleCommand(content::DevToolsAgentHost* agent_host, | 33 base::DictionaryValue* HandleCommand(content::DevToolsAgentHost* agent_host, |
33 base::DictionaryValue* command) override; | 34 base::DictionaryValue* command) override; |
34 | 35 |
| 36 // Delete owned browser contexts. |
| 37 void Shutdown(); |
| 38 |
| 39 base::WeakPtr<HeadlessDevToolsManagerDelegate> GetWeakPtr(); |
| 40 |
35 private: | 41 private: |
36 std::unique_ptr<base::Value> CreateTarget( | 42 std::unique_ptr<base::Value> CreateTarget( |
37 const base::DictionaryValue* params); | 43 const base::DictionaryValue* params); |
38 std::unique_ptr<base::Value> CloseTarget(const base::DictionaryValue* params); | 44 std::unique_ptr<base::Value> CloseTarget(const base::DictionaryValue* params); |
39 std::unique_ptr<base::Value> CreateBrowserContext( | 45 std::unique_ptr<base::Value> CreateBrowserContext( |
40 const base::DictionaryValue* params); | 46 const base::DictionaryValue* params); |
41 std::unique_ptr<base::Value> DisposeBrowserContext( | 47 std::unique_ptr<base::Value> DisposeBrowserContext( |
42 const base::DictionaryValue* params); | 48 const base::DictionaryValue* params); |
43 | 49 |
44 HeadlessBrowserImpl* browser_; // Not owned. | 50 HeadlessBrowserImpl* browser_; // Not owned. |
45 std::map<std::string, std::unique_ptr<HeadlessBrowserContext>> | 51 std::map<std::string, std::unique_ptr<HeadlessBrowserContext>> |
46 browser_context_map_; | 52 browser_context_map_; |
47 | 53 |
48 using CommandMemberFnPtr = std::unique_ptr<base::Value> ( | 54 using CommandMemberFnPtr = std::unique_ptr<base::Value> ( |
49 HeadlessDevToolsManagerDelegate::*)(const base::DictionaryValue* params); | 55 HeadlessDevToolsManagerDelegate::*)(const base::DictionaryValue* params); |
50 | 56 |
51 std::map<std::string, CommandMemberFnPtr> command_map_; | 57 std::map<std::string, CommandMemberFnPtr> command_map_; |
| 58 |
| 59 std::unique_ptr<HeadlessBrowserContext> default_browser_context_; |
| 60 |
| 61 base::WeakPtrFactory<HeadlessDevToolsManagerDelegate> weak_ptr_factory_; |
52 }; | 62 }; |
53 | 63 |
54 } // namespace headless | 64 } // namespace headless |
55 | 65 |
56 #endif // HEADLESS_LIB_BROWSER_HEADLESS_DEVTOOLS_MANAGER_DELEGATE_H_ | 66 #endif // HEADLESS_LIB_BROWSER_HEADLESS_DEVTOOLS_MANAGER_DELEGATE_H_ |
OLD | NEW |