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" |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 | 330 |
331 if (!count) { | 331 if (!count) { |
332 NOTREACHED(); | 332 NOTREACHED(); |
333 return false; | 333 return false; |
334 } | 334 } |
335 | 335 |
336 return sender_->Send(new AutomationMsg_ConstrainedWindowCount( | 336 return sender_->Send(new AutomationMsg_ConstrainedWindowCount( |
337 0, handle_, count)); | 337 0, handle_, count)); |
338 } | 338 } |
339 | 339 |
340 ConstrainedWindowProxy* TabProxy::GetConstrainedWindow( | 340 scoped_refptr<ConstrainedWindowProxy> TabProxy::GetConstrainedWindow( |
341 int window_index) const { | 341 int window_index) const { |
342 if (!is_valid()) | 342 if (!is_valid()) |
343 return NULL; | 343 return NULL; |
344 | 344 |
345 int handle = 0; | 345 int handle = 0; |
346 if (sender_->Send(new AutomationMsg_ConstrainedWindow(0, handle_, | 346 if (!sender_->Send(new AutomationMsg_ConstrainedWindow(0, handle_, |
347 window_index, | 347 window_index, |
348 &handle))) { | 348 &handle))) |
349 return new ConstrainedWindowProxy(sender_, tracker_, handle); | 349 return NULL; |
| 350 |
| 351 if (handle == 0) |
| 352 return NULL; |
| 353 |
| 354 ConstrainedWindowProxy* w = static_cast<ConstrainedWindowProxy*>( |
| 355 tracker_->GetResource(handle)); |
| 356 if (!w) { |
| 357 w = new ConstrainedWindowProxy(sender_, tracker_, handle); |
| 358 w->AddRef(); |
350 } | 359 } |
351 | 360 |
352 return NULL; | 361 // Since there is no scoped_refptr::attach. |
| 362 scoped_refptr<ConstrainedWindowProxy> result; |
| 363 result.swap(&w); |
| 364 return result; |
353 } | 365 } |
354 | 366 |
355 bool TabProxy::WaitForChildWindowCountToChange(int count, int* new_count, | 367 bool TabProxy::WaitForChildWindowCountToChange(int count, int* new_count, |
356 int wait_timeout) { | 368 int wait_timeout) { |
357 int intervals = std::min(wait_timeout/automation::kSleepTime, 1); | 369 int intervals = std::min(wait_timeout/automation::kSleepTime, 1); |
358 for (int i = 0; i < intervals; ++i) { | 370 for (int i = 0; i < intervals; ++i) { |
359 PlatformThread::Sleep(automation::kSleepTime); | 371 PlatformThread::Sleep(automation::kSleepTime); |
360 bool succeeded = GetConstrainedWindowCount(new_count); | 372 bool succeeded = GetConstrainedWindowCount(new_count); |
361 if (!succeeded) return false; | 373 if (!succeeded) return false; |
362 if (count != *new_count) return true; | 374 if (count != *new_count) return true; |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 params.top = top; | 642 params.top = top; |
631 params.width = width; | 643 params.width = width; |
632 params.height = height; | 644 params.height = height; |
633 params.flags = flags; | 645 params.flags = flags; |
634 params.set_parent = (::IsWindow(parent_window) ? true : false); | 646 params.set_parent = (::IsWindow(parent_window) ? true : false); |
635 params.parent_window = parent_window; | 647 params.parent_window = parent_window; |
636 sender_->Send(new AutomationMsg_TabReposition(0, handle_, params)); | 648 sender_->Send(new AutomationMsg_TabReposition(0, handle_, params)); |
637 } | 649 } |
638 | 650 |
639 #endif // defined(OS_WIN) | 651 #endif // defined(OS_WIN) |
| 652 |
| 653 void TabProxy::AddObserver(TabProxyDelegate* observer) { |
| 654 AutoLock lock(list_lock_); |
| 655 observers_list_.AddObserver(observer); |
| 656 } |
| 657 |
| 658 void TabProxy::RemoveObserver(TabProxyDelegate* observer) { |
| 659 AutoLock lock(list_lock_); |
| 660 observers_list_.RemoveObserver(observer); |
| 661 } |
| 662 |
| 663 // Called on Channel background thread, if TabMessages filter is installed. |
| 664 void TabProxy::OnMessageReceived(const IPC::Message& message) { |
| 665 AutoLock lock(list_lock_); |
| 666 FOR_EACH_OBSERVER(TabProxyDelegate, observers_list_, |
| 667 OnMessageReceived(this, message)); |
| 668 } |
OLD | NEW |