OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/test/chromedriver/chrome/chrome_impl.h" | 5 #include "chrome/test/chromedriver/chrome/chrome_impl.h" |
6 | 6 |
| 7 #include "base/bind.h" |
7 #include "chrome/test/chromedriver/chrome/devtools_client.h" | 8 #include "chrome/test/chromedriver/chrome/devtools_client.h" |
8 #include "chrome/test/chromedriver/chrome/devtools_event_listener.h" | 9 #include "chrome/test/chromedriver/chrome/devtools_event_listener.h" |
9 #include "chrome/test/chromedriver/chrome/devtools_http_client.h" | 10 #include "chrome/test/chromedriver/chrome/devtools_http_client.h" |
10 #include "chrome/test/chromedriver/chrome/status.h" | 11 #include "chrome/test/chromedriver/chrome/status.h" |
11 #include "chrome/test/chromedriver/chrome/web_view_impl.h" | 12 #include "chrome/test/chromedriver/chrome/web_view_impl.h" |
12 #include "chrome/test/chromedriver/net/port_server.h" | 13 #include "chrome/test/chromedriver/net/port_server.h" |
13 | 14 |
| 15 namespace { |
| 16 |
| 17 void DoNothingWithWebViewInfo(const WebViewInfo& view) { |
| 18 } |
| 19 |
| 20 } // namespace |
| 21 |
14 ChromeImpl::~ChromeImpl() { | 22 ChromeImpl::~ChromeImpl() { |
15 if (!quit_) | 23 if (!quit_) |
16 port_reservation_->Leak(); | 24 port_reservation_->Leak(); |
17 } | 25 } |
18 | 26 |
19 Status ChromeImpl::GetAsDesktop(ChromeDesktopImpl** desktop) { | 27 Status ChromeImpl::GetAsDesktop(ChromeDesktopImpl** desktop) { |
20 return Status(kUnknownError, "operation unsupported"); | 28 return Status(kUnknownError, "operation unsupported"); |
21 } | 29 } |
22 | 30 |
23 const BrowserInfo* ChromeImpl::GetBrowserInfo() const { | 31 const BrowserInfo* ChromeImpl::GetBrowserInfo() const { |
24 return devtools_http_client_->browser_info(); | 32 return devtools_http_client_->browser_info(); |
25 } | 33 } |
26 | 34 |
27 bool ChromeImpl::HasCrashedWebView() { | 35 bool ChromeImpl::HasCrashedWebView() { |
28 for (WebViewList::iterator it = web_views_.begin(); | 36 for (WebViewList::iterator it = web_views_.begin(); |
29 it != web_views_.end(); ++it) { | 37 it != web_views_.end(); ++it) { |
30 if ((*it)->WasCrashed()) | 38 if ((*it)->WasCrashed()) |
31 return true; | 39 return true; |
32 } | 40 } |
33 return false; | 41 return false; |
34 } | 42 } |
35 | 43 |
36 Status ChromeImpl::GetWebViewIds(std::list<std::string>* web_view_ids) { | 44 Status ChromeImpl::GetWebViewIds(std::list<std::string>* web_view_ids) { |
| 45 WebViewCallback callback = base::Bind(&DoNothingWithWebViewInfo); |
| 46 return UpdateWebViewIds(web_view_ids, callback); |
| 47 } |
| 48 |
| 49 Status ChromeImpl::UpdateWebViewIds(std::list<std::string>* web_view_ids, |
| 50 const WebViewCallback& on_open_web_view) { |
37 WebViewsInfo views_info; | 51 WebViewsInfo views_info; |
38 Status status = devtools_http_client_->GetWebViewsInfo(&views_info); | 52 Status status = devtools_http_client_->GetWebViewsInfo(&views_info); |
39 if (status.IsError()) | 53 if (status.IsError()) |
40 return status; | 54 return status; |
41 | 55 |
42 // Check if some web views are closed. | 56 // Check if some web views are closed. |
43 WebViewList::iterator it = web_views_.begin(); | 57 WebViewList::iterator it = web_views_.begin(); |
44 while (it != web_views_.end()) { | 58 while (it != web_views_.end()) { |
45 if (!views_info.GetForId((*it)->GetId())) { | 59 if (!views_info.GetForId((*it)->GetId())) { |
46 it = web_views_.erase(it); | 60 it = web_views_.erase(it); |
(...skipping 25 matching lines...) Expand all Loading... |
72 devtools_event_listeners_.begin(); | 86 devtools_event_listeners_.begin(); |
73 listener != devtools_event_listeners_.end(); ++listener) { | 87 listener != devtools_event_listeners_.end(); ++listener) { |
74 client->AddListener(*listener); | 88 client->AddListener(*listener); |
75 // OnConnected will fire when DevToolsClient connects later. | 89 // OnConnected will fire when DevToolsClient connects later. |
76 } | 90 } |
77 web_views_.push_back(make_linked_ptr(new WebViewImpl( | 91 web_views_.push_back(make_linked_ptr(new WebViewImpl( |
78 view.id, | 92 view.id, |
79 devtools_http_client_->browser_info(), | 93 devtools_http_client_->browser_info(), |
80 client.Pass(), | 94 client.Pass(), |
81 devtools_http_client_->device_metrics()))); | 95 devtools_http_client_->device_metrics()))); |
| 96 on_open_web_view.Run(view); |
82 } | 97 } |
83 } | 98 } |
84 } | 99 } |
85 | 100 |
86 std::list<std::string> web_view_ids_tmp; | 101 std::list<std::string> web_view_ids_tmp; |
87 for (WebViewList::const_iterator web_view_iter = web_views_.begin(); | 102 for (WebViewList::const_iterator web_view_iter = web_views_.begin(); |
88 web_view_iter != web_views_.end(); ++web_view_iter) { | 103 web_view_iter != web_views_.end(); ++web_view_iter) { |
89 web_view_ids_tmp.push_back((*web_view_iter)->GetId()); | 104 web_view_ids_tmp.push_back((*web_view_iter)->GetId()); |
90 } | 105 } |
91 web_view_ids->swap(web_view_ids_tmp); | 106 web_view_ids->swap(web_view_ids_tmp); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 scoped_ptr<DevToolsHttpClient> http_client, | 155 scoped_ptr<DevToolsHttpClient> http_client, |
141 scoped_ptr<DevToolsClient> websocket_client, | 156 scoped_ptr<DevToolsClient> websocket_client, |
142 ScopedVector<DevToolsEventListener>& devtools_event_listeners, | 157 ScopedVector<DevToolsEventListener>& devtools_event_listeners, |
143 scoped_ptr<PortReservation> port_reservation) | 158 scoped_ptr<PortReservation> port_reservation) |
144 : quit_(false), | 159 : quit_(false), |
145 devtools_http_client_(http_client.Pass()), | 160 devtools_http_client_(http_client.Pass()), |
146 devtools_websocket_client_(websocket_client.Pass()), | 161 devtools_websocket_client_(websocket_client.Pass()), |
147 port_reservation_(port_reservation.Pass()) { | 162 port_reservation_(port_reservation.Pass()) { |
148 devtools_event_listeners_.swap(devtools_event_listeners); | 163 devtools_event_listeners_.swap(devtools_event_listeners); |
149 } | 164 } |
OLD | NEW |