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/window_proxy.h" | 5 #include "chrome/test/automation/window_proxy.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 #include <algorithm> | 8 #include <algorithm> |
9 | 9 |
10 #include "base/gfx/rect.h" | 10 #include "base/gfx/rect.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 | 111 |
112 if (!view_id) { | 112 if (!view_id) { |
113 NOTREACHED(); | 113 NOTREACHED(); |
114 return false; | 114 return false; |
115 } | 115 } |
116 | 116 |
117 return sender_->Send(new AutomationMsg_GetFocusedViewID(0, handle_, | 117 return sender_->Send(new AutomationMsg_GetFocusedViewID(0, handle_, |
118 view_id)); | 118 view_id)); |
119 } | 119 } |
120 | 120 |
121 BrowserProxy* WindowProxy::GetBrowser() { | 121 scoped_refptr<BrowserProxy> WindowProxy::GetBrowser() { |
122 return GetBrowserWithTimeout(base::kNoTimeout, NULL); | 122 return GetBrowserWithTimeout(base::kNoTimeout, NULL); |
123 } | 123 } |
124 | 124 |
125 BrowserProxy* WindowProxy::GetBrowserWithTimeout(uint32 timeout_ms, | 125 scoped_refptr<BrowserProxy> WindowProxy::GetBrowserWithTimeout( |
126 bool* is_timeout) { | 126 uint32 timeout_ms, bool* is_timeout) { |
127 if (!is_valid()) | 127 if (!is_valid()) |
128 return false; | 128 return NULL; |
129 | 129 |
130 bool handle_ok = false; | 130 bool handle_ok = false; |
131 int browser_handle = 0; | 131 int browser_handle = 0; |
132 | 132 |
133 sender_->Send(new AutomationMsg_BrowserForWindow(0, handle_, &handle_ok, | 133 sender_->Send(new AutomationMsg_BrowserForWindow(0, handle_, &handle_ok, |
134 &browser_handle)); | 134 &browser_handle)); |
135 if (!handle_ok) | 135 if (!handle_ok) |
136 return NULL; | 136 return NULL; |
137 | 137 |
138 return new BrowserProxy(sender_, tracker_, browser_handle); | 138 BrowserProxy* browser = |
| 139 static_cast<BrowserProxy*>(tracker_->GetResource(browser_handle)); |
| 140 if (!browser) { |
| 141 browser = new BrowserProxy(sender_, tracker_, browser_handle); |
| 142 browser->AddRef(); |
| 143 } |
| 144 |
| 145 // Since there is no scoped_refptr::attach. |
| 146 scoped_refptr<BrowserProxy> result; |
| 147 result.swap(&browser); |
| 148 return result; |
139 } | 149 } |
OLD | NEW |