OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/testing_automation_provider.h" | 5 #include "chrome/browser/automation/testing_automation_provider.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" | 101 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" |
102 #include "chrome/browser/ui/fullscreen/fullscreen_exit_bubble_type.h" | 102 #include "chrome/browser/ui/fullscreen/fullscreen_exit_bubble_type.h" |
103 #include "chrome/browser/ui/host_desktop.h" | 103 #include "chrome/browser/ui/host_desktop.h" |
104 #include "chrome/browser/ui/login/login_prompt.h" | 104 #include "chrome/browser/ui/login/login_prompt.h" |
105 #include "chrome/browser/ui/omnibox/location_bar.h" | 105 #include "chrome/browser/ui/omnibox/location_bar.h" |
106 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" | 106 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
107 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 107 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
108 #include "chrome/browser/ui/search_engines/keyword_editor_controller.h" | 108 #include "chrome/browser/ui/search_engines/keyword_editor_controller.h" |
109 #include "chrome/browser/ui/startup/startup_types.h" | 109 #include "chrome/browser/ui/startup/startup_types.h" |
110 #include "chrome/common/automation_constants.h" | 110 #include "chrome/common/automation_constants.h" |
111 #include "chrome/common/automation_events.h" | |
112 #include "chrome/common/automation_id.h" | 111 #include "chrome/common/automation_id.h" |
113 #include "chrome/common/automation_messages.h" | 112 #include "chrome/common/automation_messages.h" |
114 #include "chrome/common/chrome_constants.h" | 113 #include "chrome/common/chrome_constants.h" |
115 #include "chrome/common/chrome_notification_types.h" | 114 #include "chrome/common/chrome_notification_types.h" |
116 #include "chrome/common/chrome_paths.h" | 115 #include "chrome/common/chrome_paths.h" |
117 #include "chrome/common/chrome_switches.h" | 116 #include "chrome/common/chrome_switches.h" |
118 #include "chrome/common/extensions/background_info.h" | 117 #include "chrome/common/extensions/background_info.h" |
119 #include "chrome/common/extensions/extension.h" | 118 #include "chrome/common/extensions/extension.h" |
120 #include "chrome/common/extensions/manifest_url_handler.h" | 119 #include "chrome/common/extensions/manifest_url_handler.h" |
121 #include "chrome/common/extensions/permissions/permission_set.h" | 120 #include "chrome/common/extensions/permissions/permission_set.h" |
(...skipping 1476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1598 handler_map_["ApplyAccelerator"] = | 1597 handler_map_["ApplyAccelerator"] = |
1599 &TestingAutomationProvider::ExecuteBrowserCommandAsyncJSON; | 1598 &TestingAutomationProvider::ExecuteBrowserCommandAsyncJSON; |
1600 handler_map_["RunCommand"] = | 1599 handler_map_["RunCommand"] = |
1601 &TestingAutomationProvider::ExecuteBrowserCommandJSON; | 1600 &TestingAutomationProvider::ExecuteBrowserCommandJSON; |
1602 handler_map_["IsMenuCommandEnabled"] = | 1601 handler_map_["IsMenuCommandEnabled"] = |
1603 &TestingAutomationProvider::IsMenuCommandEnabledJSON; | 1602 &TestingAutomationProvider::IsMenuCommandEnabledJSON; |
1604 handler_map_["ActivateTab"] = | 1603 handler_map_["ActivateTab"] = |
1605 &TestingAutomationProvider::ActivateTabJSON; | 1604 &TestingAutomationProvider::ActivateTabJSON; |
1606 handler_map_["BringBrowserToFront"] = | 1605 handler_map_["BringBrowserToFront"] = |
1607 &TestingAutomationProvider::BringBrowserToFrontJSON; | 1606 &TestingAutomationProvider::BringBrowserToFrontJSON; |
1608 handler_map_["WaitForAllTabsToStopLoading"] = | |
1609 &TestingAutomationProvider::WaitForAllViewsToStopLoading; | |
1610 handler_map_["GetIndicesFromTab"] = | 1607 handler_map_["GetIndicesFromTab"] = |
1611 &TestingAutomationProvider::GetIndicesFromTab; | 1608 &TestingAutomationProvider::GetIndicesFromTab; |
1612 handler_map_["NavigateToURL"] = | 1609 handler_map_["NavigateToURL"] = |
1613 &TestingAutomationProvider::NavigateToURL; | 1610 &TestingAutomationProvider::NavigateToURL; |
1614 handler_map_["GetActiveTabIndex"] = | 1611 handler_map_["GetActiveTabIndex"] = |
1615 &TestingAutomationProvider::GetActiveTabIndexJSON; | 1612 &TestingAutomationProvider::GetActiveTabIndexJSON; |
1616 handler_map_["AppendTab"] = | 1613 handler_map_["AppendTab"] = |
1617 &TestingAutomationProvider::AppendTabJSON; | 1614 &TestingAutomationProvider::AppendTabJSON; |
1618 handler_map_["OpenNewBrowserWindow"] = | 1615 handler_map_["OpenNewBrowserWindow"] = |
1619 &TestingAutomationProvider::OpenNewBrowserWindow; | 1616 &TestingAutomationProvider::OpenNewBrowserWindow; |
(...skipping 22 matching lines...) Expand all Loading... |
1642 handler_map_["GoForward"] = | 1639 handler_map_["GoForward"] = |
1643 &TestingAutomationProvider::GoForward; | 1640 &TestingAutomationProvider::GoForward; |
1644 handler_map_["GoBack"] = | 1641 handler_map_["GoBack"] = |
1645 &TestingAutomationProvider::GoBack; | 1642 &TestingAutomationProvider::GoBack; |
1646 handler_map_["Reload"] = | 1643 handler_map_["Reload"] = |
1647 &TestingAutomationProvider::ReloadJSON; | 1644 &TestingAutomationProvider::ReloadJSON; |
1648 handler_map_["OpenFindInPage"] = | 1645 handler_map_["OpenFindInPage"] = |
1649 &TestingAutomationProvider::OpenFindInPage; | 1646 &TestingAutomationProvider::OpenFindInPage; |
1650 handler_map_["IsFindInPageVisible"] = | 1647 handler_map_["IsFindInPageVisible"] = |
1651 &TestingAutomationProvider::IsFindInPageVisible; | 1648 &TestingAutomationProvider::IsFindInPageVisible; |
1652 handler_map_["CaptureEntirePage"] = | |
1653 &TestingAutomationProvider::CaptureEntirePageJSON; | |
1654 handler_map_["SetDownloadShelfVisible"] = | 1649 handler_map_["SetDownloadShelfVisible"] = |
1655 &TestingAutomationProvider::SetDownloadShelfVisibleJSON; | 1650 &TestingAutomationProvider::SetDownloadShelfVisibleJSON; |
1656 handler_map_["IsDownloadShelfVisible"] = | 1651 handler_map_["IsDownloadShelfVisible"] = |
1657 &TestingAutomationProvider::IsDownloadShelfVisibleJSON; | 1652 &TestingAutomationProvider::IsDownloadShelfVisibleJSON; |
1658 handler_map_["GetDownloadDirectory"] = | 1653 handler_map_["GetDownloadDirectory"] = |
1659 &TestingAutomationProvider::GetDownloadDirectoryJSON; | 1654 &TestingAutomationProvider::GetDownloadDirectoryJSON; |
1660 handler_map_["GetCookies"] = | 1655 handler_map_["GetCookies"] = |
1661 &TestingAutomationProvider::GetCookiesJSON; | 1656 &TestingAutomationProvider::GetCookiesJSON; |
1662 handler_map_["DeleteCookie"] = | 1657 handler_map_["DeleteCookie"] = |
1663 &TestingAutomationProvider::DeleteCookieJSON; | 1658 &TestingAutomationProvider::DeleteCookieJSON; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1710 handler_map_["WebkitMouseButtonUp"] = | 1705 handler_map_["WebkitMouseButtonUp"] = |
1711 &TestingAutomationProvider::WebkitMouseButtonUp; | 1706 &TestingAutomationProvider::WebkitMouseButtonUp; |
1712 handler_map_["WebkitMouseButtonDown"] = | 1707 handler_map_["WebkitMouseButtonDown"] = |
1713 &TestingAutomationProvider::WebkitMouseButtonDown; | 1708 &TestingAutomationProvider::WebkitMouseButtonDown; |
1714 handler_map_["WebkitMouseDoubleClick"] = | 1709 handler_map_["WebkitMouseDoubleClick"] = |
1715 &TestingAutomationProvider::WebkitMouseDoubleClick; | 1710 &TestingAutomationProvider::WebkitMouseDoubleClick; |
1716 handler_map_["DragAndDropFilePaths"] = | 1711 handler_map_["DragAndDropFilePaths"] = |
1717 &TestingAutomationProvider::DragAndDropFilePaths; | 1712 &TestingAutomationProvider::DragAndDropFilePaths; |
1718 handler_map_["SendWebkitKeyEvent"] = | 1713 handler_map_["SendWebkitKeyEvent"] = |
1719 &TestingAutomationProvider::SendWebkitKeyEvent; | 1714 &TestingAutomationProvider::SendWebkitKeyEvent; |
1720 handler_map_["ProcessWebMouseEvent"] = | |
1721 &TestingAutomationProvider::ProcessWebMouseEvent; | |
1722 handler_map_["ActivateTab"] = | 1715 handler_map_["ActivateTab"] = |
1723 &TestingAutomationProvider::ActivateTabJSON; | 1716 &TestingAutomationProvider::ActivateTabJSON; |
1724 handler_map_["GetAppModalDialogMessage"] = | 1717 handler_map_["GetAppModalDialogMessage"] = |
1725 &TestingAutomationProvider::GetAppModalDialogMessage; | 1718 &TestingAutomationProvider::GetAppModalDialogMessage; |
1726 handler_map_["AcceptOrDismissAppModalDialog"] = | 1719 handler_map_["AcceptOrDismissAppModalDialog"] = |
1727 &TestingAutomationProvider::AcceptOrDismissAppModalDialog; | 1720 &TestingAutomationProvider::AcceptOrDismissAppModalDialog; |
1728 handler_map_["ActionOnSSLBlockingPage"] = | 1721 handler_map_["ActionOnSSLBlockingPage"] = |
1729 &TestingAutomationProvider::ActionOnSSLBlockingPage; | 1722 &TestingAutomationProvider::ActionOnSSLBlockingPage; |
1730 handler_map_["GetSecurityState"] = | 1723 handler_map_["GetSecurityState"] = |
1731 &TestingAutomationProvider::GetSecurityState; | 1724 &TestingAutomationProvider::GetSecurityState; |
(...skipping 28 matching lines...) Expand all Loading... |
1760 handler_map_["UninstallExtensionById"] = | 1753 handler_map_["UninstallExtensionById"] = |
1761 &TestingAutomationProvider::UninstallExtensionById; | 1754 &TestingAutomationProvider::UninstallExtensionById; |
1762 handler_map_["SetExtensionStateById"] = | 1755 handler_map_["SetExtensionStateById"] = |
1763 &TestingAutomationProvider::SetExtensionStateById; | 1756 &TestingAutomationProvider::SetExtensionStateById; |
1764 handler_map_["TriggerPageActionById"] = | 1757 handler_map_["TriggerPageActionById"] = |
1765 &TestingAutomationProvider::TriggerPageActionById; | 1758 &TestingAutomationProvider::TriggerPageActionById; |
1766 handler_map_["TriggerBrowserActionById"] = | 1759 handler_map_["TriggerBrowserActionById"] = |
1767 &TestingAutomationProvider::TriggerBrowserActionById; | 1760 &TestingAutomationProvider::TriggerBrowserActionById; |
1768 handler_map_["UpdateExtensionsNow"] = | 1761 handler_map_["UpdateExtensionsNow"] = |
1769 &TestingAutomationProvider::UpdateExtensionsNow; | 1762 &TestingAutomationProvider::UpdateExtensionsNow; |
1770 #if !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS)) | |
1771 handler_map_["HeapProfilerDump"] = | |
1772 &TestingAutomationProvider::HeapProfilerDump; | |
1773 #endif // !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS)) | |
1774 handler_map_["OverrideGeoposition"] = | 1763 handler_map_["OverrideGeoposition"] = |
1775 &TestingAutomationProvider::OverrideGeoposition; | 1764 &TestingAutomationProvider::OverrideGeoposition; |
1776 handler_map_["SimulateAsanMemoryBug"] = | 1765 handler_map_["SimulateAsanMemoryBug"] = |
1777 &TestingAutomationProvider::SimulateAsanMemoryBug; | 1766 &TestingAutomationProvider::SimulateAsanMemoryBug; |
1778 | 1767 |
1779 #if defined(OS_CHROMEOS) | 1768 #if defined(OS_CHROMEOS) |
1780 handler_map_["AcceptOOBENetworkScreen"] = | 1769 handler_map_["AcceptOOBENetworkScreen"] = |
1781 &TestingAutomationProvider::AcceptOOBENetworkScreen; | 1770 &TestingAutomationProvider::AcceptOOBENetworkScreen; |
1782 handler_map_["AcceptOOBEEula"] = &TestingAutomationProvider::AcceptOOBEEula; | 1771 handler_map_["AcceptOOBEEula"] = &TestingAutomationProvider::AcceptOOBEEula; |
1783 handler_map_["CancelOOBEUpdate"] = | 1772 handler_map_["CancelOOBEUpdate"] = |
(...skipping 2260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4044 // been updated). This observer will delete itself. | 4033 // been updated). This observer will delete itself. |
4045 ExtensionsUpdatedObserver* observer = new ExtensionsUpdatedObserver( | 4034 ExtensionsUpdatedObserver* observer = new ExtensionsUpdatedObserver( |
4046 manager, this, reply_message); | 4035 manager, this, reply_message); |
4047 extensions::ExtensionUpdater::CheckParams params; | 4036 extensions::ExtensionUpdater::CheckParams params; |
4048 params.install_immediately = true; | 4037 params.install_immediately = true; |
4049 params.callback = base::Bind(&ExtensionsUpdatedObserver::UpdateCheckFinished, | 4038 params.callback = base::Bind(&ExtensionsUpdatedObserver::UpdateCheckFinished, |
4050 base::Unretained(observer)); | 4039 base::Unretained(observer)); |
4051 updater->CheckNow(params); | 4040 updater->CheckNow(params); |
4052 } | 4041 } |
4053 | 4042 |
4054 #if !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS)) | |
4055 // Sample json input: { "command": "HeapProfilerDump", | |
4056 // "process_type": "renderer", | |
4057 // "reason": "Perf bot", | |
4058 // "tab_index": 0, | |
4059 // "windex": 0 } | |
4060 // "auto_id" is acceptable instead of "tab_index" and "windex". | |
4061 void TestingAutomationProvider::HeapProfilerDump( | |
4062 DictionaryValue* args, | |
4063 IPC::Message* reply_message) { | |
4064 AutomationJSONReply reply(this, reply_message); | |
4065 | |
4066 std::string process_type_string; | |
4067 if (!args->GetString("process_type", &process_type_string)) { | |
4068 reply.SendError("No process type is specified"); | |
4069 return; | |
4070 } | |
4071 | |
4072 std::string reason_string; | |
4073 if (args->GetString("reason", &reason_string)) | |
4074 reason_string += " (via PyAuto testing)"; | |
4075 else | |
4076 reason_string = "By PyAuto testing"; | |
4077 | |
4078 if (process_type_string == "browser") { | |
4079 if (!::IsHeapProfilerRunning()) { | |
4080 reply.SendError("The heap profiler is not running"); | |
4081 return; | |
4082 } | |
4083 ::HeapProfilerDump(reason_string.c_str()); | |
4084 reply.SendSuccess(NULL); | |
4085 return; | |
4086 } else if (process_type_string == "renderer") { | |
4087 WebContents* web_contents; | |
4088 std::string error; | |
4089 | |
4090 if (!GetTabFromJSONArgs(args, &web_contents, &error)) { | |
4091 reply.SendError(error); | |
4092 return; | |
4093 } | |
4094 | |
4095 RenderViewHost* render_view = web_contents->GetRenderViewHost(); | |
4096 if (!render_view) { | |
4097 reply.SendError("Tab has no associated RenderViewHost"); | |
4098 return; | |
4099 } | |
4100 | |
4101 AutomationTabHelper* automation_tab_helper = | |
4102 AutomationTabHelper::FromWebContents(web_contents); | |
4103 automation_tab_helper->HeapProfilerDump(reason_string); | |
4104 reply.SendSuccess(NULL); | |
4105 return; | |
4106 } | |
4107 | |
4108 reply.SendError("Process type is not supported"); | |
4109 } | |
4110 #endif // !defined(NO_TCMALLOC) && (defined(OS_LINUX) || defined(OS_CHROMEOS)) | |
4111 | |
4112 namespace { | 4043 namespace { |
4113 | 4044 |
4114 void SendSuccessIfAlive( | 4045 void SendSuccessIfAlive( |
4115 base::WeakPtr<AutomationProvider> provider, | 4046 base::WeakPtr<AutomationProvider> provider, |
4116 IPC::Message* reply_message) { | 4047 IPC::Message* reply_message) { |
4117 if (provider) | 4048 if (provider) |
4118 AutomationJSONReply(provider.get(), reply_message).SendSuccess(NULL); | 4049 AutomationJSONReply(provider.get(), reply_message).SendSuccess(NULL); |
4119 } | 4050 } |
4120 | 4051 |
4121 } // namespace | 4052 } // namespace |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4404 if (!GetRenderViewFromJSONArgs(args, profile(), &view, &error)) { | 4335 if (!GetRenderViewFromJSONArgs(args, profile(), &view, &error)) { |
4405 AutomationJSONReply(this, reply_message).SendError(error); | 4336 AutomationJSONReply(this, reply_message).SendError(error); |
4406 return; | 4337 return; |
4407 } | 4338 } |
4408 new InputEventAckNotificationObserver(this, reply_message, event.type, 1); | 4339 new InputEventAckNotificationObserver(this, reply_message, event.type, 1); |
4409 view->ForwardKeyboardEvent(event); | 4340 view->ForwardKeyboardEvent(event); |
4410 } | 4341 } |
4411 | 4342 |
4412 namespace { | 4343 namespace { |
4413 | 4344 |
4414 bool ReadScriptEvaluationRequestList( | |
4415 base::Value* value, | |
4416 std::vector<ScriptEvaluationRequest>* list, | |
4417 std::string* error_msg) { | |
4418 ListValue* request_list; | |
4419 if (!value->GetAsList(&request_list)) | |
4420 return false; | |
4421 | |
4422 for (size_t i = 0; i < request_list->GetSize(); ++i) { | |
4423 DictionaryValue* request_dict; | |
4424 if (!request_list->GetDictionary(i, &request_dict)) { | |
4425 *error_msg = "Script evaluation request was not a dictionary"; | |
4426 return false; | |
4427 } | |
4428 ScriptEvaluationRequest request; | |
4429 if (!request_dict->GetString("script", &request.script) || | |
4430 !request_dict->GetString("frame_xpath", &request.frame_xpath)) { | |
4431 *error_msg = "Script evaluation request was invalid"; | |
4432 return false; | |
4433 } | |
4434 list->push_back(request); | |
4435 } | |
4436 return true; | |
4437 } | |
4438 | |
4439 void SendPointIfAlive( | |
4440 base::WeakPtr<AutomationProvider> provider, | |
4441 IPC::Message* reply_message, | |
4442 const gfx::Point& point) { | |
4443 if (provider) { | |
4444 DictionaryValue dict; | |
4445 dict.SetInteger("x", point.x()); | |
4446 dict.SetInteger("y", point.y()); | |
4447 AutomationJSONReply(provider.get(), reply_message).SendSuccess(&dict); | |
4448 } | |
4449 } | |
4450 | |
4451 void SendErrorIfAlive( | |
4452 base::WeakPtr<AutomationProvider> provider, | |
4453 IPC::Message* reply_message, | |
4454 const automation::Error& error) { | |
4455 if (provider) { | |
4456 AutomationJSONReply(provider.get(), reply_message).SendError(error); | |
4457 } | |
4458 } | |
4459 | |
4460 } // namespace | |
4461 | |
4462 void TestingAutomationProvider::ProcessWebMouseEvent( | |
4463 DictionaryValue* args, | |
4464 IPC::Message* reply_message) { | |
4465 if (SendErrorIfModalDialogActive(this, reply_message)) | |
4466 return; | |
4467 | |
4468 RenderViewHost* view; | |
4469 std::string error; | |
4470 if (!GetRenderViewFromJSONArgs(args, profile(), &view, &error)) { | |
4471 AutomationJSONReply(this, reply_message).SendError(error); | |
4472 return; | |
4473 } | |
4474 | |
4475 int type; | |
4476 int button; | |
4477 int modifiers; | |
4478 WebKit::WebMouseEvent event; | |
4479 if (!args->GetInteger("type", &type) || | |
4480 !args->GetInteger("button", &button) || | |
4481 !args->GetInteger("x", &event.x) || | |
4482 !args->GetInteger("y", &event.y) || | |
4483 !args->GetInteger("click_count", &event.clickCount) || | |
4484 !args->GetInteger("modifiers", &modifiers)) { | |
4485 AutomationJSONReply(this, reply_message) | |
4486 .SendError("WebMouseEvent has missing or invalid parameters"); | |
4487 return; | |
4488 } | |
4489 if (type == automation::kMouseDown) { | |
4490 event.type = WebKit::WebInputEvent::MouseDown; | |
4491 } else if (type == automation::kMouseUp) { | |
4492 event.type = WebKit::WebInputEvent::MouseUp; | |
4493 } else if (type == automation::kMouseMove) { | |
4494 event.type = WebKit::WebInputEvent::MouseMove; | |
4495 } else if (type == automation::kMouseEnter) { | |
4496 event.type = WebKit::WebInputEvent::MouseEnter; | |
4497 } else if (type == automation::kMouseLeave) { | |
4498 event.type = WebKit::WebInputEvent::MouseLeave; | |
4499 } else if (type == automation::kContextMenu) { | |
4500 event.type = WebKit::WebInputEvent::ContextMenu; | |
4501 } else { | |
4502 AutomationJSONReply(this, reply_message) | |
4503 .SendError("'type' refers to an unrecognized mouse event type"); | |
4504 return; | |
4505 } | |
4506 if (button == automation::kLeftButton) { | |
4507 event.button = WebKit::WebMouseEvent::ButtonLeft; | |
4508 } else if (button == automation::kMiddleButton) { | |
4509 event.button = WebKit::WebMouseEvent::ButtonMiddle; | |
4510 } else if (button == automation::kRightButton) { | |
4511 event.button = WebKit::WebMouseEvent::ButtonRight; | |
4512 } else if (button == automation::kNoButton) { | |
4513 event.button = WebKit::WebMouseEvent::ButtonNone; | |
4514 } else { | |
4515 AutomationJSONReply(this, reply_message) | |
4516 .SendError("'button' refers to an unrecognized button"); | |
4517 return; | |
4518 } | |
4519 event.modifiers = 0; | |
4520 if (modifiers & automation::kShiftKeyMask) | |
4521 event.modifiers |= WebKit::WebInputEvent::ShiftKey; | |
4522 if (modifiers & automation::kControlKeyMask) | |
4523 event.modifiers |= WebKit::WebInputEvent::ControlKey; | |
4524 if (modifiers & automation::kAltKeyMask) | |
4525 event.modifiers |= WebKit::WebInputEvent::AltKey; | |
4526 if (modifiers & automation::kMetaKeyMask) | |
4527 event.modifiers |= WebKit::WebInputEvent::MetaKey; | |
4528 | |
4529 AutomationMouseEvent automation_event; | |
4530 automation_event.mouse_event = event; | |
4531 Value* location_script_chain_value; | |
4532 if (args->Get("location_script_chain", &location_script_chain_value)) { | |
4533 if (!ReadScriptEvaluationRequestList( | |
4534 location_script_chain_value, | |
4535 &automation_event.location_script_chain, | |
4536 &error)) { | |
4537 AutomationJSONReply(this, reply_message).SendError(error); | |
4538 return; | |
4539 } | |
4540 } | |
4541 | |
4542 new AutomationMouseEventProcessor( | |
4543 view, | |
4544 automation_event, | |
4545 base::Bind(&SendPointIfAlive, AsWeakPtr(), reply_message), | |
4546 base::Bind(&SendErrorIfAlive, AsWeakPtr(), reply_message)); | |
4547 } | |
4548 | |
4549 namespace { | |
4550 | |
4551 // Gets the active JavaScript modal dialog, or NULL if none. | 4345 // Gets the active JavaScript modal dialog, or NULL if none. |
4552 JavaScriptAppModalDialog* GetActiveJavaScriptModalDialog( | 4346 JavaScriptAppModalDialog* GetActiveJavaScriptModalDialog( |
4553 ErrorCode* error_code) { | 4347 ErrorCode* error_code) { |
4554 AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance(); | 4348 AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance(); |
4555 if (!dialog_queue->HasActiveDialog() || | 4349 if (!dialog_queue->HasActiveDialog() || |
4556 !dialog_queue->active_dialog()->IsJavaScriptModalDialog()) { | 4350 !dialog_queue->active_dialog()->IsJavaScriptModalDialog()) { |
4557 *error_code = automation::kNoJavaScriptModalDialogOpen; | 4351 *error_code = automation::kNoJavaScriptModalDialogOpen; |
4558 return NULL; | 4352 return NULL; |
4559 } | 4353 } |
4560 return static_cast<JavaScriptAppModalDialog*>(dialog_queue->active_dialog()); | 4354 return static_cast<JavaScriptAppModalDialog*>(dialog_queue->active_dialog()); |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4859 } | 4653 } |
4860 | 4654 |
4861 void TestingAutomationProvider::DenyCurrentFullscreenOrMouseLockRequest( | 4655 void TestingAutomationProvider::DenyCurrentFullscreenOrMouseLockRequest( |
4862 Browser* browser, | 4656 Browser* browser, |
4863 base::DictionaryValue* args, | 4657 base::DictionaryValue* args, |
4864 IPC::Message* reply_message) { | 4658 IPC::Message* reply_message) { |
4865 browser->fullscreen_controller()->OnDenyFullscreenPermission(); | 4659 browser->fullscreen_controller()->OnDenyFullscreenPermission(); |
4866 AutomationJSONReply(this, reply_message).SendSuccess(NULL); | 4660 AutomationJSONReply(this, reply_message).SendSuccess(NULL); |
4867 } | 4661 } |
4868 | 4662 |
4869 void TestingAutomationProvider::WaitForAllViewsToStopLoading( | |
4870 DictionaryValue* args, | |
4871 IPC::Message* reply_message) { | |
4872 if (AppModalDialogQueue::GetInstance()->HasActiveDialog()) { | |
4873 AutomationJSONReply(this, reply_message).SendSuccess(NULL); | |
4874 return; | |
4875 } | |
4876 | |
4877 // This class will send the message immediately if no tab is loading. | |
4878 new AllViewsStoppedLoadingObserver( | |
4879 this, reply_message, | |
4880 extensions::ExtensionSystem::Get(profile())->process_manager()); | |
4881 } | |
4882 | |
4883 void TestingAutomationProvider::WaitForTabToBeRestored( | 4663 void TestingAutomationProvider::WaitForTabToBeRestored( |
4884 DictionaryValue* args, | 4664 DictionaryValue* args, |
4885 IPC::Message* reply_message) { | 4665 IPC::Message* reply_message) { |
4886 WebContents* web_contents; | 4666 WebContents* web_contents; |
4887 std::string error; | 4667 std::string error; |
4888 if (!GetTabFromJSONArgs(args, &web_contents, &error)) { | 4668 if (!GetTabFromJSONArgs(args, &web_contents, &error)) { |
4889 AutomationJSONReply(this, reply_message).SendError(error); | 4669 AutomationJSONReply(this, reply_message).SendError(error); |
4890 return; | 4670 return; |
4891 } | 4671 } |
4892 NavigationController& controller = web_contents->GetController(); | 4672 NavigationController& controller = web_contents->GetController(); |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5439 if (!GetTabFromJSONArgs(args, &web_contents, &error)) { | 5219 if (!GetTabFromJSONArgs(args, &web_contents, &error)) { |
5440 AutomationJSONReply(this, reply_message).SendError(error); | 5220 AutomationJSONReply(this, reply_message).SendError(error); |
5441 return; | 5221 return; |
5442 } | 5222 } |
5443 NavigationController& controller = web_contents->GetController(); | 5223 NavigationController& controller = web_contents->GetController(); |
5444 new NavigationNotificationObserver(&controller, this, reply_message, | 5224 new NavigationNotificationObserver(&controller, this, reply_message, |
5445 1, false, true); | 5225 1, false, true); |
5446 controller.Reload(false); | 5226 controller.Reload(false); |
5447 } | 5227 } |
5448 | 5228 |
5449 void TestingAutomationProvider::CaptureEntirePageJSON( | |
5450 DictionaryValue* args, | |
5451 IPC::Message* reply_message) { | |
5452 if (SendErrorIfModalDialogActive(this, reply_message)) | |
5453 return; | |
5454 | |
5455 WebContents* web_contents; | |
5456 std::string error; | |
5457 | |
5458 if (!GetTabFromJSONArgs(args, &web_contents, &error)) { | |
5459 AutomationJSONReply(this, reply_message).SendError(error); | |
5460 return; | |
5461 } | |
5462 | |
5463 base::FilePath::StringType path_str; | |
5464 if (!args->GetString("path", &path_str)) { | |
5465 AutomationJSONReply(this, reply_message) | |
5466 .SendError("'path' missing or invalid"); | |
5467 return; | |
5468 } | |
5469 | |
5470 RenderViewHost* render_view = web_contents->GetRenderViewHost(); | |
5471 if (render_view) { | |
5472 base::FilePath path(path_str); | |
5473 // This will delete itself when finished. | |
5474 PageSnapshotTaker* snapshot_taker = new PageSnapshotTaker( | |
5475 this, reply_message, web_contents, path); | |
5476 snapshot_taker->Start(); | |
5477 } else { | |
5478 AutomationJSONReply(this, reply_message) | |
5479 .SendError("Tab has no associated RenderViewHost"); | |
5480 } | |
5481 } | |
5482 | |
5483 void TestingAutomationProvider::GetCookiesJSON( | 5229 void TestingAutomationProvider::GetCookiesJSON( |
5484 DictionaryValue* args, IPC::Message* reply_message) { | 5230 DictionaryValue* args, IPC::Message* reply_message) { |
5485 automation_util::GetCookiesJSON(this, args, reply_message); | 5231 automation_util::GetCookiesJSON(this, args, reply_message); |
5486 } | 5232 } |
5487 | 5233 |
5488 void TestingAutomationProvider::DeleteCookieJSON( | 5234 void TestingAutomationProvider::DeleteCookieJSON( |
5489 DictionaryValue* args, IPC::Message* reply_message) { | 5235 DictionaryValue* args, IPC::Message* reply_message) { |
5490 automation_util::DeleteCookieJSON(this, args, reply_message); | 5236 automation_util::DeleteCookieJSON(this, args, reply_message); |
5491 } | 5237 } |
5492 | 5238 |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5944 if (g_browser_process) | 5690 if (g_browser_process) |
5945 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 5691 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
5946 } | 5692 } |
5947 | 5693 |
5948 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, | 5694 void TestingAutomationProvider::EnsureTabSelected(Browser* browser, |
5949 WebContents* tab) { | 5695 WebContents* tab) { |
5950 TabStripModel* tab_strip = browser->tab_strip_model(); | 5696 TabStripModel* tab_strip = browser->tab_strip_model(); |
5951 if (tab_strip->GetActiveWebContents() != tab) | 5697 if (tab_strip->GetActiveWebContents() != tab) |
5952 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(tab), true); | 5698 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(tab), true); |
5953 } | 5699 } |
OLD | NEW |