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/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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 #include "chrome/browser/ui/browser_window.h" | 102 #include "chrome/browser/ui/browser_window.h" |
103 #include "chrome/browser/ui/find_bar/find_bar.h" | 103 #include "chrome/browser/ui/find_bar/find_bar.h" |
104 #include "chrome/browser/ui/fullscreen_controller.h" | 104 #include "chrome/browser/ui/fullscreen_controller.h" |
105 #include "chrome/browser/ui/fullscreen_exit_bubble_type.h" | 105 #include "chrome/browser/ui/fullscreen_exit_bubble_type.h" |
106 #include "chrome/browser/ui/login/login_prompt.h" | 106 #include "chrome/browser/ui/login/login_prompt.h" |
107 #include "chrome/browser/ui/media_stream_infobar_delegate.h" | 107 #include "chrome/browser/ui/media_stream_infobar_delegate.h" |
108 #include "chrome/browser/ui/omnibox/location_bar.h" | 108 #include "chrome/browser/ui/omnibox/location_bar.h" |
109 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 109 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
110 #include "chrome/browser/ui/search_engines/keyword_editor_controller.h" | 110 #include "chrome/browser/ui/search_engines/keyword_editor_controller.h" |
111 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 111 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 112 #include "chrome/common/automation_constants.h" |
| 113 #include "chrome/common/automation_events.h" |
112 #include "chrome/common/automation_id.h" | 114 #include "chrome/common/automation_id.h" |
113 #include "chrome/common/automation_messages.h" | 115 #include "chrome/common/automation_messages.h" |
114 #include "chrome/common/chrome_constants.h" | 116 #include "chrome/common/chrome_constants.h" |
115 #include "chrome/common/chrome_notification_types.h" | 117 #include "chrome/common/chrome_notification_types.h" |
116 #include "chrome/common/chrome_paths.h" | 118 #include "chrome/common/chrome_paths.h" |
117 #include "chrome/common/chrome_switches.h" | 119 #include "chrome/common/chrome_switches.h" |
118 #include "chrome/common/chrome_view_type.h" | 120 #include "chrome/common/chrome_view_type.h" |
119 #include "chrome/common/extensions/extension.h" | 121 #include "chrome/common/extensions/extension.h" |
120 #include "chrome/common/extensions/extension_action.h" | 122 #include "chrome/common/extensions/extension_action.h" |
121 #include "chrome/common/extensions/url_pattern.h" | 123 #include "chrome/common/extensions/url_pattern.h" |
(...skipping 5781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5903 bool meta = !!(modifiers & automation::kMetaKeyMask); | 5905 bool meta = !!(modifiers & automation::kMetaKeyMask); |
5904 if (!ui_controls::SendKeyPressNotifyWhenDone( | 5906 if (!ui_controls::SendKeyPressNotifyWhenDone( |
5905 window, static_cast<ui::KeyboardCode>(keycode), | 5907 window, static_cast<ui::KeyboardCode>(keycode), |
5906 control, shift, alt, meta, | 5908 control, shift, alt, meta, |
5907 base::Bind(SendSuccessReply, AsWeakPtr(), reply_message))) { | 5909 base::Bind(SendSuccessReply, AsWeakPtr(), reply_message))) { |
5908 AutomationJSONReply(this, reply_message) | 5910 AutomationJSONReply(this, reply_message) |
5909 .SendError("Could not send the native key event"); | 5911 .SendError("Could not send the native key event"); |
5910 } | 5912 } |
5911 } | 5913 } |
5912 | 5914 |
| 5915 namespace { |
| 5916 |
| 5917 bool ReadScriptEvaluationRequestList( |
| 5918 base::Value* value, |
| 5919 std::vector<ScriptEvaluationRequest>* list, |
| 5920 std::string* error_msg) { |
| 5921 ListValue* request_list; |
| 5922 if (!value->GetAsList(&request_list)) |
| 5923 return false; |
| 5924 |
| 5925 for (size_t i = 0; i < request_list->GetSize(); ++i) { |
| 5926 DictionaryValue* request_dict; |
| 5927 if (!request_list->GetDictionary(i, &request_dict)) { |
| 5928 *error_msg = "Script evaluation request was not a dictionary"; |
| 5929 return false; |
| 5930 } |
| 5931 ScriptEvaluationRequest request; |
| 5932 if (!request_dict->GetString("script", &request.script) || |
| 5933 !request_dict->GetString("frame_xpath", &request.frame_xpath)) { |
| 5934 *error_msg = "Script evaluation request was invalid"; |
| 5935 return false; |
| 5936 } |
| 5937 list->push_back(request); |
| 5938 } |
| 5939 return true; |
| 5940 } |
| 5941 |
| 5942 void SendPointIfAlive( |
| 5943 base::WeakPtr<AutomationProvider> provider, |
| 5944 IPC::Message* reply_message, |
| 5945 const gfx::Point& point) { |
| 5946 if (provider) { |
| 5947 DictionaryValue dict; |
| 5948 dict.SetInteger("x", point.x()); |
| 5949 dict.SetInteger("y", point.y()); |
| 5950 AutomationJSONReply(provider.get(), reply_message).SendSuccess(&dict); |
| 5951 } |
| 5952 } |
| 5953 |
| 5954 void SendErrorIfAlive( |
| 5955 base::WeakPtr<AutomationProvider> provider, |
| 5956 IPC::Message* reply_message, |
| 5957 const automation::Error& error) { |
| 5958 if (provider) { |
| 5959 AutomationJSONReply(provider.get(), reply_message).SendError(error); |
| 5960 } |
| 5961 } |
| 5962 |
| 5963 } // namespace |
| 5964 |
5913 void TestingAutomationProvider::ProcessWebMouseEvent( | 5965 void TestingAutomationProvider::ProcessWebMouseEvent( |
5914 DictionaryValue* args, | 5966 DictionaryValue* args, |
5915 IPC::Message* reply_message) { | 5967 IPC::Message* reply_message) { |
5916 if (SendErrorIfModalDialogActive(this, reply_message)) | 5968 if (SendErrorIfModalDialogActive(this, reply_message)) |
5917 return; | 5969 return; |
5918 | 5970 |
5919 RenderViewHost* view; | 5971 RenderViewHost* view; |
5920 std::string error; | 5972 std::string error; |
5921 if (!GetRenderViewFromJSONArgs(args, profile(), &view, &error)) { | 5973 if (!GetRenderViewFromJSONArgs(args, profile(), &view, &error)) { |
5922 AutomationJSONReply(this, reply_message).SendError(error); | 5974 AutomationJSONReply(this, reply_message).SendError(error); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5970 event.modifiers = 0; | 6022 event.modifiers = 0; |
5971 if (modifiers & automation::kShiftKeyMask) | 6023 if (modifiers & automation::kShiftKeyMask) |
5972 event.modifiers |= WebKit::WebInputEvent::ShiftKey; | 6024 event.modifiers |= WebKit::WebInputEvent::ShiftKey; |
5973 if (modifiers & automation::kControlKeyMask) | 6025 if (modifiers & automation::kControlKeyMask) |
5974 event.modifiers |= WebKit::WebInputEvent::ControlKey; | 6026 event.modifiers |= WebKit::WebInputEvent::ControlKey; |
5975 if (modifiers & automation::kAltKeyMask) | 6027 if (modifiers & automation::kAltKeyMask) |
5976 event.modifiers |= WebKit::WebInputEvent::AltKey; | 6028 event.modifiers |= WebKit::WebInputEvent::AltKey; |
5977 if (modifiers & automation::kMetaKeyMask) | 6029 if (modifiers & automation::kMetaKeyMask) |
5978 event.modifiers |= WebKit::WebInputEvent::MetaKey; | 6030 event.modifiers |= WebKit::WebInputEvent::MetaKey; |
5979 | 6031 |
5980 view->ForwardMouseEvent(event); | 6032 AutomationMouseEvent automation_event; |
5981 new InputEventAckNotificationObserver(this, reply_message, event.type, | 6033 automation_event.mouse_event = event; |
5982 1); | 6034 Value* location_script_chain_value; |
| 6035 if (args->Get("location_script_chain", &location_script_chain_value)) { |
| 6036 if (!ReadScriptEvaluationRequestList( |
| 6037 location_script_chain_value, |
| 6038 &automation_event.location_script_chain, |
| 6039 &error)) { |
| 6040 AutomationJSONReply(this, reply_message).SendError(error); |
| 6041 return; |
| 6042 } |
| 6043 } |
| 6044 |
| 6045 new AutomationMouseEventProcessor( |
| 6046 view, |
| 6047 automation_event, |
| 6048 base::Bind(&SendPointIfAlive, AsWeakPtr(), reply_message), |
| 6049 base::Bind(&SendErrorIfAlive, AsWeakPtr(), reply_message)); |
5983 } | 6050 } |
5984 | 6051 |
5985 namespace { | 6052 namespace { |
5986 | 6053 |
5987 // Gets the active JavaScript modal dialog, or NULL if none. | 6054 // Gets the active JavaScript modal dialog, or NULL if none. |
5988 JavaScriptAppModalDialog* GetActiveJavaScriptModalDialog( | 6055 JavaScriptAppModalDialog* GetActiveJavaScriptModalDialog( |
5989 ErrorCode* error_code) { | 6056 ErrorCode* error_code) { |
5990 AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance(); | 6057 AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance(); |
5991 if (!dialog_queue->HasActiveDialog() || | 6058 if (!dialog_queue->HasActiveDialog() || |
5992 !dialog_queue->active_dialog()->IsJavaScriptModalDialog()) { | 6059 !dialog_queue->active_dialog()->IsJavaScriptModalDialog()) { |
(...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7127 *browser_handle = browser_tracker_->Add(browser); | 7194 *browser_handle = browser_tracker_->Add(browser); |
7128 *success = true; | 7195 *success = true; |
7129 } | 7196 } |
7130 } | 7197 } |
7131 } | 7198 } |
7132 | 7199 |
7133 void TestingAutomationProvider::OnRemoveProvider() { | 7200 void TestingAutomationProvider::OnRemoveProvider() { |
7134 if (g_browser_process) | 7201 if (g_browser_process) |
7135 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 7202 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
7136 } | 7203 } |
OLD | NEW |