| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/automation/automation_provider.h" | 5 #include "chrome/browser/automation/automation_provider.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| 11 #include "base/run_loop.h" |
| 11 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/automation/automation_browser_tracker.h" | 13 #include "chrome/browser/automation/automation_browser_tracker.h" |
| 13 #include "chrome/browser/automation/automation_tab_tracker.h" | 14 #include "chrome/browser/automation/automation_tab_tracker.h" |
| 14 #include "chrome/browser/automation/automation_window_tracker.h" | 15 #include "chrome/browser/automation/automation_window_tracker.h" |
| 15 #include "chrome/browser/external_tab/external_tab_container.h" | 16 #include "chrome/browser/external_tab/external_tab_container.h" |
| 16 #include "chrome/browser/printing/print_view_manager.h" | 17 #include "chrome/browser/printing/print_view_manager.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/sessions/restore_tab_helper.h" | 19 #include "chrome/browser/sessions/restore_tab_helper.h" |
| 19 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/browser/ui/browser_window.h" | 21 #include "chrome/browser/ui/browser_window.h" |
| 21 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 22 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 22 #include "chrome/common/automation_messages.h" | 23 #include "chrome/common/automation_messages.h" |
| 23 #include "chrome/common/render_messages.h" | 24 #include "chrome/common/render_messages.h" |
| 24 #include "content/public/browser/navigation_controller.h" | 25 #include "content/public/browser/navigation_controller.h" |
| 25 #include "content/public/browser/render_view_host.h" | 26 #include "content/public/browser/render_view_host.h" |
| 26 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 27 #include "content/public/common/page_zoom.h" | 28 #include "content/public/common/page_zoom.h" |
| 28 #include "ui/base/keycodes/keyboard_codes.h" | 29 #include "ui/base/keycodes/keyboard_codes.h" |
| 29 #include "ui/ui_controls/ui_controls.h" | 30 #include "ui/ui_controls/ui_controls.h" |
| 30 #include "ui/views/focus/accelerator_handler.h" | 31 #include "ui/views/focus/accelerator_handler.h" |
| 31 #include "ui/views/widget/root_view.h" | 32 #include "ui/views/widget/root_view.h" |
| 32 | 33 |
| 33 using content::NavigationController; | 34 using content::NavigationController; |
| 34 using content::RenderViewHost; | 35 using content::RenderViewHost; |
| 35 using content::WebContents; | 36 using content::WebContents; |
| 36 | 37 |
| 37 namespace { | 38 namespace { |
| 38 | 39 |
| 40 // Allow some pending tasks up to |num_deferrals| generations to complete. |
| 41 void DeferredQuitRunLoop(const base::Closure& quit_task, |
| 42 int num_quit_deferrals) { |
| 43 if (num_quit_deferrals <= 0) { |
| 44 quit_task.Run(); |
| 45 } else { |
| 46 MessageLoop::current()->PostTask(FROM_HERE, |
| 47 base::Bind(&DeferredQuitRunLoop, quit_task, num_quit_deferrals - 1)); |
| 48 } |
| 49 } |
| 50 |
| 39 // This callback just adds another callback to the event queue. This is useful | 51 // This callback just adds another callback to the event queue. This is useful |
| 40 // if you want to ensure that any callbacks added to the event queue after this | 52 // if you want to ensure that any callbacks added to the event queue after this |
| 41 // one have already been processed by the time |callback| is run. | 53 // one have already been processed by the time |callback| is run. |
| 42 void InvokeCallbackLater(const base::Closure& callback) { | 54 void InvokeCallbackLater(const base::Closure& callback) { |
| 43 MessageLoop::current()->PostTask(FROM_HERE, callback); | 55 MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 44 } | 56 } |
| 45 | 57 |
| 46 void MoveMouse(const POINT& point) { | 58 void MoveMouse(const POINT& point) { |
| 47 SetCursorPos(point.x, point.y); | 59 SetCursorPos(point.x, point.y); |
| 48 | 60 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 SendMessage(top_level_hwnd, WM_MOUSEMOVE, wparam_flags, | 144 SendMessage(top_level_hwnd, WM_MOUSEMOVE, wparam_flags, |
| 133 MAKELPARAM(drag_path[i].x(), drag_path[i].y())); | 145 MAKELPARAM(drag_path[i].x(), drag_path[i].y())); |
| 134 } | 146 } |
| 135 POINT end = drag_path[drag_path.size() - 1].ToPOINT(); | 147 POINT end = drag_path[drag_path.size() - 1].ToPOINT(); |
| 136 MapWindowPoints(top_level_hwnd, HWND_DESKTOP, &end, 1); | 148 MapWindowPoints(top_level_hwnd, HWND_DESKTOP, &end, 1); |
| 137 MoveMouse(end); | 149 MoveMouse(end); |
| 138 | 150 |
| 139 if (press_escape_en_route) { | 151 if (press_escape_en_route) { |
| 140 // Press Escape, making sure we wait until chrome processes the escape. | 152 // Press Escape, making sure we wait until chrome processes the escape. |
| 141 // TODO(phajdan.jr): make this use ui_test_utils::SendKeyPressSync. | 153 // TODO(phajdan.jr): make this use ui_test_utils::SendKeyPressSync. |
| 154 views::AcceleratorHandler handler; |
| 155 base::RunLoop run_loop(&handler); |
| 156 // Number of times to repost Quit task to allow pending tasks to complete. |
| 157 // See kNumQuitDeferrals in ui_test_utils.cc for explanation. |
| 158 int num_quit_deferrals = 10; |
| 142 ui_controls::SendKeyPressNotifyWhenDone( | 159 ui_controls::SendKeyPressNotifyWhenDone( |
| 143 window, ui::VKEY_ESCAPE, | 160 window, ui::VKEY_ESCAPE, |
| 144 ((flags & ui::EF_CONTROL_DOWN) == | 161 ((flags & ui::EF_CONTROL_DOWN) == |
| 145 ui::EF_CONTROL_DOWN), | 162 ui::EF_CONTROL_DOWN), |
| 146 ((flags & ui::EF_SHIFT_DOWN) == | 163 ((flags & ui::EF_SHIFT_DOWN) == |
| 147 ui::EF_SHIFT_DOWN), | 164 ui::EF_SHIFT_DOWN), |
| 148 ((flags & ui::EF_ALT_DOWN) == ui::EF_ALT_DOWN), | 165 ((flags & ui::EF_ALT_DOWN) == ui::EF_ALT_DOWN), |
| 149 false, | 166 false, |
| 150 MessageLoop::QuitClosure()); | 167 base::Bind(&DeferredQuitRunLoop, run_loop.QuitClosure(), |
| 168 num_quit_deferrals)); |
| 151 MessageLoopForUI* loop = MessageLoopForUI::current(); | 169 MessageLoopForUI* loop = MessageLoopForUI::current(); |
| 152 views::AcceleratorHandler handler; | |
| 153 MessageLoop::ScopedNestableTaskAllower allow(loop); | 170 MessageLoop::ScopedNestableTaskAllower allow(loop); |
| 154 loop->RunWithDispatcher(&handler); | 171 run_loop.Run(); |
| 155 } | 172 } |
| 156 SendMessage(top_level_hwnd, up_message, wparam_flags, | 173 SendMessage(top_level_hwnd, up_message, wparam_flags, |
| 157 MAKELPARAM(end.x, end.y)); | 174 MAKELPARAM(end.x, end.y)); |
| 158 | 175 |
| 159 MessageLoop::current()->PostTask( | 176 MessageLoop::current()->PostTask( |
| 160 FROM_HERE, base::Bind( | 177 FROM_HERE, base::Bind( |
| 161 &InvokeCallbackLater, | 178 &InvokeCallbackLater, |
| 162 base::Bind(&WindowDragResponseCallback, this, reply_message))); | 179 base::Bind(&WindowDragResponseCallback, this, reply_message))); |
| 163 } else { | 180 } else { |
| 164 AutomationMsg_WindowDrag::WriteReplyParams(reply_message, false); | 181 AutomationMsg_WindowDrag::WriteReplyParams(reply_message, false); |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 void AutomationProvider::OnSetZoomLevel(int handle, int zoom_level) { | 418 void AutomationProvider::OnSetZoomLevel(int handle, int zoom_level) { |
| 402 if (tab_tracker_->ContainsHandle(handle)) { | 419 if (tab_tracker_->ContainsHandle(handle)) { |
| 403 NavigationController* tab = tab_tracker_->GetResource(handle); | 420 NavigationController* tab = tab_tracker_->GetResource(handle); |
| 404 if (tab->GetWebContents() && tab->GetWebContents()->GetRenderViewHost()) { | 421 if (tab->GetWebContents() && tab->GetWebContents()->GetRenderViewHost()) { |
| 405 RenderViewHost* host = tab->GetWebContents()->GetRenderViewHost(); | 422 RenderViewHost* host = tab->GetWebContents()->GetRenderViewHost(); |
| 406 content::PageZoom zoom = static_cast<content::PageZoom>(zoom_level); | 423 content::PageZoom zoom = static_cast<content::PageZoom>(zoom_level); |
| 407 host->Zoom(zoom); | 424 host->Zoom(zoom); |
| 408 } | 425 } |
| 409 } | 426 } |
| 410 } | 427 } |
| OLD | NEW |