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/browser_proxy.h" | 5 #include "chrome/test/automation/browser_proxy.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/platform_thread.h" | 10 #include "base/platform_thread.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 105 |
106 if (active_tab_index_response >= 0) { | 106 if (active_tab_index_response >= 0) { |
107 *active_tab_index = active_tab_index_response; | 107 *active_tab_index = active_tab_index_response; |
108 } else { | 108 } else { |
109 succeeded = false; | 109 succeeded = false; |
110 } | 110 } |
111 | 111 |
112 return succeeded; | 112 return succeeded; |
113 } | 113 } |
114 | 114 |
115 TabProxy* BrowserProxy::GetTab(int tab_index) const { | 115 scoped_refptr<TabProxy> BrowserProxy::GetTab(int tab_index) const { |
116 if (!is_valid()) | 116 if (!is_valid()) |
117 return NULL; | 117 return NULL; |
118 | 118 |
119 int handle = 0; | 119 int tab_handle = 0; |
120 | 120 |
121 sender_->Send(new AutomationMsg_Tab(0, handle_, tab_index, &handle)); | 121 sender_->Send(new AutomationMsg_Tab(0, handle_, tab_index, &tab_handle)); |
122 if (!handle) | 122 if (!tab_handle) |
123 return NULL; | 123 return NULL; |
124 | 124 |
125 return new TabProxy(sender_, tracker_, handle); | 125 TabProxy* tab = static_cast<TabProxy*>(tracker_->GetResource(tab_handle)); |
| 126 if (!tab) { |
| 127 tab = new TabProxy(sender_, tracker_, tab_handle); |
| 128 tab->AddRef(); |
| 129 } |
| 130 |
| 131 // Since there is no scoped_refptr::attach. |
| 132 scoped_refptr<TabProxy> result; |
| 133 result.swap(&tab); |
| 134 return result; |
126 } | 135 } |
127 | 136 |
128 TabProxy* BrowserProxy::GetActiveTab() const { | 137 scoped_refptr<TabProxy> BrowserProxy::GetActiveTab() const { |
129 return GetActiveTabWithTimeout(base::kNoTimeout, NULL); | 138 return GetActiveTabWithTimeout(base::kNoTimeout, NULL); |
130 } | 139 } |
131 | 140 |
132 TabProxy* BrowserProxy::GetActiveTabWithTimeout(uint32 timeout_ms, | 141 scoped_refptr<TabProxy> BrowserProxy::GetActiveTabWithTimeout(uint32 timeout_ms, |
133 bool* is_timeout) const { | 142 bool* is_timeout) const { |
134 int active_tab_index; | 143 int active_tab_index; |
135 if (!GetActiveTabIndexWithTimeout(&active_tab_index, timeout_ms, is_timeout)) | 144 if (!GetActiveTabIndexWithTimeout(&active_tab_index, timeout_ms, is_timeout)) |
136 return NULL; | 145 return NULL; |
137 return GetTab(active_tab_index); | 146 return GetTab(active_tab_index); |
138 } | 147 } |
139 | 148 |
140 bool BrowserProxy::GetTabCount(int* num_tabs) const { | 149 bool BrowserProxy::GetTabCount(int* num_tabs) const { |
141 return GetTabCountWithTimeout(num_tabs, base::kNoTimeout, NULL); | 150 return GetTabCountWithTimeout(num_tabs, base::kNoTimeout, NULL); |
142 } | 151 } |
143 | 152 |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 if (!is_valid()) | 367 if (!is_valid()) |
359 return false; | 368 return false; |
360 | 369 |
361 bool result = false; | 370 bool result = false; |
362 | 371 |
363 sender_->Send(new AutomationMsg_SetBooleanPreference(0, handle_, name, | 372 sender_->Send(new AutomationMsg_SetBooleanPreference(0, handle_, name, |
364 value, &result)); | 373 value, &result)); |
365 return result; | 374 return result; |
366 } | 375 } |
367 | 376 |
368 WindowProxy* BrowserProxy::GetWindow() const { | 377 scoped_refptr<WindowProxy> BrowserProxy::GetWindow() const { |
369 if (!is_valid()) | 378 if (!is_valid()) |
370 return false; | 379 return NULL; |
371 | 380 |
372 bool handle_ok = false; | 381 bool handle_ok = false; |
373 int window_handle = 0; | 382 int window_handle = 0; |
374 | 383 |
375 sender_->Send(new AutomationMsg_WindowForBrowser(0, handle_, &handle_ok, | 384 sender_->Send(new AutomationMsg_WindowForBrowser(0, handle_, &handle_ok, |
376 &window_handle)); | 385 &window_handle)); |
377 if (!handle_ok) | 386 if (!handle_ok) |
378 return NULL; | 387 return NULL; |
379 | 388 |
380 return new WindowProxy(sender_, tracker_, window_handle); | 389 WindowProxy* window = |
| 390 static_cast<WindowProxy*>(tracker_->GetResource(window_handle)); |
| 391 if (!window) { |
| 392 window = new WindowProxy(sender_, tracker_, window_handle); |
| 393 window->AddRef(); |
| 394 } |
| 395 |
| 396 // Since there is no scoped_refptr::attach. |
| 397 scoped_refptr<WindowProxy> result; |
| 398 result.swap(&window); |
| 399 return result; |
381 } | 400 } |
382 | 401 |
383 AutocompleteEditProxy* BrowserProxy::GetAutocompleteEdit() { | 402 scoped_refptr<AutocompleteEditProxy> BrowserProxy::GetAutocompleteEdit() { |
384 if (!is_valid()) | 403 if (!is_valid()) |
385 return NULL; | 404 return NULL; |
386 | 405 |
387 bool handle_ok = false; | 406 bool handle_ok = false; |
388 int autocomplete_edit_handle = 0; | 407 int autocomplete_edit_handle = 0; |
389 | 408 |
390 sender_->Send(new AutomationMsg_AutocompleteEditForBrowser( | 409 sender_->Send(new AutomationMsg_AutocompleteEditForBrowser( |
391 0, handle_, &handle_ok, &autocomplete_edit_handle)); | 410 0, handle_, &handle_ok, &autocomplete_edit_handle)); |
392 | 411 |
393 if (!handle_ok) | 412 if (!handle_ok) |
394 return NULL; | 413 return NULL; |
395 | 414 |
396 return new AutocompleteEditProxy(sender_, tracker_, autocomplete_edit_handle); | 415 AutocompleteEditProxy* p = static_cast<AutocompleteEditProxy*>( |
| 416 tracker_->GetResource(autocomplete_edit_handle)); |
| 417 |
| 418 if (!p) { |
| 419 p = new AutocompleteEditProxy(sender_, tracker_, autocomplete_edit_handle); |
| 420 p->AddRef(); |
| 421 } |
| 422 |
| 423 // Since there is no scoped_refptr::attach. |
| 424 scoped_refptr<AutocompleteEditProxy> result; |
| 425 result.swap(&p); |
| 426 return result; |
397 } | 427 } |
OLD | NEW |