OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/automation/tab_proxy.h" | 5 #include "chrome/test/automation/tab_proxy.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "chrome/common/json_value_serializer.h" | 10 #include "chrome/common/json_value_serializer.h" |
11 #include "chrome/test/automation/automation_constants.h" | 11 #include "chrome/test/automation/automation_constants.h" |
12 #include "chrome/test/automation/automation_messages.h" | 12 #include "chrome/test/automation/automation_messages.h" |
13 #include "chrome/test/automation/automation_proxy.h" | 13 #include "chrome/test/automation/automation_proxy.h" |
14 #include "chrome/test/automation/constrained_window_proxy.h" | 14 #include "chrome/test/automation/constrained_window_proxy.h" |
15 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
16 | 16 |
17 bool TabProxy::GetTabTitle(std::wstring* title) const { | 17 bool TabProxy::GetTabTitle(std::wstring* title) const { |
18 if (!is_valid()) | 18 if (!is_valid()) |
19 return false; | 19 return false; |
20 | 20 |
21 if (!title) { | 21 if (!title) { |
22 NOTREACHED(); | 22 NOTREACHED(); |
23 return false; | 23 return false; |
24 } | 24 } |
25 | 25 |
26 IPC::Message* response = NULL; | 26 IPC::Message* response = NULL; |
| 27 int tab_title_size_response; |
| 28 |
27 bool succeeded = sender_->SendAndWaitForResponse( | 29 bool succeeded = sender_->SendAndWaitForResponse( |
28 new AutomationMsg_TabTitleRequest(0, handle_), &response, | 30 new AutomationMsg_TabTitleRequest(0, handle_), &response, |
29 AutomationMsg_TabTitleResponse::ID); | 31 AutomationMsg_TabTitleResponse::ID) && |
| 32 AutomationMsg_TabTitleResponse::Read(response, &tab_title_size_response, t
itle) && |
| 33 tab_title_size_response >= 0; |
| 34 scoped_ptr<IPC::Message> auto_deleter(response); |
30 | 35 |
31 if (!succeeded) | |
32 return false; | |
33 | |
34 void* iter = NULL; | |
35 int tab_title_size_response = -1; | |
36 if (response->ReadInt(&iter, &tab_title_size_response) && | |
37 (tab_title_size_response >= 0)) { | |
38 response->ReadWString(&iter, title); | |
39 } else { | |
40 succeeded = false; | |
41 } | |
42 | |
43 delete response; | |
44 return succeeded; | 36 return succeeded; |
45 } | 37 } |
46 | 38 |
47 bool TabProxy::IsShelfVisible(bool* is_visible) { | 39 bool TabProxy::IsShelfVisible(bool* is_visible) { |
48 if (!is_valid()) | 40 if (!is_valid()) |
49 return false; | 41 return false; |
50 | 42 |
51 if (!is_visible) { | 43 if (!is_visible) { |
52 NOTREACHED(); | 44 NOTREACHED(); |
53 return false; | 45 return false; |
54 } | 46 } |
55 | 47 |
56 IPC::Message* response = NULL; | 48 IPC::Message* response = NULL; |
57 bool succeeded = sender_->SendAndWaitForResponse( | 49 bool succeeded = sender_->SendAndWaitForResponse( |
58 new AutomationMsg_ShelfVisibilityRequest(0, handle_), | 50 new AutomationMsg_ShelfVisibilityRequest(0, handle_), |
59 &response, | 51 &response, AutomationMsg_ShelfVisibilityResponse::ID) && |
60 AutomationMsg_ShelfVisibilityResponse::ID); | 52 AutomationMsg_ShelfVisibilityResponse::Read(response, is_visible); |
61 if (!succeeded) | 53 scoped_ptr<IPC::Message> auto_deleter(response); |
62 return false; | 54 return succeeded; |
63 | |
64 void* iter = NULL; | |
65 response->ReadBool(&iter, is_visible); | |
66 delete response; | |
67 return true; | |
68 } | 55 } |
69 | 56 |
70 bool TabProxy::OpenFindInPage() { | 57 bool TabProxy::OpenFindInPage() { |
71 if (!is_valid()) | 58 if (!is_valid()) |
72 return false; | 59 return false; |
73 | 60 |
74 return sender_->Send( | 61 return sender_->Send(new AutomationMsg_OpenFindInPageRequest(0, handle_)); |
75 new AutomationMsg_OpenFindInPageRequest(0, handle_)); | |
76 // This message expects no response. | 62 // This message expects no response. |
77 } | 63 } |
78 | 64 |
79 bool TabProxy::IsFindWindowFullyVisible(bool* is_visible) { | 65 bool TabProxy::IsFindWindowFullyVisible(bool* is_visible) { |
80 if (!is_valid()) | 66 if (!is_valid()) |
81 return false; | 67 return false; |
82 | 68 |
83 if (!is_visible) { | 69 if (!is_visible) { |
84 NOTREACHED(); | 70 NOTREACHED(); |
85 return false; | 71 return false; |
86 } | 72 } |
87 | 73 |
88 IPC::Message* response = NULL; | 74 IPC::Message* response = NULL; |
89 bool succeeded = sender_->SendAndWaitForResponse( | 75 bool succeeded = sender_->SendAndWaitForResponse( |
90 new AutomationMsg_FindWindowVisibilityRequest(0, handle_), | 76 new AutomationMsg_FindWindowVisibilityRequest(0, handle_), |
91 &response, | 77 &response, AutomationMsg_FindWindowVisibilityResponse::ID) && |
92 AutomationMsg_FindWindowVisibilityResponse::ID); | 78 AutomationMsg_FindWindowVisibilityResponse::Read(response, is_visible); |
93 if (!succeeded) | 79 scoped_ptr<IPC::Message> auto_deleter(response); |
94 return false; | 80 return succeeded; |
95 | |
96 void* iter = NULL; | |
97 response->ReadBool(&iter, is_visible); | |
98 delete response; | |
99 return true; | |
100 } | 81 } |
101 | 82 |
102 bool TabProxy::GetFindWindowLocation(int* x, int* y) { | 83 bool TabProxy::GetFindWindowLocation(int* x, int* y) { |
103 if (!is_valid() || !x || !y) | 84 if (!is_valid() || !x || !y) |
104 return false; | 85 return false; |
105 | 86 |
106 IPC::Message* response = NULL; | 87 IPC::Message* response = NULL; |
107 bool succeeded = sender_->SendAndWaitForResponse( | 88 bool succeeded = sender_->SendAndWaitForResponse( |
108 new AutomationMsg_FindWindowLocationRequest(0, handle_), | 89 new AutomationMsg_FindWindowLocationRequest(0, handle_), |
109 &response, | 90 &response, AutomationMsg_FindWindowLocationResponse::ID) && |
110 AutomationMsg_FindWindowLocationResponse::ID); | 91 AutomationMsg_FindWindowLocationResponse::Read(response, x, y); |
111 if (!succeeded) | 92 scoped_ptr<IPC::Message> auto_deleter(response); |
112 return false; | 93 return succeeded; |
113 | |
114 void* iter = NULL; | |
115 response->ReadInt(&iter, x); | |
116 response->ReadInt(&iter, y); | |
117 delete response; | |
118 return true; | |
119 } | 94 } |
120 | 95 |
121 int TabProxy::FindInPage(const std::wstring& search_string, | 96 int TabProxy::FindInPage(const std::wstring& search_string, |
122 FindInPageDirection forward, | 97 FindInPageDirection forward, |
123 FindInPageCase match_case, | 98 FindInPageCase match_case, |
124 bool find_next, | 99 bool find_next, |
125 int* active_ordinal) { | 100 int* ordinal) { |
126 if (!is_valid()) | 101 if (!is_valid()) |
127 return -1; | 102 return -1; |
128 | 103 |
129 FindInPageRequest request = {0}; | 104 FindInPageRequest request = {0}; |
130 request.search_string = search_string; | 105 request.search_string = search_string; |
131 request.find_next = find_next; | 106 request.find_next = find_next; |
132 // The explicit comparison to TRUE avoids a warning (C4800). | 107 // The explicit comparison to TRUE avoids a warning (C4800). |
133 request.match_case = match_case == TRUE; | 108 request.match_case = match_case == TRUE; |
134 request.forward = forward == TRUE; | 109 request.forward = forward == TRUE; |
135 | 110 |
136 IPC::Message* response = NULL; | 111 IPC::Message* response = NULL; |
| 112 int matches; |
137 bool succeeded = sender_->SendAndWaitForResponse( | 113 bool succeeded = sender_->SendAndWaitForResponse( |
138 new AutomationMsg_FindRequest(0, handle_, request), | 114 new AutomationMsg_FindRequest(0, handle_, request), |
139 &response, | 115 &response, AutomationMsg_FindInPageResponse2::ID) && |
140 AutomationMsg_FindInPageResponse2::ID); | 116 AutomationMsg_FindInPageResponse2::Read(response, ordinal, &matches); |
| 117 scoped_ptr<IPC::Message> auto_deleter(response); |
141 if (!succeeded) | 118 if (!succeeded) |
142 return -1; | 119 return -1; |
143 | 120 return matches; |
144 void* iter = NULL; | |
145 int ordinal; | |
146 int matches_found; | |
147 response->ReadInt(&iter, &ordinal); | |
148 response->ReadInt(&iter, &matches_found); | |
149 if (active_ordinal) | |
150 *active_ordinal = ordinal; | |
151 delete response; | |
152 return matches_found; | |
153 } | 121 } |
154 | 122 |
155 int TabProxy::NavigateToURL(const GURL& url) { | 123 int TabProxy::NavigateToURL(const GURL& url) { |
156 return NavigateToURLWithTimeout(url, INFINITE, NULL); | 124 return NavigateToURLWithTimeout(url, INFINITE, NULL); |
157 } | 125 } |
158 | 126 |
159 int TabProxy::NavigateToURLWithTimeout(const GURL& url, | 127 int TabProxy::NavigateToURLWithTimeout(const GURL& url, |
160 uint32 timeout_ms, | 128 uint32 timeout_ms, |
161 bool* is_timeout) { | 129 bool* is_timeout) { |
162 if (!is_valid()) | 130 if (!is_valid()) |
163 return AUTOMATION_MSG_NAVIGATION_ERROR; | 131 return AUTOMATION_MSG_NAVIGATION_ERROR; |
164 | 132 |
165 IPC::Message* response = NULL; | 133 IPC::Message* response = NULL; |
166 bool succeeded = sender_->SendAndWaitForResponseWithTimeout( | |
167 new AutomationMsg_NavigateToURLRequest(0, handle_, url), &response, | |
168 AutomationMsg_NavigateToURLResponse::ID, timeout_ms, is_timeout); | |
169 | |
170 if (!succeeded) | |
171 return AUTOMATION_MSG_NAVIGATION_ERROR; | |
172 | |
173 void* iter = NULL; | |
174 int navigate_response = AUTOMATION_MSG_NAVIGATION_ERROR; | 134 int navigate_response = AUTOMATION_MSG_NAVIGATION_ERROR; |
175 response->ReadInt(&iter, &navigate_response); | 135 if (sender_->SendAndWaitForResponseWithTimeout( |
176 | 136 new AutomationMsg_NavigateToURLRequest(0, handle_, url), &response, |
177 delete response; | 137 AutomationMsg_NavigateToURLResponse::ID, timeout_ms, is_timeout)) { |
| 138 AutomationMsg_NavigateToURLResponse::Read(response, &navigate_response); |
| 139 } |
| 140 scoped_ptr<IPC::Message> auto_deleter(response); |
178 return navigate_response; | 141 return navigate_response; |
179 } | 142 } |
180 | 143 |
181 int TabProxy::NavigateInExternalTab(const GURL& url) { | 144 int TabProxy::NavigateInExternalTab(const GURL& url) { |
182 if (!is_valid()) | 145 if (!is_valid()) |
183 return AUTOMATION_MSG_NAVIGATION_ERROR; | 146 return AUTOMATION_MSG_NAVIGATION_ERROR; |
184 | 147 |
185 IPC::Message* response = NULL; | 148 IPC::Message* response = NULL; |
186 bool is_timeout = false; | 149 bool is_timeout = false; |
187 bool succeeded = sender_->SendAndWaitForResponseWithTimeout( | 150 int rv = AUTOMATION_MSG_NAVIGATION_ERROR; |
188 new AutomationMsg_NavigateInExternalTabRequest(0, handle_, url), &response, | 151 if (sender_->SendAndWaitForResponseWithTimeout( |
189 AutomationMsg_NavigateInExternalTabResponse::ID, INFINITE, &is_timeout); | 152 new AutomationMsg_NavigateInExternalTabRequest(0, handle_, url), |
190 | 153 &response, AutomationMsg_NavigateInExternalTabResponse::ID, INFINITE, |
191 if (!succeeded) | 154 &is_timeout)) { |
192 return AUTOMATION_MSG_NAVIGATION_ERROR; | 155 AutomationMsg_NavigateInExternalTabResponse::Read(response, &rv); |
193 | 156 } |
194 void* iter = NULL; | 157 scoped_ptr<IPC::Message> auto_deleter(response); |
195 int navigate_response = AUTOMATION_MSG_NAVIGATION_ERROR; | 158 return rv; |
196 response->ReadInt(&iter, &navigate_response); | |
197 | |
198 delete response; | |
199 return navigate_response; | |
200 } | 159 } |
201 | 160 |
202 bool TabProxy::SetAuth(const std::wstring& username, | 161 bool TabProxy::SetAuth(const std::wstring& username, |
203 const std::wstring& password) { | 162 const std::wstring& password) { |
204 if (!is_valid()) | 163 if (!is_valid()) |
205 return false; | 164 return false; |
206 | 165 |
207 IPC::Message* response = NULL; | 166 IPC::Message* response = NULL; |
| 167 int navigate_response = -1; |
208 bool succeeded = sender_->SendAndWaitForResponse( | 168 bool succeeded = sender_->SendAndWaitForResponse( |
209 new AutomationMsg_SetAuthRequest(0, handle_, username, password), &response, | 169 new AutomationMsg_SetAuthRequest(0, handle_, username, password), |
210 AutomationMsg_SetAuthResponse::ID); | 170 &response, AutomationMsg_SetAuthResponse::ID) && |
211 | 171 AutomationMsg_SetAuthResponse::Read(response, &navigate_response) && |
212 if (!succeeded) | 172 navigate_response >= 0; |
213 return false; | 173 scoped_ptr<IPC::Message> auto_deleter(response); |
214 | |
215 void* iter = NULL; | |
216 int navigate_response = -1; | |
217 succeeded = (response->ReadInt(&iter, &navigate_response) && | |
218 navigate_response >= 0); | |
219 | |
220 delete response; | |
221 return succeeded; | 174 return succeeded; |
222 } | 175 } |
223 | 176 |
224 bool TabProxy::CancelAuth() { | 177 bool TabProxy::CancelAuth() { |
225 if (!is_valid()) | 178 if (!is_valid()) |
226 return false; | 179 return false; |
227 | 180 |
228 IPC::Message* response = NULL; | 181 IPC::Message* response = NULL; |
| 182 int navigate_response = -1; |
229 bool succeeded = sender_->SendAndWaitForResponse( | 183 bool succeeded = sender_->SendAndWaitForResponse( |
230 new AutomationMsg_CancelAuthRequest(0, handle_), &response, | 184 new AutomationMsg_CancelAuthRequest(0, handle_), &response, |
231 AutomationMsg_CancelAuthResponse::ID); | 185 AutomationMsg_CancelAuthResponse::ID) && |
232 | 186 AutomationMsg_CancelAuthResponse::Read(response, &navigate_response) && |
233 if (!succeeded) | 187 navigate_response >= 0; |
234 return false; | 188 scoped_ptr<IPC::Message> auto_deleter(response); |
235 | |
236 void* iter = NULL; | |
237 int navigate_response = -1; | |
238 succeeded = (response->ReadInt(&iter, &navigate_response) && | |
239 navigate_response >= 0); | |
240 | |
241 delete response; | |
242 return succeeded; | 189 return succeeded; |
243 } | 190 } |
244 | 191 |
245 bool TabProxy::NeedsAuth() const { | 192 bool TabProxy::NeedsAuth() const { |
246 if (!is_valid()) | 193 if (!is_valid()) |
247 return false; | 194 return false; |
248 | 195 |
249 IPC::Message* response = NULL; | 196 IPC::Message* response = NULL; |
| 197 bool needs_auth = false; |
250 bool succeeded = sender_->SendAndWaitForResponse( | 198 bool succeeded = sender_->SendAndWaitForResponse( |
251 new AutomationMsg_NeedsAuthRequest(0, handle_), &response, | 199 new AutomationMsg_NeedsAuthRequest(0, handle_), &response, |
252 AutomationMsg_NeedsAuthResponse::ID); | 200 AutomationMsg_NeedsAuthResponse::ID) && |
253 | 201 AutomationMsg_NeedsAuthResponse::Read(response, &needs_auth); |
254 if (!succeeded) | 202 scoped_ptr<IPC::Message> auto_deleter(response); |
255 return false; | |
256 | |
257 void* iter = NULL; | |
258 bool needs_auth = false; | |
259 response->ReadBool(&iter, &needs_auth); | |
260 | |
261 delete response; | |
262 return needs_auth; | 203 return needs_auth; |
263 } | 204 } |
264 | 205 |
265 int TabProxy::GoBack() { | 206 int TabProxy::GoBack() { |
266 if (!is_valid()) | 207 if (!is_valid()) |
267 return AUTOMATION_MSG_NAVIGATION_ERROR; | 208 return AUTOMATION_MSG_NAVIGATION_ERROR; |
268 | 209 |
269 IPC::Message* response = NULL; | 210 IPC::Message* response = NULL; |
270 bool succeeded = sender_->SendAndWaitForResponse( | |
271 new AutomationMsg_GoBackRequest(0, handle_), &response, | |
272 AutomationMsg_GoBackResponse::ID); | |
273 | |
274 if (!succeeded) | |
275 return AUTOMATION_MSG_NAVIGATION_ERROR; | |
276 | |
277 void* iter = NULL; | |
278 int navigate_response = AUTOMATION_MSG_NAVIGATION_ERROR; | 211 int navigate_response = AUTOMATION_MSG_NAVIGATION_ERROR; |
279 response->ReadInt(&iter, &navigate_response); | 212 if (sender_->SendAndWaitForResponse( |
280 | 213 new AutomationMsg_GoBackRequest(0, handle_), &response, |
281 delete response; | 214 AutomationMsg_GoBackResponse::ID)) { |
| 215 AutomationMsg_GoBackResponse::Read(response, &navigate_response); |
| 216 } |
| 217 scoped_ptr<IPC::Message> auto_deleter(response); |
282 return navigate_response; | 218 return navigate_response; |
283 } | 219 } |
284 | 220 |
285 int TabProxy::GoForward() { | 221 int TabProxy::GoForward() { |
286 if (!is_valid()) | 222 if (!is_valid()) |
287 return AUTOMATION_MSG_NAVIGATION_ERROR; | 223 return AUTOMATION_MSG_NAVIGATION_ERROR; |
288 | 224 |
289 IPC::Message* response = NULL; | 225 IPC::Message* response = NULL; |
290 bool succeeded = sender_->SendAndWaitForResponse( | |
291 new AutomationMsg_GoForwardRequest(0, handle_), &response, | |
292 AutomationMsg_GoForwardResponse::ID); | |
293 | |
294 if (!succeeded) | |
295 return AUTOMATION_MSG_NAVIGATION_ERROR; | |
296 | |
297 void* iter = NULL; | |
298 int navigate_response = AUTOMATION_MSG_NAVIGATION_ERROR; | 226 int navigate_response = AUTOMATION_MSG_NAVIGATION_ERROR; |
299 response->ReadInt(&iter, &navigate_response); | 227 if (sender_->SendAndWaitForResponse( |
300 | 228 new AutomationMsg_GoForwardRequest(0, handle_), &response, |
301 delete response; | 229 AutomationMsg_GoForwardResponse::ID)) { |
| 230 AutomationMsg_GoForwardResponse::Read(response, &navigate_response); |
| 231 } |
| 232 scoped_ptr<IPC::Message> auto_deleter(response); |
302 return navigate_response; | 233 return navigate_response; |
303 } | 234 } |
304 | 235 |
305 int TabProxy::Reload() { | 236 int TabProxy::Reload() { |
306 if (!is_valid()) | 237 if (!is_valid()) |
307 return AUTOMATION_MSG_NAVIGATION_ERROR; | 238 return AUTOMATION_MSG_NAVIGATION_ERROR; |
308 | 239 |
309 IPC::Message* response = NULL; | 240 IPC::Message* response = NULL; |
310 bool succeeded = sender_->SendAndWaitForResponse( | |
311 new AutomationMsg_ReloadRequest(0, handle_), &response, | |
312 AutomationMsg_ReloadResponse::ID); | |
313 | |
314 if (!succeeded) | |
315 return AUTOMATION_MSG_NAVIGATION_ERROR; | |
316 | |
317 void* iter = NULL; | |
318 int navigate_response = AUTOMATION_MSG_NAVIGATION_ERROR; | 241 int navigate_response = AUTOMATION_MSG_NAVIGATION_ERROR; |
319 response->ReadInt(&iter, &navigate_response); | 242 if (sender_->SendAndWaitForResponse( |
320 | 243 new AutomationMsg_ReloadRequest(0, handle_), &response, |
321 delete response; | 244 AutomationMsg_ReloadResponse::ID)) { |
| 245 AutomationMsg_ReloadResponse::Read(response, &navigate_response); |
| 246 } |
| 247 scoped_ptr<IPC::Message> auto_deleter(response); |
322 return navigate_response; | 248 return navigate_response; |
323 } | 249 } |
324 | 250 |
325 bool TabProxy::GetRedirectsFrom(const GURL& source_url, | 251 bool TabProxy::GetRedirectsFrom(const GURL& source_url, |
326 std::vector<GURL>* redirects) { | 252 std::vector<GURL>* redirects) { |
327 std::vector<GURL> output; | |
328 | |
329 IPC::Message* response = NULL; | 253 IPC::Message* response = NULL; |
330 bool succeeded = sender_->SendAndWaitForResponse( | 254 bool succeeded = sender_->SendAndWaitForResponse( |
331 new AutomationMsg_RedirectsFromRequest(0, handle_, source_url), &response, | 255 new AutomationMsg_RedirectsFromRequest(0, handle_, source_url), &response, |
332 AutomationMsg_RedirectsFromResponse::ID); | 256 AutomationMsg_RedirectsFromResponse::ID); |
333 if (!succeeded) | |
334 return false; | |
335 scoped_ptr<IPC::Message> auto_deleter(response); | 257 scoped_ptr<IPC::Message> auto_deleter(response); |
| 258 if (succeeded) { |
| 259 succeeded = AutomationMsg_RedirectsFromResponse::Read( |
| 260 response, &succeeded, redirects) && |
| 261 succeeded; |
| 262 } |
336 | 263 |
337 void* iter = NULL; | 264 return succeeded; |
338 int num_redirects; | |
339 if (!response->ReadInt(&iter, &num_redirects)) | |
340 return false; | |
341 if (num_redirects < 0) | |
342 return false; // Negative redirect counts indicate failure. | |
343 | |
344 for (int i = 0; i < num_redirects; i++) { | |
345 GURL cur; | |
346 if (!IPC::ParamTraits<GURL>::Read(response, &iter, &cur)) | |
347 return false; | |
348 output.push_back(cur); | |
349 } | |
350 redirects->swap(output); | |
351 return true; | |
352 } | 265 } |
353 | 266 |
354 bool TabProxy::GetCurrentURL(GURL* url) const { | 267 bool TabProxy::GetCurrentURL(GURL* url) const { |
355 if (!is_valid()) | 268 if (!is_valid()) |
356 return false; | 269 return false; |
357 | 270 |
358 if (!url) { | 271 if (!url) { |
359 NOTREACHED(); | 272 NOTREACHED(); |
360 return false; | 273 return false; |
361 } | 274 } |
362 | 275 |
363 IPC::Message* response = NULL; | 276 IPC::Message* response = NULL; |
364 bool succeeded = sender_->SendAndWaitForResponse( | 277 bool succeeded; |
365 new AutomationMsg_TabURLRequest(0, handle_), &response, | 278 succeeded = sender_->SendAndWaitForResponse( |
366 AutomationMsg_TabURLResponse::ID); | 279 new AutomationMsg_TabURLRequest(0, handle_), &response, |
367 | 280 AutomationMsg_TabURLResponse::ID) && |
368 if (!succeeded) | 281 AutomationMsg_TabURLResponse::Read(response, &succeeded, url); |
369 return false; | 282 scoped_ptr<IPC::Message> auto_deleter(response); |
370 | |
371 void* iter = NULL; | |
372 bool tab_url_success = false; | |
373 if (response->ReadBool(&iter, &tab_url_success) && tab_url_success) { | |
374 if (!IPC::ParamTraits<GURL>::Read(response, &iter, url)) | |
375 succeeded = false; | |
376 } else { | |
377 succeeded = false; | |
378 } | |
379 | |
380 delete response; | |
381 return succeeded; | 283 return succeeded; |
382 } | 284 } |
383 | 285 |
384 bool TabProxy::NavigateToURLAsync(const GURL& url) { | 286 bool TabProxy::NavigateToURLAsync(const GURL& url) { |
385 if (!is_valid()) | 287 if (!is_valid()) |
386 return false; | 288 return false; |
387 | 289 |
388 IPC::Message* response = NULL; | 290 IPC::Message* response = NULL; |
389 bool succeeded = sender_->SendAndWaitForResponse( | 291 bool status = false; |
390 new AutomationMsg_NavigationAsyncRequest(0, handle_, url), &response, | 292 if (sender_->SendAndWaitForResponse( |
391 AutomationMsg_NavigationAsyncResponse::ID); | 293 new AutomationMsg_NavigationAsyncRequest(0, handle_, url), &response, |
392 | 294 AutomationMsg_NavigationAsyncResponse::ID)) { |
393 if (!succeeded) | 295 AutomationMsg_NavigationAsyncResponse::Read(response, &status); |
394 return false; | |
395 | |
396 bool status; | |
397 if (AutomationMsg_NavigationAsyncResponse::Read(response, &status) && | |
398 status) { | |
399 succeeded = true; | |
400 } | 296 } |
401 | 297 scoped_ptr<IPC::Message> auto_deleter(response); |
402 delete response; | 298 return status; |
403 return succeeded; | |
404 } | 299 } |
405 | 300 |
406 bool TabProxy::GetHWND(HWND* hwnd) const { | 301 bool TabProxy::GetHWND(HWND* hwnd) const { |
407 if (!is_valid()) | 302 if (!is_valid()) |
408 return false; | 303 return false; |
409 if (!hwnd) { | 304 if (!hwnd) { |
410 NOTREACHED(); | 305 NOTREACHED(); |
411 return false; | 306 return false; |
412 } | 307 } |
413 IPC::Message* response = NULL; | 308 IPC::Message* response = NULL; |
414 bool succeeded = sender_->SendAndWaitForResponse( | |
415 new AutomationMsg_TabHWNDRequest(0, handle_), &response, | |
416 AutomationMsg_TabHWNDResponse::ID); | |
417 if (!succeeded) | |
418 return false; | |
419 void* iter = NULL; | |
420 HWND tab_hwnd = NULL; | 309 HWND tab_hwnd = NULL; |
421 if (AutomationMsg_TabHWNDResponse::Read(response, &tab_hwnd) && tab_hwnd) { | 310 bool succeeded = false; |
422 *hwnd = tab_hwnd; | 311 if (sender_->SendAndWaitForResponse( |
423 } else { | 312 new AutomationMsg_TabHWNDRequest(0, handle_), &response, |
424 succeeded = false; | 313 AutomationMsg_TabHWNDResponse::ID)) { |
| 314 succeeded = AutomationMsg_TabHWNDResponse::Read(response, &tab_hwnd); |
425 } | 315 } |
426 | 316 scoped_ptr<IPC::Message> auto_deleter(response); |
427 delete response; | |
428 return succeeded; | 317 return succeeded; |
429 } | 318 } |
430 | 319 |
431 bool TabProxy::GetProcessID(int* process_id) const { | 320 bool TabProxy::GetProcessID(int* process_id) const { |
432 if (!is_valid()) | 321 if (!is_valid()) |
433 return false; | 322 return false; |
434 | 323 |
435 if (!process_id) { | 324 if (!process_id) { |
436 NOTREACHED(); | 325 NOTREACHED(); |
437 return false; | 326 return false; |
438 } | 327 } |
439 | 328 |
440 IPC::Message* response = NULL; | 329 IPC::Message* response = NULL; |
441 bool succeeded = sender_->SendAndWaitForResponse( | 330 bool succeeded = false; |
442 new AutomationMsg_TabProcessIDRequest(0, handle_), &response, | 331 if (sender_->SendAndWaitForResponse( |
443 AutomationMsg_TabProcessIDResponse::ID); | 332 new AutomationMsg_TabProcessIDRequest(0, handle_), &response, |
444 | 333 AutomationMsg_TabProcessIDResponse::ID)) { |
445 if (!succeeded) | 334 succeeded = AutomationMsg_TabProcessIDResponse::Read(response, process_id); |
446 return false; | |
447 | |
448 void* iter = NULL; | |
449 int pid; | |
450 if (AutomationMsg_TabProcessIDResponse::Read(response, &pid) && (pid >= 0)) { | |
451 *process_id = pid; | |
452 } else { | |
453 succeeded = false; | |
454 } | 335 } |
455 | 336 scoped_ptr<IPC::Message> auto_deleter(response); |
456 delete response; | |
457 return succeeded; | 337 return succeeded; |
458 } | 338 } |
459 | 339 |
460 bool TabProxy::ExecuteAndExtractString(const std::wstring& frame_xpath, | 340 bool TabProxy::ExecuteAndExtractString(const std::wstring& frame_xpath, |
461 const std::wstring& jscript, | 341 const std::wstring& jscript, |
462 std::wstring* string_value) { | 342 std::wstring* string_value) { |
463 Value* root = NULL; | 343 Value* root = NULL; |
464 bool succeeded = ExecuteAndExtractValue(frame_xpath, jscript, &root); | 344 bool succeeded = ExecuteAndExtractValue(frame_xpath, jscript, &root); |
465 if (!succeeded) | 345 if (!succeeded) |
466 return false; | 346 return false; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 | 414 |
535 if (!value) { | 415 if (!value) { |
536 NOTREACHED(); | 416 NOTREACHED(); |
537 return false; | 417 return false; |
538 } | 418 } |
539 | 419 |
540 IPC::Message* response = NULL; | 420 IPC::Message* response = NULL; |
541 bool succeeded = sender_->SendAndWaitForResponse( | 421 bool succeeded = sender_->SendAndWaitForResponse( |
542 new AutomationMsg_DomOperationRequest(0, handle_, frame_xpath, jscript), | 422 new AutomationMsg_DomOperationRequest(0, handle_, frame_xpath, jscript), |
543 &response, AutomationMsg_DomOperationResponse::ID); | 423 &response, AutomationMsg_DomOperationResponse::ID); |
544 | |
545 void* iter = NULL; | |
546 std::string json; | 424 std::string json; |
547 succeeded = response->ReadString(&iter, &json); | 425 if (succeeded) |
548 if (!succeeded) { | 426 succeeded = AutomationMsg_DomOperationResponse::Read(response, &json); |
549 delete response; | 427 scoped_ptr<IPC::Message> auto_deleter(response); |
| 428 if (!succeeded) |
550 return false; | 429 return false; |
551 } | |
552 // Wrap |json| in an array before deserializing because valid JSON has an | 430 // Wrap |json| in an array before deserializing because valid JSON has an |
553 // array or an object as the root. | 431 // array or an object as the root. |
554 json.insert(0, "["); | 432 json.insert(0, "["); |
555 json.append("]"); | 433 json.append("]"); |
556 | 434 |
557 JSONStringValueSerializer deserializer(json); | 435 JSONStringValueSerializer deserializer(json); |
558 *value = deserializer.Deserialize(NULL); | 436 *value = deserializer.Deserialize(NULL); |
559 | |
560 delete response; | |
561 return *value != NULL; | 437 return *value != NULL; |
562 } | 438 } |
563 | 439 |
564 bool TabProxy::GetConstrainedWindowCount(int* count) const { | 440 bool TabProxy::GetConstrainedWindowCount(int* count) const { |
565 if (!is_valid()) | 441 if (!is_valid()) |
566 return false; | 442 return false; |
567 | 443 |
568 if (!count) { | 444 if (!count) { |
569 NOTREACHED(); | 445 NOTREACHED(); |
570 return false; | 446 return false; |
571 } | 447 } |
572 | 448 |
573 IPC::Message* response = NULL; | 449 IPC::Message* response = NULL; |
574 bool succeeded = sender_->SendAndWaitForResponse( | 450 bool succeeded = sender_->SendAndWaitForResponse( |
575 new AutomationMsg_ConstrainedWindowCountRequest(0, handle_), | 451 new AutomationMsg_ConstrainedWindowCountRequest(0, handle_), |
576 &response, AutomationMsg_ConstrainedWindowCountResponse::ID); | 452 &response, AutomationMsg_ConstrainedWindowCountResponse::ID) && |
577 | 453 AutomationMsg_ConstrainedWindowCountResponse::Read(response, count); |
578 void* iter = NULL; | 454 scoped_ptr<IPC::Message> auto_deleter(response); |
579 int count_response = -1; | |
580 if (response->ReadInt(&iter, &count_response) && | |
581 (count_response >= 0)) { | |
582 *count = count_response; | |
583 } else { | |
584 succeeded = false; | |
585 } | |
586 | |
587 delete response; | |
588 return succeeded; | 455 return succeeded; |
589 } | 456 } |
590 | 457 |
591 ConstrainedWindowProxy* TabProxy::GetConstrainedWindow( | 458 ConstrainedWindowProxy* TabProxy::GetConstrainedWindow( |
592 int window_index) const { | 459 int window_index) const { |
593 if (!is_valid()) | 460 if (!is_valid()) |
594 return NULL; | 461 return NULL; |
595 | 462 |
596 IPC::Message* response = NULL; | 463 IPC::Message* response = NULL; |
597 bool succeeded = sender_->SendAndWaitForResponse( | |
598 new AutomationMsg_ConstrainedWindowRequest(0, handle_, window_index), | |
599 &response, AutomationMsg_ConstrainedWindowResponse::ID); | |
600 if (!succeeded) | |
601 return NULL; | |
602 | |
603 void* iter = NULL; | |
604 int handle; | 464 int handle; |
605 | 465 if (sender_->SendAndWaitForResponse( |
606 scoped_ptr<IPC::Message> response_deleter(response); // Ensure deleted. | 466 new AutomationMsg_ConstrainedWindowRequest(0, handle_, window_index), |
607 if (response->ReadInt(&iter, &handle) && (handle != 0)) | 467 &response, AutomationMsg_ConstrainedWindowResponse::ID)) { |
608 return new ConstrainedWindowProxy(sender_, tracker_, handle); | 468 scoped_ptr<IPC::Message> response_deleter(response); |
| 469 if (AutomationMsg_ConstrainedWindowResponse::Read(response, &handle)) |
| 470 return new ConstrainedWindowProxy(sender_, tracker_, handle); |
| 471 } |
609 return NULL; | 472 return NULL; |
610 } | 473 } |
611 | 474 |
612 bool TabProxy::WaitForChildWindowCountToChange(int count, int* new_count, | 475 bool TabProxy::WaitForChildWindowCountToChange(int count, int* new_count, |
613 int wait_timeout) { | 476 int wait_timeout) { |
614 int intervals = std::min(wait_timeout/automation::kSleepTime, 1); | 477 int intervals = std::min(wait_timeout/automation::kSleepTime, 1); |
615 for (int i = 0; i < intervals; ++i) { | 478 for (int i = 0; i < intervals; ++i) { |
616 Sleep(automation::kSleepTime); | 479 Sleep(automation::kSleepTime); |
617 bool succeeded = GetConstrainedWindowCount(new_count); | 480 bool succeeded = GetConstrainedWindowCount(new_count); |
618 if (!succeeded) return false; | 481 if (!succeeded) return false; |
619 if (count != *new_count) return true; | 482 if (count != *new_count) return true; |
620 } | 483 } |
621 // Constrained Window count did not change, return false. | 484 // Constrained Window count did not change, return false. |
622 return false; | 485 return false; |
623 } | 486 } |
624 | 487 |
625 bool TabProxy::GetCookies(const GURL& url, std::string* cookies) { | 488 bool TabProxy::GetCookies(const GURL& url, std::string* cookies) { |
626 if (!is_valid()) | 489 if (!is_valid()) |
627 return false; | 490 return false; |
628 | 491 |
629 IPC::Message* response = NULL; | 492 IPC::Message* response = NULL; |
| 493 int size; |
630 bool succeeded = sender_->SendAndWaitForResponse( | 494 bool succeeded = sender_->SendAndWaitForResponse( |
631 new AutomationMsg_GetCookiesRequest(0, url, handle_), &response, | 495 new AutomationMsg_GetCookiesRequest(0, url, handle_), &response, |
632 AutomationMsg_GetCookiesResponse::ID); | 496 AutomationMsg_GetCookiesResponse::ID) && |
633 | 497 AutomationMsg_GetCookiesResponse::Read(response, &size, cookies) && |
634 if (succeeded) { | 498 size >= 0; |
635 void* iter = NULL; | 499 scoped_ptr<IPC::Message> response_deleter(response); |
636 int size; | |
637 std::string local_value; | |
638 | |
639 if (response->ReadInt(&iter, &size) && size >=0) { | |
640 if (!response->ReadString(&iter, cookies)) { | |
641 succeeded = false; | |
642 } | |
643 } else { | |
644 succeeded = false; | |
645 } | |
646 } | |
647 | |
648 delete response; | |
649 return succeeded; | 500 return succeeded; |
650 } | 501 } |
651 | 502 |
652 bool TabProxy::GetCookieByName(const GURL& url, | 503 bool TabProxy::GetCookieByName(const GURL& url, |
653 const std::string& name, | 504 const std::string& name, |
654 std::string* cookie) { | 505 std::string* cookie) { |
655 std::string cookies; | 506 std::string cookies; |
656 if (!GetCookies(url, &cookies)) | 507 if (!GetCookies(url, &cookies)) |
657 return false; | 508 return false; |
658 | 509 |
659 std::string namestr = name + "="; | 510 std::string namestr = name + "="; |
660 std::string::size_type idx = cookies.find(namestr); | 511 std::string::size_type idx = cookies.find(namestr); |
661 if (idx != std::string::npos) { | 512 if (idx != std::string::npos) { |
662 cookies.erase(0, idx + namestr.length()); | 513 cookies.erase(0, idx + namestr.length()); |
663 *cookie = cookies.substr(0, cookies.find(";")); | 514 *cookie = cookies.substr(0, cookies.find(";")); |
664 } else { | 515 } else { |
665 cookie->clear(); | 516 cookie->clear(); |
666 } | 517 } |
667 | 518 |
668 return true; | 519 return true; |
669 } | 520 } |
670 | 521 |
671 bool TabProxy::SetCookie(const GURL& url, const std::string& value) { | 522 bool TabProxy::SetCookie(const GURL& url, const std::string& value) { |
672 IPC::Message* response = NULL; | 523 IPC::Message* response = NULL; |
| 524 int response_value; |
673 bool succeeded = sender_->SendAndWaitForResponse( | 525 bool succeeded = sender_->SendAndWaitForResponse( |
674 new AutomationMsg_SetCookieRequest(0, url, value, handle_), &response, | 526 new AutomationMsg_SetCookieRequest(0, url, value, handle_), &response, |
675 AutomationMsg_SetCookieResponse::ID); | 527 AutomationMsg_SetCookieResponse::ID) && |
676 if (!succeeded) | 528 AutomationMsg_SetCookieResponse::Read(response, &response_value) && |
677 return false; | 529 response_value >= 0; |
678 | 530 scoped_ptr<IPC::Message> response_deleter(response); |
679 void* iter = NULL; | |
680 int response_value; | |
681 | |
682 if (!response->ReadInt(&iter, &response_value) || response_value < 0) { | |
683 succeeded = false; | |
684 } | |
685 | |
686 delete response; | |
687 return succeeded; | 531 return succeeded; |
688 } | 532 } |
689 | 533 |
690 int TabProxy::InspectElement(int x, int y) { | 534 int TabProxy::InspectElement(int x, int y) { |
691 if (!is_valid()) | 535 if (!is_valid()) |
692 return -1; | 536 return -1; |
693 | 537 |
694 IPC::Message* response = NULL; | 538 IPC::Message* response = NULL; |
695 bool succeeded = sender_->SendAndWaitForResponse( | 539 int ret = -1; |
| 540 if (sender_->SendAndWaitForResponse( |
696 new AutomationMsg_InspectElementRequest(0, handle_, x, y), | 541 new AutomationMsg_InspectElementRequest(0, handle_, x, y), |
697 &response, AutomationMsg_InspectElementResponse::ID); | 542 &response, AutomationMsg_InspectElementResponse::ID)) { |
698 if (!succeeded) | 543 AutomationMsg_InspectElementResponse::Read(response, &ret); |
699 return -1; | 544 } |
700 | 545 scoped_ptr<IPC::Message> response_deleter(response); |
701 int ret; | |
702 AutomationMsg_InspectElementResponse::Read(response, &ret); | |
703 return ret; | 546 return ret; |
704 } | 547 } |
705 | 548 |
706 bool TabProxy::GetDownloadDirectory(std::wstring* download_directory) { | 549 bool TabProxy::GetDownloadDirectory(std::wstring* directory) { |
707 DCHECK(download_directory); | 550 DCHECK(directory); |
708 if (!is_valid()) | 551 if (!is_valid()) |
709 return false; | 552 return false; |
710 | 553 |
711 IPC::Message* response = NULL; | 554 IPC::Message* response = NULL; |
712 bool succeeded = | 555 bool succeeded = sender_->SendAndWaitForResponse( |
713 sender_->SendAndWaitForResponse( | 556 new AutomationMsg_DownloadDirectoryRequest(0, handle_), &response, |
714 new AutomationMsg_DownloadDirectoryRequest(0, handle_), | 557 AutomationMsg_DownloadDirectoryResponse::ID) && |
715 &response, | 558 AutomationMsg_DownloadDirectoryResponse::Read(response, directory); |
716 AutomationMsg_DownloadDirectoryResponse::ID); | 559 scoped_ptr<IPC::Message> response_deleter(response); |
717 if (!succeeded) | 560 return succeeded; |
718 return false; | |
719 | |
720 void* iter = NULL; | |
721 response->ReadWString(&iter, download_directory); | |
722 delete response; | |
723 return true; | |
724 } | 561 } |
725 | 562 |
726 bool TabProxy::ShowInterstitialPage(const std::string& html_text, | 563 bool TabProxy::ShowInterstitialPage(const std::string& html_text, |
727 int timeout_ms) { | 564 int timeout_ms) { |
728 if (!is_valid()) | 565 if (!is_valid()) |
729 return false; | 566 return false; |
730 | 567 |
731 bool is_timeout = false; | 568 bool is_timeout = false; |
732 IPC::Message* response = NULL; | 569 IPC::Message* response = NULL; |
733 bool succeeded = sender_->SendAndWaitForResponseWithTimeout( | 570 bool succeeded = sender_->SendAndWaitForResponseWithTimeout( |
734 new AutomationMsg_ShowInterstitialPageRequest(0, handle_, html_text), | 571 new AutomationMsg_ShowInterstitialPageRequest(0, handle_, html_text), |
735 &response, | 572 &response, AutomationMsg_ShowInterstitialPageResponse::ID, timeout_ms, |
736 AutomationMsg_ShowInterstitialPageResponse::ID, timeout_ms, &is_timeout); | 573 &is_timeout) && |
737 | 574 AutomationMsg_ShowInterstitialPageResponse::Read(response, &succeeded) && |
738 if (!succeeded || !is_timeout) | 575 succeeded; |
739 return false; | 576 scoped_ptr<IPC::Message> response_deleter(response); |
740 | 577 return succeeded; |
741 void* iter = NULL; | |
742 bool result = true; | |
743 response->ReadBool(&iter, &result); | |
744 | |
745 delete response; | |
746 return result; | |
747 } | 578 } |
748 | 579 |
749 bool TabProxy::HideInterstitialPage() { | 580 bool TabProxy::HideInterstitialPage() { |
750 if (!is_valid()) | 581 if (!is_valid()) |
751 return false; | 582 return false; |
752 | 583 |
753 IPC::Message* response = NULL; | 584 IPC::Message* response = NULL; |
754 bool succeeded = | 585 bool result; |
755 sender_->SendAndWaitForResponse( | 586 bool succeeded = sender_->SendAndWaitForResponse( |
756 new AutomationMsg_HideInterstitialPageRequest(0, handle_), | 587 new AutomationMsg_HideInterstitialPageRequest(0, handle_), |
757 &response, | 588 &response, AutomationMsg_HideInterstitialPageResponse::ID) && |
758 AutomationMsg_HideInterstitialPageResponse::ID); | 589 AutomationMsg_HideInterstitialPageResponse::Read(response, &result) && |
759 | 590 result; |
760 if (!succeeded) | 591 scoped_ptr<IPC::Message> response_deleter(response); |
761 return false; | 592 return succeeded; |
762 | |
763 void* iter = NULL; | |
764 bool result = true; | |
765 response->ReadBool(&iter, &result); | |
766 | |
767 delete response; | |
768 return result; | |
769 } | 593 } |
770 | 594 |
771 bool TabProxy::Close() { | 595 bool TabProxy::Close() { |
772 return Close(false); | 596 return Close(false); |
773 } | 597 } |
774 | 598 |
775 bool TabProxy::Close(bool wait_until_closed) { | 599 bool TabProxy::Close(bool wait_until_closed) { |
776 if (!is_valid()) | 600 if (!is_valid()) |
777 return false; | 601 return false; |
778 | 602 |
779 IPC::Message* response = NULL; | 603 IPC::Message* response = NULL; |
780 bool succeeded = | 604 bool succeeded = sender_->SendAndWaitForResponse( |
781 sender_->SendAndWaitForResponse( | 605 new AutomationMsg_CloseTabRequest(0, handle_, wait_until_closed), |
782 new AutomationMsg_CloseTabRequest(0, handle_, wait_until_closed), | 606 &response, AutomationMsg_CloseTabResponse::ID) && |
783 &response, | 607 AutomationMsg_CloseTabResponse::Read(response, &succeeded) && |
784 AutomationMsg_CloseTabResponse::ID); | 608 succeeded; |
785 | 609 scoped_ptr<IPC::Message> response_deleter(response); |
786 if (!succeeded) | 610 return succeeded; |
787 return false; | |
788 | |
789 void* iter = NULL; | |
790 bool result = true; | |
791 response->ReadBool(&iter, &result); | |
792 | |
793 delete response; | |
794 return result; | |
795 } | 611 } |
796 | 612 |
797 bool TabProxy::SetAccelerators(HACCEL accel_table, | 613 bool TabProxy::SetAccelerators(HACCEL accel_table, |
798 int accel_table_entry_count) { | 614 int accel_table_entry_count) { |
799 if (!is_valid()) | 615 if (!is_valid()) |
800 return false; | 616 return false; |
801 | 617 |
802 IPC::Message* response = NULL; | 618 IPC::Message* response = NULL; |
803 bool is_timeout = false; | 619 bool is_timeout = false; |
804 bool succeeded = sender_->SendAndWaitForResponseWithTimeout( | 620 bool succeeded = sender_->SendAndWaitForResponseWithTimeout( |
805 new AutomationMsg_SetAcceleratorsForTab(0, handle_, accel_table, | 621 new AutomationMsg_SetAcceleratorsForTab( |
806 accel_table_entry_count), | 622 0, handle_, accel_table, accel_table_entry_count), |
807 &response, | 623 &response, AutomationMsg_SetAcceleratorsForTabResponse::ID, INFINITE, |
808 AutomationMsg_SetAcceleratorsForTabResponse::ID, INFINITE, &is_timeout); | 624 &is_timeout) && |
809 | 625 AutomationMsg_SetAcceleratorsForTabResponse::Read(response, &succeeded) && |
810 if (!succeeded) | 626 succeeded; |
811 return AUTOMATION_MSG_NAVIGATION_ERROR; | 627 scoped_ptr<IPC::Message> response_deleter(response); |
812 | 628 return succeeded; |
813 void* iter = NULL; | |
814 bool set_accel_response = false; | |
815 response->ReadBool(&iter, &set_accel_response); | |
816 | |
817 delete response; | |
818 return set_accel_response; | |
819 } | 629 } |
820 | 630 |
821 bool TabProxy::ProcessUnhandledAccelerator(const MSG& msg) { | 631 bool TabProxy::ProcessUnhandledAccelerator(const MSG& msg) { |
822 if (!is_valid()) | 632 if (!is_valid()) |
823 return false; | 633 return false; |
824 return sender_->Send( | 634 return sender_->Send( |
825 new AutomationMsg_ProcessUnhandledAccelerator(0, handle_, msg)); | 635 new AutomationMsg_ProcessUnhandledAccelerator(0, handle_, msg)); |
826 // This message expects no response | 636 // This message expects no response |
827 } | 637 } |
828 | 638 |
829 bool TabProxy::WaitForTabToBeRestored(uint32 timeout_ms) { | 639 bool TabProxy::WaitForTabToBeRestored(uint32 timeout_ms) { |
830 if (!is_valid()) | 640 if (!is_valid()) |
831 return false; | 641 return false; |
832 IPC::Message* response = NULL; | 642 IPC::Message* response = NULL; |
833 bool is_timeout; | 643 bool is_timeout; |
834 return sender_->SendAndWaitForResponseWithTimeout( | 644 bool succeeded = sender_->SendAndWaitForResponseWithTimeout( |
835 new AutomationMsg_WaitForTabToBeRestored(0, handle_), &response, | 645 new AutomationMsg_WaitForTabToBeRestored(0, handle_), &response, |
836 AutomationMsg_TabFinishedRestoring::ID, timeout_ms, &is_timeout); | 646 AutomationMsg_TabFinishedRestoring::ID, timeout_ms, &is_timeout); |
| 647 scoped_ptr<IPC::Message> response_deleter(response); |
| 648 return succeeded; |
837 } | 649 } |
838 | 650 |
839 bool TabProxy::GetSecurityState(SecurityStyle* security_style, | 651 bool TabProxy::GetSecurityState(SecurityStyle* security_style, |
840 int* ssl_cert_status, | 652 int* ssl_cert_status, |
841 int* mixed_content_state) { | 653 int* mixed_content_state) { |
842 DCHECK(security_style && ssl_cert_status && mixed_content_state); | 654 DCHECK(security_style && ssl_cert_status && mixed_content_state); |
843 | 655 |
844 if (!is_valid()) | 656 if (!is_valid()) |
845 return false; | 657 return false; |
846 | 658 |
847 IPC::Message* response = NULL; | 659 IPC::Message* response = NULL; |
848 bool is_timeout = false; | 660 bool is_timeout = false; |
849 bool succeeded = sender_->SendAndWaitForResponseWithTimeout( | 661 int value; |
| 662 bool succeeded; |
| 663 succeeded = sender_->SendAndWaitForResponseWithTimeout( |
850 new AutomationMsg_GetSecurityState(0, handle_), | 664 new AutomationMsg_GetSecurityState(0, handle_), |
851 &response, | 665 &response, |
852 AutomationMsg_GetSecurityStateResponse::ID, INFINITE, &is_timeout); | 666 AutomationMsg_GetSecurityStateResponse::ID, INFINITE, &is_timeout) && |
| 667 AutomationMsg_GetSecurityStateResponse::Read( |
| 668 response, &succeeded, &value, ssl_cert_status, mixed_content_state); |
| 669 if (succeeded) |
| 670 *security_style = static_cast<SecurityStyle>(value); |
853 scoped_ptr<IPC::Message> auto_deleter(response); | 671 scoped_ptr<IPC::Message> auto_deleter(response); |
854 | 672 return succeeded; |
855 if (!succeeded) | |
856 return false; | |
857 | |
858 void* iter = NULL; | |
859 int value; | |
860 | |
861 response->ReadBool(&iter, &succeeded); | |
862 if (!succeeded) | |
863 return false; | |
864 response->ReadInt(&iter, &value); | |
865 *security_style = static_cast<SecurityStyle>(value); | |
866 response->ReadInt(&iter, ssl_cert_status); | |
867 response->ReadInt(&iter, mixed_content_state); | |
868 | |
869 return true; | |
870 } | 673 } |
871 | 674 |
872 bool TabProxy::GetPageType(NavigationEntry::PageType* page_type) { | 675 bool TabProxy::GetPageType(NavigationEntry::PageType* page_type) { |
873 DCHECK(page_type); | 676 DCHECK(page_type); |
874 | 677 |
875 if (!is_valid()) | 678 if (!is_valid()) |
876 return false; | 679 return false; |
877 | 680 |
878 IPC::Message* response = NULL; | 681 IPC::Message* response = NULL; |
879 bool is_timeout = false; | 682 bool is_timeout = false; |
880 bool succeeded = sender_->SendAndWaitForResponseWithTimeout( | 683 int value; |
| 684 bool succeeded; |
| 685 succeeded = sender_->SendAndWaitForResponseWithTimeout( |
881 new AutomationMsg_GetPageType(0, handle_), | 686 new AutomationMsg_GetPageType(0, handle_), |
882 &response, | 687 &response, |
883 AutomationMsg_GetPageTypeResponse::ID, INFINITE, &is_timeout); | 688 AutomationMsg_GetPageTypeResponse::ID, INFINITE, &is_timeout) && |
| 689 AutomationMsg_GetPageTypeResponse::Read(response, &succeeded, &value); |
884 scoped_ptr<IPC::Message> auto_deleter(response); | 690 scoped_ptr<IPC::Message> auto_deleter(response); |
885 | 691 if (succeeded) |
886 if (!succeeded) | 692 *page_type = static_cast<NavigationEntry::PageType>(value); |
887 return false; | 693 return succeeded; |
888 | |
889 void* iter = NULL; | |
890 int value; | |
891 response->ReadBool(&iter, &succeeded); | |
892 if (!succeeded) | |
893 return false; | |
894 response->ReadInt(&iter, &value); | |
895 *page_type = static_cast<NavigationEntry::PageType>(value); | |
896 return true; | |
897 } | 694 } |
898 | 695 |
899 bool TabProxy::TakeActionOnSSLBlockingPage(bool proceed) { | 696 bool TabProxy::TakeActionOnSSLBlockingPage(bool proceed) { |
900 if (!is_valid()) | 697 if (!is_valid()) |
901 return false; | 698 return false; |
902 | 699 |
903 IPC::Message* response = NULL; | 700 IPC::Message* response = NULL; |
904 bool is_timeout = false; | 701 bool timeout = false; |
905 bool succeeded = sender_->SendAndWaitForResponseWithTimeout( | 702 bool success = sender_->SendAndWaitForResponseWithTimeout( |
906 new AutomationMsg_ActionOnSSLBlockingPage(0, handle_, proceed), | 703 new AutomationMsg_ActionOnSSLBlockingPage(0, handle_, proceed), |
907 &response, | 704 &response, |
908 AutomationMsg_ActionOnSSLBlockingPageResponse::ID, INFINITE, &is_timeout); | 705 AutomationMsg_ActionOnSSLBlockingPageResponse::ID, INFINITE, &timeout) && |
| 706 AutomationMsg_ActionOnSSLBlockingPageResponse::Read(response, &success) && |
| 707 success; |
909 scoped_ptr<IPC::Message> auto_deleter(response); | 708 scoped_ptr<IPC::Message> auto_deleter(response); |
910 | 709 return success; |
911 if (!succeeded) | |
912 return false; | |
913 | |
914 void* iter = NULL; | |
915 bool status = false; | |
916 response->ReadBool(&iter, &status); | |
917 | |
918 return status; | |
919 } | 710 } |
920 | 711 |
921 bool TabProxy::PrintNow() { | 712 bool TabProxy::PrintNow() { |
922 if (!is_valid()) | 713 if (!is_valid()) |
923 return false; | 714 return false; |
924 | 715 |
925 IPC::Message* response = NULL; | 716 IPC::Message* response = NULL; |
926 bool succeeded = sender_->SendAndWaitForResponse( | 717 bool succeeded = sender_->SendAndWaitForResponse( |
927 new AutomationMsg_PrintNowRequest(0, handle_), &response, | 718 new AutomationMsg_PrintNowRequest(0, handle_), &response, |
928 AutomationMsg_PrintNowResponse::ID); | 719 AutomationMsg_PrintNowResponse::ID) && |
| 720 AutomationMsg_PrintNowResponse::Read(response, &succeeded) && |
| 721 succeeded; |
929 scoped_ptr<IPC::Message> auto_deleter(response); | 722 scoped_ptr<IPC::Message> auto_deleter(response); |
930 if (!succeeded) | 723 return succeeded; |
931 return false; | |
932 | |
933 void* iter = NULL; | |
934 succeeded = false; | |
935 return response->ReadBool(&iter, &succeeded) && succeeded; | |
936 } | 724 } |
937 | 725 |
938 bool TabProxy::SavePage(const std::wstring& file_name, | 726 bool TabProxy::SavePage(const std::wstring& file_name, |
939 const std::wstring& dir_path, | 727 const std::wstring& dir_path, |
940 SavePackage::SavePackageType type) { | 728 SavePackage::SavePackageType type) { |
941 if (!is_valid()) | 729 if (!is_valid()) |
942 return false; | 730 return false; |
943 | 731 |
944 IPC::Message* response = NULL; | 732 IPC::Message* response = NULL; |
945 bool succeeded = sender_->SendAndWaitForResponse( | 733 bool succeeded = sender_->SendAndWaitForResponse( |
946 new AutomationMsg_SavePageRequest(0, handle_, file_name, | 734 new AutomationMsg_SavePageRequest( |
947 dir_path, static_cast<int>(type)), | 735 0, handle_, file_name, dir_path, static_cast<int>(type)), |
948 &response, | 736 &response, AutomationMsg_SavePageResponse::ID) && |
949 AutomationMsg_SavePageResponse::ID); | 737 AutomationMsg_SavePageResponse::Read(response, &succeeded) && |
950 | 738 succeeded; |
951 if (!succeeded) | 739 scoped_ptr<IPC::Message> auto_deleter(response); |
952 return false; | |
953 | |
954 void* iter = NULL; | |
955 response->ReadBool(&iter, &succeeded); | |
956 delete response; | |
957 | |
958 return succeeded; | 740 return succeeded; |
959 } | 741 } |
960 | 742 |
961 void TabProxy::HandleMessageFromExternalHost(AutomationHandle handle, | 743 void TabProxy::HandleMessageFromExternalHost(AutomationHandle handle, |
962 const std::string& target, | 744 const std::string& target, |
963 const std::string& message) { | 745 const std::string& message) { |
964 if (!is_valid()) | 746 if (!is_valid()) |
965 return; | 747 return; |
966 | 748 |
967 bool succeeded = | 749 bool succeeded = |
968 sender_->Send(new AutomationMsg_HandleMessageFromExternalHost(0, handle, | 750 sender_->Send(new AutomationMsg_HandleMessageFromExternalHost(0, handle, |
969 target, | 751 target, |
970 message)); | 752 message)); |
971 DCHECK(succeeded); | 753 DCHECK(succeeded); |
972 } | 754 } |
973 | 755 |
974 bool TabProxy::GetSSLInfoBarCount(int* count) { | 756 bool TabProxy::GetSSLInfoBarCount(int* count) { |
975 if (!is_valid()) | 757 if (!is_valid()) |
976 return false; | 758 return false; |
977 | 759 |
978 IPC::Message* response = NULL; | 760 IPC::Message* response = NULL; |
979 bool success = sender_->SendAndWaitForResponse( | 761 bool success = sender_->SendAndWaitForResponse( |
980 new AutomationMsg_GetSSLInfoBarCountRequest(0, handle_), | 762 new AutomationMsg_GetSSLInfoBarCountRequest(0, handle_), |
981 &response, | 763 &response, AutomationMsg_GetSSLInfoBarCountResponse::ID) && |
982 AutomationMsg_GetSSLInfoBarCountResponse::ID); | 764 AutomationMsg_GetSSLInfoBarCountResponse::Read(response, count) && |
| 765 count >= 0; |
983 scoped_ptr<IPC::Message> auto_deleter(response); | 766 scoped_ptr<IPC::Message> auto_deleter(response); |
984 if (!success) | 767 return success; |
985 return false; | |
986 | |
987 void* iter = NULL; | |
988 response->ReadInt(&iter, count); | |
989 return true; | |
990 } | 768 } |
991 | 769 |
992 bool TabProxy::ClickSSLInfoBarLink(int info_bar_index, | 770 bool TabProxy::ClickSSLInfoBarLink(int info_bar_index, |
993 bool wait_for_navigation) { | 771 bool wait_for_navigation) { |
994 if (!is_valid()) | 772 if (!is_valid()) |
995 return false; | 773 return false; |
996 | 774 |
997 IPC::Message* response = NULL; | 775 IPC::Message* response = NULL; |
998 bool success = sender_->SendAndWaitForResponse( | 776 bool success = sender_->SendAndWaitForResponse( |
999 new AutomationMsg_ClickSSLInfoBarLinkRequest(0, handle_, | 777 new AutomationMsg_ClickSSLInfoBarLinkRequest( |
1000 info_bar_index, | 778 0, handle_, info_bar_index, wait_for_navigation), |
1001 wait_for_navigation), | 779 &response, AutomationMsg_ClickSSLInfoBarLinkResponse::ID) && |
1002 &response, | 780 AutomationMsg_ClickSSLInfoBarLinkResponse::Read(response, &success) && |
1003 AutomationMsg_ClickSSLInfoBarLinkResponse::ID); | 781 success; |
1004 scoped_ptr<IPC::Message> auto_deleter(response); | 782 scoped_ptr<IPC::Message> auto_deleter(response); |
1005 if (!success) | |
1006 return false; | |
1007 | |
1008 void* iter = NULL; | |
1009 response->ReadBool(&iter, &success); | |
1010 return success; | 783 return success; |
1011 } | 784 } |
1012 | 785 |
1013 bool TabProxy::GetLastNavigationTime(int64* last_navigation_time) { | 786 bool TabProxy::GetLastNavigationTime(int64* nav_time) { |
1014 if (!is_valid()) | 787 if (!is_valid()) |
1015 return false; | 788 return false; |
1016 | 789 |
1017 IPC::Message* response = NULL; | 790 IPC::Message* response = NULL; |
1018 bool success = sender_->SendAndWaitForResponse( | 791 bool success = sender_->SendAndWaitForResponse( |
1019 new AutomationMsg_GetLastNavigationTimeRequest(0, handle_), | 792 new AutomationMsg_GetLastNavigationTimeRequest(0, handle_), |
1020 &response, | 793 &response, AutomationMsg_GetLastNavigationTimeResponse::ID) && |
1021 AutomationMsg_GetLastNavigationTimeResponse::ID); | 794 AutomationMsg_GetLastNavigationTimeResponse::Read(response, nav_time); |
1022 scoped_ptr<IPC::Message> auto_deleter(response); | 795 scoped_ptr<IPC::Message> auto_deleter(response); |
1023 if (!success) | 796 return success; |
1024 return false; | |
1025 | |
1026 void* iter = NULL; | |
1027 response->ReadInt64(&iter, last_navigation_time); | |
1028 return true; | |
1029 } | 797 } |
1030 | 798 |
1031 bool TabProxy::WaitForNavigation(int64 last_navigation_time) { | 799 bool TabProxy::WaitForNavigation(int64 last_navigation_time) { |
1032 if (!is_valid()) | 800 if (!is_valid()) |
1033 return false; | 801 return false; |
1034 | 802 |
1035 IPC::Message* response = NULL; | 803 IPC::Message* response = NULL; |
1036 bool success = sender_->SendAndWaitForResponse( | 804 bool success = sender_->SendAndWaitForResponse( |
1037 new AutomationMsg_WaitForNavigationRequest(0, | 805 new AutomationMsg_WaitForNavigationRequest( |
1038 handle_, | 806 0, handle_, last_navigation_time), |
1039 last_navigation_time), | 807 &response, AutomationMsg_WaitForNavigationResponse::ID) && |
1040 &response, | 808 AutomationMsg_WaitForNavigationResponse::Read(response, &success) && |
1041 AutomationMsg_WaitForNavigationResponse::ID); | 809 success; |
1042 scoped_ptr<IPC::Message> auto_deleter(response); | 810 scoped_ptr<IPC::Message> auto_deleter(response); |
1043 if (!success) | |
1044 return false; | |
1045 | |
1046 void* iter = NULL; | |
1047 response->ReadBool(&iter, &success); | |
1048 return success; | 811 return success; |
1049 } | 812 } |
1050 | 813 |
1051 bool TabProxy::GetPageCurrentEncoding(std::wstring* encoding) { | 814 bool TabProxy::GetPageCurrentEncoding(std::wstring* encoding) { |
1052 if (!is_valid()) | 815 if (!is_valid()) |
1053 return false; | 816 return false; |
1054 | 817 |
1055 IPC::Message* response; | 818 IPC::Message* response; |
1056 bool succeeded = sender_->SendAndWaitForResponse( | 819 bool succeeded = sender_->SendAndWaitForResponse( |
1057 new AutomationMsg_GetPageCurrentEncodingRequest(0, handle_), | 820 new AutomationMsg_GetPageCurrentEncodingRequest(0, handle_), |
1058 &response, | 821 &response, AutomationMsg_GetPageCurrentEncodingResponse::ID) && |
1059 AutomationMsg_GetPageCurrentEncodingResponse::ID); | 822 AutomationMsg_GetPageCurrentEncodingResponse::Read(response, encoding); |
1060 | 823 scoped_ptr<IPC::Message> response_deleter(response); |
1061 scoped_ptr<IPC::Message> response_deleter(response); // Delete on return. | |
1062 if (!succeeded) | |
1063 return false; | |
1064 | |
1065 void* iter = NULL; | |
1066 succeeded = response->ReadWString(&iter, encoding); | |
1067 return succeeded; | 824 return succeeded; |
1068 } | 825 } |
1069 | 826 |
1070 bool TabProxy::OverrideEncoding(const std::wstring& encoding) { | 827 bool TabProxy::OverrideEncoding(const std::wstring& encoding) { |
1071 if (!is_valid()) | 828 if (!is_valid()) |
1072 return false; | 829 return false; |
1073 | 830 |
1074 IPC::Message* response; | 831 IPC::Message* response; |
1075 bool succeeded = sender_->SendAndWaitForResponse( | 832 bool succeeded = sender_->SendAndWaitForResponse( |
1076 new AutomationMsg_OverrideEncodingRequest(0, handle_, encoding), | 833 new AutomationMsg_OverrideEncodingRequest(0, handle_, encoding), |
1077 &response, | 834 &response, AutomationMsg_OverrideEncodingResponse::ID) && |
1078 AutomationMsg_OverrideEncodingResponse::ID); | 835 AutomationMsg_OverrideEncodingResponse::Read(response, &succeeded) && |
1079 | 836 succeeded; |
1080 scoped_ptr<IPC::Message> response_deleter(response); // Delete on return. | 837 scoped_ptr<IPC::Message> response_deleter(response); |
1081 if (!succeeded) | 838 return succeeded; |
1082 return false; | |
1083 | |
1084 void* iter = NULL; | |
1085 bool successed_set_value = false; | |
1086 succeeded = response->ReadBool(&iter, &successed_set_value); | |
1087 return succeeded && successed_set_value; | |
1088 } | 839 } |
OLD | NEW |