Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: chrome/test/automation/tab_proxy.cc

Issue 5998006: Clean up Automation and Chrome Frame IPC code. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/test/automation/extension_proxy.cc ('k') | chrome/test/automation/window_proxy.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "base/string16.h" 10 #include "base/string16.h"
(...skipping 15 matching lines...) Expand all
26 return false; 26 return false;
27 27
28 if (!title) { 28 if (!title) {
29 NOTREACHED(); 29 NOTREACHED();
30 return false; 30 return false;
31 } 31 }
32 32
33 int tab_title_size_response = 0; 33 int tab_title_size_response = 0;
34 34
35 bool succeeded = sender_->Send( 35 bool succeeded = sender_->Send(
36 new AutomationMsg_TabTitle(0, handle_, &tab_title_size_response, title)); 36 new AutomationMsg_TabTitle(handle_, &tab_title_size_response, title));
37 return succeeded; 37 return succeeded;
38 } 38 }
39 39
40 bool TabProxy::GetTabIndex(int* index) const { 40 bool TabProxy::GetTabIndex(int* index) const {
41 if (!is_valid()) 41 if (!is_valid())
42 return false; 42 return false;
43 43
44 if (!index) { 44 if (!index) {
45 NOTREACHED(); 45 NOTREACHED();
46 return false; 46 return false;
47 } 47 }
48 48
49 return sender_->Send(new AutomationMsg_TabIndex(0, handle_, index)); 49 return sender_->Send(new AutomationMsg_TabIndex(handle_, index));
50 } 50 }
51 51
52 int TabProxy::FindInPage(const std::wstring& search_string, 52 int TabProxy::FindInPage(const std::wstring& search_string,
53 FindInPageDirection forward, 53 FindInPageDirection forward,
54 FindInPageCase match_case, 54 FindInPageCase match_case,
55 bool find_next, 55 bool find_next,
56 int* ordinal) { 56 int* ordinal) {
57 if (!is_valid()) 57 if (!is_valid())
58 return -1; 58 return -1;
59 59
60 AutomationMsg_Find_Params params; 60 AutomationMsg_Find_Params params;
61 params.unused = 0; 61 params.unused = 0;
62 params.search_string = WideToUTF16Hack(search_string); 62 params.search_string = WideToUTF16Hack(search_string);
63 params.find_next = find_next; 63 params.find_next = find_next;
64 params.match_case = (match_case == CASE_SENSITIVE); 64 params.match_case = (match_case == CASE_SENSITIVE);
65 params.forward = (forward == FWD); 65 params.forward = (forward == FWD);
66 66
67 int matches = 0; 67 int matches = 0;
68 int ordinal2 = 0; 68 int ordinal2 = 0;
69 bool succeeded = sender_->Send(new AutomationMsg_Find(0, handle_, 69 bool succeeded = sender_->Send(new AutomationMsg_Find(handle_,
70 params, 70 params,
71 &ordinal2, 71 &ordinal2,
72 &matches)); 72 &matches));
73 if (!succeeded) 73 if (!succeeded)
74 return -1; 74 return -1;
75 if (ordinal) 75 if (ordinal)
76 *ordinal = ordinal2; 76 *ordinal = ordinal2;
77 return matches; 77 return matches;
78 } 78 }
79 79
80 AutomationMsg_NavigationResponseValues TabProxy::NavigateToURL( 80 AutomationMsg_NavigationResponseValues TabProxy::NavigateToURL(
81 const GURL& url) { 81 const GURL& url) {
82 return NavigateToURLBlockUntilNavigationsComplete(url, 1); 82 return NavigateToURLBlockUntilNavigationsComplete(url, 1);
83 } 83 }
84 84
85 AutomationMsg_NavigationResponseValues 85 AutomationMsg_NavigationResponseValues
86 TabProxy::NavigateToURLBlockUntilNavigationsComplete( 86 TabProxy::NavigateToURLBlockUntilNavigationsComplete(
87 const GURL& url, int number_of_navigations) { 87 const GURL& url, int number_of_navigations) {
88 if (!is_valid()) 88 if (!is_valid())
89 return AUTOMATION_MSG_NAVIGATION_ERROR; 89 return AUTOMATION_MSG_NAVIGATION_ERROR;
90 90
91 AutomationMsg_NavigationResponseValues navigate_response = 91 AutomationMsg_NavigationResponseValues navigate_response =
92 AUTOMATION_MSG_NAVIGATION_ERROR; 92 AUTOMATION_MSG_NAVIGATION_ERROR;
93 93
94 if (number_of_navigations == 1) { 94 sender_->Send(new AutomationMsg_NavigateToURLBlockUntilNavigationsComplete(
95 // TODO(phajdan.jr): Remove when the reference build gets updated. 95 handle_, url, number_of_navigations, &navigate_response));
96 // This is only for backwards compatibility.
97 sender_->Send(new AutomationMsg_NavigateToURL(0, handle_, url,
98 &navigate_response));
99 } else {
100 sender_->Send(new AutomationMsg_NavigateToURLBlockUntilNavigationsComplete(
101 0, handle_, url, number_of_navigations, &navigate_response));
102 }
103 96
104 return navigate_response; 97 return navigate_response;
105 } 98 }
106 99
107 bool TabProxy::SetAuth(const std::wstring& username, 100 bool TabProxy::SetAuth(const std::wstring& username,
108 const std::wstring& password) { 101 const std::wstring& password) {
109 if (!is_valid()) 102 if (!is_valid())
110 return false; 103 return false;
111 104
112 AutomationMsg_NavigationResponseValues navigate_response = 105 AutomationMsg_NavigationResponseValues navigate_response =
113 AUTOMATION_MSG_NAVIGATION_ERROR; 106 AUTOMATION_MSG_NAVIGATION_ERROR;
114 sender_->Send(new AutomationMsg_SetAuth(0, handle_, username, password, 107 sender_->Send(new AutomationMsg_SetAuth(handle_, username, password,
115 &navigate_response)); 108 &navigate_response));
116 return navigate_response == AUTOMATION_MSG_NAVIGATION_SUCCESS; 109 return navigate_response == AUTOMATION_MSG_NAVIGATION_SUCCESS;
117 } 110 }
118 111
119 bool TabProxy::CancelAuth() { 112 bool TabProxy::CancelAuth() {
120 if (!is_valid()) 113 if (!is_valid())
121 return false; 114 return false;
122 115
123 AutomationMsg_NavigationResponseValues navigate_response = 116 AutomationMsg_NavigationResponseValues navigate_response =
124 AUTOMATION_MSG_NAVIGATION_ERROR; 117 AUTOMATION_MSG_NAVIGATION_ERROR;
125 sender_->Send(new AutomationMsg_CancelAuth(0, handle_, &navigate_response)); 118 sender_->Send(new AutomationMsg_CancelAuth(handle_, &navigate_response));
126 return navigate_response == AUTOMATION_MSG_NAVIGATION_SUCCESS; 119 return navigate_response == AUTOMATION_MSG_NAVIGATION_SUCCESS;
127 } 120 }
128 121
129 bool TabProxy::NeedsAuth() const { 122 bool TabProxy::NeedsAuth() const {
130 if (!is_valid()) 123 if (!is_valid())
131 return false; 124 return false;
132 125
133 bool needs_auth = false; 126 bool needs_auth = false;
134 sender_->Send(new AutomationMsg_NeedsAuth(0, handle_, &needs_auth)); 127 sender_->Send(new AutomationMsg_NeedsAuth(handle_, &needs_auth));
135 return needs_auth; 128 return needs_auth;
136 } 129 }
137 130
138 AutomationMsg_NavigationResponseValues TabProxy::GoBack() { 131 AutomationMsg_NavigationResponseValues TabProxy::GoBack() {
139 return GoBackBlockUntilNavigationsComplete(1); 132 return GoBackBlockUntilNavigationsComplete(1);
140 } 133 }
141 134
142 AutomationMsg_NavigationResponseValues 135 AutomationMsg_NavigationResponseValues
143 TabProxy::GoBackBlockUntilNavigationsComplete(int number_of_navigations) { 136 TabProxy::GoBackBlockUntilNavigationsComplete(int number_of_navigations) {
144 if (!is_valid()) 137 if (!is_valid())
145 return AUTOMATION_MSG_NAVIGATION_ERROR; 138 return AUTOMATION_MSG_NAVIGATION_ERROR;
146 139
147 AutomationMsg_NavigationResponseValues navigate_response = 140 AutomationMsg_NavigationResponseValues navigate_response =
148 AUTOMATION_MSG_NAVIGATION_ERROR; 141 AUTOMATION_MSG_NAVIGATION_ERROR;
149 sender_->Send(new AutomationMsg_GoBackBlockUntilNavigationsComplete( 142 sender_->Send(new AutomationMsg_GoBackBlockUntilNavigationsComplete(
150 0, handle_, number_of_navigations, &navigate_response)); 143 handle_, number_of_navigations, &navigate_response));
151 return navigate_response; 144 return navigate_response;
152 } 145 }
153 146
154 AutomationMsg_NavigationResponseValues TabProxy::GoForward() { 147 AutomationMsg_NavigationResponseValues TabProxy::GoForward() {
155 return GoForwardBlockUntilNavigationsComplete(1); 148 return GoForwardBlockUntilNavigationsComplete(1);
156 } 149 }
157 150
158 AutomationMsg_NavigationResponseValues 151 AutomationMsg_NavigationResponseValues
159 TabProxy::GoForwardBlockUntilNavigationsComplete( 152 TabProxy::GoForwardBlockUntilNavigationsComplete(
160 int number_of_navigations) { 153 int number_of_navigations) {
161 if (!is_valid()) 154 if (!is_valid())
162 return AUTOMATION_MSG_NAVIGATION_ERROR; 155 return AUTOMATION_MSG_NAVIGATION_ERROR;
163 156
164 AutomationMsg_NavigationResponseValues navigate_response = 157 AutomationMsg_NavigationResponseValues navigate_response =
165 AUTOMATION_MSG_NAVIGATION_ERROR; 158 AUTOMATION_MSG_NAVIGATION_ERROR;
166 sender_->Send(new AutomationMsg_GoForwardBlockUntilNavigationsComplete( 159 sender_->Send(new AutomationMsg_GoForwardBlockUntilNavigationsComplete(
167 0, handle_, number_of_navigations, &navigate_response)); 160 handle_, number_of_navigations, &navigate_response));
168 return navigate_response; 161 return navigate_response;
169 } 162 }
170 163
171 AutomationMsg_NavigationResponseValues TabProxy::Reload() { 164 AutomationMsg_NavigationResponseValues TabProxy::Reload() {
172 if (!is_valid()) 165 if (!is_valid())
173 return AUTOMATION_MSG_NAVIGATION_ERROR; 166 return AUTOMATION_MSG_NAVIGATION_ERROR;
174 167
175 AutomationMsg_NavigationResponseValues navigate_response = 168 AutomationMsg_NavigationResponseValues navigate_response =
176 AUTOMATION_MSG_NAVIGATION_ERROR; 169 AUTOMATION_MSG_NAVIGATION_ERROR;
177 sender_->Send(new AutomationMsg_Reload(0, handle_, &navigate_response)); 170 sender_->Send(new AutomationMsg_Reload(handle_, &navigate_response));
178 return navigate_response; 171 return navigate_response;
179 } 172 }
180 173
181 bool TabProxy::GetRedirectsFrom(const GURL& source_url, 174 bool TabProxy::GetRedirectsFrom(const GURL& source_url,
182 std::vector<GURL>* redirects) { 175 std::vector<GURL>* redirects) {
183 bool succeeded = false; 176 bool succeeded = false;
184 sender_->Send(new AutomationMsg_RedirectsFrom(0, handle_, 177 sender_->Send(new AutomationMsg_RedirectsFrom(handle_,
185 source_url, 178 source_url,
186 &succeeded, 179 &succeeded,
187 redirects)); 180 redirects));
188 return succeeded; 181 return succeeded;
189 } 182 }
190 183
191 bool TabProxy::GetCurrentURL(GURL* url) const { 184 bool TabProxy::GetCurrentURL(GURL* url) const {
192 if (!is_valid()) 185 if (!is_valid())
193 return false; 186 return false;
194 187
195 if (!url) { 188 if (!url) {
196 NOTREACHED(); 189 NOTREACHED();
197 return false; 190 return false;
198 } 191 }
199 192
200 bool succeeded = false; 193 bool succeeded = false;
201 sender_->Send(new AutomationMsg_TabURL(0, handle_, &succeeded, url)); 194 sender_->Send(new AutomationMsg_TabURL(handle_, &succeeded, url));
202 return succeeded; 195 return succeeded;
203 } 196 }
204 197
205 bool TabProxy::NavigateToURLAsync(const GURL& url) { 198 bool TabProxy::NavigateToURLAsync(const GURL& url) {
206 if (!is_valid()) 199 if (!is_valid())
207 return false; 200 return false;
208 201
209 bool status = false; 202 bool status = false;
210 sender_->Send(new AutomationMsg_NavigationAsync(0, 203 sender_->Send(new AutomationMsg_NavigationAsync(handle_,
211 handle_,
212 url, 204 url,
213 &status)); 205 &status));
214 return status; 206 return status;
215 } 207 }
216 208
217 bool TabProxy::NavigateToURLAsyncWithDisposition( 209 bool TabProxy::NavigateToURLAsyncWithDisposition(
218 const GURL& url, 210 const GURL& url,
219 WindowOpenDisposition disposition) { 211 WindowOpenDisposition disposition) {
220 if (!is_valid()) 212 if (!is_valid())
221 return false; 213 return false;
222 214
223 bool status = false; 215 bool status = false;
224 sender_->Send(new AutomationMsg_NavigationAsyncWithDisposition(0, 216 sender_->Send(new AutomationMsg_NavigationAsyncWithDisposition(handle_,
225 handle_,
226 url, 217 url,
227 disposition, 218 disposition,
228 &status)); 219 &status));
229 return status; 220 return status;
230 } 221 }
231 222
232 bool TabProxy::GetProcessID(int* process_id) const { 223 bool TabProxy::GetProcessID(int* process_id) const {
233 if (!is_valid()) 224 if (!is_valid())
234 return false; 225 return false;
235 226
236 if (!process_id) { 227 if (!process_id) {
237 NOTREACHED(); 228 NOTREACHED();
238 return false; 229 return false;
239 } 230 }
240 231
241 return sender_->Send(new AutomationMsg_TabProcessID(0, handle_, process_id)); 232 return sender_->Send(new AutomationMsg_TabProcessID(handle_, process_id));
242 } 233 }
243 234
244 bool TabProxy::ExecuteAndExtractString(const std::wstring& frame_xpath, 235 bool TabProxy::ExecuteAndExtractString(const std::wstring& frame_xpath,
245 const std::wstring& jscript, 236 const std::wstring& jscript,
246 std::wstring* string_value) { 237 std::wstring* string_value) {
247 Value* root = NULL; 238 Value* root = NULL;
248 bool succeeded = ExecuteAndExtractValue(frame_xpath, jscript, &root); 239 bool succeeded = ExecuteAndExtractValue(frame_xpath, jscript, &root);
249 if (!succeeded) 240 if (!succeeded)
250 return false; 241 return false;
251 242
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 Value** value) { 307 Value** value) {
317 if (!is_valid()) 308 if (!is_valid())
318 return false; 309 return false;
319 310
320 if (!value) { 311 if (!value) {
321 NOTREACHED(); 312 NOTREACHED();
322 return false; 313 return false;
323 } 314 }
324 315
325 std::string json; 316 std::string json;
326 if (!sender_->Send(new AutomationMsg_DomOperation(0, handle_, frame_xpath, 317 if (!sender_->Send(new AutomationMsg_DomOperation(handle_, frame_xpath,
327 jscript, &json))) 318 jscript, &json)))
328 return false; 319 return false;
329 // Wrap |json| in an array before deserializing because valid JSON has an 320 // Wrap |json| in an array before deserializing because valid JSON has an
330 // array or an object as the root. 321 // array or an object as the root.
331 json.insert(0, "["); 322 json.insert(0, "[");
332 json.append("]"); 323 json.append("]");
333 324
334 JSONStringValueSerializer deserializer(json); 325 JSONStringValueSerializer deserializer(json);
335 *value = deserializer.Deserialize(NULL, NULL); 326 *value = deserializer.Deserialize(NULL, NULL);
336 return *value != NULL; 327 return *value != NULL;
337 } 328 }
338 329
339 DOMElementProxyRef TabProxy::GetDOMDocument() { 330 DOMElementProxyRef TabProxy::GetDOMDocument() {
340 if (!is_valid()) 331 if (!is_valid())
341 return NULL; 332 return NULL;
342 333
343 int element_handle; 334 int element_handle;
344 if (!ExecuteJavaScriptAndGetReturn("document", &element_handle)) 335 if (!ExecuteJavaScriptAndGetReturn("document", &element_handle))
345 return NULL; 336 return NULL;
346 return GetObjectProxy<DOMElementProxy>(element_handle); 337 return GetObjectProxy<DOMElementProxy>(element_handle);
347 } 338 }
348 339
349 bool TabProxy::SetEnableExtensionAutomation( 340 bool TabProxy::SetEnableExtensionAutomation(
350 const std::vector<std::string>& functions_enabled) { 341 const std::vector<std::string>& functions_enabled) {
351 if (!is_valid()) 342 if (!is_valid())
352 return false; 343 return false;
353 344
354 return sender_->Send(new AutomationMsg_SetEnableExtensionAutomation( 345 return sender_->Send(new AutomationMsg_SetEnableExtensionAutomation(
355 0, handle_, functions_enabled)); 346 handle_, functions_enabled));
356 } 347 }
357 348
358 bool TabProxy::GetConstrainedWindowCount(int* count) const { 349 bool TabProxy::GetConstrainedWindowCount(int* count) const {
359 if (!is_valid()) 350 if (!is_valid())
360 return false; 351 return false;
361 352
362 if (!count) { 353 if (!count) {
363 NOTREACHED(); 354 NOTREACHED();
364 return false; 355 return false;
365 } 356 }
366 357
367 return sender_->Send(new AutomationMsg_ConstrainedWindowCount( 358 return sender_->Send(new AutomationMsg_ConstrainedWindowCount(
368 0, handle_, count)); 359 handle_, count));
369 } 360 }
370 361
371 bool TabProxy::WaitForChildWindowCountToChange(int count, int* new_count, 362 bool TabProxy::WaitForChildWindowCountToChange(int count, int* new_count,
372 int wait_timeout) { 363 int wait_timeout) {
373 int intervals = std::max(wait_timeout / automation::kSleepTime, 1); 364 int intervals = std::max(wait_timeout / automation::kSleepTime, 1);
374 for (int i = 0; i < intervals; ++i) { 365 for (int i = 0; i < intervals; ++i) {
375 PlatformThread::Sleep(automation::kSleepTime); 366 PlatformThread::Sleep(automation::kSleepTime);
376 bool succeeded = GetConstrainedWindowCount(new_count); 367 bool succeeded = GetConstrainedWindowCount(new_count);
377 if (!succeeded) 368 if (!succeeded)
378 return false; 369 return false;
379 if (count != *new_count) 370 if (count != *new_count)
380 return true; 371 return true;
381 } 372 }
382 // Constrained Window count did not change, return false. 373 // Constrained Window count did not change, return false.
383 return false; 374 return false;
384 } 375 }
385 376
386 bool TabProxy::GetBlockedPopupCount(int* count) const { 377 bool TabProxy::GetBlockedPopupCount(int* count) const {
387 if (!is_valid()) 378 if (!is_valid())
388 return false; 379 return false;
389 380
390 if (!count) { 381 if (!count) {
391 NOTREACHED(); 382 NOTREACHED();
392 return false; 383 return false;
393 } 384 }
394 385
395 return sender_->Send(new AutomationMsg_BlockedPopupCount( 386 return sender_->Send(new AutomationMsg_BlockedPopupCount(
396 0, handle_, count)); 387 handle_, count));
397 } 388 }
398 389
399 bool TabProxy::WaitForBlockedPopupCountToChangeTo(int target_count, 390 bool TabProxy::WaitForBlockedPopupCountToChangeTo(int target_count,
400 int wait_timeout) { 391 int wait_timeout) {
401 int intervals = std::max(wait_timeout / automation::kSleepTime, 1); 392 int intervals = std::max(wait_timeout / automation::kSleepTime, 1);
402 for (int i = 0; i < intervals; ++i) { 393 for (int i = 0; i < intervals; ++i) {
403 PlatformThread::Sleep(automation::kSleepTime); 394 PlatformThread::Sleep(automation::kSleepTime);
404 int new_count = -1; 395 int new_count = -1;
405 bool succeeded = GetBlockedPopupCount(&new_count); 396 bool succeeded = GetBlockedPopupCount(&new_count);
406 if (!succeeded) 397 if (!succeeded)
407 return false; 398 return false;
408 if (target_count == new_count) 399 if (target_count == new_count)
409 return true; 400 return true;
410 } 401 }
411 // Constrained Window count did not change, return false. 402 // Constrained Window count did not change, return false.
412 return false; 403 return false;
413 } 404 }
414 405
415 bool TabProxy::GetCookies(const GURL& url, std::string* cookies) { 406 bool TabProxy::GetCookies(const GURL& url, std::string* cookies) {
416 if (!is_valid()) 407 if (!is_valid())
417 return false; 408 return false;
418 409
419 int size = 0; 410 int size = 0;
420 return sender_->Send(new AutomationMsg_GetCookies(0, url, handle_, &size, 411 return sender_->Send(new AutomationMsg_GetCookies(url, handle_, &size,
421 cookies)); 412 cookies));
422 } 413 }
423 414
424 bool TabProxy::GetCookieByName(const GURL& url, 415 bool TabProxy::GetCookieByName(const GURL& url,
425 const std::string& name, 416 const std::string& name,
426 std::string* cookie) { 417 std::string* cookie) {
427 std::string cookies; 418 std::string cookies;
428 if (!GetCookies(url, &cookies)) 419 if (!GetCookies(url, &cookies))
429 return false; 420 return false;
430 421
431 std::string namestr = name + "="; 422 std::string namestr = name + "=";
432 std::string::size_type idx = cookies.find(namestr); 423 std::string::size_type idx = cookies.find(namestr);
433 if (idx != std::string::npos) { 424 if (idx != std::string::npos) {
434 cookies.erase(0, idx + namestr.length()); 425 cookies.erase(0, idx + namestr.length());
435 *cookie = cookies.substr(0, cookies.find(";")); 426 *cookie = cookies.substr(0, cookies.find(";"));
436 } else { 427 } else {
437 cookie->clear(); 428 cookie->clear();
438 } 429 }
439 430
440 return true; 431 return true;
441 } 432 }
442 433
443 bool TabProxy::SetCookie(const GURL& url, const std::string& value) { 434 bool TabProxy::SetCookie(const GURL& url, const std::string& value) {
444 int response_value = 0; 435 int response_value = 0;
445 return sender_->Send(new AutomationMsg_SetCookie(0, url, value, handle_, 436 return sender_->Send(new AutomationMsg_SetCookie(url, value, handle_,
446 &response_value)); 437 &response_value));
447 } 438 }
448 439
449 bool TabProxy::DeleteCookie(const GURL& url, const std::string& name) { 440 bool TabProxy::DeleteCookie(const GURL& url, const std::string& name) {
450 bool succeeded; 441 bool succeeded;
451 sender_->Send(new AutomationMsg_DeleteCookie(0, url, name, handle_, 442 sender_->Send(new AutomationMsg_DeleteCookie(url, name, handle_,
452 &succeeded)); 443 &succeeded));
453 return succeeded; 444 return succeeded;
454 } 445 }
455 446
456 bool TabProxy::ShowCollectedCookiesDialog() { 447 bool TabProxy::ShowCollectedCookiesDialog() {
457 bool succeeded = false; 448 bool succeeded = false;
458 return sender_->Send(new AutomationMsg_ShowCollectedCookiesDialog( 449 return sender_->Send(new AutomationMsg_ShowCollectedCookiesDialog(
459 0, handle_, &succeeded)) && succeeded; 450 handle_, &succeeded)) && succeeded;
460 } 451 }
461 452
462 int TabProxy::InspectElement(int x, int y) { 453 int TabProxy::InspectElement(int x, int y) {
463 if (!is_valid()) 454 if (!is_valid())
464 return -1; 455 return -1;
465 456
466 int ret = -1; 457 int ret = -1;
467 sender_->Send(new AutomationMsg_InspectElement(0, handle_, x, y, &ret)); 458 sender_->Send(new AutomationMsg_InspectElement(handle_, x, y, &ret));
468 return ret; 459 return ret;
469 } 460 }
470 461
471 bool TabProxy::GetDownloadDirectory(FilePath* directory) { 462 bool TabProxy::GetDownloadDirectory(FilePath* directory) {
472 DCHECK(directory); 463 DCHECK(directory);
473 if (!is_valid()) 464 if (!is_valid())
474 return false; 465 return false;
475 466
476 return sender_->Send(new AutomationMsg_DownloadDirectory(0, handle_, 467 return sender_->Send(new AutomationMsg_DownloadDirectory(handle_,
477 directory)); 468 directory));
478 } 469 }
479 470
480 bool TabProxy::ShowInterstitialPage(const std::string& html_text) { 471 bool TabProxy::ShowInterstitialPage(const std::string& html_text) {
481 if (!is_valid()) 472 if (!is_valid())
482 return false; 473 return false;
483 474
484 AutomationMsg_NavigationResponseValues result = 475 AutomationMsg_NavigationResponseValues result =
485 AUTOMATION_MSG_NAVIGATION_ERROR; 476 AUTOMATION_MSG_NAVIGATION_ERROR;
486 if (!sender_->Send(new AutomationMsg_ShowInterstitialPage( 477 if (!sender_->Send(new AutomationMsg_ShowInterstitialPage(
487 0, handle_, html_text, &result))) { 478 handle_, html_text, &result))) {
488 return false; 479 return false;
489 } 480 }
490 481
491 return result == AUTOMATION_MSG_NAVIGATION_SUCCESS; 482 return result == AUTOMATION_MSG_NAVIGATION_SUCCESS;
492 } 483 }
493 484
494 bool TabProxy::HideInterstitialPage() { 485 bool TabProxy::HideInterstitialPage() {
495 if (!is_valid()) 486 if (!is_valid())
496 return false; 487 return false;
497 488
498 bool result = false; 489 bool result = false;
499 sender_->Send(new AutomationMsg_HideInterstitialPage(0, handle_, &result)); 490 sender_->Send(new AutomationMsg_HideInterstitialPage(handle_, &result));
500 return result; 491 return result;
501 } 492 }
502 493
503 bool TabProxy::Close() { 494 bool TabProxy::Close() {
504 return Close(false); 495 return Close(false);
505 } 496 }
506 497
507 bool TabProxy::Close(bool wait_until_closed) { 498 bool TabProxy::Close(bool wait_until_closed) {
508 if (!is_valid()) 499 if (!is_valid())
509 return false; 500 return false;
510 501
511 bool succeeded = false; 502 bool succeeded = false;
512 sender_->Send(new AutomationMsg_CloseTab(0, handle_, wait_until_closed, 503 sender_->Send(new AutomationMsg_CloseTab(handle_, wait_until_closed,
513 &succeeded)); 504 &succeeded));
514 return succeeded; 505 return succeeded;
515 } 506 }
516 507
517 #if defined(OS_WIN) 508 #if defined(OS_WIN)
518 bool TabProxy::ProcessUnhandledAccelerator(const MSG& msg) { 509 bool TabProxy::ProcessUnhandledAccelerator(const MSG& msg) {
519 if (!is_valid()) 510 if (!is_valid())
520 return false; 511 return false;
521 512
522 return sender_->Send( 513 return sender_->Send(
523 new AutomationMsg_ProcessUnhandledAccelerator(0, handle_, msg)); 514 new AutomationMsg_ProcessUnhandledAccelerator(handle_, msg));
524 // This message expects no response 515 // This message expects no response
525 } 516 }
526 517
527 bool TabProxy::SetInitialFocus(bool reverse, bool restore_focus_to_view) { 518 bool TabProxy::SetInitialFocus(bool reverse, bool restore_focus_to_view) {
528 if (!is_valid()) 519 if (!is_valid())
529 return false; 520 return false;
530 521
531 return sender_->Send( 522 return sender_->Send(
532 new AutomationMsg_SetInitialFocus(0, handle_, reverse, 523 new AutomationMsg_SetInitialFocus(handle_, reverse,
533 restore_focus_to_view)); 524 restore_focus_to_view));
534 // This message expects no response 525 // This message expects no response
535 } 526 }
536 527
537 AutomationMsg_NavigationResponseValues TabProxy::NavigateInExternalTab( 528 AutomationMsg_NavigationResponseValues TabProxy::NavigateInExternalTab(
538 const GURL& url, const GURL& referrer) { 529 const GURL& url, const GURL& referrer) {
539 if (!is_valid()) 530 if (!is_valid())
540 return AUTOMATION_MSG_NAVIGATION_ERROR; 531 return AUTOMATION_MSG_NAVIGATION_ERROR;
541 532
542 AutomationMsg_NavigationResponseValues rv = AUTOMATION_MSG_NAVIGATION_ERROR; 533 AutomationMsg_NavigationResponseValues rv = AUTOMATION_MSG_NAVIGATION_ERROR;
543 sender_->Send(new AutomationMsg_NavigateInExternalTab(0, handle_, url, 534 sender_->Send(new AutomationMsg_NavigateInExternalTab(handle_, url,
544 referrer, &rv)); 535 referrer, &rv));
545 return rv; 536 return rv;
546 } 537 }
547 538
548 AutomationMsg_NavigationResponseValues TabProxy::NavigateExternalTabAtIndex( 539 AutomationMsg_NavigationResponseValues TabProxy::NavigateExternalTabAtIndex(
549 int index) { 540 int index) {
550 if (!is_valid()) 541 if (!is_valid())
551 return AUTOMATION_MSG_NAVIGATION_ERROR; 542 return AUTOMATION_MSG_NAVIGATION_ERROR;
552 543
553 AutomationMsg_NavigationResponseValues rv = AUTOMATION_MSG_NAVIGATION_ERROR; 544 AutomationMsg_NavigationResponseValues rv = AUTOMATION_MSG_NAVIGATION_ERROR;
554 sender_->Send(new AutomationMsg_NavigateExternalTabAtIndex(0, handle_, index, 545 sender_->Send(new AutomationMsg_NavigateExternalTabAtIndex(handle_, index,
555 &rv)); 546 &rv));
556 return rv; 547 return rv;
557 } 548 }
558 549
559 void TabProxy::HandleMessageFromExternalHost(const std::string& message, 550 void TabProxy::HandleMessageFromExternalHost(const std::string& message,
560 const std::string& origin, 551 const std::string& origin,
561 const std::string& target) { 552 const std::string& target) {
562 if (!is_valid()) 553 if (!is_valid())
563 return; 554 return;
564 555
565 sender_->Send( 556 sender_->Send(
566 new AutomationMsg_HandleMessageFromExternalHost( 557 new AutomationMsg_HandleMessageFromExternalHost(
567 0, handle_, message, origin, target)); 558 handle_, message, origin, target));
568 } 559 }
569 #endif // defined(OS_WIN) 560 #endif // defined(OS_WIN)
570 561
571 bool TabProxy::WaitForTabToBeRestored(uint32 timeout_ms) { 562 bool TabProxy::WaitForTabToBeRestored(uint32 timeout_ms) {
572 if (!is_valid()) 563 if (!is_valid())
573 return false; 564 return false;
574 return sender_->Send(new AutomationMsg_WaitForTabToBeRestored(0, handle_)); 565 return sender_->Send(new AutomationMsg_WaitForTabToBeRestored(handle_));
575 } 566 }
576 567
577 bool TabProxy::GetSecurityState(SecurityStyle* security_style, 568 bool TabProxy::GetSecurityState(SecurityStyle* security_style,
578 int* ssl_cert_status, 569 int* ssl_cert_status,
579 int* insecure_content_status) { 570 int* insecure_content_status) {
580 DCHECK(security_style && ssl_cert_status && insecure_content_status); 571 DCHECK(security_style && ssl_cert_status && insecure_content_status);
581 572
582 if (!is_valid()) 573 if (!is_valid())
583 return false; 574 return false;
584 575
585 bool succeeded = false; 576 bool succeeded = false;
586 577
587 sender_->Send(new AutomationMsg_GetSecurityState( 578 sender_->Send(new AutomationMsg_GetSecurityState(
588 0, handle_, &succeeded, security_style, ssl_cert_status, 579 handle_, &succeeded, security_style, ssl_cert_status,
589 insecure_content_status)); 580 insecure_content_status));
590 581
591 return succeeded; 582 return succeeded;
592 } 583 }
593 584
594 bool TabProxy::GetPageType(PageType* type) { 585 bool TabProxy::GetPageType(PageType* type) {
595 DCHECK(type); 586 DCHECK(type);
596 587
597 if (!is_valid()) 588 if (!is_valid())
598 return false; 589 return false;
599 590
600 bool succeeded = false; 591 bool succeeded = false;
601 sender_->Send(new AutomationMsg_GetPageType(0, handle_, &succeeded, type)); 592 sender_->Send(new AutomationMsg_GetPageType(handle_, &succeeded, type));
602 return succeeded; 593 return succeeded;
603 } 594 }
604 595
605 bool TabProxy::TakeActionOnSSLBlockingPage(bool proceed) { 596 bool TabProxy::TakeActionOnSSLBlockingPage(bool proceed) {
606 if (!is_valid()) 597 if (!is_valid())
607 return false; 598 return false;
608 599
609 AutomationMsg_NavigationResponseValues result = 600 AutomationMsg_NavigationResponseValues result =
610 AUTOMATION_MSG_NAVIGATION_ERROR; 601 AUTOMATION_MSG_NAVIGATION_ERROR;
611 sender_->Send(new AutomationMsg_ActionOnSSLBlockingPage(0, handle_, proceed, 602 sender_->Send(new AutomationMsg_ActionOnSSLBlockingPage(handle_, proceed,
612 &result)); 603 &result));
613 return result == AUTOMATION_MSG_NAVIGATION_SUCCESS || 604 return result == AUTOMATION_MSG_NAVIGATION_SUCCESS ||
614 result == AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED; 605 result == AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED;
615 } 606 }
616 607
617 bool TabProxy::PrintNow() { 608 bool TabProxy::PrintNow() {
618 if (!is_valid()) 609 if (!is_valid())
619 return false; 610 return false;
620 611
621 bool succeeded = false; 612 bool succeeded = false;
622 sender_->Send(new AutomationMsg_PrintNow(0, handle_, &succeeded)); 613 sender_->Send(new AutomationMsg_PrintNow(handle_, &succeeded));
623 return succeeded; 614 return succeeded;
624 } 615 }
625 616
626 bool TabProxy::PrintAsync() { 617 bool TabProxy::PrintAsync() {
627 if (!is_valid()) 618 if (!is_valid())
628 return false; 619 return false;
629 620
630 return sender_->Send(new AutomationMsg_PrintAsync(0, handle_)); 621 return sender_->Send(new AutomationMsg_PrintAsync(handle_));
631 } 622 }
632 623
633 bool TabProxy::SavePage(const FilePath& file_name, 624 bool TabProxy::SavePage(const FilePath& file_name,
634 const FilePath& dir_path, 625 const FilePath& dir_path,
635 SavePackage::SavePackageType type) { 626 SavePackage::SavePackageType type) {
636 if (!is_valid()) 627 if (!is_valid())
637 return false; 628 return false;
638 629
639 bool succeeded = false; 630 bool succeeded = false;
640 sender_->Send(new AutomationMsg_SavePage(0, handle_, file_name, dir_path, 631 sender_->Send(new AutomationMsg_SavePage(handle_, file_name, dir_path,
641 static_cast<int>(type), 632 static_cast<int>(type),
642 &succeeded)); 633 &succeeded));
643 return succeeded; 634 return succeeded;
644 } 635 }
645 636
646 bool TabProxy::GetInfoBarCount(int* count) { 637 bool TabProxy::GetInfoBarCount(int* count) {
647 if (!is_valid()) 638 if (!is_valid())
648 return false; 639 return false;
649 640
650 return sender_->Send(new AutomationMsg_GetInfoBarCount(0, handle_, count)); 641 return sender_->Send(new AutomationMsg_GetInfoBarCount(handle_, count));
651 } 642 }
652 643
653 bool TabProxy::WaitForInfoBarCount(int target_count) { 644 bool TabProxy::WaitForInfoBarCount(int target_count) {
654 if (!is_valid()) 645 if (!is_valid())
655 return false; 646 return false;
656 647
657 bool success = false; 648 bool success = false;
658 return sender_->Send(new AutomationMsg_WaitForInfoBarCount( 649 return sender_->Send(new AutomationMsg_WaitForInfoBarCount(
659 0, handle_, target_count, &success)) && success; 650 handle_, target_count, &success)) && success;
660 } 651 }
661 652
662 bool TabProxy::ClickInfoBarAccept(int info_bar_index, 653 bool TabProxy::ClickInfoBarAccept(int info_bar_index,
663 bool wait_for_navigation) { 654 bool wait_for_navigation) {
664 if (!is_valid()) 655 if (!is_valid())
665 return false; 656 return false;
666 657
667 AutomationMsg_NavigationResponseValues result = 658 AutomationMsg_NavigationResponseValues result =
668 AUTOMATION_MSG_NAVIGATION_ERROR; 659 AUTOMATION_MSG_NAVIGATION_ERROR;
669 sender_->Send(new AutomationMsg_ClickInfoBarAccept( 660 sender_->Send(new AutomationMsg_ClickInfoBarAccept(
670 0, handle_, info_bar_index, wait_for_navigation, &result)); 661 handle_, info_bar_index, wait_for_navigation, &result));
671 return result == AUTOMATION_MSG_NAVIGATION_SUCCESS || 662 return result == AUTOMATION_MSG_NAVIGATION_SUCCESS ||
672 result == AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED; 663 result == AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED;
673 } 664 }
674 665
675 bool TabProxy::GetLastNavigationTime(int64* nav_time) { 666 bool TabProxy::GetLastNavigationTime(int64* nav_time) {
676 if (!is_valid()) 667 if (!is_valid())
677 return false; 668 return false;
678 669
679 bool success = false; 670 bool success = false;
680 success = sender_->Send(new AutomationMsg_GetLastNavigationTime( 671 success = sender_->Send(new AutomationMsg_GetLastNavigationTime(
681 0, handle_, nav_time)); 672 handle_, nav_time));
682 return success; 673 return success;
683 } 674 }
684 675
685 bool TabProxy::WaitForNavigation(int64 last_navigation_time) { 676 bool TabProxy::WaitForNavigation(int64 last_navigation_time) {
686 if (!is_valid()) 677 if (!is_valid())
687 return false; 678 return false;
688 679
689 AutomationMsg_NavigationResponseValues result = 680 AutomationMsg_NavigationResponseValues result =
690 AUTOMATION_MSG_NAVIGATION_ERROR; 681 AUTOMATION_MSG_NAVIGATION_ERROR;
691 sender_->Send(new AutomationMsg_WaitForNavigation(0, handle_, 682 sender_->Send(new AutomationMsg_WaitForNavigation(handle_,
692 last_navigation_time, 683 last_navigation_time,
693 &result)); 684 &result));
694 return result == AUTOMATION_MSG_NAVIGATION_SUCCESS || 685 return result == AUTOMATION_MSG_NAVIGATION_SUCCESS ||
695 result == AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED; 686 result == AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED;
696 } 687 }
697 688
698 bool TabProxy::GetPageCurrentEncoding(std::string* encoding) { 689 bool TabProxy::GetPageCurrentEncoding(std::string* encoding) {
699 if (!is_valid()) 690 if (!is_valid())
700 return false; 691 return false;
701 692
702 bool succeeded = sender_->Send( 693 bool succeeded = sender_->Send(
703 new AutomationMsg_GetPageCurrentEncoding(0, handle_, encoding)); 694 new AutomationMsg_GetPageCurrentEncoding(handle_, encoding));
704 return succeeded; 695 return succeeded;
705 } 696 }
706 697
707 bool TabProxy::OverrideEncoding(const std::string& encoding) { 698 bool TabProxy::OverrideEncoding(const std::string& encoding) {
708 if (!is_valid()) 699 if (!is_valid())
709 return false; 700 return false;
710 701
711 bool succeeded = false; 702 bool succeeded = false;
712 sender_->Send(new AutomationMsg_OverrideEncoding(0, handle_, encoding, 703 sender_->Send(new AutomationMsg_OverrideEncoding(handle_, encoding,
713 &succeeded)); 704 &succeeded));
714 return succeeded; 705 return succeeded;
715 } 706 }
716 707
717 bool TabProxy::LoadBlockedPlugins() { 708 bool TabProxy::LoadBlockedPlugins() {
718 if (!is_valid()) 709 if (!is_valid())
719 return false; 710 return false;
720 711
721 bool succeeded = false; 712 bool succeeded = false;
722 sender_->Send(new AutomationMsg_LoadBlockedPlugins(0, handle_, &succeeded)); 713 sender_->Send(new AutomationMsg_LoadBlockedPlugins(handle_, &succeeded));
723 return succeeded; 714 return succeeded;
724 } 715 }
725 716
726 bool TabProxy::CaptureEntirePageAsPNG(const FilePath& path) { 717 bool TabProxy::CaptureEntirePageAsPNG(const FilePath& path) {
727 if (!is_valid()) 718 if (!is_valid())
728 return false; 719 return false;
729 720
730 bool succeeded = false; 721 bool succeeded = false;
731 sender_->Send(new AutomationMsg_CaptureEntirePageAsPNG(0, handle_, path, 722 sender_->Send(new AutomationMsg_CaptureEntirePageAsPNG(handle_, path,
732 &succeeded)); 723 &succeeded));
733 return succeeded; 724 return succeeded;
734 } 725 }
735 726
736 #if defined(OS_WIN) 727 #if defined(OS_WIN)
737 void TabProxy::Reposition(HWND window, HWND window_insert_after, int left, 728 void TabProxy::Reposition(HWND window, HWND window_insert_after, int left,
738 int top, int width, int height, int flags, 729 int top, int width, int height, int flags,
739 HWND parent_window) { 730 HWND parent_window) {
740 IPC::Reposition_Params params = {0}; 731 Reposition_Params params = {0};
741 params.window = window; 732 params.window = window;
742 params.window_insert_after = window_insert_after; 733 params.window_insert_after = window_insert_after;
743 params.left = left; 734 params.left = left;
744 params.top = top; 735 params.top = top;
745 params.width = width; 736 params.width = width;
746 params.height = height; 737 params.height = height;
747 params.flags = flags; 738 params.flags = flags;
748 params.set_parent = (::IsWindow(parent_window) ? true : false); 739 params.set_parent = (::IsWindow(parent_window) ? true : false);
749 params.parent_window = parent_window; 740 params.parent_window = parent_window;
750 sender_->Send(new AutomationMsg_TabReposition(0, handle_, params)); 741 sender_->Send(new AutomationMsg_TabReposition(handle_, params));
751 } 742 }
752 743
753 void TabProxy::SendContextMenuCommand(int selected_command) { 744 void TabProxy::SendContextMenuCommand(int selected_command) {
754 sender_->Send(new AutomationMsg_ForwardContextMenuCommandToChrome( 745 sender_->Send(new AutomationMsg_ForwardContextMenuCommandToChrome(
755 0, handle_, selected_command)); 746 handle_, selected_command));
756 } 747 }
757 748
758 void TabProxy::OnHostMoved() { 749 void TabProxy::OnHostMoved() {
759 sender_->Send(new AutomationMsg_BrowserMove(0, handle_)); 750 sender_->Send(new AutomationMsg_BrowserMove(handle_));
760 } 751 }
761 #endif // defined(OS_WIN) 752 #endif // defined(OS_WIN)
762 753
763 void TabProxy::SelectAll() { 754 void TabProxy::SelectAll() {
764 sender_->Send(new AutomationMsg_SelectAll(0, handle_)); 755 sender_->Send(new AutomationMsg_SelectAll(handle_));
765 } 756 }
766 757
767 void TabProxy::Cut() { 758 void TabProxy::Cut() {
768 sender_->Send(new AutomationMsg_Cut(0, handle_)); 759 sender_->Send(new AutomationMsg_Cut(handle_));
769 } 760 }
770 761
771 void TabProxy::Copy() { 762 void TabProxy::Copy() {
772 sender_->Send(new AutomationMsg_Copy(0, handle_)); 763 sender_->Send(new AutomationMsg_Copy(handle_));
773 } 764 }
774 765
775 void TabProxy::Paste() { 766 void TabProxy::Paste() {
776 sender_->Send(new AutomationMsg_Paste(0, handle_)); 767 sender_->Send(new AutomationMsg_Paste(handle_));
777 } 768 }
778 769
779 void TabProxy::ReloadAsync() { 770 void TabProxy::ReloadAsync() {
780 sender_->Send(new AutomationMsg_ReloadAsync(0, handle_)); 771 sender_->Send(new AutomationMsg_ReloadAsync(handle_));
781 } 772 }
782 773
783 void TabProxy::StopAsync() { 774 void TabProxy::StopAsync() {
784 sender_->Send(new AutomationMsg_StopAsync(0, handle_)); 775 sender_->Send(new AutomationMsg_StopAsync(handle_));
785 } 776 }
786 777
787 void TabProxy::SaveAsAsync() { 778 void TabProxy::SaveAsAsync() {
788 sender_->Send(new AutomationMsg_SaveAsAsync(0, handle_)); 779 sender_->Send(new AutomationMsg_SaveAsAsync(handle_));
789 } 780 }
790 781
791 void TabProxy::AddObserver(TabProxyDelegate* observer) { 782 void TabProxy::AddObserver(TabProxyDelegate* observer) {
792 AutoLock lock(list_lock_); 783 AutoLock lock(list_lock_);
793 observers_list_.AddObserver(observer); 784 observers_list_.AddObserver(observer);
794 } 785 }
795 786
796 void TabProxy::RemoveObserver(TabProxyDelegate* observer) { 787 void TabProxy::RemoveObserver(TabProxyDelegate* observer) {
797 AutoLock lock(list_lock_); 788 AutoLock lock(list_lock_);
798 observers_list_.RemoveObserver(observer); 789 observers_list_.RemoveObserver(observer);
(...skipping 14 matching lines...) Expand all
813 TabProxy::~TabProxy() {} 804 TabProxy::~TabProxy() {}
814 805
815 bool TabProxy::ExecuteJavaScriptAndGetJSON(const std::string& script, 806 bool TabProxy::ExecuteJavaScriptAndGetJSON(const std::string& script,
816 std::string* json) { 807 std::string* json) {
817 if (!is_valid()) 808 if (!is_valid())
818 return false; 809 return false;
819 if (!json) { 810 if (!json) {
820 NOTREACHED(); 811 NOTREACHED();
821 return false; 812 return false;
822 } 813 }
823 return sender_->Send(new AutomationMsg_DomOperation(0, handle_, L"", 814 return sender_->Send(new AutomationMsg_DomOperation(handle_, L"",
824 UTF8ToWide(script), 815 UTF8ToWide(script),
825 json)); 816 json));
826 } 817 }
827 818
828 void TabProxy::FirstObjectAdded() { 819 void TabProxy::FirstObjectAdded() {
829 AddRef(); 820 AddRef();
830 } 821 }
831 822
832 void TabProxy::LastObjectRemoved() { 823 void TabProxy::LastObjectRemoved() {
833 Release(); 824 Release();
834 } 825 }
OLDNEW
« no previous file with comments | « chrome/test/automation/extension_proxy.cc ('k') | chrome/test/automation/window_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698