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