| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/bind.h" |
| 6 #include "base/bind_helpers.h" |
| 5 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 6 #include "base/location.h" | 8 #include "base/location.h" |
| 7 #include "chrome_frame/external_tab.h" | 9 #include "chrome_frame/external_tab.h" |
| 8 #include "base/task.h" | 10 #include "base/task.h" |
| 9 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
| 10 #include "chrome/common/automation_messages.h" | 12 #include "chrome/common/automation_messages.h" |
| 11 #include "chrome_frame/chrome_frame_delegate.h" | 13 #include "chrome_frame/chrome_frame_delegate.h" |
| 12 #include "chrome_frame/utils.h" | 14 #include "chrome_frame/utils.h" |
| 13 | 15 |
| 14 DISABLE_RUNNABLE_METHOD_REFCOUNT(ExternalTabProxy); | |
| 15 DISABLE_RUNNABLE_METHOD_REFCOUNT(UIDelegate); | |
| 16 | |
| 17 namespace { | 16 namespace { |
| 18 static base::LazyInstance<ChromeProxyFactory> g_proxy_factory = | 17 static base::LazyInstance<ChromeProxyFactory> g_proxy_factory = |
| 19 LAZY_INSTANCE_INITIALIZER; | 18 LAZY_INSTANCE_INITIALIZER; |
| 20 | 19 |
| 21 struct UserDataHolder : public SyncMessageContext { | 20 struct UserDataHolder : public SyncMessageContext { |
| 22 explicit UserDataHolder(void* p) : data(p) {} | 21 explicit UserDataHolder(void* p) : data(p) {} |
| 23 void* data; | 22 void* data; |
| 24 }; | 23 }; |
| 25 } | 24 } |
| 26 | 25 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 Init(); | 107 Init(); |
| 109 ui_delegate_ = delegate; | 108 ui_delegate_ = delegate; |
| 110 // TODO(stoyan): Shall we check the CanNavigate(create_params.url)? | 109 // TODO(stoyan): Shall we check the CanNavigate(create_params.url)? |
| 111 tab_params_ = create_params; | 110 tab_params_ = create_params; |
| 112 state_ = INIT_IN_PROGRESS; | 111 state_ = INIT_IN_PROGRESS; |
| 113 proxy_factory_->GetProxy(this, create_params.proxy_params); | 112 proxy_factory_->GetProxy(this, create_params.proxy_params); |
| 114 } | 113 } |
| 115 | 114 |
| 116 void ExternalTabProxy::Connected(ChromeProxy* proxy) { | 115 void ExternalTabProxy::Connected(ChromeProxy* proxy) { |
| 117 // in ipc thread | 116 // in ipc thread |
| 118 ui_.PostTask(FROM_HERE, NewRunnableMethod(this, | 117 ui_.PostTask(FROM_HERE, base::Bind(&ExternalTabProxy::UiConnected, |
| 119 &ExternalTabProxy::UiConnected, proxy)); | 118 base::Unretained(this), proxy)); |
| 120 } | 119 } |
| 121 | 120 |
| 122 void ExternalTabProxy::UiConnected(ChromeProxy* proxy) { | 121 void ExternalTabProxy::UiConnected(ChromeProxy* proxy) { |
| 123 proxy_ = proxy; | 122 proxy_ = proxy; |
| 124 ExternalTabSettings settings; | 123 ExternalTabSettings settings; |
| 125 settings.parent = m_hWnd; | 124 settings.parent = m_hWnd; |
| 126 settings.style = WS_CHILD; | 125 settings.style = WS_CHILD; |
| 127 settings.is_incognito = tab_params_.is_incognito; | 126 settings.is_incognito = tab_params_.is_incognito; |
| 128 // TODO(stoyan): FIX this. | 127 // TODO(stoyan): FIX this. |
| 129 settings.load_requests_via_automation = true; | 128 settings.load_requests_via_automation = true; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 140 proxy->CreateTab(this, settings); | 139 proxy->CreateTab(this, settings); |
| 141 } | 140 } |
| 142 | 141 |
| 143 void ExternalTabProxy::Disconnected() { | 142 void ExternalTabProxy::Disconnected() { |
| 144 // in ipc thread | 143 // in ipc thread |
| 145 DCHECK(done_.get() != NULL); | 144 DCHECK(done_.get() != NULL); |
| 146 done_->Signal(); | 145 done_->Signal(); |
| 147 } | 146 } |
| 148 | 147 |
| 149 void ExternalTabProxy::PeerLost(ChromeProxy* proxy, DisconnectReason reason) { | 148 void ExternalTabProxy::PeerLost(ChromeProxy* proxy, DisconnectReason reason) { |
| 150 ui_.PostTask(FROM_HERE, NewRunnableMethod(this, &ExternalTabProxy::UiPeerLost, | 149 ui_.PostTask(FROM_HERE, base::Bind(&ExternalTabProxy::UiPeerLost, |
| 151 proxy, reason)); | 150 base::Unretained(this), proxy, reason)); |
| 152 } | 151 } |
| 153 | 152 |
| 154 void ExternalTabProxy::UiPeerLost(ChromeProxy* proxy, DisconnectReason reason) { | 153 void ExternalTabProxy::UiPeerLost(ChromeProxy* proxy, DisconnectReason reason) { |
| 155 // TODO(stoyan): | 154 // TODO(stoyan): |
| 156 } | 155 } |
| 157 | 156 |
| 158 void ExternalTabProxy::Navigate(const std::string& url, | 157 void ExternalTabProxy::Navigate(const std::string& url, |
| 159 const std::string& referrer, | 158 const std::string& referrer, |
| 160 NavigationConstraints* navigation_constraints) { | 159 NavigationConstraints* navigation_constraints) { |
| 161 // in ui thread | 160 // in ui thread |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 if (pending_navigation_.url.is_valid()) | 223 if (pending_navigation_.url.is_valid()) |
| 225 proxy_->Tab_Navigate(tab_, pending_navigation_.url, | 224 proxy_->Tab_Navigate(tab_, pending_navigation_.url, |
| 226 pending_navigation_.referrer); | 225 pending_navigation_.referrer); |
| 227 } | 226 } |
| 228 } | 227 } |
| 229 | 228 |
| 230 void ExternalTabProxy::Completed_CreateTab(bool success, HWND chrome_wnd, | 229 void ExternalTabProxy::Completed_CreateTab(bool success, HWND chrome_wnd, |
| 231 HWND tab_window, int tab_handle, | 230 HWND tab_window, int tab_handle, |
| 232 int session_id) { | 231 int session_id) { |
| 233 // in ipc_thread. | 232 // in ipc_thread. |
| 234 ui_.PostTask(FROM_HERE, NewRunnableMethod(this, | 233 ui_.PostTask( |
| 235 &ExternalTabProxy::UiCompleted_CreateTab, | 234 FROM_HERE, base::Bind(&ExternalTabProxy::UiCompleted_CreateTab, |
| 236 success, chrome_wnd, tab_window, tab_handle, session_id)); | 235 base::Unretained(this), success, chrome_wnd, |
| 236 tab_window, tab_handle, session_id)); |
| 237 } | 237 } |
| 238 | 238 |
| 239 void ExternalTabProxy::Completed_ConnectToTab( | 239 void ExternalTabProxy::Completed_ConnectToTab( |
| 240 bool success, HWND chrome_window, HWND tab_window, int tab_handle, | 240 bool success, HWND chrome_window, HWND tab_window, int tab_handle, |
| 241 int session_id) { | 241 int session_id) { |
| 242 CHECK(0); | 242 CHECK(0); |
| 243 } | 243 } |
| 244 | 244 |
| 245 void ExternalTabProxy::Completed_Navigate( | 245 void ExternalTabProxy::Completed_Navigate( |
| 246 bool success, enum AutomationMsg_NavigationResponseValues res) { | 246 bool success, enum AutomationMsg_NavigationResponseValues res) { |
| 247 // ipc_thread; | 247 // ipc_thread; |
| 248 CHECK(0); | 248 CHECK(0); |
| 249 } | 249 } |
| 250 | 250 |
| 251 void ExternalTabProxy::OnNavigationStateChanged( | 251 void ExternalTabProxy::OnNavigationStateChanged( |
| 252 int flags, const NavigationInfo& nav_info) { | 252 int flags, const NavigationInfo& nav_info) { |
| 253 ui_.PostTask(FROM_HERE, NewRunnableMethod(ui_delegate_, | 253 ui_.PostTask(FROM_HERE, |
| 254 &UIDelegate::OnNavigationStateChanged, flags, nav_info)); | 254 base::Bind(&UIDelegate::OnNavigationStateChanged, |
| 255 base::Unretained(ui_delegate_), flags, nav_info)); |
| 255 } | 256 } |
| 256 | 257 |
| 257 void ExternalTabProxy::OnUpdateTargetUrl(const std::wstring& url) { | 258 void ExternalTabProxy::OnUpdateTargetUrl(const std::wstring& url) { |
| 258 ui_.PostTask(FROM_HERE, NewRunnableMethod(ui_delegate_, | 259 ui_.PostTask(FROM_HERE, base::Bind(&UIDelegate::OnUpdateTargetUrl, |
| 259 &UIDelegate::OnUpdateTargetUrl, url)); | 260 base::Unretained(ui_delegate_), url)); |
| 260 } | 261 } |
| 261 | 262 |
| 262 void ExternalTabProxy::OnTabLoaded(const GURL& url) { | 263 void ExternalTabProxy::OnTabLoaded(const GURL& url) { |
| 263 ui_.PostTask(FROM_HERE, NewRunnableMethod(ui_delegate_, | 264 ui_.PostTask(FROM_HERE, base::Bind(&UIDelegate::OnLoad, |
| 264 &UIDelegate::OnLoad, url)); | 265 base::Unretained(ui_delegate_), url)); |
| 265 } | 266 } |
| 266 | 267 |
| 267 void ExternalTabProxy::OnMoveWindow(const gfx::Rect& pos) { | 268 void ExternalTabProxy::OnMoveWindow(const gfx::Rect& pos) { |
| 268 ui_.PostTask(FROM_HERE, NewRunnableMethod(ui_delegate_, | 269 ui_.PostTask(FROM_HERE, base::Bind(&UIDelegate::OnMoveWindow, |
| 269 &UIDelegate::OnMoveWindow, pos)); | 270 base::Unretained(ui_delegate_), pos)); |
| 270 } | 271 } |
| 271 | 272 |
| 272 void ExternalTabProxy::OnMessageToHost(const std::string& message, | 273 void ExternalTabProxy::OnMessageToHost(const std::string& message, |
| 273 const std::string& origin, | 274 const std::string& origin, |
| 274 const std::string& target) { | 275 const std::string& target) { |
| 275 ui_.PostTask(FROM_HERE, NewRunnableMethod(ui_delegate_, | 276 ui_.PostTask( |
| 276 &UIDelegate::OnMessageFromChromeFrame, message, origin, target)); | 277 FROM_HERE, |
| 278 base::Bind(&UIDelegate::OnMessageFromChromeFrame, |
| 279 base::Unretained(ui_delegate_), message, origin, target)); |
| 277 } | 280 } |
| 278 | 281 |
| 279 void ExternalTabProxy::OnHandleAccelerator(const MSG& accel_message) { | 282 void ExternalTabProxy::OnHandleAccelerator(const MSG& accel_message) { |
| 280 ui_.PostTask(FROM_HERE, NewRunnableMethod(ui_delegate_, | 283 ui_.PostTask(FROM_HERE, |
| 281 &UIDelegate::OnHandleAccelerator, accel_message)); | 284 base::Bind(&UIDelegate::OnHandleAccelerator, |
| 285 base::Unretained(ui_delegate_), accel_message)); |
| 282 } | 286 } |
| 283 | 287 |
| 284 void ExternalTabProxy::OnHandleContextMenu( | 288 void ExternalTabProxy::OnHandleContextMenu( |
| 285 const ContextMenuModel& context_menu_model, | 289 const ContextMenuModel& context_menu_model, |
| 286 int align_flags, | 290 int align_flags, |
| 287 const MiniContextMenuParams& params) { | 291 const MiniContextMenuParams& params) { |
| 288 ui_.PostTask(FROM_HERE, NewRunnableMethod(ui_delegate_, | 292 ui_.PostTask(FROM_HERE, |
| 289 &UIDelegate::OnHandleContextMenu, context_menu_model, align_flags, | 293 base::Bind(&UIDelegate::OnHandleContextMenu, |
| 290 params)); | 294 base::Unretained(ui_delegate_), context_menu_model, |
| 295 align_flags, params)); |
| 291 } | 296 } |
| 292 | 297 |
| 293 void ExternalTabProxy::OnTabbedOut(bool reverse) { | 298 void ExternalTabProxy::OnTabbedOut(bool reverse) { |
| 294 ui_.PostTask(FROM_HERE, NewRunnableMethod(ui_delegate_, | 299 ui_.PostTask(FROM_HERE, base::Bind(&UIDelegate::OnTabbedOut, |
| 295 &UIDelegate::OnTabbedOut, reverse)); | 300 base::Unretained(ui_delegate_), reverse)); |
| 296 } | 301 } |
| 297 | 302 |
| 298 void ExternalTabProxy::OnGoToHistoryOffset(int offset) { | 303 void ExternalTabProxy::OnGoToHistoryOffset(int offset) { |
| 299 ui_.PostTask(FROM_HERE, NewRunnableMethod(ui_delegate_, | 304 ui_.PostTask(FROM_HERE, base::Bind(&UIDelegate::OnGoToHistoryOffset, |
| 300 &UIDelegate::OnGoToHistoryOffset, offset)); | 305 base::Unretained(ui_delegate_), offset)); |
| 301 } | 306 } |
| 302 | 307 |
| 303 void ExternalTabProxy::OnOpenURL(const GURL& url_to_open, const GURL& referrer, | 308 void ExternalTabProxy::OnOpenURL(const GURL& url_to_open, const GURL& referrer, |
| 304 int open_disposition) { | 309 int open_disposition) { |
| 305 ui_.PostTask(FROM_HERE, NewRunnableMethod(ui_delegate_, | 310 ui_.PostTask( |
| 306 &UIDelegate::OnOpenURL, url_to_open, referrer, open_disposition)); | 311 FROM_HERE, |
| 312 base::Bind(&UIDelegate::OnOpenURL, base::Unretained(ui_delegate_), |
| 313 url_to_open, referrer, open_disposition)); |
| 307 } | 314 } |
| 308 | 315 |
| 309 void ExternalTabProxy::OnNavigationFailed(int error_code, const GURL& gurl) { | 316 void ExternalTabProxy::OnNavigationFailed(int error_code, const GURL& gurl) { |
| 310 // TODO(stoyan): | 317 // TODO(stoyan): |
| 311 } | 318 } |
| 312 | 319 |
| 313 void ExternalTabProxy::OnDidNavigate(const NavigationInfo& navigation_info) { | 320 void ExternalTabProxy::OnDidNavigate(const NavigationInfo& navigation_info) { |
| 314 // TODO(stoyan): | 321 // TODO(stoyan): |
| 315 } | 322 } |
| 316 | 323 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 341 } | 348 } |
| 342 | 349 |
| 343 void ExternalTabProxy::OnTabClosed() { | 350 void ExternalTabProxy::OnTabClosed() { |
| 344 // TODO(stoyan): | 351 // TODO(stoyan): |
| 345 } | 352 } |
| 346 | 353 |
| 347 void ExternalTabProxy::OnAttachTab( | 354 void ExternalTabProxy::OnAttachTab( |
| 348 const AttachExternalTabParams& attach_params) { | 355 const AttachExternalTabParams& attach_params) { |
| 349 // TODO(stoyan): | 356 // TODO(stoyan): |
| 350 } | 357 } |
| OLD | NEW |