OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "headless/lib/browser/headless_browser_impl.h" | 5 #include "headless/lib/browser/headless_browser_impl.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 } | 98 } |
99 | 99 |
100 void HeadlessBrowserImpl::Shutdown() { | 100 void HeadlessBrowserImpl::Shutdown() { |
101 DCHECK(BrowserMainThread()->BelongsToCurrentThread()); | 101 DCHECK(BrowserMainThread()->BelongsToCurrentThread()); |
102 BrowserMainThread()->PostTask(FROM_HERE, | 102 BrowserMainThread()->PostTask(FROM_HERE, |
103 base::MessageLoop::QuitWhenIdleClosure()); | 103 base::MessageLoop::QuitWhenIdleClosure()); |
104 } | 104 } |
105 | 105 |
106 std::vector<HeadlessWebContents*> HeadlessBrowserImpl::GetAllWebContents() { | 106 std::vector<HeadlessWebContents*> HeadlessBrowserImpl::GetAllWebContents() { |
107 std::vector<HeadlessWebContents*> result; | 107 std::vector<HeadlessWebContents*> result; |
108 result.reserve(web_contents_.size()); | 108 result.reserve(web_contents_map_.size()); |
109 | 109 |
110 for (const auto& web_contents_pair : web_contents_) { | 110 for (const auto& web_contents_pair : web_contents_map_) { |
111 result.push_back(web_contents_pair.first); | 111 result.push_back(web_contents_pair.second.get()); |
112 } | 112 } |
113 | 113 |
114 return result; | 114 return result; |
115 } | 115 } |
116 | 116 |
117 HeadlessBrowserMainParts* HeadlessBrowserImpl::browser_main_parts() const { | 117 HeadlessBrowserMainParts* HeadlessBrowserImpl::browser_main_parts() const { |
118 DCHECK(BrowserMainThread()->BelongsToCurrentThread()); | 118 DCHECK(BrowserMainThread()->BelongsToCurrentThread()); |
119 return browser_main_parts_; | 119 return browser_main_parts_; |
120 } | 120 } |
121 | 121 |
(...skipping 15 matching lines...) Expand all Loading... |
137 new HeadlessWindowTreeClient(window_tree_host_->window())); | 137 new HeadlessWindowTreeClient(window_tree_host_->window())); |
138 | 138 |
139 on_start_callback_.Run(this); | 139 on_start_callback_.Run(this); |
140 on_start_callback_ = base::Callback<void(HeadlessBrowser*)>(); | 140 on_start_callback_ = base::Callback<void(HeadlessBrowser*)>(); |
141 } | 141 } |
142 | 142 |
143 HeadlessWebContentsImpl* HeadlessBrowserImpl::RegisterWebContents( | 143 HeadlessWebContentsImpl* HeadlessBrowserImpl::RegisterWebContents( |
144 std::unique_ptr<HeadlessWebContentsImpl> web_contents) { | 144 std::unique_ptr<HeadlessWebContentsImpl> web_contents) { |
145 DCHECK(web_contents); | 145 DCHECK(web_contents); |
146 HeadlessWebContentsImpl* unowned_web_contents = web_contents.get(); | 146 HeadlessWebContentsImpl* unowned_web_contents = web_contents.get(); |
147 web_contents_[unowned_web_contents] = std::move(web_contents); | 147 web_contents_map_[unowned_web_contents->GetDevtoolsAgentHostId()] = |
| 148 std::move(web_contents); |
148 return unowned_web_contents; | 149 return unowned_web_contents; |
149 } | 150 } |
150 | 151 |
151 void HeadlessBrowserImpl::DestroyWebContents( | 152 void HeadlessBrowserImpl::DestroyWebContents( |
152 HeadlessWebContentsImpl* web_contents) { | 153 HeadlessWebContentsImpl* web_contents) { |
153 auto it = web_contents_.find(web_contents); | 154 auto it = web_contents_map_.find(web_contents->GetDevtoolsAgentHostId()); |
154 DCHECK(it != web_contents_.end()); | 155 DCHECK(it != web_contents_map_.end()); |
155 web_contents_.erase(it); | 156 web_contents_map_.erase(it); |
| 157 } |
| 158 |
| 159 HeadlessWebContents* HeadlessBrowserImpl::GetWebContentsForDevtoolsAgentHostId( |
| 160 const std::string& devtools_agent_host_id) { |
| 161 auto it = web_contents_map_.find(devtools_agent_host_id); |
| 162 if (it == web_contents_map_.end()) |
| 163 return nullptr; |
| 164 return it->second.get(); |
156 } | 165 } |
157 | 166 |
158 void HeadlessBrowserImpl::SetOptionsForTesting( | 167 void HeadlessBrowserImpl::SetOptionsForTesting( |
159 HeadlessBrowser::Options options) { | 168 HeadlessBrowser::Options options) { |
160 options_ = std::move(options); | 169 options_ = std::move(options); |
161 browser_main_parts()->default_browser_context()->SetOptionsForTesting( | 170 browser_main_parts()->default_browser_context()->SetOptionsForTesting( |
162 &options_); | 171 &options_); |
163 } | 172 } |
164 | 173 |
165 void RunChildProcessIfNeeded(int argc, const char** argv) { | 174 void RunChildProcessIfNeeded(int argc, const char** argv) { |
(...skipping 18 matching lines...) Expand all Loading... |
184 | 193 |
185 // Child processes should not end up here. | 194 // Child processes should not end up here. |
186 base::CommandLine command_line(options.argc, options.argv); | 195 base::CommandLine command_line(options.argc, options.argv); |
187 DCHECK(!command_line.HasSwitch(switches::kProcessType)); | 196 DCHECK(!command_line.HasSwitch(switches::kProcessType)); |
188 #endif | 197 #endif |
189 return RunContentMain(std::move(options), | 198 return RunContentMain(std::move(options), |
190 std::move(on_browser_start_callback)); | 199 std::move(on_browser_start_callback)); |
191 } | 200 } |
192 | 201 |
193 } // namespace headless | 202 } // namespace headless |
OLD | NEW |