Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: chrome/browser/automation/testing_automation_provider.cc

Issue 10384023: Determine the element location and click synchronously on the renderer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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 }
dennis_jeffrey 2012/05/08 19:18:49 no need for curly braces
kkania 2012/05/09 18:19:59 Done.
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 } // namespace
5943
5913 void TestingAutomationProvider::ProcessWebMouseEvent( 5944 void TestingAutomationProvider::ProcessWebMouseEvent(
5914 DictionaryValue* args, 5945 DictionaryValue* args,
5915 IPC::Message* reply_message) { 5946 IPC::Message* reply_message) {
5916 if (SendErrorIfModalDialogActive(this, reply_message)) 5947 if (SendErrorIfModalDialogActive(this, reply_message))
5917 return; 5948 return;
5918 5949
5919 RenderViewHost* view; 5950 content::WebContents* web_contents;
5920 std::string error; 5951 std::string error;
5921 if (!GetRenderViewFromJSONArgs(args, profile(), &view, &error)) { 5952 if (!GetTabFromJSONArgs(args, &web_contents, &error)) {
5922 AutomationJSONReply(this, reply_message).SendError(error); 5953 AutomationJSONReply(this, reply_message).SendError(error);
5923 return; 5954 return;
5924 } 5955 }
5925 5956
5926 int type; 5957 int type;
5927 int button; 5958 int button;
5928 int modifiers; 5959 int modifiers;
5929 WebKit::WebMouseEvent event; 5960 WebKit::WebMouseEvent event;
5930 if (!args->GetInteger("type", &type) || 5961 if (!args->GetInteger("type", &type) ||
5931 !args->GetInteger("button", &button) || 5962 !args->GetInteger("button", &button) ||
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
5970 event.modifiers = 0; 6001 event.modifiers = 0;
5971 if (modifiers & automation::kShiftKeyMask) 6002 if (modifiers & automation::kShiftKeyMask)
5972 event.modifiers |= WebKit::WebInputEvent::ShiftKey; 6003 event.modifiers |= WebKit::WebInputEvent::ShiftKey;
5973 if (modifiers & automation::kControlKeyMask) 6004 if (modifiers & automation::kControlKeyMask)
5974 event.modifiers |= WebKit::WebInputEvent::ControlKey; 6005 event.modifiers |= WebKit::WebInputEvent::ControlKey;
5975 if (modifiers & automation::kAltKeyMask) 6006 if (modifiers & automation::kAltKeyMask)
5976 event.modifiers |= WebKit::WebInputEvent::AltKey; 6007 event.modifiers |= WebKit::WebInputEvent::AltKey;
5977 if (modifiers & automation::kMetaKeyMask) 6008 if (modifiers & automation::kMetaKeyMask)
5978 event.modifiers |= WebKit::WebInputEvent::MetaKey; 6009 event.modifiers |= WebKit::WebInputEvent::MetaKey;
5979 6010
5980 view->ForwardMouseEvent(event); 6011 TabContentsWrapper* tab_contents =
5981 new InputEventAckNotificationObserver(this, reply_message, event.type, 6012 TabContentsWrapper::GetCurrentWrapperForContents(web_contents);
5982 1); 6013 if (!tab_contents) {
dennis_jeffrey 2012/05/08 19:18:49 Could you add a comment to explain the difference
kkania 2012/05/09 18:19:59 Got rid of this hack. I didn't actually need it an
6014 web_contents->GetRenderViewHost()->ForwardMouseEvent(event);
6015 new InputEventAckNotificationObserver(this, reply_message, event.type, 1);
6016 return;
6017 }
6018
6019 AutomationMouseEvent automation_event;
6020 automation_event.mouse_event = event;
6021 Value* location_script_chain_value;
6022 if (args->Get("location_script_chain", &location_script_chain_value)) {
6023 if (!ReadScriptEvaluationRequestList(
6024 location_script_chain_value,
6025 &automation_event.location_script_chain,
6026 &error)) {
6027 AutomationJSONReply(this, reply_message).SendError(error);
6028 return;
6029 }
6030 }
6031 tab_contents->automation_tab_helper()->ProcessMouseEvent(automation_event);
6032 new MouseEventProcessedObserver(this, reply_message, tab_contents);
5983 } 6033 }
5984 6034
5985 namespace { 6035 namespace {
5986 6036
5987 // Gets the active JavaScript modal dialog, or NULL if none. 6037 // Gets the active JavaScript modal dialog, or NULL if none.
5988 JavaScriptAppModalDialog* GetActiveJavaScriptModalDialog( 6038 JavaScriptAppModalDialog* GetActiveJavaScriptModalDialog(
5989 ErrorCode* error_code) { 6039 ErrorCode* error_code) {
5990 AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance(); 6040 AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance();
5991 if (!dialog_queue->HasActiveDialog() || 6041 if (!dialog_queue->HasActiveDialog() ||
5992 !dialog_queue->active_dialog()->IsJavaScriptModalDialog()) { 6042 !dialog_queue->active_dialog()->IsJavaScriptModalDialog()) {
(...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after
7127 *browser_handle = browser_tracker_->Add(browser); 7177 *browser_handle = browser_tracker_->Add(browser);
7128 *success = true; 7178 *success = true;
7129 } 7179 }
7130 } 7180 }
7131 } 7181 }
7132 7182
7133 void TestingAutomationProvider::OnRemoveProvider() { 7183 void TestingAutomationProvider::OnRemoveProvider() {
7134 if (g_browser_process) 7184 if (g_browser_process)
7135 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); 7185 g_browser_process->GetAutomationProviderList()->RemoveProvider(this);
7136 } 7186 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698